Skip to content

Commit 35c8d21

Browse files
committed
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 <[email protected]> Reviewed-by: James Clark <[email protected]> Reviewed-by: Ravi Bangoria <[email protected]> Acked-by: Kan Liang <[email protected]> Cc: James Clark <[email protected]> Cc: Atish Patra <[email protected]> Cc: Mingwei Zhang <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent bb6e7cb commit 35c8d21

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

tools/perf/builtin-kvm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv)
21472147
"buildid-list", "stat", NULL };
21482148
const char *kvm_usage[] = { NULL, NULL };
21492149

2150+
exclude_GH_default = true;
21502151
perf_host = 0;
21512152
perf_guest = 1;
21522153

tools/perf/tests/parse-events.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static int test__group2(struct evlist *evlist)
932932
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
933933
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
934934
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);
936936
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
937937
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
938938
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
@@ -947,7 +947,7 @@ static int test__group2(struct evlist *evlist)
947947
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
948948
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
949949
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);
951951
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
952952
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
953953
if (evsel__has_leader(evsel, leader))
@@ -1072,7 +1072,7 @@ static int test__group3(struct evlist *evlist __maybe_unused)
10721072
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
10731073
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
10741074
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);
10761076
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
10771077
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
10781078
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
@@ -1222,7 +1222,7 @@ static int test__group5(struct evlist *evlist __maybe_unused)
12221222
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
12231223
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
12241224
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);
12261226
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
12271227
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
12281228
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
@@ -1437,7 +1437,7 @@ static int test__leader_sample1(struct evlist *evlist)
14371437
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14381438
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
14391439
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);
14411441
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14421442
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
14431443
TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
@@ -1453,7 +1453,7 @@ static int test__leader_sample1(struct evlist *evlist)
14531453
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14541454
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
14551455
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);
14571457
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14581458
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
14591459
TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader));
@@ -1468,7 +1468,7 @@ static int test__leader_sample1(struct evlist *evlist)
14681468
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14691469
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
14701470
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);
14721472
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
14731473
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
14741474
TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
@@ -1497,7 +1497,7 @@ static int test__leader_sample2(struct evlist *evlist __maybe_unused)
14971497
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
14981498
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
14991499
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);
15011501
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
15021502
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
15031503
TEST_ASSERT_VAL("wrong group name", !evsel->group_name);
@@ -1513,7 +1513,7 @@ static int test__leader_sample2(struct evlist *evlist __maybe_unused)
15131513
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
15141514
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
15151515
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);
15171517
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
15181518
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
15191519
TEST_ASSERT_VAL("wrong group name", !evsel->group_name);

tools/perf/tests/shell/attr/test-record-dummy-C0

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ precise_ip=0
3737
mmap_data=0
3838
sample_id_all=1
3939
exclude_host=0
40-
exclude_guest=1
40+
exclude_guest=0
4141
exclude_callchain_kernel=0
4242
exclude_callchain_user=0
4343
mmap2=1

tools/perf/util/parse-events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ static int parse_events__modifier_list(struct parse_events_state *parse_state,
17401740
if (mod.user) {
17411741
if (!exclude)
17421742
exclude = eu = ek = eh = 1;
1743-
if (!exclude_GH && !perf_guest)
1743+
if (!exclude_GH && !perf_guest && exclude_GH_default)
17441744
eG = 1;
17451745
eu = 0;
17461746
}

tools/perf/util/util.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void)
7878

7979
bool test_attr__enabled;
8080

81+
bool exclude_GH_default;
82+
8183
bool perf_host = true;
8284
bool perf_guest = false;
8385

8486
void event_attr_init(struct perf_event_attr *attr)
8587
{
88+
/* to capture ABI version */
89+
attr->size = sizeof(*attr);
90+
91+
if (!exclude_GH_default)
92+
return;
93+
8694
if (!perf_host)
8795
attr->exclude_host = 1;
8896
if (!perf_guest)
8997
attr->exclude_guest = 1;
90-
/* to capture ABI version */
91-
attr->size = sizeof(*attr);
9298
}
9399

94100
int mkdir_p(char *path, mode_t mode)

tools/perf/util/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ extern const char perf_more_info_string[];
2121

2222
extern const char *input_name;
2323

24+
/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
25+
extern bool exclude_GH_default;
26+
2427
extern bool perf_host;
2528
extern bool perf_guest;
2629

0 commit comments

Comments
 (0)