diff options
| -rw-r--r-- | tools/perf/builtin-annotate.c | 25 | ||||
| -rw-r--r-- | tools/perf/builtin-report.c | 26 | ||||
| -rw-r--r-- | tools/perf/builtin-sched.c | 30 | ||||
| -rw-r--r-- | tools/perf/builtin-trace.c | 13 | ||||
| -rw-r--r-- | tools/perf/util/thread.c | 27 | ||||
| -rw-r--r-- | tools/perf/util/thread.h | 8 | 
6 files changed, 45 insertions, 84 deletions
| diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 8c84320ecb06..3fe0de03004d 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
| @@ -37,10 +37,6 @@ static int print_line; | |||
| 37 | static unsigned long page_size; | 37 | static unsigned long page_size; | 
| 38 | static unsigned long mmap_window = 32; | 38 | static unsigned long mmap_window = 32; | 
| 39 | 39 | ||
| 40 | static struct rb_root threads; | ||
| 41 | static struct thread *last_match; | ||
| 42 | |||
| 43 | |||
| 44 | struct sym_ext { | 40 | struct sym_ext { | 
| 45 | struct rb_node node; | 41 | struct rb_node node; | 
| 46 | double percent; | 42 | double percent; | 
| @@ -96,12 +92,10 @@ static int | |||
| 96 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) | 92 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) | 
| 97 | { | 93 | { | 
| 98 | char level; | 94 | char level; | 
| 99 | struct thread *thread; | ||
| 100 | u64 ip = event->ip.ip; | 95 | u64 ip = event->ip.ip; | 
| 101 | struct map *map = NULL; | 96 | struct map *map = NULL; | 
| 102 | struct symbol *sym = NULL; | 97 | struct symbol *sym = NULL; | 
| 103 | 98 | struct thread *thread = threads__findnew(event->ip.pid); | |
| 104 | thread = threads__findnew(event->ip.pid, &threads, &last_match); | ||
| 105 | 99 | ||
| 106 | dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", | 100 | dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n", | 
| 107 | (void *)(offset + head), | 101 | (void *)(offset + head), | 
| @@ -166,10 +160,8 @@ got_map: | |||
| 166 | static int | 160 | static int | 
| 167 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | 161 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | 
| 168 | { | 162 | { | 
| 169 | struct thread *thread; | ||
| 170 | struct map *map = map__new(&event->mmap, NULL, 0); | 163 | struct map *map = map__new(&event->mmap, NULL, 0); | 
| 171 | 164 | struct thread *thread = threads__findnew(event->mmap.pid); | |
| 172 | thread = threads__findnew(event->mmap.pid, &threads, &last_match); | ||
| 173 | 165 | ||
| 174 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n", | 166 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n", | 
| 175 | (void *)(offset + head), | 167 | (void *)(offset + head), | 
| @@ -194,9 +186,8 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 194 | static int | 186 | static int | 
| 195 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 187 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 
| 196 | { | 188 | { | 
| 197 | struct thread *thread; | 189 | struct thread *thread = threads__findnew(event->comm.pid); | 
| 198 | 190 | ||
| 199 | thread = threads__findnew(event->comm.pid, &threads, &last_match); | ||
| 200 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 191 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 
| 201 | (void *)(offset + head), | 192 | (void *)(offset + head), | 
| 202 | (void *)(long)(event->header.size), | 193 | (void *)(long)(event->header.size), | 
| @@ -215,11 +206,9 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 215 | static int | 206 | static int | 
| 216 | process_fork_event(event_t *event, unsigned long offset, unsigned long head) | 207 | process_fork_event(event_t *event, unsigned long offset, unsigned long head) | 
| 217 | { | 208 | { | 
| 218 | struct thread *thread; | 209 | struct thread *thread = threads__findnew(event->fork.pid); | 
| 219 | struct thread *parent; | 210 | struct thread *parent = threads__findnew(event->fork.ppid); | 
| 220 | 211 | ||
| 221 | thread = threads__findnew(event->fork.pid, &threads, &last_match); | ||
| 222 | parent = threads__findnew(event->fork.ppid, &threads, &last_match); | ||
| 223 | dump_printf("%p [%p]: PERF_RECORD_FORK: %d:%d\n", | 212 | dump_printf("%p [%p]: PERF_RECORD_FORK: %d:%d\n", | 
| 224 | (void *)(offset + head), | 213 | (void *)(offset + head), | 
| 225 | (void *)(long)(event->header.size), | 214 | (void *)(long)(event->header.size), | 
| @@ -558,7 +547,7 @@ static int __cmd_annotate(void) | |||
| 558 | uint32_t size; | 547 | uint32_t size; | 
| 559 | char *buf; | 548 | char *buf; | 
| 560 | 549 | ||
| 561 | register_idle_thread(&threads, &last_match); | 550 | register_idle_thread(); | 
| 562 | 551 | ||
| 563 | input = open(input_name, O_RDONLY); | 552 | input = open(input_name, O_RDONLY); | 
| 564 | if (input < 0) { | 553 | if (input < 0) { | 
| @@ -659,7 +648,7 @@ more: | |||
| 659 | return 0; | 648 | return 0; | 
| 660 | 649 | ||
| 661 | if (verbose > 3) | 650 | if (verbose > 3) | 
| 662 | threads__fprintf(stdout, &threads); | 651 | threads__fprintf(stdout); | 
| 663 | 652 | ||
| 664 | if (verbose > 2) | 653 | if (verbose > 2) | 
| 665 | dsos__fprintf(stdout); | 654 | dsos__fprintf(stdout); | 
| diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index f57a23b19f3c..015c79745966 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
| @@ -55,9 +55,6 @@ static char callchain_default_opt[] = "fractal,0.5"; | |||
| 55 | static char *cwd; | 55 | static char *cwd; | 
| 56 | static int cwdlen; | 56 | static int cwdlen; | 
| 57 | 57 | ||
| 58 | static struct rb_root threads; | ||
| 59 | static struct thread *last_match; | ||
| 60 | |||
| 61 | static struct perf_header *header; | 58 | static struct perf_header *header; | 
| 62 | 59 | ||
| 63 | static u64 sample_type; | 60 | static u64 sample_type; | 
| @@ -593,15 +590,13 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 593 | { | 590 | { | 
| 594 | char level; | 591 | char level; | 
| 595 | struct symbol *sym = NULL; | 592 | struct symbol *sym = NULL; | 
| 596 | struct thread *thread; | ||
| 597 | u64 ip = event->ip.ip; | 593 | u64 ip = event->ip.ip; | 
| 598 | u64 period = 1; | 594 | u64 period = 1; | 
| 599 | struct map *map = NULL; | 595 | struct map *map = NULL; | 
| 600 | void *more_data = event->ip.__more_data; | 596 | void *more_data = event->ip.__more_data; | 
| 601 | struct ip_callchain *chain = NULL; | 597 | struct ip_callchain *chain = NULL; | 
| 602 | int cpumode; | 598 | int cpumode; | 
| 603 | 599 | struct thread *thread = threads__findnew(event->ip.pid); | |
| 604 | thread = threads__findnew(event->ip.pid, &threads, &last_match); | ||
| 605 | 600 | ||
| 606 | if (sample_type & PERF_SAMPLE_PERIOD) { | 601 | if (sample_type & PERF_SAMPLE_PERIOD) { | 
| 607 | period = *(u64 *)more_data; | 602 | period = *(u64 *)more_data; | 
| @@ -685,10 +680,8 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 685 | static int | 680 | static int | 
| 686 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | 681 | process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | 
| 687 | { | 682 | { | 
| 688 | struct thread *thread; | ||
| 689 | struct map *map = map__new(&event->mmap, cwd, cwdlen); | 683 | struct map *map = map__new(&event->mmap, cwd, cwdlen); | 
| 690 | 684 | struct thread *thread = threads__findnew(event->mmap.pid); | |
| 691 | thread = threads__findnew(event->mmap.pid, &threads, &last_match); | ||
| 692 | 685 | ||
| 693 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", | 686 | dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n", | 
| 694 | (void *)(offset + head), | 687 | (void *)(offset + head), | 
| @@ -714,9 +707,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 714 | static int | 707 | static int | 
| 715 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 708 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 
| 716 | { | 709 | { | 
| 717 | struct thread *thread; | 710 | struct thread *thread = threads__findnew(event->comm.pid); | 
| 718 | |||
| 719 | thread = threads__findnew(event->comm.pid, &threads, &last_match); | ||
| 720 | 711 | ||
| 721 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 712 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 
| 722 | (void *)(offset + head), | 713 | (void *)(offset + head), | 
| @@ -736,11 +727,8 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 736 | static int | 727 | static int | 
| 737 | process_task_event(event_t *event, unsigned long offset, unsigned long head) | 728 | process_task_event(event_t *event, unsigned long offset, unsigned long head) | 
| 738 | { | 729 | { | 
| 739 | struct thread *thread; | 730 | struct thread *thread = threads__findnew(event->fork.pid); | 
| 740 | struct thread *parent; | 731 | struct thread *parent = threads__findnew(event->fork.ppid); | 
| 741 | |||
| 742 | thread = threads__findnew(event->fork.pid, &threads, &last_match); | ||
| 743 | parent = threads__findnew(event->fork.ppid, &threads, &last_match); | ||
| 744 | 732 | ||
| 745 | dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", | 733 | dump_printf("%p [%p]: PERF_RECORD_%s: (%d:%d):(%d:%d)\n", | 
| 746 | (void *)(offset + head), | 734 | (void *)(offset + head), | 
| @@ -857,7 +845,7 @@ static int __cmd_report(void) | |||
| 857 | struct thread *idle; | 845 | struct thread *idle; | 
| 858 | int ret; | 846 | int ret; | 
| 859 | 847 | ||
| 860 | idle = register_idle_thread(&threads, &last_match); | 848 | idle = register_idle_thread(); | 
| 861 | thread__comm_adjust(idle); | 849 | thread__comm_adjust(idle); | 
| 862 | 850 | ||
| 863 | if (show_threads) | 851 | if (show_threads) | 
| @@ -881,7 +869,7 @@ static int __cmd_report(void) | |||
| 881 | return 0; | 869 | return 0; | 
| 882 | 870 | ||
| 883 | if (verbose > 3) | 871 | if (verbose > 3) | 
| 884 | threads__fprintf(stdout, &threads); | 872 | threads__fprintf(stdout); | 
| 885 | 873 | ||
| 886 | if (verbose > 2) | 874 | if (verbose > 2) | 
| 887 | dsos__fprintf(stdout); | 875 | dsos__fprintf(stdout); | 
| diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 387a44234368..73bdad029730 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
| @@ -24,9 +24,6 @@ static char const *input_name = "perf.data"; | |||
| 24 | 24 | ||
| 25 | static unsigned long total_comm = 0; | 25 | static unsigned long total_comm = 0; | 
| 26 | 26 | ||
| 27 | static struct rb_root threads; | ||
| 28 | static struct thread *last_match; | ||
| 29 | |||
| 30 | static struct perf_header *header; | 27 | static struct perf_header *header; | 
| 31 | static u64 sample_type; | 28 | static u64 sample_type; | 
| 32 | 29 | ||
| @@ -641,9 +638,7 @@ static void test_calibrations(void) | |||
| 641 | static int | 638 | static int | 
| 642 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 639 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 
| 643 | { | 640 | { | 
| 644 | struct thread *thread; | 641 | struct thread *thread = threads__findnew(event->comm.tid); | 
| 645 | |||
| 646 | thread = threads__findnew(event->comm.tid, &threads, &last_match); | ||
| 647 | 642 | ||
| 648 | dump_printf("%p [%p]: perf_event_comm: %s:%d\n", | 643 | dump_printf("%p [%p]: perf_event_comm: %s:%d\n", | 
| 649 | (void *)(offset + head), | 644 | (void *)(offset + head), | 
| @@ -1086,8 +1081,8 @@ latency_switch_event(struct trace_switch_event *switch_event, | |||
| 1086 | die("hm, delta: %Ld < 0 ?\n", delta); | 1081 | die("hm, delta: %Ld < 0 ?\n", delta); | 
| 1087 | 1082 | ||
| 1088 | 1083 | ||
| 1089 | sched_out = threads__findnew(switch_event->prev_pid, &threads, &last_match); | 1084 | sched_out = threads__findnew(switch_event->prev_pid); | 
| 1090 | sched_in = threads__findnew(switch_event->next_pid, &threads, &last_match); | 1085 | sched_in = threads__findnew(switch_event->next_pid); | 
| 1091 | 1086 | ||
| 1092 | out_events = thread_atoms_search(&atom_root, sched_out, &cmp_pid); | 1087 | out_events = thread_atoms_search(&atom_root, sched_out, &cmp_pid); | 
| 1093 | if (!out_events) { | 1088 | if (!out_events) { | 
| @@ -1120,13 +1115,10 @@ latency_runtime_event(struct trace_runtime_event *runtime_event, | |||
| 1120 | u64 timestamp, | 1115 | u64 timestamp, | 
| 1121 | struct thread *this_thread __used) | 1116 | struct thread *this_thread __used) | 
| 1122 | { | 1117 | { | 
| 1123 | struct work_atoms *atoms; | 1118 | struct thread *thread = threads__findnew(runtime_event->pid); | 
| 1124 | struct thread *thread; | 1119 | struct work_atoms *atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); | 
| 1125 | 1120 | ||
| 1126 | BUG_ON(cpu >= MAX_CPUS || cpu < 0); | 1121 | BUG_ON(cpu >= MAX_CPUS || cpu < 0); | 
| 1127 | |||
| 1128 | thread = threads__findnew(runtime_event->pid, &threads, &last_match); | ||
| 1129 | atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); | ||
| 1130 | if (!atoms) { | 1122 | if (!atoms) { | 
| 1131 | thread_atoms_insert(thread); | 1123 | thread_atoms_insert(thread); | 
| 1132 | atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); | 1124 | atoms = thread_atoms_search(&atom_root, thread, &cmp_pid); | 
| @@ -1153,7 +1145,7 @@ latency_wakeup_event(struct trace_wakeup_event *wakeup_event, | |||
| 1153 | if (!wakeup_event->success) | 1145 | if (!wakeup_event->success) | 
| 1154 | return; | 1146 | return; | 
| 1155 | 1147 | ||
| 1156 | wakee = threads__findnew(wakeup_event->pid, &threads, &last_match); | 1148 | wakee = threads__findnew(wakeup_event->pid); | 
| 1157 | atoms = thread_atoms_search(&atom_root, wakee, &cmp_pid); | 1149 | atoms = thread_atoms_search(&atom_root, wakee, &cmp_pid); | 
| 1158 | if (!atoms) { | 1150 | if (!atoms) { | 
| 1159 | thread_atoms_insert(wakee); | 1151 | thread_atoms_insert(wakee); | 
| @@ -1202,7 +1194,7 @@ latency_migrate_task_event(struct trace_migrate_task_event *migrate_task_event, | |||
| 1202 | if (profile_cpu == -1) | 1194 | if (profile_cpu == -1) | 
| 1203 | return; | 1195 | return; | 
| 1204 | 1196 | ||
| 1205 | migrant = threads__findnew(migrate_task_event->pid, &threads, &last_match); | 1197 | migrant = threads__findnew(migrate_task_event->pid); | 
| 1206 | atoms = thread_atoms_search(&atom_root, migrant, &cmp_pid); | 1198 | atoms = thread_atoms_search(&atom_root, migrant, &cmp_pid); | 
| 1207 | if (!atoms) { | 1199 | if (!atoms) { | 
| 1208 | thread_atoms_insert(migrant); | 1200 | thread_atoms_insert(migrant); | 
| @@ -1458,8 +1450,8 @@ map_switch_event(struct trace_switch_event *switch_event, | |||
| 1458 | die("hm, delta: %Ld < 0 ?\n", delta); | 1450 | die("hm, delta: %Ld < 0 ?\n", delta); | 
| 1459 | 1451 | ||
| 1460 | 1452 | ||
| 1461 | sched_out = threads__findnew(switch_event->prev_pid, &threads, &last_match); | 1453 | sched_out = threads__findnew(switch_event->prev_pid); | 
| 1462 | sched_in = threads__findnew(switch_event->next_pid, &threads, &last_match); | 1454 | sched_in = threads__findnew(switch_event->next_pid); | 
| 1463 | 1455 | ||
| 1464 | curr_thread[this_cpu] = sched_in; | 1456 | curr_thread[this_cpu] = sched_in; | 
| 1465 | 1457 | ||
| @@ -1649,7 +1641,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 1649 | if (!(sample_type & PERF_SAMPLE_RAW)) | 1641 | if (!(sample_type & PERF_SAMPLE_RAW)) | 
| 1650 | return 0; | 1642 | return 0; | 
| 1651 | 1643 | ||
| 1652 | thread = threads__findnew(event->ip.pid, &threads, &last_match); | 1644 | thread = threads__findnew(event->ip.pid); | 
| 1653 | 1645 | ||
| 1654 | if (sample_type & PERF_SAMPLE_TIME) { | 1646 | if (sample_type & PERF_SAMPLE_TIME) { | 
| 1655 | timestamp = *(u64 *)more_data; | 1647 | timestamp = *(u64 *)more_data; | 
| @@ -1725,7 +1717,7 @@ static struct perf_file_handler file_handler = { | |||
| 1725 | 1717 | ||
| 1726 | static int read_events(void) | 1718 | static int read_events(void) | 
| 1727 | { | 1719 | { | 
| 1728 | register_idle_thread(&threads, &last_match); | 1720 | register_idle_thread(); | 
| 1729 | register_perf_file_handler(&file_handler); | 1721 | register_perf_file_handler(&file_handler); | 
| 1730 | 1722 | ||
| 1731 | return mmap_dispatch_perf_file(&header, input_name, 0, 0, &cwdlen, &cwd); | 1723 | return mmap_dispatch_perf_file(&header, input_name, 0, 0, &cwdlen, &cwd); | 
| diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index fb3f3c220211..ccf867dbab5c 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
| @@ -19,9 +19,6 @@ static char const *input_name = "perf.data"; | |||
| 19 | static unsigned long total = 0; | 19 | static unsigned long total = 0; | 
| 20 | static unsigned long total_comm = 0; | 20 | static unsigned long total_comm = 0; | 
| 21 | 21 | ||
| 22 | static struct rb_root threads; | ||
| 23 | static struct thread *last_match; | ||
| 24 | |||
| 25 | static struct perf_header *header; | 22 | static struct perf_header *header; | 
| 26 | static u64 sample_type; | 23 | static u64 sample_type; | 
| 27 | 24 | ||
| @@ -32,9 +29,7 @@ static int cwdlen; | |||
| 32 | static int | 29 | static int | 
| 33 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 30 | process_comm_event(event_t *event, unsigned long offset, unsigned long head) | 
| 34 | { | 31 | { | 
| 35 | struct thread *thread; | 32 | struct thread *thread = threads__findnew(event->comm.pid); | 
| 36 | |||
| 37 | thread = threads__findnew(event->comm.pid, &threads, &last_match); | ||
| 38 | 33 | ||
| 39 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 34 | dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n", | 
| 40 | (void *)(offset + head), | 35 | (void *)(offset + head), | 
| @@ -54,14 +49,12 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head) | |||
| 54 | static int | 49 | static int | 
| 55 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) | 50 | process_sample_event(event_t *event, unsigned long offset, unsigned long head) | 
| 56 | { | 51 | { | 
| 57 | struct thread *thread; | ||
| 58 | u64 ip = event->ip.ip; | 52 | u64 ip = event->ip.ip; | 
| 59 | u64 timestamp = -1; | 53 | u64 timestamp = -1; | 
| 60 | u32 cpu = -1; | 54 | u32 cpu = -1; | 
| 61 | u64 period = 1; | 55 | u64 period = 1; | 
| 62 | void *more_data = event->ip.__more_data; | 56 | void *more_data = event->ip.__more_data; | 
| 63 | 57 | struct thread *thread = threads__findnew(event->ip.pid); | |
| 64 | thread = threads__findnew(event->ip.pid, &threads, &last_match); | ||
| 65 | 58 | ||
| 66 | if (sample_type & PERF_SAMPLE_TIME) { | 59 | if (sample_type & PERF_SAMPLE_TIME) { | 
| 67 | timestamp = *(u64 *)more_data; | 60 | timestamp = *(u64 *)more_data; | 
| @@ -135,7 +128,7 @@ static struct perf_file_handler file_handler = { | |||
| 135 | 128 | ||
| 136 | static int __cmd_trace(void) | 129 | static int __cmd_trace(void) | 
| 137 | { | 130 | { | 
| 138 | register_idle_thread(&threads, &last_match); | 131 | register_idle_thread(); | 
| 139 | register_perf_file_handler(&file_handler); | 132 | register_perf_file_handler(&file_handler); | 
| 140 | 133 | ||
| 141 | return mmap_dispatch_perf_file(&header, input_name, 0, 0, &cwdlen, &cwd); | 134 | return mmap_dispatch_perf_file(&header, input_name, 0, 0, &cwdlen, &cwd); | 
| 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); | 
| diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 845d9b62f96f..1abef3b7455d 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
| @@ -15,13 +15,11 @@ struct thread { | |||
| 15 | }; | 15 | }; | 
| 16 | 16 | ||
| 17 | int thread__set_comm(struct thread *self, const char *comm); | 17 | int thread__set_comm(struct thread *self, const char *comm); | 
| 18 | struct thread * | 18 | struct thread *threads__findnew(pid_t pid); | 
| 19 | threads__findnew(pid_t pid, struct rb_root *threads, struct thread **last_match); | 19 | struct thread *register_idle_thread(void); | 
| 20 | struct thread * | ||
| 21 | register_idle_thread(struct rb_root *threads, struct thread **last_match); | ||
| 22 | void thread__insert_map(struct thread *self, struct map *map); | 20 | void thread__insert_map(struct thread *self, struct map *map); | 
| 23 | int thread__fork(struct thread *self, struct thread *parent); | 21 | int thread__fork(struct thread *self, struct thread *parent); | 
| 24 | size_t threads__fprintf(FILE *fp, struct rb_root *threads); | 22 | size_t threads__fprintf(FILE *fp); | 
| 25 | 23 | ||
| 26 | void maps__insert(struct rb_root *maps, struct map *map); | 24 | void maps__insert(struct rb_root *maps, struct map *map); | 
| 27 | struct map *maps__find(struct rb_root *maps, u64 ip); | 25 | struct map *maps__find(struct rb_root *maps, u64 ip); | 
