Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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>

+23 -13
+1
tools/perf/builtin-kvm.c
··· 2147 2147 "buildid-list", "stat", NULL }; 2148 2148 const char *kvm_usage[] = { NULL, NULL }; 2149 2149 2150 + exclude_GH_default = true; 2150 2151 perf_host = 0; 2151 2152 perf_guest = 1; 2152 2153
+9 -9
tools/perf/tests/parse-events.c
··· 932 932 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 933 933 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 934 934 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 935 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 935 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 936 936 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 937 937 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 938 938 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); ··· 947 947 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 948 948 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 949 949 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 950 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 950 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 951 951 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 952 952 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 953 953 if (evsel__has_leader(evsel, leader)) ··· 1072 1072 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1073 1073 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1074 1074 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1075 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1075 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1076 1076 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1077 1077 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1078 1078 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); ··· 1222 1222 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1223 1223 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1224 1224 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1225 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1225 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1226 1226 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1227 1227 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1228 1228 TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); ··· 1437 1437 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1438 1438 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1439 1439 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1440 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1440 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1441 1441 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1442 1442 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1443 1443 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); ··· 1453 1453 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1454 1454 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1455 1455 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1456 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1456 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1457 1457 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1458 1458 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1459 1459 TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); ··· 1468 1468 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1469 1469 TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); 1470 1470 TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); 1471 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1471 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1472 1472 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1473 1473 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1474 1474 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); ··· 1497 1497 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1498 1498 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1499 1499 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1500 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1500 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1501 1501 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1502 1502 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1503 1503 TEST_ASSERT_VAL("wrong group name", !evsel->group_name); ··· 1513 1513 TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); 1514 1514 TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); 1515 1515 TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); 1516 - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); 1516 + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); 1517 1517 TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); 1518 1518 TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); 1519 1519 TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
+1 -1
tools/perf/tests/shell/attr/test-record-dummy-C0
··· 37 37 mmap_data=0 38 38 sample_id_all=1 39 39 exclude_host=0 40 - exclude_guest=1 40 + exclude_guest=0 41 41 exclude_callchain_kernel=0 42 42 exclude_callchain_user=0 43 43 mmap2=1
+1 -1
tools/perf/util/parse-events.c
··· 1740 1740 if (mod.user) { 1741 1741 if (!exclude) 1742 1742 exclude = eu = ek = eh = 1; 1743 - if (!exclude_GH && !perf_guest) 1743 + if (!exclude_GH && !perf_guest && exclude_GH_default) 1744 1744 eG = 1; 1745 1745 eu = 0; 1746 1746 }
+8 -2
tools/perf/util/util.c
··· 78 78 79 79 bool test_attr__enabled; 80 80 81 + bool exclude_GH_default; 82 + 81 83 bool perf_host = true; 82 84 bool perf_guest = false; 83 85 84 86 void event_attr_init(struct perf_event_attr *attr) 85 87 { 88 + /* to capture ABI version */ 89 + attr->size = sizeof(*attr); 90 + 91 + if (!exclude_GH_default) 92 + return; 93 + 86 94 if (!perf_host) 87 95 attr->exclude_host = 1; 88 96 if (!perf_guest) 89 97 attr->exclude_guest = 1; 90 - /* to capture ABI version */ 91 - attr->size = sizeof(*attr); 92 98 } 93 99 94 100 int mkdir_p(char *path, mode_t mode)
+3
tools/perf/util/util.h
··· 21 21 22 22 extern const char *input_name; 23 23 24 + /* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */ 25 + extern bool exclude_GH_default; 26 + 24 27 extern bool perf_host; 25 28 extern bool perf_guest; 26 29