aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-09 10:24:25 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:35:31 -0500
commitb424eba27160dd19577896d4520b8eebabed919f (patch)
treef70a5cceecb05ad86b043f7b7cde6b5401af536f /tools
parent01c2d99bcf6fc7f6ce3fe3d0fb38b124e1f127fc (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/build-id.c4
-rw-r--r--tools/perf/util/map.c4
-rw-r--r--tools/perf/util/map.h9
-rw-r--r--tools/perf/util/session.c47
-rw-r--r--tools/perf/util/session.h3
-rw-r--r--tools/perf/util/thread.c6
6 files changed, 58 insertions, 15 deletions
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index a91cd99f26ea..f2fe6ec08945 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -48,8 +48,8 @@ static int perf_event__exit_del_thread(union perf_event *event,
48 event->fork.ppid, event->fork.ptid); 48 event->fork.ppid, event->fork.ptid);
49 49
50 if (thread) { 50 if (thread) {
51 rb_erase(&thread->rb_node, &session->threads); 51 rb_erase(&thread->rb_node, &session->host_machine.threads);
52 session->last_match = NULL; 52 session->host_machine.last_match = NULL;
53 thread__delete(thread); 53 thread__delete(thread);
54 } 54 }
55 55
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 78284b13e808..316aa0ab7122 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -562,6 +562,10 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid)
562 INIT_LIST_HEAD(&self->user_dsos); 562 INIT_LIST_HEAD(&self->user_dsos);
563 INIT_LIST_HEAD(&self->kernel_dsos); 563 INIT_LIST_HEAD(&self->kernel_dsos);
564 564
565 self->threads = RB_ROOT;
566 INIT_LIST_HEAD(&self->dead_threads);
567 self->last_match = NULL;
568
565 self->kmaps.machine = self; 569 self->kmaps.machine = self;
566 self->pid = pid; 570 self->pid = pid;
567 self->root_dir = strdup(root_dir); 571 self->root_dir = strdup(root_dir);
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 890d85545d0f..bde6835ee257 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -62,6 +62,9 @@ struct machine {
62 struct rb_node rb_node; 62 struct rb_node rb_node;
63 pid_t pid; 63 pid_t pid;
64 char *root_dir; 64 char *root_dir;
65 struct rb_root threads;
66 struct list_head dead_threads;
67 struct thread *last_match;
65 struct list_head user_dsos; 68 struct list_head user_dsos;
66 struct list_head kernel_dsos; 69 struct list_head kernel_dsos;
67 struct map_groups kmaps; 70 struct map_groups kmaps;
@@ -190,6 +193,12 @@ struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
190 struct map **mapp, 193 struct map **mapp,
191 symbol_filter_t filter); 194 symbol_filter_t filter);
192 195
196
197struct thread *machine__findnew_thread(struct machine *machine, pid_t pid);
198void machine__remove_thread(struct machine *machine, struct thread *th);
199
200size_t machine__fprintf(struct machine *machine, FILE *fp);
201
193static inline 202static inline
194struct symbol *machine__find_kernel_symbol(struct machine *self, 203struct symbol *machine__find_kernel_symbol(struct machine *self,
195 enum map_type type, u64 addr, 204 enum map_type type, u64 addr,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 85c1e6b76f0a..a76666f17767 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -139,9 +139,6 @@ struct perf_session *perf_session__new(const char *filename, int mode,
139 goto out; 139 goto out;
140 140
141 memcpy(self->filename, filename, len); 141 memcpy(self->filename, filename, len);
142 self->threads = RB_ROOT;
143 INIT_LIST_HEAD(&self->dead_threads);
144 self->last_match = NULL;
145 /* 142 /*
146 * On 64bit we can mmap the data file in one go. No need for tiny mmap 143 * On 64bit we can mmap the data file in one go. No need for tiny mmap
147 * slices. On 32bit we use 32MB. 144 * slices. On 32bit we use 32MB.
@@ -184,17 +181,22 @@ out_delete:
184 return NULL; 181 return NULL;
185} 182}
186 183
187static void perf_session__delete_dead_threads(struct perf_session *self) 184static void machine__delete_dead_threads(struct machine *machine)
188{ 185{
189 struct thread *n, *t; 186 struct thread *n, *t;
190 187
191 list_for_each_entry_safe(t, n, &self->dead_threads, node) { 188 list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
192 list_del(&t->node); 189 list_del(&t->node);
193 thread__delete(t); 190 thread__delete(t);
194 } 191 }
195} 192}
196 193
197static void perf_session__delete_threads(struct perf_session *self) 194static void perf_session__delete_dead_threads(struct perf_session *session)
195{
196 machine__delete_dead_threads(&session->host_machine);
197}
198
199static void machine__delete_threads(struct machine *self)
198{ 200{
199 struct rb_node *nd = rb_first(&self->threads); 201 struct rb_node *nd = rb_first(&self->threads);
200 202
@@ -207,6 +209,11 @@ static void perf_session__delete_threads(struct perf_session *self)
207 } 209 }
208} 210}
209 211
212static void perf_session__delete_threads(struct perf_session *session)
213{
214 machine__delete_threads(&session->host_machine);
215}
216
210void perf_session__delete(struct perf_session *self) 217void perf_session__delete(struct perf_session *self)
211{ 218{
212 perf_session__destroy_kernel_maps(self); 219 perf_session__destroy_kernel_maps(self);
@@ -217,7 +224,7 @@ void perf_session__delete(struct perf_session *self)
217 free(self); 224 free(self);
218} 225}
219 226
220void perf_session__remove_thread(struct perf_session *self, struct thread *th) 227void machine__remove_thread(struct machine *self, struct thread *th)
221{ 228{
222 self->last_match = NULL; 229 self->last_match = NULL;
223 rb_erase(&th->rb_node, &self->threads); 230 rb_erase(&th->rb_node, &self->threads);
@@ -884,6 +891,11 @@ void perf_event_header__bswap(struct perf_event_header *self)
884 self->size = bswap_16(self->size); 891 self->size = bswap_16(self->size);
885} 892}
886 893
894struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
895{
896 return machine__findnew_thread(&session->host_machine, pid);
897}
898
887static struct thread *perf_session__register_idle_thread(struct perf_session *self) 899static struct thread *perf_session__register_idle_thread(struct perf_session *self)
888{ 900{
889 struct thread *thread = perf_session__findnew(self, 0); 901 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)
1224 return ret; 1236 return ret;
1225} 1237}
1226 1238
1239size_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
1248void 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
1227struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, 1260struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
1228 unsigned int type) 1261 unsigned int type)
1229{ 1262{
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 6e393c98eb34..76d462d3bef7 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -30,9 +30,6 @@ struct perf_session {
30 struct perf_header header; 30 struct perf_header header;
31 unsigned long size; 31 unsigned long size;
32 unsigned long mmap_window; 32 unsigned long mmap_window;
33 struct rb_root threads;
34 struct list_head dead_threads;
35 struct thread *last_match;
36 struct machine host_machine; 33 struct machine host_machine;
37 struct rb_root machines; 34 struct rb_root machines;
38 struct perf_evlist *evlist; 35 struct perf_evlist *evlist;
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index d5d3b22250f3..fb4b7ea6752f 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -61,7 +61,7 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
61 map_groups__fprintf(&self->mg, verbose, fp); 61 map_groups__fprintf(&self->mg, verbose, fp);
62} 62}
63 63
64struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) 64struct thread *machine__findnew_thread(struct machine *self, pid_t pid)
65{ 65{
66 struct rb_node **p = &self->threads.rb_node; 66 struct rb_node **p = &self->threads.rb_node;
67 struct rb_node *parent = NULL; 67 struct rb_node *parent = NULL;
@@ -125,12 +125,12 @@ int thread__fork(struct thread *self, struct thread *parent)
125 return 0; 125 return 0;
126} 126}
127 127
128size_t perf_session__fprintf(struct perf_session *self, FILE *fp) 128size_t machine__fprintf(struct machine *machine, FILE *fp)
129{ 129{
130 size_t ret = 0; 130 size_t ret = 0;
131 struct rb_node *nd; 131 struct rb_node *nd;
132 132
133 for (nd = rb_first(&self->threads); nd; nd = rb_next(nd)) { 133 for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
134 struct thread *pos = rb_entry(nd, struct thread, rb_node); 134 struct thread *pos = rb_entry(nd, struct thread, rb_node);
135 135
136 ret += thread__fprintf(pos, fp); 136 ret += thread__fprintf(pos, fp);