Skip to content

Commit 442ad22

Browse files
ahunter6acmel
authored andcommitted
perf record: Fix duplicated sideband events with Intel PT system wide tracing
Commit 0a892c1 ("perf record: Add dummy event during system wide synthesis") reveals an issue with Intel PT system wide tracing. Specifically that Intel PT already adds a dummy tracking event, and it is not the first event. Adding another dummy tracking event causes duplicated sideband events. Fix by checking for an existing dummy tracking event first. Example showing duplicated switch events: Before: # perf record -a -e intel_pt//u uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.895 MB perf.data ] # perf script --no-itrace --show-switch-events | head swapper 0 [007] 6390.516222: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 11/11 swapper 0 [007] 6390.516222: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 11/11 rcu_sched 11 [007] 6390.516223: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 0/0 rcu_sched 11 [007] 6390.516224: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 0/0 rcu_sched 11 [007] 6390.516227: PERF_RECORD_SWITCH_CPU_WIDE OUT next pid/tid: 0/0 rcu_sched 11 [007] 6390.516227: PERF_RECORD_SWITCH_CPU_WIDE OUT next pid/tid: 0/0 swapper 0 [007] 6390.516228: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 11/11 swapper 0 [007] 6390.516228: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 11/11 swapper 0 [002] 6390.516415: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 5556/5559 swapper 0 [002] 6390.516416: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 5556/5559 After: # perf record -a -e intel_pt//u uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.868 MB perf.data ] # perf script --no-itrace --show-switch-events | head swapper 0 [005] 6450.567013: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 7179/7181 perf 7181 [005] 6450.567014: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 0/0 perf 7181 [005] 6450.567028: PERF_RECORD_SWITCH_CPU_WIDE OUT next pid/tid: 0/0 swapper 0 [005] 6450.567029: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 7179/7181 swapper 0 [005] 6450.571699: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 11/11 rcu_sched 11 [005] 6450.571700: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 0/0 rcu_sched 11 [005] 6450.571702: PERF_RECORD_SWITCH_CPU_WIDE OUT next pid/tid: 0/0 swapper 0 [005] 6450.571703: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 11/11 swapper 0 [005] 6450.579703: PERF_RECORD_SWITCH_CPU_WIDE OUT preempt next pid/tid: 11/11 rcu_sched 11 [005] 6450.579704: PERF_RECORD_SWITCH_CPU_WIDE IN prev pid/tid: 0/0 Signed-off-by: Adrian Hunter <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 640432e commit 442ad22

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

tools/perf/builtin-record.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -852,20 +852,20 @@ static int record__open(struct record *rec)
852852
* event synthesis.
853853
*/
854854
if (opts->initial_delay || target__has_cpu(&opts->target)) {
855-
if (perf_evlist__add_dummy(evlist))
856-
return -ENOMEM;
855+
pos = perf_evlist__get_tracking_event(evlist);
856+
if (!evsel__is_dummy_event(pos)) {
857+
/* Set up dummy event. */
858+
if (perf_evlist__add_dummy(evlist))
859+
return -ENOMEM;
860+
pos = evlist__last(evlist);
861+
perf_evlist__set_tracking_event(evlist, pos);
862+
}
857863

858-
/* Disable tracking of mmaps on lead event. */
859-
pos = evlist__first(evlist);
860-
pos->tracking = 0;
861-
/* Set up dummy event. */
862-
pos = evlist__last(evlist);
863-
pos->tracking = 1;
864864
/*
865865
* Enable the dummy event when the process is forked for
866866
* initial_delay, immediately for system wide.
867867
*/
868-
if (opts->initial_delay)
868+
if (opts->initial_delay && !pos->immediate)
869869
pos->core.attr.enable_on_exec = 1;
870870
else
871871
pos->immediate = 1;

tools/perf/util/evlist.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,18 @@ void perf_evlist__to_front(struct evlist *evlist,
15661566
list_splice(&move, &evlist->core.entries);
15671567
}
15681568

1569+
struct evsel *perf_evlist__get_tracking_event(struct evlist *evlist)
1570+
{
1571+
struct evsel *evsel;
1572+
1573+
evlist__for_each_entry(evlist, evsel) {
1574+
if (evsel->tracking)
1575+
return evsel;
1576+
}
1577+
1578+
return evlist__first(evlist);
1579+
}
1580+
15691581
void perf_evlist__set_tracking_event(struct evlist *evlist,
15701582
struct evsel *tracking_evsel)
15711583
{

tools/perf/util/evlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ void perf_evlist__to_front(struct evlist *evlist,
335335
evlist__cpu_iter_start(evlist); \
336336
perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
337337

338+
struct evsel *perf_evlist__get_tracking_event(struct evlist *evlist);
338339
void perf_evlist__set_tracking_event(struct evlist *evlist,
339340
struct evsel *tracking_evsel);
340341

tools/perf/util/evsel.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,6 @@ static void evsel__apply_config_terms(struct evsel *evsel,
898898
}
899899
}
900900

901-
static bool is_dummy_event(struct evsel *evsel)
902-
{
903-
return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) &&
904-
(evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
905-
}
906-
907901
struct evsel_config_term *__evsel__get_config_term(struct evsel *evsel, enum evsel_term_type type)
908902
{
909903
struct evsel_config_term *term, *found_term = NULL;
@@ -1161,7 +1155,7 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
11611155
* The software event will trigger -EOPNOTSUPP error out,
11621156
* if BRANCH_STACK bit is set.
11631157
*/
1164-
if (is_dummy_event(evsel))
1158+
if (evsel__is_dummy_event(evsel))
11651159
evsel__reset_sample_bit(evsel, BRANCH_STACK);
11661160
}
11671161

tools/perf/util/evsel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ static inline bool evsel__has_br_stack(const struct evsel *evsel)
399399
evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK;
400400
}
401401

402+
static inline bool evsel__is_dummy_event(struct evsel *evsel)
403+
{
404+
return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) &&
405+
(evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
406+
}
407+
402408
struct perf_env *evsel__env(struct evsel *evsel);
403409

404410
int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);

0 commit comments

Comments
 (0)