Skip to content

Commit 720a3ae

Browse files
committed
perf session: Remove threads from tree on PERF_RECORD_EXIT
Move them to a session->dead_threads list just like we do with maps that are replaced, because we may have hist_entries pointing to them. This fixes a bug when inserting maps for a new thread that reused the TID, mixing maps for two different threads, causing an endless loop. The code for insering maps should be made more robust but for .35 this is the minimalistic patch. Reported-by: Ingo Molnar <mingo@elte.hu> Cc: David S. Miller <davem@davemloft.net> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 174787c commit 720a3ae

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎tools/perf/util/event.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,10 @@ int event__process_task(event_t *self, struct perf_session *session)
538538
dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
539539
self->fork.ppid, self->fork.ptid);
540540

541-
if (self->header.type == PERF_RECORD_EXIT)
541+
if (self->header.type == PERF_RECORD_EXIT) {
542+
perf_session__remove_thread(session, thread);
542543
return 0;
544+
}
543545

544546
if (thread == NULL || parent == NULL ||
545547
thread__fork(thread, parent) < 0) {

‎tools/perf/util/session.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
9090

9191
memcpy(self->filename, filename, len);
9292
self->threads = RB_ROOT;
93+
INIT_LIST_HEAD(&self->dead_threads);
9394
self->hists_tree = RB_ROOT;
9495
self->last_match = NULL;
9596
self->mmap_window = 32;
@@ -131,6 +132,16 @@ void perf_session__delete(struct perf_session *self)
131132
free(self);
132133
}
133134

135+
void perf_session__remove_thread(struct perf_session *self, struct thread *th)
136+
{
137+
rb_erase(&th->rb_node, &self->threads);
138+
/*
139+
* We may have references to this thread, for instance in some hist_entry
140+
* instances, so just move them to a separate list.
141+
*/
142+
list_add_tail(&th->node, &self->dead_threads);
143+
}
144+
134145
static bool symbol__match_parent_regex(struct symbol *sym)
135146
{
136147
if (sym->name && !regexec(&parent_regex, sym->name, 0, NULL, 0))

‎tools/perf/util/session.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct perf_session {
2626
unsigned long size;
2727
unsigned long mmap_window;
2828
struct rb_root threads;
29+
struct list_head dead_threads;
2930
struct thread *last_match;
3031
struct machine host_machine;
3132
struct rb_root machines;
@@ -99,6 +100,7 @@ int perf_session__create_kernel_maps(struct perf_session *self);
99100

100101
int do_read(int fd, void *buf, size_t size);
101102
void perf_session__update_sample_type(struct perf_session *self);
103+
void perf_session__remove_thread(struct perf_session *self, struct thread *th);
102104

103105
static inline
104106
struct machine *perf_session__find_host_machine(struct perf_session *self)

‎tools/perf/util/thread.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include "symbol.h"
77

88
struct thread {
9-
struct rb_node rb_node;
9+
union {
10+
struct rb_node rb_node;
11+
struct list_head node;
12+
};
1013
struct map_groups mg;
1114
pid_t pid;
1215
char shortname[3];

0 commit comments

Comments
 (0)