From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A747CDF60 for ; Wed, 2 Oct 2024 03:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839228; cv=none; b=PNcD4ImUTsvt4uunqUb509n7A3JBcYkqA4sZ1Lsxpm6sZi+LwNc/O1GwOZwwFX27K1rEjz2uHyBDaFlbgHYwMv73ZaqG/broPK+GFnDbY3dvx6lk17FRUhB9OtohG0wRT5vpXVoZO1K1hnUxQYhFy+jG5tZ36VIyQWOgAgeC3h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839228; c=relaxed/simple; bh=Z0h5c1P0yeBhm5Am9G6JjbqtoJL+eQh4PwduChMZ9UI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dp8SZUjDvKoXCTLbh9A6aQPvIR1AI0netow+K2KGRTsB3YWRPZpXRTTT0dvw5SXb9biylJfrg14GLYxGtRVJINtY7dbcK+jSaPAIAr4PmPJtguZfGHntDGNjaIbik65w8QbVT81lpVePkopbmWm2pSt9InTBDKcsThLygKBiNc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FFzNJevI; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FFzNJevI" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e29b4f8837so6536397b3.0 for ; Tue, 01 Oct 2024 20:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839225; x=1728444025; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=mlqVBWAOpVfJanfv4s+m+V064r/fmGnZe909uVEp74Q=; b=FFzNJevIRBYbarn+yFm4lSAD+eH7A8qZ1d2QYfz2+J5ql6DsrGvrYC/8pQYqSjXxZT 67wXoeEstlxnvePIEb7R0cX1vt9+MRJUTpEg5M5ZHnPEua54k9kIIqNb+mLgjDNasUUI 9XN/0C63fwMhHbZDx0EVqA1Xid6FpX1yQ6uoDY08kN5zGrtrRlfjtjIVdRNOpno8Sa4A rr1E4QHQUbllEJDXK8J3Sl5uVDGUvwt44nwbdPHHP7xc/Aowk5ZOKXvR7PeS+g/9tdUA IPzslAqmeKFdSF4AEo1JlnvcC02+NP20Z7j3Gx0RJpA44y/FXT3sr4M3+HeK26VDMAkC PJfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839225; x=1728444025; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mlqVBWAOpVfJanfv4s+m+V064r/fmGnZe909uVEp74Q=; b=V/hw138SX4NKtL1FAKBhGeM6967LnwstBY0xdtvBNdZZOgH5LXpKkZ8I25l8ITzHGO q1Hk6W+Yv+Xz0HbV683eM8vmJovFu38e5j4oY5Rr7iuMf00XjpMZL0lW37NTtkFnAUha fe9MgCh7oOG9ek/5fYkikWkplSvCpc6I3FQvHcGf+MnUWcY/tw0H3MX+1tMlszj/E37K SqeVDHCdKe7TEZYha0tb77Y2xudiLUeVyH5ub4eO1N8JPAoc6RZQwQT9Xq4zAJZwZ9Vl tGd47A3bJ1XnFhHUBvJT7VhuEmetq/HFd+KMZSGLtARpmEq6jLbDz1AcC2KFcCGv4OAB t7dw== X-Forwarded-Encrypted: i=1; AJvYcCW749efeURbGECsgnazqEoKWrWH31EwBWsUW6nWy8X/8rxHlIa0nC24IiJjd2SP64hJ3wI+kDeLn25OyEg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7sr2pVAC2En9UX9Ol3RnKIs4IwfTVqTGxm5a0TUbDEO5xy3+A aMWKVdTkR5qK2D0XEmXePqR7VdNm1BJLbXQRk3uiGzPQv7uuSsB7euK/5o+yfA26j2QI5CKtiZF 9CinGMQ== X-Google-Smtp-Source: AGHT+IGzuGaCwhO4F5RbpJtWD80jojIRLpMbMtUnTcgGgB1r9Jr5pkreMHPYLvjuBmCRnD7/UJ/Wuc0bIOVS X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:690c:64c9:b0:6db:e464:addc with SMTP id 00721157ae682-6e2a34b7328mr410007b3.4.1727839224568; Tue, 01 Oct 2024 20:20:24 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:04 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 01/13] perf pmu: Simplify an asprintf error message From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use ifs rather than ?: to avoid a large compound statement. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/pmu.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8993b5853687..cb2eb2407de5 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1466,13 +1466,12 @@ static int pmu_config_term(const struct perf_pmu *p= mu, if (err) { char *err_str; =20 - parse_events_error__handle(err, term->err_val, - asprintf(&err_str, - "value too big for format (%s), maximum is %llu", - format->name, (unsigned long long)max_val) < 0 - ? strdup("value too big for format") - : err_str, - NULL); + if (asprintf(&err_str, + "value too big for format (%s), maximum is %llu", + format->name, (unsigned long long)max_val) < 0) { + err_str =3D strdup("value too big for format"); + } + parse_events_error__handle(err, term->err_val, err_str, /*help=3D*/NULL= ); return -EINVAL; } /* --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C699214A85 for ; Wed, 2 Oct 2024 03:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839229; cv=none; b=TiVanfC7HfFQPw9AYgIJeZ/Kj/smGMNrHHQFa1TatqOR4HDTaYOYhJRlXWEueXfZYOo6vhXkTtaG8llmbNPXLs7s+5Dzl0lYITlspndFCQromcXdr0MoZUC8T/cQeLS87d/1bkIRbCTqKeZ+7scvvrlRnO019PUQJd56GHXabkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839229; c=relaxed/simple; bh=YWlEC9E2v6TPbXto6REFNEMjNj2MpJCCm4sErqLG7r8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=debFlpHwBtKL5JpT+KSHah0CdGf8GPIbZ86mwSekAvGMnA9zn94yi63Nn8URiyTcSCI6yBxunG8JsA0zVlbqUsD1FatiZPoKKKYCd/oPBMUhvkHki07M01d3+iM+A8Gsh9tRmhKayq2yntouhmadjQL2gKmwUnCRyJ3uGTRg0uA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zfoyPads; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zfoyPads" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d7124939beso100485807b3.2 for ; Tue, 01 Oct 2024 20:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839227; x=1728444027; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=VE9+IE7hHSrPc5kQbTceMm06rK1QDC9BFjLSZ+vA0i8=; b=zfoyPadssky7gu41wv9N7Zdc0Ya/AE6E1B5wxM4FknrUJ+QABNa3Tp1ca6Rcm4tb2x tNA+E0sLPwhY6OuPNkq98c4M6uslsvWc6KY/D9RQCJmf0YancvO6okLhnz0CRZSMrpFy 9ARh6gdk8PQsevnpLUSl8HHsE4L/zSTv8bL+pNQuejZ4M00VwwFvG5B8Su2K/2gN+dfx ld6WjbEE3G3lHdT6TuixOQieCZnK3HYw4kMIHBQ50m/CbxZmob4nS33p1oZbpBAD50Bv DMVlbYFaNN4grbulhE+InMSFYFZ4KylC6utvtw2wjHlk2B430zwKcRadFEl76Ww6eTUD 9CKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839227; x=1728444027; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VE9+IE7hHSrPc5kQbTceMm06rK1QDC9BFjLSZ+vA0i8=; b=YGXef1uDZTOmfwXrndVqJyDGRkVE7owYzRLEioJ2dYqbSArAkm9Nx4TfmEH0lKeJYR 3hB3kr35iQUht6IbDSCi+0z8boGVQvCPqVejXERG+7/eLG+7f3I+hQG6A6ok7FkvzDny bdBdS64l07TJNDYYsoV+065ysBvq9TOIfDzY1ZlumGZUI7VqqeMstslLpIOmFLP/IFtQ 2YBh5m2EDUAZgCEOvZcyDoD/mNc7abQUUmV9acD0cLn8SnxuGbvibv0P2w/cyj8YlE45 lTzFUEGUquhdpAgN/+HZSlC/kYEzJVEFbxGlUDSKsNth/bG3Z8sh5YueRa+oOtXNgdR8 jkIg== X-Forwarded-Encrypted: i=1; AJvYcCXG+cirfrMqN7DcR6O6njd7uoyyRVCCQGcmagbzKj+uA3QU24zNOx/kve28yVnZ1cbwWAESHuhpkVEVzGg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9LyW3DqwWo1N8KM1BtEFXvrQUWD6x2ZJQ6uzLimQ6bL0dpTeb fcD4V1a6wMjgsRnOf4Supb9c2ISW+ea2zvkjlGRAdf1xfEW/rWECUQaEjTG4OJeUqswYAxL4ax1 zFeNRqQ== X-Google-Smtp-Source: AGHT+IH/inkFspuhxgcTa9B9c/jF0G4nAk8RuafY1f+rzXiimD8J3ME4ldlsb5wIzWznJRsJHDGFpFXfnKiT X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:690c:4c13:b0:62f:1f63:ae4f with SMTP id 00721157ae682-6e2a2adca3dmr620527b3.1.1727839226771; Tue, 01 Oct 2024 20:20:26 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:05 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 02/13] perf pmu: Allow hardcoded terms to be applied to attributes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hard coded terms like "config=3D10" are skipped by perf_pmu__config assuming they were already applied to a perf_event_attr by parse event's config_attr function. When doing a reverse number to name lookup in perf_pmu__name_from_config, as the hardcoded terms aren't applied the config value is incorrect leading to misses or false matches. Fix this by adding a parameter to have perf_pmu__config apply hardcoded terms too (not just in parse event's config_term_common). Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/arch/x86/util/intel-pt.c | 3 +- tools/perf/tests/pmu.c | 3 +- tools/perf/util/parse-events.c | 4 ++- tools/perf/util/pmu.c | 56 ++++++++++++++++++++++++----- tools/perf/util/pmu.h | 4 ++- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index ea510a7486b1..8f235d8b67b6 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -75,7 +75,8 @@ static int intel_pt_parse_terms_with_default(const struct= perf_pmu *pmu, goto out_free; =20 attr.config =3D *config; - err =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/true, /*err= =3D*/NULL); + err =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/true, /*app= ly_hardcoded=3D*/false, + /*err=3D*/NULL); if (err) goto out_free; =20 diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index be18506f6a24..6a681e3fb552 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -176,7 +176,8 @@ static int test__pmu_format(struct test_suite *test __m= aybe_unused, int subtest } =20 memset(&attr, 0, sizeof(attr)); - ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, /*er= r=3D*/NULL); + ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, + /*apply_hardcoded=3D*/false, /*err=3D*/NULL); if (ret) { pr_err("perf_pmu__config_terms failed"); goto err_out; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e96cf13dc396..6ae611e70fae 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1546,7 +1546,9 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, return -ENOMEM; } =20 - if (perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { + /* Skip configuring hard coded terms that were applied by config_attr. */ + if (perf_pmu__config(pmu, &attr, &parsed_terms, /*apply_hardcoded=3D*/fal= se, + parse_state->error)) { free_config_terms(&config_terms); parse_events_terms__exit(&parsed_terms); return -EINVAL; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index cb2eb2407de5..a1c7e879cb2f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1366,7 +1366,8 @@ static int pmu_config_term(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_term *term, struct parse_events_terms *head_terms, - bool zero, struct parse_events_error *err) + bool zero, bool apply_hardcoded, + struct parse_events_error *err) { struct perf_pmu_format *format; __u64 *vp; @@ -1380,11 +1381,46 @@ static int pmu_config_term(const struct perf_pmu *p= mu, return 0; =20 /* - * Hardcoded terms should be already in, so nothing - * to be done for them. + * Hardcoded terms are generally handled in event parsing, which + * traditionally have had to handle not having a PMU. An alias may + * have hard coded config values, optionally apply them below. */ - if (parse_events__is_hardcoded_term(term)) + if (parse_events__is_hardcoded_term(term)) { + /* Config terms set all bits in the config. */ + DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS); + + if (!apply_hardcoded) + return 0; + + bitmap_fill(bits, PERF_PMU_FORMAT_BITS); + + switch (term->type_term) { + case PARSE_EVENTS__TERM_TYPE_CONFIG: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG1: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config1, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG2: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config2, zero); + break; + case PARSE_EVENTS__TERM_TYPE_CONFIG3: + assert(term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_NUM); + pmu_format_value(bits, term->val.num, &attr->config3, zero); + break; + case PARSE_EVENTS__TERM_TYPE_USER: /* Not hardcoded. */ + return -EINVAL; + case PARSE_EVENTS__TERM_TYPE_NAME ... PARSE_EVENTS__TERM_TYPE_HARDWARE: + /* Skip non-config terms. */ + break; + default: + break; + } return 0; + } =20 format =3D pmu_find_format(&pmu->format, term->config); if (!format) { @@ -1487,12 +1523,13 @@ static int pmu_config_term(const struct perf_pmu *p= mu, int perf_pmu__config_terms(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *terms, - bool zero, struct parse_events_error *err) + bool zero, bool apply_hardcoded, + struct parse_events_error *err) { struct parse_events_term *term; =20 list_for_each_entry(term, &terms->terms, list) { - if (pmu_config_term(pmu, attr, term, terms, zero, err)) + if (pmu_config_term(pmu, attr, term, terms, zero, apply_hardcoded, err)) return -EINVAL; } =20 @@ -1506,6 +1543,7 @@ int perf_pmu__config_terms(const struct perf_pmu *pmu, */ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *head_terms, + bool apply_hardcoded, struct parse_events_error *err) { bool zero =3D !!pmu->perf_event_attr_init_default; @@ -1514,7 +1552,7 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, if (perf_pmu__is_fake(pmu)) return 0; =20 - return perf_pmu__config_terms(pmu, attr, head_terms, zero, err); + return perf_pmu__config_terms(pmu, attr, head_terms, zero, apply_hardcode= d, err); } =20 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu, @@ -2283,7 +2321,9 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { struct perf_event_attr attr =3D {.config =3D 0,}; - int ret =3D perf_pmu__config(pmu, &attr, &event->terms, NULL); + + int ret =3D perf_pmu__config(pmu, &attr, &event->terms, /*apply_hardcode= d=3D*/true, + /*err=3D*/NULL); =20 if (ret =3D=3D 0 && config =3D=3D attr.config) return event->name; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index d352d53b8d55..c70317d3fb04 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -206,11 +206,13 @@ typedef int (*pmu_format_callback)(void *state, const= char *name, int config, void pmu_add_sys_aliases(struct perf_pmu *pmu); int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *head_terms, + bool apply_hardcoded, struct parse_events_error *error); int perf_pmu__config_terms(const struct perf_pmu *pmu, struct perf_event_attr *attr, struct parse_events_terms *terms, - bool zero, struct parse_events_error *error); + bool zero, bool apply_hardcoded, + struct parse_events_error *error); __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name); int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms = *head_terms, --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5306618B09 for ; Wed, 2 Oct 2024 03:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839232; cv=none; b=IiMU4wQgGUQfQ8w4OCb4cFR2RcvBURaaxJv69uhFHV8v06y53rwPAAvR3u/eNFmuUVNn5/3oQTJjZ9PN8QG9nAZUZ5g5zqbJxFyNVRjXak330lsitWNK5l6ONWeAq7PrifaW+QcudG8ZwwQEZ/6v9cEXbUzgMaUSAOyST+9/13M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839232; c=relaxed/simple; bh=pbd0mtz7VbHTf9Txoh97J1oZDoDP3tqW9zIloce5NSE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=L1VX0CtDFjqPTNOJRFlwJU/AaGH2qa+qY+/Y4frcAShu813SJ+WY9I7IM4iG1JUYXTUZ9cYEM3vrH91lx5y6YIMqQPkXjxrA3JprTf9uK8tKOZf1MB4NwsG6+swSh2PwtKQhAxXXKlK/rf2wD1bT12a95QsUkLH2s1znboNYKfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DcSd1WeI; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DcSd1WeI" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e26046ed465so7631305276.3 for ; Tue, 01 Oct 2024 20:20:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839229; x=1728444029; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=39T+6noF1HDYHixFiWW8nys9E5rCFMsxZqBd3BPaByY=; b=DcSd1WeIoaya/OLsqKgxKzHR9cKxv1Y1LoQk5xOPveRM1fGBMyKj6a2syWAkylpENC 9A4cGNfdrjW/XK29IMJTwj2RL6RWrOkeRZvoUdM8EXtmUaAVZ8oAeNcUbWTLxb7Mi8K8 srDZAPM7vUoPdmcS9RNZPOdQrVkqITbjcCyFGawJN3qhRsfTyeIxDWwfmXpIJNT1QHTa im2x3faWIeF6B0zpL88amoFuURW3qA0P6aC9BApVaXaAU1zyHyDgwZOzB8iZ+9il7Vr5 xmfW2Hdh0Fclp+tRRDvN4c9/N3UkfAqH7VZpPXSxqgO1tqtyV7O76GDUVvTnIUxBX0Be NcWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839229; x=1728444029; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=39T+6noF1HDYHixFiWW8nys9E5rCFMsxZqBd3BPaByY=; b=k5x23qBVII8XpLc7gzRKKjMawF+IsDXqETLihuy4q6O313PZILz46QzNGjLnmv1s8q juxDSMzBzOpnYrF8Hq1rVLzfzchYWoOTtt/fj53mn/lzh8iPbMWiZBoNAQKJCR0Sg+Hb I5S6bzgINcP63jGPynE9Kj81TCCymCWKEpIcG+l1BpFcjNWd6aytjgICXI6+7/Smsv2j Ke1q8wBiL4/MDcxEY7c+r/AaTtz9cPb/CMIy4omj0mYDU8wyOYLtlZZhRBkydOZ55haI s99EnTKrghRU0r5yT0FG+byMHXvn0gqPyl89UuscwxDgyZQyLySHYJImbe/ziRaTBj5V EUDg== X-Forwarded-Encrypted: i=1; AJvYcCXbEx9Hjy8haPr5mwqqHXjwMyB7Bbwtyrh96+9ITzLcdAx+dePhbsm7sM1uxmEpAbswn8/KPXm6+XiKR94=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2tS/8q6BGJt/jQhEAkCGKLRhplhMo9IiTA0MQ6Ngs5YArvFhB vjqvBu28KUXhoIXvnDulSvjn8sKq56KlMYTedyFBXyypDz2yZJkPtFZUwoMR2i1Jt8gdHcZK7tT Ise5Vuw== X-Google-Smtp-Source: AGHT+IGGXpz7W1T1yyjYa2QLFOERmH1YOJwoLGSUEPWG+E5FM/tlDieHSEHZd2aGX20w6HMLgZUOd0Zysatg X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a25:bc8d:0:b0:e25:e5b9:8114 with SMTP id 3f1490d57ef6-e26383e33d0mr5567276.4.1727839229299; Tue, 01 Oct 2024 20:20:29 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:06 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 03/13] perf parse-events: Expose/rename config_term_name From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expose config_term_name as parse_events__term_type_str so that PMUs not in pmu.c may access it. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/parse-events.c | 20 +++++++++++--------- tools/perf/util/parse-events.h | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6ae611e70fae..228ae469d44a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -800,7 +800,7 @@ static int check_type_val(struct parse_events_term *ter= m, =20 static bool config_term_shrinked; =20 -static const char *config_term_name(enum parse_events__term_type term_type) +const char *parse_events__term_type_str(enum parse_events__term_type term_= type) { /* * Update according to parse-events.l @@ -886,7 +886,7 @@ config_term_avail(enum parse_events__term_type term_typ= e, struct parse_events_er =20 /* term_type is validated so indexing is safe */ if (asprintf(&err_str, "'%s' is not usable in 'perf stat'", - config_term_name(term_type)) >=3D 0) + parse_events__term_type_str(term_type)) >=3D 0) parse_events_error__handle(err, -1, err_str, NULL); return false; } @@ -1010,7 +1010,7 @@ do { \ case PARSE_EVENTS__TERM_TYPE_HARDWARE: default: parse_events_error__handle(err, term->err_term, - strdup(config_term_name(term->type_term)), + strdup(parse_events__term_type_str(term->type_term)), parse_events_formats_error_string(NULL)); return -EINVAL; } @@ -1134,8 +1134,9 @@ static int config_term_tracepoint(struct perf_event_a= ttr *attr, default: if (err) { parse_events_error__handle(err, term->err_term, - strdup(config_term_name(term->type_term)), - strdup("valid terms: call-graph,stack-size\n")); + strdup(parse_events__term_type_str(term->type_term)), + strdup("valid terms: call-graph,stack-size\n") + ); } return -EINVAL; } @@ -2582,7 +2583,7 @@ int parse_events_term__num(struct parse_events_term *= *term, struct parse_events_term temp =3D { .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, .type_term =3D type_term, - .config =3D config ? : strdup(config_term_name(type_term)), + .config =3D config ? : strdup(parse_events__term_type_str(type_term)), .no_value =3D no_value, .err_term =3D loc_term ? loc_term->first_column : 0, .err_val =3D loc_val ? loc_val->first_column : 0, @@ -2616,7 +2617,7 @@ int parse_events_term__term(struct parse_events_term = **term, void *loc_term, void *loc_val) { return parse_events_term__str(term, term_lhs, NULL, - strdup(config_term_name(term_rhs)), + strdup(parse_events__term_type_str(term_rhs)), loc_term, loc_val); } =20 @@ -2723,7 +2724,8 @@ int parse_events_terms__to_strbuf(const struct parse_= events_terms *terms, struct if (ret < 0) return ret; } else if ((unsigned int)term->type_term < __PARSE_EVENTS__TERM_TYPE_NR= ) { - ret =3D strbuf_addf(sb, "%s=3D", config_term_name(term->type_term)); + ret =3D strbuf_addf(sb, "%s=3D", + parse_events__term_type_str(term->type_term)); if (ret < 0) return ret; } @@ -2743,7 +2745,7 @@ static void config_terms_list(char *buf, size_t buf_s= z) =20 buf[0] =3D '\0'; for (i =3D 0; i < __PARSE_EVENTS__TERM_TYPE_NR; i++) { - const char *name =3D config_term_name(i); + const char *name =3D parse_events__term_type_str(i); =20 if (!config_term_avail(i, NULL)) continue; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 2b52f8d6aa29..ac1feaaeb8d5 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -168,6 +168,8 @@ struct parse_events_state { bool wild_card_pmus; }; =20 +const char *parse_events__term_type_str(enum parse_events__term_type term_= type); + bool parse_events__filter_pmu(const struct parse_events_state *parse_state, const struct perf_pmu *pmu); void parse_events__shrink_config_terms(void); --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 889F72746A for ; Wed, 2 Oct 2024 03:20:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839235; cv=none; b=qH2dOOrzbTcM1PZ8Qq68Pz94WcmVk90UVoe8bbwmoPbsQReSt/fapUqcE97onMBXo86ZIQrEBooutNNdhFbR/o+FgOoPhDNxB3NsE1QH9irnaJ0FBKg1BRwxD0Dsc3U5pT/VRkQmamIYFRFciZcpu1hwH2xxQo73+vaVwDewRmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839235; c=relaxed/simple; bh=WPhdtrk29aUIAmq0GlMnMniVrOofr6eu3wEHjxj+ZxY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=rn0Rzrr3gj8Kx6sAMbZho3VKR1HzjTUYcPbDH6DOEd2wJ8mR/0xq2/Xehn67JMsBgyE4J1FPm8N3cZuPkaaoS4M5wC5kfM0iTRddivxut339Dgx0+aUyOMHZQkq1d2nUE1mn2bzE+Vw1rlYpnbGhceYyDcuLvn6ChXUTfesZsPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HofbOSMV; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HofbOSMV" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e284982a31so42776367b3.3 for ; Tue, 01 Oct 2024 20:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839232; x=1728444032; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3RvT0hd2jmfWz0O+rVB1v2rttLdCldvdrDWZmCaZ1dU=; b=HofbOSMVMv8eAqc/691ttPWa6gMvLNXbhbm+UYQ2lSjtE3SKb7zt+V5HStJQkNhNdf RX1LS3POrGT8JgPceOPXIMzDE63xu14XtJUCMFre7c54KW2IMvbQ7wLyD8+4qK3pLj93 UfS0IrCXRMpCxujkYClC7n1322pmMaDiGBPbCFANiEAHNloRYXxoRv/n2sE3nwrftUp2 YHYnyVpcVz7iA+ivdbJXsmu/b2ij0qKoCEGIxTAQ81r/HlyxBDn3jXmvm4HXoCiTyhc8 t28H7uo/FxEx2LAzodmvL2zDOjdLFGdZozukFOg02jX8cy7/xo7XwbwGo28ORu0b1Oaq CilQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839232; x=1728444032; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3RvT0hd2jmfWz0O+rVB1v2rttLdCldvdrDWZmCaZ1dU=; b=GFwPO41wfmiyvaulcAPwNMVoEN9t9ygp9eaKLaVNdEO6HrmJMPRy4l0UBJfYAhN4mK 9s44WYs7KQD7UCYxgGHD0X4oYI4MSGYK2hIwNN8g63Fr5mHaIph1wYuHFEJPwmVXWpVa ihYbilWl5eiuSZbXfVbOEmNEZ/Xix4FwUkjYUu0Ys8URcVF+JYcgMV1JhVSAcYLX+Aji wFUrxdKSLKNuiyMo8YSMHNu9aZ1i7bagAL/cZxto3RbvMPfadWHkZ2KOD7/Lu/D8+hI7 9B0ycDkHulmkN5YEjYvo+GnPbQUrXQ3HsSlqOjhFKCmqpSEmTc5nmBtKkWH/f4GwE6oe kAKg== X-Forwarded-Encrypted: i=1; AJvYcCWbhSE3JUmmAfk2rY1vAFRVG6phDfxiRJfXkz9wvk5c+3/1irj5aEcYGfKfp7LT+h4aZxl0j79xGn3skg8=@vger.kernel.org X-Gm-Message-State: AOJu0Yze5hbOCNTuSGUP2FztSqUIXifQCb+m8MdqGAwLnDppW6MtajHg ynnEOBOOx6gwowYqwpb3Fw+Nsmd8JGH7KQlWvhxinXkZgiy9FbeCWK8WS1VoEk+7rmw69Gf0PR4 oeW7NAw== X-Google-Smtp-Source: AGHT+IGfTs0iZHGxdUySylhPhFR7UaMyVyaMyd1CSHpVGkI17g2GVF6Z0evlE9vVQnAF+b8A5TVpZ33wpCwc X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:690c:480e:b0:68d:52a1:bf4 with SMTP id 00721157ae682-6e2a2ae8697mr189557b3.2.1727839231625; Tue, 01 Oct 2024 20:20:31 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:07 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 04/13] perf tool_pmu: Factor tool events into their own PMU From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than treat tool events as a special kind of event, create a tool only PMU where the events/aliases match the existing duration_time, user_time and system_time events. Remove special parsing and printing support for the tool events, but add function calls for when PMU functions are called on a tool_pmu. Move the tool PMU code in evsel into tool_pmu.c to better encapsulate the tool event behavior in that file. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-list.c | 13 +- tools/perf/builtin-stat.c | 1 + tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 272 ++-------------------- tools/perf/util/evsel.h | 28 +-- tools/perf/util/metricgroup.c | 1 + tools/perf/util/parse-events.c | 39 ---- tools/perf/util/parse-events.h | 3 - tools/perf/util/parse-events.l | 11 - tools/perf/util/parse-events.y | 16 -- tools/perf/util/pmu.c | 20 +- tools/perf/util/pmu.h | 2 + tools/perf/util/pmus.c | 9 + tools/perf/util/print-events.c | 36 +-- tools/perf/util/print-events.h | 1 - tools/perf/util/stat-display.c | 6 +- tools/perf/util/stat-shadow.c | 1 + tools/perf/util/tool_pmu.c | 411 +++++++++++++++++++++++++++++++++ tools/perf/util/tool_pmu.h | 51 ++++ 19 files changed, 530 insertions(+), 392 deletions(-) create mode 100644 tools/perf/util/tool_pmu.c create mode 100644 tools/perf/util/tool_pmu.h diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 65b8cba324be..b8378ba18c28 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -19,6 +19,7 @@ #include "util/string2.h" #include "util/strlist.h" #include "util/strbuf.h" +#include "util/tool_pmu.h" #include #include #include @@ -614,9 +615,18 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); else if (strcmp(argv[i], "sw") =3D=3D 0 || strcmp(argv[i], "software") =3D=3D 0) { + char *old_pmu_glob =3D default_ps.pmu_glob; + print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); - print_tool_events(&print_cb, ps); + default_ps.pmu_glob =3D strdup("tool"); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); + default_ps.pmu_glob =3D old_pmu_glob; } else if (strcmp(argv[i], "cache") =3D=3D 0 || strcmp(argv[i], "hwcache") =3D=3D 0) print_hwcache_events(&print_cb, ps); @@ -664,7 +674,6 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); - print_tool_events(&print_cb, ps); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1521b6df2606..ff4214900ae0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -46,6 +46,7 @@ #include "util/parse-events.h" #include "util/pmus.h" #include "util/pmu.h" +#include "util/tool_pmu.h" #include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index dc616292b2dd..fa508e113dd0 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -83,6 +83,7 @@ perf-util-y +=3D pmu.o perf-util-y +=3D pmus.o perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.o +perf-util-y +=3D tool_pmu.o perf-util-y +=3D svghelper.o perf-util-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o perf-util-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index edfb376f0611..3d5d974a0429 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +50,7 @@ #include "off_cpu.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" #include "rlimit.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" @@ -71,33 +71,6 @@ struct perf_missing_features perf_missing_features; =20 static clockid_t clockid; =20 -static const char *const perf_tool_event__tool_names[PERF_TOOL_MAX] =3D { - NULL, - "duration_time", - "user_time", - "system_time", -}; - -const char *perf_tool_event__to_str(enum perf_tool_event ev) -{ - if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) - return perf_tool_event__tool_names[ev]; - - return NULL; -} - -enum perf_tool_event perf_tool_event__from_str(const char *str) -{ - int i; - - perf_tool_event__for_each_event(i) { - if (!strcmp(str, perf_tool_event__tool_names[i])) - return i; - } - return PERF_TOOL_NONE; -} - - static int evsel__no_extra_init(struct evsel *evsel __maybe_unused) { return 0; @@ -416,7 +389,6 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.leader =3D orig->core.leader; =20 evsel->max_events =3D orig->max_events; - evsel->tool_event =3D orig->tool_event; free((char *)evsel->unit); evsel->unit =3D strdup(orig->unit); if (evsel->unit =3D=3D NULL) @@ -614,11 +586,6 @@ static int evsel__sw_name(struct evsel *evsel, char *b= f, size_t size) return r + evsel__add_modifiers(evsel, bf + r, size - r); } =20 -static int evsel__tool_name(enum perf_tool_event ev, char *bf, size_t size) -{ - return scnprintf(bf, size, "%s", perf_tool_event__to_str(ev)); -} - static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) { int r; @@ -769,10 +736,7 @@ const char *evsel__name(struct evsel *evsel) break; =20 case PERF_TYPE_SOFTWARE: - if (evsel__is_tool(evsel)) - evsel__tool_name(evsel__tool_event(evsel), bf, sizeof(bf)); - else - evsel__sw_name(evsel, bf, sizeof(bf)); + evsel__sw_name(evsel, bf, sizeof(bf)); break; =20 case PERF_TYPE_TRACEPOINT: @@ -783,6 +747,10 @@ const char *evsel__name(struct evsel *evsel) evsel__bp_name(evsel, bf, sizeof(bf)); break; =20 + case PERF_PMU_TYPE_TOOL: + scnprintf(bf, sizeof(bf), "%s", evsel__tool_pmu_event_name(evsel)); + break; + default: scnprintf(bf, sizeof(bf), "unknown attr type: %d", evsel->core.attr.type); @@ -808,7 +776,7 @@ const char *evsel__metric_id(const struct evsel *evsel) return evsel->metric_id; =20 if (evsel__is_tool(evsel)) - return perf_tool_event__to_str(evsel__tool_event(evsel)); + return evsel__tool_pmu_event_name(evsel); =20 return "unknown"; } @@ -1680,167 +1648,6 @@ static int evsel__read_group(struct evsel *leader, = int cpu_map_idx, int thread) return evsel__process_group_data(leader, cpu_map_idx, thread, data); } =20 -static bool read_until_char(struct io *io, char e) -{ - int c; - - do { - c =3D io__get_char(io); - if (c =3D=3D -1) - return false; - } while (c !=3D e); - return true; -} - -static int read_stat_field(int fd, struct perf_cpu cpu, int field, __u64 *= val) -{ - char buf[256]; - struct io io; - int i; - - io__init(&io, fd, buf, sizeof(buf)); - - /* Skip lines to relevant CPU. */ - for (i =3D -1; i < cpu.cpu; i++) { - if (!read_until_char(&io, '\n')) - return -EINVAL; - } - /* Skip to "cpu". */ - if (io__get_char(&io) !=3D 'c') return -EINVAL; - if (io__get_char(&io) !=3D 'p') return -EINVAL; - if (io__get_char(&io) !=3D 'u') return -EINVAL; - - /* Skip N of cpuN. */ - if (!read_until_char(&io, ' ')) - return -EINVAL; - - i =3D 1; - while (true) { - if (io__get_dec(&io, val) !=3D ' ') - break; - if (field =3D=3D i) - return 0; - i++; - } - return -EINVAL; -} - -static int read_pid_stat_field(int fd, int field, __u64 *val) -{ - char buf[256]; - struct io io; - int c, i; - - io__init(&io, fd, buf, sizeof(buf)); - if (io__get_dec(&io, val) !=3D ' ') - return -EINVAL; - if (field =3D=3D 1) - return 0; - - /* Skip comm. */ - if (io__get_char(&io) !=3D '(' || !read_until_char(&io, ')')) - return -EINVAL; - if (field =3D=3D 2) - return -EINVAL; /* String can't be returned. */ - - /* Skip state */ - if (io__get_char(&io) !=3D ' ' || io__get_char(&io) =3D=3D -1) - return -EINVAL; - if (field =3D=3D 3) - return -EINVAL; /* String can't be returned. */ - - /* Loop over numeric fields*/ - if (io__get_char(&io) !=3D ' ') - return -EINVAL; - - i =3D 4; - while (true) { - c =3D io__get_dec(&io, val); - if (c =3D=3D -1) - return -EINVAL; - if (c =3D=3D -2) { - /* Assume a -ve was read */ - c =3D io__get_dec(&io, val); - *val *=3D -1; - } - if (c !=3D ' ') - return -EINVAL; - if (field =3D=3D i) - return 0; - i++; - } - return -EINVAL; -} - -static int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thre= ad) -{ - __u64 *start_time, cur_time, delta_start; - int fd, err =3D 0; - struct perf_counts_values *count; - bool adjust =3D false; - - count =3D perf_counts(evsel->counts, cpu_map_idx, thread); - - switch (evsel__tool_event(evsel)) { - case PERF_TOOL_DURATION_TIME: - /* - * Pretend duration_time is only on the first CPU and thread, or - * else aggregation will scale duration_time by the number of - * CPUs/threads. - */ - start_time =3D &evsel->start_time; - if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) - cur_time =3D rdclock(); - else - cur_time =3D *start_time; - break; - case PERF_TOOL_USER_TIME: - case PERF_TOOL_SYSTEM_TIME: { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; - - start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); - fd =3D FD(evsel, cpu_map_idx, thread); - lseek(fd, SEEK_SET, 0); - if (evsel->pid_stat) { - /* The event exists solely on 1 CPU. */ - if (cpu_map_idx =3D=3D 0) - err =3D read_pid_stat_field(fd, system ? 15 : 14, &cur_time); - else - cur_time =3D 0; - } else { - /* The event is for all threads. */ - if (thread =3D=3D 0) { - struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel->core.cpus, - cpu_map_idx); - - err =3D read_stat_field(fd, cpu, system ? 3 : 1, &cur_time); - } else { - cur_time =3D 0; - } - } - adjust =3D true; - break; - } - case PERF_TOOL_NONE: - case PERF_TOOL_MAX: - default: - err =3D -EINVAL; - } - if (err) - return err; - - delta_start =3D cur_time - *start_time; - if (adjust) { - __u64 ticks_per_sec =3D sysconf(_SC_CLK_TCK); - - delta_start *=3D 1000000000 / ticks_per_sec; - } - count->val =3D delta_start; - count->ena =3D count->run =3D delta_start; - count->lost =3D 0; - return 0; -} - bool __evsel__match(const struct evsel *evsel, u32 type, u64 config) { =20 @@ -2056,6 +1863,7 @@ static struct perf_thread_map *empty_thread_map; static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map = *cpus, struct perf_thread_map *threads) { + int ret =3D 0; int nthreads =3D perf_thread_map__nr(threads); =20 if ((perf_missing_features.write_backward && evsel->core.attr.write_backw= ard) || @@ -2086,19 +1894,14 @@ static int __evsel__prepare_open(struct evsel *evse= l, struct perf_cpu_map *cpus, perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) = < 0) return -ENOMEM; =20 - if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && - !evsel->start_times) { - evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), nthreads, si= zeof(__u64)); - if (!evsel->start_times) - return -ENOMEM; - } + if (evsel__is_tool(evsel)) + ret =3D evsel__tool_pmu_prepare_open(evsel, cpus, nthreads); =20 evsel->open_flags =3D PERF_FLAG_FD_CLOEXEC; if (evsel->cgrp) evsel->open_flags |=3D PERF_FLAG_PID_CGROUP; =20 - return 0; + return ret; } =20 static void evsel__disable_missing_features(struct evsel *evsel) @@ -2276,13 +2079,6 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, int pid =3D -1, err, old_errno; enum rlimit_action set_rlimit =3D NO_CHANGE; =20 - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_DURATION_TIME) { - if (evsel->core.attr.sample_period) /* no sampling */ - return -EINVAL; - evsel->start_time =3D rdclock(); - return 0; - } - if (evsel__is_retire_lat(evsel)) return tpebs_start(evsel->evlist); =20 @@ -2307,6 +2103,12 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, pr_debug3("Opening: %s\n", evsel__name(evsel)); display_attr(&evsel->core.attr); =20 + if (evsel__is_tool(evsel)) { + return evsel__tool_pmu_open(evsel, threads, + start_cpu_map_idx, + end_cpu_map_idx); + } + for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 for (thread =3D 0; thread < nthreads; thread++) { @@ -2318,46 +2120,6 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME) { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; - __u64 *start_time =3D NULL; - - if (evsel->core.attr.sample_period) { - /* no sampling */ - err =3D -EINVAL; - goto out_close; - } - if (pid > -1) { - char buf[64]; - - snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); - fd =3D open(buf, O_RDONLY); - evsel->pid_stat =3D true; - } else { - fd =3D open("/proc/stat", O_RDONLY); - } - FD(evsel, idx, thread) =3D fd; - if (fd < 0) { - err =3D -errno; - goto out_close; - } - start_time =3D xyarray__entry(evsel->start_times, idx, thread); - if (pid > -1) { - err =3D read_pid_stat_field(fd, system ? 15 : 14, - start_time); - } else { - struct perf_cpu cpu; - - cpu =3D perf_cpu_map__cpu(evsel->core.cpus, idx); - err =3D read_stat_field(fd, cpu, system ? 3 : 1, - start_time); - } - if (err) - goto out_close; - continue; - } - group_fd =3D get_group_fd(evsel, idx, thread); =20 if (group_fd =3D=3D -2) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3e751ea769ac..cccb1ed12e4e 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -11,6 +11,7 @@ #include #include "symbol_conf.h" #include "pmus.h" +#include "pmu.h" =20 struct bpf_object; struct cgroup; @@ -22,25 +23,9 @@ struct target; struct hashmap; struct bperf_leader_bpf; struct bperf_follower_bpf; -struct perf_pmu; =20 typedef int (evsel__sb_cb_t)(union perf_event *event, void *data); =20 -enum perf_tool_event { - PERF_TOOL_NONE =3D 0, - PERF_TOOL_DURATION_TIME =3D 1, - PERF_TOOL_USER_TIME =3D 2, - PERF_TOOL_SYSTEM_TIME =3D 3, - - PERF_TOOL_MAX, -}; - -const char *perf_tool_event__to_str(enum perf_tool_event ev); -enum perf_tool_event perf_tool_event__from_str(const char *str); - -#define perf_tool_event__for_each_event(ev) \ - for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) - /** struct evsel - event selector * * @evlist - evlist this evsel is in, if it is in one. @@ -82,7 +67,6 @@ struct evsel { const char *unit; struct cgroup *cgrp; const char *metric_id; - enum perf_tool_event tool_event; /* parse modifier helper */ int exclude_GH; int sample_read; @@ -320,21 +304,11 @@ const char *evsel__name(struct evsel *evsel); bool evsel__name_is(struct evsel *evsel, const char *name); const char *evsel__metric_id(const struct evsel *evsel); =20 -static inline bool evsel__is_tool(const struct evsel *evsel) -{ - return evsel->tool_event !=3D PERF_TOOL_NONE; -} - static inline bool evsel__is_retire_lat(const struct evsel *evsel) { return evsel->retire_lat; } =20 -static inline enum perf_tool_event evsel__tool_event(const struct evsel *e= vsel) -{ - return evsel->tool_event; -} - const char *evsel__group_name(struct evsel *evsel); int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); =20 diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 9c6fa6b4f628..827bab455d5b 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -14,6 +14,7 @@ #include "pmus.h" #include "print-events.h" #include "smt.h" +#include "tool_pmu.h" #include "expr.h" #include "rblist.h" #include diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 228ae469d44a..4507ae68198b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -301,38 +301,6 @@ static int add_event(struct list_head *list, int *idx, alternate_hw_config) ? 0 : -ENOMEM; } =20 -static int add_event_tool(struct list_head *list, int *idx, - enum perf_tool_event tool_event) -{ - struct evsel *evsel; - struct perf_event_attr attr =3D { - .type =3D PERF_TYPE_SOFTWARE, - .config =3D PERF_COUNT_SW_DUMMY, - }; - struct perf_cpu_map *cpu_list =3D NULL; - - if (tool_event =3D=3D PERF_TOOL_DURATION_TIME) { - /* Duration time is gathered globally, pretend it is only on CPU0. */ - cpu_list =3D perf_cpu_map__new("0"); - } - evsel =3D __add_event(list, idx, &attr, /*init_attr=3D*/true, /*name=3D*/= NULL, - /*metric_id=3D*/NULL, /*pmu=3D*/NULL, - /*config_terms=3D*/NULL, /*auto_merge_stats=3D*/false, - cpu_list, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); - perf_cpu_map__put(cpu_list); - if (!evsel) - return -ENOMEM; - evsel->tool_event =3D tool_event; - if (tool_event =3D=3D PERF_TOOL_DURATION_TIME - || tool_event =3D=3D PERF_TOOL_USER_TIME - || tool_event =3D=3D PERF_TOOL_SYSTEM_TIME) { - free((char *)evsel->unit); - evsel->unit =3D strdup("ns"); - } - return 0; -} - /** * parse_aliases - search names for entries beginning or equalling str ign= oring * case. If mutliple entries in names match str then the l= ongest @@ -1430,13 +1398,6 @@ int parse_events_add_numeric(struct parse_events_sta= te *parse_state, type, /*extended_type=3D*/0, config, head_config); } =20 -int parse_events_add_tool(struct parse_events_state *parse_state, - struct list_head *list, - int tool_event) -{ - return add_event_tool(list, &parse_state->idx, tool_event); -} - static bool config_term_percore(struct list_head *config_terms) { struct evsel_config_term *term; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index ac1feaaeb8d5..3f4334ec6231 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -229,9 +229,6 @@ int parse_events_add_numeric(struct parse_events_state = *parse_state, u32 type, u64 config, const struct parse_events_terms *head_config, bool wildcard); -int parse_events_add_tool(struct parse_events_state *parse_state, - struct list_head *list, - int tool_event); int parse_events_add_cache(struct list_head *list, int *idx, const char *n= ame, struct parse_events_state *parse_state, struct parse_events_terms *parsed_terms); diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 5a0bcd7f166a..14e5bd856a18 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -121,14 +121,6 @@ static int sym(yyscan_t scanner, int type, int config) return type =3D=3D PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; } =20 -static int tool(yyscan_t scanner, enum perf_tool_event event) -{ - YYSTYPE *yylval =3D parse_events_get_lval(scanner); - - yylval->num =3D event; - return PE_VALUE_SYM_TOOL; -} - static int term(yyscan_t scanner, enum parse_events__term_type type) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); @@ -404,9 +396,6 @@ cpu-migrations|migrations { return sym(yyscanner, PER= F_TYPE_SOFTWARE, PERF_COU alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_ALIGNMENT_FAULTS); } emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_EMULATION_FAULTS); } dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY= ); } -duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } -user_time { return tool(yyscanner, PERF_TOOL_USER_TIME); } -system_time { return tool(yyscanner, PERF_TOOL_SYSTEM_TIME); } bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_B= PF_OUTPUT); } cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_CGROUP_SWITCHES); } =20 diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index dcf47fabdfdd..f888cbb076d6 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -56,7 +56,6 @@ static void free_list_evsel(struct list_head* list_evsel) =20 %token PE_START_EVENTS PE_START_TERMS %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM -%token PE_VALUE_SYM_TOOL %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -68,7 +67,6 @@ static void free_list_evsel(struct list_head* list_evsel) %type PE_VALUE %type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW -%type PE_VALUE_SYM_TOOL %type PE_MODIFIER_EVENT %type PE_TERM %type value_sym @@ -350,20 +348,6 @@ value_sym sep_slash_slash_dc PE_ABORT(err); $$ =3D list; } -| -PE_VALUE_SYM_TOOL sep_slash_slash_dc -{ - struct list_head *list; - int err; - - list =3D alloc_list(); - if (!list) - YYNOMEM; - err =3D parse_events_add_tool(_parse_state, list, $1); - if (err) - YYNOMEM; - $$ =3D list; -} =20 event_legacy_cache: PE_LEGACY_CACHE opt_event_config diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index a1c7e879cb2f..762942853351 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -19,6 +19,7 @@ #include "evsel.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" #include #include #include "parse-events.h" @@ -1548,6 +1549,9 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, { bool zero =3D !!pmu->perf_event_attr_init_default; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__config_terms(attr, head_terms, err); + /* Fake PMU doesn't have proper terms so nothing to configure in attr. */ if (perf_pmu__is_fake(pmu)) return 0; @@ -1660,8 +1664,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->scale =3D 0.0; info->snapshot =3D false; =20 - /* Fake PMU doesn't rewrite terms. */ - if (perf_pmu__is_fake(pmu)) + /* Tool/fake PMU doesn't rewrite terms. */ + if (perf_pmu__is_tool(pmu) || perf_pmu__is_fake(pmu)) goto out; =20 list_for_each_entry_safe(term, h, &head_terms->terms, list) { @@ -1831,6 +1835,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) { if (!name) return false; + if (perf_pmu__is_tool(pmu)) + return perf_tool_event__from_str(name) !=3D PERF_TOOL_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -1842,6 +1848,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__num_events(); + pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases; =20 @@ -1902,6 +1911,9 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, int ret =3D 0; struct strbuf sb; =20 + if (perf_pmu__is_tool(pmu)) + return tool_pmu__for_each_event_cb(pmu, state, cb); + strbuf_init(&sb, /*hint=3D*/ 0); pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); @@ -1990,6 +2002,7 @@ bool perf_pmu__is_software(const struct perf_pmu *pmu) case PERF_TYPE_HW_CACHE: return false; case PERF_TYPE_RAW: return false; case PERF_TYPE_BREAKPOINT: return true; + case PERF_PMU_TYPE_TOOL: return true; default: break; } for (size_t i =3D 0; i < ARRAY_SIZE(known_sw_pmus); i++) { @@ -2317,6 +2330,9 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) if (!pmu) return NULL; =20 + if (perf_pmu__is_tool(pmu)) + return perf_tool_event__to_str(config); + pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index c70317d3fb04..36fced2bf065 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -37,6 +37,7 @@ struct perf_pmu_caps { }; =20 enum { + PERF_PMU_TYPE_TOOL =3D 0xFFFFFFFE, PERF_PMU_TYPE_FAKE =3D 0xFFFFFFFF, }; =20 @@ -282,6 +283,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmu= s, int dirfd, const char struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *c= ore_pmus); void perf_pmu__delete(struct perf_pmu *pmu); struct perf_pmu *perf_pmus__find_core_pmu(void); + const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config); bool perf_pmu__is_fake(const struct perf_pmu *pmu); =20 diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 52109af5f2f1..6e657c44de58 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -15,6 +15,7 @@ #include "evsel.h" #include "pmus.h" #include "pmu.h" +#include "tool_pmu.h" #include "print-events.h" #include "strbuf.h" =20 @@ -200,6 +201,7 @@ static void pmu_read_sysfs(bool core_only) int fd; DIR *dir; struct dirent *dent; + struct perf_pmu *tool_pmu; =20 if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) return; @@ -229,6 +231,10 @@ static void pmu_read_sysfs(bool core_only) pr_err("Failure to set up any core PMUs\n"); } list_sort(NULL, &core_pmus, pmus_cmp); + if (!core_only) { + tool_pmu =3D perf_pmus__tool_pmu(); + list_add_tail(&tool_pmu->list, &other_pmus); + } list_sort(NULL, &other_pmus, pmus_cmp); if (!list_empty(&core_pmus)) { read_sysfs_core_pmus =3D true; @@ -584,6 +590,9 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi int len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 + if (perf_pmu__is_tool(pmu)) + continue; + if (!pmu->is_core) desc =3D NULL; =20 diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 81e0135cddf0..a786cbfb0ff5 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -29,6 +29,7 @@ #include "tracepoint.h" #include "pfm.h" #include "thread_map.h" +#include "tool_pmu.h" #include "util.h" =20 #define MAX_NAME_LEN 100 @@ -43,21 +44,6 @@ static const char * const event_type_descriptors[] =3D { "Hardware breakpoint", }; =20 -static const struct event_symbol event_symbols_tool[PERF_TOOL_MAX] =3D { - [PERF_TOOL_DURATION_TIME] =3D { - .symbol =3D "duration_time", - .alias =3D "", - }, - [PERF_TOOL_USER_TIME] =3D { - .symbol =3D "user_time", - .alias =3D "", - }, - [PERF_TOOL_SYSTEM_TIME] =3D { - .symbol =3D "system_time", - .alias =3D "", - }, -}; - /* * Print the events from /tracing/events */ @@ -341,24 +327,6 @@ int print_hwcache_events(const struct print_callbacks = *print_cb, void *print_sta return 0; } =20 -void print_tool_events(const struct print_callbacks *print_cb, void *print= _state) -{ - // Start at 1 because the first enum entry means no tool event. - for (int i =3D 1; i < PERF_TOOL_MAX; ++i) { - print_cb->print_event(print_state, - "tool", - /*pmu_name=3D*/NULL, - event_symbols_tool[i].symbol, - event_symbols_tool[i].alias, - /*scale_unit=3D*/NULL, - /*deprecated=3D*/false, - "Tool event", - /*desc=3D*/NULL, - /*long_desc=3D*/NULL, - /*encoding_desc=3D*/NULL); - } -} - void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max) @@ -422,8 +390,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX); =20 - print_tool_events(print_cb, print_state); - print_hwcache_events(print_cb, print_state); =20 perf_pmus__print_pmu_events(print_cb, print_state); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index bf4290bef0cd..445efa1636c1 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -36,7 +36,6 @@ void print_sdt_events(const struct print_callbacks *print= _cb, void *print_state) void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max); -void print_tool_events(const struct print_callbacks *print_cb, void *print= _state); void print_tracepoint_events(const struct print_callbacks *print_cb, void = *print_state); bool is_event_supported(u8 type, u64 config); =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 5402998881c4..ca8527067869 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -22,6 +22,7 @@ #include "iostat.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -982,7 +983,10 @@ static bool should_skip_zero_counter(struct perf_stat_= config *config, if (config->aggr_mode =3D=3D AGGR_THREAD && config->system_wide) return true; =20 - /* Tool events have the software PMU but are only gathered on 1. */ + /* + * Many tool events are only gathered on the first index, skip other + * zero values. + */ if (evsel__is_tool(counter)) return true; =20 diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 3ce756b8ede5..50f347217d84 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -15,6 +15,7 @@ #include #include "iostat.h" #include "util/hashmap.h" +#include "tool_pmu.h" =20 struct stats walltime_nsecs_stats; struct rusage_stats ru_stats; diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c new file mode 100644 index 000000000000..f41fed39d70d --- /dev/null +++ b/tools/perf/util/tool_pmu.c @@ -0,0 +1,411 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include "cgroup.h" +#include "counts.h" +#include "evsel.h" +#include "pmu.h" +#include "print-events.h" +#include "time-utils.h" +#include "tool_pmu.h" +#include +#include +#include +#include +#include + +static const char *const tool_pmu__event_names[PERF_TOOL_MAX] =3D { + NULL, + "duration_time", + "user_time", + "system_time", +}; + + +const char *perf_tool_event__to_str(enum perf_tool_event ev) +{ + if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + return tool_pmu__event_names[ev]; + + return NULL; +} + +enum perf_tool_event perf_tool_event__from_str(const char *str) +{ + int i; + + perf_tool_event__for_each_event(i) { + if (!strcasecmp(str, tool_pmu__event_names[i])) + return i; + } + return PERF_TOOL_NONE; +} + +static int tool_pmu__config_term(struct perf_event_attr *attr, + struct parse_events_term *term, + struct parse_events_error *err) +{ + if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { + enum perf_tool_event ev =3D perf_tool_event__from_str(term->config); + + if (ev =3D=3D PERF_TOOL_NONE) + goto err_out; + + attr->config =3D ev; + return 0; + } +err_out: + if (err) { + char *err_str; + + parse_events_error__handle(err, term->err_val, + asprintf(&err_str, + "unexpected tool event term (%s) %s", + parse_events__term_type_str(term->type_term), + term->config) < 0 + ? strdup("unexpected tool event term") + : err_str, + NULL); + } + return -EINVAL; +} + +int tool_pmu__config_terms(struct perf_event_attr *attr, + struct parse_events_terms *terms, + struct parse_events_error *err) +{ + struct parse_events_term *term; + + list_for_each_entry(term, &terms->terms, list) { + if (tool_pmu__config_term(attr, term, err)) + return -EINVAL; + } + + return 0; + +} + +int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb) +{ + struct pmu_event_info info =3D { + .pmu =3D pmu, + .event_type_desc =3D "Tool event", + }; + int i; + + perf_tool_event__for_each_event(i) { + int ret; + + info.name =3D perf_tool_event__to_str(i); + info.alias =3D NULL; + info.scale_unit =3D NULL; + info.desc =3D NULL; + info.long_desc =3D NULL; + info.encoding_desc =3D NULL; + info.topic =3D NULL; + info.pmu_name =3D pmu->name; + info.deprecated =3D false; + ret =3D cb(state, &info); + if (ret) + return ret; + } + return 0; +} + +bool perf_pmu__is_tool(const struct perf_pmu *pmu) +{ + return pmu && pmu->type =3D=3D PERF_PMU_TYPE_TOOL; +} + +bool evsel__is_tool(const struct evsel *evsel) +{ + return perf_pmu__is_tool(evsel->pmu); +} + +enum perf_tool_event evsel__tool_event(const struct evsel *evsel) +{ + if (!evsel__is_tool(evsel)) + return PERF_TOOL_NONE; + + return (enum perf_tool_event)evsel->core.attr.config; +} + +const char *evsel__tool_pmu_event_name(const struct evsel *evsel) +{ + return perf_tool_event__to_str(evsel->core.attr.config); +} + +static bool read_until_char(struct io *io, char e) +{ + int c; + + do { + c =3D io__get_char(io); + if (c =3D=3D -1) + return false; + } while (c !=3D e); + return true; +} + +static int read_stat_field(int fd, struct perf_cpu cpu, int field, __u64 *= val) +{ + char buf[256]; + struct io io; + int i; + + io__init(&io, fd, buf, sizeof(buf)); + + /* Skip lines to relevant CPU. */ + for (i =3D -1; i < cpu.cpu; i++) { + if (!read_until_char(&io, '\n')) + return -EINVAL; + } + /* Skip to "cpu". */ + if (io__get_char(&io) !=3D 'c') return -EINVAL; + if (io__get_char(&io) !=3D 'p') return -EINVAL; + if (io__get_char(&io) !=3D 'u') return -EINVAL; + + /* Skip N of cpuN. */ + if (!read_until_char(&io, ' ')) + return -EINVAL; + + i =3D 1; + while (true) { + if (io__get_dec(&io, val) !=3D ' ') + break; + if (field =3D=3D i) + return 0; + i++; + } + return -EINVAL; +} + +static int read_pid_stat_field(int fd, int field, __u64 *val) +{ + char buf[256]; + struct io io; + int c, i; + + io__init(&io, fd, buf, sizeof(buf)); + if (io__get_dec(&io, val) !=3D ' ') + return -EINVAL; + if (field =3D=3D 1) + return 0; + + /* Skip comm. */ + if (io__get_char(&io) !=3D '(' || !read_until_char(&io, ')')) + return -EINVAL; + if (field =3D=3D 2) + return -EINVAL; /* String can't be returned. */ + + /* Skip state */ + if (io__get_char(&io) !=3D ' ' || io__get_char(&io) =3D=3D -1) + return -EINVAL; + if (field =3D=3D 3) + return -EINVAL; /* String can't be returned. */ + + /* Loop over numeric fields*/ + if (io__get_char(&io) !=3D ' ') + return -EINVAL; + + i =3D 4; + while (true) { + c =3D io__get_dec(&io, val); + if (c =3D=3D -1) + return -EINVAL; + if (c =3D=3D -2) { + /* Assume a -ve was read */ + c =3D io__get_dec(&io, val); + *val *=3D -1; + } + if (c !=3D ' ') + return -EINVAL; + if (field =3D=3D i) + return 0; + i++; + } + return -EINVAL; +} + +int evsel__tool_pmu_prepare_open(struct evsel *evsel, + struct perf_cpu_map *cpus, + int nthreads) +{ + if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && + !evsel->start_times) { + evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), + nthreads, + sizeof(__u64)); + if (!evsel->start_times) + return -ENOMEM; + } + return 0; +} + +#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y)) + +int evsel__tool_pmu_open(struct evsel *evsel, + struct perf_thread_map *threads, + int start_cpu_map_idx, int end_cpu_map_idx) +{ + enum perf_tool_event ev =3D evsel__tool_event(evsel); + int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; + + if (ev =3D=3D PERF_TOOL_DURATION_TIME) { + if (evsel->core.attr.sample_period) /* no sampling */ + return -EINVAL; + evsel->start_time =3D rdclock(); + return 0; + } + + if (evsel->cgrp) + pid =3D evsel->cgrp->fd; + + nthreads =3D perf_thread_map__nr(threads); + for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { + for (thread =3D 0; thread < nthreads; thread++) { + if (thread >=3D nthreads) + break; + + if (!evsel->cgrp && !evsel->core.system_wide) + pid =3D perf_thread_map__pid(threads, thread); + + if (ev =3D=3D PERF_TOOL_USER_TIME || ev =3D=3D PERF_TOOL_SYSTEM_TIME) { + bool system =3D ev =3D=3D PERF_TOOL_SYSTEM_TIME; + __u64 *start_time =3D NULL; + int fd; + + if (evsel->core.attr.sample_period) { + /* no sampling */ + err =3D -EINVAL; + goto out_close; + } + if (pid > -1) { + char buf[64]; + + snprintf(buf, sizeof(buf), "/proc/%d/stat", pid); + fd =3D open(buf, O_RDONLY); + evsel->pid_stat =3D true; + } else { + fd =3D open("/proc/stat", O_RDONLY); + } + FD(evsel, idx, thread) =3D fd; + if (fd < 0) { + err =3D -errno; + goto out_close; + } + start_time =3D xyarray__entry(evsel->start_times, idx, thread); + if (pid > -1) { + err =3D read_pid_stat_field(fd, system ? 15 : 14, + start_time); + } else { + struct perf_cpu cpu; + + cpu =3D perf_cpu_map__cpu(evsel->core.cpus, idx); + err =3D read_stat_field(fd, cpu, system ? 3 : 1, + start_time); + } + if (err) + goto out_close; + } + + } + } + return 0; +out_close: + if (err) + threads->err_thread =3D thread; + + old_errno =3D errno; + do { + while (--thread >=3D 0) { + if (FD(evsel, idx, thread) >=3D 0) + close(FD(evsel, idx, thread)); + FD(evsel, idx, thread) =3D -1; + } + thread =3D nthreads; + } while (--idx >=3D 0); + errno =3D old_errno; + return err; +} + +int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread) +{ + __u64 *start_time, cur_time, delta_start; + int fd, err =3D 0; + struct perf_counts_values *count; + bool adjust =3D false; + + count =3D perf_counts(evsel->counts, cpu_map_idx, thread); + + switch (evsel__tool_event(evsel)) { + case PERF_TOOL_DURATION_TIME: + /* + * Pretend duration_time is only on the first CPU and thread, or + * else aggregation will scale duration_time by the number of + * CPUs/threads. + */ + start_time =3D &evsel->start_time; + if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) + cur_time =3D rdclock(); + else + cur_time =3D *start_time; + break; + case PERF_TOOL_USER_TIME: + case PERF_TOOL_SYSTEM_TIME: { + bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; + + start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); + fd =3D FD(evsel, cpu_map_idx, thread); + lseek(fd, SEEK_SET, 0); + if (evsel->pid_stat) { + /* The event exists solely on 1 CPU. */ + if (cpu_map_idx =3D=3D 0) + err =3D read_pid_stat_field(fd, system ? 15 : 14, &cur_time); + else + cur_time =3D 0; + } else { + /* The event is for all threads. */ + if (thread =3D=3D 0) { + struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel->core.cpus, + cpu_map_idx); + + err =3D read_stat_field(fd, cpu, system ? 3 : 1, &cur_time); + } else { + cur_time =3D 0; + } + } + adjust =3D true; + break; + } + case PERF_TOOL_NONE: + case PERF_TOOL_MAX: + default: + err =3D -EINVAL; + } + if (err) + return err; + + delta_start =3D cur_time - *start_time; + if (adjust) { + __u64 ticks_per_sec =3D sysconf(_SC_CLK_TCK); + + delta_start *=3D 1000000000 / ticks_per_sec; + } + count->val =3D delta_start; + count->ena =3D count->run =3D delta_start; + count->lost =3D 0; + return 0; +} + +struct perf_pmu *perf_pmus__tool_pmu(void) +{ + static struct perf_pmu tool =3D { + .name =3D "tool", + .type =3D PERF_PMU_TYPE_TOOL, + .aliases =3D LIST_HEAD_INIT(tool.aliases), + .caps =3D LIST_HEAD_INIT(tool.caps), + .format =3D LIST_HEAD_INIT(tool.format), + }; + + return &tool; +} diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h new file mode 100644 index 000000000000..05a4052c8b9d --- /dev/null +++ b/tools/perf/util/tool_pmu.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __TOOL_PMU_H +#define __TOOL_PMU_H + +#include "pmu.h" + +struct evsel; +struct perf_thread_map; +struct print_callbacks; + +enum perf_tool_event { + PERF_TOOL_NONE =3D 0, + PERF_TOOL_DURATION_TIME =3D 1, + PERF_TOOL_USER_TIME =3D 2, + PERF_TOOL_SYSTEM_TIME =3D 3, + + PERF_TOOL_MAX, +}; + +#define perf_tool_event__for_each_event(ev) \ + for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + +static inline size_t tool_pmu__num_events(void) +{ + return PERF_TOOL_MAX - 1; +} + +const char *perf_tool_event__to_str(enum perf_tool_event ev); +enum perf_tool_event perf_tool_event__from_str(const char *str); +int tool_pmu__config_terms(struct perf_event_attr *attr, + struct parse_events_terms *terms, + struct parse_events_error *err); +int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); + +bool perf_pmu__is_tool(const struct perf_pmu *pmu); + + +bool evsel__is_tool(const struct evsel *evsel); +enum perf_tool_event evsel__tool_event(const struct evsel *evsel); +const char *evsel__tool_pmu_event_name(const struct evsel *evsel); +int evsel__tool_pmu_prepare_open(struct evsel *evsel, + struct perf_cpu_map *cpus, + int nthreads); +int evsel__tool_pmu_open(struct evsel *evsel, + struct perf_thread_map *threads, + int start_cpu_map_idx, int end_cpu_map_idx); +int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread); + +struct perf_pmu *perf_pmus__tool_pmu(void); + +#endif /* __TOOL_PMU_H */ --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12ED339FD6 for ; Wed, 2 Oct 2024 03:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839237; cv=none; b=OQxJ0KNx1HAhZx7vsKAxSQVzVy80GT+uuwlggYG4J9rqAd69ERMw3/ZUXuPTBrqpDfnCZksJHpeDrlFPD94aeqCy/6YhO048cvKWWFIX74VrHTIss2p0BDo7htov2IBmzNwYZaQIS+TG6CBhBN62n12fvcyR7QpSy9zt4WryOMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839237; c=relaxed/simple; bh=As9d1gYtVYK0KHsjI99H0jFT/UICzWYqeggFKzU2MN0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dg3bP0eUYOHu3uyEYBzoht74frqeTrQ4pBU8LPb60b1EAhpmZa/gomijsBRqDjQLaVq4aBxFNxCgbrVljVlRIlAka+t/Jdn6nVS6WIjtYFZFyHqX4W6YDWkHW8HcF/YwJ6QkkMpUwHof/D7vY3AnYtf7Ww1KlJSEQ9yjVvtuT2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WUpN43rJ; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WUpN43rJ" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e25cfee6581so10037907276.2 for ; Tue, 01 Oct 2024 20:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839234; x=1728444034; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=o7cQZp65V853hQXjAoHCXSEhby/HXKQXUpWvfk2FmYo=; b=WUpN43rJysErC4ftH7whrDi1zsQg74mJ3vktOU8q5VzQgT8fusV7vfsNnhaWvw4l32 iBOKGDed21c/inifvG4ONfGTl7+kxFW9HqKjVnwsRpkNQYTWj9tr8VVkBNcbdQ53LXyH 3Sfmvhxra7G7urxaqiBj/Et4Ts+NoHEJyol5IMum5Jw5g+G7rz6Tk5X8y8OjCvQvhDb6 DtZPFkOPdwG0s+GnMtRlMki1FMX4BhIOPpiUoLoyD3MUcGDoiXklWHoNSLRy6wiP8dOj YTDRARfx0do4FfeDPABepWibguOO/FQCY9vP1mava5q/6uOKSrO3kRDP4Vsuy9dlw1C4 gS8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839234; x=1728444034; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o7cQZp65V853hQXjAoHCXSEhby/HXKQXUpWvfk2FmYo=; b=q3EXOYUwL+rtvzchC2GC8+va4y8u/ajWsFRLa8gwfngy/+DPKAKkN6E9D+AR2wwV5H UdN0+62sL4pB3AZq3lXkPJgwfLg6eSYhYfXZOsa/meqiwfab1knpZSxZlhUYPK4ODpi1 BOBYa5PIpmpKiPf7dp/VzwlJYXTwQp7vsUp6aOGZuT82y3P8xEeRx2Ns4zgP99HpySbx 33uXyiTTflFZrYzPnr3TE7A2rfjThO5XpvSbRkp+fOw2aTe8YU68Mu62ExNGxYnqLCNp SRHz+X0Rlis75uez6sw4VflBayWzWNaZjZvnq8KkqvQU9v+OgHRfhuClhi+87HTqe5mC Yazg== X-Forwarded-Encrypted: i=1; AJvYcCVh2GpQpnVSmh2ND2WerUJQ0IUg08TK2e0llBXIx2zLXetQJtsz2EEe9zTPxmm1Xcn8I/04S2t5LULBtnQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxdMFzpVhHjVvpWRw6KOgS1Pq6BPLF2/SZL0Gg4tg/E3aGjJD3o FfrUHv3q+pQoSex90Qlor858hGvk+mOxkRgcn4qqsJ0PD1JVGTVufWBpAxBRehcJg76JisrR7cW o+yKSaA== X-Google-Smtp-Source: AGHT+IGecXdtH6W5QjhxOfcD/jgYNDa1MZe1gFxoPHtcYIWikIlhn8rBPbKeqaTrf3aG4g2Ugi2dm1OzfVGD X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a5b:bd0:0:b0:e25:7027:fa79 with SMTP id 3f1490d57ef6-e263842fb72mr1218276.8.1727839234013; Tue, 01 Oct 2024 20:20:34 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:08 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 05/13] perf tool_pmu: Rename enum perf_tool_event to tool_pmu_event From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To better reflect the events listed are from the tool PMU. Rename the enum values from PERF_TOOL_* to TOOL_PMU__EVENT_*. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/builtin-stat.c | 6 ++--- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/metricgroup.c | 12 +++++----- tools/perf/util/pmu.c | 2 +- tools/perf/util/stat-shadow.c | 10 ++++---- tools/perf/util/tool_pmu.c | 44 +++++++++++++++++------------------ tools/perf/util/tool_pmu.h | 22 +++++++++--------- 7 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ff4214900ae0..52beed515c51 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -295,14 +295,14 @@ static int read_single_counter(struct evsel *counter,= int cpu_map_idx, int threa * terminates. Use the wait4 values in that case. */ if (err && cpu_map_idx =3D=3D 0 && - (evsel__tool_event(counter) =3D=3D PERF_TOOL_USER_TIME || - evsel__tool_event(counter) =3D=3D PERF_TOOL_SYSTEM_TIME)) { + (evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_USER_TIME || + evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME)) { u64 val, *start_time; struct perf_counts_values *count =3D perf_counts(counter->counts, cpu_map_idx, thread); =20 start_time =3D xyarray__entry(counter->start_times, cpu_map_idx, thread); - if (evsel__tool_event(counter) =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(counter) =3D=3D TOOL_PMU__EVENT_USER_TIME) val =3D ru_stats.ru_utime_usec_stat.mean; else val =3D ru_stats.ru_stime_usec_stat.mean; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 3d5d974a0429..59b2d38c9a65 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1467,8 +1467,8 @@ void evsel__exit(struct evsel *evsel) evsel->per_pkg_mask =3D NULL; zfree(&evsel->metric_events); perf_evsel__object.fini(evsel); - if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_USER_TIME) xyarray__delete(evsel->start_times); } =20 diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 827bab455d5b..1250bf5050b0 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -674,20 +674,20 @@ static int metricgroup__build_event_string(struct str= buf *events, struct hashmap_entry *cur; size_t bkt; bool no_group =3D true, has_tool_events =3D false; - bool tool_events[PERF_TOOL_MAX] =3D {false}; + bool tool_events[TOOL_PMU__EVENT_MAX] =3D {false}; int ret =3D 0; =20 #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) =20 hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *sep, *rsep, *id =3D cur->pkey; - enum perf_tool_event ev; + enum tool_pmu_event ev; =20 pr_debug("found event %s\n", id); =20 /* Always move tool events outside of the group. */ ev =3D perf_tool_event__from_str(id); - if (ev !=3D PERF_TOOL_NONE) { + if (ev !=3D TOOL_PMU__EVENT_NONE) { has_tool_events =3D true; tool_events[ev] =3D true; continue; @@ -1375,7 +1375,7 @@ static void metricgroup__free_metrics(struct list_hea= d *metric_list) * to true if tool event is found. */ static void find_tool_events(const struct list_head *metric_list, - bool tool_events[PERF_TOOL_MAX]) + bool tool_events[TOOL_PMU__EVENT_MAX]) { struct metric *m; =20 @@ -1447,7 +1447,7 @@ static int build_combined_expr_ctx(const struct list_= head *metric_list, */ static int parse_ids(bool metric_no_merge, bool fake_pmu, struct expr_parse_ctx *ids, const char *modifier, - bool group_events, const bool tool_events[PERF_TOOL_MAX], + bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], struct evlist **out_evlist) { struct parse_events_error parse_error; @@ -1536,7 +1536,7 @@ static int parse_groups(struct evlist *perf_evlist, struct evlist *combined_evlist =3D NULL; LIST_HEAD(metric_list); struct metric *m; - bool tool_events[PERF_TOOL_MAX] =3D {false}; + bool tool_events[TOOL_PMU__EVENT_MAX] =3D {false}; bool is_default =3D !strcmp(str, "Default"); int ret; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 762942853351..77e848ac5841 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1836,7 +1836,7 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) if (!name) return false; if (perf_pmu__is_tool(pmu)) - return perf_tool_event__from_str(name) !=3D PERF_TOOL_NONE; + return perf_tool_event__from_str(name) !=3D TOOL_PMU__EVENT_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 50f347217d84..b54afb56e3d6 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -382,22 +382,22 @@ static int prepare_metric(const struct metric_expr *m= exp, double scale; =20 switch (evsel__tool_event(metric_events[i])) { - case PERF_TOOL_DURATION_TIME: + case TOOL_PMU__EVENT_DURATION_TIME: stats =3D &walltime_nsecs_stats; scale =3D 1e-9; break; - case PERF_TOOL_USER_TIME: + case TOOL_PMU__EVENT_USER_TIME: stats =3D &ru_stats.ru_utime_usec_stat; scale =3D 1e-6; break; - case PERF_TOOL_SYSTEM_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: stats =3D &ru_stats.ru_stime_usec_stat; scale =3D 1e-6; break; - case PERF_TOOL_NONE: + case TOOL_PMU__EVENT_NONE: pr_err("Invalid tool event 'none'"); abort(); - case PERF_TOOL_MAX: + case TOOL_PMU__EVENT_MAX: pr_err("Invalid tool event 'max'"); abort(); default: diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index f41fed39d70d..ae0ca023f5ed 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -12,7 +12,7 @@ #include #include =20 -static const char *const tool_pmu__event_names[PERF_TOOL_MAX] =3D { +static const char *const tool_pmu__event_names[TOOL_PMU__EVENT_MAX] =3D { NULL, "duration_time", "user_time", @@ -20,15 +20,15 @@ static const char *const tool_pmu__event_names[PERF_TOO= L_MAX] =3D { }; =20 =20 -const char *perf_tool_event__to_str(enum perf_tool_event ev) +const char *perf_tool_event__to_str(enum tool_pmu_event ev) { - if (ev > PERF_TOOL_NONE && ev < PERF_TOOL_MAX) + if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) return tool_pmu__event_names[ev]; =20 return NULL; } =20 -enum perf_tool_event perf_tool_event__from_str(const char *str) +enum tool_pmu_event perf_tool_event__from_str(const char *str) { int i; =20 @@ -36,7 +36,7 @@ enum perf_tool_event perf_tool_event__from_str(const char= *str) if (!strcasecmp(str, tool_pmu__event_names[i])) return i; } - return PERF_TOOL_NONE; + return TOOL_PMU__EVENT_NONE; } =20 static int tool_pmu__config_term(struct perf_event_attr *attr, @@ -44,9 +44,9 @@ static int tool_pmu__config_term(struct perf_event_attr *= attr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum perf_tool_event ev =3D perf_tool_event__from_str(term->config); + enum tool_pmu_event ev =3D perf_tool_event__from_str(term->config); =20 - if (ev =3D=3D PERF_TOOL_NONE) + if (ev =3D=3D TOOL_PMU__EVENT_NONE) goto err_out; =20 attr->config =3D ev; @@ -120,12 +120,12 @@ bool evsel__is_tool(const struct evsel *evsel) return perf_pmu__is_tool(evsel->pmu); } =20 -enum perf_tool_event evsel__tool_event(const struct evsel *evsel) +enum tool_pmu_event evsel__tool_event(const struct evsel *evsel) { if (!evsel__is_tool(evsel)) - return PERF_TOOL_NONE; + return TOOL_PMU__EVENT_NONE; =20 - return (enum perf_tool_event)evsel->core.attr.config; + return (enum tool_pmu_event)evsel->core.attr.config; } =20 const char *evsel__tool_pmu_event_name(const struct evsel *evsel) @@ -229,8 +229,8 @@ int evsel__tool_pmu_prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, int nthreads) { - if ((evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) && + if ((evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_USER_TIME) && !evsel->start_times) { evsel->start_times =3D xyarray__new(perf_cpu_map__nr(cpus), nthreads, @@ -247,10 +247,10 @@ int evsel__tool_pmu_open(struct evsel *evsel, struct perf_thread_map *threads, int start_cpu_map_idx, int end_cpu_map_idx) { - enum perf_tool_event ev =3D evsel__tool_event(evsel); + enum tool_pmu_event ev =3D evsel__tool_event(evsel); int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; =20 - if (ev =3D=3D PERF_TOOL_DURATION_TIME) { + if (ev =3D=3D TOOL_PMU__EVENT_DURATION_TIME) { if (evsel->core.attr.sample_period) /* no sampling */ return -EINVAL; evsel->start_time =3D rdclock(); @@ -269,8 +269,8 @@ int evsel__tool_pmu_open(struct evsel *evsel, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - if (ev =3D=3D PERF_TOOL_USER_TIME || ev =3D=3D PERF_TOOL_SYSTEM_TIME) { - bool system =3D ev =3D=3D PERF_TOOL_SYSTEM_TIME; + if (ev =3D=3D TOOL_PMU__EVENT_USER_TIME || ev =3D=3D TOOL_PMU__EVENT_SY= STEM_TIME) { + bool system =3D ev =3D=3D TOOL_PMU__EVENT_SYSTEM_TIME; __u64 *start_time =3D NULL; int fd; =20 @@ -338,7 +338,7 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 switch (evsel__tool_event(evsel)) { - case PERF_TOOL_DURATION_TIME: + case TOOL_PMU__EVENT_DURATION_TIME: /* * Pretend duration_time is only on the first CPU and thread, or * else aggregation will scale duration_time by the number of @@ -350,9 +350,9 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) else cur_time =3D *start_time; break; - case PERF_TOOL_USER_TIME: - case PERF_TOOL_SYSTEM_TIME: { - bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; + case TOOL_PMU__EVENT_USER_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: { + bool system =3D evsel__tool_event(evsel) =3D=3D TOOL_PMU__EVENT_SYSTEM_T= IME; =20 start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); fd =3D FD(evsel, cpu_map_idx, thread); @@ -377,8 +377,8 @@ int evsel__read_tool(struct evsel *evsel, int cpu_map_i= dx, int thread) adjust =3D true; break; } - case PERF_TOOL_NONE: - case PERF_TOOL_MAX: + case TOOL_PMU__EVENT_NONE: + case TOOL_PMU__EVENT_MAX: default: err =3D -EINVAL; } diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index 05a4052c8b9d..b27a26133927 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -8,25 +8,25 @@ struct evsel; struct perf_thread_map; struct print_callbacks; =20 -enum perf_tool_event { - PERF_TOOL_NONE =3D 0, - PERF_TOOL_DURATION_TIME =3D 1, - PERF_TOOL_USER_TIME =3D 2, - PERF_TOOL_SYSTEM_TIME =3D 3, +enum tool_pmu_event { + TOOL_PMU__EVENT_NONE =3D 0, + TOOL_PMU__EVENT_DURATION_TIME =3D 1, + TOOL_PMU__EVENT_USER_TIME =3D 2, + TOOL_PMU__EVENT_SYSTEM_TIME =3D 3, =20 - PERF_TOOL_MAX, + TOOL_PMU__EVENT_MAX, }; =20 #define perf_tool_event__for_each_event(ev) \ - for ((ev) =3D PERF_TOOL_DURATION_TIME; (ev) < PERF_TOOL_MAX; ev++) + for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 static inline size_t tool_pmu__num_events(void) { - return PERF_TOOL_MAX - 1; + return TOOL_PMU__EVENT_MAX - 1; } =20 -const char *perf_tool_event__to_str(enum perf_tool_event ev); -enum perf_tool_event perf_tool_event__from_str(const char *str); +const char *perf_tool_event__to_str(enum tool_pmu_event ev); +enum tool_pmu_event perf_tool_event__from_str(const char *str); int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); @@ -36,7 +36,7 @@ bool perf_pmu__is_tool(const struct perf_pmu *pmu); =20 =20 bool evsel__is_tool(const struct evsel *evsel); -enum perf_tool_event evsel__tool_event(const struct evsel *evsel); +enum tool_pmu_event evsel__tool_event(const struct evsel *evsel); const char *evsel__tool_pmu_event_name(const struct evsel *evsel); int evsel__tool_pmu_prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A45839FC5 for ; Wed, 2 Oct 2024 03:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839239; cv=none; b=suoxIZB2ZjBHXlQGGBDda9Pc8MumNVEvllW3OVERsSRuTtTyuWT9jYCwkJE0KALLUyjJxLRDT48zo4szI7xInE1i2AGLB2QENsDXUuqDdYiTV0+Tq8r7G7QvXO9V2gcaG4sD/NINYFc3HJUBN4MdfB2VImsXuYfTl8vkUeKyAPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839239; c=relaxed/simple; bh=0g1nRVYc2P1gyjRrCJd52ixWbdM+SC58Z1dsoHnQioM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=R8sz+DgYLpsRiA7slhpvpyFIdEpGOI40oloilJhurqSfFNXyGAmaLIGuY1q9UauSVgNVMouE8AvZkL4mXh5b1Baosu2FyaIfD5m4uBbaDNhJroD79PhY9E6XPbJ/g1WP7oueMp6I+04D8YohOy2ec1055C8ycr47xTmOjC0UP6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZOjGWkWY; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZOjGWkWY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d7124939beso100487227b3.2 for ; Tue, 01 Oct 2024 20:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839236; x=1728444036; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=bF65nLXk1UolurWKQzuL9+6VFLZl4ud9B1SFXRw/LFg=; b=ZOjGWkWYUvP1dsfLeKbLLFIB1FgvN5BPvCKwzpqHQ21xu4M27imgphf9HrgGQDmu4G n5UYTPBnoi8FcEPvjwrH0t9zfCG7LgOsuFlt6RvPqNC5Z2KlYI8uyk1n012v8KfQUsgv A7UgmaG7xqEBDCREwuFtaXXs8hzDiRErF2tSO9BQqyRhFwSADW2WLI/2BoXZ0PV7y1CR BwRSxB85bR1eyk4MSUObK51qBNtLKAl2Gn85sKUbVcNwYPf+h1KhqABkOMoG9JT7FITP VCJPLdom0L3+UDP+j/KiW9smJjVpRgHMolZU4xwKsJkGNVlhI9B9wuUltIfSejVxIo6Q 2+9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839236; x=1728444036; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bF65nLXk1UolurWKQzuL9+6VFLZl4ud9B1SFXRw/LFg=; b=B6GeD4zhbgGO2z21tEteerLt1g19niuFCbYyvl+zNTOC8fn1HN6BKEHzz6HQOD4+FY JhWSO5lH7e6x51CGgzbmQ4BQcxKX5GLrpSUSJfT0YNwZDYSnDxvZVjQg5da5K8YBD35G GlGUgEpvXy0+LptsS3ofhzWC6Cu1umB7ITbuva0teKOSAU/A0rSHkvOpwhEnkfOeIEPG 2AXSmvmFXJ62f66i5LWasLksMxHkfFGoSHW4ceZ6Bm6XknDYvd0WkSNcOZ5JI2lWtFZ0 Nax/OiIVejlgPLohhV8GYVgdY6iq1g7po/6QeMRrWNVqi46LwOWwI4neEhB72sZtZ5BZ 7xrQ== X-Forwarded-Encrypted: i=1; AJvYcCU/2Ca/n2dEoZvYd8c+CProv/P9SR4FDilcI+ETobB10eWr7U0m2IbkdDv3aKOKpKQqrOLX9AV9ubuyyhQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6jcjRF+43Y0LEYDmp4EUvLzLxe3DoZtTS9Y17nivxBKWpxeah umfkjsOcrpe/r7RfwnlEzzxlWUqXmiZVBiIpMUesTYN8JX0Xua0LLLpZJqk2UCsMt2LQdzXZyXb LobIgvg== X-Google-Smtp-Source: AGHT+IFaO8lHdOniNRTpaZuldspmldGJ3TH5FSCfkfLccbjjJ2qmbvropjIYlUbtldgOQhvjL8xdViilvcKa X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:6902:10c7:b0:e24:a00a:518e with SMTP id 3f1490d57ef6-e263840d766mr9239276.7.1727839236256; Tue, 01 Oct 2024 20:20:36 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:09 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 06/13] perf tool_pmu: Rename perf_tool_event__* to tool_pmu__* From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now the events are associated with the tool PMU, rename the functions to reflect this. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/evsel.c | 2 +- tools/perf/util/metricgroup.c | 22 +++++++++++----------- tools/perf/util/pmu.c | 4 ++-- tools/perf/util/tool_pmu.c | 16 ++++++++-------- tools/perf/util/tool_pmu.h | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 59b2d38c9a65..e6fdbbb3398e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1669,7 +1669,7 @@ bool __evsel__match(const struct evsel *evsel, u32 ty= pe, u64 config) int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) - return evsel__read_tool(evsel, cpu_map_idx, thread); + return evsel__tool_pmu_read(evsel, cpu_map_idx, thread); =20 if (evsel__is_retire_lat(evsel)) return evsel__read_retire_lat(evsel, cpu_map_idx, thread); diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 1250bf5050b0..46920ebadfd1 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -686,7 +686,7 @@ static int metricgroup__build_event_string(struct strbu= f *events, pr_debug("found event %s\n", id); =20 /* Always move tool events outside of the group. */ - ev =3D perf_tool_event__from_str(id); + ev =3D tool_pmu__str_to_event(id); if (ev !=3D TOOL_PMU__EVENT_NONE) { has_tool_events =3D true; tool_events[ev] =3D true; @@ -755,14 +755,14 @@ static int metricgroup__build_event_string(struct str= buf *events, if (has_tool_events) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (tool_events[i]) { if (!no_group) { ret =3D strbuf_addch(events, ','); RETURN_IF_NON_ZERO(ret); } no_group =3D false; - ret =3D strbuf_addstr(events, perf_tool_event__to_str(i)); + ret =3D strbuf_addstr(events, tool_pmu__event_to_str(i)); RETURN_IF_NON_ZERO(ret); } } @@ -1148,14 +1148,14 @@ static int metric_list_cmp(void *priv __maybe_unuse= d, const struct list_head *l, int i, left_count, right_count; =20 left_count =3D hashmap__size(left->pctx->ids); - perf_tool_event__for_each_event(i) { - if (!expr__get_id(left->pctx, perf_tool_event__to_str(i), &data)) + tool_pmu__for_each_event(i) { + if (!expr__get_id(left->pctx, tool_pmu__event_to_str(i), &data)) left_count--; } =20 right_count =3D hashmap__size(right->pctx->ids); - perf_tool_event__for_each_event(i) { - if (!expr__get_id(right->pctx, perf_tool_event__to_str(i), &data)) + tool_pmu__for_each_event(i) { + if (!expr__get_id(right->pctx, tool_pmu__event_to_str(i), &data)) right_count--; } =20 @@ -1382,11 +1382,11 @@ static void find_tool_events(const struct list_head= *metric_list, list_for_each_entry(m, metric_list, nd) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { struct expr_id_data *data; =20 if (!tool_events[i] && - !expr__get_id(m->pctx, perf_tool_event__to_str(i), &data)) + !expr__get_id(m->pctx, tool_pmu__event_to_str(i), &data)) tool_events[i] =3D true; } } @@ -1472,9 +1472,9 @@ static int parse_ids(bool metric_no_merge, bool fake_= pmu, * event1 if #smt_on else 0 * Add a tool event to avoid a parse error on an empty string. */ - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (tool_events[i]) { - char *tmp =3D strdup(perf_tool_event__to_str(i)); + char *tmp =3D strdup(tool_pmu__event_to_str(i)); =20 if (!tmp) return -ENOMEM; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 77e848ac5841..d3c7a1c4254c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1836,7 +1836,7 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) if (!name) return false; if (perf_pmu__is_tool(pmu)) - return perf_tool_event__from_str(name) !=3D TOOL_PMU__EVENT_NONE; + return tool_pmu__str_to_event(name) !=3D TOOL_PMU__EVENT_NONE; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -2331,7 +2331,7 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) return NULL; =20 if (perf_pmu__is_tool(pmu)) - return perf_tool_event__to_str(config); + return tool_pmu__event_to_str(config); =20 pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index ae0ca023f5ed..2a1524dc2e31 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -20,7 +20,7 @@ static const char *const tool_pmu__event_names[TOOL_PMU__= EVENT_MAX] =3D { }; =20 =20 -const char *perf_tool_event__to_str(enum tool_pmu_event ev) +const char *tool_pmu__event_to_str(enum tool_pmu_event ev) { if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) return tool_pmu__event_names[ev]; @@ -28,11 +28,11 @@ const char *perf_tool_event__to_str(enum tool_pmu_event= ev) return NULL; } =20 -enum tool_pmu_event perf_tool_event__from_str(const char *str) +enum tool_pmu_event tool_pmu__str_to_event(const char *str) { int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { if (!strcasecmp(str, tool_pmu__event_names[i])) return i; } @@ -44,7 +44,7 @@ static int tool_pmu__config_term(struct perf_event_attr *= attr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum tool_pmu_event ev =3D perf_tool_event__from_str(term->config); + enum tool_pmu_event ev =3D tool_pmu__str_to_event(term->config); =20 if (ev =3D=3D TOOL_PMU__EVENT_NONE) goto err_out; @@ -91,10 +91,10 @@ int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, v= oid *state, pmu_event_cal }; int i; =20 - perf_tool_event__for_each_event(i) { + tool_pmu__for_each_event(i) { int ret; =20 - info.name =3D perf_tool_event__to_str(i); + info.name =3D tool_pmu__event_to_str(i); info.alias =3D NULL; info.scale_unit =3D NULL; info.desc =3D NULL; @@ -130,7 +130,7 @@ enum tool_pmu_event evsel__tool_event(const struct evse= l *evsel) =20 const char *evsel__tool_pmu_event_name(const struct evsel *evsel) { - return perf_tool_event__to_str(evsel->core.attr.config); + return tool_pmu__event_to_str(evsel->core.attr.config); } =20 static bool read_until_char(struct io *io, char e) @@ -328,7 +328,7 @@ int evsel__tool_pmu_open(struct evsel *evsel, return err; } =20 -int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread) +int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread) { __u64 *start_time, cur_time, delta_start; int fd, err =3D 0; diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index b27a26133927..b156645206c4 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -17,7 +17,7 @@ enum tool_pmu_event { TOOL_PMU__EVENT_MAX, }; =20 -#define perf_tool_event__for_each_event(ev) \ +#define tool_pmu__for_each_event(ev) \ for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 static inline size_t tool_pmu__num_events(void) @@ -25,8 +25,8 @@ static inline size_t tool_pmu__num_events(void) return TOOL_PMU__EVENT_MAX - 1; } =20 -const char *perf_tool_event__to_str(enum tool_pmu_event ev); -enum tool_pmu_event perf_tool_event__from_str(const char *str); +const char *tool_pmu__event_to_str(enum tool_pmu_event ev); +enum tool_pmu_event tool_pmu__str_to_event(const char *str); int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); @@ -44,7 +44,7 @@ int evsel__tool_pmu_prepare_open(struct evsel *evsel, int evsel__tool_pmu_open(struct evsel *evsel, struct perf_thread_map *threads, int start_cpu_map_idx, int end_cpu_map_idx); -int evsel__read_tool(struct evsel *evsel, int cpu_map_idx, int thread); +int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread); =20 struct perf_pmu *perf_pmus__tool_pmu(void); =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6AC016419 for ; Wed, 2 Oct 2024 03:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839242; cv=none; b=JnR/2HVmYZOeUgTPg2JL7zdCQcguQMJGyiEB9ryzfbrvfkDcvxgABLMCBWs+RLSh3LvJUj7ZXgXYuTFhXpoLx7n4Dk0qEuIuFM0lmWFCtZzq6KQl1QWCitUeYduuH4hfrR201wDSm9UCFGAt2ooe10iGFgpMO6UZA78WxUUAsds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839242; c=relaxed/simple; bh=I/ar9DfXbRCvm5R/UAPa7V42FuCshaHGTf7cVwciI5Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Q/xDR7bSyR4rfTeK+AqG8Nv97dgYeuKdGmn+WD0PrpBhYeX47b/qVYdXx0EPrK+kVJI1lBWjX32OWhnR8hALD20AO7POvd9noVURryMa6/PWHMGKDuO7ysZb+rZTyVUiyZ9PXustehLcDgYIffqw3kCMecOMA1MoUnT5SeXa5lU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kSYEL1va; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kSYEL1va" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e25cc76cae1so600502276.0 for ; Tue, 01 Oct 2024 20:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839239; x=1728444039; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9pK3XsqehiBBcnuzo5zZEX67K88H1Nl4FUBcwZmg+jY=; b=kSYEL1vaKjv6WNbZhxQ4TYXlXTtpPfPnlbEilhOcQVb/zhzW2MuvDT1e2qDOmDD/5S ixqyZKv6l++S6jSgxeMF67UF3jMyyqVINScl5mRXAKQXtP4T3yw/LkjNcXy+XLY9BTzO SU2FqxfHbrn5Oue9+KuZvl/KGKhnW7WBTYnXGt4av8P94KzZsJa83f8d+MoTmGVKKSA/ +Md+c8Nt66J1rR6ajMaQVbHzWmNkR5IsshXw26/olsyHyvwIPNshLVNIEQs9z8sE03Jw 6QHCh/H76wen+c/N56cyJa+fKMvCyF2ObYbyq9BZFs0SIHKTsxTbV+pG1f8llZsSGZBN +lwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839239; x=1728444039; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9pK3XsqehiBBcnuzo5zZEX67K88H1Nl4FUBcwZmg+jY=; b=er3TuyYWfaCTHyHvNyyApmg7kWJR859L+fCR0YXX1FpkMavKqD0nBa59HUf8aK50qy hr32uZ16qYqc8rTsgUwodvcEycQoQOu9Ff/wWj1yhYkKxl3DJcBA8667scWRRxeiDraC TrWXF+YHPr0GaNSXGDef/Jv/lQS2rYI02H97FWD1YiEmHJsxWf2dCEU+zkMx2PSMAUSP Nk2qxsR0zvkreBChIuYGrHcxqXT/DzxDren2SZjw270VTpJNvyBVDAFosh/cpAbpCC7d 26jomR6GaWcJhT1psOvrUtXqS8nXDDqC4HjhhYdMpiXc/RWgwTF7UPJW9jRCma65mQ2v /4rA== X-Forwarded-Encrypted: i=1; AJvYcCVZW/ZBockdEZJJMRS1I6YKaJbJlW0RLSDe2WCYBcwjyyzP8QyVcgpdy88DW064VyxIfWXYRj67rO2kDNQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwxHeoErs/rlWsfzLxEJ8sNfS4JfVbqE+2oT4GUWiaVnxakFchJ N5rtLpnhuET7LAjM5KVzWQWvK8NYqOrBF0yiQ4C9IbG3mF+eaK0Any8Zuy1cS1DwEDGUtTUCfwB m8I2mQQ== X-Google-Smtp-Source: AGHT+IGZ5tbevQcPNNLTJ/8aj+ShVgJQCP9xzIv6Orl0ORHomvz0Sm1OGj1c5uwYXSuiXLy4TVST0UFNYJak X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a5b:46:0:b0:e25:e2af:7e7b with SMTP id 3f1490d57ef6-e262bece746mr63295276.0.1727839238761; Tue, 01 Oct 2024 20:20:38 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:10 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 07/13] perf tool_pmu: Move expr literals to tool_pmu From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the expr literals like "#smt_on" as tool events, this allows stat events to give the values. On my laptop with hyperthreading enabled: ``` $ perf stat -e "has_pmem,num_cores,num_cpus,num_cpus_online,num_dies,num_pa= ckages,smt_on,system_tsc_freq" true Performance counter stats for 'true': 0 has_pmem 8 num_cores 16 num_cpus 16 num_cpus_online 1 num_dies 1 num_packages 1 smt_on 2,496,000,000 system_tsc_freq 0.001113637 seconds time elapsed 0.001218000 seconds user 0.000000000 seconds sys ``` And with hyperthreading disabled: ``` $ perf stat -e "has_pmem,num_cores,num_cpus,num_cpus_online,num_dies,num_pa= ckages,smt_on,system_tsc_freq" true Performance counter stats for 'true': 0 has_pmem 8 num_cores 16 num_cpus 8 num_cpus_online 1 num_dies 1 num_packages 0 smt_on 2,496,000,000 system_tsc_freq 0.000802115 seconds time elapsed 0.000000000 seconds user 0.000806000 seconds sys ``` As zero matters for these values, in stat-display should_skip_zero_counter only skip the zero value if it is not the first aggregation index. The tool event implementations are used in expr but not evaluated as events for simplicity. Also core_wide isn't made a tool event as it requires command line parameters. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/arch/arm64/util/pmu.c | 5 +- tools/perf/arch/x86/util/tsc.c | 18 ++-- tools/perf/util/expr.c | 93 +++----------------- tools/perf/util/pmu.c | 5 -- tools/perf/util/pmu.h | 1 - tools/perf/util/stat-display.c | 8 +- tools/perf/util/stat-shadow.c | 11 ++- tools/perf/util/tool_pmu.c | 146 ++++++++++++++++++++++++++++++- tools/perf/util/tool_pmu.h | 19 +++- tools/perf/util/tsc.h | 2 +- 10 files changed, 201 insertions(+), 107 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 2a4eab2d160e..a0964b191fcb 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -5,6 +5,7 @@ #include "../../../util/header.h" #include "../../../util/pmu.h" #include "../../../util/pmus.h" +#include "../../../util/tool_pmu.h" #include #include =20 @@ -24,7 +25,7 @@ const struct pmu_metrics_table *pmu_metrics_table__find(v= oid) return NULL; } =20 -double perf_pmu__cpu_slots_per_cycle(void) +u64 tool_pmu__cpu_slots_per_cycle(void) { char path[PATH_MAX]; unsigned long long slots =3D 0; @@ -41,5 +42,5 @@ double perf_pmu__cpu_slots_per_cycle(void) filename__read_ull(path, &slots); } =20 - return slots ? (double)slots : NAN; + return slots; } diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c index e2d6cfe21057..3a439e4b12d2 100644 --- a/tools/perf/arch/x86/util/tsc.c +++ b/tools/perf/arch/x86/util/tsc.c @@ -24,9 +24,9 @@ u64 rdtsc(void) * ... * will return 3000000000. */ -static double cpuinfo_tsc_freq(void) +static u64 cpuinfo_tsc_freq(void) { - double result =3D 0; + u64 result =3D 0; FILE *cpuinfo; char *line =3D NULL; size_t len =3D 0; @@ -34,20 +34,22 @@ static double cpuinfo_tsc_freq(void) cpuinfo =3D fopen("/proc/cpuinfo", "r"); if (!cpuinfo) { pr_err("Failed to read /proc/cpuinfo for TSC frequency\n"); - return NAN; + return 0; } while (getline(&line, &len, cpuinfo) > 0) { if (!strncmp(line, "model name", 10)) { char *pos =3D strstr(line + 11, " @ "); + double float_result; =20 - if (pos && sscanf(pos, " @ %lfGHz", &result) =3D=3D 1) { - result *=3D 1000000000; + if (pos && sscanf(pos, " @ %lfGHz", &float_result) =3D=3D 1) { + float_result *=3D 1000000000; + result =3D (u64)float_result; goto out; } } } out: - if (fpclassify(result) =3D=3D FP_ZERO) + if (result =3D=3D 0) pr_err("Failed to find TSC frequency in /proc/cpuinfo\n"); =20 free(line); @@ -55,7 +57,7 @@ static double cpuinfo_tsc_freq(void) return result; } =20 -double arch_get_tsc_freq(void) +u64 arch_get_tsc_freq(void) { unsigned int a, b, c, d, lvl; static bool cached; @@ -86,6 +88,6 @@ double arch_get_tsc_freq(void) return tsc; } =20 - tsc =3D (double)c * (double)b / (double)a; + tsc =3D (u64)c * (u64)b / (u64)a; return tsc; } diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index b2536a59c44e..5e3732bc2fa5 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -5,25 +5,22 @@ #include #include #include "metricgroup.h" -#include "cpumap.h" -#include "cputopo.h" #include "debug.h" #include "evlist.h" #include "expr.h" +#include "pmu.h" +#include "smt.h" +#include "tool_pmu.h" #include #include #include "util/hashmap.h" #include "util/header.h" #include "util/pmu.h" -#include "smt.h" -#include "tsc.h" -#include #include #include #include #include #include -#include "pmu.h" =20 struct expr_id_data { union { @@ -393,90 +390,26 @@ double expr_id_data__source_count(const struct expr_i= d_data *data) return data->val.source_count; } =20 -#if !defined(__i386__) && !defined(__x86_64__) -double arch_get_tsc_freq(void) -{ - return 0.0; -} -#endif - -static double has_pmem(void) -{ - static bool has_pmem, cached; - const char *sysfs =3D sysfs__mountpoint(); - char path[PATH_MAX]; - - if (!cached) { - snprintf(path, sizeof(path), "%s/firmware/acpi/tables/NFIT", sysfs); - has_pmem =3D access(path, F_OK) =3D=3D 0; - cached =3D true; - } - return has_pmem ? 1.0 : 0.0; -} - double expr__get_literal(const char *literal, const struct expr_scanner_ct= x *ctx) { - const struct cpu_topology *topology; double result =3D NAN; + enum tool_pmu_event ev =3D tool_pmu__str_to_event(literal + 1); =20 - if (!strcmp("#num_cpus", literal)) { - result =3D cpu__max_present_cpu().cpu; - goto out; - } - if (!strcmp("#num_cpus_online", literal)) { - struct perf_cpu_map *online =3D cpu_map__online(); - - if (online) - result =3D perf_cpu_map__nr(online); - goto out; - } + if (ev !=3D TOOL_PMU__EVENT_NONE) { + u64 count; =20 - if (!strcasecmp("#system_tsc_freq", literal)) { - result =3D arch_get_tsc_freq(); - goto out; - } + if (tool_pmu__read_event(ev, &count)) + result =3D count; + else + pr_err("Failure to read '%s'", literal); =20 - /* - * Assume that topology strings are consistent, such as CPUs "0-1" - * wouldn't be listed as "0,1", and so after deduplication the number of - * these strings gives an indication of the number of packages, dies, - * etc. - */ - if (!strcasecmp("#smt_on", literal)) { - result =3D smt_on() ? 1.0 : 0.0; - goto out; - } - if (!strcmp("#core_wide", literal)) { + } else if (!strcmp("#core_wide", literal)) { result =3D core_wide(ctx->system_wide, ctx->user_requested_cpu_list) ? 1.0 : 0.0; - goto out; - } - if (!strcmp("#num_packages", literal)) { - topology =3D online_topology(); - result =3D topology->package_cpus_lists; - goto out; - } - if (!strcmp("#num_dies", literal)) { - topology =3D online_topology(); - result =3D topology->die_cpus_lists; - goto out; - } - if (!strcmp("#num_cores", literal)) { - topology =3D online_topology(); - result =3D topology->core_cpus_lists; - goto out; - } - if (!strcmp("#slots", literal)) { - result =3D perf_pmu__cpu_slots_per_cycle(); - goto out; - } - if (!strcmp("#has_pmem", literal)) { - result =3D has_pmem(); - goto out; + } else { + pr_err("Unrecognized literal '%s'", literal); } =20 - pr_err("Unrecognized literal '%s'", literal); -out: pr_debug2("literal: %s =3D %f\n", literal, result); return result; } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index d3c7a1c4254c..9228650a62d2 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2254,11 +2254,6 @@ bool perf_pmu__match(const struct perf_pmu *pmu, con= st char *tok) (need_fnmatch && !fnmatch(tok, name, 0)); } =20 -double __weak perf_pmu__cpu_slots_per_cycle(void) -{ - return NAN; -} - int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size) { const char *sysfs =3D sysfs__mountpoint(); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 36fced2bf065..e400db9e9eb1 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -271,7 +271,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pm= u); =20 bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok); =20 -double perf_pmu__cpu_slots_per_cycle(void); int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size); int perf_pmu__pathname_scnprintf(char *buf, size_t size, const char *pmu_name, const char *filename); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ca8527067869..ef0ca8cd802d 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -987,8 +987,12 @@ static bool should_skip_zero_counter(struct perf_stat_= config *config, * Many tool events are only gathered on the first index, skip other * zero values. */ - if (evsel__is_tool(counter)) - return true; + if (evsel__is_tool(counter)) { + struct aggr_cpu_id own_id =3D + config->aggr_get_id(config, (struct perf_cpu){ .cpu =3D 0 }); + + return !aggr_cpu_id__equal(id, &own_id); + } =20 /* * Skip value 0 when it's an uncore event and the given aggr id diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index b54afb56e3d6..6227de848083 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -400,8 +400,17 @@ static int prepare_metric(const struct metric_expr *me= xp, case TOOL_PMU__EVENT_MAX: pr_err("Invalid tool event 'max'"); abort(); + case TOOL_PMU__EVENT_HAS_PMEM: + case TOOL_PMU__EVENT_NUM_CORES: + case TOOL_PMU__EVENT_NUM_CPUS: + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: + case TOOL_PMU__EVENT_NUM_DIES: + case TOOL_PMU__EVENT_NUM_PACKAGES: + case TOOL_PMU__EVENT_SLOTS: + case TOOL_PMU__EVENT_SMT_ON: + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: default: - pr_err("Unknown tool event '%s'", evsel__name(metric_events[i])); + pr_err("Unexpected tool event '%s'", evsel__name(metric_events[i])); abort(); } val =3D avg_stats(stats) * scale; diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 2a1524dc2e31..cfdc09dece1e 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -1,11 +1,16 @@ // SPDX-License-Identifier: GPL-2.0-only #include "cgroup.h" #include "counts.h" +#include "cputopo.h" #include "evsel.h" #include "pmu.h" #include "print-events.h" +#include "smt.h" #include "time-utils.h" #include "tool_pmu.h" +#include "tsc.h" +#include +#include #include #include #include @@ -17,6 +22,15 @@ static const char *const tool_pmu__event_names[TOOL_PMU_= _EVENT_MAX] =3D { "duration_time", "user_time", "system_time", + "has_pmem", + "num_cores", + "num_cpus", + "num_cpus_online", + "num_dies", + "num_packages", + "slots", + "smt_on", + "system_tsc_freq", }; =20 =20 @@ -33,8 +47,14 @@ enum tool_pmu_event tool_pmu__str_to_event(const char *s= tr) int i; =20 tool_pmu__for_each_event(i) { - if (!strcasecmp(str, tool_pmu__event_names[i])) + if (!strcasecmp(str, tool_pmu__event_names[i])) { +#if !defined(__aarch64__) + /* The slots event should only appear on arm64. */ + if (i =3D=3D TOOL_PMU__EVENT_SLOTS) + return TOOL_PMU__EVENT_NONE; +#endif return i; + } } return TOOL_PMU__EVENT_NONE; } @@ -250,6 +270,9 @@ int evsel__tool_pmu_open(struct evsel *evsel, enum tool_pmu_event ev =3D evsel__tool_event(evsel); int pid =3D -1, idx =3D 0, thread =3D 0, nthreads, err =3D 0, old_errno; =20 + if (ev =3D=3D TOOL_PMU__EVENT_NUM_CPUS) + return 0; + if (ev =3D=3D TOOL_PMU__EVENT_DURATION_TIME) { if (evsel->core.attr.sample_period) /* no sampling */ return -EINVAL; @@ -328,16 +351,133 @@ int evsel__tool_pmu_open(struct evsel *evsel, return err; } =20 +#if !defined(__i386__) && !defined(__x86_64__) +u64 arch_get_tsc_freq(void) +{ + return 0; +} +#endif + +#if !defined(__aarch64__) +u64 tool_pmu__cpu_slots_per_cycle(void) +{ + return 0; +} +#endif + +static bool has_pmem(void) +{ + static bool has_pmem, cached; + const char *sysfs =3D sysfs__mountpoint(); + char path[PATH_MAX]; + + if (!cached) { + snprintf(path, sizeof(path), "%s/firmware/acpi/tables/NFIT", sysfs); + has_pmem =3D access(path, F_OK) =3D=3D 0; + cached =3D true; + } + return has_pmem; +} + +bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result) +{ + const struct cpu_topology *topology; + + switch (ev) { + case TOOL_PMU__EVENT_HAS_PMEM: + *result =3D has_pmem() ? 1 : 0; + return true; + + case TOOL_PMU__EVENT_NUM_CORES: + topology =3D online_topology(); + *result =3D topology->core_cpus_lists; + return true; + + case TOOL_PMU__EVENT_NUM_CPUS: + *result =3D cpu__max_present_cpu().cpu; + return true; + + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: { + struct perf_cpu_map *online =3D cpu_map__online(); + + if (online) { + *result =3D perf_cpu_map__nr(online); + return true; + } + return false; + } + case TOOL_PMU__EVENT_NUM_DIES: + topology =3D online_topology(); + *result =3D topology->die_cpus_lists; + return true; + + case TOOL_PMU__EVENT_NUM_PACKAGES: + topology =3D online_topology(); + *result =3D topology->package_cpus_lists; + return true; + + case TOOL_PMU__EVENT_SLOTS: + *result =3D tool_pmu__cpu_slots_per_cycle(); + return *result ? true : false; + + case TOOL_PMU__EVENT_SMT_ON: + *result =3D smt_on() ? 1 : 0; + return true; + + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: + *result =3D arch_get_tsc_freq(); + return true; + + case TOOL_PMU__EVENT_NONE: + case TOOL_PMU__EVENT_DURATION_TIME: + case TOOL_PMU__EVENT_USER_TIME: + case TOOL_PMU__EVENT_SYSTEM_TIME: + case TOOL_PMU__EVENT_MAX: + default: + return false; + } +} + int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread) { __u64 *start_time, cur_time, delta_start; + unsigned long val; int fd, err =3D 0; - struct perf_counts_values *count; + struct perf_counts_values *count, *old_count =3D NULL; bool adjust =3D false; + enum tool_pmu_event ev =3D evsel__tool_event(evsel); =20 count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 - switch (evsel__tool_event(evsel)) { + switch (ev) { + case TOOL_PMU__EVENT_HAS_PMEM: + case TOOL_PMU__EVENT_NUM_CORES: + case TOOL_PMU__EVENT_NUM_CPUS: + case TOOL_PMU__EVENT_NUM_CPUS_ONLINE: + case TOOL_PMU__EVENT_NUM_DIES: + case TOOL_PMU__EVENT_NUM_PACKAGES: + case TOOL_PMU__EVENT_SLOTS: + case TOOL_PMU__EVENT_SMT_ON: + case TOOL_PMU__EVENT_SYSTEM_TSC_FREQ: + if (evsel->prev_raw_counts) + old_count =3D perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + val =3D 0; + if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) { + if (!tool_pmu__read_event(ev, &val)) { + count->lost++; + val =3D 0; + } + } + if (old_count) { + count->val =3D old_count->val + val; + count->run =3D old_count->run + 1; + count->ena =3D old_count->ena + 1; + } else { + count->val =3D val; + count->run++; + count->ena++; + } + return 0; case TOOL_PMU__EVENT_DURATION_TIME: /* * Pretend duration_time is only on the first CPU and thread, or diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index b156645206c4..ecdf316525bb 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -10,9 +10,18 @@ struct print_callbacks; =20 enum tool_pmu_event { TOOL_PMU__EVENT_NONE =3D 0, - TOOL_PMU__EVENT_DURATION_TIME =3D 1, - TOOL_PMU__EVENT_USER_TIME =3D 2, - TOOL_PMU__EVENT_SYSTEM_TIME =3D 3, + TOOL_PMU__EVENT_DURATION_TIME, + TOOL_PMU__EVENT_USER_TIME, + TOOL_PMU__EVENT_SYSTEM_TIME, + TOOL_PMU__EVENT_HAS_PMEM, + TOOL_PMU__EVENT_NUM_CORES, + TOOL_PMU__EVENT_NUM_CPUS, + TOOL_PMU__EVENT_NUM_CPUS_ONLINE, + TOOL_PMU__EVENT_NUM_DIES, + TOOL_PMU__EVENT_NUM_PACKAGES, + TOOL_PMU__EVENT_SLOTS, + TOOL_PMU__EVENT_SMT_ON, + TOOL_PMU__EVENT_SYSTEM_TSC_FREQ, =20 TOOL_PMU__EVENT_MAX, }; @@ -31,9 +40,11 @@ int tool_pmu__config_terms(struct perf_event_attr *attr, struct parse_events_terms *terms, struct parse_events_error *err); int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); +bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result); =20 -bool perf_pmu__is_tool(const struct perf_pmu *pmu); +u64 tool_pmu__cpu_slots_per_cycle(void); =20 +bool perf_pmu__is_tool(const struct perf_pmu *pmu); =20 bool evsel__is_tool(const struct evsel *evsel); enum tool_pmu_event evsel__tool_event(const struct evsel *evsel); diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h index 88fd1c4c1cb8..57ce8449647f 100644 --- a/tools/perf/util/tsc.h +++ b/tools/perf/util/tsc.h @@ -25,7 +25,7 @@ int perf_read_tsc_conversion(const struct perf_event_mmap= _page *pc, u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc); u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc); u64 rdtsc(void); -double arch_get_tsc_freq(void); +u64 arch_get_tsc_freq(void); =20 size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp); =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4922E55E58 for ; Wed, 2 Oct 2024 03:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839245; cv=none; b=GdSjqq31/0JJhwDjbem7P+AbNnobmCt5eYnczFHOJB08MEXafwrpx00QD9J9+E1bNwCgYsylTQMdReAaLSB6lgljBMKlI4kMoO3rOAUB92HZjyHyKL0+X9zghJyimWU3n2BU1mLi9oJe41bQ7/boNytBn/xAve1C5PKh2FsNrm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839245; c=relaxed/simple; bh=/bk2X1mEjBnO/58ncGztLNXEHUh2XE6RXX7qE9l/E+w=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=YrW6yij389BCKYG5a3A29stKKZrwoUfN88re0DcjEvYImSTrL9HNWvajCbxMQYx3wfJ6F7QtU01l++vbCTEEs3ytU9kn2auKGYgm7c6zOq8Wo73kql0iktRWSQr7fF8xf4A+Pc88TPfcvSPXBWbBbm1ftrJ3yWblEDLnezTmPww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=J295WeYs; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="J295WeYs" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e22f8dc491so57431267b3.1 for ; Tue, 01 Oct 2024 20:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839241; x=1728444041; darn=vger.kernel.org; h=content-transfer-encoding:to:from:subject:references:mime-version :message-id:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=2j+PdhSRd6WvrLriDoC1695XR9/14hLFVY0i3VO90/s=; b=J295WeYswUEC1CvJ6RgUQHFZ1wR1GUhS5V3LX2Y110YHVW1RFMpUsYgbzRnGgWCoKO ZsuhXjKcYMYmj5V4SOBDgrCZKpgb5fc6zB0eKLhTyndimwSxXIpQQMC6pdD9EZxlh8vo bRgms0MVCWa0v6wnrhF2UkI5wLuU7NxQh0yI/fkDunmZ21/hiZFxrL3OxgV2vCCZTlU5 LYz6BF39L9xuPnwTDZPt9qfTgQLqKXHyJGe5ypmMxpoWA1Uya0NPs730JGC/+Idlhe1l AuxSH6yVT4b1o7xRqyOz5YbqpOApfmD7JVn8qTzngQruK0g4YEDZ/64LtsnMg5QbZ4Os evcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839241; x=1728444041; h=content-transfer-encoding:to:from:subject:references:mime-version :message-id:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=2j+PdhSRd6WvrLriDoC1695XR9/14hLFVY0i3VO90/s=; b=HWuWEGtJl0W+UH61FEb/Hr8G7K+F8tN80HgYzt0VHWKi8FHLLRsZqTpoDlbormiicm Hb/62RsozQxyISD8Nn2Mkth89gVPUS1ph2Ylud8pUIa6zV19oPHGR0qzrgdLx/aekLtk FICvFrUrFkT9o9JE5nLZdKoKzL9L2QWt7quPLNRoeqsjFrlFlPYO4wT416wd0YuFthdx RiA3n5uGR31+yoZVBMKTa9gIAqopOLBP5qaahBbCL04BKGAcuGuhRr7sXSg7bQzcgaI+ D8TZ1/np0+sbPu1ufNvHsuNaDKu3vR7nmgt9RvIsk8v5A9moK6ptuz7bwG1n347M3EUk ERUA== X-Forwarded-Encrypted: i=1; AJvYcCVkI0ZabZ0jp8RQUZvGervhm17VkOTq3rycH5HFTc80BgBb8iVYts93xzNLG2bgBrMLLWOJTg1BFRVrRLA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+OzRCI+DVdTGDGoebJgURJevJGInTD4hW5bPngG6suHfY/dhM AFOetkVTxs9BCQPzcjV/FuGeUXL1q3HdYDTUk4qykIO/vOrGmgEQpmVOuq9n+KMSoBLWeMcNFXL 4eZ+9/Q== X-Google-Smtp-Source: AGHT+IGCLpcpjQp7WooQYlBENclXT9yRcpl0p3hmwAHF0WuRZvIV5EBWryWkmtprfb9wcow1BqHDtqSYPKIM X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:690c:fcb:b0:6e2:120b:be57 with SMTP id 00721157ae682-6e2a2e05268mr512997b3.5.1727839241194; Tue, 01 Oct 2024 20:20:41 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:11 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 08/13] perf jevents: Add tool event json under a common architecture From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the notion of a common architecture/model that can be used to find event tables for common PMUs like the tool PMU. By having tool events be json standard PMU attribute configuration, descriptions, etc. can be used and these routines are already optimized for things like binary searching. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- .../pmu-events/arch/common/common/tool.json | 74 +++++++ tools/perf/pmu-events/empty-pmu-events.c | 208 +++++++++++------- tools/perf/pmu-events/jevents.py | 16 +- 3 files changed, 215 insertions(+), 83 deletions(-) create mode 100644 tools/perf/pmu-events/arch/common/common/tool.json diff --git a/tools/perf/pmu-events/arch/common/common/tool.json b/tools/per= f/pmu-events/arch/common/common/tool.json new file mode 100644 index 000000000000..12f2ef1813a6 --- /dev/null +++ b/tools/perf/pmu-events/arch/common/common/tool.json @@ -0,0 +1,74 @@ +[ + { + "Unit": "tool", + "EventName": "duration_time", + "BriefDescription": "Wall clock interval time in nanoseconds", + "ConfigCode": "1" + }, + { + "Unit": "tool", + "EventName": "user_time", + "BriefDescription": "User (non-kernel) time in nanoseconds", + "ConfigCode": "2" + }, + { + "Unit": "tool", + "EventName": "system_time", + "BriefDescription": "System/kernel time in nanoseconds", + "ConfigCode": "3" + }, + { + "Unit": "tool", + "EventName": "has_pmem", + "BriefDescription": "1 if persistent memory installed otherwise 0", + "ConfigCode": "4" + }, + { + "Unit": "tool", + "EventName": "num_cores", + "BriefDescription": "Number of cores. A core consists of 1 or more thr= ead, with each thread being associated with a logical Linux CPU", + "ConfigCode": "5" + }, + { + "Unit": "tool", + "EventName": "num_cpus", + "BriefDescription": "Number of logical Linux CPUs. There may be multip= le such CPUs on a core", + "ConfigCode": "6" + }, + { + "Unit": "tool", + "EventName": "num_cpus_online", + "BriefDescription": "Number of online logical Linux CPUs. There may be= multiple such CPUs on a core", + "ConfigCode": "7" + }, + { + "Unit": "tool", + "EventName": "num_dies", + "BriefDescription": "Number of dies. Each die has 1 or more cores", + "ConfigCode": "8" + }, + { + "Unit": "tool", + "EventName": "num_packages", + "BriefDescription": "Number of packages. Each package has 1 or more di= e", + "ConfigCode": "9" + }, + { + "Unit": "tool", + "EventName": "slots", + "BriefDescription": "Number of functional units that in parallel can e= xecute parts of an instruction", + "ConfigCode": "10" + }, + { + "Unit": "tool", + "EventName": "smt_on", + "BriefDescription": "1 if simultaneous multithreading (aka hyperthread= ing) is enable otherwise 0", + "ConfigCode": "11" + }, + { + "Unit": "tool", + "EventName": "system_tsc_freq", + "BriefDescription": "The amount a Time Stamp Counter (TSC) increases p= er second", + "ConfigCode": "12" + } +] diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index c592079982fb..47ed8b03e445 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -19,72 +19,109 @@ struct pmu_table_entry { }; =20 static const char *const big_c_string =3D -/* offset=3D0 */ "default_core\000" -/* offset=3D13 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000eve= nt=3D0x8a\000\00000\000\000" -/* offset=3D72 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000eve= nt=3D0x8b\000\00000\000\000" -/* offset=3D131 */ "l3_cache_rd\000cache\000L3 cache access, read\000event= =3D0x40\000\00000\000Attributable Level 3 cache access, read\000" -/* offset=3D226 */ "segment_reg_loads.any\000other\000Number of segment re= gister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" -/* offset=3D325 */ "dispatch_blocked.any\000other\000Memory cluster signal= s to block micro-op dispatch for any reason\000event=3D9,period=3D200000,um= ask=3D0x20\000\00000\000\000" -/* offset=3D455 */ "eist_trans\000other\000Number of Enhanced Intel SpeedS= tep(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00= 000\000\000" -/* offset=3D570 */ "hisi_sccl,ddrc\000" -/* offset=3D585 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write com= mands\000event=3D2\000\00000\000DDRC write commands\000" -/* offset=3D671 */ "uncore_cbox\000" -/* offset=3D683 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cro= ss-core snoop resulted from L3 Eviction which misses in some processor core= \000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from= L3 Eviction which misses in some processor core\000" -/* offset=3D914 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0x= e0\000\00000\000UNC_CBO_HYPHEN\000" -/* offset=3D979 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D1050 */ "hisi_sccl,l3c\000" -/* offset=3D1064 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" -/* offset=3D1144 */ "uncore_imc_free_running\000" -/* offset=3D1168 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" -/* offset=3D1263 */ "uncore_imc\000" -/* offset=3D1274 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" -/* offset=3D1352 */ "uncore_sys_ddr_pmu\000" -/* offset=3D1371 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" -/* offset=3D1444 */ "uncore_sys_ccn_pmu\000" -/* offset=3D1463 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" -/* offset=3D1537 */ "uncore_sys_cmn_pmu\000" -/* offset=3D1556 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" -/* offset=3D1696 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D1718 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D1781 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D1947 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D2011 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D2078 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D2149 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D2243 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D2377 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D2441 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D2509 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D2579 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D2601 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D2623 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D2643 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D0 */ "tool\000" +/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000" +/* offset=3D78 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000" +/* offset=3D145 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000" +/* offset=3D210 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000" +/* offset=3D283 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000" +/* offset=3D425 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000" +/* offset=3D525 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000" +/* offset=3D639 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000" +/* offset=3D712 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000" +/* offset=3D795 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0" +/* offset=3D902 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000" +/* offset=3D1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000" +/* offset=3D1102 */ "default_core\000" +/* offset=3D1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000" +/* offset=3D1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000" +/* offset=3D1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000Attributable Level 3 cache access, read\000" +/* offset=3D1328 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" +/* offset=3D1427 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000" +/* offset=3D1557 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000" +/* offset=3D1672 */ "hisi_sccl,ddrc\000" +/* offset=3D1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000DDRC write commands\000" +/* offset=3D1773 */ "uncore_cbox\000" +/* offset=3D1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted fro= m L3 Eviction which misses in some processor core\000" +/* offset=3D2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000UNC_CBO_HYPHEN\000" +/* offset=3D2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" +/* offset=3D2152 */ "hisi_sccl,l3c\000" +/* offset=3D2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" +/* offset=3D2246 */ "uncore_imc_free_running\000" +/* offset=3D2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" +/* offset=3D2365 */ "uncore_imc\000" +/* offset=3D2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" +/* offset=3D2454 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" +/* offset=3D2546 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" +/* offset=3D2639 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" +/* offset=3D2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 +static const struct compact_pmu_event pmu_events__common_tool[] =3D { +{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000 */ +{ 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000 */ +{ 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000 */ +{ 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000 */ +{ 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= */ +{ 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000 */ +{ 712 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000 */ +{ 795 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000 */ +{ 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000 */ +{ 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000 */ +{ 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000 */ +{ 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000 */ + +}; + +const struct pmu_table_entry pmu_events__common[] =3D { +{ + .entries =3D pmu_events__common_tool, + .num_entries =3D ARRAY_SIZE(pmu_events__common_tool), + .pmu_name =3D { 0 /* tool\000 */ }, +}, +}; + static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 13 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0x8= a\000\00000\000\000 */ -{ 72 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0x8= b\000\00000\000\000 */ -{ 325 }, /* dispatch_blocked.any\000other\000Memory cluster signals to blo= ck micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0x= 20\000\00000\000\000 */ -{ 455 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) T= echnology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000\= 000 */ -{ 131 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40\= 000\00000\000Attributable Level 3 cache access, read\000 */ -{ 226 }, /* segment_reg_loads.any\000other\000Number of segment register l= oads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ +{ 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000 */ +{ 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000 */ +{ 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000 */ +{ 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000 */ +{ 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000Attributable Level 3 cache access, read\000 */ +{ 1328 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 585 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\00= 0event=3D2\000\00000\000DDRC write commands\000 */ +{ 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000DDRC write commands\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 1064 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ +{ 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 914 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\0= 0000\000UNC_CBO_HYPHEN\000 */ -{ 979 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\0= 00\00000\000UNC_CBO_TWO_HYPH\000 */ -{ 683 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core = snoop resulted from L3 Eviction which misses in some processor core\000even= t=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evic= tion which misses in some processor core\000 */ +{ 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000UNC_CBO_HYPHEN\000 */ +{ 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000UNC_CBO_TWO_HYPH\000 */ +{ 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evi= ction which misses in some processor core\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 1274 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ +{ 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 1168 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ +{ 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ =20 }; =20 @@ -92,51 +129,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu[= ] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 0 /* default_core\000 */ }, + .pmu_name =3D { 1102 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 570 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 1672 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 1050 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2152 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 671 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1773 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 1263 /* uncore_imc\000 */ }, + .pmu_name =3D { 2365 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 1144 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2246 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 1696 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 2377 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 2149 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 2243 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 2441 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 2509 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 1781 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 1718 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 2643 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 2579 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 2601 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 2623 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 2078 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 1947 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 2011 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -144,18 +181,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 0 /* default_core\000 */ }, + .pmu_name =3D { 1102 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 1463 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ +{ 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 1556 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ +{ 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 1371 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ +{ 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ =20 }; =20 @@ -163,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 1444 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2546 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 1537 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2639 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 1352 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2454 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -210,6 +247,15 @@ struct pmu_events_map { * table of PMU events. */ const struct pmu_events_map pmu_events_map[] =3D { +{ + .arch =3D "common", + .cpuid =3D "common", + .event_table =3D { + .pmus =3D pmu_events__common, + .num_pmus =3D ARRAY_SIZE(pmu_events__common), + }, + .metric_table =3D {}, +}, { .arch =3D "testarch", .cpuid =3D "testcpu", diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index bb0a5d92df4a..3d2c4e6efeb4 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -292,6 +292,7 @@ class JsonEvent: 'cpu_atom': 'cpu_atom', 'ali_drw': 'ali_drw', 'arm_cmn': 'arm_cmn', + 'tool': 'tool', } return table[unit] if unit in table else f'uncore_{unit.lower()}' =20 @@ -721,6 +722,17 @@ const struct pmu_events_map pmu_events_map[] =3D { \t\t.num_pmus =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu), \t} }, +""") + elif arch =3D=3D 'common': + _args.output_file.write("""{ +\t.arch =3D "common", +\t.cpuid =3D "common", +\t.event_table =3D { +\t\t.pmus =3D pmu_events__common, +\t\t.num_pmus =3D ARRAY_SIZE(pmu_events__common), +\t}, +\t.metric_table =3D {}, +}, """) else: with open(f'{_args.starting_dir}/{arch}/mapfile.csv') as csvfile: @@ -1241,7 +1253,7 @@ def main() -> None: if len(parents) =3D=3D _args.model.split(',')[0].count('/'): # We're testing the correct directory. item_path =3D '/'.join(parents) + ('/' if len(parents) > 0 else = '') + item.name - if 'test' not in item_path and item_path not in _args.model.spli= t(','): + if 'test' not in item_path and 'common' not in item_path and ite= m_path not in _args.model.split(','): continue action(parents, item) if item.is_dir(): @@ -1289,7 +1301,7 @@ struct pmu_table_entry { for item in os.scandir(_args.starting_dir): if not item.is_dir(): continue - if item.name =3D=3D _args.arch or _args.arch =3D=3D 'all' or item.name= =3D=3D 'test': + if item.name =3D=3D _args.arch or _args.arch =3D=3D 'all' or item.name= =3D=3D 'test' or item.name =3D=3D 'common': archs.append(item.name) =20 if len(archs) < 2 and _args.arch !=3D 'none': --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA8D239FD6 for ; Wed, 2 Oct 2024 03:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839246; cv=none; b=UAGJtMSXPZTKDd3HUZXoUwiEWARRHLcgszRX+fWcxza7ivp9kjOYe9rSS0PE36FhBdLGq7xDohcYCOBLHgUiItwaCpAx3C7A1vuai3zW/2GOuz1lUBOJnH9ywKvla0BxABo4ca+fTaFOV9DY+D+CO/aL2RDCBzuqLOyddtyNkYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839246; c=relaxed/simple; bh=U1ihmZxImzymMR83S4d4i4eQ/Rj8mWMZst8NNO7Uu6c=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=pkIuaHlELAteRg0BuW6Kjf4Xh3iFSd1UZ7EMka09+MRU2Qrf3mKxqIXBvRVWxTMW1dNS9gjGDGNbtRY47xaOQxCziHyFpwObjXUbM7dTpjNbWZ4g2CUo4eQLhsnnNLfpnb1YZ+TYgvjwZWXJ+kTIWzZG55w4fE+23q6/C3AQbuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nDpkUB5x; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nDpkUB5x" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e24b43799e9so6268939276.2 for ; Tue, 01 Oct 2024 20:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839244; x=1728444044; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=4m9hxaxVGb2/DjCTUbZ0ZYfS7f+prrXxgLhCXKtfp/w=; b=nDpkUB5x2gLLfkSVi0lUaNtsbsh+JuKeJa/Zr2WIDD6u75bX2rGDPsXas7OnvczQId eHLcLa376FeUyng+NxzE6o9Lctso6pf8GrjscHCrpelqDtvVOaBJpbqGRbzNIe9QY8Tj dleIHsTFXcNzdvMnm3BgVFTnx3ifxk8/DEp8mduS+f/0CPhxEPulewzclP9K2dUlB4sc 1IzqE6ROT4vbwy3t+e/uHv7PP4y4vGhCFLSPyv2wCmDpmrInUP3lQ93seg8Y8M9n10uN lvX/Ua6nSOkUuVjuB9/UGg93yzwFq4mG7/gGZAdW/ut+jMS+7MaeTs09yDMOQwJ+MKZ0 wOcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839244; x=1728444044; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4m9hxaxVGb2/DjCTUbZ0ZYfS7f+prrXxgLhCXKtfp/w=; b=j64CMxnqMcagr7892NvsSogjUwQW5ohvCyQyEHTjzPDLCWnJpLQTm8QSVL31nIY7wd TJiftD3XoiQwIcET0K0KHIL2D+MRHGVoFzBXApcQeUnkgl87pB0Z299dgzHEp5sWaRsk VGeX9idG6lIKWzcFJnag3B/pjPHbH0H5zVcI3si5II3buIaHWEttC6TLZ/zLHp3paAsd RoeqDJFOdYIKzuFXL4WX4hNyshoL7gMi+XG4WceXN1tTGQYzvLcsCCqqQdU7GKRph5T9 liW2R3SLJKJJCJ9x/LtM46DPPOwfD5ZMvjRLy/cFjQVMN6dfnveTYupj7pu61vbYSMrU vDlg== X-Forwarded-Encrypted: i=1; AJvYcCUzFPLlo3x5hFmMqyx3F7aMivWG6EpgCIw0aPASWZPWnIYzEZAseWErZVTLMzJ5xZ016LgH9lAe1O+S1n8=@vger.kernel.org X-Gm-Message-State: AOJu0YzB8lm9QipeZxdp+tqrAvM/U2lG1qy3qNXVNZ45FR/TPkjTVAX5 zMmdDL523s0kStaV1TI5gtZkGSSz1TK6A/E30mUdlyB8CcPqRHPMK8Pqr+hVvSNIPlsOtygbTEF 3SVpwRQ== X-Google-Smtp-Source: AGHT+IGk8tH/JZalGU9H7+VDhh7I7rqK7Uv6KfFFeGynkaBAN4j3eCeW/GXJA5L2Www6c63c9f7yzaeMXMDz X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a05:6902:10c7:b0:e24:a00a:518e with SMTP id 3f1490d57ef6-e263840d766mr9241276.7.1727839243484; Tue, 01 Oct 2024 20:20:43 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:12 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 09/13] perf tool_pmu: Switch to standard pmu functions and json descriptions From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the regular PMU approaches with tool json events to reduce the amount of special tool_pmu code - tool_pmu__config_terms and tool_pmu__for_each_event_cb are removed. Some functions remain, like tool_pmu__str_to_event, as conveniences to metricgroups. Add tool_pmu__skip_event/tool_pmu__num_skip_events to handle the case that tool json events shouldn't appear on certain architectures. This isn't done in jevents.py due to complexity in the empty-pmu-events.c and when all vendor json is built into the tool. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/util/pmu.c | 26 ++++----- tools/perf/util/pmus.c | 4 +- tools/perf/util/tool_pmu.c | 109 +++++++++++-------------------------- tools/perf/util/tool_pmu.h | 12 +--- 4 files changed, 46 insertions(+), 105 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 9228650a62d2..0789758598c0 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1549,9 +1549,6 @@ int perf_pmu__config(struct perf_pmu *pmu, struct per= f_event_attr *attr, { bool zero =3D !!pmu->perf_event_attr_init_default; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__config_terms(attr, head_terms, err); - /* Fake PMU doesn't have proper terms so nothing to configure in attr. */ if (perf_pmu__is_fake(pmu)) return 0; @@ -1664,8 +1661,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->scale =3D 0.0; info->snapshot =3D false; =20 - /* Tool/fake PMU doesn't rewrite terms. */ - if (perf_pmu__is_tool(pmu) || perf_pmu__is_fake(pmu)) + /* Fake PMU doesn't rewrite terms. */ + if (perf_pmu__is_fake(pmu)) goto out; =20 list_for_each_entry_safe(term, h, &head_terms->terms, list) { @@ -1835,8 +1832,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) { if (!name) return false; - if (perf_pmu__is_tool(pmu)) - return tool_pmu__str_to_event(name) !=3D TOOL_PMU__EVENT_NONE; + if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) + return false; if (perf_pmu__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) return true; if (pmu->cpu_aliases_added || !pmu->events_table) @@ -1848,9 +1845,6 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__num_events(); - pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases + pmu->sys_json_aliases; =20 @@ -1861,6 +1855,9 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) else assert(pmu->cpu_json_aliases =3D=3D 0); =20 + if (perf_pmu__is_tool(pmu)) + nr -=3D tool_pmu__num_skip_events(); + return pmu->selectable ? nr + 1 : nr; } =20 @@ -1911,15 +1908,15 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, = bool skip_duplicate_pmus, int ret =3D 0; struct strbuf sb; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__for_each_event_cb(pmu, state, cb); - strbuf_init(&sb, /*hint=3D*/ 0); pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { size_t buf_used, pmu_name_len; =20 + if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(event->name)) + continue; + info.pmu_name =3D event->pmu_name ?: pmu->name; pmu_name_len =3D pmu_deduped_name_len(pmu, info.pmu_name, skip_duplicate_pmus); @@ -2325,9 +2322,6 @@ const char *perf_pmu__name_from_config(struct perf_pm= u *pmu, u64 config) if (!pmu) return NULL; =20 - if (perf_pmu__is_tool(pmu)) - return tool_pmu__event_to_str(config); - pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6e657c44de58..107de86c2637 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -440,6 +440,7 @@ static int perf_pmus__print_pmu_events__callback(void *= vstate, pr_err("Unexpected event %s/%s/\n", info->pmu->name, info->name); return 1; } + assert(info->pmu !=3D NULL || info->name !=3D NULL); s =3D &state->aliases[state->index]; s->pmu =3D info->pmu; #define COPY_STR(str) s->str =3D info->str ? strdup(info->str) : NULL @@ -590,9 +591,6 @@ void perf_pmus__print_raw_pmu_events(const struct print= _callbacks *print_cb, voi int len =3D pmu_name_len_no_suffix(pmu->name); const char *desc =3D "(see 'man perf-list' or 'man perf-record' on how t= o encode it)"; =20 - if (perf_pmu__is_tool(pmu)) - continue; - if (!pmu->is_core) desc =3D NULL; =20 diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index cfdc09dece1e..ea9d50f02520 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -33,101 +33,54 @@ static const char *const tool_pmu__event_names[TOOL_PM= U__EVENT_MAX] =3D { "system_tsc_freq", }; =20 - -const char *tool_pmu__event_to_str(enum tool_pmu_event ev) -{ - if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) - return tool_pmu__event_names[ev]; - - return NULL; -} - -enum tool_pmu_event tool_pmu__str_to_event(const char *str) +bool tool_pmu__skip_event(const char *name __maybe_unused) { - int i; - - tool_pmu__for_each_event(i) { - if (!strcasecmp(str, tool_pmu__event_names[i])) { #if !defined(__aarch64__) - /* The slots event should only appear on arm64. */ - if (i =3D=3D TOOL_PMU__EVENT_SLOTS) - return TOOL_PMU__EVENT_NONE; + /* The slots event should only appear on arm64. */ + if (strcasecmp(name, "slots") =3D=3D 0) + return true; #endif - return i; - } - } - return TOOL_PMU__EVENT_NONE; +#if !defined(__i386__) && !defined(__x86_64__) + /* The system_tsc_freq event should only appear on x86. */ + if (strcasecmp(name, "system_tsc_freq") =3D=3D 0) + return true; +#endif + return false; } =20 -static int tool_pmu__config_term(struct perf_event_attr *attr, - struct parse_events_term *term, - struct parse_events_error *err) +int tool_pmu__num_skip_events(void) { - if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER) { - enum tool_pmu_event ev =3D tool_pmu__str_to_event(term->config); + int num =3D 0; =20 - if (ev =3D=3D TOOL_PMU__EVENT_NONE) - goto err_out; - - attr->config =3D ev; - return 0; - } -err_out: - if (err) { - char *err_str; - - parse_events_error__handle(err, term->err_val, - asprintf(&err_str, - "unexpected tool event term (%s) %s", - parse_events__term_type_str(term->type_term), - term->config) < 0 - ? strdup("unexpected tool event term") - : err_str, - NULL); - } - return -EINVAL; +#if !defined(__aarch64__) + num++; +#endif +#if !defined(__i386__) && !defined(__x86_64__) + num++; +#endif + return num; } =20 -int tool_pmu__config_terms(struct perf_event_attr *attr, - struct parse_events_terms *terms, - struct parse_events_error *err) +const char *tool_pmu__event_to_str(enum tool_pmu_event ev) { - struct parse_events_term *term; - - list_for_each_entry(term, &terms->terms, list) { - if (tool_pmu__config_term(attr, term, err)) - return -EINVAL; - } - - return 0; + if (ev > TOOL_PMU__EVENT_NONE && ev < TOOL_PMU__EVENT_MAX) + return tool_pmu__event_names[ev]; =20 + return NULL; } =20 -int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb) +enum tool_pmu_event tool_pmu__str_to_event(const char *str) { - struct pmu_event_info info =3D { - .pmu =3D pmu, - .event_type_desc =3D "Tool event", - }; int i; =20 + if (tool_pmu__skip_event(str)) + return TOOL_PMU__EVENT_NONE; + tool_pmu__for_each_event(i) { - int ret; - - info.name =3D tool_pmu__event_to_str(i); - info.alias =3D NULL; - info.scale_unit =3D NULL; - info.desc =3D NULL; - info.long_desc =3D NULL; - info.encoding_desc =3D NULL; - info.topic =3D NULL; - info.pmu_name =3D pmu->name; - info.deprecated =3D false; - ret =3D cb(state, &info); - if (ret) - return ret; + if (!strcasecmp(str, tool_pmu__event_names[i])) + return i; } - return 0; + return TOOL_PMU__EVENT_NONE; } =20 bool perf_pmu__is_tool(const struct perf_pmu *pmu) @@ -546,6 +499,8 @@ struct perf_pmu *perf_pmus__tool_pmu(void) .caps =3D LIST_HEAD_INIT(tool.caps), .format =3D LIST_HEAD_INIT(tool.format), }; + if (!tool.events_table) + tool.events_table =3D find_core_events_table("common", "common"); =20 return &tool; } diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h index ecdf316525bb..a60184859080 100644 --- a/tools/perf/util/tool_pmu.h +++ b/tools/perf/util/tool_pmu.h @@ -29,17 +29,11 @@ enum tool_pmu_event { #define tool_pmu__for_each_event(ev) \ for ((ev) =3D TOOL_PMU__EVENT_DURATION_TIME; (ev) < TOOL_PMU__EVENT_MAX; = ev++) =20 -static inline size_t tool_pmu__num_events(void) -{ - return TOOL_PMU__EVENT_MAX - 1; -} - const char *tool_pmu__event_to_str(enum tool_pmu_event ev); enum tool_pmu_event tool_pmu__str_to_event(const char *str); -int tool_pmu__config_terms(struct perf_event_attr *attr, - struct parse_events_terms *terms, - struct parse_events_error *err); -int tool_pmu__for_each_event_cb(struct perf_pmu *pmu, void *state, pmu_eve= nt_callback cb); +bool tool_pmu__skip_event(const char *name); +int tool_pmu__num_skip_events(void); + bool tool_pmu__read_event(enum tool_pmu_event ev, u64 *result); =20 u64 tool_pmu__cpu_slots_per_cycle(void); --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C82C770FB for ; Wed, 2 Oct 2024 03:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839249; cv=none; b=OS+Eg8dnRO8nXuQX4r9ibF/o9W8K3cLR51RISjMyI+dPGDecrMaAGQw4FH8N9IipY4A0LjtoFkqm/Lom/DlnSMuJSZjJgE/l5yq2Aofh5MKHakstR489aWOaRdY8kYI0xVH8AmYVzOuHfEhalNbrUyq55K5R/ov7LcqpCaOAxLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839249; c=relaxed/simple; bh=nevn6QdpTPNOH75n4LVtcfTWGgvd8nbW5G13PSM+U6E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=NHyGv5YPSRL5nzspdOBrC19BgzUMBe3ieayWf7AAwqPLYuPtfmFeolIeaOrur9xy/SyHbw0jwzDnZ3pPfCHS07k2XmdeP1lAZpnVUgJrU6PTlSaBVmOic+KFSt4PmT82pyMRLRQ/ZpAIIWSeowAKbxGBwwJbcHZOExf8ASXbDKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZA6RjM1e; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZA6RjM1e" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e262e764f46so2695599276.1 for ; Tue, 01 Oct 2024 20:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839246; x=1728444046; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=+oj4Y9eHpVg/gdEJT0IT5tvkpqw09K2+hvamqZ+w/kw=; b=ZA6RjM1eg80Tq/8Zbv2nS6AhT2+eNJAHxC8nGebCdIw3ZhDAkD4YlA9JtcDP7Y1UJz 7cLDhNodYRu7O8yip8OLQhcPAldH0YOCzCeJMh2SG5j7OWUkcbjWaBcmmKB8dm8hS9u1 Gc2oMvkm5PIXRsvTtEgFxQ8iVMK6q7bb40N5bs8R+1JM3hpE2iIoaSDau0VDXDtzctY/ u7IWq45nCoh2rCipBKTHQtI+qI23Wvi6k2y6ltWxayF3/PdRBNLvoCsxn31NqpJfhJZ6 F55y4PLOL3fOBQrremUOLI79rKZLoJardcyKrB6bukYhCvoTue5/nFRhA28rPZqKRudv W4Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839246; x=1728444046; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+oj4Y9eHpVg/gdEJT0IT5tvkpqw09K2+hvamqZ+w/kw=; b=wwx8GQ7uu1GPMFpz5dGmYZzPoh7szaZF3sC7uKrCJgLGgvMbnwDmRWhHbPk91lPDA0 7J+HRCy9WS/CF0kCYwNnFeyTN+Uu7WEP2KeDCvt/GhO5wC0nw+OjY6bCwjVKPQ/HFxCt e2yu9CGxnbBN0YKPKkYbMXwq1idCMApEIuW4g40gNSY0NnG5PhxPJZVL+h3wLd4KuomM kQYaj2k70s84bmpsHmrB7HfO5jyFuYNBJxgmq9wBwMF5NExWmtX9iRqrsE57fzpo1mc9 ZbUwnDyOG24L6gDCHdqzIx1yVc+e3n3GsyiEsZ8k21rFYfJcPLhDDD5A4KzZrVm9qWbV cYsw== X-Forwarded-Encrypted: i=1; AJvYcCVwvy4F26OZF0XXjhnfYLVIHWciBfERd6okNZTeUOyCVxXwHYaVWiC+WZ6KUBtjyOHws/33xrieowC88B8=@vger.kernel.org X-Gm-Message-State: AOJu0YyUzB0sskkpR6Bq/uskKEIy0yb0LTLVdy5CXewXDtr9molf2dgi plt0mZ0rRo5LG/hewpgEtAtBI8B6m3h6Dc0deKfZW5DZ+nezu/922BV+V/ZE8/xZNk6MqyXhYSS F0W3prQ== X-Google-Smtp-Source: AGHT+IFLk7ckbsAJqcLwrQRm4BJhemsydjTxufIg28XGBfWDeiOLwgIHId6YTSQJzTWxSJ3Yi6j/wvokeIBY X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a25:8403:0:b0:e0e:c9bc:3206 with SMTP id 3f1490d57ef6-e26383c1058mr1238276.5.1727839246192; Tue, 01 Oct 2024 20:20:46 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:13 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-11-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 10/13] perf tests: Add tool PMU test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure parsing with and without PMU creates events with the expected config values. This ensures the tool.json doesn't get out of sync with tool_pmu_event enum. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + tools/perf/tests/tool_pmu.c | 111 ++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tools/perf/tests/tool_pmu.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 5671ee530019..a771e4928247 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -67,6 +67,7 @@ perf-test-y +=3D sigtrap.o perf-test-y +=3D event_groups.o perf-test-y +=3D symbols.o perf-test-y +=3D util.o +perf-test-y +=3D tool_pmu.o =20 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) perf-test-$(CONFIG_DWARF_UNWIND) +=3D dwarf-unwind.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 470a9709427d..3b30f258c395 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -73,6 +73,7 @@ static struct test_suite *generic_tests[] =3D { &suite__PERF_RECORD, &suite__pmu, &suite__pmu_events, + &suite__tool_pmu, &suite__dso_data, &suite__perf_evsel__roundtrip_name_test, #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 6ea2be86b7bf..1ed76d4156b6 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -83,6 +83,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test); DECLARE_SUITE(syscall_openat_tp_fields); DECLARE_SUITE(pmu); DECLARE_SUITE(pmu_events); +DECLARE_SUITE(tool_pmu); DECLARE_SUITE(attr); DECLARE_SUITE(dso_data); DECLARE_SUITE(dso_data_cache); diff --git a/tools/perf/tests/tool_pmu.c b/tools/perf/tests/tool_pmu.c new file mode 100644 index 000000000000..94d0dd8fd3cb --- /dev/null +++ b/tools/perf/tests/tool_pmu.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "tests.h" +#include "tool_pmu.h" + +static int do_test(enum tool_pmu_event ev, bool with_pmu) +{ + struct evlist *evlist =3D evlist__new(); + struct evsel *evsel; + struct parse_events_error err; + int ret; + char str[128]; + bool found =3D false; + + if (!evlist) { + pr_err("evlist allocation failed\n"); + return TEST_FAIL; + } + + if (with_pmu) + snprintf(str, sizeof(str), "tool/%s/", tool_pmu__event_to_str(ev)); + else + strncpy(str, tool_pmu__event_to_str(ev), sizeof(str)); + + parse_events_error__init(&err); + ret =3D parse_events(evlist, str, &err); + if (ret) { + evlist__delete(evlist); + if (tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + ret =3D TEST_OK; + goto out; + } + + pr_debug("FAILED %s:%d failed to parse event '%s', err %d\n", + __FILE__, __LINE__, str, ret); + parse_events_error__print(&err, str); + ret =3D TEST_FAIL; + goto out; + } + + ret =3D TEST_OK; + if (with_pmu ? (evlist->core.nr_entries !=3D 1) : (evlist->core.nr_entrie= s < 1)) { + pr_debug("FAILED %s:%d Unexpected number of events for '%s' of %d\n", + __FILE__, __LINE__, str, evlist->core.nr_entries); + ret =3D TEST_FAIL; + goto out; + } + + evlist__for_each_entry(evlist, evsel) { + if (perf_pmu__is_tool(evsel->pmu)) { + if (evsel->core.attr.config !=3D ev) { + pr_debug("FAILED %s:%d Unexpected config for '%s', %lld !=3D %d\n", + __FILE__, __LINE__, str, evsel->core.attr.config, ev); + ret =3D TEST_FAIL; + goto out; + } + found =3D true; + } + } + + if (!found && !tool_pmu__skip_event(tool_pmu__event_to_str(ev))) { + pr_debug("FAILED %s:%d Didn't find tool event '%s' in parsed evsels\n", + __FILE__, __LINE__, str); + ret =3D TEST_FAIL; + } + +out: + evlist__delete(evlist); + return ret; +} + +static int test__tool_pmu_without_pmu(struct test_suite *test __maybe_unus= ed, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret =3D do_test(i, /*with_pmu=3D*/false); + + if (ret !=3D TEST_OK) + return ret; + } + return TEST_OK; +} + +static int test__tool_pmu_with_pmu(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int i; + + tool_pmu__for_each_event(i) { + int ret =3D do_test(i, /*with_pmu=3D*/true); + + if (ret !=3D TEST_OK) + return ret; + } + return TEST_OK; +} + +static struct test_case tests__tool_pmu[] =3D { + TEST_CASE("Parsing without PMU name", tool_pmu_without_pmu), + TEST_CASE("Parsing with PMU name", tool_pmu_with_pmu), + { .name =3D NULL, } +}; + +struct test_suite suite__tool_pmu =3D { + .desc =3D "Tool PMU", + .test_cases =3D tests__tool_pmu, +}; --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 10:36:58 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 360047F484 for ; Wed, 2 Oct 2024 03:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839252; cv=none; b=gQoEohaHHKzE9cSBTgC7d/1tYOZE+ByXeS1qYqS3/gJvy+i9vU98G0Kts83YtywH8ngUvg6sRuA9wsr/TwVCpdMBIr5LpLPxterEJ4xq0ZONAI8OJPP5bhAD3XgBMeNuYQlL2kii27f6pX9j+Fo2RlxBLh8NN8lCA7o6I1ZPXoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727839252; c=relaxed/simple; bh=JdNCR1ulxNMz2pf6MYcEoqfuBVHrv4ixaJ7sqqfw6mM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cC/7I5bQdaqYogilFPCi8RLTsqq+Q7fWj/0/X33Vqcoi4vqPgoALKwiNRzrfie8zJACoA+FIxOAV2tLBTFatQ0QwpGYrPGaqJ6IFc/2hu+1kekhZ4c0hgkFs1ebsOAgZbd9CUzB7gLsQtiF0+tOZuVQGjEWoji/OBriLom8883w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2SSoRq87; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2SSoRq87" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db791c42e3so96818337b3.1 for ; Tue, 01 Oct 2024 20:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727839249; x=1728444049; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cuGVv95s4BqWOf7+ejg7OzuLzxZXkVPK8VbbzkDh4D4=; b=2SSoRq87At3TTgp6hnY2KTbXOpWh5pS+zny65PPc0AJN5+SPqJqhF1Cx5T/XnrH1FU /xwyVdyxkwV9agATx/0tvpuvzuefzWCWbec3GRYyKFy/ItikmIrSD8rrhYQwB0XmygBT 7yx2hkIKzT7G9DNnZ2GSgcSYmORA1Jp1iPwqXFbz1TSCzGFgQTDrtVbZaucD3dufr3v5 8+EdNwlLlEX5pkGZLcoo8C8rw3kgq1o9zLPuWS+CVduCt+Z/dPBg/bWvlAOS60M17q2x OQqY1erEf0YKEG+zlzAY/d2fY6dSjeIiPIHOkQIRIihW9iVVGYEqW0EHtjb5pDL2Y1Ic rtuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727839249; x=1728444049; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cuGVv95s4BqWOf7+ejg7OzuLzxZXkVPK8VbbzkDh4D4=; b=wzNBJIT2fM7qbCDnTynveoV619pjsnMKHFmnkBe8D80b2Mgs5PXdPHliOdArHV+CXP u37HP7Kaa79f4ExyYk3npOG1iIrSL/+DPRY19Sfp5wYK/okLwvCWQ8eRgOSD4dKZNuac /QLoypWajOeYXWhLCJ0R4j8hhmN3fggZjZNodaJKpu2Jw42EafM2i35inI7657zIy2Gp Oy2lz432CZx0FNTpKIZwDHzdTbWpERUH1c1gNYBMIRNxpmVYFuycb/tmrb+KPsa1X/aM ciGtKna69LgBk6WBIqHRH8QXhaTX1/zKTnbev8gzy4jd4DO7vDkdoR4rUuzFxlIplGR+ ptXQ== X-Forwarded-Encrypted: i=1; AJvYcCX9jIHNyFFSinxkqOVO+PUTflRVlDEqgVgbTQ4xks/J/4FejL9h87W6bOh1XUr8HVupsXumvjB/8/cHI/I=@vger.kernel.org X-Gm-Message-State: AOJu0YwM/fpzz4UDetP3x4tlqHadx/ocM2tS40Cj6ITm7ppq9MLbaGmi 2hIbbsy6m5ZUhsBf+w8J8xbJd2KYf0YlewRh3cPQ5G/5qRNewWjFosC2WuM4PinmCbHr/JtqRoa mVugiMQ== X-Google-Smtp-Source: AGHT+IFPoiL49NsIoLkZbuSyJPAUeXCd6TUoiSYiqWtfPUOHUR/WptSKjNYv8F69kJ4N5uXOBZc5LpBCvNSi X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:ffa1:6d00:2acb:535f]) (user=irogers job=sendgmr) by 2002:a25:ab61:0:b0:e0b:a712:2ceb with SMTP id 3f1490d57ef6-e26383c0975mr8633276.5.1727839248782; Tue, 01 Oct 2024 20:20:48 -0700 (PDT) Date: Tue, 1 Oct 2024 20:20:14 -0700 In-Reply-To: <20241002032016.333748-1-irogers@google.com> Message-Id: <20241002032016.333748-12-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241002032016.333748-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v3 11/13] perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Weilin Wang , Ravi Bangoria , Sandipan Das , Xu Yang , Benjamin Gray , Athira Jajeev , Howard Chu , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , "Steinar H. Gunderson" , Ze Gao , Dominique Martinet , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The hwmon sysfs ABI is defined in Documentation/hwmon/sysfs-interface.rst. Create a PMU that reads the hwmon input and can be used in `perf stat` and metrics much as an uncore PMU can. For example, the following shows reading the CPU temperature and 2 fan speeds alongside the uncore frequency: ``` $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M = UNCORE_FREQ -I 1000 1.001153138 52.00 'C temp_cpu 1.001153138 2,588 rpm fan1 1.001153138 2,482 rpm hwmon_thinkpad/fan2/ 1.001153138 8 tool/num_cpus_online/ 1.001153138 1,077,101,397 UNC_CLOCK.SOCKET #= 1.08 UNCORE_FREQ 1.001153138 1,012,773,595 duration_time ... ``` The PMUs are named from /sys/class/hwmon/hwmon/name and have an alias of hwmon. The events are naned using the _label files as well as the prefix, the latter guaranteed to be unique. In `perf list` the other hwmon files are used to give a richer description, for example: ``` hwmon: temp1 [Temperature in unit acpitz named temp1. Unit: hwmon_acpitz] in0 [Voltage in unit bat0 named in0. Unit: hwmon_bat0] temp_core_0 OR temp2 [Temperature in unit coretemp named Core 0. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] temp_core_1 OR temp3 [Temperature in unit coretemp named Core 1. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] ... temp_package_id_0 OR temp1 [Temperature in unit coretemp named Package id 0. crit=3D100'C,max= =3D100'C crit_alarm=3D0'C. Unit: hwmon_coretemp] temp1 [Temperature in unit iwlwifi_1 named temp1. Unit: hwmon_iwlwifi_1] temp_composite OR temp1 [Temperature in unit nvme named Composite. alarm=3D0'C,crit=3D86.85'= C,max=3D75.85'C, min=3D-273.15'C. Unit: hwmon_nvme] temp_sensor_1 OR temp2 [Temperature in unit nvme named Sensor 1. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] temp_sensor_2 OR temp3 [Temperature in unit nvme named Sensor 2. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] fan1 [Fan in unit thinkpad named fan1. Unit: hwmon_thinkpad] fan2 [Fan in unit thinkpad named fan2. Unit: hwmon_thinkpad] ... temp_cpu OR temp1 [Temperature in unit thinkpad named CPU. Unit: hwmon_thinkpad] temp_gpu OR temp2 [Temperature in unit thinkpad named GPU. Unit: hwmon_thinkpad] curr1 [Current in unit ucsi_source_psy_usbc000_0 named curr1. max=3D1.5A. = Unit: hwmon_ucsi_source_psy_usbc000_0] in0 [Voltage in unit ucsi_source_psy_usbc000_0 named in0. max=3D5V,min= =3D5V. Unit: hwmon_ucsi_source_psy_usbc000_0] ``` As there may be multiple hwmon devices a range of PMU types are reserved for their use and to identify the PMU as belonging to the hwmon types. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 9 + tools/perf/util/hwmon_pmu.c | 818 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 154 +++++++ tools/perf/util/pmu.c | 20 + tools/perf/util/pmu.h | 2 + tools/perf/util/pmus.c | 2 + 7 files changed, 1006 insertions(+) create mode 100644 tools/perf/util/hwmon_pmu.c create mode 100644 tools/perf/util/hwmon_pmu.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index fa508e113dd0..9eb8b1c3df94 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -83,6 +83,7 @@ perf-util-y +=3D pmu.o perf-util-y +=3D pmus.o perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.o +perf-util-y +=3D hwmon_pmu.o perf-util-y +=3D tool_pmu.o perf-util-y +=3D svghelper.o perf-util-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index e6fdbbb3398e..e1ad19669549 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -50,6 +50,7 @@ #include "off_cpu.h" #include "pmu.h" #include "pmus.h" +#include "hwmon_pmu.h" #include "tool_pmu.h" #include "rlimit.h" #include "../perf-sys.h" @@ -1671,6 +1672,9 @@ int evsel__read_counter(struct evsel *evsel, int cpu_= map_idx, int thread) if (evsel__is_tool(evsel)) return evsel__tool_pmu_read(evsel, cpu_map_idx, thread); =20 + if (evsel__is_hwmon(evsel)) + return evsel__hwmon_pmu_read(evsel, cpu_map_idx, thread); + if (evsel__is_retire_lat(evsel)) return evsel__read_retire_lat(evsel, cpu_map_idx, thread); =20 @@ -2108,6 +2112,11 @@ static int evsel__open_cpu(struct evsel *evsel, stru= ct perf_cpu_map *cpus, start_cpu_map_idx, end_cpu_map_idx); } + if (evsel__is_hwmon(evsel)) { + return evsel__hwmon_pmu_open(evsel, threads, + start_cpu_map_idx, + end_cpu_map_idx); + } =20 for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c new file mode 100644 index 000000000000..142584018a4f --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,818 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "counts.h" +#include "debug.h" +#include "evsel.h" +#include "hashmap.h" +#include "hwmon_pmu.h" +#include "pmu.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { + NULL, + "cpu", + "curr", + "energy", + "fan", + "humidity", + "in", + "intrusion", + "power", + "pwm", + "temp", +}; + +static const char *const hwmon_units[HWMON_TYPE_MAX] =3D { + NULL, + "V", /* cpu */ + "A", /* curr */ + "J", /* energy */ + "rpm", /* fan */ + "%", /* humidity */ + "V", /* in */ + "", /* intrusion */ + "W", /* power */ + "Hz", /* pwm */ + "'C", /* temp */ +}; + +const char * const hwmon_item_strs[HWMON_ITEM__MAX] =3D { + NULL, + "accuracy", + "alarm", + "auto_channels_temp", + "average", + "average_highest", + "average_interval", + "average_interval_max", + "average_interval_min", + "average_lowest", + "average_max", + "average_min", + "beep", + "cap", + "cap_hyst", + "cap_max", + "cap_min", + "crit", + "crit_hyst", + "div", + "emergency", + "emergency_hist", + "enable", + "fault", + "freq", + "highest", + "input", + "label", + "lcrit", + "lcrit_hyst", + "lowest", + "max", + "max_hyst", + "min", + "min_hyst", + "mod", + "offset", + "pulses", + "rated_max", + "rated_min", + "reset_history", + "target", + "type", + "vid", +}; + +struct hwmon_pmu { + struct perf_pmu pmu; + struct hashmap events; + int hwmon_dir_fd; +}; + +/** + * union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key + * represents an event. + * + * Related hwmon files start that this key represents. + */ +union hwmon_pmu_event_key { + long type_and_num; + struct { + int num :16; + enum hwmon_type type :8; + }; +}; + +/** + * struct hwmon_pmu_event_value: Value in hwmon_pmu->events. + * + * Hwmon files are of the form _ and may have a suffix + * _alarm. + */ +struct hwmon_pmu_event_value { + /** @items: which item files are present. */ + DECLARE_BITMAP(items, HWMON_ITEM__MAX); + /** @alarm_items: which item files are present. */ + DECLARE_BITMAP(alarm_items, HWMON_ITEM__MAX); + /** @label: contents of _label if present. */ + char *label; + /** @name: name computed from label of the form _