From nobody Thu May 2 00:32:48 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1641910875677836.8016682531353; Tue, 11 Jan 2022 06:21:15 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241765AbiAKOVN (ORCPT ); Tue, 11 Jan 2022 09:21:13 -0500 Received: from forward500o.mail.yandex.net ([37.140.190.195]:59498 "EHLO forward500o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241774AbiAKOVL (ORCPT ); Tue, 11 Jan 2022 09:21:11 -0500 Received: from sas1-49a2f795d8eb.qloud-c.yandex.net (sas1-49a2f795d8eb.qloud-c.yandex.net [IPv6:2a02:6b8:c08:c505:0:640:49a2:f795]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 427B9942363; Tue, 11 Jan 2022 17:21:06 +0300 (MSK) Received: from sas1-37da021029ee.qloud-c.yandex.net (sas1-37da021029ee.qloud-c.yandex.net [2a02:6b8:c08:1612:0:640:37da:210]) by sas1-49a2f795d8eb.qloud-c.yandex.net (mxback/Yandex) with ESMTP id EikuKe4oJT-L4fOE3jQ; Tue, 11 Jan 2022 17:21:06 +0300 Received: by sas1-37da021029ee.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id l3U269SIUy-L3Pq5u6g; Tue, 11 Jan 2022 17:21:04 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1641910866; bh=O4dtUcfS47xQno2hdUMnHIDEsNKgjBtaKVEzsBNYXP8=; h=In-Reply-To:References:Date:Subject:To:From:Message-Id:Cc; b=F+2B6vkQDohj597k8vuzWQIrElSFb18VybmU4LaN/oUjX7A/ncZpeJsdxmmuVnACL u6apa4GdfSspErYvCmLQYl4ZbNZbjjJJpRygR7IyM8oQQBIc7mVTctoJxslR3UJ0QM jxwEdW6ygJXzB9v+J1HD59CVMjg34TC9+PN7mHzM= Authentication-Results: sas1-49a2f795d8eb.qloud-c.yandex.net; dkim=pass header.i=@maquefel.me X-Yandex-Fwd: 2 From: Nikita Shubin Cc: Atish Patra , linux-riscv@lists.infradead.org, linux@yadro.com, Nikita Shubin , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kajol Jain , Adrian Hunter , Kan Liang , Jin Yao , Ian Rogers , Andi Kleen , John Garry , Riccardo Mancini , Madhavan Srinivasan , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/1] perf tools: Add 'm' event modifier for counting machine Date: Tue, 11 Jan 2022 17:20:48 +0300 Message-Id: <20220111142054.18733-2-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220111142054.18733-1-nikita.shubin@maquefel.me> References: <20220111142054.18733-1-nikita.shubin@maquefel.me> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1641910877589100003 Content-Type: text/plain; charset="utf-8" From: Nikita Shubin Adding 'm' event modifier for machine mode counting. Any event specified with 'm', will set exclude_machine to zero. Default behavior is setting exclude_machine to zero, unless kernel or user specified explicitly. Adding automated tests. Signed-off-by: Nikita Shubin --- include/uapi/linux/perf_event.h | 3 ++- tools/include/uapi/linux/perf_event.h | 3 ++- tools/perf/Documentation/perf-list.txt | 1 + tools/perf/tests/parse-events.c | 18 ++++++++++++++++++ tools/perf/util/evsel.c | 4 +++- tools/perf/util/parse-events.c | 18 +++++++++++++----- tools/perf/util/parse-events.l | 2 +- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_even= t.h index bd8860eeb291..b70c245664eb 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -409,7 +409,8 @@ struct perf_event_attr { inherit_thread : 1, /* children only inherit if cloned with CLONE_THR= EAD */ remove_on_exec : 1, /* event is removed from task on exec */ sigtrap : 1, /* send synchronous SIGTRAP on event */ - __reserved_1 : 26; + exclude_machine: 1, /* don't count M-Mode */ + __reserved_1 : 25; =20 union { __u32 wakeup_events; /* wakeup every n events */ diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/lin= ux/perf_event.h index bd8860eeb291..17f4d3ac10da 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -409,7 +409,8 @@ struct perf_event_attr { inherit_thread : 1, /* children only inherit if cloned with CLONE_THR= EAD */ remove_on_exec : 1, /* event is removed from task on exec */ sigtrap : 1, /* send synchronous SIGTRAP on event */ - __reserved_1 : 26; + exclude_machine: 1, /* don't count events in M-Mode */ + __reserved_1 : 25; =20 union { __u32 wakeup_events; /* wakeup every n events */ diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentat= ion/perf-list.txt index 4dc8d0af19df..e6d10d95df70 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt @@ -53,6 +53,7 @@ counted. The following modifiers exist: =20 u - user-space counting k - kernel counting + m - machine counting h - hypervisor counting I - non idle counting G - guest counting (in KVM guests) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index a508f1dbcb2a..617a66003648 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1323,6 +1323,19 @@ static int test__exclusive_group(struct evlist *evli= st) =20 return 0; } + +static int test__checkevent_exclude_machine_modifier(struct evlist *evlist) +{ + struct evsel *evsel =3D evlist__first(evlist); + + TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); + TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); + TEST_ASSERT_VAL("wrong exclude_machine", !evsel->core.attr.exclude_machin= e); + TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); + + return test__checkevent_symbolic_name(evlist); +} + static int test__checkevent_breakpoint_len(struct evlist *evlist) { struct evsel *evsel =3D evlist__first(evlist); @@ -1943,6 +1956,11 @@ static struct evlist_test test__events[] =3D { .check =3D test__exclusive_group, .id =3D 57, }, + { + .name =3D "instructions:m", + .check =3D test__checkevent_exclude_machine_modifier, + .id =3D 58, + }, }; =20 static struct evlist_test test__events_pmu[] =3D { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a59fb2ecb84e..a49c995908dc 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -542,9 +542,11 @@ static int evsel__add_modifiers(struct evsel *evsel, c= har *bf, size_t size) r +=3D scnprintf(bf + r, size - r, "%c", mod); \ } } while(0) =20 - if (attr->exclude_kernel || attr->exclude_user || attr->exclude_hv) { + if (attr->exclude_kernel || attr->exclude_user || + attr->exclude_hv || attr->exclude_machine) { MOD_PRINT(kernel, 'k'); MOD_PRINT(user, 'u'); + MOD_PRINT(machine, 'm'); MOD_PRINT(hv, 'h'); exclude_guest_default =3D true; } diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5bfb6f892489..920397e1b959 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1867,6 +1867,7 @@ struct event_modifier { int weak; int exclusive; int bpf_counter; + int em; }; =20 static int get_event_modifier(struct event_modifier *mod, char *str, @@ -1874,6 +1875,7 @@ static int get_event_modifier(struct event_modifier *= mod, char *str, { int eu =3D evsel ? evsel->core.attr.exclude_user : 0; int ek =3D evsel ? evsel->core.attr.exclude_kernel : 0; + int em =3D evsel ? evsel->core.attr.exclude_machine : 0; int eh =3D evsel ? evsel->core.attr.exclude_hv : 0; int eH =3D evsel ? evsel->core.attr.exclude_host : 0; int eG =3D evsel ? evsel->core.attr.exclude_guest : 0; @@ -1884,7 +1886,7 @@ static int get_event_modifier(struct event_modifier *= mod, char *str, int pinned =3D evsel ? evsel->core.attr.pinned : 0; int exclusive =3D evsel ? evsel->core.attr.exclusive : 0; =20 - int exclude =3D eu | ek | eh; + int exclude =3D eu | ek | eh | em; int exclude_GH =3D evsel ? evsel->exclude_GH : 0; int weak =3D 0; int bpf_counter =3D 0; @@ -1894,17 +1896,17 @@ static int get_event_modifier(struct event_modifier= *mod, char *str, while (*str) { if (*str =3D=3D 'u') { if (!exclude) - exclude =3D eu =3D ek =3D eh =3D 1; + exclude =3D eu =3D ek =3D eh =3D em =3D 1; if (!exclude_GH && !perf_guest) eG =3D 1; eu =3D 0; } else if (*str =3D=3D 'k') { if (!exclude) - exclude =3D eu =3D ek =3D eh =3D 1; + exclude =3D eu =3D ek =3D eh =3D em =3D 1; ek =3D 0; } else if (*str =3D=3D 'h') { if (!exclude) - exclude =3D eu =3D ek =3D eh =3D 1; + exclude =3D eu =3D ek =3D eh =3D em =3D 1; eh =3D 0; } else if (*str =3D=3D 'G') { if (!exclude_GH) @@ -1933,6 +1935,10 @@ static int get_event_modifier(struct event_modifier = *mod, char *str, weak =3D 1; } else if (*str =3D=3D 'b') { bpf_counter =3D 1; + } else if (*str =3D=3D 'm') { + if (!exclude) + exclude =3D eu =3D ek =3D eh =3D em =3D 1; + em =3D 0; } else break; =20 @@ -1958,6 +1964,7 @@ static int get_event_modifier(struct event_modifier *= mod, char *str, mod->eH =3D eH; mod->eG =3D eG; mod->eI =3D eI; + mod->em =3D em; mod->precise =3D precise; mod->precise_max =3D precise_max; mod->exclude_GH =3D exclude_GH; @@ -1979,7 +1986,7 @@ static int check_modifier(char *str) char *p =3D str; =20 /* The sizeof includes 0 byte as well. */ - if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1)) + if (strlen(str) > (sizeof("ukmhGHpppPSDIWeb") - 1)) return -1; =20 while (*p) { @@ -2011,6 +2018,7 @@ int parse_events__modifier_event(struct list_head *li= st, char *str, bool add) =20 evsel->core.attr.exclude_user =3D mod.eu; evsel->core.attr.exclude_kernel =3D mod.ek; + evsel->core.attr.exclude_machine=3D mod.em; evsel->core.attr.exclude_hv =3D mod.eh; evsel->core.attr.precise_ip =3D mod.precise; evsel->core.attr.exclude_host =3D mod.eH; diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 4efe9872c667..5528a52611de 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -214,7 +214,7 @@ name_tag [\'][a-zA-Z_*?\[\]][a-zA-Z0-9_*?\-,\.\[\]:=3D]= *[\'] name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.:]* drv_cfg_term [a-zA-Z0-9_\.]+(=3D[a-zA-Z0-9_*?\.:]+)? /* If you add a modifier you need to update check_modifier() */ -modifier_event [ukhpPGHSDIWeb]+ +modifier_event [ukhpPGHSDIWebm]+ modifier_bp [rwx]{1,3} =20 %% --=20 2.31.1