perf/core improvements
Hi Ingo,
Please pull from:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 perf/core
Regards,
- Arnaldo
Ian Munsie (2):
perf session: Fallback to unordered processing if no sample_id_all perf record,report,annotate,diff: Process events in order
tools/perf/builtin-annotate.c | 4 +++- tools/perf/builtin-buildid-list.c | 3 ++- tools/perf/builtin-diff.c | 6 ++++-- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 3 ++- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-record.c | 7 +++++-- tools/perf/builtin-report.c | 4 +++- tools/perf/builtin-sched.c | 3 ++- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-timechart.c | 3 ++- tools/perf/builtin-top.c | 2 +- tools/perf/util/session.c | 11 ++++++++++- tools/perf/util/session.h | 5 ++++- 14 files changed, 41 insertions(+), 16 deletions(-)
PATCH 1/2 perf session: Fallback to unordered processing if no sample_id_all
From: Ian Munsie <[email protected]>
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.
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-buildid-list.c | 3 ++- tools/perf/builtin-diff.c | 4 ++-- tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 3 ++- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 3 ++- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-timechart.c | 3 ++- tools/perf/builtin-top.c | 2 +- tools/perf/util/session.c | 11 ++++++++++- tools/perf/util/session.h | 5 ++++- 14 files changed, 31 insertions(+), 15 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -382,7 +382,7 @@ static int __cmd_annotate(void)int ret;struct perf_session *session; - session =perf_session__new (input_name,O_RDONLY , force, false); + session =perf_session__new (input_name,O_RDONLY , force, false, &event_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-buildid-list.c +2 -1
@@ -39,7 +39,8 @@ static int __cmd_buildid_list(void)int err =-1 ;struct perf_session *session; - session =perf_session__new (input_name,O_RDONLY , force, false); + session =perf_session__new (input_name,O_RDONLY , force, false, + &build_id__mark_dso_hit_ops);if (session ==NULL )return -1 ;
tools/perf/builtin-diff.c +2 -2
@@ -142,8 +142,8 @@ static int __cmd_diff(void)int ret, i;struct perf_session *session[2 ]; - session[0 ] =perf_session__new (input_old,O_RDONLY , force, false); - session[1 ] =perf_session__new (input_new,O_RDONLY , force, false); + session[0 ] =perf_session__new (input_old,O_RDONLY , force, false, &event_ops); + session[1 ] =perf_session__new (input_new,O_RDONLY , force, false, &event_ops);if (session[0 ] ==NULL || session[1 ] ==NULL )return -ENOMEM ;
tools/perf/builtin-inject.c +1 -1
@@ -196,7 +196,7 @@ static int __cmd_inject(void) inject_ops.tracing_data = event__repipe_tracing_data; } - session =perf_session__new (input_name,O_RDONLY , false, true); + session =perf_session__new (input_name,O_RDONLY , false, true, &inject_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-kmem.c +2 -1
@@ -481,7 +481,8 @@ static void sort_result(void)static int __cmd_kmem (void ) {int err = -EINVAL ; -struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 , false); +struct perf_session *session =perf_session__new (input_name,O_RDONLY , +0 , false, &event_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-lock.c +1 -1
@@ -858,7 +858,7 @@ static struct perf_event_ops eops = {static int read_events (void ) { - session =perf_session__new (input_name,O_RDONLY ,0 , false); + session =perf_session__new (input_name,O_RDONLY ,0 , false, &eops);if (!session)die ("Initializing perf session failed\n" );
tools/perf/builtin-record.c +1 -1
@@ -571,7 +571,7 @@ static int __cmd_record(int argc, const char **argv) } session =perf_session__new (output_name,O_WRONLY , - write_mode ==WRITE_FORCE , false); + write_mode ==WRITE_FORCE , false,NULL );if (session ==NULL ) {pr_err ("Not enough memory for reading perf file header\n" );return -1 ;
tools/perf/builtin-report.c +1 -1
@@ -308,7 +308,7 @@ static int __cmd_report(void)signal (SIGINT , sig_handler); - session =perf_session__new (input_name,O_RDONLY , force, false); + session =perf_session__new (input_name,O_RDONLY , force, false, &event_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-sched.c +2 -1
@@ -1643,7 +1643,8 @@ static struct perf_event_ops event_ops = {static int read_events (void ) {int err = -EINVAL ; -struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 , false); +struct perf_session *session =perf_session__new (input_name,O_RDONLY , +0 , false, &event_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-script.c +1 -1
@@ -779,7 +779,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)if (!script_name)setup_pager (); - session =perf_session__new (input_name,O_RDONLY ,0 , false); + session =perf_session__new (input_name,O_RDONLY ,0 , false, &event_ops);if (session ==NULL )return -ENOMEM ;
tools/perf/builtin-timechart.c +2 -1
@@ -937,7 +937,8 @@ static struct perf_event_ops event_ops = {static int __cmd_timechart (void ) { -struct perf_session *session =perf_session__new (input_name,O_RDONLY ,0 , false); +struct perf_session *session =perf_session__new (input_name,O_RDONLY , +0 , false, &event_ops);int ret = -EINVAL ;if (session ==NULL )
tools/perf/builtin-top.c +1 -1
@@ -1272,7 +1272,7 @@ static int __cmd_top(void)* FIXME: perf_session__new should allow passing a O_MMAP, so that all this * mmap reading, etc is encapsulated in it. Use O_WRONLY for now. */ -struct perf_session *session =perf_session__new (NULL ,O_WRONLY , false, false); +struct perf_session *session =perf_session__new (NULL ,O_WRONLY , false, false,NULL );if (session ==NULL )return -ENOMEM ;
tools/perf/util/session.c +10 -1
@@ -125,7 +125,9 @@ static void perf_session__destroy_kernel_maps(struct perf_session *self)machines__destroy_guest_kernel_maps (&self->machines); } -struct perf_session *perf_session__new (const char *filename,int mode,bool force,bool repipe) +struct perf_session *perf_session__new (const char *filename,int mode, +bool force,bool repipe, +struct perf_event_ops *ops) {size_t len = filename ?strlen (filename) +1 :0 ;struct perf_session *self =zalloc (sizeof (*self) + len);
@@ -170,6 +172,13 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc }perf_session__update_sample_type (self); + +if (ops && ops->ordering_requires_timestamps && + ops->ordered_samples && !self->sample_id_all) { +dump_printf ("WARNING: No sample_id_all support, falling back to unordered processing\n" ); + ops->ordered_samples = false; + } + out:return self; out_free:
tools/perf/util/session.h +4 -1
@@ -78,9 +78,12 @@ struct perf_event_ops { build_id;event_op2 finished_round;bool ordered_samples; +bool ordering_requires_timestamps; }; -struct perf_session *perf_session__new (const char *filename,int mode,bool force,bool repipe); +struct perf_session *perf_session__new (const char *filename,int mode, +bool force,bool repipe, +struct perf_event_ops *ops);void perf_session__delete (struct perf_session *self);void perf_event_header__bswap (struct perf_event_header *self);
Signature · 1 line
1.6.2.5
PATCH 2/2 perf record,report,annotate,diff: Process events in order
In reply to Arnaldo Carvalho de MeloFrom: Ian Munsie <[email protected]>
This patch changes perf report to ask for the ID info on all events be default if recording from multiple CPUs.
Perf report, annotate and diff will now process the events in order if the kernel is able to provide timestamps on all events. This ensures that events such as COMM and MMAP which are necessary to correctly interpret samples are processed prior to those samples so that they are attributed correctly.
Before:
# perf record ./cachetest # perf report
# Events: 6K cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ...............................
#
74.11% :3259 [unknown] [k] 0x4a6c
1.50% cachetest ld-2.11.2.so [.] 0x1777c
1.46% :3259 [kernel.kallsyms] [k] .perf_event_mmap_ctx
1.25% :3259 [kernel.kallsyms] [k] restore
0.74% :3259 [kernel.kallsyms] [k] ._raw_spin_lock
0.71% :3259 [kernel.kallsyms] [k] .filemap_fault
0.66% :3259 [kernel.kallsyms] [k] .memset
0.54% cachetest [kernel.kallsyms] [k] .sha_transform
0.54% :3259 [kernel.kallsyms] [k] .copy_4K_page
0.54% :3259 [kernel.kallsyms] [k] .find_get_page
0.52% :3259 [kernel.kallsyms] [k] .trace_hardirqs_off
0.50% :3259 [kernel.kallsyms] [k] .__do_fault
<SNIP>After:
# perf report
# Events: 6K cycles
#
# Overhead Command Shared Object Symbol
# ........ ....... ................. ...............................
#
44.28% cachetest cachetest [.] sumArrayNaive
22.53% cachetest cachetest [.] sumArrayOptimal
6.59% cachetest ld-2.11.2.so [.] 0x1777c
2.13% cachetest [unknown] [k] 0x340
1.46% cachetest [kernel.kallsyms] [k] .perf_event_mmap_ctx
1.25% cachetest [kernel.kallsyms] [k] restore
0.74% cachetest [kernel.kallsyms] [k] ._raw_spin_lock
0.71% cachetest [kernel.kallsyms] [k] .filemap_fault
0.66% cachetest [kernel.kallsyms] [k] .memset
0.54% cachetest [kernel.kallsyms] [k] .copy_4K_page
0.54% cachetest [kernel.kallsyms] [k] .find_get_page
0.54% cachetest [kernel.kallsyms] [k] .sha_transform
0.52% cachetest [kernel.kallsyms] [k] .trace_hardirqs_off
0.50% cachetest [kernel.kallsyms] [k] .__do_fault
<SNIP>Cc: Frederic Weisbecker <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
LKML-Reference: <[email protected]>
--- tools/perf/builtin-annotate.c | 2 ++ tools/perf/builtin-diff.c | 2 ++ tools/perf/builtin-record.c | 5 ++++- tools/perf/builtin-report.c | 2 ++ 4 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/builtin-annotate.c +2 -0
@@ -375,6 +375,8 @@ static struct perf_event_ops event_ops = { .mmap = event__process_mmap, .comm = event__process_comm, .fork = event__process_task, + .ordered_samples = true, + .ordering_requires_timestamps = true, };static int __cmd_annotate (void )
tools/perf/builtin-diff.c +2 -0
@@ -61,6 +61,8 @@ static struct perf_event_ops event_ops = { .exit = event__process_task, .fork = event__process_task, .lost = event__process_lost, + .ordered_samples = true, + .ordering_requires_timestamps = true, }; static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
tools/perf/builtin-record.c +4 -1
@@ -285,7 +285,7 @@ static void create_counter(int counter, int cpu)if (system_wide) attr->sample_type |=PERF_SAMPLE_CPU ; -if (sample_time) +if (sample_time || system_wide || !no_inherit || cpu_list) attr->sample_type |=PERF_SAMPLE_TIME ;if (raw_samples) {
@@ -327,6 +327,9 @@ try_again:* Old kernel, no attr->sample_id_type_all field */ sample_id_all_avail = false; +if (!sample_time && !raw_samples) + attr->sample_type &= ~PERF_SAMPLE_TIME ; + goto retry_sample_id; }
tools/perf/builtin-report.c +2 -0
@@ -244,6 +244,8 @@ static struct perf_event_ops event_ops = { .event_type = event__process_event_type, .tracing_data = event__process_tracing_data, .build_id = event__process_build_id, + .ordered_samples = true, + .ordering_requires_timestamps = true, };extern volatile int session_done;
Signature · 1 line
1.6.2.5