diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-06-06 03:58:57 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-06-06 05:37:22 -0400 |
commit | a21ca2cac582886a3e95c8bb84ff7c52d4d15e54 (patch) | |
tree | d110005d81e46b1afb3204fbaacc132d0ec946ee /Documentation/perf_counter/builtin-top.c | |
parent | 2f335a02b3c816e77e7df1d15b12e3bbb8f4c8f0 (diff) |
perf_counter: Separate out attr->type from attr->config
Counter type is a frequently used value and we do a lot of
bit juggling by encoding and decoding it from attr->config.
Clean this up by creating a separate attr->type field.
Also clean up the various similarly complex user-space bits
all around counter attribute management.
The net improvement is significant, and it will be easier
to add a new major type (which is what triggered this cleanup).
(This changes the ABI, all tools are adapted.)
(PowerPC build-tested.)
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/builtin-top.c')
-rw-r--r-- | Documentation/perf_counter/builtin-top.c | 67 |
1 files changed, 23 insertions, 44 deletions
diff --git a/Documentation/perf_counter/builtin-top.c b/Documentation/perf_counter/builtin-top.c index b2f480b5a134..98a6d53e17b3 100644 --- a/Documentation/perf_counter/builtin-top.c +++ b/Documentation/perf_counter/builtin-top.c | |||
@@ -48,22 +48,11 @@ | |||
48 | #include <linux/unistd.h> | 48 | #include <linux/unistd.h> |
49 | #include <linux/types.h> | 49 | #include <linux/types.h> |
50 | 50 | ||
51 | static int system_wide = 0; | 51 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; |
52 | 52 | ||
53 | static __u64 default_event_id[MAX_COUNTERS] = { | 53 | static int system_wide = 0; |
54 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK), | ||
55 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CONTEXT_SWITCHES), | ||
56 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), | ||
57 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_PAGE_FAULTS), | ||
58 | 54 | ||
59 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CPU_CYCLES), | 55 | static int default_interval = 100000; |
60 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_INSTRUCTIONS), | ||
61 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_REFERENCES), | ||
62 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_MISSES), | ||
63 | }; | ||
64 | static int default_interval = 100000; | ||
65 | static int event_count[MAX_COUNTERS]; | ||
66 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | ||
67 | 56 | ||
68 | static __u64 count_filter = 5; | 57 | static __u64 count_filter = 5; |
69 | static int print_entries = 15; | 58 | static int print_entries = 15; |
@@ -85,15 +74,6 @@ static int delay_secs = 2; | |||
85 | static int zero; | 74 | static int zero; |
86 | static int dump_symtab; | 75 | static int dump_symtab; |
87 | 76 | ||
88 | static const unsigned int default_count[] = { | ||
89 | 1000000, | ||
90 | 1000000, | ||
91 | 10000, | ||
92 | 10000, | ||
93 | 1000000, | ||
94 | 10000, | ||
95 | }; | ||
96 | |||
97 | /* | 77 | /* |
98 | * Symbols | 78 | * Symbols |
99 | */ | 79 | */ |
@@ -112,7 +92,7 @@ struct sym_entry { | |||
112 | 92 | ||
113 | struct sym_entry *sym_filter_entry; | 93 | struct sym_entry *sym_filter_entry; |
114 | 94 | ||
115 | struct dso *kernel_dso; | 95 | struct dso *kernel_dso; |
116 | 96 | ||
117 | /* | 97 | /* |
118 | * Symbols will be added here in record_ip and will get out | 98 | * Symbols will be added here in record_ip and will get out |
@@ -213,7 +193,7 @@ static void print_sym_table(void) | |||
213 | 100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec))); | 193 | 100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec))); |
214 | 194 | ||
215 | if (nr_counters == 1) { | 195 | if (nr_counters == 1) { |
216 | printf("%d", event_count[0]); | 196 | printf("%Ld", attrs[0].sample_period); |
217 | if (freq) | 197 | if (freq) |
218 | printf("Hz "); | 198 | printf("Hz "); |
219 | else | 199 | else |
@@ -421,10 +401,10 @@ static void process_event(uint64_t ip, int counter) | |||
421 | } | 401 | } |
422 | 402 | ||
423 | struct mmap_data { | 403 | struct mmap_data { |
424 | int counter; | 404 | int counter; |
425 | void *base; | 405 | void *base; |
426 | unsigned int mask; | 406 | unsigned int mask; |
427 | unsigned int prev; | 407 | unsigned int prev; |
428 | }; | 408 | }; |
429 | 409 | ||
430 | static unsigned int mmap_read_head(struct mmap_data *md) | 410 | static unsigned int mmap_read_head(struct mmap_data *md) |
@@ -539,7 +519,7 @@ static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | |||
539 | 519 | ||
540 | static int __cmd_top(void) | 520 | static int __cmd_top(void) |
541 | { | 521 | { |
542 | struct perf_counter_attr attr; | 522 | struct perf_counter_attr *attr; |
543 | pthread_t thread; | 523 | pthread_t thread; |
544 | int i, counter, group_fd, nr_poll = 0; | 524 | int i, counter, group_fd, nr_poll = 0; |
545 | unsigned int cpu; | 525 | unsigned int cpu; |
@@ -553,13 +533,12 @@ static int __cmd_top(void) | |||
553 | if (target_pid == -1 && profile_cpu == -1) | 533 | if (target_pid == -1 && profile_cpu == -1) |
554 | cpu = i; | 534 | cpu = i; |
555 | 535 | ||
556 | memset(&attr, 0, sizeof(attr)); | 536 | attr = attrs + counter; |
557 | attr.config = event_id[counter]; | ||
558 | attr.sample_period = event_count[counter]; | ||
559 | attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; | ||
560 | attr.freq = freq; | ||
561 | 537 | ||
562 | fd[i][counter] = sys_perf_counter_open(&attr, target_pid, cpu, group_fd, 0); | 538 | attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID; |
539 | attr->freq = freq; | ||
540 | |||
541 | fd[i][counter] = sys_perf_counter_open(attr, target_pid, cpu, group_fd, 0); | ||
563 | if (fd[i][counter] < 0) { | 542 | if (fd[i][counter] < 0) { |
564 | int err = errno; | 543 | int err = errno; |
565 | 544 | ||
@@ -670,7 +649,6 @@ int cmd_top(int argc, const char **argv, const char *prefix) | |||
670 | page_size = sysconf(_SC_PAGE_SIZE); | 649 | page_size = sysconf(_SC_PAGE_SIZE); |
671 | 650 | ||
672 | create_events_help(events_help_msg); | 651 | create_events_help(events_help_msg); |
673 | memcpy(event_id, default_event_id, sizeof(default_event_id)); | ||
674 | 652 | ||
675 | argc = parse_options(argc, argv, options, top_usage, 0); | 653 | argc = parse_options(argc, argv, options, top_usage, 0); |
676 | if (argc) | 654 | if (argc) |
@@ -688,19 +666,22 @@ int cmd_top(int argc, const char **argv, const char *prefix) | |||
688 | profile_cpu = -1; | 666 | profile_cpu = -1; |
689 | } | 667 | } |
690 | 668 | ||
691 | if (!nr_counters) { | 669 | if (!nr_counters) |
692 | nr_counters = 1; | 670 | nr_counters = 1; |
693 | event_id[0] = 0; | ||
694 | } | ||
695 | 671 | ||
696 | if (delay_secs < 1) | 672 | if (delay_secs < 1) |
697 | delay_secs = 1; | 673 | delay_secs = 1; |
698 | 674 | ||
675 | parse_symbols(); | ||
676 | |||
677 | /* | ||
678 | * Fill in the ones not specifically initialized via -c: | ||
679 | */ | ||
699 | for (counter = 0; counter < nr_counters; counter++) { | 680 | for (counter = 0; counter < nr_counters; counter++) { |
700 | if (event_count[counter]) | 681 | if (attrs[counter].sample_period) |
701 | continue; | 682 | continue; |
702 | 683 | ||
703 | event_count[counter] = default_interval; | 684 | attrs[counter].sample_period = default_interval; |
704 | } | 685 | } |
705 | 686 | ||
706 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); | 687 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
@@ -710,7 +691,5 @@ int cmd_top(int argc, const char **argv, const char *prefix) | |||
710 | if (target_pid != -1 || profile_cpu != -1) | 691 | if (target_pid != -1 || profile_cpu != -1) |
711 | nr_cpus = 1; | 692 | nr_cpus = 1; |
712 | 693 | ||
713 | parse_symbols(); | ||
714 | |||
715 | return __cmd_top(); | 694 | return __cmd_top(); |
716 | } | 695 | } |