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