Skip to content

Commit b424eba

Browse files
committed
perf session: Move threads to struct machine
The 'machine' abstraction was introduced with 'perf kvm' where we could have samples for the host and multiple guests, but at the time we ended up keeping the list of all machines threads all in session->host_machine. Move the threads rb_tree to struct machine to separate the namespaces. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic 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> Link: http://lkml.kernel.org/n/tip-mdg7sm6j3va09vtgj49gbsrp@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 01c2d99 commit b424eba

6 files changed

Lines changed: 58 additions & 15 deletions

File tree

‎tools/perf/util/build-id.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static int perf_event__exit_del_thread(union perf_event *event,
4848
event->fork.ppid, event->fork.ptid);
4949

5050
if (thread) {
51-
rb_erase(&thread->rb_node, &session->threads);
52-
session->last_match = NULL;
51+
rb_erase(&thread->rb_node, &session->host_machine.threads);
52+
session->host_machine.last_match = NULL;
5353
thread__delete(thread);
5454
}
5555

‎tools/perf/util/map.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid)
562562
INIT_LIST_HEAD(&self->user_dsos);
563563
INIT_LIST_HEAD(&self->kernel_dsos);
564564

565+
self->threads = RB_ROOT;
566+
INIT_LIST_HEAD(&self->dead_threads);
567+
self->last_match = NULL;
568+
565569
self->kmaps.machine = self;
566570
self->pid = pid;
567571
self->root_dir = strdup(root_dir);

‎tools/perf/util/map.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ struct machine {
6262
struct rb_node rb_node;
6363
pid_t pid;
6464
char *root_dir;
65+
struct rb_root threads;
66+
struct list_head dead_threads;
67+
struct thread *last_match;
6568
struct list_head user_dsos;
6669
struct list_head kernel_dsos;
6770
struct map_groups kmaps;
@@ -190,6 +193,12 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
190193
struct map **mapp,
191194
symbol_filter_t filter);
192195

196+
197+
struct thread *machine__findnew_thread(struct machine *machine, pid_t pid);
198+
void machine__remove_thread(struct machine *machine, struct thread *th);
199+
200+
size_t machine__fprintf(struct machine *machine, FILE *fp);
201+
193202
static inline
194203
struct symbol *machine__find_kernel_symbol(struct machine *self,
195204
enum map_type type, u64 addr,

‎tools/perf/util/session.c‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ struct perf_session *perf_session__new(const char *filename, int mode,
139139
goto out;
140140

141141
memcpy(self->filename, filename, len);
142-
self->threads = RB_ROOT;
143-
INIT_LIST_HEAD(&self->dead_threads);
144-
self->last_match = NULL;
145142
/*
146143
* On 64bit we can mmap the data file in one go. No need for tiny mmap
147144
* slices. On 32bit we use 32MB.
@@ -184,17 +181,22 @@ struct perf_session *perf_session__new(const char *filename, int mode,
184181
return NULL;
185182
}
186183

187-
static void perf_session__delete_dead_threads(struct perf_session *self)
184+
static void machine__delete_dead_threads(struct machine *machine)
188185
{
189186
struct thread *n, *t;
190187

191-
list_for_each_entry_safe(t, n, &self->dead_threads, node) {
188+
list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
192189
list_del(&t->node);
193190
thread__delete(t);
194191
}
195192
}
196193

197-
static void perf_session__delete_threads(struct perf_session *self)
194+
static void perf_session__delete_dead_threads(struct perf_session *session)
195+
{
196+
machine__delete_dead_threads(&session->host_machine);
197+
}
198+
199+
static void machine__delete_threads(struct machine *self)
198200
{
199201
struct rb_node *nd = rb_first(&self->threads);
200202

@@ -207,6 +209,11 @@ static void perf_session__delete_threads(struct perf_session *self)
207209
}
208210
}
209211

212+
static void perf_session__delete_threads(struct perf_session *session)
213+
{
214+
machine__delete_threads(&session->host_machine);
215+
}
216+
210217
void perf_session__delete(struct perf_session *self)
211218
{
212219
perf_session__destroy_kernel_maps(self);
@@ -217,7 +224,7 @@ void perf_session__delete(struct perf_session *self)
217224
free(self);
218225
}
219226

220-
void perf_session__remove_thread(struct perf_session *self, struct thread *th)
227+
void machine__remove_thread(struct machine *self, struct thread *th)
221228
{
222229
self->last_match = NULL;
223230
rb_erase(&th->rb_node, &self->threads);
@@ -884,6 +891,11 @@ void perf_event_header__bswap(struct perf_event_header *self)
884891
self->size = bswap_16(self->size);
885892
}
886893

894+
struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
895+
{
896+
return machine__findnew_thread(&session->host_machine, pid);
897+
}
898+
887899
static struct thread *perf_session__register_idle_thread(struct perf_session *self)
888900
{
889901
struct thread *thread = perf_session__findnew(self, 0);
@@ -1224,6 +1236,27 @@ size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
12241236
return ret;
12251237
}
12261238

1239+
size_t perf_session__fprintf(struct perf_session *session, FILE *fp)
1240+
{
1241+
/*
1242+
* FIXME: Here we have to actually print all the machines in this
1243+
* session, not just the host...
1244+
*/
1245+
return machine__fprintf(&session->host_machine, fp);
1246+
}
1247+
1248+
void perf_session__remove_thread(struct perf_session *session,
1249+
struct thread *th)
1250+
{
1251+
/*
1252+
* FIXME: This one makes no sense, we need to remove the thread from
1253+
* the machine it belongs to, perf_session can have many machines, so
1254+
* doing it always on ->host_machine is wrong. Fix when auditing all
1255+
* the 'perf kvm' code.
1256+
*/
1257+
machine__remove_thread(&session->host_machine, th);
1258+
}
1259+
12271260
struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
12281261
unsigned int type)
12291262
{

‎tools/perf/util/session.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ struct perf_session {
3030
struct perf_header header;
3131
unsigned long size;
3232
unsigned long mmap_window;
33-
struct rb_root threads;
34-
struct list_head dead_threads;
35-
struct thread *last_match;
3633
struct machine host_machine;
3734
struct rb_root machines;
3835
struct perf_evlist *evlist;

‎tools/perf/util/thread.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
6161
map_groups__fprintf(&self->mg, verbose, fp);
6262
}
6363

64-
struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
64+
struct thread *machine__findnew_thread(struct machine *self, pid_t pid)
6565
{
6666
struct rb_node **p = &self->threads.rb_node;
6767
struct rb_node *parent = NULL;
@@ -125,12 +125,12 @@ int thread__fork(struct thread *self, struct thread *parent)
125125
return 0;
126126
}
127127

128-
size_t perf_session__fprintf(struct perf_session *self, FILE *fp)
128+
size_t machine__fprintf(struct machine *machine, FILE *fp)
129129
{
130130
size_t ret = 0;
131131
struct rb_node *nd;
132132

133-
for (nd = rb_first(&self->threads); nd; nd = rb_next(nd)) {
133+
for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
134134
struct thread *pos = rb_entry(nd, struct thread, rb_node);
135135

136136
ret += thread__fprintf(pos, fp);

0 commit comments

Comments
 (0)