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