aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/thread.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-10-13 10:16:29 -0400
committerIngo Molnar <mingo@elte.hu>2009-10-13 11:12:18 -0400
commitd5b889f2ecec7849e851ddd31c34bdfb3482b5de (patch)
tree001c95641ddf734a1e5e1fdee7e821f042c08f0b /tools/perf/util/thread.c
parentf4f0b418188cc7995375acbb54e87c80f21861bd (diff)
perf tools: Move threads & last_match to threads.c
This was just being copy'n'pasted all over. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <20091013141629.GD21809@ghostprotocols.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/thread.c')
-rw-r--r--tools/perf/util/thread.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 3b56aebb1f4b..f53fad7c0a8d 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -6,6 +6,9 @@
6#include "util.h" 6#include "util.h"
7#include "debug.h" 7#include "debug.h"
8 8
9static struct rb_root threads;
10static struct thread *last_match;
11
9static struct thread *thread__new(pid_t pid) 12static struct thread *thread__new(pid_t pid)
10{ 13{
11 struct thread *self = calloc(1, sizeof(*self)); 14 struct thread *self = calloc(1, sizeof(*self));
@@ -50,10 +53,9 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
50 return ret; 53 return ret;
51} 54}
52 55
53struct thread * 56struct thread *threads__findnew(pid_t pid)
54threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match)
55{ 57{
56 struct rb_node **p = &threads->rb_node; 58 struct rb_node **p = &threads.rb_node;
57 struct rb_node *parent = NULL; 59 struct rb_node *parent = NULL;
58 struct thread *th; 60 struct thread *th;
59 61
@@ -62,15 +64,15 @@ threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match)
62 * so most of the time we dont have to look up 64 * so most of the time we dont have to look up
63 * the full rbtree: 65 * the full rbtree:
64 */ 66 */
65 if (*last_match && (*last_match)->pid == pid) 67 if (last_match && last_match->pid == pid)
66 return *last_match; 68 return last_match;
67 69
68 while (*p != NULL) { 70 while (*p != NULL) {
69 parent = *p; 71 parent = *p;
70 th = rb_entry(parent, struct thread, rb_node); 72 th = rb_entry(parent, struct thread, rb_node);
71 73
72 if (th->pid == pid) { 74 if (th->pid == pid) {
73 *last_match = th; 75 last_match = th;
74 return th; 76 return th;
75 } 77 }
76 78
@@ -83,17 +85,16 @@ threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match)
83 th = thread__new(pid); 85 th = thread__new(pid);
84 if (th != NULL) { 86 if (th != NULL) {
85 rb_link_node(&th->rb_node, parent, p); 87 rb_link_node(&th->rb_node, parent, p);
86 rb_insert_color(&th->rb_node, threads); 88 rb_insert_color(&th->rb_node, &threads);
87 *last_match = th; 89 last_match = th;
88 } 90 }
89 91
90 return th; 92 return th;
91} 93}
92 94
93struct thread * 95struct thread *register_idle_thread(void)
94register_idle_thread(struct rb_root *threads, struct thread **last_match)
95{ 96{
96 struct thread *thread = threads__findnew(0, threads, last_match); 97 struct thread *thread = threads__findnew(0);
97 98
98 if (!thread || thread__set_comm(thread, "swapper")) { 99 if (!thread || thread__set_comm(thread, "swapper")) {
99 fprintf(stderr, "problem inserting idle task.\n"); 100 fprintf(stderr, "problem inserting idle task.\n");
@@ -197,12 +198,12 @@ int thread__fork(struct thread *self, struct thread *parent)
197 return 0; 198 return 0;
198} 199}
199 200
200size_t threads__fprintf(FILE *fp, struct rb_root *threads) 201size_t threads__fprintf(FILE *fp)
201{ 202{
202 size_t ret = 0; 203 size_t ret = 0;
203 struct rb_node *nd; 204 struct rb_node *nd;
204 205
205 for (nd = rb_first(threads); nd; nd = rb_next(nd)) { 206 for (nd = rb_first(&threads); nd; nd = rb_next(nd)) {
206 struct thread *pos = rb_entry(nd, struct thread, rb_node); 207 struct thread *pos = rb_entry(nd, struct thread, rb_node);
207 208
208 ret += thread__fprintf(pos, fp); 209 ret += thread__fprintf(pos, fp);