aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWu Fengguang <fengguang.wu@intel.com>2009-03-19 22:08:02 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-06 03:30:20 -0400
commitcea92ce5b07078cd62c4712d51390b09a43dba2e (patch)
treee14c059faa150f0e01d7c9082041ddbc10efb94b
parente0143bad9dbf2a8fad4c5430562bceba196b66ea (diff)
perf_counter tools: Merge common code into perfcounters.h
kerneltop's MAX_COUNTERS is increased from 8 to 64(the value used by perfstat). Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--Documentation/perf_counter/kerneltop.c132
-rw-r--r--Documentation/perf_counter/perfcounters.h137
-rw-r--r--Documentation/perf_counter/perfstat.c134
3 files changed, 139 insertions, 264 deletions
diff --git a/Documentation/perf_counter/kerneltop.c b/Documentation/perf_counter/kerneltop.c
index cf0e30bab5d5..fe70a2c92a8e 100644
--- a/Documentation/perf_counter/kerneltop.c
+++ b/Documentation/perf_counter/kerneltop.c
@@ -65,126 +65,7 @@
65 65
66#include <linux/unistd.h> 66#include <linux/unistd.h>
67 67
68#ifdef __x86_64__ 68#include "perfcounters.h"
69# define __NR_perf_counter_open 295
70#endif
71
72#ifdef __i386__
73# define __NR_perf_counter_open 333
74#endif
75
76/*
77 * Pick up some kernel type conventions:
78 */
79#define __user
80#define asmlinkage
81
82typedef unsigned int __u32;
83typedef unsigned long long __u64;
84typedef long long __s64;
85
86/*
87 * User-space ABI bits:
88 */
89
90/*
91 * Generalized performance counter event types, used by the hw_event.type
92 * parameter of the sys_perf_counter_open() syscall:
93 */
94enum hw_event_types {
95 /*
96 * Common hardware events, generalized by the kernel:
97 */
98 PERF_COUNT_CPU_CYCLES = 0,
99 PERF_COUNT_INSTRUCTIONS = 1,
100 PERF_COUNT_CACHE_REFERENCES = 2,
101 PERF_COUNT_CACHE_MISSES = 3,
102 PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
103 PERF_COUNT_BRANCH_MISSES = 5,
104 PERF_COUNT_BUS_CYCLES = 6,
105
106 PERF_HW_EVENTS_MAX = 7,
107
108 /*
109 * Special "software" counters provided by the kernel, even if
110 * the hardware does not support performance counters. These
111 * counters measure various physical and sw events of the
112 * kernel (and allow the profiling of them as well):
113 */
114 PERF_COUNT_CPU_CLOCK = -1,
115 PERF_COUNT_TASK_CLOCK = -2,
116 PERF_COUNT_PAGE_FAULTS = -3,
117 PERF_COUNT_CONTEXT_SWITCHES = -4,
118 PERF_COUNT_CPU_MIGRATIONS = -5,
119
120 PERF_SW_EVENTS_MIN = -6,
121};
122
123/*
124 * IRQ-notification data record type:
125 */
126enum perf_counter_record_type {
127 PERF_RECORD_SIMPLE = 0,
128 PERF_RECORD_IRQ = 1,
129 PERF_RECORD_GROUP = 2,
130};
131
132/*
133 * Hardware event to monitor via a performance monitoring counter:
134 */
135struct perf_counter_hw_event {
136 __s64 type;
137
138 __u64 irq_period;
139 __u64 record_type;
140 __u64 read_format;
141
142 __u64 disabled : 1, /* off by default */
143 nmi : 1, /* NMI sampling */
144 raw : 1, /* raw event type */
145 inherit : 1, /* children inherit it */
146 pinned : 1, /* must always be on PMU */
147 exclusive : 1, /* only group on PMU */
148 exclude_user : 1, /* don't count user */
149 exclude_kernel : 1, /* ditto kernel */
150 exclude_hv : 1, /* ditto hypervisor */
151 exclude_idle : 1, /* don't count when idle */
152
153 __reserved_1 : 54;
154
155 __u32 extra_config_len;
156 __u32 __reserved_4;
157
158 __u64 __reserved_2;
159 __u64 __reserved_3;
160};
161
162/*
163 * Ioctls that can be done on a perf counter fd:
164 */
165#define PERF_COUNTER_IOC_ENABLE _IO('$', 0)
166#define PERF_COUNTER_IOC_DISABLE _IO('$', 1)
167
168asmlinkage int sys_perf_counter_open(
169
170 struct perf_counter_hw_event *hw_event_uptr __user,
171 pid_t pid,
172 int cpu,
173 int group_fd,
174 unsigned long flags)
175{
176 int ret;
177
178 ret = syscall(
179 __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
180#if defined(__x86_64__) || defined(__i386__)
181 if (ret < 0 && ret > -4096) {
182 errno = -ret;
183 ret = -1;
184 }
185#endif
186 return ret;
187}
188 69
189const char *event_types [] = { 70const char *event_types [] = {
190 "CPU cycles", 71 "CPU cycles",
@@ -205,21 +86,10 @@ const unsigned int default_count[] = {
205 10000, 86 10000,
206}; 87};
207 88
208/*
209 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
210 * counters in the current task.
211 */
212#define PR_TASK_PERF_COUNTERS_DISABLE 31
213#define PR_TASK_PERF_COUNTERS_ENABLE 32
214
215#define MAX_COUNTERS 8
216
217static int nr_counters = -1; 89static int nr_counters = -1;
218 90
219static __u64 count_filter = 100; 91static __u64 count_filter = 100;
220 92
221#define MAX_NR_CPUS 256
222
223static int event_count[MAX_COUNTERS]; 93static int event_count[MAX_COUNTERS];
224static unsigned long event_id[MAX_COUNTERS]; 94static unsigned long event_id[MAX_COUNTERS];
225static int event_raw[MAX_COUNTERS]; 95static int event_raw[MAX_COUNTERS];
diff --git a/Documentation/perf_counter/perfcounters.h b/Documentation/perf_counter/perfcounters.h
new file mode 100644
index 000000000000..8c1559b25f10
--- /dev/null
+++ b/Documentation/perf_counter/perfcounters.h
@@ -0,0 +1,137 @@
1/*
2 * Ioctls that can be done on a perf counter fd:
3 */
4#define PERF_COUNTER_IOC_ENABLE _IO('$', 0)
5#define PERF_COUNTER_IOC_DISABLE _IO('$', 1)
6
7/*
8 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
9 * counters in the current task.
10 */
11#define PR_TASK_PERF_COUNTERS_DISABLE 31
12#define PR_TASK_PERF_COUNTERS_ENABLE 32
13
14#define MAX_COUNTERS 64
15#define MAX_NR_CPUS 256
16
17#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
18
19/*
20 * Pick up some kernel type conventions:
21 */
22#define __user
23#define asmlinkage
24
25typedef unsigned int __u32;
26typedef unsigned long long __u64;
27typedef long long __s64;
28
29/*
30 * User-space ABI bits:
31 */
32
33/*
34 * Generalized performance counter event types, used by the hw_event.type
35 * parameter of the sys_perf_counter_open() syscall:
36 */
37enum hw_event_types {
38 /*
39 * Common hardware events, generalized by the kernel:
40 */
41 PERF_COUNT_CPU_CYCLES = 0,
42 PERF_COUNT_INSTRUCTIONS = 1,
43 PERF_COUNT_CACHE_REFERENCES = 2,
44 PERF_COUNT_CACHE_MISSES = 3,
45 PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
46 PERF_COUNT_BRANCH_MISSES = 5,
47 PERF_COUNT_BUS_CYCLES = 6,
48
49 PERF_HW_EVENTS_MAX = 7,
50
51 /*
52 * Special "software" counters provided by the kernel, even if
53 * the hardware does not support performance counters. These
54 * counters measure various physical and sw events of the
55 * kernel (and allow the profiling of them as well):
56 */
57 PERF_COUNT_CPU_CLOCK = -1,
58 PERF_COUNT_TASK_CLOCK = -2,
59 PERF_COUNT_PAGE_FAULTS = -3,
60 PERF_COUNT_CONTEXT_SWITCHES = -4,
61 PERF_COUNT_CPU_MIGRATIONS = -5,
62
63 PERF_SW_EVENTS_MIN = -6,
64};
65
66/*
67 * IRQ-notification data record type:
68 */
69enum perf_counter_record_type {
70 PERF_RECORD_SIMPLE = 0,
71 PERF_RECORD_IRQ = 1,
72 PERF_RECORD_GROUP = 2,
73};
74
75/*
76 * Hardware event to monitor via a performance monitoring counter:
77 */
78struct perf_counter_hw_event {
79 __s64 type;
80
81 __u64 irq_period;
82 __u64 record_type;
83 __u64 read_format;
84
85 __u64 disabled : 1, /* off by default */
86 nmi : 1, /* NMI sampling */
87 raw : 1, /* raw event type */
88 inherit : 1, /* children inherit it */
89 pinned : 1, /* must always be on PMU */
90 exclusive : 1, /* only group on PMU */
91 exclude_user : 1, /* don't count user */
92 exclude_kernel : 1, /* ditto kernel */
93 exclude_hv : 1, /* ditto hypervisor */
94 exclude_idle : 1, /* don't count when idle */
95
96 __reserved_1 : 54;
97
98 __u32 extra_config_len;
99 __u32 __reserved_4;
100
101 __u64 __reserved_2;
102 __u64 __reserved_3;
103};
104
105#ifdef __x86_64__
106# define __NR_perf_counter_open 295
107#endif
108
109#ifdef __i386__
110# define __NR_perf_counter_open 333
111#endif
112
113#ifdef __powerpc__
114#define __NR_perf_counter_open 319
115#endif
116
117asmlinkage int sys_perf_counter_open(
118
119 struct perf_counter_hw_event *hw_event_uptr __user,
120 pid_t pid,
121 int cpu,
122 int group_fd,
123 unsigned long flags)
124{
125 int ret;
126
127 ret = syscall(
128 __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
129#if defined(__x86_64__) || defined(__i386__)
130 if (ret < 0 && ret > -4096) {
131 errno = -ret;
132 ret = -1;
133 }
134#endif
135 return ret;
136}
137
diff --git a/Documentation/perf_counter/perfstat.c b/Documentation/perf_counter/perfstat.c
index 9a5808fbcf90..a3d4a7a602f6 100644
--- a/Documentation/perf_counter/perfstat.c
+++ b/Documentation/perf_counter/perfstat.c
@@ -52,133 +52,7 @@
52 52
53#include <linux/unistd.h> 53#include <linux/unistd.h>
54 54
55#ifdef __x86_64__ 55#include "perfcounters.h"
56# define __NR_perf_counter_open 295
57#endif
58
59#ifdef __i386__
60# define __NR_perf_counter_open 333
61#endif
62
63#ifdef __powerpc__
64#define __NR_perf_counter_open 319
65#endif
66
67/*
68 * Pick up some kernel type conventions:
69 */
70#define __user
71#define asmlinkage
72
73typedef unsigned int __u32;
74typedef unsigned long long __u64;
75typedef long long __s64;
76
77#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
78
79/*
80 * User-space ABI bits:
81 */
82
83/*
84 * Generalized performance counter event types, used by the hw_event.type
85 * parameter of the sys_perf_counter_open() syscall:
86 */
87enum hw_event_types {
88 /*
89 * Common hardware events, generalized by the kernel:
90 */
91 PERF_COUNT_CPU_CYCLES = 0,
92 PERF_COUNT_INSTRUCTIONS = 1,
93 PERF_COUNT_CACHE_REFERENCES = 2,
94 PERF_COUNT_CACHE_MISSES = 3,
95 PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
96 PERF_COUNT_BRANCH_MISSES = 5,
97 PERF_COUNT_BUS_CYCLES = 6,
98
99 PERF_HW_EVENTS_MAX = 7,
100
101 /*
102 * Special "software" counters provided by the kernel, even if
103 * the hardware does not support performance counters. These
104 * counters measure various physical and sw events of the
105 * kernel (and allow the profiling of them as well):
106 */
107 PERF_COUNT_CPU_CLOCK = -1,
108 PERF_COUNT_TASK_CLOCK = -2,
109 PERF_COUNT_PAGE_FAULTS = -3,
110 PERF_COUNT_CONTEXT_SWITCHES = -4,
111 PERF_COUNT_CPU_MIGRATIONS = -5,
112
113 PERF_SW_EVENTS_MIN = -6,
114};
115
116/*
117 * IRQ-notification data record type:
118 */
119enum perf_counter_record_type {
120 PERF_RECORD_SIMPLE = 0,
121 PERF_RECORD_IRQ = 1,
122 PERF_RECORD_GROUP = 2,
123};
124
125/*
126 * Hardware event to monitor via a performance monitoring counter:
127 */
128struct perf_counter_hw_event {
129 __s64 type;
130
131 __u64 irq_period;
132 __u64 record_type;
133 __u64 read_format;
134
135 __u64 disabled : 1, /* off by default */
136 nmi : 1, /* NMI sampling */
137 raw : 1, /* raw event type */
138 inherit : 1, /* children inherit it */
139 pinned : 1, /* must always be on PMU */
140 exclusive : 1, /* only group on PMU */
141 exclude_user : 1, /* don't count user */
142 exclude_kernel : 1, /* ditto kernel */
143 exclude_hv : 1, /* ditto hypervisor */
144 exclude_idle : 1, /* don't count when idle */
145
146 __reserved_1 : 54;
147
148 __u32 extra_config_len;
149 __u32 __reserved_4;
150
151 __u64 __reserved_2;
152 __u64 __reserved_3;
153};
154
155/*
156 * Ioctls that can be done on a perf counter fd:
157 */
158#define PERF_COUNTER_IOC_ENABLE _IO('$', 0)
159#define PERF_COUNTER_IOC_DISABLE _IO('$', 1)
160
161asmlinkage int sys_perf_counter_open(
162
163 struct perf_counter_hw_event *hw_event_uptr __user,
164 pid_t pid,
165 int cpu,
166 int group_fd,
167 unsigned long flags)
168{
169 int ret;
170
171 ret = syscall(
172 __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
173#if defined(__x86_64__) || defined(__i386__)
174 if (ret < 0 && ret > -4096) {
175 errno = -ret;
176 ret = -1;
177 }
178#endif
179 return ret;
180}
181
182 56
183static char *hw_event_names [] = { 57static char *hw_event_names [] = {
184 "CPU cycles", 58 "CPU cycles",
@@ -224,9 +98,6 @@ static struct event_symbol event_symbols [] = {
224 {PERF_COUNT_CPU_MIGRATIONS, "migrations", }, 98 {PERF_COUNT_CPU_MIGRATIONS, "migrations", },
225}; 99};
226 100
227#define MAX_COUNTERS 64
228#define MAX_NR_CPUS 256
229
230static int nr_counters = 0; 101static int nr_counters = 0;
231static int nr_cpus = 0; 102static int nr_cpus = 0;
232 103
@@ -388,9 +259,6 @@ err:
388 259
389char fault_here[1000000]; 260char fault_here[1000000];
390 261
391#define PR_TASK_PERF_COUNTERS_DISABLE 31
392#define PR_TASK_PERF_COUNTERS_ENABLE 32
393
394static int fd[MAX_NR_CPUS][MAX_COUNTERS]; 262static int fd[MAX_NR_CPUS][MAX_COUNTERS];
395 263
396static void create_counter(int counter) 264static void create_counter(int counter)