From nobody Sat Feb 7 23:06:17 2026 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 CAB045025E for ; Sat, 7 Sep 2024 05:08:43 +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=1725685725; cv=none; b=J10LlRtANr/UQ4Rz5vjUUvIntb0ItCNKgejTqSB686+Mrfrdiov+ajXzZMwN245EK4IsOqVy3Sk9E5rAlRZwSPMNX2upcWpsAZ5cjvTsiCumrKHF210X6vOsY6QC9BnZtNLkA/o5atYHGAb/+Gun+6GdJur15mj2cRbu31OpjEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685725; c=relaxed/simple; bh=GtXRyRAclVPuKyzrz5Y0RxXirN/zDK2r6Wx7Lfe/Aic=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=htZUosPrsr+f1BVJjSIXNnjc0vbXdBpnjoUDk91dvEsqINUTuMKZPUS2YtO5oPBiVZbIwW/xsQEafzdOd0IzoywIw9d5o3j551JHO85v+e1GWA3yjDiKD4izDgcE0CabjER+CEk8myGz71RKv2tHVa9gC76mCWbd0htlllEGuSA= 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=xHNgr0SV; 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="xHNgr0SV" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d4f52a4069so102142907b3.3 for ; Fri, 06 Sep 2024 22:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685723; x=1726290523; 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=8ApYaFx0+sxUWqA8R+JFTFM43Yl04Vb2u4ryemp0VHs=; b=xHNgr0SVPVKyRp865NREJy4AX9c3abPTA1J+ykmhjnLVoEaypehL0I/MVbRD55IHjx i+E+NqEUaNR84rWMq70+TqdJ+Nw47i9zfBEKTaNYJ18wzFnFobRgyKv96rmku4G8Xtm/ WUh5nDhzB79gZ9aIum9NsTmOHpIoi+i/oGRjyZv6T3c7DvfgjjeqqN2OndFR/I71ejKC xQ/cCfYfBU0LsWABtJs87iN3KkQCnhRX3APyBZ9u/kNEnARuQ3PUY6EuyLjXVDW21v2f xPmPZxnDDMHwoZzAdPsQ3hMlz5wHI6i9ySvFYxz6sbGV+VAJJ2uQOlEYeIhO/IEpRdWo a9HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685723; x=1726290523; 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=8ApYaFx0+sxUWqA8R+JFTFM43Yl04Vb2u4ryemp0VHs=; b=v4+FLxK7gjmgdzQiZ6hsmYs6vTHh+1VoqSjzVUNFx1ZLHRoqXVmhx01z7rkdWBisuB KWfE30j4d39+0V1YLRJrGFlfZZhty9Sj7ZQRr0iWRmZsS026Kd7//9qvxDvJ3to8friL I5JH0SdTOJ88uaAHI7ZOXRnygiwnQoEAipepUD0ZJpYxCG3ZycjES2kY2UyKyUVN49JU SwQY0et2/JX4F5DuGtryZjpJpXIvHqDWISs3ymI/b4jYaHU24yKZJWqqecThiyPFPRIR pIaV9YlLqXwEu09VlV9B/Tzlx/GkXu2pOwa4SCjj3Isqabcimbtv24HuR420exzzckf6 QnRw== X-Forwarded-Encrypted: i=1; AJvYcCWarQSt+AXnjFkENeddkR2BEGgcEqtLUIKl19qFyFN9GVKKPfIuY7RSKvPisWawLmloQyvZfLyX3HEyU04=@vger.kernel.org X-Gm-Message-State: AOJu0YwQvPruxbtL094Y5pPnGnf2VqN5ouREf18PcfOwxE8hvNGT6bqZ bFNXtDxuvFyiydHv4l5mg+UtZUjsPYFRvUhbx6QKJ3EDXwY6uFp/0+67ta7BNWBdMjux5mJ8RCt pRNyILA== X-Google-Smtp-Source: AGHT+IEP84F/M2rTb3JNZ7bCbxgU/+jIK+b9LqWkHujq8bu5u0u7fEm7frKSL7le+5SzKQ0eekBwy8lqkNNo X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:6902:4d1:b0:e0e:a784:2957 with SMTP id 3f1490d57ef6-e1d34865f70mr12294276.1.1725685722506; Fri, 06 Sep 2024 22:08:42 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:16 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 01/15] perf list: Avoid potential out of bounds memory read 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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" If a desc string is 0 length then -1 will be out of bounds, add a check. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 82cb4b1010aa..65b8cba324be 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -173,7 +173,7 @@ static void default_print_event(void *ps, const char *p= mu_name, const char *topi if (pmu_name && strcmp(pmu_name, "default_core")) { desc_len =3D strlen(desc); desc_len =3D asprintf(&desc_with_unit, - desc[desc_len - 1] !=3D '.' + desc_len > 0 && desc[desc_len - 1] !=3D '.' ? "%s. Unit: %s" : "%s Unit: %s", desc, pmu_name); } --=20 2.46.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 05D6C130499 for ; Sat, 7 Sep 2024 05:08:45 +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=1725685728; cv=none; b=sU69/7huIFW3RG3msAGX2eGtDrfMD228ZFSIreRnE9CiymQfKILU89yLrrRAgGU26mT8XMi5D6+99cdNSbb8oYtlMkzaJwn2OI1T2t/murgtFufxl71SQwF53RNyhB0oMM16fPleb0lfaakr62uOFf6UJuOW/NEpTJjl6WIzD4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685728; c=relaxed/simple; bh=2GbShflx1OPw5Hbs1ieTu8gN+brQN8XBGn8Xey2e14o=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=fG92CnQMYBhyr8iXk3nTL5TYDUy8qI4oVAisAgVZ3b06QkJmbGWLqch1M1ZnBnpF8HxIdYD1KfN7byBReeKNlbaIZaKgF8CoavaY8D6bVEMnwX7h5jcIkQ3GxKv+nK7zSGgy/enag80cNzK5eFqp5ocKaIQ6jiRkXda9i6KbTkI= 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=tx/aTRk5; 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="tx/aTRk5" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d3e062dbeeso70670347b3.0 for ; Fri, 06 Sep 2024 22:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685725; x=1726290525; 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=4qvnGpoqY98o8DkcV53COwqz0b4ydGD421TbHN+KxuU=; b=tx/aTRk5O4VXSZbhVrcjA0Q2KNdxlaFmE4yr60imD7Bhrbs8MhbxePi74+GY9BV914 Y6QFTLbW6gbu0DJVbsn+2NDIL6453r2+f3vIyCX5ahQFF852MZ/y7xDKKP2YZ2V7vf73 0ToLEFfCwyBvXICRZ91AS5VSamJDVC/i7lG2rlcmHLt3M/qRzEiXhRKrMMxzNzuRD+R9 zV2bgz4O2AIpg9d+nIDeVypgzMSVFFbiF6jwPvJOEDJEXQXr5W2Twdr8vZ5AccCVNFjy Beozr+iOIj+X3uOnRqOEDMIJzRxkEC8CmVU2gosUKiKzfNlR/ymIr/SxoMALrfdRA+FQ MxnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685725; x=1726290525; 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=4qvnGpoqY98o8DkcV53COwqz0b4ydGD421TbHN+KxuU=; b=lGgZDJ+1Lm5P/gVumXGhaCdnF+QzlfEyWRW7MMMjJGdIgf8uAGzr2Uk9xyAOZCXbsY 06XLBRlJy/dvg6SvhBJezyQ91XXPVVzsPgxNWe8h1iXsMJKIbgY7CC252/gDBHymKbC8 KBndQUxw7hCCGzTEJcKhUMso4Wa1JE+EFxLZg7GbDMLesom2cmm3xVvKhvVt1nYwZPZh RwRBHDvC1V+GWKTK0H9hbvYJxQ+4Kop0pyuIdTIIlH9JY+j1kwUMAAxBhR6N7taT/2kr LMfMTHPFA2a/fbLt8JcPb2CxdehPjoS8HNaNABS/mlfyl8tDOcFPoaTuVNPth0bnOXz2 B20w== X-Forwarded-Encrypted: i=1; AJvYcCXEXUu8j2Xi0j9N+ZYMYFiMI/MsXlECze+XvzmLTEFOAWCrkqrMlPey8yG9wGeFSZ9KtNCE4r/ji3F97pY=@vger.kernel.org X-Gm-Message-State: AOJu0YxmMwPIBXB30B8xkw5huwq7vifKsgoj2OeMiwBP30RYrvh3Rndr iWkwlwEWTAaUhjdBgJZb/Cz0MVZ4C+Yfgdto0A8JHFEf4+0NaBjO12KvllobUuSYOTGkjRpYHHC pNhzBdQ== X-Google-Smtp-Source: AGHT+IHXWJ46JY3jkQNVeV0QMNhgFfqcqA+JJTd2bTX6fyr7eZn1QoFO0U14ouPnFLalZCsSfINQHClIb6Lf X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:4b85:b0:6a1:741b:b723 with SMTP id 00721157ae682-6db2606a8fbmr6772437b3.5.1725685724868; Fri, 06 Sep 2024 22:08:44 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:17 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 02/15] perf pmus: Fake PMU clean up 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 passing a fake PMU around, just pass that the fake PMU should be used - true when doing testing. Move the fake PMU into pmus.[ch] and try to abstract the PMU's properties in pmu.c, ie so there is less "if fake_pmu" in non-PMU code. Give the fake PMU a made up type number. Signed-off-by: Ian Rogers --- tools/perf/tests/parse-events.c | 4 ++-- tools/perf/tests/pmu-events.c | 12 +++++------- tools/perf/util/metricgroup.c | 10 +++++----- tools/perf/util/parse-events.c | 33 +++++++++++++++++---------------- tools/perf/util/parse-events.h | 8 ++++---- tools/perf/util/pmu.c | 21 +++++++++++++++------ tools/perf/util/pmu.h | 7 ++++--- tools/perf/util/pmus.c | 11 +++++++++++ tools/perf/util/pmus.h | 1 + 9 files changed, 64 insertions(+), 43 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index edc2adcf1bae..a9a77dfe0e97 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -2500,7 +2500,7 @@ static int test_event(const struct evlist_test *e) return TEST_FAIL; } parse_events_error__init(&err); - ret =3D __parse_events(evlist, e->name, /*pmu_filter=3D*/NULL, &err, /*fa= ke_pmu=3D*/NULL, + ret =3D __parse_events(evlist, e->name, /*pmu_filter=3D*/NULL, &err, /*fa= ke_pmu=3D*/false, /*warn_if_reordered=3D*/true, /*fake_tp=3D*/true); if (ret) { pr_debug("failed to parse event '%s', err %d\n", e->name, ret); @@ -2529,7 +2529,7 @@ static int test_event_fake_pmu(const char *str) =20 parse_events_error__init(&err); ret =3D __parse_events(evlist, str, /*pmu_filter=3D*/NULL, &err, - &perf_pmu__fake, /*warn_if_reordered=3D*/true, + /*fake_pmu=3D*/true, /*warn_if_reordered=3D*/true, /*fake_tp=3D*/true); if (ret) { pr_debug("failed to parse event '%s', err %d\n", diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index ff3e7bc0a77f..db004d26fcb0 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -819,8 +819,7 @@ static bool is_number(const char *str) return errno =3D=3D 0 && end_ptr !=3D str; } =20 -static int check_parse_id(const char *id, struct parse_events_error *error, - struct perf_pmu *fake_pmu) +static int check_parse_id(const char *id, struct parse_events_error *error) { struct evlist *evlist; int ret; @@ -841,7 +840,7 @@ static int check_parse_id(const char *id, struct parse_= events_error *error, for (cur =3D strchr(dup, '@') ; cur; cur =3D strchr(++cur, '@')) *cur =3D '/'; =20 - ret =3D __parse_events(evlist, dup, /*pmu_filter=3D*/NULL, error, fake_pm= u, + ret =3D __parse_events(evlist, dup, /*pmu_filter=3D*/NULL, error, /*fake_= pmu=3D*/true, /*warn_if_reordered=3D*/true, /*fake_tp=3D*/false); free(dup); =20 @@ -855,7 +854,7 @@ static int check_parse_fake(const char *id) int ret; =20 parse_events_error__init(&error); - ret =3D check_parse_id(id, &error, &perf_pmu__fake); + ret =3D check_parse_id(id, &error); parse_events_error__exit(&error); return ret; } @@ -1051,9 +1050,8 @@ static int test__parsing_fake_callback(const struct p= mu_metric *pm, } =20 /* - * Parse all the metrics for current architecture, - * or all defined cpus via the 'fake_pmu' - * in parse_events. + * Parse all the metrics for current architecture, or all defined cpus via= the + * 'fake_pmu' in parse_events. */ static int test__parsing_fake(struct test_suite *test __maybe_unused, int subtest __maybe_unused) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 69f6a46402c3..4dff3e925a47 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1436,7 +1436,7 @@ static int build_combined_expr_ctx(const struct list_= head *metric_list, * parse_ids - Build the event string for the ids and parse them creating = an * evlist. The encoded metric_ids are decoded. * @metric_no_merge: is metric sharing explicitly disabled. - * @fake_pmu: used when testing metrics not supported by the current CPU. + * @fake_pmu: use a fake PMU when testing metrics not supported by the cur= rent CPU. * @ids: the event identifiers parsed from a metric. * @modifier: any modifiers added to the events. * @group_events: should events be placed in a weak group. @@ -1444,7 +1444,7 @@ static int build_combined_expr_ctx(const struct list_= head *metric_list, * the overall list of metrics. * @out_evlist: the created list of events. */ -static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, +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], struct evlist **out_evlist) @@ -1528,7 +1528,7 @@ static int parse_groups(struct evlist *perf_evlist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, - struct perf_pmu *fake_pmu, + bool fake_pmu, struct rblist *metric_events_list, const struct pmu_metrics_table *table) { @@ -1703,7 +1703,7 @@ int metricgroup__parse_groups(struct evlist *perf_evl= ist, =20 return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_mer= ge, metric_no_threshold, user_requested_cpu_list, system_wide, - /*fake_pmu=3D*/NULL, metric_events, table); + /*fake_pmu=3D*/false, metric_events, table); } =20 int metricgroup__parse_groups_test(struct evlist *evlist, @@ -1717,7 +1717,7 @@ int metricgroup__parse_groups_test(struct evlist *evl= ist, /*metric_no_threshold=3D*/false, /*user_requested_cpu_list=3D*/NULL, /*system_wide=3D*/false, - &perf_pmu__fake, metric_events, table); + /*fake_pmu=3D*/true, metric_events, table); } =20 struct metricgroup__has_metric_data { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index fab01ba54e34..081ceff467f2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1478,8 +1478,8 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, } =20 /* Look for event names in the terms and rewrite into format based terms.= */ - if (!parse_state->fake_pmu && perf_pmu__check_alias(pmu, &parsed_terms, - &info, &alias_rewrote_terms, err)) { + if (perf_pmu__check_alias(pmu, &parsed_terms, + &info, &alias_rewrote_terms, err)) { parse_events_terms__exit(&parsed_terms); return -EINVAL; } @@ -1515,8 +1515,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, return -ENOMEM; } =20 - if (!parse_state->fake_pmu && - perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { + if (perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { free_config_terms(&config_terms); parse_events_terms__exit(&parsed_terms); return -EINVAL; @@ -1536,11 +1535,6 @@ static int parse_events_add_pmu(struct parse_events_= state *parse_state, =20 evsel->percore =3D config_term_percore(&evsel->config_terms); =20 - if (parse_state->fake_pmu) { - parse_events_terms__exit(&parsed_terms); - return 0; - } - parse_events_terms__exit(&parsed_terms); free((char *)evsel->unit); evsel->unit =3D strdup(info.unit); @@ -1616,13 +1610,13 @@ int parse_events_multi_pmu_add(struct parse_events_= state *parse_state, } =20 if (parse_state->fake_pmu) { - if (!parse_events_add_pmu(parse_state, list, parse_state->fake_pmu, &par= sed_terms, + if (!parse_events_add_pmu(parse_state, list, perf_pmus__fake_pmu(), &par= sed_terms, /*auto_merge_stats=3D*/true)) { struct strbuf sb; =20 strbuf_init(&sb, /*hint=3D*/ 0); parse_events_terms__to_strbuf(&parsed_terms, &sb); - pr_debug("%s -> %s/%s/\n", event_name, "fake_pmu", sb.buf); + pr_debug("%s -> fake/%s/\n", event_name, sb.buf); strbuf_release(&sb); ok++; } @@ -1656,11 +1650,18 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pa= rse_events_state *parse_state INIT_LIST_HEAD(*listp); =20 /* Attempt to add to list assuming event_or_pmu is a PMU name. */ - pmu =3D parse_state->fake_pmu ?: perf_pmus__find(event_or_pmu); + pmu =3D perf_pmus__find(event_or_pmu); if (pmu && !parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_t= erms, /*auto_merge_stats=3D*/false)) return 0; =20 + if (parse_state->fake_pmu) { + if (!parse_events_add_pmu(parse_state, *listp, perf_pmus__fake_pmu(), + const_parsed_terms, + /*auto_merge_stats=3D*/false)) + return 0; + } + pmu =3D NULL; /* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */ while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { @@ -1961,8 +1962,8 @@ static int evsel__compute_group_pmu_name(struct evsel= *evsel, } } } - /* Assign the actual name taking care that the fake PMU lacks a name. */ - evsel->group_pmu_name =3D strdup(group_pmu_name ?: "fake"); + /* Record computed name. */ + evsel->group_pmu_name =3D strdup(group_pmu_name); return evsel->group_pmu_name ? 0 : -ENOMEM; } =20 @@ -2124,7 +2125,7 @@ static int parse_events__sort_events_and_fix_groups(s= truct list_head *list) } =20 int __parse_events(struct evlist *evlist, const char *str, const char *pmu= _filter, - struct parse_events_error *err, struct perf_pmu *fake_pmu, + struct parse_events_error *err, bool fake_pmu, bool warn_if_reordered, bool fake_tp) { struct parse_events_state parse_state =3D { @@ -2343,7 +2344,7 @@ int parse_events_option(const struct option *opt, con= st char *str, =20 parse_events_error__init(&err); ret =3D __parse_events(*args->evlistp, str, args->pmu_filter, &err, - /*fake_pmu=3D*/NULL, /*warn_if_reordered=3D*/true, + /*fake_pmu=3D*/false, /*warn_if_reordered=3D*/true, /*fake_tp=3D*/false); =20 if (ret) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index b735cd9e0acf..bfbf391451d9 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -31,14 +31,14 @@ int parse_events_option(const struct option *opt, const= char *str, int unset); int parse_events_option_new_evlist(const struct option *opt, const char *s= tr, int unset); __attribute__((nonnull(1, 2, 4))) int __parse_events(struct evlist *evlist, const char *str, const char *pmu= _filter, - struct parse_events_error *error, struct perf_pmu *fake_pmu, + struct parse_events_error *error, bool fake_pmu, bool warn_if_reordered, bool fake_tp); =20 __attribute__((nonnull(1, 2, 3))) static inline int parse_events(struct evlist *evlist, const char *str, struct parse_events_error *err) { - return __parse_events(evlist, str, /*pmu_filter=3D*/NULL, err, /*fake_pmu= =3D*/NULL, + return __parse_events(evlist, str, /*pmu_filter=3D*/NULL, err, /*fake_pmu= =3D*/false, /*warn_if_reordered=3D*/true, /*fake_tp=3D*/false); } =20 @@ -150,8 +150,8 @@ struct parse_events_state { struct parse_events_terms *terms; /* Start token. */ int stoken; - /* Special fake PMU marker for testing. */ - struct perf_pmu *fake_pmu; + /* Use the fake PMU marker for testing. */ + bool fake_pmu; /* Skip actual tracepoint processing for testing. */ bool fake_tp; /* If non-null, when wildcard matching only match the given PMU. */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0b38c51bd6eb..50e2e7abffab 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -30,10 +30,6 @@ #include "util/evsel_config.h" #include =20 -struct perf_pmu perf_pmu__fake =3D { - .name =3D "fake", -}; - #define UNIT_MAX_LEN 31 /* max length for event unit name */ =20 enum event_source { @@ -1173,6 +1169,11 @@ struct perf_pmu *perf_pmu__create_placeholder_core_p= mu(struct list_head *core_pm return pmu; } =20 +static bool perf_pmu__is_fake(const struct perf_pmu *pmu) +{ + return pmu->type =3D=3D PERF_PMU_TYPE_FAKE; +} + void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) { struct perf_pmu_format *format; @@ -1183,7 +1184,7 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *= pmu) pmu->formats_checked =3D true; =20 /* fake pmu doesn't have format list */ - if (pmu =3D=3D &perf_pmu__fake) + if (perf_pmu__is_fake(pmu)) return; =20 list_for_each_entry(format, &pmu->format, list) { @@ -1511,6 +1512,10 @@ int perf_pmu__config(struct perf_pmu *pmu, struct pe= rf_event_attr *attr, { bool zero =3D !!pmu->perf_event_attr_init_default; =20 + /* Fake PMU doesn't have proper terms so nothing to configure in attr. */ + if (perf_pmu__is_fake(pmu)) + return 0; + return perf_pmu__config_terms(pmu, attr, head_terms, zero, err); } =20 @@ -1619,6 +1624,10 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, stru= ct 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)) + goto out; + list_for_each_entry_safe(term, h, &head_terms->terms, list) { alias =3D pmu_find_alias(pmu, term); if (!alias) @@ -1641,7 +1650,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ list_del_init(&term->list); parse_events_term__delete(term); } - +out: /* * if no unit or scale found in aliases, then * set defaults as for evsel diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b2d3fd291f02..d6f702e55a05 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -36,6 +36,10 @@ struct perf_pmu_caps { struct list_head list; }; =20 +enum { + PERF_PMU_TYPE_FAKE =3D 0xFFFFFFFF, +}; + /** * struct perf_pmu */ @@ -173,9 +177,6 @@ struct perf_pmu { struct perf_mem_event *mem_events; }; =20 -/** @perf_pmu__fake: A special global PMU used for testing. */ -extern struct perf_pmu perf_pmu__fake; - struct perf_pmu_info { const char *unit; double scale; diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 3fcabfd8fca1..864cbfa1f960 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -720,3 +720,14 @@ struct perf_pmu *perf_pmus__add_test_pmu(int test_sysf= s_dirfd, const char *name) */ return perf_pmu__lookup(&other_pmus, test_sysfs_dirfd, name, /*eager_load= =3D*/true); } + +struct perf_pmu *perf_pmus__fake_pmu(void) +{ + static struct perf_pmu fake =3D { + .name =3D "fake", + .type =3D PERF_PMU_TYPE_FAKE, + .format =3D LIST_HEAD_INIT(fake.format), + }; + + return &fake; +} diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index bdbff02324bb..e1742b56eec7 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -30,5 +30,6 @@ bool perf_pmus__supports_extended_type(void); char *perf_pmus__default_pmu_name(void); =20 struct perf_pmu *perf_pmus__add_test_pmu(int test_sysfs_dirfd, const char = *name); +struct perf_pmu *perf_pmus__fake_pmu(void); =20 #endif /* __PMUS_H */ --=20 2.46.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 46716146000 for ; Sat, 7 Sep 2024 05:08:48 +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=1725685729; cv=none; b=eD/fjl0ElsQa3vjIhRoFtL9Awr6QQQ5clqiKaEuc1dd+xKkbmz8qi42r6LnMDVqhogII7/OUVbK1K04sEgWB6vNnVau1/63Pewl+REMaGXsv3prdE3s8E8zZ0RD61D9rk6Nfgm/CuSU47kL4hg7bLD99KO/umfZzZyAoxaalv4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685729; c=relaxed/simple; bh=WFu+5y8QRKtMZSfoRCTOTpmMOyl9HcFrp2FvXFrJg7w=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gX9hwALFVuGn7QEvvMZCw/S45y7IaA4Ut2UZH66JtSOpN1eCCH7erTd49IGw9D1sUQ2k7YZMWGFDPNE/6mOxfOYwbvLWoSvTlGS2DOKXDvEgD24KP4iTrxW3jWgDCJYgIn4MdcarRaicuVExYHRro0sSUvHeKd05vgc+KaSUb+Q= 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=BtHnvi7b; 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="BtHnvi7b" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d475205628so89781067b3.0 for ; Fri, 06 Sep 2024 22:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685727; x=1726290527; 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=gnJ5bQcxWcBEjqFa4fDewaQZBBcymf58nuYFxDuPtGE=; b=BtHnvi7byvG0m5YvfCvhNiJ+IUTTS8ba6CDz2Zw/W5EjlUAeVZBpwXafnXMKJFNgv0 NrD1IwiS1WKqQr3zRu/sCgZnYgPeK4PmknvXi9w7XGYXkbWM+Nrh4O62v627yscDkO0Y LGWelmL+OEMyjnoQKN9pXGxfMBE8ZLH5CrkmFHhaa8q4jOZWoq65PVioxzbdR8fZTRti lribxgDsdCZHV9rJ5aRccrLCk4Q+3cmZw5InfiwJRcyQ42YE3HDVBzWqWnKW9VQiU1C0 qRAGEo03/o3RDx53GxHCtM2Z0Q6N8HTPor0fMkGmVxxvVHMAk4/tXhHn4IDRrheKu9/s XMTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685727; x=1726290527; 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=gnJ5bQcxWcBEjqFa4fDewaQZBBcymf58nuYFxDuPtGE=; b=nu3EE3FI2gP/N2xCo26er70cq8zwLIBH3qGqb4ISdIFaG1PtfpC6wL+iTd9iATg7Yo OXA9nzGnGdRm1wjjo9FCcyssUT7PRrWh/wqmCAYpWSIpJ9+GaQIZwKHBe8IrJggfbkOT Eh9wjqkyhUjHReMu+vuyGQ7alV/Hh9v9v5ruTstNhDVEmIKt+pyGXYl6UuWIs7/+jNIn ty+TGjMRSuovMhrj5Qq1yH022eUM6l3HdFlXXCXpY7nJ9CYaub/3zNnIsFWSd+LtgjI7 rSktWDnsOzVs6MP+MG3JSBtKz7Yn8wnUViTwu5MzNkIBbl+xYksVjXhSWMRTSTTO/Wd8 OsgQ== X-Forwarded-Encrypted: i=1; AJvYcCVkycXZ0bepGKlXK4PYelQ+K0Ug9MQgiXVnfj7YfIaIxH6sktELYKxxRn4dD7XOyabImAZf8HajKqqTL3A=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7AkLJURkfIh4Th4zHKfn8Xt878L/1TlmgEgW5sP0biHMiRyKf ZPohGg9hWK5vf+D0UImcvNtnyT0VXjIRnC2623z46D0J3K6QL4EEZLbfBbsBrvJU8KSHsN/w0Jf YYyX0dg== X-Google-Smtp-Source: AGHT+IFTJ0A52z3gMmDUeSdc9NNKQBO5uzT/5BCT5fI3Wi24F4j+wnthp1Ie8Bb6r90x5y4Inys9YsFccWPt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:6c81:b0:69b:c01:82a5 with SMTP id 00721157ae682-6db4526c2c0mr1787397b3.7.1725685727310; Fri, 06 Sep 2024 22:08:47 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:18 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 03/15] perf evsel: Add accessor for tool_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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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" Currently tool events use a dedicated variable within the evsel. Later changes will move this to the unused struct perf_event_attr config for these events. Add an accessor to allow the later change to be well typed and avoid changing all uses. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 6 +++--- tools/perf/util/evsel.c | 24 ++++++++++++------------ tools/perf/util/evsel.h | 5 +++++ tools/perf/util/stat-shadow.c | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cf985cdb9a6e..689a3d43c258 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -294,14 +294,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 && - (counter->tool_event =3D=3D PERF_TOOL_USER_TIME || - counter->tool_event =3D=3D PERF_TOOL_SYSTEM_TIME)) { + (evsel__tool_event(counter) =3D=3D PERF_TOOL_USER_TIME || + evsel__tool_event(counter) =3D=3D PERF_TOOL_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 (counter->tool_event =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(counter) =3D=3D PERF_TOOL_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 49cc71511c0c..dbf9c8cee3c5 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -773,7 +773,7 @@ const char *evsel__name(struct evsel *evsel) =20 case PERF_TYPE_SOFTWARE: if (evsel__is_tool(evsel)) - evsel__tool_name(evsel->tool_event, bf, sizeof(bf)); + evsel__tool_name(evsel__tool_event(evsel), bf, sizeof(bf)); else evsel__sw_name(evsel, bf, sizeof(bf)); break; @@ -811,7 +811,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); + return perf_tool_event__to_str(evsel__tool_event(evsel)); =20 return "unknown"; } @@ -1503,8 +1503,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 =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel->tool_event =3D=3D PERF_TOOL_USER_TIME) + if (evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME || + evsel__tool_event(evsel) =3D=3D PERF_TOOL_USER_TIME) xyarray__delete(evsel->start_times); } =20 @@ -1785,7 +1785,7 @@ static int evsel__read_tool(struct evsel *evsel, int = cpu_map_idx, int thread) =20 count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 - switch (evsel->tool_event) { + switch (evsel__tool_event(evsel)) { case PERF_TOOL_DURATION_TIME: /* * Pretend duration_time is only on the first CPU and thread, or @@ -1800,7 +1800,7 @@ static int evsel__read_tool(struct evsel *evsel, int = cpu_map_idx, int thread) break; case PERF_TOOL_USER_TIME: case PERF_TOOL_SYSTEM_TIME: { - bool system =3D evsel->tool_event =3D=3D PERF_TOOL_SYSTEM_TIME; + bool system =3D evsel__tool_event(evsel) =3D=3D PERF_TOOL_SYSTEM_TIME; =20 start_time =3D xyarray__entry(evsel->start_times, cpu_map_idx, thread); fd =3D FD(evsel, cpu_map_idx, thread); @@ -2072,8 +2072,8 @@ static int __evsel__prepare_open(struct evsel *evsel,= 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 =3D=3D PERF_TOOL_SYSTEM_TIME || - evsel->tool_event =3D=3D PERF_TOOL_USER_TIME) && + 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) @@ -2262,7 +2262,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, int pid =3D -1, err, old_errno; enum rlimit_action set_rlimit =3D NO_CHANGE; =20 - if (evsel->tool_event =3D=3D PERF_TOOL_DURATION_TIME) { + 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(); @@ -2304,9 +2304,9 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - if (evsel->tool_event =3D=3D PERF_TOOL_USER_TIME || - evsel->tool_event =3D=3D PERF_TOOL_SYSTEM_TIME) { - bool system =3D evsel->tool_event =3D=3D PERF_TOOL_SYSTEM_TIME; + 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; =20 if (evsel->core.attr.sample_period) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 15acf293e12a..15e745a9a798 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -330,6 +330,11 @@ static inline bool evsel__is_retire_lat(const struct e= vsel *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/stat-shadow.c b/tools/perf/util/stat-shadow.c index 6bb975e46de3..99376c12dd8e 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -380,7 +380,7 @@ static int prepare_metric(const struct metric_expr *mex= p, struct stats *stats; double scale; =20 - switch (metric_events[i]->tool_event) { + switch (evsel__tool_event(metric_events[i])) { case PERF_TOOL_DURATION_TIME: stats =3D &walltime_nsecs_stats; scale =3D 1e-9; --=20 2.46.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 CB29B1487E9 for ; Sat, 7 Sep 2024 05:08:50 +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=1725685732; cv=none; b=Afeh1iwG/P0iyBgf09ZK1IF4sRTrbbKVUqQIbUU4xm//wQZUGZOV3H3no+2BTS4xwTM11kMHI7O0cDXUMfdocYP/Na0FIoFS5RIQSf0pMBqdYqN7oiuJRY9WFyUzXr17fMDhJo2po0SmLtpzbS1JGqJVsPl2VmprQ+Cs3rImO+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685732; c=relaxed/simple; bh=HkKh04X8D6J+bMpYJGXztyOf9L9ngWoa7v1G2rn5Oi8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=IaD7SaMWa5QL3rTMGcl32+awuwcvRXltOHpMeVc+mVMerA19Fu1wYi69O5ug7O4Gg3/2Sx/hv4NXpgUUN8IynoFrqXzh4x3x8rWgpfoSOBGEJuhFCyBCd3biLnr6lEiLRLFHjTv1RR80woVihvppvtc/sM66Qo0zxQrYHLMbJm4= 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=CLCa+Nip; 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="CLCa+Nip" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02fff66a83so6487900276.0 for ; Fri, 06 Sep 2024 22:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685730; x=1726290530; 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=QKvA61WwO8WManIDEry3xBPvYjCmgFaen6iyvj8dmS0=; b=CLCa+NipwramntTlpL4SbzoTMVP8F8LgejlnIN3w5Ju9hGCndXTEvx9os8Q11ia926 H8HRkKH7yqOUr3C0zh/I5MTr3nZ/SRsNhWncqq1SQ/uD8Oo5bdLz8LGCv8ptPpogN8qy Hm2LD+7OEYSB9hSdG25tMhDKgnqjvj5d0vU5o4gga4AVgakBuAhWIY4gfFL/X+V7tjxh ktWJQihx41SZIZcXDcaxUhWI/tXCVqTjwilLdNAy17a68wSFEKPTxCKOhYvPB+MNb6HR /GH2BvpVDP4/f4RA0TxEa53nDlEG1M16sJ1By3ivSLTevEitf+qdh18OoHof0sR1iVMz 3h8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685730; x=1726290530; 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=QKvA61WwO8WManIDEry3xBPvYjCmgFaen6iyvj8dmS0=; b=m4gY4P9F31dwAz4SN6lAjOsxHmLJHiQBOK0y3ii6/dxlSvzLiOy4nI4G5t68Tv/tci kjYKrXNyC+t8AOM0ZaDL/zREt79CUo/XxACwR16i+y3EifvWXwR4sdlhlEvfTAy+F8if 4ABxlURjcVbN9ReuZjT8NmoMspfWdf8rqbHzFToBQiFVuwwbiT0O5t8schHfHBUN7IMN mS0lp/EudduUIW2L9zg1fXnyZ2uUclDrZg++K5kYdqvEFls5eeR2ASjzOZiFrK8wn2Mn QHTlk2O9jmE5k0A07FVXfF8+QYds7vKw+3pT9tgQuKXOIMOVETB/nB3HZINnGbb/RbZJ 8y6w== X-Forwarded-Encrypted: i=1; AJvYcCX8Mbok6sosRhaq2vFlJWGXxAyW5drXRMBOSOO33HJXEj/drK6XTI3U6vi9CeLlC0fXwBqLXBNNaccAI9c=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6eAjAieMK1+Swkc0zFq54pU4CQXfQ7A3+CEgx1rHOQJXScwZj Hd10qamZJgJ7leiunjIvRB5EBSOMhIgtgSzc2fKb+KTUUE9RUOA4ylzXOM+O/ikdaamJlF5KtgD gz6dR1A== X-Google-Smtp-Source: AGHT+IF7UBKTi9sJI18dojLizpBg3DhTO/Azd5rIjyDI4e7nelFwAEZSFGGcydoCgyKhtL3urTmxhEGBxaKF X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a5b:6c6:0:b0:e1a:9a4d:a500 with SMTP id 3f1490d57ef6-e1d34a1461cmr7217276.11.1725685729619; Fri, 06 Sep 2024 22:08:49 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:19 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 04/15] perf pmu: To info add event_type_desc 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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" All PMU events are assumed to be "Kernel PMU event", however, this isn't true for fake PMUs and won't be true with the addition of more software PMUs. Make the PMU's type description name configurable - largely for printing callbacks. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 1 + tools/perf/util/pmu.h | 1 + tools/perf/util/pmus.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 50e2e7abffab..72bfc321e4b3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1857,6 +1857,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, struct perf_pmu_alias *event; struct pmu_event_info info =3D { .pmu =3D pmu, + .event_type_desc =3D "Kernel PMU event", }; int ret =3D 0; struct strbuf sb; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index d6f702e55a05..4397c48ad569 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -194,6 +194,7 @@ struct pmu_event_info { const char *encoding_desc; const char *topic; const char *pmu_name; + const char *event_type_desc; const char *str; bool deprecated; }; diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 864cbfa1f960..93e5c0435ee0 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -371,6 +371,7 @@ struct sevent { const char *encoding_desc; const char *topic; const char *pmu_name; + const char *event_type_desc; bool deprecated; }; =20 @@ -444,6 +445,7 @@ static int perf_pmus__print_pmu_events__callback(void *= vstate, COPY_STR(encoding_desc); COPY_STR(topic); COPY_STR(pmu_name); + COPY_STR(event_type_desc); #undef COPY_STR s->deprecated =3D info->deprecated; state->index++; @@ -498,7 +500,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p aliases[j].alias, aliases[j].scale_unit, aliases[j].deprecated, - "Kernel PMU event", + aliases[j].event_type_desc, aliases[j].desc, aliases[j].long_desc, aliases[j].encoding_desc); @@ -511,6 +513,7 @@ void perf_pmus__print_pmu_events(const struct print_cal= lbacks *print_cb, void *p zfree(&aliases[j].encoding_desc); zfree(&aliases[j].topic); zfree(&aliases[j].pmu_name); + zfree(&aliases[j].event_type_desc); } if (printed && pager_in_use()) printf("\n"); --=20 2.46.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 F27ED14A09E for ; Sat, 7 Sep 2024 05:08:52 +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=1725685734; cv=none; b=sxJ1Wp7DsOW44pUaN0ttaBfPAybZNN/NnK30NxV7KbYaFHGcscEInTsq8Mr+UeMIZyvTG+kLc0os977cSeBC9CngR5etcsu7MzmCywU1cZJ+W8mMdjhUFyIiQdCN+1ZA+aoRz9wrknyVL1GjtPli9U6k48ffWg/n6k/cqczb6VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685734; c=relaxed/simple; bh=m1WPfgl7SP89GnaSfdxl2RxnyAm/9Kd02ncuz7JYQHo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gFHBMZjK3P73m0gxLBiInTe9hdw1OrlRRDjwmx8McXF5810WDveYi1c0XrAqnDHbIOjjlS+RWDISoNPwgajPNLms8XHdtL/+bToziL6CTwGJ283O2E2X5kzMVJVYzUvsWOCcPHOLA55LyczGbcWO+1XWw6Hiy602bgI8DL14TRk= 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=eu+tf5Ot; 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="eu+tf5Ot" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02a4de4f4eso6586093276.1 for ; Fri, 06 Sep 2024 22:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685732; x=1726290532; 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=a5r49TcDCPH7T31bKkTHHjqs94+2zUrOQeYr8a1P3XQ=; b=eu+tf5OtcY8ZUj7bSQo+d4FUhai6KwJ2zVOpRC30qTMddor3kjkHsjDcbiVAOYnabU YBtWXZ8vb9SpOMR9mZEQKp5l81bOHrk1qfHTNO5yY3y8pD0pSi2u9ew43X+7WheS9AQo AfCINMeO4eIOiMBBmRepv9pNfxehK4tgU+qCjWA6ijz0AlNIXUf5OFVkJVe9wuQmJ0PF fx+WrNQ/yi44uJ0DQjIlOrGghpnkRIfcb9kdBaaPw6embus62JMrKbEwLP+6ZsgANW8Z KBH1uGZpUOaezFS1zj2USODzlXORnU/hHGKwRFTKHixcO44Fo+mF0ylzVdA06/+ggHdW opvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685732; x=1726290532; 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=a5r49TcDCPH7T31bKkTHHjqs94+2zUrOQeYr8a1P3XQ=; b=ZNmH1zQUHWyYbeYI7ldH7KM2JV3QDkrTfUcm6z/N6wp77/s6qTwPBoAcA+gL2YIFLs vAkfvrTaSzqbImMWh9CzEiLtLyVY1+pWmMouaHZVngzVS7saLSxMHZX7o2RCoGnodxDK ED6UNhUyCq85/fylzuDZXN0Z4v4hFPzHQLXaG9Yc1K7aNFpcmbbVOKgBifPeuAl8N42G aCbKSMgBrxTgK/e6uaX+1KVjOOaPGj12LqbXmyU+I35SXtfXDZvzQ+L4TRBCxH7UmowZ 1CA629acBj6hMoUzxEd75WQguhoKrIoiBd4UC9EfHjkj7F4rpThL+EdNnLqXOprPIlMS twuw== X-Forwarded-Encrypted: i=1; AJvYcCXJspkhfooqYIHpkNTM9lWV6JE5d+4tE/fQU7i2d+UjBH4cesJzoegQqRn6MBfStYgJpePf2nQ/NgJ69B4=@vger.kernel.org X-Gm-Message-State: AOJu0YxcujI5X6d5ZuBN2NNULmJgX6cmx1XK+FxvkifrqvLQ1T5Mjt8N biqc64ul4+84HDfhag+vSzmYaz6RZ8qqN4N9k5yM8fxzmIDi4IKkZOoYV7t8ywVH1O5XfiemwEC 6YPZyAQ== X-Google-Smtp-Source: AGHT+IE0EKaeMy7eJuhDT92fQLJKrgy/uZcZe5uCVRdZiDDQ3ing5jXBYBWu0n5fxCO0bKSAum8dkVGrPuL8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:6902:4d1:b0:e0b:cce3:45c7 with SMTP id 3f1490d57ef6-e1d349e38d5mr7954276.9.1725685731891; Fri, 06 Sep 2024 22:08:51 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:20 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 05/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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 | 54 ++++++++++++++++++++++++----- tools/perf/util/pmu.h | 4 ++- 5 files changed, 56 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 081ceff467f2..30b78fe8d704 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1515,7 +1515,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 72bfc321e4b3..29bd0fa9f88c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1367,7 +1367,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; @@ -1381,11 +1382,44 @@ 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; + } return 0; + } =20 format =3D pmu_find_format(&pmu->format, term->config); if (!format) { @@ -1489,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 @@ -1508,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; @@ -1516,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, @@ -2281,7 +2317,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 4397c48ad569..af7532ca7fb1 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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 4C98914B967 for ; Sat, 7 Sep 2024 05:08:55 +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=1725685736; cv=none; b=Wtvu5XalEU3s65fu4QCYeCe41RNftaqMPMcx5B0wcA+NuvFYXsdGcdloVwaZ7u8dplf/mZUfraXkQKNBkuF6/9x8TxQjDEkAsUQJcdNJ732xZqb+uV8m2J5ZYzOgCThtqb3fMU8qGWoD7B0ECRTV8WobTWtvRqf6fUnDmPUh14w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685736; c=relaxed/simple; bh=4cOZXSssGH5UHbeiNemyHw9AfNWWkQY3k/4vv6r+rYg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=YZ2DuYnKU4zL1gyqgJ3RctnI9T8GMb5RWbiCFTcl6QYDUUyEO49UeFZtnyG+ZVNVUMm/7Vvorw8Tx/z9OTDQ5070Kc7AkHWFVguS5s7QFh7mDlrpFLVXkG16qyCfkhBv8S6xMCcB4h8bZYnoFQzWbvMlIK6yBZp8d8wROM+6FEQ= 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=rSmLK2b6; 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="rSmLK2b6" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d4f52a4069so102144067b3.3 for ; Fri, 06 Sep 2024 22:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685734; x=1726290534; 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=K446thzmdZyY//9ueXzoZapLMwoJZQ44b1S89B5s8Ac=; b=rSmLK2b65RgRfYaJ4UToZO3bKX/CB+Ymaji0pJTBk8tYPPNMqmSx5C7wcdkVoQCeEK MjMOxjCfQz/2HAnKZg0y5JZKYnn/+WhF+O0rIE/8O/t1bVojmihm0s5LEHGPPwJ5LB3A v99qizbQAU8A5xJZ2xUg7zT1MNjfVYyn7tQHgyYW2hi8Qf2Dc5kvEVAI42nqpDpOiM8h VAwrQXLUbT6dUA97Pf2MSZP18HzfItTmoURaPoKk4uuIYrf8155mE62v1qlO/v/AxPfv JJaZltjAxuqZdkVOnzgQk6MrQtttlToFl6t2bt8DYYHzpadgRFsV7p6xK7Pr/aWCaI5b qPmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685734; x=1726290534; 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=K446thzmdZyY//9ueXzoZapLMwoJZQ44b1S89B5s8Ac=; b=kixvyTuHintifW4TtdHDBHJ5NXSo7Zvc/6M8Wk0bnw1YxJDqMGGvYULj1tdlenAH+5 VmQ8DH0QRAAjxPiX0fmiX+TsN8Xt14uTlXKf94u9iL8HYkT1u4z/RDddcZVwlEMKLoPm 1MmVw+opxc8ouNxcRtFsV6S/pAPTXy7R87UIoSHGcynCXS1K4Jffmurhkpg0LTVPKNK4 J9nI1pyCsWHC+mon1GWuALA0owacBVGXQVEulcClfgT/xUu0ItDyKvRubBV4QZ2t8Mic rV9qDClZKDAcxWML3tEWP203WzjBF2nDISTbTaz5x6JTm8XM9HDTvmNOGzX6XV7+bSYn VXGA== X-Forwarded-Encrypted: i=1; AJvYcCWLvufsZK92GxWNn956ga7HBww0W+U9uihFfTSjctnvR0dzhLlPU0xveYYXEh7mLD3NJuhIJRprPN1Ylls=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5hclhrTJExJoEgtwDpsY8Y2x0plpXT1b3RjXzH5E9ddlEU3KR uNze5xT4+H5ZjY7Jmg27D5Ia00aJyPTZhQRhPtcaCvs6K8HS5g+yn1yBtUG+LVu2OHrBFKkRncf xTz79Cw== X-Google-Smtp-Source: AGHT+IG5ulMeYZYI+0rmqtyIoRb8/mTAk4z4SLB4POy1XLmQNC5TMS8PJhGseVM70zE/iZ51QJ2+nhNJuJxc X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:b1d:b0:61c:89a4:dd5f with SMTP id 00721157ae682-6db44a5d1eamr3228967b3.0.1725685734285; Fri, 06 Sep 2024 22:08:54 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:21 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 06/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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 30b78fe8d704..b68a744f41ba 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -772,7 +772,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 @@ -858,7 +858,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; } @@ -982,7 +982,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; } @@ -1105,8 +1105,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; } @@ -2546,7 +2547,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, @@ -2580,7 +2581,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 @@ -2687,7 +2688,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; } @@ -2707,7 +2709,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 bfbf391451d9..cf3f07db0295 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -162,6 +162,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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 A0F651514CB for ; Sat, 7 Sep 2024 05:08:57 +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=1725685740; cv=none; b=ciMKhGxI2SckIHnLUY5Xyx4N/WQvpethq36DCCcicekZze+CezUCCvE0LAA6kZ4au7wtoZDHi5LY9Mnxk8KuwQsNKfK8etlidVjbWoA6qEXWNAswdYSVssPUK9lxivZ2WiZ3kQ1dE7geI1TGi6RH4axOtLPmTal5dIovExPacDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685740; c=relaxed/simple; bh=ZUA58Go7Paa9FNArSeF2JqV7JukRYrPivcjrDirkUfs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kMVmUhjsNa0W/xGuh1ETKhoMlLCzT7o1J8t+M/377pLelFmMZKr+nyy4Ml06yUXFXSg9nHehVZY3izuTYpYyf82Sl75O/ZJqnHk+Ydvc7kshn39vUoiIDEtfx4LwfeLX6uTto9atA9ep9pGuQEXQOsmqC8MwuPeo47Cv2YKgGRM= 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=hjXFjndD; 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="hjXFjndD" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e163641feb9so9938511276.0 for ; Fri, 06 Sep 2024 22:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685737; x=1726290537; 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=4gafpIV7PLTIXAbNaWFlCtGU7rGYxILnDpzQagriofg=; b=hjXFjndDwivT7rUWERpSu5cb0iw+A4VYDVPRg6JJo3IqqZAH+XgiRrXREICa9zHWyK TEQyHoSfL7nM2/VffnNwBaqOW90Jf/1Vy9WirWovKz8DtnUuUzkX/d7xU+VTBGxqJSll cCE+0c6LgjPrSwvQ9uiCdCAankieSQHtdQluYqAsX4+rzvID0cxtmYGlxu47uMHmlDu4 wFU+w4m0pUO4UJ4C6qEqcGS43fu2sriCcmfTXsziJ6inzyftMcyy+8kExHS9cmpJ/4SG 6Mx8kiOoxutYiL3733lrhvJ60VGxHc6x1zduxefTFM1PSseHggMZFbdQmX8MnYMAwJoA t2Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685737; x=1726290537; 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=4gafpIV7PLTIXAbNaWFlCtGU7rGYxILnDpzQagriofg=; b=HLMtvLMW9dYb1i7kV7roMxVUL1IDtuJekciRkZw0Bg2RpoGndNUc7g8ZaF2w7rdQH8 A9sOKN3wByOi+L/ERg1fGT6WG0/yIae3sa57++ZUE98pmxJt/iqkBrZ3WDlcAEmn+3Xx JmNYA83SsPuURC5Q1MkWoqiGMlW+cBABxtSlZIihSyrXH5d9b6PnM8TU3EyJZa7GVJJO v7edygJ9heLRiKSpMWLoFNmsGTFknrHT5tzNXI5+a5g6TnwNM9F9m7BzmSVC2Zku5f02 efgVC9mXhryYDmT6wgf+23wq1LEb5itvn+71eFLE1RLTmwyNHuyowkRfQGxQyyBMHhiS 9Kww== X-Forwarded-Encrypted: i=1; AJvYcCV6bZ/HA1K768O/F3Pfen0TVIF5Kj2ChieIbVjJmm2i6KfcplP9GNuf0TMHXq1wKu1MPVipWdHhJfMlBDs=@vger.kernel.org X-Gm-Message-State: AOJu0YwkJgvbm/RcJKG0s+Ddgxt1XFqek9ddOARe/cHwNeGgY8k2SLCj UicYfL0x1pfmogjQxB0DkZUFGf+pQigNfbnhPRWCBQfBFuS9NQqaNOXK4abbcw/5XaPS4xbKPFv BakvBKQ== X-Google-Smtp-Source: AGHT+IHIoB1Nh1VGLmC7EC5MPRgCuu1qV6s29+DvUzZD6IROPLEsPc2gBvgXs/PmOY63R+Qe/tZYTK70d5Qu X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a25:8448:0:b0:e1a:6fb8:1c3b with SMTP id 3f1490d57ef6-e1d342906damr19126276.2.1725685736589; Fri, 06 Sep 2024 22:08:56 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:22 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 07/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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 | 37 --- 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(+), 390 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 689a3d43c258..ae525fdcfbde 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 260cec2f6c0b..80187e3a52be 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 dbf9c8cee3c5..b75c4a4c7aa7 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; @@ -421,7 +394,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) @@ -617,11 +589,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; @@ -772,10 +739,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: @@ -786,6 +750,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); @@ -811,7 +779,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"; } @@ -1684,167 +1652,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; -} - int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) @@ -2042,6 +1849,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) || @@ -2072,19 +1880,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) @@ -2262,13 +2065,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 @@ -2293,6 +2089,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++) { @@ -2304,46 +2106,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 15e745a9a798..bc30491bd490 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. @@ -83,7 +68,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 4dff3e925a47..9181548e8881 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 b68a744f41ba..80e2b4e06ab0 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -297,36 +297,6 @@ static int add_event(struct list_head *list, int *idx, /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL) ? 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, - }; - const char *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 "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); - 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 @@ -1400,13 +1370,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 cf3f07db0295..d77be173af22 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -223,9 +223,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 b3c51f06cbdc..5c4669264177 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 29bd0fa9f88c..bbb8e207c6b9 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) { @@ -1827,6 +1831,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) @@ -1838,6 +1844,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 @@ -1898,6 +1907,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); @@ -1986,6 +1998,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++) { @@ -2313,6 +2326,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 af7532ca7fb1..880a8dc661b7 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); =20 #endif /* __PMU_H */ diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 93e5c0435ee0..36329bc77316 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 ea96e4ebad8c..a82a8ec79b39 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -21,6 +21,7 @@ #include "iostat.h" #include "pmu.h" #include "pmus.h" +#include "tool_pmu.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -946,7 +947,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 99376c12dd8e..2d653f91400e 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..89b64f6482d9 --- /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, + .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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 C796553376 for ; Sat, 7 Sep 2024 05:08:59 +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=1725685741; cv=none; b=RSdt/P+0kQ8l/ddVq0B+n+Uvpf+Q2fz1s8Nf1TFr4tlyAgfjwISh/1icCm2eC8+O0zAHmEBzULcbpEh3++YXA8yErnTz+dWV1WKcIpfJyeJi4g73n32h0DpbuXt+w9yn/8sGKN8dOBqCOk5SLH8Loj4lCo+8j5L3CofpB7m+/yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685741; c=relaxed/simple; bh=75dGXkHnvH4DX5lfJ2HzzwoXZbnDSb+E2+IJh277Jn4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=CWQL3kfuzlBSFMaKx6p+ACY1BO5CqzKcj5aWHk271dy0dLxoVvTytXF5Y48SC1GWF6NSpnjTJwFU2NeNJadngPtEuowpYDIt4BoZyuDFF7jC+JSaESbGtI+e9EECAg6PnZamAojAHJDzSsD7X9zNkL7iNcR1fxMiHDexxOAcGfM= 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=O45mARPv; 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="O45mARPv" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d7124938d1so96091637b3.0 for ; Fri, 06 Sep 2024 22:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685739; x=1726290539; 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=VrGvdwW5yLz083CnTna6J/pmY0XcB40Dee27b7gRxxY=; b=O45mARPvgQv3l5EPNxSQHxu4I0orGxBF4I9Zxzea0cA8CbE49cBKWMGDqmtmPsOsl7 F790byyvKeoU9Ho82Ufm143axC0mRIQHlk0mEXc62hV3qhENraDsOw26j0PyOFQ1RZat MoKf7CO7Nds7NEKzjX5Q9z+pWOBBlY/ptOGsZdx9LIyOFRK4WuaylBdbzjj3JmUBB13a W3lDJJOqgw2kQM39zE9I0+8kMO4DI2+SW2BYImbx5YaP5mNsOypZgIcNKIEV6U9uHo79 yyYfmyC0YblHwHzp6C0/BmCE+VZ9IhO/0FGnzyPnXyw1YLPbtVav93W/O9aq/smJvXdf y6mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685739; x=1726290539; 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=VrGvdwW5yLz083CnTna6J/pmY0XcB40Dee27b7gRxxY=; b=tJdg6UeCXZ9m9zvI+fQCLewfAct3y/aYPClVtwfi/UdxzX7AAm6N7w7vE7T56phJ0u GkEwsyNkXR/VZKiOKA8emHMr5R0WNvZR3rrzxSl6I63GwTP/fHQbWPQIyKsH4FqCw4zP zsM5jet+khUCOdqpMBgVRrZE5C0MZ4uNPSNmYVX9RoyOcGyr7c2X/tZoFU7q47BSasnO 7j0ubaJu52UBFdt1XPzzG43zDYttAFLwcUA4v6hbeAoJfCY16qwGqfR/EDiJEonfbiUt cQpFffzPxuQ2per9IVMFVgSdeoZJbeix8DpRUP/1j0sMx6DWAj3IdauARL8irdbCUeub FqtQ== X-Forwarded-Encrypted: i=1; AJvYcCX9GcRfn5uVOb6TCcCA2O4230VmznIba16a2SasfjaRwmdtPVBge22Xm7Kw/YhqcSNG3f4I5MJ5AuIcMgE=@vger.kernel.org X-Gm-Message-State: AOJu0YxYxJs8ZBUmMs0xQ7CAsTIi1JXaOdfoR/eXS67E4teVZEer6nr4 cZd7x7kprhq9GfIBuIQcmwjQkhc+IS0vD6w/xYhZeQt845h/vfphW8tJg00yVQpfRPEBguDo+tZ CEocOXA== X-Google-Smtp-Source: AGHT+IFqZ3pfnPg/jGKsmtv9aGLrHcKWNCzR2QL4S+3irkokhORj+3Mwjl7zTFG0PiCY1Dn6qnaTlK510dQE X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:b11:b0:6a9:3d52:79e9 with SMTP id 00721157ae682-6db45157840mr2763397b3.4.1725685738842; Fri, 06 Sep 2024 22:08:58 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:23 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 08/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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 ae525fdcfbde..a6b4d1b98b3a 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 b75c4a4c7aa7..c0b49c5dd3cf 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1471,8 +1471,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 9181548e8881..0e21e2f9c170 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 bbb8e207c6b9..34766151cfc3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1832,7 +1832,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 2d653f91400e..e56969d1e39d 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 89b64f6482d9..c56fc0c13899 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) @@ -231,8 +231,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, @@ -249,10 +249,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(); @@ -271,8 +271,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 @@ -340,7 +340,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 @@ -352,9 +352,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); @@ -379,8 +379,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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 C355A14F9E2 for ; Sat, 7 Sep 2024 05:09:01 +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=1725685743; cv=none; b=uX9mVJ5gt1+ky286NW28cL1a7I3EDCTqLvW906l9tW7Sy9N1kHKLjBA9q2WlACd32motMGcE2sC/+J0ixxi9I7DYuGiZ8j/MdwDu8950H5GZmj6UzopLQ8wmEeAqEzqOxuXU9Uw0VnxySSZvh71LSzjZN6qoFnyChXvcehHYhkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685743; c=relaxed/simple; bh=SS4AyC2HZ6wr5r+I3X0KxiCA+QUhaGbOEHDFVyEpN+Y=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=N2q2zBNZNeTQSQlPKm/SUvjkSrW15AjeDNIm6Tp06P3ZUKnppTiQfQb1ll9KqExcd5OK5iurL37r7eWNZqNAwg26b4bpRK6ZGjN2ihMoPFOcqQJ3IMny7Of5nRON2GOf1xxPiACGsWbn+1ndqZq19QQx1gga0E3OZVNN35NoYR0= 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=nuyl8Fy4; 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="nuyl8Fy4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6c3982a0c65so111508337b3.1 for ; Fri, 06 Sep 2024 22:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685741; x=1726290541; 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=HSf1ni/yxtxnti2/oeR7c7DGLW13Imy8ZmiYhJT1zrk=; b=nuyl8Fy4RdtE3Fclji/pYON+joF6i+BnSSGNpimPG/SZIuWZYdtpLU7iQMFhUU64uC 1N2xw4ByoPjjSn+I2a0kPdEjaMe8i0ai7MGdkfHTyVCPO7IFcwSz4DwL6Sq9akvvZqbi QG/lXJw4wYSxtUiaYijnTqyW9CaL84F3abVHNjveWieCfXwUVnBTV+Y0dOu55npIYbjK oPfg8B1P+EOA+YlC21yu+T48s9UvbVXrDeRlENCV8Zz6xqy4Ox0gSeoOhCEH9XkDU1l3 JzyI4qTjgREMrGRiZam/k3dojkzFjP5OrLCdYx1nJdaB64gYyuodwoKJSWogQJEOsfD0 CzGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685741; x=1726290541; 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=HSf1ni/yxtxnti2/oeR7c7DGLW13Imy8ZmiYhJT1zrk=; b=OE4PdzbxE0tHw7NCRC7B5yUrrmR0PqmVoU0A9sn8wdXp/HILfGI7IcPVEYJdC48Q+K 5xFaUdmajeA8k/3aWa/3reZ1jkK1EmQ3DeHx7fUHiQkd7NKp7OusqImRsTDtezMpa1UF kkNSLItDnbLHT4nXmCu74/lIXLM7/pFRaoDDbrhddCvVF4JfpFeb1LGfaTBvG5pYZ5F1 BAHa0YStDEp2tyqul1Bdvp+kvZYKcTDyyEWszQXPl44wsubBxAMQCI7IOgqDvSL9y/kd eAo6WApsKL3Qbzg9P7g+4wcaUIwZ4+SEVh1m436ZDqD4xIWy0OQGl1lbUIAytKCgcm+C JqyA== X-Forwarded-Encrypted: i=1; AJvYcCVz3gaCDAx0VrIf8gWPEV4XSA8BfjFuy+BOjdR5pDaEkOUlMbJ9ol6zSdXIRUCYhM6GJ1ieW268RDLMjNk=@vger.kernel.org X-Gm-Message-State: AOJu0YxEVoC2MHLUy5sTrSma8YJ2nKUOsxq7xlnpipuHI5nPNUkMVxt5 sOu7ktDGKPViC2rINAcKx5NmF677S+ISH+yK41dgdLwFsFXaA9B8aocZBStquKgcug1xRV2MWCy WSdOZAQ== X-Google-Smtp-Source: AGHT+IGwXDBxEgaxf8qekRWOgcxeET/yUxtmBdTxQ0BuycxWuZS+279M0BgIeh09ULDAU0htc1vR1SxWOKc3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:dc6:b0:6b2:3ecc:817 with SMTP id 00721157ae682-6db45160a0bmr4725717b3.8.1725685740937; Fri, 06 Sep 2024 22:09:00 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:24 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 09/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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 c0b49c5dd3cf..9e748ed20988 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1655,7 +1655,7 @@ static int evsel__read_group(struct evsel *leader, in= t cpu_map_idx, int thread) 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 0e21e2f9c170..e5dd932e4d3f 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 34766151cfc3..69c26dad3e6c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1832,7 +1832,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) @@ -2327,7 +2327,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 c56fc0c13899..fb08b0400c81 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) @@ -330,7 +330,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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 2A2DC156F5E for ; Sat, 7 Sep 2024 05:09:03 +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=1725685746; cv=none; b=lXOfkXZ1+j30Ke1HP0S4slUseMnw8Bb3gqtvCNmmtpA4HVWk6LyEbN2SBXaTkOfVnf+AfnotPD4RXMNcRTNbf7xhG+4iBPWc8/ahzcAPTy4pfLEnK9aMhPnpjA1nVaI0qz2XNBO8AXS/1fHs9g9jCW9gfrUj2QSU+sC1cDeN1j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685746; c=relaxed/simple; bh=w+MSU/GxF4uk5gnqU73Mg6f05KmFAhPjJSa72347Paw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=C/SLjE0V4a5kqM3s4nT8wyV9ZgJecVmb1d1KP8sxSR0xAtfAp+e4LxV3HVxQGtfCCgTS65MifMDzYzR2UaNMJfE7WkQMyITURMeJcCm1lYzOWHhcQJvWsBjlKH04eyJbaBQ5acYUCNVOUSolzkDsp+hYkk0PbJ9F/dJp1AWsJa4= 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=AmPQPmK3; 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="AmPQPmK3" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d3e062dbeeso70672327b3.0 for ; Fri, 06 Sep 2024 22:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685743; x=1726290543; 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=wmVUnjFm+zAY0Kpt7IDUp9vOsl66EtPqifUSOTtURms=; b=AmPQPmK3nYEYIBzoG3d/NLZamj228Lf8jmAnRP/pJAfRhgdbsAzVteStDxrP3+hRDQ 8dAaBfml83PR/dvh8kK1U7j1vnvXOHfX87c+UaasiFL9MWBxkBuCeJgeQHPvqP3peyHR NwX4xb69zgltu77aZqO0NslFAbE5js+C9UnG3/TCp8lxguqgFYEOfknac0O36ZiDzdUb jRfUkZd2v0a/SgBG4jV4Jd24JOyLRU0i2aneSaJRI6t8pljFy4AgGHvr1twD4g6i6biE xJC8/hGXAyanbXOUiPV/kPjE/5qX9H9dbIDcJkWZ6qa+4EPti0uBFQXhAEM9Del+PhP2 /CnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685743; x=1726290543; 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=wmVUnjFm+zAY0Kpt7IDUp9vOsl66EtPqifUSOTtURms=; b=Utvw1iGxLYQk5qzIC8fa65wKonBI7+ixukQuLIXYhHASLe4w8DfFyNp0qSF9pfpQ61 vsBHgCSsHwIUZpLqXJaDgQ5e70FJee4RHu6GyECprSpJ7qBEN5OZ2Vii4jeS9vf5k1tc dQZQLvShGTYkiOGz4bK5Xsq73rgYc55DSXf5zOyFWXH9yO5csIGxl+7Dactj64xTqZPt d8LMP8gm8d0cN3Ne59ycKC8lG1udaQW54sylSuXL0Dn2rTGamsR9yecwNC87IkgsJx4k fRya89oMiQFRGFaGMNk28/pWQYHxxiEL8BE3YZUf02GI3QO3rfr2Wifh/XLMm9qR8sUw +kzA== X-Forwarded-Encrypted: i=1; AJvYcCWqq1BlpzhodItvBzbwqMqKEle2I7FAkTZaKfCUEjobj5CS742IYzI2D9uPbHn/W9f9j1OF8QvQ9Rgsjik=@vger.kernel.org X-Gm-Message-State: AOJu0YwQFb6nQSehtOOwTDUFneA7RyJp2pu9OVdnqyQal+tVn4Fc9HDo RWfRutSorlaMP9x8uPizzc8M8Fyk0hAAEirEgzxst6xjV40X8/+g4h4wq0u5M18QHDhWJ3ojItl oaiLBfg== X-Google-Smtp-Source: AGHT+IFMvcZeI6EUpZ2DJcMUiuvY7XEcQQeZpyg1eKa0CmbRt3+ZnoVIpP4z9OPdGZGOJzwwq8dW4CqNZiYV X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:2098:b0:651:2eea:4dfe with SMTP id 00721157ae682-6db2582e473mr3978797b3.0.1725685743003; Fri, 06 Sep 2024 22:09:03 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:25 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 10/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- tools/perf/arch/arm64/util/pmu.c | 5 +- tools/perf/arch/x86/util/tsc.c | 16 ++-- 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, 200 insertions(+), 106 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..c79415b3cc5d 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; @@ -39,15 +39,17 @@ static double cpuinfo_tsc_freq(void) 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 69c26dad3e6c..a412c9c62f9c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2250,11 +2250,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 880a8dc661b7..c4ca359d4215 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 a82a8ec79b39..ad8baf33fdba 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -951,8 +951,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 e56969d1e39d..aa367c667926 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 fb08b0400c81..3dc7cc7b8d32 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; } @@ -252,6 +272,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; @@ -330,16 +353,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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 31D87131BAF for ; Sat, 7 Sep 2024 05:09:06 +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=1725685748; cv=none; b=POVg5k71nK/l/6K/xTbjLqp2OeETUTx9bSSCnYAhBl1mW4Z1MM2KiXVlxj85ys8bGrGLMS1RxJs0RCVa/31aXv4OUFuBYlwMJe5SDiqmgWRvyCJbPzOYl6JrYWZD2qTGA2QYhQiKOXp3wyH0EhkDFmNlEJcQHNKfcbxG/0ebflQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685748; c=relaxed/simple; bh=JzntPdpDL+v54thlxfWMKvOw0Z2S7hJeXfw45blAFmA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=mxKhVrmNX2tVHEE3maOawc89/eoMatc+sOWw035LiD5/CBCcYiC7JGebyuJ1RPgFKYVT3+xFGc8RvUPcy1zWERF1eJbyUZh3+Zm0yXYmjn2UhELJEisMszkBUvitGZNaSJFWOufKJYk9erMAl5b/ZI2qbX3GYHn7eV1R9xi34zE= 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=rEXyrunR; 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="rEXyrunR" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b41e02c255so98519187b3.3 for ; Fri, 06 Sep 2024 22:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685745; x=1726290545; 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=TuVDlNi2p6DwKKPcpYUJIHKCwbbCXMYeSF60lTrW7pE=; b=rEXyrunRa/RRwkt7QTsGAd9dTPawm8WE+NQH4KY8JtZ73/qJnfu+IM/Iz9zRZldvaX 5w6ubfRtin6aCrcW9D6nZbeDH6uWzJKrK2ud65H3Sn+zkGcWpmQXZBZn+MZQy5J1xeE2 FZ3PLDqmqS4102lqK2SSnIfG/P1BMmgRhUNFlh+xTkH5IsXZ6gL2cZM+Fcatvh7KpKq6 8lbkrWDJsftqDzewOYjcxBSxfxARv+7TUPA9ViipdKNCTis11FkkqAxVxlZ3tiNLnieb 30GljP8NBrt0CX/Gh7TFuAS3R+INPd6ybsjWEgDkJA2cKNee4I2OVA7OYdCTwcm9nZfU YkxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685745; x=1726290545; 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=TuVDlNi2p6DwKKPcpYUJIHKCwbbCXMYeSF60lTrW7pE=; b=FVHeSphPBWw0F/Cp4zpJRyi4U69k/G1L6jgk+/Dt9nrBJbxGvNfPpS+SKmsKcqNB9W TquSQ4XRzO4PxEcVH19hJsi5uuIe7QOfShtygQ1jhGQmxBGXZecr0Bz4Jy7mp0y46CgM XC5vJctUUJM5QgxTeMun77p/+gAUdiFpWRlSOEonjEc14+5DUXS4bFOMzmPbba3RA0bX 4dCGxrn0LAdMBQnYNKdziCoHT7HzVwKXrdsg2fSBfghvTm3tAeiEktaFeUxNzFI3lXw6 VWXcEAdG6vRQSFVwDKVXuHC9XuCHc5Usb45tYJ85kgSeX0My8SkX4Ww2IaNbbp1513Ot 46FA== X-Forwarded-Encrypted: i=1; AJvYcCUlqdO9TrHc42gDt/VGmY3ocVdD2wwj6FfaWiNuMxicjoNtQiKiQ+zcgPv1mA7ALQ8AJUKNJneS3f2bzwQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyEU/ZeJOnykVCyNlMLxLXYhTDEPKy9cZMciM2lK4HeUec1v+Nt tQLs5bwwpu3mlmpBBzIbEePVhNqAsovr0s8udrD5waIWJ/24MDUBhER7M5H4eheMyeSSD5WJJmo gfdp8zA== X-Google-Smtp-Source: AGHT+IEembpgBQ0ImxCjJ3M2fvCxfdbLlFqfqgUtKqJbew2ULnyZ05HTYBC0OQp+//xOLhaAl8v+rwwoHPHM X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a05:690c:4b10:b0:68e:8de6:618b with SMTP id 00721157ae682-6db44d89f07mr1877487b3.2.1725685745290; Fri, 06 Sep 2024 22:09:05 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:26 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-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: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 11/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- .../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 1d96b2204e52..c932543bdc77 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 @@ -718,6 +719,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: @@ -1238,7 +1250,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(): @@ -1286,7 +1298,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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 8284B158A30 for ; Sat, 7 Sep 2024 05:09:08 +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=1725685750; cv=none; b=N4asWOc2WYD7xxrerGI+hu9h+JTmkxrVd7zv5Xr4Z4NlYXRkLy+6ItYAdoH2QaBnbWjdXroXll24XXGLAHGu3qNs6+eA8WG/idQDROSIH8c2hm913H81LJ+uoH+wttyFaYy/VC2cDpLBeP8/Fouj4AsvK199XuL56rBFDbsCK14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685750; c=relaxed/simple; bh=BCTWy93AfdqyOigImfyqNMnfwBuoTS0E2c+uZn61FBs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=UfQyZftZkR3DlekzN6V5eVb27ImALKOEJ+JPkFfNqOj4QPCOL6eH8CmLZna2aIroP+HCzsSIFJyq9LIGk0hfKXqsk+eM+KTj9XIj5ZWLTzJ0wC+WJTvRb5Fwf8JQFnikv0sjdf9ejmOQ5Lzr2BCtN8xWiUX6DekvAMpo7ML2sb0= 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=Bm+eZ+Md; 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="Bm+eZ+Md" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e1d46cee0b0so606500276.2 for ; Fri, 06 Sep 2024 22:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685748; x=1726290548; 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=slZLFT9lPrc7VqceilkcCPojjko5Bk6sW8avWD2Z9qM=; b=Bm+eZ+MdZzmBQLA1IwIRDPki92RNA/gAa3/iwb2+ObSJk5YsJvJiwoBROcDXHAryOK TIsOIcVDr8zYwW0OUFYVWEV8Jnj58cUQKoWJvpm18BeXiuS/3F0dglKxPke8qESlYqFS ij2XH8KeAV+IQ0rjXmWhrU8lFVf8Zx+RU4+DHnRJdgLa5NLPzhz0v54eVPcQOkhZLjAP 5QGlVUsWMaWLTm6BlyEv1A+i4EE5Wyy4qwCt7HPockx0I9FlmpJEGll4Uahylned4vj8 mYvL/zVSXxbZoEJ1dWHNU1jKZXeBVE2b/bC8Hn0ubYkUgPR+taRkU6sGBppuFv1QWZew zI8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685748; x=1726290548; 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=slZLFT9lPrc7VqceilkcCPojjko5Bk6sW8avWD2Z9qM=; b=tJ36YvOEPRPpGJaHeINq+1O43/3nIFE2bYPKf/3vMlsk4kyegaRB5lUj4m193lRc0O cYBxYvo/ywPvimYotLZJ1FnBKpraKTGD1GaYDiXnk+iigwVlEVP1xSWnmnGIblVXZ7f9 KWNlx39hhDJmX+1IY2a6suFX3vlAWznBLjo6nnhHtsCqeXFKx/VuPrh7PWo/mR8cmTdY RnLrKS383nx3PCJG/PNC4o24SqbW3DUFuXJwdDih6kLVvmE9CRWYTeCbz5xWfpqeg2El YH5/59JFZ/9Dycq6aCmPIHvuIHzuX1QcyGHbN+83QmOg4kw0kKFutt1FOpsljslPGyBE o2nA== X-Forwarded-Encrypted: i=1; AJvYcCXze0WpLlqPGLsLoLVMOwMDYL6QtCdBnKi2oU36tL0eqVw3C0wtMZZmfnsLgqdihi503346rFPTxArFpH8=@vger.kernel.org X-Gm-Message-State: AOJu0YyGYmWHBXzrsHiaWQitv4pgJMzV32v9D2MgreOxg4cfVcFXNonO llIYMBWXN2RGAFaqttCaqfNUcOn7B5oKY2ZbLBeKhiYVgyLWk4IICnklIuZfoE8rVWME/JgGT/q Mv6L8wA== X-Google-Smtp-Source: AGHT+IGLiZcjgrj2XjNehV5+ClfMF3R9wQ2qO71KbUxt7f6DyDr91FIcVb8RjqFnfZGSwjjR0iqUkJkUrKp3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a25:3628:0:b0:e03:2f90:e81d with SMTP id 3f1490d57ef6-e1d34a40ed1mr9063276.11.1725685747597; Fri, 06 Sep 2024 22:09:07 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:27 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-13-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 12/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- tools/perf/util/pmu.c | 26 ++++----- tools/perf/util/pmus.c | 4 +- tools/perf/util/tool_pmu.c | 111 ++++++++++++------------------------- tools/perf/util/tool_pmu.h | 12 +--- 4 files changed, 48 insertions(+), 105 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index a412c9c62f9c..5ff6556292fd 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) { @@ -1831,8 +1828,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) @@ -1844,9 +1841,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 @@ -1857,6 +1851,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 @@ -1907,15 +1904,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); @@ -2321,9 +2318,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 36329bc77316..19673b9991c6 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 3dc7cc7b8d32..f2d26e9e51f5 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) { - 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) @@ -544,8 +497,12 @@ 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), }; + 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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 E8E7A159583 for ; Sat, 7 Sep 2024 05:09:10 +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=1725685752; cv=none; b=kgGdD+b7InHC/nMZwkTCyDHDurJ08uVNJHdHauE/dUTe96CwiK77vVtgXsBT0BSPkVoAojL8ydC3zBO3jD8Gih4AUficGSLjoR20AoFURuKhh2rv0zsvSM9W52xeGuHzYMgiPJIECltLBO68epz4mYn0k39XSE+O6KCpeBal9bc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685752; c=relaxed/simple; bh=zgNzTknoxQWGaTxAWg+yg5AbW9anNUVCe+80Iw5kmk8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=q8XfJqL0FvmDjg14clolCIDPSfyNt+z76hgg5G4gtK1nfNCP5tPVsVAXvpj3mn9nUhnJdr7Q8Z+YjuUWzUv+69r6P9A1T7K91BivkqGWxarFTyA6f37eCvdwh9S3WWwSaNRt1FpaciKsFIPvwKaacAZQ+IIGE+POUyjLlfVizXM= 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=P3t9Mpt4; 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="P3t9Mpt4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b41e02c255so98520267b3.3 for ; Fri, 06 Sep 2024 22:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685750; x=1726290550; 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=V/Ar3dUi50U5MkQ1SlyAwk/I3yarddmL36DdZBmDzV4=; b=P3t9Mpt43rtdvWFM305G1ygVnyo77Gt52k5Dxtt1SDcQ86/fVPmkpUHsoehLtnz+53 HuC0N54Ze9clr+AlJoBk1nZf0F5e1c7Xqn04tu7rkBqg6Tx4iA0XAayoZgrrUapopVW3 t+ypcMYHYKiLq9IJ/9+XaC+Dk7TlhUMnrut45JHrDF9ht+a2P82GQ+57ciHJVzD8gyv+ qNlBk9a0z4pQQlJosR0wsVmmbpvObabFPbTXwQNNwB8oPoivAE898OKXKZSYOyJXzkhb uqeJE6507hRJa0y8LkAIiWkUtuSX8CpgmiUu9+CvA/LSFePCAn/1me38ELygofDkf8VI X84Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685750; x=1726290550; 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=V/Ar3dUi50U5MkQ1SlyAwk/I3yarddmL36DdZBmDzV4=; b=WdZ+Wg7Z3SnYKi4xeK3wI3teu5JmIvPWBnxg681FvTIY6ytNPZG7sduhRyN9BkwgEq rETt9ED7tkg/t+TPIi2s62Zg6pAsHIH1HnfFa2ktG0aQOmFLg6/dG5ayPLRzjY0oHBMX T/pJk9hQRVZHE8jwUyzGZRLpoMp53I7rtiT1uwX2ZlYUr7nIc87dSh05gi9xabl1cRW8 eozxqunUqy3fOtvANygGcOeD9bIAPsmGE3RZY8hnkh0V6PjQubUGcL2TALipIQuo0WsT Cxsysb8NNulzrFFCek0qUZ7OkhMP9QUTYO3NjXrNe4JwaSJEmsyLekK5IcRMsXcnlz2d KQAw== X-Forwarded-Encrypted: i=1; AJvYcCUz4RcGK08qM7wrBMYYscq5qQpORsephtBYcaUy7mfBr+KHKrOp/MMncxp4PghPDchWWZzS0FaL1T/iYvQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxsiRt3I4o91Sq+72Cr3KpnUEbsSql0bdQMhlTAs+xWJSOWIGfq 3VthbQIeYn3jl27IPkIs1RpRqCDtBf3yzDlH6T30lrWtm50bYOCW3JeAQEPkn7QYSlSqILjsizR qOQ8uEg== X-Google-Smtp-Source: AGHT+IE8fHd4LfbapRE/tIEDY9qTS5Fj2ijGjPzlTc2FTO6xmYM62oDetj4uPSv3jpaKIE4fx+/hRNzhtD5i X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a5b:c0c:0:b0:e11:5f87:1e3c with SMTP id 3f1490d57ef6-e1d34a7f845mr40886276.11.1725685749881; Fri, 06 Sep 2024 22:09:09 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:28 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-14-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 13/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 --- 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.0.469.g59c65b2a67-goog From nobody Sat Feb 7 23:06:17 2026 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 2737F15B0F2 for ; Sat, 7 Sep 2024 05:09:13 +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=1725685756; cv=none; b=lVOZPICufKQ/uCUV+Aowk5hutqvBlwBtHQeXy4cm+byTXJ8gts/1EQns8x5qC+RuJOVeE8237NbIIBNgFIARC/6PGCMW8kuW5pZQGRgUKqQZwADQ2znSFVGNrN3TwTNGSk1+BIskb91T7VZ3FEcnFm9QeP6SDdTdXdYvpGnE64I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725685756; c=relaxed/simple; bh=FOX7pLDcGfrRZTHYWhBGnzl7IC1Py2lDZtzjHljEXoY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=owp7AvsLLrPaXWOa5hPDJqZec7NNt20QnW1BSclcpGdg5+XvQbZ6lO+Mn13rjqoaypsfbzB/XypblDDyleNWjzA6ffoX1ZwK2Agb8CfPx0r2JrpIxXYfv/awOjDYqhbiyaUTveZ1wqTib7Ig9LCzhiF9AGcGVU8inGTMaxnjpQY= 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=gxzhulXu; 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="gxzhulXu" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0353b731b8so6432269276.2 for ; Fri, 06 Sep 2024 22:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685752; x=1726290552; 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=5NlHiF1ClYEsWWA3HPjRhvrAwRvkn2sl14wP19dmpL0=; b=gxzhulXuMrZ6cGiVDcaonsmxJShn0VMVzKhsy4iNNZkq0eRUL4IEo1k+BnotQ5Vd5m vyLDAsDvUhNDgAgrPzEMehUfop2g3JKZwTCEiTkbQlzDDARax02wltU4YdqahVm5Cnkd admpqcY/S6rOijWLJQSZqMLL4t7WbMt1N/Qt5lyTqCgPZX2i806JuPSDIFAQsIlnLj/R 2KDdw7D0s8lpaQsqusZkkm8IDp1oVFNz9aDraF6DwWtjZlBhZAZZaEG/vZQU7GqWs0cR qOHp+WIku+Xh2+Z9wrphpADyGYQHgI4pNT+/OB6FpXG5DButzV7O/XB/gZUj3ULMwOjK v7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685752; x=1726290552; 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=5NlHiF1ClYEsWWA3HPjRhvrAwRvkn2sl14wP19dmpL0=; b=j6gXU/mc9I6vdZgltKGZiOf9hhqmMYnDEfA6pA3lrKLakfFEAr3Eu2FGzF+VBYK8iT lGrofSP3X63nS8gByEwr9dokfYKbGys7+B5tuwlyXS74BrzunpmR0HFyvGba7btVlv7/ wff05aTyBZxSc0JvkqxlLiP9ksB/D+N1vBevGEqC3oeMKZbI+f7HZ34dJBEZlf+iD6UR e/ocw0m2zZ9EiUtM0lQhw9Kxjwfunp/Wg80jsjobvuEvA8eUOmSKmE7PR0Li7IvPX5/2 wQrjuI+VM5k0HlcpVdD92goABWf3tVIw5YDT/lJQdTvGW4ozIFoUL9+/N1BYbOa5JJgt ncmw== X-Forwarded-Encrypted: i=1; AJvYcCU8YccQ8tLfZKSdeFL9bJYRsAuAMC9f7nrP3ibEgZhds2Oehl6to9xH+gzO4lbcRjwYWh4RrzoDHiMeoGA=@vger.kernel.org X-Gm-Message-State: AOJu0YzziZKYn/2RGH6RFP0c3Jk0oVgwHjSCcKR1/QsjtLtDGM1sLNJA /OvKYrOZijDMMBOZx2Joe3nAasb8lUkVtxLo5nnuhi4dKTjOGnplKc+63ILrJu8ksFAy0Spf3Xp digOmRA== X-Google-Smtp-Source: AGHT+IGtxbuxKOlDV9nyRM8BCumn9q0l8P5usCr9+dKzRRO4OI6STSNJ3CjgQtiKap5Rx4qfKJo2DwrnherP X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a25:86c1:0:b0:e0e:4350:d7de with SMTP id 3f1490d57ef6-e1d349dae5dmr7119276.9.1725685752143; Fri, 06 Sep 2024 22:09:12 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:29 -0700 In-Reply-To: <20240907050830.6752-1-irogers@google.com> Message-Id: <20240907050830.6752-15-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240907050830.6752-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 14/15] 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 , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , "=?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 | 879 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 30 ++ tools/perf/util/pmu.c | 17 + tools/perf/util/pmu.h | 2 + tools/perf/util/pmus.c | 2 + 7 files changed, 940 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 80187e3a52be..b1dd5d176d1c 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 9e748ed20988..64883d2aa1bb 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" @@ -1657,6 +1658,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 @@ -2094,6 +2098,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..cc8816b787ca --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,879 @@ +// 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 + +enum hwmon_type { + HWMON_TYPE_NONE, + + HWMON_TYPE_CPU, + HWMON_TYPE_CURR, + HWMON_TYPE_ENERGY, + HWMON_TYPE_FAN, + HWMON_TYPE_HUMIDITY, + HWMON_TYPE_IN, + HWMON_TYPE_INTRUSION, + HWMON_TYPE_POWER, + HWMON_TYPE_PWM, + HWMON_TYPE_TEMP, + + HWMON_TYPE_MAX +}; + +static 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 */ +}; + +enum hwmon_item { + HWMON_ITEM_NONE, + + HWMON_ITEM_ACCURACY, + HWMON_ITEM_ALARM, + HWMON_ITEM_AUTO_CHANNELS_TEMP, + HWMON_ITEM_AVERAGE, + HWMON_ITEM_AVERAGE_HIGHEST, + HWMON_ITEM_AVERAGE_INTERVAL, + HWMON_ITEM_AVERAGE_INTERVAL_MAX, + HWMON_ITEM_AVERAGE_INTERVAL_MIN, + HWMON_ITEM_AVERAGE_LOWEST, + HWMON_ITEM_AVERAGE_MAX, + HWMON_ITEM_AVERAGE_MIN, + HWMON_ITEM_BEEP, + HWMON_ITEM_CAP, + HWMON_ITEM_CAP_HYST, + HWMON_ITEM_CAP_MAX, + HWMON_ITEM_CAP_MIN, + HWMON_ITEM_CRIT, + HWMON_ITEM_CRIT_HYST, + HWMON_ITEM_DIV, + HWMON_ITEM_EMERGENCY, + HWMON_ITEM_EMERGENCY_HIST, + HWMON_ITEM_ENABLE, + HWMON_ITEM_FAULT, + HWMON_ITEM_FREQ, + HWMON_ITEM_HIGHEST, + HWMON_ITEM_INPUT, + HWMON_ITEM_LABEL, + HWMON_ITEM_LCRIT, + HWMON_ITEM_LCRIT_HYST, + HWMON_ITEM_LOWEST, + HWMON_ITEM_MAX, + HWMON_ITEM_MAX_HYST, + HWMON_ITEM_MIN, + HWMON_ITEM_MIN_HYST, + HWMON_ITEM_MOD, + HWMON_ITEM_OFFSET, + HWMON_ITEM_PULSES, + HWMON_ITEM_RATED_MAX, + HWMON_ITEM_RATED_MIN, + HWMON_ITEM_RESET_HISTORY, + HWMON_ITEM_TARGET, + HWMON_ITEM_TYPE, + HWMON_ITEM_VID, + + HWMON_ITEM__MAX, +}; + +static 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 pmu_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 _