perf tools: Fix use of wrong event when processing exit events
Adrian Hunter
reviewerPATCH 1/1 perf tools: Fix use of wrong event when processing exit events
In a couple of cases the 'comm' member of 'union event' has been used instead of the correct member ('fork') when processing exit events.
In the cases where it has been used incorrectly, only the 'pid' and 'tid' are affected. The 'pid' value would be correct anyway because it is in the same position in 'comm' and 'fork' events, but the 'tid' would have been incorrectly assigned from 'ppid'. However, for exit events, the kernel puts the current task in the 'ppid' and 'ttid' which is the same as the exiting task. That is 'ppid' == 'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the data goes wrong only when tracing multi-threaded programs.
It is hard to find an example of how this would produce an error in practice. There are 3 occurences of the fix:
1. perf script is only affected if !sample_id_all which only happens on old kernels
2. intel_pt is only affected when decoding without timestamps and would probably still decode correctly - the exit event is only used to flush out data which anyway gets flushed at the end of the session
3. intel_bts also uses the exit event to flush data which would probably not cause errors as it would get flushed at the end of the session instead
--- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-script.c +2 -2
@@ -739,8 +739,8 @@ static int process_exit_event(struct perf_tool *tool,if (!evsel->attr.sample_id_all) { sample->cpu =0 ; sample->time =0 ; - sample->tid = event->comm.tid; - sample->pid = event->comm.pid; + sample->tid = event->fork.tid; + sample->pid = event->fork.pid; }print_sample_start (sample, thread, evsel);perf_event__fprintf (event, stdout);
tools/perf/util/intel-bts.c +1 -1
@@ -623,7 +623,7 @@ static int intel_bts_process_event(struct perf_session *session,if (err)return err;if (event->header.type ==PERF_RECORD_EXIT ) { - err =intel_bts_process_tid_exit (bts, event->comm.tid); + err =intel_bts_process_tid_exit (bts, event->fork.tid);if (err)return err; }
tools/perf/util/intel-pt.c +1 -1
@@ -1464,7 +1464,7 @@ static int intel_pt_process_event(struct perf_session *session,if (pt->timeless_decoding) {if (event->header.type ==PERF_RECORD_EXIT ) { err =intel_pt_process_timeless_queues (pt, - event->comm.tid, + event->fork.tid, sample->time); } }else if (timestamp) {
Signature · 1 line
1.9.1
Adrian Hunter
reviewerQuoted 26 lines · Adrian Hunter
In a couple of cases the 'comm' member of 'union event' has been used instead of the correct member ('fork') when processing exit events.
In the cases where it has been used incorrectly, only the 'pid' and 'tid' are affected. The 'pid' value would be correct anyway because it is in the same position in 'comm' and 'fork' events, but the 'tid' would have been incorrectly assigned from 'ppid'. However, for exit events, the kernel puts the current task in the 'ppid' and 'ttid' which is the same as the exiting task. That is 'ppid' == 'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the data goes wrong only when tracing multi-threaded programs.
It is hard to find an example of how this would produce an error in practice. There are 3 occurences of the fix:
1. perf script is only affected if !sample_id_all which only happens on old kernels
2.intel_ptis only affected when decoding without timestamps and would probably still decode correctly - the exit event is only used to flush out data which anyway gets flushed at the end of the session
3.intel_btsalso uses the exit event to flush data which would probably not cause errors as it would get flushed at the end of the session instead
Quoted 1 line
Signed-off-by Adrian Hunter <[email protected]>
I think it would be worth picking this one up for 4.3
Quoted 48 lines
--- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/builtin-script.c +2
-2@@ -739,8 +739,8 @@ static int process_exit_event(struct perf_tool *tool,if (!evsel->attr.sample_id_all) { sample->cpu =0 ; sample->time =0 ; - sample->tid = event->comm.tid; - sample->pid = event->comm.pid; + sample->tid = event->fork.tid; + sample->pid = event->fork.pid; }print_sample_start (sample, thread, evsel);perf_event__fprintf (event, stdout);tools/perf/util/intel-bts.c +1
-1@@ -623,7 +623,7 @@ static int intel_bts_process_event(struct perf_session *session,if (err)return err;if (event->header.type ==PERF_RECORD_EXIT ) { - err =intel_bts_process_tid_exit (bts, event->comm.tid); + err =intel_bts_process_tid_exit (bts, event->fork.tid);if (err)return err; }tools/perf/util/intel-pt.c +1
-1@@ -1464,7 +1464,7 @@ static int intel_pt_process_event(struct perf_session *session,if (pt->timeless_decoding) {if (event->header.type ==PERF_RECORD_EXIT ) { err =intel_pt_process_timeless_queues (pt, - event->comm.tid, + event->fork.tid, sample->time); } }else if (timestamp) {
Arnaldo Carvalho de Melo
maintainerEm Wed, Sep 02, 2015 at 04:00:08PM +0300, Adrian Hunter escreveu:
Quoted 27 lines · Adrian Hunter
Quoted 26 lines
In a couple of cases the 'comm' member of 'union event' has been used instead of the correct member ('fork') when processing exit events.
In the cases where it has been used incorrectly, only the 'pid' and 'tid' are affected. The 'pid' value would be correct anyway because it is in the same position in 'comm' and 'fork' events, but the 'tid' would have been incorrectly assigned from 'ppid'. However, for exit events, the kernel puts the current task in the 'ppid' and 'ttid' which is the same as the exiting task. That is 'ppid' == 'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the data goes wrong only when tracing multi-threaded programs.
It is hard to find an example of how this would produce an error in practice. There are 3 occurences of the fix:
1. perf script is only affected if !sample_id_all which only happens on old kernels
2.intel_ptis only affected when decoding without timestamps and would probably still decode correctly - the exit event is only used to flush out data which anyway gets flushed at the end of the session
3.intel_btsalso uses the exit event to flush data which would probably not cause errors as it would get flushed at the end of the session instead
Quoted 3 lines
Quoted 1 line
Signed-off-by Adrian Hunter <[email protected]>I think it would be worth picking this one up for 4.3
I guess I had this picked up, is there anything else from you that is outstanding?
- Arnaldo
Quoted 48 lines
Quoted 48 lines
--- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)tools/perf/builtin-script.c +2
-2@@ -739,8 +739,8 @@ static int process_exit_event(struct perf_tool *tool,if (!evsel->attr.sample_id_all) { sample->cpu =0 ; sample->time =0 ; - sample->tid = event->comm.tid; - sample->pid = event->comm.pid; + sample->tid = event->fork.tid; + sample->pid = event->fork.pid; }print_sample_start (sample, thread, evsel);perf_event__fprintf (event, stdout);tools/perf/util/intel-bts.c +1
-1@@ -623,7 +623,7 @@ static int intel_bts_process_event(struct perf_session *session,if (err)return err;if (event->header.type ==PERF_RECORD_EXIT ) { - err =intel_bts_process_tid_exit (bts, event->comm.tid); + err =intel_bts_process_tid_exit (bts, event->fork.tid);if (err)return err; }tools/perf/util/intel-pt.c +1
-1@@ -1464,7 +1464,7 @@ static int intel_pt_process_event(struct perf_session *session,if (pt->timeless_decoding) {if (event->header.type ==PERF_RECORD_EXIT ) { err =intel_pt_process_timeless_queues (pt, - event->comm.tid, + event->fork.tid, sample->time); } }else if (timestamp) {
Adrian Hunter
reviewerQuoted 28 lines · Arnaldo Carvalho de Melo
Em Wed, Sep 02, 2015 at 04:00:08PM +0300, Adrian Hunter escreveu:
Quoted 27 lines · Adrian Hunter
Quoted 26 lines
In a couple of cases the 'comm' member of 'union event' has been used instead of the correct member ('fork') when processing exit events.
In the cases where it has been used incorrectly, only the 'pid' and 'tid' are affected. The 'pid' value would be correct anyway because it is in the same position in 'comm' and 'fork' events, but the 'tid' would have been incorrectly assigned from 'ppid'. However, for exit events, the kernel puts the current task in the 'ppid' and 'ttid' which is the same as the exiting task. That is 'ppid' == 'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the data goes wrong only when tracing multi-threaded programs.
It is hard to find an example of how this would produce an error in practice. There are 3 occurences of the fix:
1. perf script is only affected if !sample_id_all which only happens on old kernels
2.intel_ptis only affected when decoding without timestamps and would probably still decode correctly - the exit event is only used to flush out data which anyway gets flushed at the end of the session
3.intel_btsalso uses the exit event to flush data which would probably not cause errors as it would get flushed at the end of the session instead
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Adrian Hunter <[email protected]>I think it would be worth picking this one up for 4.3
I guess I had this picked up, is there anything else from you that is outstanding?
Only "perf tools: Add support for PERF_RECORD_SWITCH to Intel PT" but that is a feature not a bug.
tip-bot for Adrian Hunter
merge botperf tools: Fix use of wrong event when processing exit events
Commit-ID: 53ff6bc37be449f546158a39c528d7814dfb15a1 Gitweb: http://git.kernel.org/tip/53ff6bc37be449f546158a39c528d7814dfb15a1 Author: Adrian Hunter <[email protected]> AuthorDate: Tue, 18 Aug 2015 12:07:05 +0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 2 Sep 2015 17:46:26 -0300
perf tools: Fix use of wrong event when processing exit events
In a couple of cases the 'comm' member of 'union event' has been used instead of the correct member ('fork') when processing exit events.
In the cases where it has been used incorrectly, only the 'pid' and 'tid' are affected. The 'pid' value would be correct anyway because it is in the same position in 'comm' and 'fork' events, but the 'tid' would have been incorrectly assigned from 'ppid'.
However, for exit events, the kernel puts the current task in the 'ppid' and 'ttid' which is the same as the exiting task. That is 'ppid' == 'pid' and if the task is not multi-threaded, 'pid' == 'tid' i.e. the data goes wrong only when tracing multi-threaded programs.
It is hard to find an example of how this would produce an error in practice. There are 3 occurences of the fix:
1. perf script is only affected if !sample_id_all which only happens on old kernels.
2. intel_pt is only affected when decoding without timestamps and would probably still decode correctly - the exit event is only used to flush out data which anyway gets flushed at the end of the session
3. intel_bts also uses the exit event to flush data which would probably not cause errors as it would get flushed at the end of the session instead
--- tools/perf/builtin-script.c | 4 ++-- tools/perf/util/intel-bts.c | 2 +- tools/perf/util/intel-pt.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/builtin-script.c +2 -2
@@ -768,8 +768,8 @@ static int process_exit_event(struct perf_tool *tool,if (!evsel->attr.sample_id_all) { sample->cpu =0 ; sample->time =0 ; - sample->tid = event->comm.tid; - sample->pid = event->comm.pid; + sample->tid = event->fork.tid; + sample->pid = event->fork.pid; }print_sample_start (sample, thread, evsel);perf_event__fprintf (event, stdout);
tools/perf/util/intel-bts.c +1 -1
@@ -623,7 +623,7 @@ static int intel_bts_process_event(struct perf_session *session,if (err)return err;if (event->header.type ==PERF_RECORD_EXIT ) { - err =intel_bts_process_tid_exit (bts, event->comm.tid); + err =intel_bts_process_tid_exit (bts, event->fork.tid);if (err)return err; }
tools/perf/util/intel-pt.c +1 -1
@@ -1494,7 +1494,7 @@ static int intel_pt_process_event(struct perf_session *session,if (pt->timeless_decoding) {if (event->header.type ==PERF_RECORD_EXIT ) { err =intel_pt_process_timeless_queues (pt, - event->comm.tid, + event->fork.tid, sample->time); } }else if (timestamp) {