Skip to content

Commit 943b69a

Browse files
Jin Yaoacmel
Jin Yao
authored andcommitted
perf parse-events: Set exclude_guest=1 for user-space counting
Currently if we run 'perf record -e cycles:u', exclude_guest=0. But it doesn't make sense in most cases that we request for user-space counting but we also get the guest report. Of course, we also need to consider 'perf kvm' usage case that authorized perf users on the host may only want to count guest user space events. For example, # perf kvm --guest record -e cycles:u When we have 'exclude_guest=1' for 'perf kvm' usage, we may get nothing from guest events. To keep perf semantics consistent and clear, this patch sets exclude_guest=1 for user-space counting but except for 'perf kvm' usage. Before: perf record -e cycles:u ./div perf evlist -v cycles:u: ..., exclude_kernel: 1, exclude_hv: 1, ... After: perf record -e cycles:u ./div perf evlist -v cycles:u: ..., exclude_kernel: 1, exclude_hv: 1, exclude_guest: 1, ... Before: perf kvm --guest record -e cycles:u -vvv perf_event_attr: size 120 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 inherit 1 exclude_kernel 1 exclude_hv 1 freq 1 sample_id_all 1 After: perf kvm --guest record -e cycles:u -vvv perf_event_attr: size 120 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|ID|CPU|PERIOD read_format ID disabled 1 inherit 1 exclude_kernel 1 exclude_hv 1 freq 1 sample_id_all 1 For Before/After, exclude_guest are both 0 for perf kvm usage. perf test 6 6: Parse event definition strings : Ok Signed-off-by: Jin Yao <[email protected]> Tested-by: Like Xu <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a060c1f commit 943b69a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

tools/perf/tests/parse-events.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static int test__group2(struct evlist *evlist)
719719
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
720720
TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel);
721721
TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
722-
TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
722+
TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
723723
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
724724
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
725725
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));
@@ -842,7 +842,7 @@ static int test__group3(struct evlist *evlist __maybe_unused)
842842
TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user);
843843
TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel);
844844
TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv);
845-
TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest);
845+
TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest);
846846
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
847847
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
848848
TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel));

tools/perf/util/parse-events.c

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "util/evsel_config.h"
3838
#include "util/event.h"
3939
#include "util/pfm.h"
40+
#include "perf.h"
4041

4142
#define MAX_NAME_LEN 100
4243

@@ -1794,6 +1795,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str,
17941795
if (*str == 'u') {
17951796
if (!exclude)
17961797
exclude = eu = ek = eh = 1;
1798+
if (!exclude_GH && !perf_guest)
1799+
eG = 1;
17971800
eu = 0;
17981801
} else if (*str == 'k') {
17991802
if (!exclude)

0 commit comments

Comments
 (0)