From nobody Fri Dec 19 08:55:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 211DA2629D; Mon, 2 Sep 2024 01:46:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241585; cv=none; b=Z26POGL4JzHi+EfZAvLCyrRDu2EZwwGYM9OXuX58EFdLJ6duNxZEFHLdHagvT7uIoDM/iuUWORcYS2qFGr3NhwUi6gCb6IoeuQSAf1rMbRQtlpbDiEzpyGO/Oa+SjNnUEPAtzmEoAyOKcW9Guah2oqbEtGpGCUTdc9Gl3ElGsjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241585; c=relaxed/simple; bh=U0ncT8Dq85ANDICoElz1hOnaFsagXVOnXrJX3yaEXj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XKS4N+MLn6d3hHNGKi3JiQQWEe+fssz2Lk1nqzt6hEq9EpN8LaVJcfuTVgB0j+VXhIW2lXnhJImGOGwVQY/ho+qqB46fQwe8bEfnI/BHcRfWb51XULDTpUYZe4hODVQ8Xkag1/iwMgzgIegspQD9hl5MUFnbOpsfLEf8JKjYXjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lzJVuZsY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lzJVuZsY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F15E8C4CEC7; Mon, 2 Sep 2024 01:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725241583; bh=U0ncT8Dq85ANDICoElz1hOnaFsagXVOnXrJX3yaEXj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lzJVuZsYNmc4Xfz+rfpv8Laf8qIG0YcvBwf+rjb1pMA9vKTOD0yasoLZxseKoo1QQ qm0Ylu5otkyF/Lb7C9aOpRDpwvKVcMqpzBzD6GlY5s9tUxUvOzDWPVkP9o2BNeF6n0 dXJeE32Z8GhOYmD2V5E9UJDYrgOPrgVAGBRGO8sGrAXgxBJnffO6Oa7RaDUJsnmgJE wbkO0MruA32bFjguC+EDPDdriSlxHYJwOQjN8KymZ3MDU2SJCIAdyNcyN5e2RLrE0C p9qxeRvcB9fhAhU62+ZsikU3n2rZocbMswdsczYGoe4kwEQUdfgOh2qFbbkA1JBUu1 MElO6lApEIM3w== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Athira Rajeev , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang , James Clark Subject: [PATCH 1/4] perf tools: Don't set attr.exclude_guest by default Date: Sun, 1 Sep 2024 18:46:18 -0700 Message-ID: <20240902014621.2002343-2-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240902014621.2002343-1-namhyung@kernel.org> References: <20240902014621.2002343-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The exclude_guest in the event attribute is to limit profiling in the host environment. But I'm not sure why we want to set it by default cause we don't care about it in most cases and I feel like it just makes new PMU implementation complicated. Of course it's useful for perf kvm command so I added the exclude_GH_default variable to preserve the old behavior for perf kvm and other commands like perf record and stat won't set the exclude bit. This is helpful for AMD IBS case since having exclude_guest bit will clear new feature bit due to the missing feature check logic. $ sysctl kernel.perf_event_paranoid kernel.perf_event_paranoid =3D 0 $ perf record -W -e ibs_op// -vv true 2>&1 | grep switching switching off PERF_FORMAT_LOST support switching off weight struct support switching off bpf_event switching off ksymbol switching off cloexec flag switching off mmap2 switching off exclude_guest, exclude_host Maybe Apple M1 users will scream but actually the default event for perf record was converted to "cycles:P" which doesn't set the exclude_guest bit already. So they need to specify the necessary modifier manually like "cycles:PH" and I think it's ok. Intestingly, I found it sets the exclude_bit if "u" modifier is used. I don't know why but it's neither intuitive nor consistent. Let's remove the bit there too. Cc: Mark Rutland Cc: James Clark Cc: Ravi Bangoria Signed-off-by: Namhyung Kim --- tools/perf/builtin-kvm.c | 1 + tools/perf/tests/attr/test-record-dummy-C0 | 2 +- tools/perf/tests/parse-events.c | 18 +++++++++--------- tools/perf/util/parse-events.c | 2 +- tools/perf/util/util.c | 10 ++++++++-- tools/perf/util/util.h | 3 +++ 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 692267b1b7e8..ca94dd3de04d 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv) "buildid-list", "stat", NULL }; const char *kvm_usage[] =3D { NULL, NULL }; =20 + exclude_HG_default =3D true; perf_host =3D 0; perf_guest =3D 1; =20 diff --git a/tools/perf/tests/attr/test-record-dummy-C0 b/tools/perf/tests/= attr/test-record-dummy-C0 index 576ec48b3aaf..8ce6f0a5df5b 100644 --- a/tools/perf/tests/attr/test-record-dummy-C0 +++ b/tools/perf/tests/attr/test-record-dummy-C0 @@ -37,7 +37,7 @@ precise_ip=3D0 mmap_data=3D0 sample_id_all=3D1 exclude_host=3D0 -exclude_guest=3D1 +exclude_guest=3D0 exclude_callchain_kernel=3D0 exclude_callchain_user=3D0 mmap2=3D1 diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index edc2adcf1bae..9179bf3084c3 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -932,7 +932,7 @@ static int test__group2(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kerne= l); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -947,7 +947,7 @@ static int test__group2(struct evlist *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_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); if (evsel__has_leader(evsel, leader)) @@ -1072,7 +1072,7 @@ static int test__group3(struct evlist *evlist __maybe= _unused) 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_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -1222,7 +1222,7 @@ static int test__group5(struct evlist *evlist __maybe= _unused) 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_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -1437,7 +1437,7 @@ static int test__leader_sample1(struct evlist *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_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1453,7 +1453,7 @@ static int test__leader_sample1(struct evlist *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_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); @@ -1468,7 +1468,7 @@ static int test__leader_sample1(struct evlist *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_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1497,7 +1497,7 @@ static int test__leader_sample2(struct evlist *evlist= __maybe_unused) 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_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1513,7 +1513,7 @@ static int test__leader_sample2(struct evlist *evlist= __maybe_unused) 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_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index fab01ba54e34..ab73b3d45f04 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1739,7 +1739,7 @@ static int parse_events__modifier_list(struct parse_e= vents_state *parse_state, if (mod.user) { if (!exclude) exclude =3D eu =3D ek =3D eh =3D 1; - if (!exclude_GH && !perf_guest) + if (!exclude_GH && !perf_guest && exclude_HG_default) eG =3D 1; eu =3D 0; } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 9d55a13787ce..7e3159faaa19 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void) =20 bool test_attr__enabled; =20 +bool exclude_HG_default; + bool perf_host =3D true; bool perf_guest =3D false; =20 void event_attr_init(struct perf_event_attr *attr) { + /* to capture ABI version */ + attr->size =3D sizeof(*attr); + + if (!exclude_HG_default) + return; + if (!perf_host) attr->exclude_host =3D 1; if (!perf_guest) attr->exclude_guest =3D 1; - /* to capture ABI version */ - attr->size =3D sizeof(*attr); } =20 int mkdir_p(char *path, mode_t mode) diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 9966c21aaf04..d33ae883a54f 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -21,6 +21,9 @@ extern const char perf_more_info_string[]; =20 extern const char *input_name; =20 +/* This will control if perf_{host,guest} will set attr.exclude_{host,gues= t}. */ +extern bool exclude_HG_default; + extern bool perf_host; extern bool perf_guest; =20 --=20 2.46.0.469.g59c65b2a67-goog From nobody Fri Dec 19 08:55:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68B0D376E9; Mon, 2 Sep 2024 01:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241586; cv=none; b=slNEG43oSOSnVL7CuXwXi1Zgmbf1uwDmOKtI5lMra7g2HRIf+6FdelkPOAEwBdMTa/FrfcGgjr322mC7lQtiIXfOrF8tfirT4b11eTOAQUCcj1Hf5Fuf6z+bpRRbBeAcqC/RPjeMNuJS6ZZ9vw7Jbx+wU5NFuoQqoW8IeOHanJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241586; c=relaxed/simple; bh=32VDGrtfHMytoPOOFqHZVvYDvIox7PLmSkvoaBgXsIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ag/0oLWqCAlAlvlPJDPqSLMFcwROiW6j3df/i9HUSvO4TYwN+nayQW41ORpn4eTLIXvHfpgFbzHsy2q0zoiTy/91h5eMEvsCdOwrcdtLJ8oosRGBnCvWEKtJlVdE6uhlTY5GZK6EAk9LOMfhjxTnO2eW/deFa10z8kL2Okc1BWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aIFNVEnS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aIFNVEnS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C60E1C4CECE; Mon, 2 Sep 2024 01:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725241584; bh=32VDGrtfHMytoPOOFqHZVvYDvIox7PLmSkvoaBgXsIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aIFNVEnSxcEGkzGCw7l2Te5Q58MnTyN15NRRL+8wGpFx4ELY8VYcjhaPYdDfEIpPp 3921zsPtICec10+cXv1DdVfPnVmpAnxCBTCCjMZb0pGwb5tetPYrxuBdPR8kXl7vRb M/jw37OZ6dE6Bk65bgCo5h3PovWCSQ6oltLEnPIrCKzPFe8jZ/p8GQy3qP9cq7zHt+ QtOzBOmWpAXq4357kNQ5BFKP7e4SWIEts6JT15KimcVu+LdHQ/TAnTzwoIg9w0XJN5 eDphdxxg0hnjbV1U5bMNaJuh/Tv3yI/waw/Tad0hZL110wYR5KcDrvqke/4+STjVPx WQzePK8kMpgUA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Athira Rajeev , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 2/4] perf tools: Simplify evsel__add_modifier() Date: Sun, 1 Sep 2024 18:46:19 -0700 Message-ID: <20240902014621.2002343-3-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240902014621.2002343-1-namhyung@kernel.org> References: <20240902014621.2002343-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since it doesn't set the exclude_guest, no need to special handle the bit and simply show only if one of host or guest bit is set. Signed-off-by: Namhyung Kim --- tools/perf/util/evsel.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 49cc71511c0c..57fe0f9b06f9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -548,7 +548,6 @@ static int evsel__add_modifiers(struct evsel *evsel, ch= ar *bf, size_t size) { int colon =3D 0, r =3D 0; struct perf_event_attr *attr =3D &evsel->core.attr; - bool exclude_guest_default =3D false; =20 #define MOD_PRINT(context, mod) do { \ if (!attr->exclude_##context) { \ @@ -560,17 +559,15 @@ static int evsel__add_modifiers(struct evsel *evsel, = char *bf, size_t size) MOD_PRINT(kernel, 'k'); MOD_PRINT(user, 'u'); MOD_PRINT(hv, 'h'); - exclude_guest_default =3D true; } =20 if (attr->precise_ip) { if (!colon) colon =3D ++r; r +=3D scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); - exclude_guest_default =3D true; } =20 - if (attr->exclude_host || attr->exclude_guest =3D=3D exclude_guest_defaul= t) { + if (attr->exclude_host || attr->exclude_guest) { MOD_PRINT(host, 'H'); MOD_PRINT(guest, 'G'); } --=20 2.46.0.469.g59c65b2a67-goog From nobody Fri Dec 19 08:55:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5235C28683; Mon, 2 Sep 2024 01:46:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241585; cv=none; b=gnMHOxI3ciYipaWUR0hwwP3gTOwk5XMzVlqhlw/PZuGINoG6tuPPU1X6UmEhok0csVKnQ/nbCte+W3rYXhA7jFziVz+u3ifAaiIKgPdsZphtfkhnELq6lNLbtLf+QY9zkWtVxuQgZ7eJV+bqejY9EVnOKAm/kqnqwfY5VMVVHlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241585; c=relaxed/simple; bh=suv85j1m1/NXNAqq3RNaOfwXgswYvyBgpuW6ErDVBEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BtOKJQSxUeSHnPwo2CtsuI0N2j7q14g+AZGv/IMxkpxbcZPdtpFnJmHCojawlj32Pqr5KoToT1+BkMycXuLUZoAWEHI0GHDmsWn/tbvPnYExwoEH6xS7z+q83zy7zB5cmxiCiTB12wy8k3I7P6p9bnJSND9Vz92nW+xpatueiq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=juZUXaoU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="juZUXaoU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89235C4CECB; Mon, 2 Sep 2024 01:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725241585; bh=suv85j1m1/NXNAqq3RNaOfwXgswYvyBgpuW6ErDVBEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=juZUXaoUAZ+p0Kjj2lc3/kAFdZI104nWvLNlGg2+9iAZmiZs/M4rzsHm/b9faQ3Lp 550N3jsaFsyFReNQTQTf9Msz3lTgBFn13tGLxzkwW5Iz+YjHLL9G3l+9LgRw54404g 3YCBqMGmtZvk85Ck0n8maXMavemizPG3Vdz5YbbGuPnA/8P3wNUQzYMDc3Oalv/vCj SR58CrZkEgM6wIDXxOsSCxLvXmzLHl3VZ9odvseCyTMFNZmWMiGprb3z2jhcFkIqkD vEmkK8+/OJ5FElISRPRuNfm3wnke3gI3L61RgTeqUWPoeMNSYiav5FLokxsEb4+52j zFdFWlK/t5V6Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Athira Rajeev , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 3/4] perf stat: Add --exclude-guest option Date: Sun, 1 Sep 2024 18:46:20 -0700 Message-ID: <20240902014621.2002343-4-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240902014621.2002343-1-namhyung@kernel.org> References: <20240902014621.2002343-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This option is to support the old behavior of setting exclude_guest by default. Now it doesn't set the bit so users want the old behavior can use this option. $ perf stat true Performance counter stats for 'true': 0.86 msec task-clock:u # 0.443 CPUs = utilized 0 context-switches:u # 0.000 /sec 0 cpu-migrations:u # 0.000 /sec 49 page-faults:u # 56.889 K/sec ... $ perf stat --exclude-guest true Performance counter stats for 'true': 0.79 msec task-clock:Hu # 0.490 CPUs = utilized 0 context-switches:Hu # 0.000 /sec 0 cpu-migrations:Hu # 0.000 /sec 49 page-faults:Hu # 62.078 K/sec ... Signed-off-by: Namhyung Kim --- tools/perf/Documentation/perf-stat.txt | 7 +++++++ tools/perf/builtin-stat.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentat= ion/perf-stat.txt index 2bc063672486..d28d8370a856 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -382,6 +382,13 @@ color the metric's computed value. Don't print output, warnings or messages. This is useful with perf stat record below to only write data to the perf.data file. =20 +--exclude-guest:: +Don't count event in the guest mode. It was the old behavior but the +default is changed to count guest events also. Use this option if you +want the old behavior (host only). Note that this option needs to be +before other events in case you added -e/--event option in the command +line. + STAT RECORD ----------- Stores stat data into perf data file. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cf985cdb9a6e..8b9889873d3e 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2492,6 +2492,8 @@ int cmd_stat(int argc, const char **argv) OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user, "Configure all used events to run in user space.", PARSE_OPT_EXCLUSIVE), + OPT_BOOLEAN(0, "exclude-guest", &exclude_HG_default, + "Don't count events in the guest mode"), OPT_BOOLEAN(0, "percore-show-thread", &stat_config.percore_show_thread, "Use with 'percore' event qualifier to show the event " "counts of one hardware thread by sum up total hardware " --=20 2.46.0.469.g59c65b2a67-goog From nobody Fri Dec 19 08:55:13 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68AE3376E0; Mon, 2 Sep 2024 01:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241586; cv=none; b=TZTntpuWWuXHeCljT/QBm/QrN1vVT4Pd2Q5efFD7u4p+cowP672nDcbxdPJBTyO3X0lJIe5athN8h1medhwCdSAuvQnldSvKVuRD45TSLULu7UV6BuIs3GQoYp0WwBrIBtCo6UCzK1gaSCjM/IHs3ZWC+6ma4vKRrgxlvwkADTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725241586; c=relaxed/simple; bh=SZsKD9uCuchZVWAml/dCRK+oDW3QBVeOZ/uiMQe13NI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GkH94fTNqbhSOWdhe3av6xnjeeTF6jgcGmboqgc6dqbcPsqW88ME6VTg5LU2VUyjGTNyIwDpglswvKvq54SQfFvgspLCftDOFJAvLCBrxkUQdZSEyHcr9NXalUvSCX1TsWK35d4chS+kAMygMdhisdgLlNXjoyXyzmZwrVzlDP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QaUJ+SZP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QaUJ+SZP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5857EC4CECC; Mon, 2 Sep 2024 01:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725241586; bh=SZsKD9uCuchZVWAml/dCRK+oDW3QBVeOZ/uiMQe13NI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QaUJ+SZPPT+iM4j6LjpFJNxBTfbFkXvsm9KfWgDN9kZTgqNBjKYfSbLQrwMAHLD9x BSCKHlpBiDIBup9cdTDi7Kd+Git8JNv2w9UoFhhSJOde5qYG8HsXQKMhIP/AV58KuZ xFVT7lQumzf525U1BOXI6ujBd6+r+tuICTBy1dKPW8aoDyp/61abGyIjcuO4WN30GO tpSg0tlCam1MqfVQWJR7HnuMPJWy/5IdX6uHrjtKNq5C5SpM/YIQ3uwxi9Uz9Gf2e9 zpOvD9pYW01u1aL5m5xjIW9sbw9vflJJIJa1URCEexYmV52AimHVedv21v5tF1Iwcc 3NlstVAoMZK+Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Athira Rajeev , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 4/4] perf tools: Do not set exclude_guest for precise_ip Date: Sun, 1 Sep 2024 18:46:21 -0700 Message-ID: <20240902014621.2002343-5-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240902014621.2002343-1-namhyung@kernel.org> References: <20240902014621.2002343-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It seems perf sets the exclude_guest bit because of Intel PEBS implementation which uses a virtual address. IIUC now kernel disables PEBS when it goes to the guest mode regardless of this bit so we don't need to set it explicitly. At least for the other archs/vendors. I found the commit 1342798cc13e set the exclude_guest for precise_ip in the tool and the commit 20b279ddb38c added kernel side enforcement which was reverted by commit a706d965dcfd later. Actually it doesn't set the exclude_guest for the default event (cycles:P) already. $ grep -m1 vendor /proc/cpuinfo vendor_id : GenuineIntel $ perf record -e cycles:P true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (9 samples) ] $ perf evlist -v | tr ',' '\n' | grep -e exclude -e precise precise_ip: 3 But having lower 'p' modifier set the bit for some reason. $ perf record -e cycles:pp true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (9 samples) ] $ perf evlist -v | tr ',' '\n' | grep -e exclude -e precise precise_ip: 2 exclude_guest: 1 Actually AMD IBS suffers from this because it doesn't support excludes and having this bit effectively disables new features in the current implementation (due to the missing feature check). $ grep -m1 vendor /proc/cpuinfo vendor_id : AuthenticAMD $ perf record -W -e cycles:p -vv true 2>&1 | grep switching switching off PERF_FORMAT_LOST support switching off weight struct support switching off bpf_event switching off ksymbol switching off cloexec flag switching off mmap2 switching off exclude_guest, exclude_host By not setting exclude_guest, we can fix this inconsistency and the troubles. Signed-off-by: Namhyung Kim --- tools/perf/tests/parse-events.c | 12 ++++-------- tools/perf/util/parse-events.c | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 9179bf3084c3..900107a171ee 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -898,8 +898,7 @@ static int test__group1(struct evlist *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_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 2= ); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); @@ -1016,9 +1015,8 @@ static int test__group3(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ TEST_ASSERT_VAL("wrong exclude guest", - evsel->core.attr.exclude_guest); + !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", @@ -1103,8 +1101,7 @@ static int test__group4(struct evlist *evlist __maybe= _unused) 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_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 1= ); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1122,8 +1119,7 @@ static int test__group4(struct evlist *evlist __maybe= _unused) 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_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 2= ); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ab73b3d45f04..4fa46ef7213c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1732,10 +1732,6 @@ static int parse_events__modifier_list(struct parse_= events_state *parse_state, int exclude =3D eu | ek | eh; int exclude_GH =3D group ? evsel->exclude_GH : 0; =20 - if (mod.precise) { - /* use of precise requires exclude_guest */ - eG =3D 1; - } if (mod.user) { if (!exclude) exclude =3D eu =3D ek =3D eh =3D 1; --=20 2.46.0.469.g59c65b2a67-goog