4 * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
5 * Copyright (C) 2008-2011, Red Hat, Inc., Ingo Molnar
6 * Copyright (C) 2008-2011, Red Hat, Inc., Peter Zijlstra
8 * Data type definitions, declarations, prototypes.
10 * Started by: Thomas Gleixner and Ingo Molnar
12 * For licencing details see kernel-base/COPYING
14 #ifndef _LINUX_PERF_EVENT_H
15 #define _LINUX_PERF_EVENT_H
17 #include <uapi/linux/perf_event.h>
20 * Kernel-internal data types and definitions:
23 #ifdef CONFIG_PERF_EVENTS
24 # include <asm/perf_event.h>
25 # include <asm/local64.h>
28 struct perf_guest_info_callbacks {
29 int (*is_in_guest)(void);
30 int (*is_user_mode)(void);
31 unsigned long (*get_guest_ip)(void);
34 #ifdef CONFIG_HAVE_HW_BREAKPOINT
35 #include <asm/hw_breakpoint.h>
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>
43 #include <linux/hrtimer.h>
45 #include <linux/pid_namespace.h>
46 #include <linux/workqueue.h>
47 #include <linux/ftrace.h>
48 #include <linux/cpu.h>
49 #include <linux/irq_work.h>
50 #include <linux/static_key.h>
51 #include <linux/jump_label_ratelimit.h>
52 #include <linux/atomic.h>
53 #include <linux/sysfs.h>
54 #include <linux/perf_regs.h>
55 #include <linux/workqueue.h>
56 #include <linux/cgroup.h>
57 #include <asm/local.h>
59 struct perf_callchain_entry {
61 __u64 ip[PERF_MAX_STACK_DEPTH];
64 struct perf_raw_record {
70 * branch stack layout:
71 * nr: number of taken branches stored in entries[]
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
78 struct perf_branch_stack {
80 struct perf_branch_entry entries[0];
86 * extra PMU register associated with an event
88 struct hw_perf_event_extra {
89 u64 config; /* register value */
90 unsigned int reg; /* register address or index */
91 int alloc; /* extra register already allocated */
92 int idx; /* index in shared_regs->regs[] */
96 * struct hw_perf_event - performance event hardware details:
98 struct hw_perf_event {
99 #ifdef CONFIG_PERF_EVENTS
101 struct { /* hardware */
104 unsigned long config_base;
105 unsigned long event_base;
106 int event_base_rdpmc;
111 struct hw_perf_event_extra extra_reg;
112 struct hw_perf_event_extra branch_reg;
114 struct { /* software */
115 struct hrtimer hrtimer;
117 struct { /* tracepoint */
118 /* for tp_event->class */
119 struct list_head tp_list;
121 struct { /* intel_cqm */
124 struct list_head cqm_events_entry;
125 struct list_head cqm_groups_entry;
126 struct list_head cqm_group_entry;
128 struct { /* itrace */
131 #ifdef CONFIG_HAVE_HW_BREAKPOINT
132 struct { /* breakpoint */
134 * Crufty hack to avoid the chicken and egg
135 * problem hw_breakpoint has with context
136 * creation and event initalization.
138 struct arch_hw_breakpoint info;
139 struct list_head bp_list;
143 struct task_struct *target;
145 local64_t prev_count;
148 local64_t period_left;
153 u64 freq_count_stamp;
158 * hw_perf_event::state flags
160 #define PERF_HES_STOPPED 0x01 /* the counter is stopped */
161 #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
162 #define PERF_HES_ARCH 0x04
167 * Common implementation detail of pmu::{start,commit,cancel}_txn
169 #define PERF_EVENT_TXN 0x1
172 * pmu::capabilities flags
174 #define PERF_PMU_CAP_NO_INTERRUPT 0x01
175 #define PERF_PMU_CAP_NO_NMI 0x02
176 #define PERF_PMU_CAP_AUX_NO_SG 0x04
177 #define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08
178 #define PERF_PMU_CAP_EXCLUSIVE 0x10
179 #define PERF_PMU_CAP_ITRACE 0x20
182 * struct pmu - generic performance monitoring unit
185 struct list_head entry;
187 struct module *module;
189 const struct attribute_group **attr_groups;
194 * various common per-pmu feature flags
198 int * __percpu pmu_disable_count;
199 struct perf_cpu_context * __percpu pmu_cpu_context;
200 atomic_t exclusive_cnt; /* < 0: cpu; > 0: tsk */
202 int hrtimer_interval_ms;
205 * Fully disable/enable this PMU, can be used to protect from the PMI
206 * as well as for lazy/batch writing of the MSRs.
208 void (*pmu_enable) (struct pmu *pmu); /* optional */
209 void (*pmu_disable) (struct pmu *pmu); /* optional */
212 * Try and initialize the event for this PMU.
213 * Should return -ENOENT when the @event doesn't match this PMU.
215 int (*event_init) (struct perf_event *event);
218 * Notification that the event was mapped or unmapped. Called
219 * in the context of the mapping task.
221 void (*event_mapped) (struct perf_event *event); /*optional*/
222 void (*event_unmapped) (struct perf_event *event); /*optional*/
224 #define PERF_EF_START 0x01 /* start the counter when adding */
225 #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
226 #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
229 * Adds/Removes a counter to/from the PMU, can be done inside
230 * a transaction, see the ->*_txn() methods.
232 int (*add) (struct perf_event *event, int flags);
233 void (*del) (struct perf_event *event, int flags);
236 * Starts/Stops a counter present on the PMU. The PMI handler
237 * should stop the counter when perf_event_overflow() returns
238 * !0. ->start() will be used to continue.
240 void (*start) (struct perf_event *event, int flags);
241 void (*stop) (struct perf_event *event, int flags);
244 * Updates the counter value of the event.
246 void (*read) (struct perf_event *event);
249 * Group events scheduling is treated as a transaction, add
250 * group events as a whole and perform one schedulability test.
251 * If the test fails, roll back the whole group
253 * Start the transaction, after this ->add() doesn't need to
254 * do schedulability tests.
256 void (*start_txn) (struct pmu *pmu); /* optional */
258 * If ->start_txn() disabled the ->add() schedulability test
259 * then ->commit_txn() is required to perform one. On success
260 * the transaction is closed. On error the transaction is kept
261 * open until ->cancel_txn() is called.
263 int (*commit_txn) (struct pmu *pmu); /* optional */
265 * Will cancel the transaction, assumes ->del() is called
266 * for each successful ->add() during the transaction.
268 void (*cancel_txn) (struct pmu *pmu); /* optional */
271 * Will return the value for perf_event_mmap_page::index for this event,
272 * if no implementation is provided it will default to: event->hw.idx + 1.
274 int (*event_idx) (struct perf_event *event); /*optional */
277 * context-switches callback
279 void (*sched_task) (struct perf_event_context *ctx,
282 * PMU specific data size
284 size_t task_ctx_size;
288 * Return the count value for a counter.
290 u64 (*count) (struct perf_event *event); /*optional*/
293 * Set up pmu-private data structures for an AUX area
295 void *(*setup_aux) (int cpu, void **pages,
296 int nr_pages, bool overwrite);
300 * Free pmu-private AUX data structures
302 void (*free_aux) (void *aux); /* optional */
306 * enum perf_event_active_state - the states of a event
308 enum perf_event_active_state {
309 PERF_EVENT_STATE_EXIT = -3,
310 PERF_EVENT_STATE_ERROR = -2,
311 PERF_EVENT_STATE_OFF = -1,
312 PERF_EVENT_STATE_INACTIVE = 0,
313 PERF_EVENT_STATE_ACTIVE = 1,
317 struct perf_sample_data;
319 typedef void (*perf_overflow_handler_t)(struct perf_event *,
320 struct perf_sample_data *,
321 struct pt_regs *regs);
323 enum perf_group_flag {
324 PERF_GROUP_SOFTWARE = 0x1,
327 #define SWEVENT_HLIST_BITS 8
328 #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
330 struct swevent_hlist {
331 struct hlist_head heads[SWEVENT_HLIST_SIZE];
332 struct rcu_head rcu_head;
335 #define PERF_ATTACH_CONTEXT 0x01
336 #define PERF_ATTACH_GROUP 0x02
337 #define PERF_ATTACH_TASK 0x04
338 #define PERF_ATTACH_TASK_DATA 0x08
344 * struct perf_event - performance event kernel representation:
347 #ifdef CONFIG_PERF_EVENTS
349 * entry onto perf_event_context::event_list;
350 * modifications require ctx->lock
351 * RCU safe iterations.
353 struct list_head event_entry;
356 * XXX: group_entry and sibling_list should be mutually exclusive;
357 * either you're a sibling on a group, or you're the group leader.
358 * Rework the code to always use the same list element.
360 * Locked for modification by both ctx->mutex and ctx->lock; holding
361 * either sufficies for read.
363 struct list_head group_entry;
364 struct list_head sibling_list;
367 * We need storage to track the entries in perf_pmu_migrate_context; we
368 * cannot use the event_entry because of RCU and we want to keep the
369 * group in tact which avoids us using the other two entries.
371 struct list_head migrate_entry;
373 struct hlist_node hlist_entry;
374 struct list_head active_entry;
377 struct perf_event *group_leader;
380 enum perf_event_active_state state;
381 unsigned int attach_state;
383 atomic64_t child_count;
386 * These are the total time in nanoseconds that the event
387 * has been enabled (i.e. eligible to run, and the task has
388 * been scheduled in, if this is a per-task event)
389 * and running (scheduled onto the CPU), respectively.
391 * They are computed from tstamp_enabled, tstamp_running and
392 * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
394 u64 total_time_enabled;
395 u64 total_time_running;
398 * These are timestamps used for computing total_time_enabled
399 * and total_time_running when the event is in INACTIVE or
400 * ACTIVE state, measured in nanoseconds from an arbitrary point
402 * tstamp_enabled: the notional time when the event was enabled
403 * tstamp_running: the notional time when the event was scheduled on
404 * tstamp_stopped: in INACTIVE state, the notional time when the
405 * event was scheduled off.
412 * timestamp shadows the actual context timing but it can
413 * be safely used in NMI interrupt context. It reflects the
414 * context time as it was when the event was last scheduled in.
416 * ctx_time already accounts for ctx->timestamp. Therefore to
417 * compute ctx_time for a sample, simply add perf_clock().
421 struct perf_event_attr attr;
425 struct hw_perf_event hw;
427 struct perf_event_context *ctx;
428 atomic_long_t refcount;
431 * These accumulate total time (in nanoseconds) that children
432 * events have been enabled and running, respectively.
434 atomic64_t child_total_time_enabled;
435 atomic64_t child_total_time_running;
438 * Protect attach/detach and child_list:
440 struct mutex child_mutex;
441 struct list_head child_list;
442 struct perf_event *parent;
447 struct list_head owner_entry;
448 struct task_struct *owner;
451 struct mutex mmap_mutex;
454 struct ring_buffer *rb;
455 struct list_head rb_entry;
456 unsigned long rcu_batches;
460 wait_queue_head_t waitq;
461 struct fasync_struct *fasync;
463 /* delayed work for NMIs and such */
467 struct irq_work pending;
469 atomic_t event_limit;
471 void (*destroy)(struct perf_event *);
472 struct rcu_head rcu_head;
474 struct pid_namespace *ns;
478 perf_overflow_handler_t overflow_handler;
479 void *overflow_handler_context;
481 #ifdef CONFIG_EVENT_TRACING
482 struct ftrace_event_call *tp_event;
483 struct event_filter *filter;
484 #ifdef CONFIG_FUNCTION_TRACER
485 struct ftrace_ops ftrace_ops;
489 #ifdef CONFIG_CGROUP_PERF
490 struct perf_cgroup *cgrp; /* cgroup event is attach to */
491 int cgrp_defer_enabled;
494 #endif /* CONFIG_PERF_EVENTS */
498 * struct perf_event_context - event context structure
500 * Used as a container for task events and CPU events as well:
502 struct perf_event_context {
505 * Protect the states of the events in the list,
506 * nr_active, and the list:
510 * Protect the list of events. Locking either mutex or lock
511 * is sufficient to ensure the list doesn't change; to change
512 * the list you need to lock both the mutex and the spinlock.
516 struct list_head active_ctx_list;
517 struct list_head pinned_groups;
518 struct list_head flexible_groups;
519 struct list_head event_list;
527 struct task_struct *task;
530 * Context clock, runs when context enabled.
536 * These fields let us detect when two contexts have both
537 * been cloned (inherited) from a common ancestor.
539 struct perf_event_context *parent_ctx;
543 int nr_cgroups; /* cgroup evts */
544 void *task_ctx_data; /* pmu specific data */
545 struct rcu_head rcu_head;
547 struct delayed_work orphans_remove;
548 bool orphans_remove_sched;
552 * Number of contexts where an event can trigger:
553 * task, softirq, hardirq, nmi.
555 #define PERF_NR_CONTEXTS 4
558 * struct perf_event_cpu_context - per cpu event context structure
560 struct perf_cpu_context {
561 struct perf_event_context ctx;
562 struct perf_event_context *task_ctx;
566 raw_spinlock_t hrtimer_lock;
567 struct hrtimer hrtimer;
568 ktime_t hrtimer_interval;
569 unsigned int hrtimer_active;
571 struct pmu *unique_pmu;
572 struct perf_cgroup *cgrp;
575 struct perf_output_handle {
576 struct perf_event *event;
577 struct ring_buffer *rb;
578 unsigned long wakeup;
587 #ifdef CONFIG_CGROUP_PERF
590 * perf_cgroup_info keeps track of time_enabled for a cgroup.
591 * This is a per-cpu dynamically allocated data structure.
593 struct perf_cgroup_info {
599 struct cgroup_subsys_state css;
600 struct perf_cgroup_info __percpu *info;
604 * Must ensure cgroup is pinned (css_get) before calling
605 * this function. In other words, we cannot call this function
606 * if there is no cgroup event for the current CPU context.
608 static inline struct perf_cgroup *
609 perf_cgroup_from_task(struct task_struct *task)
611 return container_of(task_css(task, perf_event_cgrp_id),
612 struct perf_cgroup, css);
614 #endif /* CONFIG_CGROUP_PERF */
616 #ifdef CONFIG_PERF_EVENTS
618 extern void *perf_aux_output_begin(struct perf_output_handle *handle,
619 struct perf_event *event);
620 extern void perf_aux_output_end(struct perf_output_handle *handle,
621 unsigned long size, bool truncated);
622 extern int perf_aux_output_skip(struct perf_output_handle *handle,
624 extern void *perf_get_aux(struct perf_output_handle *handle);
626 extern int perf_pmu_register(struct pmu *pmu, const char *name, int type);
627 extern void perf_pmu_unregister(struct pmu *pmu);
629 extern int perf_num_counters(void);
630 extern const char *perf_pmu_name(void);
631 extern void __perf_event_task_sched_in(struct task_struct *prev,
632 struct task_struct *task);
633 extern void __perf_event_task_sched_out(struct task_struct *prev,
634 struct task_struct *next);
635 extern int perf_event_init_task(struct task_struct *child);
636 extern void perf_event_exit_task(struct task_struct *child);
637 extern void perf_event_free_task(struct task_struct *task);
638 extern void perf_event_delayed_put(struct task_struct *task);
639 extern void perf_event_print_debug(void);
640 extern void perf_pmu_disable(struct pmu *pmu);
641 extern void perf_pmu_enable(struct pmu *pmu);
642 extern void perf_sched_cb_dec(struct pmu *pmu);
643 extern void perf_sched_cb_inc(struct pmu *pmu);
644 extern int perf_event_task_disable(void);
645 extern int perf_event_task_enable(void);
646 extern int perf_event_refresh(struct perf_event *event, int refresh);
647 extern void perf_event_update_userpage(struct perf_event *event);
648 extern int perf_event_release_kernel(struct perf_event *event);
649 extern struct perf_event *
650 perf_event_create_kernel_counter(struct perf_event_attr *attr,
652 struct task_struct *task,
653 perf_overflow_handler_t callback,
655 extern void perf_pmu_migrate_context(struct pmu *pmu,
656 int src_cpu, int dst_cpu);
657 extern u64 perf_event_read_value(struct perf_event *event,
658 u64 *enabled, u64 *running);
661 struct perf_sample_data {
663 * Fields set by perf_sample_data_init(), group so as to
664 * minimize the cachelines touched.
667 struct perf_raw_record *raw;
668 struct perf_branch_stack *br_stack;
672 union perf_mem_data_src data_src;
675 * The other fields, optionally {set,used} by
676 * perf_{prepare,output}_sample().
691 struct perf_callchain_entry *callchain;
694 * regs_user may point to task_pt_regs or to regs_user_copy, depending
697 struct perf_regs regs_user;
698 struct pt_regs regs_user_copy;
700 struct perf_regs regs_intr;
702 } ____cacheline_aligned;
704 /* default value for data source */
705 #define PERF_MEM_NA (PERF_MEM_S(OP, NA) |\
706 PERF_MEM_S(LVL, NA) |\
707 PERF_MEM_S(SNOOP, NA) |\
708 PERF_MEM_S(LOCK, NA) |\
711 static inline void perf_sample_data_init(struct perf_sample_data *data,
712 u64 addr, u64 period)
714 /* remaining struct members initialized in perf_prepare_sample() */
717 data->br_stack = NULL;
718 data->period = period;
720 data->data_src.val = PERF_MEM_NA;
724 extern void perf_output_sample(struct perf_output_handle *handle,
725 struct perf_event_header *header,
726 struct perf_sample_data *data,
727 struct perf_event *event);
728 extern void perf_prepare_sample(struct perf_event_header *header,
729 struct perf_sample_data *data,
730 struct perf_event *event,
731 struct pt_regs *regs);
733 extern int perf_event_overflow(struct perf_event *event,
734 struct perf_sample_data *data,
735 struct pt_regs *regs);
737 extern void perf_event_output(struct perf_event *event,
738 struct perf_sample_data *data,
739 struct pt_regs *regs);
742 perf_event_header__init_id(struct perf_event_header *header,
743 struct perf_sample_data *data,
744 struct perf_event *event);
746 perf_event__output_id_sample(struct perf_event *event,
747 struct perf_output_handle *handle,
748 struct perf_sample_data *sample);
751 perf_log_lost_samples(struct perf_event *event, u64 lost);
753 static inline bool is_sampling_event(struct perf_event *event)
755 return event->attr.sample_period != 0;
759 * Return 1 for a software event, 0 for a hardware event
761 static inline int is_software_event(struct perf_event *event)
763 return event->pmu->task_ctx_nr == perf_sw_context;
766 extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
768 extern void ___perf_sw_event(u32, u64, struct pt_regs *, u64);
769 extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
771 #ifndef perf_arch_fetch_caller_regs
772 static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
776 * Take a snapshot of the regs. Skip ip and frame pointer to
777 * the nth caller. We only need a few of the regs:
778 * - ip for PERF_SAMPLE_IP
779 * - cs for user_mode() tests
780 * - bp for callchains
781 * - eflags, for future purposes, just in case
783 static inline void perf_fetch_caller_regs(struct pt_regs *regs)
785 memset(regs, 0, sizeof(*regs));
787 perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
790 static __always_inline void
791 perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
793 if (static_key_false(&perf_swevent_enabled[event_id]))
794 __perf_sw_event(event_id, nr, regs, addr);
797 DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]);
800 * 'Special' version for the scheduler, it hard assumes no recursion,
801 * which is guaranteed by us not actually scheduling inside other swevents
802 * because those disable preemption.
804 static __always_inline void
805 perf_sw_event_sched(u32 event_id, u64 nr, u64 addr)
807 if (static_key_false(&perf_swevent_enabled[event_id])) {
808 struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
810 perf_fetch_caller_regs(regs);
811 ___perf_sw_event(event_id, nr, regs, addr);
815 extern struct static_key_deferred perf_sched_events;
817 static __always_inline bool
818 perf_sw_migrate_enabled(void)
820 if (static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_CPU_MIGRATIONS]))
825 static inline void perf_event_task_migrate(struct task_struct *task)
827 if (perf_sw_migrate_enabled())
828 task->sched_migrated = 1;
831 static inline void perf_event_task_sched_in(struct task_struct *prev,
832 struct task_struct *task)
834 if (static_key_false(&perf_sched_events.key))
835 __perf_event_task_sched_in(prev, task);
837 if (perf_sw_migrate_enabled() && task->sched_migrated) {
838 struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
840 perf_fetch_caller_regs(regs);
841 ___perf_sw_event(PERF_COUNT_SW_CPU_MIGRATIONS, 1, regs, 0);
842 task->sched_migrated = 0;
846 static inline void perf_event_task_sched_out(struct task_struct *prev,
847 struct task_struct *next)
849 perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0);
851 if (static_key_false(&perf_sched_events.key))
852 __perf_event_task_sched_out(prev, next);
855 static inline u64 __perf_event_count(struct perf_event *event)
857 return local64_read(&event->count) + atomic64_read(&event->child_count);
860 extern void perf_event_mmap(struct vm_area_struct *vma);
861 extern struct perf_guest_info_callbacks *perf_guest_cbs;
862 extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
863 extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
865 extern void perf_event_exec(void);
866 extern void perf_event_comm(struct task_struct *tsk, bool exec);
867 extern void perf_event_fork(struct task_struct *tsk);
870 DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
872 extern void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs);
873 extern void perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs);
875 static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64 ip)
877 if (entry->nr < PERF_MAX_STACK_DEPTH)
878 entry->ip[entry->nr++] = ip;
881 extern int sysctl_perf_event_paranoid;
882 extern int sysctl_perf_event_mlock;
883 extern int sysctl_perf_event_sample_rate;
884 extern int sysctl_perf_cpu_time_max_percent;
886 extern void perf_sample_event_took(u64 sample_len_ns);
888 extern int perf_proc_update_handler(struct ctl_table *table, int write,
889 void __user *buffer, size_t *lenp,
891 extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
892 void __user *buffer, size_t *lenp,
896 static inline bool perf_paranoid_tracepoint_raw(void)
898 return sysctl_perf_event_paranoid > -1;
901 static inline bool perf_paranoid_cpu(void)
903 return sysctl_perf_event_paranoid > 0;
906 static inline bool perf_paranoid_kernel(void)
908 return sysctl_perf_event_paranoid > 1;
911 extern void perf_event_init(void);
912 extern void perf_tp_event(u64 addr, u64 count, void *record,
913 int entry_size, struct pt_regs *regs,
914 struct hlist_head *head, int rctx,
915 struct task_struct *task);
916 extern void perf_bp_event(struct perf_event *event, void *data);
918 #ifndef perf_misc_flags
919 # define perf_misc_flags(regs) \
920 (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
921 # define perf_instruction_pointer(regs) instruction_pointer(regs)
924 static inline bool has_branch_stack(struct perf_event *event)
926 return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
929 static inline bool needs_branch_stack(struct perf_event *event)
931 return event->attr.branch_sample_type != 0;
934 static inline bool has_aux(struct perf_event *event)
936 return event->pmu->setup_aux;
939 extern int perf_output_begin(struct perf_output_handle *handle,
940 struct perf_event *event, unsigned int size);
941 extern void perf_output_end(struct perf_output_handle *handle);
942 extern unsigned int perf_output_copy(struct perf_output_handle *handle,
943 const void *buf, unsigned int len);
944 extern unsigned int perf_output_skip(struct perf_output_handle *handle,
946 extern int perf_swevent_get_recursion_context(void);
947 extern void perf_swevent_put_recursion_context(int rctx);
948 extern u64 perf_swevent_set_period(struct perf_event *event);
949 extern void perf_event_enable(struct perf_event *event);
950 extern void perf_event_disable(struct perf_event *event);
951 extern int __perf_event_disable(void *info);
952 extern void perf_event_task_tick(void);
953 #else /* !CONFIG_PERF_EVENTS: */
955 perf_aux_output_begin(struct perf_output_handle *handle,
956 struct perf_event *event) { return NULL; }
958 perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
961 perf_aux_output_skip(struct perf_output_handle *handle,
962 unsigned long size) { return -EINVAL; }
964 perf_get_aux(struct perf_output_handle *handle) { return NULL; }
966 perf_event_task_migrate(struct task_struct *task) { }
968 perf_event_task_sched_in(struct task_struct *prev,
969 struct task_struct *task) { }
971 perf_event_task_sched_out(struct task_struct *prev,
972 struct task_struct *next) { }
973 static inline int perf_event_init_task(struct task_struct *child) { return 0; }
974 static inline void perf_event_exit_task(struct task_struct *child) { }
975 static inline void perf_event_free_task(struct task_struct *task) { }
976 static inline void perf_event_delayed_put(struct task_struct *task) { }
977 static inline void perf_event_print_debug(void) { }
978 static inline int perf_event_task_disable(void) { return -EINVAL; }
979 static inline int perf_event_task_enable(void) { return -EINVAL; }
980 static inline int perf_event_refresh(struct perf_event *event, int refresh)
986 perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
988 perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) { }
990 perf_bp_event(struct perf_event *event, void *data) { }
992 static inline int perf_register_guest_info_callbacks
993 (struct perf_guest_info_callbacks *callbacks) { return 0; }
994 static inline int perf_unregister_guest_info_callbacks
995 (struct perf_guest_info_callbacks *callbacks) { return 0; }
997 static inline void perf_event_mmap(struct vm_area_struct *vma) { }
998 static inline void perf_event_exec(void) { }
999 static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
1000 static inline void perf_event_fork(struct task_struct *tsk) { }
1001 static inline void perf_event_init(void) { }
1002 static inline int perf_swevent_get_recursion_context(void) { return -1; }
1003 static inline void perf_swevent_put_recursion_context(int rctx) { }
1004 static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; }
1005 static inline void perf_event_enable(struct perf_event *event) { }
1006 static inline void perf_event_disable(struct perf_event *event) { }
1007 static inline int __perf_event_disable(void *info) { return -1; }
1008 static inline void perf_event_task_tick(void) { }
1011 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_NO_HZ_FULL)
1012 extern bool perf_event_can_stop_tick(void);
1014 static inline bool perf_event_can_stop_tick(void) { return true; }
1017 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
1018 extern void perf_restore_debug_store(void);
1020 static inline void perf_restore_debug_store(void) { }
1023 #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
1026 * This has to have a higher priority than migration_notifier in sched/core.c.
1028 #define perf_cpu_notifier(fn) \
1030 static struct notifier_block fn##_nb = \
1031 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
1032 unsigned long cpu = smp_processor_id(); \
1033 unsigned long flags; \
1035 cpu_notifier_register_begin(); \
1036 fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE, \
1037 (void *)(unsigned long)cpu); \
1038 local_irq_save(flags); \
1039 fn(&fn##_nb, (unsigned long)CPU_STARTING, \
1040 (void *)(unsigned long)cpu); \
1041 local_irq_restore(flags); \
1042 fn(&fn##_nb, (unsigned long)CPU_ONLINE, \
1043 (void *)(unsigned long)cpu); \
1044 __register_cpu_notifier(&fn##_nb); \
1045 cpu_notifier_register_done(); \
1049 * Bare-bones version of perf_cpu_notifier(), which doesn't invoke the
1050 * callback for already online CPUs.
1052 #define __perf_cpu_notifier(fn) \
1054 static struct notifier_block fn##_nb = \
1055 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
1057 __register_cpu_notifier(&fn##_nb); \
1060 struct perf_pmu_events_attr {
1061 struct device_attribute attr;
1063 const char *event_str;
1066 ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
1069 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
1070 static struct perf_pmu_events_attr _var = { \
1071 .attr = __ATTR(_name, 0444, _show, NULL), \
1075 #define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
1076 static struct perf_pmu_events_attr _var = { \
1077 .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \
1079 .event_str = _str, \
1082 #define PMU_FORMAT_ATTR(_name, _format) \
1084 _name##_show(struct device *dev, \
1085 struct device_attribute *attr, \
1088 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
1089 return sprintf(page, _format "\n"); \
1092 static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
1094 #endif /* _LINUX_PERF_EVENT_H */