diff options
Diffstat (limited to 'tools/perf/util/thread.c')
| -rw-r--r-- | tools/perf/util/thread.c | 27 |
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 | ||
| 9 | static struct rb_root threads; | ||
| 10 | static struct thread *last_match; | ||
| 11 | |||
| 9 | static struct thread *thread__new(pid_t pid) | 12 | static 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 | ||
| 53 | struct thread * | 56 | struct thread *threads__findnew(pid_t pid) |
| 54 | threads__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 | ||
| 93 | struct thread * | 95 | struct thread *register_idle_thread(void) |
| 94 | register_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 | ||
| 200 | size_t threads__fprintf(FILE *fp, struct rb_root *threads) | 201 | size_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); |
