perf tools: Don't set attr.exclude_guest by default
authorNamhyung Kim <namhyung@kernel.org>
Wed, 16 Oct 2024 06:23:52 +0000 (23:23 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 22 Oct 2024 16:52:11 +0000 (09:52 -0700)
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

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.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com>
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Cc: James Clark <james.clark@arm.com>
Cc: Atish Patra <atishp@atishpatra.org>
Cc: Mingwei Zhang <mizhang@google.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Link: https://lore.kernel.org/r/20241016062359.264929-3-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-kvm.c
tools/perf/tests/parse-events.c
tools/perf/tests/shell/attr/test-record-dummy-C0
tools/perf/util/parse-events.c
tools/perf/util/util.c
tools/perf/util/util.h

index 55ea17c5ff02acf7d17e8ffd5e968e84c50afb1d..099ce3ebf67ce6eef823e3330a67743d1fb6b9f4 100644 (file)
@@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv)
                                                "buildid-list", "stat", NULL };
        const char *kvm_usage[] = { NULL, NULL };
 
+       exclude_GH_default = true;
        perf_host  = 0;
        perf_guest = 1;
 
index 78e999f03d2d75f41d8deed42e6e3a1d7e1cf839..727683f249f66f5a3ca819621195e587c5dc8184 100644 (file)
@@ -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);
index 3050298bd6140d64999c2d3db51f20103544901b..91499405fff4d32bb305390121d087d3087cb743 100644 (file)
@@ -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
index 4507ae68198bd6a825ceea4401141e6134c31c4b..687125570f5633827f09a3345f420163b21a4617 100644 (file)
@@ -1740,7 +1740,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_GH_default)
                                eG = 1;
                        eu = 0;
                }
index 9d55a13787ce3c051d8109d3ca7d064697481904..280c86d61d8a7956db645980dad7a07ab9725906 100644 (file)
@@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void)
 
 bool test_attr__enabled;
 
+bool exclude_GH_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_GH_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)
index 14f2c70906be8684e63788054d57c4359db80f26..2359362885eafb910fc507191e5f9e54396824b9 100644 (file)
@@ -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_GH_default;
+
 extern bool perf_host;
 extern bool perf_guest;