Skip to contentSkip to conversation

perf tools: Do not set attr.exclude_guest by default (v1)

PATCH In review Namhyung Kim 3 participants 9 messages Sep 2, 2024 – Sep 3, 2024 1 message not in the archive perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf tools: Do not set attr.exclude_guest by default (v1)

Hello,

I found perf tools set exclude_guest bit inconsistently. It used to set the bit but now the default event for perf record doesn't. So I'm wondering why we want the bit in the first place.

Actually it's not good for PMUs don't support any exclusion like AMD IBS because it disables new features after the exclude_guest due to the missing feature detection logic.

AFAIK it doesn't matter for the most cases but perf kvm. If users need to set the bit, they can still use :H modifier. Please let me know if it's ok for you.

Thanks,
Namhyung

Namhyung Kim (4):
perf tools: Don't set attr.exclude_guest by default perf tools: Simplify evsel__add_modifier() perf stat: Add --exclude-guest option
perf tools: Do not set exclude_guest for precise_ip

 tools/perf/Documentation/perf-stat.txt     |  7 +++++
 tools/perf/builtin-kvm.c                   |  1 +
 tools/perf/builtin-stat.c                  |  2 ++
 tools/perf/tests/attr/test-record-dummy-C0 |  2 +-
 tools/perf/tests/parse-events.c            | 30 ++++++++++------------
 tools/perf/util/evsel.c                    |  5 +---
 tools/perf/util/parse-events.c             |  6 +----
 tools/perf/util/util.c                     | 10 ++++++--
 tools/perf/util/util.h                     |  3 +++
 9 files changed, 37 insertions(+), 29 deletions(-)
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
author maintainer
#1 lore raw

PATCH 1/4 perf tools: Don't set attr.exclude_guest by default

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 = 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 <[email protected]>
Cc James Clark <[email protected]>
Cc Ravi Bangoria <[email protected]>
---
 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(-)
tools/perf/builtin-kvm.c +1 -0
index 692267b1b7e8..ca94dd3de04d 100644
@@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv)
 						"buildid-list", "stat", NULL };
 	const char *kvm_usage[] = { NULL, NULL };
 
+	exclude_HG_default = true;
 	perf_host  = 0;
 	perf_guest = 1;
 
tools/perf/tests/attr/test-record-dummy-C0 +1 -1
index 576ec48b3aaf..8ce6f0a5df5b 100644
@@ -37,7 +37,7 @@ precise_ip=0
 mmap_data=0
 sample_id_all=1
 exclude_host=0
-exclude_guest=1
+exclude_guest=0
 exclude_callchain_kernel=0
 exclude_callchain_user=0
 mmap2=1
tools/perf/tests/parse-events.c +9 -9
index edc2adcf1bae..9179bf3084c3 100644
@@ -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_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));
@@ -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);
tools/perf/util/parse-events.c +1 -1
index fab01ba54e34..ab73b3d45f04 100644
@@ -1739,7 +1739,7 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
 		if (mod.user) {
 			if (!exclude)
 				exclude = eu = ek = eh = 1;
-			if (!exclude_GH && !perf_guest)
+			if (!exclude_GH && !perf_guest && exclude_HG_default)
 				eG = 1;
 			eu = 0;
 		}
tools/perf/util/util.c +8 -2
index 9d55a13787ce..7e3159faaa19 100644
@@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void)
 
 bool test_attr__enabled;
 
+bool exclude_HG_default;
+
 bool perf_host  = true;
 bool perf_guest = false;
 
 void event_attr_init(struct perf_event_attr *attr)
 {
+	/* to capture ABI version */
+	attr->size = sizeof(*attr);
+
+	if (!exclude_HG_default)
+		return;
+
 	if (!perf_host)
 		attr->exclude_host  = 1;
 	if (!perf_guest)
 		attr->exclude_guest = 1;
-	/* to capture ABI version */
-	attr->size = sizeof(*attr);
 }
 
 int mkdir_p(char *path, mode_t mode)
tools/perf/util/util.h +3 -0
index 9966c21aaf04..d33ae883a54f 100644
@@ -21,6 +21,9 @@ extern const char perf_more_info_string[];
 
 extern const char *input_name;
 
+/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
+extern bool exclude_HG_default;
+
 extern bool perf_host;
 extern bool perf_guest;
 
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
reviewer
#2 lore raw

Re: [PATCH 1/4] perf tools: Don't set attr.exclude_guest by default

Quoted 10 lines · Namhyung Kim

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.

Probably another case where again the real fix would be to add /sys/bus/event_source/devices/cpu_core/caps/exclude_guest and then we're able to keep the defaults.

Quoted 13 lines
   $ sysctl kernel.perf_event_paranoid
   kernel.perf_event_paranoid = 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
Quoted 4 lines

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.

I'm reading this to assume that the default record command was always broken then? But what about any other command, now isn't just "cycles" also broken making it worse?

See 25412c036:

...
(c) The Apple M1/M2 PMU requires that perf_event_attr::exclude_guest is set as the hardware PMU does not count while a guest is running (but might be extended in future to do so).
...

Quoted 185 lines

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 <[email protected]>
Cc James Clark <[email protected]>
Cc Ravi Bangoria <[email protected]>
---
  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(-)
tools/perf/builtin-kvm.c +1 -0
index 692267b1b7e8..ca94dd3de04d 100644
@@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv)
  						"buildid-list", "stat", NULL };
  	const char *kvm_usage[] = { NULL, NULL };
 
+	exclude_HG_default = true;
  	perf_host  = 0;
  	perf_guest = 1;
 
tools/perf/tests/attr/test-record-dummy-C0 +1 -1
index 576ec48b3aaf..8ce6f0a5df5b 100644
@@ -37,7 +37,7 @@ precise_ip=0
  mmap_data=0
  sample_id_all=1
  exclude_host=0
-exclude_guest=1
+exclude_guest=0
  exclude_callchain_kernel=0
  exclude_callchain_user=0
  mmap2=1
tools/perf/tests/parse-events.c +9 -9
index edc2adcf1bae..9179bf3084c3 100644
@@ -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_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));
@@ -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);
tools/perf/util/parse-events.c +1 -1
index fab01ba54e34..ab73b3d45f04 100644
@@ -1739,7 +1739,7 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
  		if (mod.user) {
  			if (!exclude)
  				exclude = eu = ek = eh = 1;
-			if (!exclude_GH && !perf_guest)
+			if (!exclude_GH && !perf_guest && exclude_HG_default)
  				eG = 1;
  			eu = 0;
  		}
tools/perf/util/util.c +8 -2
index 9d55a13787ce..7e3159faaa19 100644
@@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void)
 
  bool test_attr__enabled;
 
+bool exclude_HG_default;
+
  bool perf_host  = true;
  bool perf_guest = false;
 
  void event_attr_init(struct perf_event_attr *attr)
  {
+	/* to capture ABI version */
+	attr->size = sizeof(*attr);
+
+	if (!exclude_HG_default)
+		return;
+
  	if (!perf_host)
  		attr->exclude_host  = 1;
  	if (!perf_guest)
  		attr->exclude_guest = 1;
-	/* to capture ABI version */
-	attr->size = sizeof(*attr);
  }
 
  int mkdir_p(char *path, mode_t mode)
tools/perf/util/util.h +3 -0
index 9966c21aaf04..d33ae883a54f 100644
@@ -21,6 +21,9 @@ extern const char perf_more_info_string[];
 
  extern const char *input_name;
 
+/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
+extern bool exclude_HG_default;
+
  extern bool perf_host;
  extern bool perf_guest;
 
author maintainer
#3 lore raw

Re: [PATCH 1/4] perf tools: Don't set attr.exclude_guest by default

Quoted 14 lines · James Clark
Quoted 10 lines · Namhyung Kim

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.

Quoted 3 lines

Probably another case where again the real fix would be to add /sys/bus/event_source/devices/cpu_core/caps/exclude_guest and then we're able to keep the defaults.

Yep, I really need to work on it. But it's another story whether it's supported and whether it's required.

Quoted 14 lines
Quoted 14 lines

   $ sysctl kernel.perf_event_paranoid
   kernel.perf_event_paranoid = 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
Quoted 8 lines
Quoted 4 lines

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.

I'm reading this to assume that the default record command was always broken then? But what about any other command, now isn't just "cycles" also broken making it worse?

Hmm.. right. Maybe we can add a detection logic to figure out the required exclude bits for a PMU at runtime.

Thanks,
Namhyung

Quoted 185 lines

See 25412c036:

...
(c) The Apple M1/M2 PMU requires that perf_event_attr::exclude_guest is set as the hardware PMU does not count while a guest is running (but might be extended in future to do so).
...

Quoted 176 lines

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 <[email protected]>
Cc James Clark <[email protected]>
Cc Ravi Bangoria <[email protected]>
---
  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(-)
tools/perf/builtin-kvm.c +1 -0
index 692267b1b7e8..ca94dd3de04d 100644
@@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv)
  						"buildid-list", "stat", NULL };
  	const char *kvm_usage[] = { NULL, NULL };
+	exclude_HG_default = true;
  	perf_host  = 0;
  	perf_guest = 1;
tools/perf/tests/attr/test-record-dummy-C0 +1 -1
index 576ec48b3aaf..8ce6f0a5df5b 100644
@@ -37,7 +37,7 @@ precise_ip=0
  mmap_data=0
  sample_id_all=1
  exclude_host=0
-exclude_guest=1
+exclude_guest=0
  exclude_callchain_kernel=0
  exclude_callchain_user=0
  mmap2=1
tools/perf/tests/parse-events.c +9 -9
index edc2adcf1bae..9179bf3084c3 100644
@@ -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_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));
@@ -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);
tools/perf/util/parse-events.c +1 -1
index fab01ba54e34..ab73b3d45f04 100644
@@ -1739,7 +1739,7 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
  		if (mod.user) {
  			if (!exclude)
  				exclude = eu = ek = eh = 1;
-			if (!exclude_GH && !perf_guest)
+			if (!exclude_GH && !perf_guest && exclude_HG_default)
  				eG = 1;
  			eu = 0;
  		}
tools/perf/util/util.c +8 -2
index 9d55a13787ce..7e3159faaa19 100644
@@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void)
  bool test_attr__enabled;
+bool exclude_HG_default;
+
  bool perf_host  = true;
  bool perf_guest = false;
  void event_attr_init(struct perf_event_attr *attr)
  {
+	/* to capture ABI version */
+	attr->size = sizeof(*attr);
+
+	if (!exclude_HG_default)
+		return;
+
  	if (!perf_host)
  		attr->exclude_host  = 1;
  	if (!perf_guest)
  		attr->exclude_guest = 1;
-	/* to capture ABI version */
-	attr->size = sizeof(*attr);
  }
  int mkdir_p(char *path, mode_t mode)
tools/perf/util/util.h +3 -0
index 9966c21aaf04..d33ae883a54f 100644
@@ -21,6 +21,9 @@ extern const char perf_more_info_string[];
  extern const char *input_name;
+/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
+extern bool exclude_HG_default;
+
  extern bool perf_host;
  extern bool perf_guest;
author maintainer
#4 lore raw

PATCH 2/4 perf tools: Simplify evsel__add_modifier()

In reply to Namhyung Kim

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.

---
 tools/perf/util/evsel.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/evsel.c +1 -4
index 49cc71511c0c..57fe0f9b06f9 100644
@@ -548,7 +548,6 @@ static int evsel__add_modifiers(struct evsel *evsel, char *bf, size_t size)
 {
 	int colon = 0, r = 0;
 	struct perf_event_attr *attr = &evsel->core.attr;
-	bool exclude_guest_default = false;
 
 #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 = true;
 	}
 
 	if (attr->precise_ip) {
 		if (!colon)
 			colon = ++r;
 		r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp");
-		exclude_guest_default = true;
 	}
 
-	if (attr->exclude_host || attr->exclude_guest == exclude_guest_default) {
+	if (attr->exclude_host || attr->exclude_guest) {
 		MOD_PRINT(host, 'H');
 		MOD_PRINT(guest, 'G');
 	}
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
author maintainer
#5 lore raw

PATCH 3/4 perf stat: Add --exclude-guest option

In reply to Namhyung Kim

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
                 ...
---
 tools/perf/Documentation/perf-stat.txt | 7 +++++++
 tools/perf/builtin-stat.c              | 2 ++
 2 files changed, 9 insertions(+)
tools/perf/Documentation/perf-stat.txt +7 -0
index 2bc063672486..d28d8370a856 100644
@@ -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.
 
+--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.
tools/perf/builtin-stat.c +2 -0
index cf985cdb9a6e..8b9889873d3e 100644
@@ -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 "
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
author maintainer
#6 lore raw

PATCH 4/4 perf tools: Do not set exclude_guest for precise_ip

In reply to Namhyung Kim

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.

---
 tools/perf/tests/parse-events.c | 12 ++++--------
 tools/perf/util/parse-events.c  |  4 ----
 2 files changed, 4 insertions(+), 12 deletions(-)
tools/perf/tests/parse-events.c +4 -8
index 9179bf3084c3..900107a171ee 100644
@@ -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 == 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 == 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 == 2);
 		TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
tools/perf/util/parse-events.c +0 -4
index ab73b3d45f04..4fa46ef7213c 100644
@@ -1732,10 +1732,6 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
 		int exclude = eu | ek | eh;
 		int exclude_GH = group ? evsel->exclude_GH : 0;
 
-		if (mod.precise) {
-			/* use of precise requires exclude_guest */
-			eG = 1;
-		}
 		if (mod.user) {
 			if (!exclude)
 				exclude = eu = ek = eh = 1;
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
maintainer
#7 lore raw
In reply to Namhyung Kim
Quoted 6 lines · Namhyung Kim

Hello,

I found perf tools set exclude_guest bit inconsistently. It used to set the bit but now the default event for perf record doesn't. So I'm wondering why we want the bit in the first place.

Quoted 7 lines

Actually it's not good for PMUs don't support any exclusion like AMD IBS because it disables new features after the exclude_guest due to the missing feature detection logic.

AFAIK it doesn't matter for the most cases but perf kvm. If users need to set the bit, they can still use :H modifier. Please let me know if it's ok for you.

IIRc the point of setting exclude_guest by default was so that default perf keeps working in the precense of that PMU pass through mess, no?

A message that is not in the archive (sent off-list or not yet received): CAM9d7cg13isO4rmwUpDAm9pL7qLYDOfXsBnGhr6eLMuUyM2Z2w@mail.gmail.com

maintainer
#9 lore raw
Quoted 19 lines · Namhyung Kim

Hi Peter,

Quoted 16 lines · Peter Zijlstra
Quoted 13 lines · Namhyung Kim

Hello,

I found perf tools set exclude_guest bit inconsistently. It used to set the bit but now the default event for perf record doesn't. So I'm wondering why we want the bit in the first place.

Actually it's not good for PMUs don't support any exclusion like AMD IBS because it disables new features after the exclude_guest due to the missing feature detection logic.

AFAIK it doesn't matter for the most cases but perf kvm. If users need to set the bit, they can still use :H modifier. Please let me know if it's ok for you.

Quoted 6 lines
Quoted 2 lines

IIRc the point of setting exclude_guest by default was so that default perf keeps working in the precense of that PMU pass through mess, no?

Sorry I haven't followed the vPMU pass through threads. It makes sense to keep the exclude_guest for the kernels with it. But I guess it's configurable via kernel config and/or boot option.

Yeah, you need KVM build with the passthrough thing on, and then at runtime enable it or something -- I too have to still read the latest posting.

Quoted 2 lines

A question, with PMU pass through would the kernel reject host events which don't set the exclude_guest?

Yes.