diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/perf_counter.h | 171 | ||||
-rw-r--r-- | include/linux/sched.h | 9 | ||||
-rw-r--r-- | include/linux/syscalls.h | 6 |
3 files changed, 186 insertions, 0 deletions
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h new file mode 100644 index 00000000000..22c4469abf4 --- /dev/null +++ b/include/linux/perf_counter.h | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * Performance counters: | ||
3 | * | ||
4 | * Copyright(C) 2008, Thomas Gleixner <tglx@linutronix.de> | ||
5 | * Copyright(C) 2008, Red Hat, Inc., Ingo Molnar | ||
6 | * | ||
7 | * Data type definitions, declarations, prototypes. | ||
8 | * | ||
9 | * Started by: Thomas Gleixner and Ingo Molnar | ||
10 | * | ||
11 | * For licencing details see kernel-base/COPYING | ||
12 | */ | ||
13 | #ifndef _LINUX_PERF_COUNTER_H | ||
14 | #define _LINUX_PERF_COUNTER_H | ||
15 | |||
16 | #include <asm/atomic.h> | ||
17 | |||
18 | #include <linux/list.h> | ||
19 | #include <linux/mutex.h> | ||
20 | #include <linux/rculist.h> | ||
21 | #include <linux/rcupdate.h> | ||
22 | #include <linux/spinlock.h> | ||
23 | |||
24 | struct task_struct; | ||
25 | |||
26 | /* | ||
27 | * Generalized hardware event types, used by the hw_event_type parameter | ||
28 | * of the sys_perf_counter_open() syscall: | ||
29 | */ | ||
30 | enum hw_event_types { | ||
31 | PERF_COUNT_CYCLES, | ||
32 | PERF_COUNT_INSTRUCTIONS, | ||
33 | PERF_COUNT_CACHE_REFERENCES, | ||
34 | PERF_COUNT_CACHE_MISSES, | ||
35 | PERF_COUNT_BRANCH_INSTRUCTIONS, | ||
36 | PERF_COUNT_BRANCH_MISSES, | ||
37 | /* | ||
38 | * If this bit is set in the type, then trigger NMI sampling: | ||
39 | */ | ||
40 | PERF_COUNT_NMI = (1 << 30), | ||
41 | }; | ||
42 | |||
43 | /* | ||
44 | * IRQ-notification data record type: | ||
45 | */ | ||
46 | enum perf_record_type { | ||
47 | PERF_RECORD_SIMPLE, | ||
48 | PERF_RECORD_IRQ, | ||
49 | PERF_RECORD_GROUP, | ||
50 | }; | ||
51 | |||
52 | /** | ||
53 | * struct hw_perf_counter - performance counter hardware details | ||
54 | */ | ||
55 | struct hw_perf_counter { | ||
56 | u64 config; | ||
57 | unsigned long config_base; | ||
58 | unsigned long counter_base; | ||
59 | int nmi; | ||
60 | unsigned int idx; | ||
61 | u64 prev_count; | ||
62 | s32 next_count; | ||
63 | u64 irq_period; | ||
64 | }; | ||
65 | |||
66 | /* | ||
67 | * Hardcoded buffer length limit for now, for IRQ-fed events: | ||
68 | */ | ||
69 | #define PERF_DATA_BUFLEN 2048 | ||
70 | |||
71 | /** | ||
72 | * struct perf_data - performance counter IRQ data sampling ... | ||
73 | */ | ||
74 | struct perf_data { | ||
75 | int len; | ||
76 | int rd_idx; | ||
77 | int overrun; | ||
78 | u8 data[PERF_DATA_BUFLEN]; | ||
79 | }; | ||
80 | |||
81 | /** | ||
82 | * struct perf_counter - performance counter kernel representation: | ||
83 | */ | ||
84 | struct perf_counter { | ||
85 | struct list_head list; | ||
86 | int active; | ||
87 | #if BITS_PER_LONG == 64 | ||
88 | atomic64_t count; | ||
89 | #else | ||
90 | atomic_t count32[2]; | ||
91 | #endif | ||
92 | u64 __irq_period; | ||
93 | |||
94 | struct hw_perf_counter hw; | ||
95 | |||
96 | struct perf_counter_context *ctx; | ||
97 | struct task_struct *task; | ||
98 | |||
99 | /* | ||
100 | * Protect attach/detach: | ||
101 | */ | ||
102 | struct mutex mutex; | ||
103 | |||
104 | int oncpu; | ||
105 | int cpu; | ||
106 | |||
107 | s32 hw_event_type; | ||
108 | enum perf_record_type record_type; | ||
109 | |||
110 | /* read() / irq related data */ | ||
111 | wait_queue_head_t waitq; | ||
112 | /* optional: for NMIs */ | ||
113 | int wakeup_pending; | ||
114 | struct perf_data *irqdata; | ||
115 | struct perf_data *usrdata; | ||
116 | struct perf_data data[2]; | ||
117 | }; | ||
118 | |||
119 | /** | ||
120 | * struct perf_counter_context - counter context structure | ||
121 | * | ||
122 | * Used as a container for task counters and CPU counters as well: | ||
123 | */ | ||
124 | struct perf_counter_context { | ||
125 | #ifdef CONFIG_PERF_COUNTERS | ||
126 | /* | ||
127 | * Protect the list of counters: | ||
128 | */ | ||
129 | spinlock_t lock; | ||
130 | struct list_head counters; | ||
131 | int nr_counters; | ||
132 | int nr_active; | ||
133 | struct task_struct *task; | ||
134 | #endif | ||
135 | }; | ||
136 | |||
137 | /** | ||
138 | * struct perf_counter_cpu_context - per cpu counter context structure | ||
139 | */ | ||
140 | struct perf_cpu_context { | ||
141 | struct perf_counter_context ctx; | ||
142 | struct perf_counter_context *task_ctx; | ||
143 | int active_oncpu; | ||
144 | int max_pertask; | ||
145 | }; | ||
146 | |||
147 | /* | ||
148 | * Set by architecture code: | ||
149 | */ | ||
150 | extern int perf_max_counters; | ||
151 | |||
152 | #ifdef CONFIG_PERF_COUNTERS | ||
153 | extern void perf_counter_task_sched_in(struct task_struct *task, int cpu); | ||
154 | extern void perf_counter_task_sched_out(struct task_struct *task, int cpu); | ||
155 | extern void perf_counter_task_tick(struct task_struct *task, int cpu); | ||
156 | extern void perf_counter_init_task(struct task_struct *task); | ||
157 | extern void perf_counter_notify(struct pt_regs *regs); | ||
158 | extern void perf_counter_print_debug(void); | ||
159 | #else | ||
160 | static inline void | ||
161 | perf_counter_task_sched_in(struct task_struct *task, int cpu) { } | ||
162 | static inline void | ||
163 | perf_counter_task_sched_out(struct task_struct *task, int cpu) { } | ||
164 | static inline void | ||
165 | perf_counter_task_tick(struct task_struct *task, int cpu) { } | ||
166 | static inline void perf_counter_init_task(struct task_struct *task) { } | ||
167 | static inline void perf_counter_notify(struct pt_regs *regs) { } | ||
168 | static inline void perf_counter_print_debug(void) { } | ||
169 | #endif | ||
170 | |||
171 | #endif /* _LINUX_PERF_COUNTER_H */ | ||
diff --git a/include/linux/sched.h b/include/linux/sched.h index 55e30d11447..4c530278391 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -71,6 +71,7 @@ struct sched_param { | |||
71 | #include <linux/fs_struct.h> | 71 | #include <linux/fs_struct.h> |
72 | #include <linux/compiler.h> | 72 | #include <linux/compiler.h> |
73 | #include <linux/completion.h> | 73 | #include <linux/completion.h> |
74 | #include <linux/perf_counter.h> | ||
74 | #include <linux/pid.h> | 75 | #include <linux/pid.h> |
75 | #include <linux/percpu.h> | 76 | #include <linux/percpu.h> |
76 | #include <linux/topology.h> | 77 | #include <linux/topology.h> |
@@ -1326,6 +1327,7 @@ struct task_struct { | |||
1326 | struct list_head pi_state_list; | 1327 | struct list_head pi_state_list; |
1327 | struct futex_pi_state *pi_state_cache; | 1328 | struct futex_pi_state *pi_state_cache; |
1328 | #endif | 1329 | #endif |
1330 | struct perf_counter_context perf_counter_ctx; | ||
1329 | #ifdef CONFIG_NUMA | 1331 | #ifdef CONFIG_NUMA |
1330 | struct mempolicy *mempolicy; | 1332 | struct mempolicy *mempolicy; |
1331 | short il_next; | 1333 | short il_next; |
@@ -2285,6 +2287,13 @@ static inline void inc_syscw(struct task_struct *tsk) | |||
2285 | #define TASK_SIZE_OF(tsk) TASK_SIZE | 2287 | #define TASK_SIZE_OF(tsk) TASK_SIZE |
2286 | #endif | 2288 | #endif |
2287 | 2289 | ||
2290 | /* | ||
2291 | * Call the function if the target task is executing on a CPU right now: | ||
2292 | */ | ||
2293 | extern void task_oncpu_function_call(struct task_struct *p, | ||
2294 | void (*func) (void *info), void *info); | ||
2295 | |||
2296 | |||
2288 | #ifdef CONFIG_MM_OWNER | 2297 | #ifdef CONFIG_MM_OWNER |
2289 | extern void mm_update_next_owner(struct mm_struct *mm); | 2298 | extern void mm_update_next_owner(struct mm_struct *mm); |
2290 | extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); | 2299 | extern void mm_init_owner(struct mm_struct *mm, struct task_struct *p); |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 04fb47bfb92..6cce728a626 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -624,4 +624,10 @@ asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len); | |||
624 | 624 | ||
625 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]); | 625 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]); |
626 | 626 | ||
627 | asmlinkage int | ||
628 | sys_perf_counter_open(u32 hw_event_type, | ||
629 | u32 hw_event_period, | ||
630 | u32 record_type, | ||
631 | pid_t pid, | ||
632 | int cpu); | ||
627 | #endif | 633 | #endif |