Skip to content

Commit 21ef97f

Browse files
Ian Munsieacmel
authored andcommitted
perf session: Fallback to unordered processing if no sample_id_all
If we are running the new perf on an old kernel without support for sample_id_all, we should fall back to the old unordered processing of events. If we didn't than we would *always* process events without timestamps out of order, whether or not we hit a reordering race. In other words, instead of there being a chance of not attributing samples correctly, we would guarantee that samples would not be attributed. While processing all events without timestamps before events with timestamps may seem like an intuitive solution, it falls down as PERF_RECORD_EXIT events would also be processed before any samples. Even with a workaround for that case, samples before/after an exec would not be attributed correctly. This patch allows commands to indicate whether they need to fall back to unordered processing, so that commands that do not care about timestamps on every event will not be affected. If we do fallback, this will print out a warning if report -D was invoked. This patch adds the test in perf_session__new so that we only need to test once per session. Commands that do not use an event_ops (such as record and top) can simply pass NULL in it's place. Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> LKML-Reference: <1291951882-sup-6069@au1.ibm.com> Signed-off-by: Ian Munsie <imunsie@au1.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7639dae commit 21ef97f

14 files changed

Lines changed: 31 additions & 15 deletions

‎tools/perf/builtin-annotate.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int __cmd_annotate(void)
382382
int ret;
383383
struct perf_session *session;
384384

385-
session = perf_session__new(input_name, O_RDONLY, force, false);
385+
session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
386386
if (session == NULL)
387387
return -ENOMEM;
388388

‎tools/perf/builtin-buildid-list.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static int __cmd_buildid_list(void)
3939
int err = -1;
4040
struct perf_session *session;
4141

42-
session = perf_session__new(input_name, O_RDONLY, force, false);
42+
session = perf_session__new(input_name, O_RDONLY, force, false,
43+
&build_id__mark_dso_hit_ops);
4344
if (session == NULL)
4445
return -1;
4546

‎tools/perf/builtin-diff.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ static int __cmd_diff(void)
142142
int ret, i;
143143
struct perf_session *session[2];
144144

145-
session[0] = perf_session__new(input_old, O_RDONLY, force, false);
146-
session[1] = perf_session__new(input_new, O_RDONLY, force, false);
145+
session[0] = perf_session__new(input_old, O_RDONLY, force, false, &event_ops);
146+
session[1] = perf_session__new(input_new, O_RDONLY, force, false, &event_ops);
147147
if (session[0] == NULL || session[1] == NULL)
148148
return -ENOMEM;
149149

‎tools/perf/builtin-inject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int __cmd_inject(void)
196196
inject_ops.tracing_data = event__repipe_tracing_data;
197197
}
198198

199-
session = perf_session__new(input_name, O_RDONLY, false, true);
199+
session = perf_session__new(input_name, O_RDONLY, false, true, &inject_ops);
200200
if (session == NULL)
201201
return -ENOMEM;
202202

‎tools/perf/builtin-kmem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ static void sort_result(void)
481481
static int __cmd_kmem(void)
482482
{
483483
int err = -EINVAL;
484-
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
484+
struct perf_session *session = perf_session__new(input_name, O_RDONLY,
485+
0, false, &event_ops);
485486
if (session == NULL)
486487
return -ENOMEM;
487488

‎tools/perf/builtin-lock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static struct perf_event_ops eops = {
858858

859859
static int read_events(void)
860860
{
861-
session = perf_session__new(input_name, O_RDONLY, 0, false);
861+
session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
862862
if (!session)
863863
die("Initializing perf session failed\n");
864864

‎tools/perf/builtin-record.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ static int __cmd_record(int argc, const char **argv)
572572
}
573573

574574
session = perf_session__new(output_name, O_WRONLY,
575-
write_mode == WRITE_FORCE, false);
575+
write_mode == WRITE_FORCE, false, NULL);
576576
if (session == NULL) {
577577
pr_err("Not enough memory for reading perf file header\n");
578578
return -1;

‎tools/perf/builtin-report.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static int __cmd_report(void)
308308

309309
signal(SIGINT, sig_handler);
310310

311-
session = perf_session__new(input_name, O_RDONLY, force, false);
311+
session = perf_session__new(input_name, O_RDONLY, force, false, &event_ops);
312312
if (session == NULL)
313313
return -ENOMEM;
314314

‎tools/perf/builtin-sched.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,8 @@ static struct perf_event_ops event_ops = {
16431643
static int read_events(void)
16441644
{
16451645
int err = -EINVAL;
1646-
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
1646+
struct perf_session *session = perf_session__new(input_name, O_RDONLY,
1647+
0, false, &event_ops);
16471648
if (session == NULL)
16481649
return -ENOMEM;
16491650

‎tools/perf/builtin-script.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
779779
if (!script_name)
780780
setup_pager();
781781

782-
session = perf_session__new(input_name, O_RDONLY, 0, false);
782+
session = perf_session__new(input_name, O_RDONLY, 0, false, &event_ops);
783783
if (session == NULL)
784784
return -ENOMEM;
785785

0 commit comments

Comments
 (0)