linux-stable/tools/perf
David Ahern 236a3bbd5c perf tools: Sample after exit loses thread correlation
Occassionally events (e.g., context-switch, sched tracepoints) are losing
the conversion of sample data associated with a thread. For example:

$ perf record -e sched:sched_switch -c 1 -a -- sleep 5
$ perf script
<selected events shown>
    ls 30482 [000] 1379727.583037: sched:sched_switch: prev_comm=ls prev_pid=30482 ...
    ls 30482 [000] 1379727.586339: sched:sched_switch: prev_comm=ls prev_pid=30482 ...
:30482 30482 [000] 1379727.589462: sched:sched_switch: prev_comm=ls prev_pid=30482 ...

The last line lost the conversion from tid to comm. If you look at the events
(perf script -D) you see why - a SAMPLE event is generated after the EXIT:

0 1379727589449774 0x1540b0 [0x38]: PERF_RECORD_EXIT(30482:30482):(30482:30482)
0 1379727589462497 0x1540e8 [0x80]: PERF_RECORD_SAMPLE(IP, 1): 30482/30482: 0xffffffff816416f1 period: 1 addr: 0
... thread: :30482:30482

When perf processes the EXIT event the thread is moved to the dead_threads
list. When the SAMPLE event is processed no thread exists for the pid so a new
one is created by machine__findnew_thread.

This patch address the problem by delaying the move to the dead_threads list
until the tid is re-used (per Adrian's suggestion).

With this patch we get the previous example shows:

  ls 30482 [000] 1379727.583037: sched:sched_switch: prev_comm=ls prev_pid=30482 ...
  ls 30482 [000] 1379727.586339: sched:sched_switch: prev_comm=ls prev_pid=30482 ...
  ls 30482 [000] 1379727.589462: sched:sched_switch: prev_comm=ls prev_pid=30482 ...

and

  0 1379727589449774 0x1540b0 [0x38]: PERF_RECORD_EXIT(30482:30482):(30482:30482)
  0 1379727589462497 0x1540e8 [0x80]: PERF_RECORD_SAMPLE(IP, 1): 30482/30482: 0xffffffff816416f1 period: 1 addr: 0
  ... thread: ls:30482

v4: per Arnaldo's request add dead flag to thread struct and set when task exits

v3: re-do from a time based check to a delayed move to dead_threads list

v2: Rebased to latest perf/core branch. Changed time comparison to use
    a macro which explicitly shows the time basis

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1376491767-84171-1-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-08-26 17:25:36 -03:00
..
arch perf tools: Fix compile of util/tsc.c 2013-08-07 17:35:24 -03:00
bench perf bench: Fix memcpy benchmark for large sizes 2013-07-22 12:41:56 -03:00
config perf tools: Use default include path notation for libtraceevent headers 2013-07-12 13:45:54 -03:00
Documentation perf trace: Make command line arguments consistent with perf-record 2013-08-26 17:25:35 -03:00
python perf python: Remove duplicate TID bit from mask 2013-08-07 17:35:25 -03:00
scripts perf script: Fix broken include in Context.xs 2013-07-10 13:47:00 -03:00
tests perf tests: Fix compile failure on do_sort_something 2013-08-14 11:42:45 -03:00
ui perf ui/gtk: Fix segmentation fault on perf_hpp__for_each_format loop 2013-08-07 17:35:39 -03:00
util perf tools: Sample after exit loses thread correlation 2013-08-26 17:25:36 -03:00
.gitignore perf tools: Ignore compiled python binaries 2012-09-07 12:10:58 -03:00
bash_completion perf tools: Complete tracepoint event names 2012-10-04 12:44:52 -03:00
builtin-annotate.c perf tools: Remove filter parameter of perf_event__preprocess_sample() 2013-08-12 10:31:11 -03:00
builtin-bench.c perf tools: Make numa benchmark optional 2013-01-30 10:36:21 -03:00
builtin-buildid-cache.c perf buildid-cache: Add --update option 2013-02-14 14:59:27 -03:00
builtin-buildid-list.c perf symbols: Generalize filter in __fprintf_buildid methods 2012-12-09 08:46:07 -03:00
builtin-diff.c perf tools: Remove filter parameter of perf_event__preprocess_sample() 2013-08-12 10:31:11 -03:00
builtin-evlist.c perf evlist: Pass the event_group info via perf_attr_details 2013-02-06 18:09:28 -03:00
builtin-help.c perf help: Fix --help for builtins 2012-10-22 12:35:49 -02:00
builtin-inject.c perf tools: Remove filter parameter of thread__find_addr_map() 2013-08-12 10:31:12 -03:00
builtin-kmem.c perf tools: struct thread has a tid not a pid 2013-07-12 13:53:50 -03:00
builtin-kvm.c perf kvm: Remove force option to cmd_record 2013-08-16 17:17:57 -03:00
builtin-list.c perf list: List kernel supplied event aliases 2013-07-12 13:53:53 -03:00
builtin-lock.c perf record: Remove -f/--force option 2013-07-08 17:37:25 -03:00
builtin-mem.c perf tools: Remove filter parameter of perf_event__preprocess_sample() 2013-08-12 10:31:11 -03:00
builtin-probe.c perf tools: Introduce tools/lib/lk library 2013-03-15 13:06:00 -03:00
builtin-record.c perf tools: Remove event types framework completely 2013-07-15 16:28:22 -03:00
builtin-report.c perf tools: Remove filter parameter of perf_event__preprocess_sample() 2013-08-12 10:31:11 -03:00
builtin-sched.c perf sched: Remove sched_process_fork tracepoint 2013-08-12 10:31:07 -03:00
builtin-script.c perf tools: Remove filter parameter of thread__find_addr_map() 2013-08-12 10:31:12 -03:00
builtin-stat.c perf stat: Flush output after each line in interval mode 2013-08-07 17:35:29 -03:00
builtin-timechart.c perf timechart: Remove event types framework only user 2013-07-15 16:14:47 -03:00
builtin-top.c perf tools: Remove filter parameter of perf_event__preprocess_sample() 2013-08-12 10:31:11 -03:00
builtin-trace.c perf trace: Make command line arguments consistent with perf-record 2013-08-26 17:25:35 -03:00
builtin.h perf tools: Add new mem command for memory access profiling 2013-04-01 12:21:44 -03:00
command-list.txt perf tools: Add new mem command for memory access profiling 2013-04-01 12:21:44 -03:00
CREDITS
design.txt perf tools: Update ioctl documentation for PERF_IOC_FLAG_GROUP 2012-05-31 11:38:42 -03:00
Makefile perf tests: Add test for reading object code 2013-08-07 17:35:30 -03:00
MANIFEST perf tools: Introduce tools/lib/lk library 2013-03-15 13:06:00 -03:00
perf-archive.sh perf archive: Make 'f' the last parameter for tar 2012-09-17 13:10:42 -03:00
perf.c perf tools: Convert needless static variable to local 2013-04-01 12:22:48 -03:00
perf.h perf kvm: Option to print events that exceed a duration 2013-08-12 10:31:04 -03:00