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