Commit | Line | Data |
---|---|---|
0793a61d | 1 | /* |
57c0c15b | 2 | * Performance events: |
0793a61d | 3 | * |
a308444c | 4 | * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de> |
e7e7ee2e IM |
5 | * Copyright (C) 2008-2011, Red Hat, Inc., Ingo Molnar |
6 | * Copyright (C) 2008-2011, Red Hat, Inc., Peter Zijlstra | |
0793a61d | 7 | * |
57c0c15b | 8 | * Data type definitions, declarations, prototypes. |
0793a61d | 9 | * |
a308444c | 10 | * Started by: Thomas Gleixner and Ingo Molnar |
0793a61d | 11 | * |
57c0c15b | 12 | * For licencing details see kernel-base/COPYING |
0793a61d | 13 | */ |
cdd6c482 IM |
14 | #ifndef _LINUX_PERF_EVENT_H |
15 | #define _LINUX_PERF_EVENT_H | |
0793a61d | 16 | |
607ca46e | 17 | #include <uapi/linux/perf_event.h> |
0793a61d | 18 | |
9f66a381 | 19 | /* |
f3dfd265 | 20 | * Kernel-internal data types and definitions: |
9f66a381 IM |
21 | */ |
22 | ||
cdd6c482 IM |
23 | #ifdef CONFIG_PERF_EVENTS |
24 | # include <asm/perf_event.h> | |
7be79236 | 25 | # include <asm/local64.h> |
f3dfd265 PM |
26 | #endif |
27 | ||
39447b38 | 28 | struct perf_guest_info_callbacks { |
e7e7ee2e IM |
29 | int (*is_in_guest)(void); |
30 | int (*is_user_mode)(void); | |
31 | unsigned long (*get_guest_ip)(void); | |
39447b38 ZY |
32 | }; |
33 | ||
2ff6cfd7 AB |
34 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
35 | #include <asm/hw_breakpoint.h> | |
36 | #endif | |
37 | ||
f3dfd265 PM |
38 | #include <linux/list.h> |
39 | #include <linux/mutex.h> | |
40 | #include <linux/rculist.h> | |
41 | #include <linux/rcupdate.h> | |
42 | #include <linux/spinlock.h> | |
d6d020e9 | 43 | #include <linux/hrtimer.h> |
3c446b3d | 44 | #include <linux/fs.h> |
709e50cf | 45 | #include <linux/pid_namespace.h> |
906010b2 | 46 | #include <linux/workqueue.h> |
5331d7b8 | 47 | #include <linux/ftrace.h> |
85cfabbc | 48 | #include <linux/cpu.h> |
e360adbe | 49 | #include <linux/irq_work.h> |
c5905afb | 50 | #include <linux/static_key.h> |
851cf6e7 | 51 | #include <linux/jump_label_ratelimit.h> |
60063497 | 52 | #include <linux/atomic.h> |
641cc938 | 53 | #include <linux/sysfs.h> |
4018994f | 54 | #include <linux/perf_regs.h> |
fadfe7be | 55 | #include <linux/workqueue.h> |
39bed6cb | 56 | #include <linux/cgroup.h> |
fa588151 | 57 | #include <asm/local.h> |
f3dfd265 | 58 | |
f9188e02 PZ |
59 | struct perf_callchain_entry { |
60 | __u64 nr; | |
61 | __u64 ip[PERF_MAX_STACK_DEPTH]; | |
62 | }; | |
63 | ||
3a43ce68 FW |
64 | struct perf_raw_record { |
65 | u32 size; | |
66 | void *data; | |
f413cdb8 FW |
67 | }; |
68 | ||
bce38cd5 SE |
69 | /* |
70 | * branch stack layout: | |
71 | * nr: number of taken branches stored in entries[] | |
72 | * | |
73 | * Note that nr can vary from sample to sample | |
74 | * branches (to, from) are stored from most recent | |
75 | * to least recent, i.e., entries[0] contains the most | |
76 | * recent branch. | |
77 | */ | |
caff2bef PZ |
78 | struct perf_branch_stack { |
79 | __u64 nr; | |
80 | struct perf_branch_entry entries[0]; | |
81 | }; | |
82 | ||
f3dfd265 PM |
83 | struct task_struct; |
84 | ||
efc9f05d SE |
85 | /* |
86 | * extra PMU register associated with an event | |
87 | */ | |
88 | struct hw_perf_event_extra { | |
89 | u64 config; /* register value */ | |
90 | unsigned int reg; /* register address or index */ | |
91 | int alloc; /* extra register already allocated */ | |
92 | int idx; /* index in shared_regs->regs[] */ | |
93 | }; | |
94 | ||
0793a61d | 95 | /** |
cdd6c482 | 96 | * struct hw_perf_event - performance event hardware details: |
0793a61d | 97 | */ |
cdd6c482 IM |
98 | struct hw_perf_event { |
99 | #ifdef CONFIG_PERF_EVENTS | |
d6d020e9 PZ |
100 | union { |
101 | struct { /* hardware */ | |
a308444c | 102 | u64 config; |
447a194b | 103 | u64 last_tag; |
a308444c | 104 | unsigned long config_base; |
cdd6c482 | 105 | unsigned long event_base; |
c48b6053 | 106 | int event_base_rdpmc; |
a308444c | 107 | int idx; |
447a194b | 108 | int last_cpu; |
9fac2cf3 | 109 | int flags; |
bce38cd5 | 110 | |
efc9f05d | 111 | struct hw_perf_event_extra extra_reg; |
bce38cd5 | 112 | struct hw_perf_event_extra branch_reg; |
d6d020e9 | 113 | }; |
721a669b | 114 | struct { /* software */ |
a308444c | 115 | struct hrtimer hrtimer; |
d6d020e9 | 116 | }; |
f22c1bb6 | 117 | struct { /* tracepoint */ |
f22c1bb6 ON |
118 | /* for tp_event->class */ |
119 | struct list_head tp_list; | |
120 | }; | |
4afbb24c MF |
121 | struct { /* intel_cqm */ |
122 | int cqm_state; | |
b3df4ec4 | 123 | u32 cqm_rmid; |
a223c1c7 | 124 | int is_group_event; |
4afbb24c MF |
125 | struct list_head cqm_events_entry; |
126 | struct list_head cqm_groups_entry; | |
127 | struct list_head cqm_group_entry; | |
128 | }; | |
ec0d7729 AS |
129 | struct { /* itrace */ |
130 | int itrace_started; | |
131 | }; | |
c7ab62bf HR |
132 | struct { /* amd_power */ |
133 | u64 pwr_acc; | |
134 | u64 ptsc; | |
135 | }; | |
24f1e32c | 136 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
45a73372 | 137 | struct { /* breakpoint */ |
d580ff86 PZ |
138 | /* |
139 | * Crufty hack to avoid the chicken and egg | |
140 | * problem hw_breakpoint has with context | |
141 | * creation and event initalization. | |
142 | */ | |
f22c1bb6 ON |
143 | struct arch_hw_breakpoint info; |
144 | struct list_head bp_list; | |
45a73372 | 145 | }; |
24f1e32c | 146 | #endif |
d6d020e9 | 147 | }; |
b0e87875 PZ |
148 | /* |
149 | * If the event is a per task event, this will point to the task in | |
150 | * question. See the comment in perf_event_alloc(). | |
151 | */ | |
50f16a8b | 152 | struct task_struct *target; |
b0e87875 PZ |
153 | |
154 | /* | |
155 | * hw_perf_event::state flags; used to track the PERF_EF_* state. | |
156 | */ | |
157 | #define PERF_HES_STOPPED 0x01 /* the counter is stopped */ | |
158 | #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */ | |
159 | #define PERF_HES_ARCH 0x04 | |
160 | ||
a4eaf7f1 | 161 | int state; |
b0e87875 PZ |
162 | |
163 | /* | |
164 | * The last observed hardware counter value, updated with a | |
165 | * local64_cmpxchg() such that pmu::read() can be called nested. | |
166 | */ | |
e7850595 | 167 | local64_t prev_count; |
b0e87875 PZ |
168 | |
169 | /* | |
170 | * The period to start the next sample with. | |
171 | */ | |
b23f3325 | 172 | u64 sample_period; |
b0e87875 PZ |
173 | |
174 | /* | |
175 | * The period we started this sample with. | |
176 | */ | |
9e350de3 | 177 | u64 last_period; |
b0e87875 PZ |
178 | |
179 | /* | |
180 | * However much is left of the current period; note that this is | |
181 | * a full 64bit value and allows for generation of periods longer | |
182 | * than hardware might allow. | |
183 | */ | |
e7850595 | 184 | local64_t period_left; |
b0e87875 PZ |
185 | |
186 | /* | |
187 | * State for throttling the event, see __perf_event_overflow() and | |
188 | * perf_adjust_freq_unthr_context(). | |
189 | */ | |
e050e3f0 | 190 | u64 interrupts_seq; |
60db5e09 | 191 | u64 interrupts; |
6a24ed6c | 192 | |
b0e87875 PZ |
193 | /* |
194 | * State for freq target events, see __perf_event_overflow() and | |
195 | * perf_adjust_freq_unthr_context(). | |
196 | */ | |
abd50713 PZ |
197 | u64 freq_time_stamp; |
198 | u64 freq_count_stamp; | |
ee06094f | 199 | #endif |
0793a61d TG |
200 | }; |
201 | ||
cdd6c482 | 202 | struct perf_event; |
621a01ea | 203 | |
8d2cacbb PZ |
204 | /* |
205 | * Common implementation detail of pmu::{start,commit,cancel}_txn | |
206 | */ | |
fbbe0701 | 207 | #define PERF_PMU_TXN_ADD 0x1 /* txn to add/schedule event on PMU */ |
4a00c16e | 208 | #define PERF_PMU_TXN_READ 0x2 /* txn to read event group from PMU */ |
fbbe0701 | 209 | |
53b25335 VW |
210 | /** |
211 | * pmu::capabilities flags | |
212 | */ | |
213 | #define PERF_PMU_CAP_NO_INTERRUPT 0x01 | |
34f43927 | 214 | #define PERF_PMU_CAP_NO_NMI 0x02 |
0a4e38e6 | 215 | #define PERF_PMU_CAP_AUX_NO_SG 0x04 |
6a279230 | 216 | #define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08 |
bed5b25a | 217 | #define PERF_PMU_CAP_EXCLUSIVE 0x10 |
ec0d7729 | 218 | #define PERF_PMU_CAP_ITRACE 0x20 |
53b25335 | 219 | |
621a01ea | 220 | /** |
4aeb0b42 | 221 | * struct pmu - generic performance monitoring unit |
621a01ea | 222 | */ |
4aeb0b42 | 223 | struct pmu { |
b0a873eb PZ |
224 | struct list_head entry; |
225 | ||
c464c76e | 226 | struct module *module; |
abe43400 | 227 | struct device *dev; |
0c9d42ed | 228 | const struct attribute_group **attr_groups; |
03d8e80b | 229 | const char *name; |
2e80a82a PZ |
230 | int type; |
231 | ||
53b25335 VW |
232 | /* |
233 | * various common per-pmu feature flags | |
234 | */ | |
235 | int capabilities; | |
236 | ||
108b02cf PZ |
237 | int * __percpu pmu_disable_count; |
238 | struct perf_cpu_context * __percpu pmu_cpu_context; | |
bed5b25a | 239 | atomic_t exclusive_cnt; /* < 0: cpu; > 0: tsk */ |
8dc85d54 | 240 | int task_ctx_nr; |
62b85639 | 241 | int hrtimer_interval_ms; |
6bde9b6c LM |
242 | |
243 | /* | |
a4eaf7f1 PZ |
244 | * Fully disable/enable this PMU, can be used to protect from the PMI |
245 | * as well as for lazy/batch writing of the MSRs. | |
6bde9b6c | 246 | */ |
ad5133b7 PZ |
247 | void (*pmu_enable) (struct pmu *pmu); /* optional */ |
248 | void (*pmu_disable) (struct pmu *pmu); /* optional */ | |
6bde9b6c | 249 | |
8d2cacbb | 250 | /* |
a4eaf7f1 | 251 | * Try and initialize the event for this PMU. |
b0e87875 PZ |
252 | * |
253 | * Returns: | |
254 | * -ENOENT -- @event is not for this PMU | |
255 | * | |
256 | * -ENODEV -- @event is for this PMU but PMU not present | |
257 | * -EBUSY -- @event is for this PMU but PMU temporarily unavailable | |
258 | * -EINVAL -- @event is for this PMU but @event is not valid | |
259 | * -EOPNOTSUPP -- @event is for this PMU, @event is valid, but not supported | |
260 | * -EACCESS -- @event is for this PMU, @event is valid, but no privilidges | |
261 | * | |
262 | * 0 -- @event is for this PMU and valid | |
263 | * | |
264 | * Other error return values are allowed. | |
8d2cacbb | 265 | */ |
b0a873eb PZ |
266 | int (*event_init) (struct perf_event *event); |
267 | ||
1e0fb9ec AL |
268 | /* |
269 | * Notification that the event was mapped or unmapped. Called | |
270 | * in the context of the mapping task. | |
271 | */ | |
272 | void (*event_mapped) (struct perf_event *event); /*optional*/ | |
273 | void (*event_unmapped) (struct perf_event *event); /*optional*/ | |
274 | ||
b0e87875 PZ |
275 | /* |
276 | * Flags for ->add()/->del()/ ->start()/->stop(). There are | |
277 | * matching hw_perf_event::state flags. | |
278 | */ | |
a4eaf7f1 PZ |
279 | #define PERF_EF_START 0x01 /* start the counter when adding */ |
280 | #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */ | |
281 | #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */ | |
282 | ||
8d2cacbb | 283 | /* |
b0e87875 PZ |
284 | * Adds/Removes a counter to/from the PMU, can be done inside a |
285 | * transaction, see the ->*_txn() methods. | |
286 | * | |
287 | * The add/del callbacks will reserve all hardware resources required | |
288 | * to service the event, this includes any counter constraint | |
289 | * scheduling etc. | |
290 | * | |
291 | * Called with IRQs disabled and the PMU disabled on the CPU the event | |
292 | * is on. | |
293 | * | |
294 | * ->add() called without PERF_EF_START should result in the same state | |
295 | * as ->add() followed by ->stop(). | |
296 | * | |
297 | * ->del() must always PERF_EF_UPDATE stop an event. If it calls | |
298 | * ->stop() that must deal with already being stopped without | |
299 | * PERF_EF_UPDATE. | |
a4eaf7f1 PZ |
300 | */ |
301 | int (*add) (struct perf_event *event, int flags); | |
302 | void (*del) (struct perf_event *event, int flags); | |
303 | ||
304 | /* | |
b0e87875 PZ |
305 | * Starts/Stops a counter present on the PMU. |
306 | * | |
307 | * The PMI handler should stop the counter when perf_event_overflow() | |
308 | * returns !0. ->start() will be used to continue. | |
309 | * | |
310 | * Also used to change the sample period. | |
311 | * | |
312 | * Called with IRQs disabled and the PMU disabled on the CPU the event | |
313 | * is on -- will be called from NMI context with the PMU generates | |
314 | * NMIs. | |
315 | * | |
316 | * ->stop() with PERF_EF_UPDATE will read the counter and update | |
317 | * period/count values like ->read() would. | |
318 | * | |
319 | * ->start() with PERF_EF_RELOAD will reprogram the the counter | |
320 | * value, must be preceded by a ->stop() with PERF_EF_UPDATE. | |
a4eaf7f1 PZ |
321 | */ |
322 | void (*start) (struct perf_event *event, int flags); | |
323 | void (*stop) (struct perf_event *event, int flags); | |
324 | ||
325 | /* | |
326 | * Updates the counter value of the event. | |
b0e87875 PZ |
327 | * |
328 | * For sampling capable PMUs this will also update the software period | |
329 | * hw_perf_event::period_left field. | |
a4eaf7f1 | 330 | */ |
cdd6c482 | 331 | void (*read) (struct perf_event *event); |
6bde9b6c LM |
332 | |
333 | /* | |
24cd7f54 PZ |
334 | * Group events scheduling is treated as a transaction, add |
335 | * group events as a whole and perform one schedulability test. | |
336 | * If the test fails, roll back the whole group | |
a4eaf7f1 PZ |
337 | * |
338 | * Start the transaction, after this ->add() doesn't need to | |
24cd7f54 | 339 | * do schedulability tests. |
fbbe0701 SB |
340 | * |
341 | * Optional. | |
8d2cacbb | 342 | */ |
fbbe0701 | 343 | void (*start_txn) (struct pmu *pmu, unsigned int txn_flags); |
8d2cacbb | 344 | /* |
a4eaf7f1 | 345 | * If ->start_txn() disabled the ->add() schedulability test |
8d2cacbb PZ |
346 | * then ->commit_txn() is required to perform one. On success |
347 | * the transaction is closed. On error the transaction is kept | |
348 | * open until ->cancel_txn() is called. | |
fbbe0701 SB |
349 | * |
350 | * Optional. | |
8d2cacbb | 351 | */ |
fbbe0701 | 352 | int (*commit_txn) (struct pmu *pmu); |
8d2cacbb | 353 | /* |
a4eaf7f1 | 354 | * Will cancel the transaction, assumes ->del() is called |
25985edc | 355 | * for each successful ->add() during the transaction. |
fbbe0701 SB |
356 | * |
357 | * Optional. | |
8d2cacbb | 358 | */ |
fbbe0701 | 359 | void (*cancel_txn) (struct pmu *pmu); |
35edc2a5 PZ |
360 | |
361 | /* | |
362 | * Will return the value for perf_event_mmap_page::index for this event, | |
363 | * if no implementation is provided it will default to: event->hw.idx + 1. | |
364 | */ | |
365 | int (*event_idx) (struct perf_event *event); /*optional */ | |
d010b332 | 366 | |
ba532500 YZ |
367 | /* |
368 | * context-switches callback | |
369 | */ | |
370 | void (*sched_task) (struct perf_event_context *ctx, | |
371 | bool sched_in); | |
4af57ef2 YZ |
372 | /* |
373 | * PMU specific data size | |
374 | */ | |
375 | size_t task_ctx_size; | |
ba532500 | 376 | |
eacd3ecc MF |
377 | |
378 | /* | |
379 | * Return the count value for a counter. | |
380 | */ | |
381 | u64 (*count) (struct perf_event *event); /*optional*/ | |
45bfb2e5 PZ |
382 | |
383 | /* | |
384 | * Set up pmu-private data structures for an AUX area | |
385 | */ | |
386 | void *(*setup_aux) (int cpu, void **pages, | |
387 | int nr_pages, bool overwrite); | |
388 | /* optional */ | |
389 | ||
390 | /* | |
391 | * Free pmu-private AUX data structures | |
392 | */ | |
393 | void (*free_aux) (void *aux); /* optional */ | |
66eb579e MR |
394 | |
395 | /* | |
396 | * Filter events for PMU-specific reasons. | |
397 | */ | |
398 | int (*filter_match) (struct perf_event *event); /* optional */ | |
621a01ea IM |
399 | }; |
400 | ||
6a930700 | 401 | /** |
cdd6c482 | 402 | * enum perf_event_active_state - the states of a event |
6a930700 | 403 | */ |
cdd6c482 | 404 | enum perf_event_active_state { |
a69b0ca4 | 405 | PERF_EVENT_STATE_DEAD = -4, |
179033b3 | 406 | PERF_EVENT_STATE_EXIT = -3, |
57c0c15b | 407 | PERF_EVENT_STATE_ERROR = -2, |
cdd6c482 IM |
408 | PERF_EVENT_STATE_OFF = -1, |
409 | PERF_EVENT_STATE_INACTIVE = 0, | |
57c0c15b | 410 | PERF_EVENT_STATE_ACTIVE = 1, |
6a930700 IM |
411 | }; |
412 | ||
9b51f66d | 413 | struct file; |
453f19ee PZ |
414 | struct perf_sample_data; |
415 | ||
a8b0ca17 | 416 | typedef void (*perf_overflow_handler_t)(struct perf_event *, |
b326e956 FW |
417 | struct perf_sample_data *, |
418 | struct pt_regs *regs); | |
419 | ||
d6f962b5 | 420 | enum perf_group_flag { |
e7e7ee2e | 421 | PERF_GROUP_SOFTWARE = 0x1, |
d6f962b5 FW |
422 | }; |
423 | ||
e7e7ee2e IM |
424 | #define SWEVENT_HLIST_BITS 8 |
425 | #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS) | |
76e1d904 FW |
426 | |
427 | struct swevent_hlist { | |
e7e7ee2e IM |
428 | struct hlist_head heads[SWEVENT_HLIST_SIZE]; |
429 | struct rcu_head rcu_head; | |
76e1d904 FW |
430 | }; |
431 | ||
8a49542c PZ |
432 | #define PERF_ATTACH_CONTEXT 0x01 |
433 | #define PERF_ATTACH_GROUP 0x02 | |
d580ff86 | 434 | #define PERF_ATTACH_TASK 0x04 |
4af57ef2 | 435 | #define PERF_ATTACH_TASK_DATA 0x08 |
8a49542c | 436 | |
877c6856 | 437 | struct perf_cgroup; |
76369139 FW |
438 | struct ring_buffer; |
439 | ||
0793a61d | 440 | /** |
cdd6c482 | 441 | * struct perf_event - performance event kernel representation: |
0793a61d | 442 | */ |
cdd6c482 IM |
443 | struct perf_event { |
444 | #ifdef CONFIG_PERF_EVENTS | |
9886167d PZ |
445 | /* |
446 | * entry onto perf_event_context::event_list; | |
447 | * modifications require ctx->lock | |
448 | * RCU safe iterations. | |
449 | */ | |
592903cd | 450 | struct list_head event_entry; |
9886167d PZ |
451 | |
452 | /* | |
453 | * XXX: group_entry and sibling_list should be mutually exclusive; | |
454 | * either you're a sibling on a group, or you're the group leader. | |
455 | * Rework the code to always use the same list element. | |
456 | * | |
457 | * Locked for modification by both ctx->mutex and ctx->lock; holding | |
458 | * either sufficies for read. | |
459 | */ | |
460 | struct list_head group_entry; | |
04289bb9 | 461 | struct list_head sibling_list; |
9886167d PZ |
462 | |
463 | /* | |
464 | * We need storage to track the entries in perf_pmu_migrate_context; we | |
465 | * cannot use the event_entry because of RCU and we want to keep the | |
466 | * group in tact which avoids us using the other two entries. | |
467 | */ | |
468 | struct list_head migrate_entry; | |
469 | ||
f3ae75de SE |
470 | struct hlist_node hlist_entry; |
471 | struct list_head active_entry; | |
0127c3ea | 472 | int nr_siblings; |
d6f962b5 | 473 | int group_flags; |
cdd6c482 | 474 | struct perf_event *group_leader; |
a4eaf7f1 | 475 | struct pmu *pmu; |
54d751d4 | 476 | void *pmu_private; |
04289bb9 | 477 | |
cdd6c482 | 478 | enum perf_event_active_state state; |
8a49542c | 479 | unsigned int attach_state; |
e7850595 | 480 | local64_t count; |
a6e6dea6 | 481 | atomic64_t child_count; |
ee06094f | 482 | |
53cfbf59 | 483 | /* |
cdd6c482 | 484 | * These are the total time in nanoseconds that the event |
53cfbf59 | 485 | * has been enabled (i.e. eligible to run, and the task has |
cdd6c482 | 486 | * been scheduled in, if this is a per-task event) |
53cfbf59 PM |
487 | * and running (scheduled onto the CPU), respectively. |
488 | * | |
489 | * They are computed from tstamp_enabled, tstamp_running and | |
cdd6c482 | 490 | * tstamp_stopped when the event is in INACTIVE or ACTIVE state. |
53cfbf59 PM |
491 | */ |
492 | u64 total_time_enabled; | |
493 | u64 total_time_running; | |
494 | ||
495 | /* | |
496 | * These are timestamps used for computing total_time_enabled | |
cdd6c482 | 497 | * and total_time_running when the event is in INACTIVE or |
53cfbf59 PM |
498 | * ACTIVE state, measured in nanoseconds from an arbitrary point |
499 | * in time. | |
cdd6c482 IM |
500 | * tstamp_enabled: the notional time when the event was enabled |
501 | * tstamp_running: the notional time when the event was scheduled on | |
53cfbf59 | 502 | * tstamp_stopped: in INACTIVE state, the notional time when the |
cdd6c482 | 503 | * event was scheduled off. |
53cfbf59 PM |
504 | */ |
505 | u64 tstamp_enabled; | |
506 | u64 tstamp_running; | |
507 | u64 tstamp_stopped; | |
508 | ||
eed01528 SE |
509 | /* |
510 | * timestamp shadows the actual context timing but it can | |
511 | * be safely used in NMI interrupt context. It reflects the | |
512 | * context time as it was when the event was last scheduled in. | |
513 | * | |
514 | * ctx_time already accounts for ctx->timestamp. Therefore to | |
515 | * compute ctx_time for a sample, simply add perf_clock(). | |
516 | */ | |
517 | u64 shadow_ctx_time; | |
518 | ||
24f1e32c | 519 | struct perf_event_attr attr; |
c320c7b7 | 520 | u16 header_size; |
6844c09d | 521 | u16 id_header_size; |
c320c7b7 | 522 | u16 read_size; |
cdd6c482 | 523 | struct hw_perf_event hw; |
0793a61d | 524 | |
cdd6c482 | 525 | struct perf_event_context *ctx; |
a6fa941d | 526 | atomic_long_t refcount; |
0793a61d | 527 | |
53cfbf59 PM |
528 | /* |
529 | * These accumulate total time (in nanoseconds) that children | |
cdd6c482 | 530 | * events have been enabled and running, respectively. |
53cfbf59 PM |
531 | */ |
532 | atomic64_t child_total_time_enabled; | |
533 | atomic64_t child_total_time_running; | |
534 | ||
0793a61d | 535 | /* |
d859e29f | 536 | * Protect attach/detach and child_list: |
0793a61d | 537 | */ |
fccc714b PZ |
538 | struct mutex child_mutex; |
539 | struct list_head child_list; | |
cdd6c482 | 540 | struct perf_event *parent; |
0793a61d TG |
541 | |
542 | int oncpu; | |
543 | int cpu; | |
544 | ||
082ff5a2 PZ |
545 | struct list_head owner_entry; |
546 | struct task_struct *owner; | |
547 | ||
7b732a75 PZ |
548 | /* mmap bits */ |
549 | struct mutex mmap_mutex; | |
550 | atomic_t mmap_count; | |
26cb63ad | 551 | |
76369139 | 552 | struct ring_buffer *rb; |
10c6db11 | 553 | struct list_head rb_entry; |
b69cf536 PZ |
554 | unsigned long rcu_batches; |
555 | int rcu_pending; | |
37d81828 | 556 | |
7b732a75 | 557 | /* poll related */ |
0793a61d | 558 | wait_queue_head_t waitq; |
3c446b3d | 559 | struct fasync_struct *fasync; |
79f14641 PZ |
560 | |
561 | /* delayed work for NMIs and such */ | |
562 | int pending_wakeup; | |
4c9e2542 | 563 | int pending_kill; |
79f14641 | 564 | int pending_disable; |
e360adbe | 565 | struct irq_work pending; |
592903cd | 566 | |
79f14641 PZ |
567 | atomic_t event_limit; |
568 | ||
cdd6c482 | 569 | void (*destroy)(struct perf_event *); |
592903cd | 570 | struct rcu_head rcu_head; |
709e50cf PZ |
571 | |
572 | struct pid_namespace *ns; | |
8e5799b1 | 573 | u64 id; |
6fb2915d | 574 | |
34f43927 | 575 | u64 (*clock)(void); |
b326e956 | 576 | perf_overflow_handler_t overflow_handler; |
4dc0da86 | 577 | void *overflow_handler_context; |
453f19ee | 578 | |
07b139c8 | 579 | #ifdef CONFIG_EVENT_TRACING |
2425bcb9 | 580 | struct trace_event_call *tp_event; |
6fb2915d | 581 | struct event_filter *filter; |
ced39002 JO |
582 | #ifdef CONFIG_FUNCTION_TRACER |
583 | struct ftrace_ops ftrace_ops; | |
584 | #endif | |
ee06094f | 585 | #endif |
6fb2915d | 586 | |
e5d1367f SE |
587 | #ifdef CONFIG_CGROUP_PERF |
588 | struct perf_cgroup *cgrp; /* cgroup event is attach to */ | |
589 | int cgrp_defer_enabled; | |
590 | #endif | |
591 | ||
6fb2915d | 592 | #endif /* CONFIG_PERF_EVENTS */ |
0793a61d TG |
593 | }; |
594 | ||
595 | /** | |
cdd6c482 | 596 | * struct perf_event_context - event context structure |
0793a61d | 597 | * |
cdd6c482 | 598 | * Used as a container for task events and CPU events as well: |
0793a61d | 599 | */ |
cdd6c482 | 600 | struct perf_event_context { |
108b02cf | 601 | struct pmu *pmu; |
0793a61d | 602 | /* |
cdd6c482 | 603 | * Protect the states of the events in the list, |
d859e29f | 604 | * nr_active, and the list: |
0793a61d | 605 | */ |
e625cce1 | 606 | raw_spinlock_t lock; |
d859e29f | 607 | /* |
cdd6c482 | 608 | * Protect the list of events. Locking either mutex or lock |
d859e29f PM |
609 | * is sufficient to ensure the list doesn't change; to change |
610 | * the list you need to lock both the mutex and the spinlock. | |
611 | */ | |
a308444c | 612 | struct mutex mutex; |
04289bb9 | 613 | |
2fde4f94 | 614 | struct list_head active_ctx_list; |
889ff015 FW |
615 | struct list_head pinned_groups; |
616 | struct list_head flexible_groups; | |
a308444c | 617 | struct list_head event_list; |
cdd6c482 | 618 | int nr_events; |
a308444c IM |
619 | int nr_active; |
620 | int is_active; | |
bfbd3381 | 621 | int nr_stat; |
0f5a2601 | 622 | int nr_freq; |
dddd3379 | 623 | int rotate_disable; |
a308444c IM |
624 | atomic_t refcount; |
625 | struct task_struct *task; | |
53cfbf59 PM |
626 | |
627 | /* | |
4af4998b | 628 | * Context clock, runs when context enabled. |
53cfbf59 | 629 | */ |
a308444c IM |
630 | u64 time; |
631 | u64 timestamp; | |
564c2b21 PM |
632 | |
633 | /* | |
634 | * These fields let us detect when two contexts have both | |
635 | * been cloned (inherited) from a common ancestor. | |
636 | */ | |
cdd6c482 | 637 | struct perf_event_context *parent_ctx; |
a308444c IM |
638 | u64 parent_gen; |
639 | u64 generation; | |
640 | int pin_count; | |
d010b332 | 641 | int nr_cgroups; /* cgroup evts */ |
4af57ef2 | 642 | void *task_ctx_data; /* pmu specific data */ |
28009ce4 | 643 | struct rcu_head rcu_head; |
0793a61d TG |
644 | }; |
645 | ||
7ae07ea3 FW |
646 | /* |
647 | * Number of contexts where an event can trigger: | |
e7e7ee2e | 648 | * task, softirq, hardirq, nmi. |
7ae07ea3 FW |
649 | */ |
650 | #define PERF_NR_CONTEXTS 4 | |
651 | ||
0793a61d | 652 | /** |
cdd6c482 | 653 | * struct perf_event_cpu_context - per cpu event context structure |
0793a61d TG |
654 | */ |
655 | struct perf_cpu_context { | |
cdd6c482 IM |
656 | struct perf_event_context ctx; |
657 | struct perf_event_context *task_ctx; | |
0793a61d | 658 | int active_oncpu; |
3b6f9e5c | 659 | int exclusive; |
4cfafd30 PZ |
660 | |
661 | raw_spinlock_t hrtimer_lock; | |
9e630205 SE |
662 | struct hrtimer hrtimer; |
663 | ktime_t hrtimer_interval; | |
4cfafd30 PZ |
664 | unsigned int hrtimer_active; |
665 | ||
3f1f3320 | 666 | struct pmu *unique_pmu; |
e5d1367f | 667 | struct perf_cgroup *cgrp; |
0793a61d TG |
668 | }; |
669 | ||
5622f295 | 670 | struct perf_output_handle { |
57c0c15b | 671 | struct perf_event *event; |
76369139 | 672 | struct ring_buffer *rb; |
6d1acfd5 | 673 | unsigned long wakeup; |
5d967a8b | 674 | unsigned long size; |
fdc26706 AS |
675 | union { |
676 | void *addr; | |
677 | unsigned long head; | |
678 | }; | |
5d967a8b | 679 | int page; |
5622f295 MM |
680 | }; |
681 | ||
39bed6cb MF |
682 | #ifdef CONFIG_CGROUP_PERF |
683 | ||
684 | /* | |
685 | * perf_cgroup_info keeps track of time_enabled for a cgroup. | |
686 | * This is a per-cpu dynamically allocated data structure. | |
687 | */ | |
688 | struct perf_cgroup_info { | |
689 | u64 time; | |
690 | u64 timestamp; | |
691 | }; | |
692 | ||
693 | struct perf_cgroup { | |
694 | struct cgroup_subsys_state css; | |
695 | struct perf_cgroup_info __percpu *info; | |
696 | }; | |
697 | ||
698 | /* | |
699 | * Must ensure cgroup is pinned (css_get) before calling | |
700 | * this function. In other words, we cannot call this function | |
701 | * if there is no cgroup event for the current CPU context. | |
702 | */ | |
703 | static inline struct perf_cgroup * | |
614e4c4e | 704 | perf_cgroup_from_task(struct task_struct *task, struct perf_event_context *ctx) |
39bed6cb | 705 | { |
614e4c4e SE |
706 | return container_of(task_css_check(task, perf_event_cgrp_id, |
707 | ctx ? lockdep_is_held(&ctx->lock) | |
708 | : true), | |
39bed6cb MF |
709 | struct perf_cgroup, css); |
710 | } | |
711 | #endif /* CONFIG_CGROUP_PERF */ | |
712 | ||
cdd6c482 | 713 | #ifdef CONFIG_PERF_EVENTS |
829b42dd | 714 | |
fdc26706 AS |
715 | extern void *perf_aux_output_begin(struct perf_output_handle *handle, |
716 | struct perf_event *event); | |
717 | extern void perf_aux_output_end(struct perf_output_handle *handle, | |
718 | unsigned long size, bool truncated); | |
719 | extern int perf_aux_output_skip(struct perf_output_handle *handle, | |
720 | unsigned long size); | |
721 | extern void *perf_get_aux(struct perf_output_handle *handle); | |
722 | ||
03d8e80b | 723 | extern int perf_pmu_register(struct pmu *pmu, const char *name, int type); |
b0a873eb | 724 | extern void perf_pmu_unregister(struct pmu *pmu); |
621a01ea | 725 | |
3bf101ba | 726 | extern int perf_num_counters(void); |
84c79910 | 727 | extern const char *perf_pmu_name(void); |
ab0cce56 JO |
728 | extern void __perf_event_task_sched_in(struct task_struct *prev, |
729 | struct task_struct *task); | |
730 | extern void __perf_event_task_sched_out(struct task_struct *prev, | |
731 | struct task_struct *next); | |
cdd6c482 IM |
732 | extern int perf_event_init_task(struct task_struct *child); |
733 | extern void perf_event_exit_task(struct task_struct *child); | |
734 | extern void perf_event_free_task(struct task_struct *task); | |
4e231c79 | 735 | extern void perf_event_delayed_put(struct task_struct *task); |
e03e7ee3 | 736 | extern struct file *perf_event_get(unsigned int fd); |
ffe8690c | 737 | extern const struct perf_event_attr *perf_event_attrs(struct perf_event *event); |
cdd6c482 | 738 | extern void perf_event_print_debug(void); |
33696fc0 PZ |
739 | extern void perf_pmu_disable(struct pmu *pmu); |
740 | extern void perf_pmu_enable(struct pmu *pmu); | |
ba532500 YZ |
741 | extern void perf_sched_cb_dec(struct pmu *pmu); |
742 | extern void perf_sched_cb_inc(struct pmu *pmu); | |
cdd6c482 IM |
743 | extern int perf_event_task_disable(void); |
744 | extern int perf_event_task_enable(void); | |
26ca5c11 | 745 | extern int perf_event_refresh(struct perf_event *event, int refresh); |
cdd6c482 | 746 | extern void perf_event_update_userpage(struct perf_event *event); |
fb0459d7 AV |
747 | extern int perf_event_release_kernel(struct perf_event *event); |
748 | extern struct perf_event * | |
749 | perf_event_create_kernel_counter(struct perf_event_attr *attr, | |
750 | int cpu, | |
38a81da2 | 751 | struct task_struct *task, |
4dc0da86 AK |
752 | perf_overflow_handler_t callback, |
753 | void *context); | |
0cda4c02 YZ |
754 | extern void perf_pmu_migrate_context(struct pmu *pmu, |
755 | int src_cpu, int dst_cpu); | |
ffe8690c | 756 | extern u64 perf_event_read_local(struct perf_event *event); |
59ed446f PZ |
757 | extern u64 perf_event_read_value(struct perf_event *event, |
758 | u64 *enabled, u64 *running); | |
5c92d124 | 759 | |
d010b332 | 760 | |
df1a132b | 761 | struct perf_sample_data { |
2565711f PZ |
762 | /* |
763 | * Fields set by perf_sample_data_init(), group so as to | |
764 | * minimize the cachelines touched. | |
765 | */ | |
766 | u64 addr; | |
767 | struct perf_raw_record *raw; | |
768 | struct perf_branch_stack *br_stack; | |
769 | u64 period; | |
770 | u64 weight; | |
771 | u64 txn; | |
772 | union perf_mem_data_src data_src; | |
5622f295 | 773 | |
2565711f PZ |
774 | /* |
775 | * The other fields, optionally {set,used} by | |
776 | * perf_{prepare,output}_sample(). | |
777 | */ | |
778 | u64 type; | |
5622f295 MM |
779 | u64 ip; |
780 | struct { | |
781 | u32 pid; | |
782 | u32 tid; | |
783 | } tid_entry; | |
784 | u64 time; | |
5622f295 MM |
785 | u64 id; |
786 | u64 stream_id; | |
787 | struct { | |
788 | u32 cpu; | |
789 | u32 reserved; | |
790 | } cpu_entry; | |
5622f295 | 791 | struct perf_callchain_entry *callchain; |
88a7c26a AL |
792 | |
793 | /* | |
794 | * regs_user may point to task_pt_regs or to regs_user_copy, depending | |
795 | * on arch details. | |
796 | */ | |
60e2364e | 797 | struct perf_regs regs_user; |
88a7c26a AL |
798 | struct pt_regs regs_user_copy; |
799 | ||
60e2364e | 800 | struct perf_regs regs_intr; |
c5ebcedb | 801 | u64 stack_user_size; |
2565711f | 802 | } ____cacheline_aligned; |
df1a132b | 803 | |
770eee1f SE |
804 | /* default value for data source */ |
805 | #define PERF_MEM_NA (PERF_MEM_S(OP, NA) |\ | |
806 | PERF_MEM_S(LVL, NA) |\ | |
807 | PERF_MEM_S(SNOOP, NA) |\ | |
808 | PERF_MEM_S(LOCK, NA) |\ | |
809 | PERF_MEM_S(TLB, NA)) | |
810 | ||
fd0d000b RR |
811 | static inline void perf_sample_data_init(struct perf_sample_data *data, |
812 | u64 addr, u64 period) | |
dc1d628a | 813 | { |
fd0d000b | 814 | /* remaining struct members initialized in perf_prepare_sample() */ |
dc1d628a PZ |
815 | data->addr = addr; |
816 | data->raw = NULL; | |
bce38cd5 | 817 | data->br_stack = NULL; |
4018994f | 818 | data->period = period; |
c3feedf2 | 819 | data->weight = 0; |
770eee1f | 820 | data->data_src.val = PERF_MEM_NA; |
fdfbbd07 | 821 | data->txn = 0; |
dc1d628a PZ |
822 | } |
823 | ||
5622f295 MM |
824 | extern void perf_output_sample(struct perf_output_handle *handle, |
825 | struct perf_event_header *header, | |
826 | struct perf_sample_data *data, | |
cdd6c482 | 827 | struct perf_event *event); |
5622f295 MM |
828 | extern void perf_prepare_sample(struct perf_event_header *header, |
829 | struct perf_sample_data *data, | |
cdd6c482 | 830 | struct perf_event *event, |
5622f295 MM |
831 | struct pt_regs *regs); |
832 | ||
a8b0ca17 | 833 | extern int perf_event_overflow(struct perf_event *event, |
5622f295 MM |
834 | struct perf_sample_data *data, |
835 | struct pt_regs *regs); | |
df1a132b | 836 | |
21509084 YZ |
837 | extern void perf_event_output(struct perf_event *event, |
838 | struct perf_sample_data *data, | |
839 | struct pt_regs *regs); | |
840 | ||
841 | extern void | |
842 | perf_event_header__init_id(struct perf_event_header *header, | |
843 | struct perf_sample_data *data, | |
844 | struct perf_event *event); | |
845 | extern void | |
846 | perf_event__output_id_sample(struct perf_event *event, | |
847 | struct perf_output_handle *handle, | |
848 | struct perf_sample_data *sample); | |
849 | ||
f38b0dbb KL |
850 | extern void |
851 | perf_log_lost_samples(struct perf_event *event, u64 lost); | |
852 | ||
6c7e550f FBH |
853 | static inline bool is_sampling_event(struct perf_event *event) |
854 | { | |
855 | return event->attr.sample_period != 0; | |
856 | } | |
857 | ||
3b6f9e5c | 858 | /* |
cdd6c482 | 859 | * Return 1 for a software event, 0 for a hardware event |
3b6f9e5c | 860 | */ |
cdd6c482 | 861 | static inline int is_software_event(struct perf_event *event) |
3b6f9e5c | 862 | { |
89a1e187 | 863 | return event->pmu->task_ctx_nr == perf_sw_context; |
3b6f9e5c PM |
864 | } |
865 | ||
c5905afb | 866 | extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX]; |
f29ac756 | 867 | |
86038c5e | 868 | extern void ___perf_sw_event(u32, u64, struct pt_regs *, u64); |
a8b0ca17 | 869 | extern void __perf_sw_event(u32, u64, struct pt_regs *, u64); |
f29ac756 | 870 | |
b0f82b81 | 871 | #ifndef perf_arch_fetch_caller_regs |
e7e7ee2e | 872 | static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { } |
b0f82b81 | 873 | #endif |
5331d7b8 FW |
874 | |
875 | /* | |
876 | * Take a snapshot of the regs. Skip ip and frame pointer to | |
877 | * the nth caller. We only need a few of the regs: | |
878 | * - ip for PERF_SAMPLE_IP | |
879 | * - cs for user_mode() tests | |
880 | * - bp for callchains | |
881 | * - eflags, for future purposes, just in case | |
882 | */ | |
b0f82b81 | 883 | static inline void perf_fetch_caller_regs(struct pt_regs *regs) |
5331d7b8 | 884 | { |
5331d7b8 FW |
885 | memset(regs, 0, sizeof(*regs)); |
886 | ||
b0f82b81 | 887 | perf_arch_fetch_caller_regs(regs, CALLER_ADDR0); |
5331d7b8 FW |
888 | } |
889 | ||
7e54a5a0 | 890 | static __always_inline void |
a8b0ca17 | 891 | perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) |
e49a5bd3 | 892 | { |
86038c5e PZI |
893 | if (static_key_false(&perf_swevent_enabled[event_id])) |
894 | __perf_sw_event(event_id, nr, regs, addr); | |
895 | } | |
896 | ||
897 | DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]); | |
7e54a5a0 | 898 | |
86038c5e PZI |
899 | /* |
900 | * 'Special' version for the scheduler, it hard assumes no recursion, | |
901 | * which is guaranteed by us not actually scheduling inside other swevents | |
902 | * because those disable preemption. | |
903 | */ | |
904 | static __always_inline void | |
905 | perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) | |
906 | { | |
c5905afb | 907 | if (static_key_false(&perf_swevent_enabled[event_id])) { |
86038c5e PZI |
908 | struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]); |
909 | ||
910 | perf_fetch_caller_regs(regs); | |
911 | ___perf_sw_event(event_id, nr, regs, addr); | |
e49a5bd3 FW |
912 | } |
913 | } | |
914 | ||
9107c89e | 915 | extern struct static_key_false perf_sched_events; |
ee6dcfa4 | 916 | |
ff303e66 PZ |
917 | static __always_inline bool |
918 | perf_sw_migrate_enabled(void) | |
919 | { | |
920 | if (static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_CPU_MIGRATIONS])) | |
921 | return true; | |
922 | return false; | |
923 | } | |
924 | ||
925 | static inline void perf_event_task_migrate(struct task_struct *task) | |
926 | { | |
927 | if (perf_sw_migrate_enabled()) | |
928 | task->sched_migrated = 1; | |
929 | } | |
930 | ||
ab0cce56 | 931 | static inline void perf_event_task_sched_in(struct task_struct *prev, |
a8d757ef | 932 | struct task_struct *task) |
ab0cce56 | 933 | { |
9107c89e | 934 | if (static_branch_unlikely(&perf_sched_events)) |
ab0cce56 | 935 | __perf_event_task_sched_in(prev, task); |
ff303e66 PZ |
936 | |
937 | if (perf_sw_migrate_enabled() && task->sched_migrated) { | |
938 | struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]); | |
939 | ||
940 | perf_fetch_caller_regs(regs); | |
941 | ___perf_sw_event(PERF_COUNT_SW_CPU_MIGRATIONS, 1, regs, 0); | |
942 | task->sched_migrated = 0; | |
943 | } | |
ab0cce56 JO |
944 | } |
945 | ||
946 | static inline void perf_event_task_sched_out(struct task_struct *prev, | |
947 | struct task_struct *next) | |
ee6dcfa4 | 948 | { |
86038c5e | 949 | perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0); |
ee6dcfa4 | 950 | |
9107c89e | 951 | if (static_branch_unlikely(&perf_sched_events)) |
ab0cce56 | 952 | __perf_event_task_sched_out(prev, next); |
ee6dcfa4 PZ |
953 | } |
954 | ||
eacd3ecc MF |
955 | static inline u64 __perf_event_count(struct perf_event *event) |
956 | { | |
957 | return local64_read(&event->count) + atomic64_read(&event->child_count); | |
958 | } | |
959 | ||
3af9e859 | 960 | extern void perf_event_mmap(struct vm_area_struct *vma); |
39447b38 | 961 | extern struct perf_guest_info_callbacks *perf_guest_cbs; |
dcf46b94 ZY |
962 | extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); |
963 | extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); | |
39447b38 | 964 | |
e041e328 | 965 | extern void perf_event_exec(void); |
82b89778 | 966 | extern void perf_event_comm(struct task_struct *tsk, bool exec); |
cdd6c482 | 967 | extern void perf_event_fork(struct task_struct *tsk); |
8d1b2d93 | 968 | |
56962b44 FW |
969 | /* Callchains */ |
970 | DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry); | |
971 | ||
e7e7ee2e IM |
972 | extern void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs); |
973 | extern void perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs); | |
568b329a AS |
974 | extern struct perf_callchain_entry * |
975 | get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, | |
976 | bool crosstask, bool add_mark); | |
977 | extern int get_callchain_buffers(void); | |
978 | extern void put_callchain_buffers(void); | |
394ee076 | 979 | |
568b329a | 980 | static inline int perf_callchain_store(struct perf_callchain_entry *entry, u64 ip) |
70791ce9 | 981 | { |
568b329a | 982 | if (entry->nr < PERF_MAX_STACK_DEPTH) { |
70791ce9 | 983 | entry->ip[entry->nr++] = ip; |
568b329a AS |
984 | return 0; |
985 | } else { | |
986 | return -1; /* no more room, stop walking the stack */ | |
987 | } | |
70791ce9 | 988 | } |
394ee076 | 989 | |
cdd6c482 IM |
990 | extern int sysctl_perf_event_paranoid; |
991 | extern int sysctl_perf_event_mlock; | |
992 | extern int sysctl_perf_event_sample_rate; | |
14c63f17 DH |
993 | extern int sysctl_perf_cpu_time_max_percent; |
994 | ||
995 | extern void perf_sample_event_took(u64 sample_len_ns); | |
1ccd1549 | 996 | |
163ec435 PZ |
997 | extern int perf_proc_update_handler(struct ctl_table *table, int write, |
998 | void __user *buffer, size_t *lenp, | |
999 | loff_t *ppos); | |
14c63f17 DH |
1000 | extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write, |
1001 | void __user *buffer, size_t *lenp, | |
1002 | loff_t *ppos); | |
1003 | ||
163ec435 | 1004 | |
320ebf09 PZ |
1005 | static inline bool perf_paranoid_tracepoint_raw(void) |
1006 | { | |
1007 | return sysctl_perf_event_paranoid > -1; | |
1008 | } | |
1009 | ||
1010 | static inline bool perf_paranoid_cpu(void) | |
1011 | { | |
1012 | return sysctl_perf_event_paranoid > 0; | |
1013 | } | |
1014 | ||
1015 | static inline bool perf_paranoid_kernel(void) | |
1016 | { | |
1017 | return sysctl_perf_event_paranoid > 1; | |
1018 | } | |
1019 | ||
cdd6c482 | 1020 | extern void perf_event_init(void); |
1c024eca PZ |
1021 | extern void perf_tp_event(u64 addr, u64 count, void *record, |
1022 | int entry_size, struct pt_regs *regs, | |
e6dab5ff AV |
1023 | struct hlist_head *head, int rctx, |
1024 | struct task_struct *task); | |
24f1e32c | 1025 | extern void perf_bp_event(struct perf_event *event, void *data); |
0d905bca | 1026 | |
9d23a90a | 1027 | #ifndef perf_misc_flags |
e7e7ee2e IM |
1028 | # define perf_misc_flags(regs) \ |
1029 | (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) | |
1030 | # define perf_instruction_pointer(regs) instruction_pointer(regs) | |
9d23a90a PM |
1031 | #endif |
1032 | ||
bce38cd5 SE |
1033 | static inline bool has_branch_stack(struct perf_event *event) |
1034 | { | |
1035 | return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; | |
a46a2300 YZ |
1036 | } |
1037 | ||
1038 | static inline bool needs_branch_stack(struct perf_event *event) | |
1039 | { | |
1040 | return event->attr.branch_sample_type != 0; | |
bce38cd5 SE |
1041 | } |
1042 | ||
45bfb2e5 PZ |
1043 | static inline bool has_aux(struct perf_event *event) |
1044 | { | |
1045 | return event->pmu->setup_aux; | |
1046 | } | |
1047 | ||
5622f295 | 1048 | extern int perf_output_begin(struct perf_output_handle *handle, |
a7ac67ea | 1049 | struct perf_event *event, unsigned int size); |
5622f295 | 1050 | extern void perf_output_end(struct perf_output_handle *handle); |
91d7753a | 1051 | extern unsigned int perf_output_copy(struct perf_output_handle *handle, |
5622f295 | 1052 | const void *buf, unsigned int len); |
5685e0ff JO |
1053 | extern unsigned int perf_output_skip(struct perf_output_handle *handle, |
1054 | unsigned int len); | |
4ed7c92d PZ |
1055 | extern int perf_swevent_get_recursion_context(void); |
1056 | extern void perf_swevent_put_recursion_context(int rctx); | |
ab573844 | 1057 | extern u64 perf_swevent_set_period(struct perf_event *event); |
44234adc FW |
1058 | extern void perf_event_enable(struct perf_event *event); |
1059 | extern void perf_event_disable(struct perf_event *event); | |
fae3fde6 | 1060 | extern void perf_event_disable_local(struct perf_event *event); |
e9d2b064 | 1061 | extern void perf_event_task_tick(void); |
e041e328 | 1062 | #else /* !CONFIG_PERF_EVENTS: */ |
fdc26706 AS |
1063 | static inline void * |
1064 | perf_aux_output_begin(struct perf_output_handle *handle, | |
1065 | struct perf_event *event) { return NULL; } | |
1066 | static inline void | |
1067 | perf_aux_output_end(struct perf_output_handle *handle, unsigned long size, | |
1068 | bool truncated) { } | |
1069 | static inline int | |
1070 | perf_aux_output_skip(struct perf_output_handle *handle, | |
1071 | unsigned long size) { return -EINVAL; } | |
1072 | static inline void * | |
1073 | perf_get_aux(struct perf_output_handle *handle) { return NULL; } | |
0793a61d | 1074 | static inline void |
ff303e66 PZ |
1075 | perf_event_task_migrate(struct task_struct *task) { } |
1076 | static inline void | |
ab0cce56 JO |
1077 | perf_event_task_sched_in(struct task_struct *prev, |
1078 | struct task_struct *task) { } | |
1079 | static inline void | |
1080 | perf_event_task_sched_out(struct task_struct *prev, | |
1081 | struct task_struct *next) { } | |
cdd6c482 IM |
1082 | static inline int perf_event_init_task(struct task_struct *child) { return 0; } |
1083 | static inline void perf_event_exit_task(struct task_struct *child) { } | |
1084 | static inline void perf_event_free_task(struct task_struct *task) { } | |
4e231c79 | 1085 | static inline void perf_event_delayed_put(struct task_struct *task) { } |
e03e7ee3 | 1086 | static inline struct file *perf_event_get(unsigned int fd) { return ERR_PTR(-EINVAL); } |
ffe8690c KX |
1087 | static inline const struct perf_event_attr *perf_event_attrs(struct perf_event *event) |
1088 | { | |
1089 | return ERR_PTR(-EINVAL); | |
1090 | } | |
1091 | static inline u64 perf_event_read_local(struct perf_event *event) { return -EINVAL; } | |
57c0c15b | 1092 | static inline void perf_event_print_debug(void) { } |
57c0c15b IM |
1093 | static inline int perf_event_task_disable(void) { return -EINVAL; } |
1094 | static inline int perf_event_task_enable(void) { return -EINVAL; } | |
26ca5c11 AK |
1095 | static inline int perf_event_refresh(struct perf_event *event, int refresh) |
1096 | { | |
1097 | return -EINVAL; | |
1098 | } | |
15dbf27c | 1099 | |
925d519a | 1100 | static inline void |
a8b0ca17 | 1101 | perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { } |
24f1e32c | 1102 | static inline void |
86038c5e PZI |
1103 | perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) { } |
1104 | static inline void | |
184f412c | 1105 | perf_bp_event(struct perf_event *event, void *data) { } |
0a4a9391 | 1106 | |
39447b38 | 1107 | static inline int perf_register_guest_info_callbacks |
e7e7ee2e | 1108 | (struct perf_guest_info_callbacks *callbacks) { return 0; } |
39447b38 | 1109 | static inline int perf_unregister_guest_info_callbacks |
e7e7ee2e | 1110 | (struct perf_guest_info_callbacks *callbacks) { return 0; } |
39447b38 | 1111 | |
57c0c15b | 1112 | static inline void perf_event_mmap(struct vm_area_struct *vma) { } |
e041e328 | 1113 | static inline void perf_event_exec(void) { } |
82b89778 | 1114 | static inline void perf_event_comm(struct task_struct *tsk, bool exec) { } |
cdd6c482 IM |
1115 | static inline void perf_event_fork(struct task_struct *tsk) { } |
1116 | static inline void perf_event_init(void) { } | |
184f412c | 1117 | static inline int perf_swevent_get_recursion_context(void) { return -1; } |
4ed7c92d | 1118 | static inline void perf_swevent_put_recursion_context(int rctx) { } |
ab573844 | 1119 | static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; } |
44234adc FW |
1120 | static inline void perf_event_enable(struct perf_event *event) { } |
1121 | static inline void perf_event_disable(struct perf_event *event) { } | |
500ad2d8 | 1122 | static inline int __perf_event_disable(void *info) { return -1; } |
e9d2b064 | 1123 | static inline void perf_event_task_tick(void) { } |
ffe8690c | 1124 | static inline int perf_event_release_kernel(struct perf_event *event) { return 0; } |
0793a61d TG |
1125 | #endif |
1126 | ||
6c4d3bc9 DR |
1127 | #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL) |
1128 | extern void perf_restore_debug_store(void); | |
1129 | #else | |
1d9d8639 | 1130 | static inline void perf_restore_debug_store(void) { } |
0793a61d TG |
1131 | #endif |
1132 | ||
e7e7ee2e | 1133 | #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x)) |
5622f295 | 1134 | |
3f6da390 | 1135 | /* |
0a0fca9d | 1136 | * This has to have a higher priority than migration_notifier in sched/core.c. |
3f6da390 | 1137 | */ |
e7e7ee2e IM |
1138 | #define perf_cpu_notifier(fn) \ |
1139 | do { \ | |
0db0628d | 1140 | static struct notifier_block fn##_nb = \ |
e7e7ee2e | 1141 | { .notifier_call = fn, .priority = CPU_PRI_PERF }; \ |
c13d38e4 | 1142 | unsigned long cpu = smp_processor_id(); \ |
6760bca9 | 1143 | unsigned long flags; \ |
f0bdb5e0 SB |
1144 | \ |
1145 | cpu_notifier_register_begin(); \ | |
e7e7ee2e | 1146 | fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE, \ |
c13d38e4 | 1147 | (void *)(unsigned long)cpu); \ |
6760bca9 | 1148 | local_irq_save(flags); \ |
e7e7ee2e | 1149 | fn(&fn##_nb, (unsigned long)CPU_STARTING, \ |
c13d38e4 | 1150 | (void *)(unsigned long)cpu); \ |
6760bca9 | 1151 | local_irq_restore(flags); \ |
e7e7ee2e | 1152 | fn(&fn##_nb, (unsigned long)CPU_ONLINE, \ |
c13d38e4 | 1153 | (void *)(unsigned long)cpu); \ |
f0bdb5e0 SB |
1154 | __register_cpu_notifier(&fn##_nb); \ |
1155 | cpu_notifier_register_done(); \ | |
3f6da390 PZ |
1156 | } while (0) |
1157 | ||
f0bdb5e0 SB |
1158 | /* |
1159 | * Bare-bones version of perf_cpu_notifier(), which doesn't invoke the | |
1160 | * callback for already online CPUs. | |
1161 | */ | |
1162 | #define __perf_cpu_notifier(fn) \ | |
1163 | do { \ | |
1164 | static struct notifier_block fn##_nb = \ | |
1165 | { .notifier_call = fn, .priority = CPU_PRI_PERF }; \ | |
1166 | \ | |
1167 | __register_cpu_notifier(&fn##_nb); \ | |
1168 | } while (0) | |
641cc938 | 1169 | |
2663960c SB |
1170 | struct perf_pmu_events_attr { |
1171 | struct device_attribute attr; | |
1172 | u64 id; | |
3a54aaa0 | 1173 | const char *event_str; |
2663960c SB |
1174 | }; |
1175 | ||
fd979c01 CS |
1176 | ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr, |
1177 | char *page); | |
1178 | ||
2663960c SB |
1179 | #define PMU_EVENT_ATTR(_name, _var, _id, _show) \ |
1180 | static struct perf_pmu_events_attr _var = { \ | |
1181 | .attr = __ATTR(_name, 0444, _show, NULL), \ | |
1182 | .id = _id, \ | |
1183 | }; | |
1184 | ||
f0405b81 CS |
1185 | #define PMU_EVENT_ATTR_STRING(_name, _var, _str) \ |
1186 | static struct perf_pmu_events_attr _var = { \ | |
1187 | .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \ | |
1188 | .id = 0, \ | |
1189 | .event_str = _str, \ | |
1190 | }; | |
1191 | ||
641cc938 JO |
1192 | #define PMU_FORMAT_ATTR(_name, _format) \ |
1193 | static ssize_t \ | |
1194 | _name##_show(struct device *dev, \ | |
1195 | struct device_attribute *attr, \ | |
1196 | char *page) \ | |
1197 | { \ | |
1198 | BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ | |
1199 | return sprintf(page, _format "\n"); \ | |
1200 | } \ | |
1201 | \ | |
1202 | static struct device_attribute format_attr_##_name = __ATTR_RO(_name) | |
1203 | ||
cdd6c482 | 1204 | #endif /* _LINUX_PERF_EVENT_H */ |