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