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>
18 #include <uapi/linux/bpf_perf_event.h>
21 * Kernel-internal data types and definitions:
24 #ifdef CONFIG_PERF_EVENTS
25 # include <asm/perf_event.h>
26 # include <asm/local64.h>
29 #define PERF_GUEST_ACTIVE 0x01
30 #define PERF_GUEST_USER 0x02
32 struct perf_guest_info_callbacks {
33 unsigned int (*state)(void);
34 unsigned long (*get_ip)(void);
35 unsigned int (*handle_intel_pt_intr)(void);
38 #ifdef CONFIG_HAVE_HW_BREAKPOINT
39 #include <asm/hw_breakpoint.h>
42 #include <linux/list.h>
43 #include <linux/mutex.h>
44 #include <linux/rculist.h>
45 #include <linux/rcupdate.h>
46 #include <linux/spinlock.h>
47 #include <linux/hrtimer.h>
49 #include <linux/pid_namespace.h>
50 #include <linux/workqueue.h>
51 #include <linux/ftrace.h>
52 #include <linux/cpu.h>
53 #include <linux/irq_work.h>
54 #include <linux/static_key.h>
55 #include <linux/jump_label_ratelimit.h>
56 #include <linux/atomic.h>
57 #include <linux/sysfs.h>
58 #include <linux/perf_regs.h>
59 #include <linux/cgroup.h>
60 #include <linux/refcount.h>
61 #include <linux/security.h>
62 #include <linux/static_call.h>
63 #include <asm/local.h>
65 struct perf_callchain_entry {
67 __u64 ip[]; /* /proc/sys/kernel/perf_event_max_stack */
70 struct perf_callchain_entry_ctx {
71 struct perf_callchain_entry *entry;
78 typedef unsigned long (*perf_copy_f)(void *dst, const void *src,
79 unsigned long off, unsigned long len);
81 struct perf_raw_frag {
83 struct perf_raw_frag *next;
91 struct perf_raw_record {
92 struct perf_raw_frag frag;
97 * branch stack layout:
98 * nr: number of taken branches stored in entries[]
99 * hw_idx: The low level index of raw branch records
100 * for the most recent branch.
101 * -1ULL means invalid/unknown.
103 * Note that nr can vary from sample to sample
104 * branches (to, from) are stored from most recent
105 * to least recent, i.e., entries[0] contains the most
107 * The entries[] is an abstraction of raw branch records,
108 * which may not be stored in age order in HW, e.g. Intel LBR.
109 * The hw_idx is to expose the low level index of raw
110 * branch record for the most recent branch aka entries[0].
111 * The hw_idx index is between -1 (unknown) and max depth,
112 * which can be retrieved in /sys/devices/cpu/caps/branches.
113 * For the architectures whose raw branch records are
114 * already stored in age order, the hw_idx should be 0.
116 struct perf_branch_stack {
119 struct perf_branch_entry entries[];
125 * extra PMU register associated with an event
127 struct hw_perf_event_extra {
128 u64 config; /* register value */
129 unsigned int reg; /* register address or index */
130 int alloc; /* extra register already allocated */
131 int idx; /* index in shared_regs->regs[] */
135 * hw_perf_event::flag values
137 * PERF_EVENT_FLAG_ARCH bits are reserved for architecture-specific
140 #define PERF_EVENT_FLAG_ARCH 0x0000ffff
141 #define PERF_EVENT_FLAG_USER_READ_CNT 0x80000000
144 * struct hw_perf_event - performance event hardware details:
146 struct hw_perf_event {
147 #ifdef CONFIG_PERF_EVENTS
149 struct { /* hardware */
152 unsigned long config_base;
153 unsigned long event_base;
154 int event_base_rdpmc;
159 struct hw_perf_event_extra extra_reg;
160 struct hw_perf_event_extra branch_reg;
162 struct { /* software */
163 struct hrtimer hrtimer;
165 struct { /* tracepoint */
166 /* for tp_event->class */
167 struct list_head tp_list;
169 struct { /* amd_power */
173 #ifdef CONFIG_HAVE_HW_BREAKPOINT
174 struct { /* breakpoint */
176 * Crufty hack to avoid the chicken and egg
177 * problem hw_breakpoint has with context
178 * creation and event initalization.
180 struct arch_hw_breakpoint info;
181 struct list_head bp_list;
184 struct { /* amd_iommu */
193 * If the event is a per task event, this will point to the task in
194 * question. See the comment in perf_event_alloc().
196 struct task_struct *target;
199 * PMU would store hardware filter configuration
204 /* Last sync'ed generation of filters */
205 unsigned long addr_filters_gen;
208 * hw_perf_event::state flags; used to track the PERF_EF_* state.
210 #define PERF_HES_STOPPED 0x01 /* the counter is stopped */
211 #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
212 #define PERF_HES_ARCH 0x04
217 * The last observed hardware counter value, updated with a
218 * local64_cmpxchg() such that pmu::read() can be called nested.
220 local64_t prev_count;
223 * The period to start the next sample with.
228 struct { /* Sampling */
230 * The period we started this sample with.
235 * However much is left of the current period;
236 * note that this is a full 64bit value and
237 * allows for generation of periods longer
238 * than hardware might allow.
240 local64_t period_left;
242 struct { /* Topdown events counting for context switch */
249 * State for throttling the event, see __perf_event_overflow() and
250 * perf_adjust_freq_unthr_context().
256 * State for freq target events, see __perf_event_overflow() and
257 * perf_adjust_freq_unthr_context().
260 u64 freq_count_stamp;
267 * Common implementation detail of pmu::{start,commit,cancel}_txn
269 #define PERF_PMU_TXN_ADD 0x1 /* txn to add/schedule event on PMU */
270 #define PERF_PMU_TXN_READ 0x2 /* txn to read event group from PMU */
273 * pmu::capabilities flags
275 #define PERF_PMU_CAP_NO_INTERRUPT 0x0001
276 #define PERF_PMU_CAP_NO_NMI 0x0002
277 #define PERF_PMU_CAP_AUX_NO_SG 0x0004
278 #define PERF_PMU_CAP_EXTENDED_REGS 0x0008
279 #define PERF_PMU_CAP_EXCLUSIVE 0x0010
280 #define PERF_PMU_CAP_ITRACE 0x0020
281 #define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x0040
282 #define PERF_PMU_CAP_NO_EXCLUDE 0x0080
283 #define PERF_PMU_CAP_AUX_OUTPUT 0x0100
284 #define PERF_PMU_CAP_EXTENDED_HW_TYPE 0x0200
286 struct perf_output_handle;
289 * struct pmu - generic performance monitoring unit
292 struct list_head entry;
294 struct module *module;
296 const struct attribute_group **attr_groups;
297 const struct attribute_group **attr_update;
302 * various common per-pmu feature flags
306 int __percpu *pmu_disable_count;
307 struct perf_cpu_context __percpu *pmu_cpu_context;
308 atomic_t exclusive_cnt; /* < 0: cpu; > 0: tsk */
310 int hrtimer_interval_ms;
312 /* number of address filters this PMU can do */
313 unsigned int nr_addr_filters;
316 * Fully disable/enable this PMU, can be used to protect from the PMI
317 * as well as for lazy/batch writing of the MSRs.
319 void (*pmu_enable) (struct pmu *pmu); /* optional */
320 void (*pmu_disable) (struct pmu *pmu); /* optional */
323 * Try and initialize the event for this PMU.
326 * -ENOENT -- @event is not for this PMU
328 * -ENODEV -- @event is for this PMU but PMU not present
329 * -EBUSY -- @event is for this PMU but PMU temporarily unavailable
330 * -EINVAL -- @event is for this PMU but @event is not valid
331 * -EOPNOTSUPP -- @event is for this PMU, @event is valid, but not supported
332 * -EACCES -- @event is for this PMU, @event is valid, but no privileges
334 * 0 -- @event is for this PMU and valid
336 * Other error return values are allowed.
338 int (*event_init) (struct perf_event *event);
341 * Notification that the event was mapped or unmapped. Called
342 * in the context of the mapping task.
344 void (*event_mapped) (struct perf_event *event, struct mm_struct *mm); /* optional */
345 void (*event_unmapped) (struct perf_event *event, struct mm_struct *mm); /* optional */
348 * Flags for ->add()/->del()/ ->start()/->stop(). There are
349 * matching hw_perf_event::state flags.
351 #define PERF_EF_START 0x01 /* start the counter when adding */
352 #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
353 #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
356 * Adds/Removes a counter to/from the PMU, can be done inside a
357 * transaction, see the ->*_txn() methods.
359 * The add/del callbacks will reserve all hardware resources required
360 * to service the event, this includes any counter constraint
363 * Called with IRQs disabled and the PMU disabled on the CPU the event
366 * ->add() called without PERF_EF_START should result in the same state
367 * as ->add() followed by ->stop().
369 * ->del() must always PERF_EF_UPDATE stop an event. If it calls
370 * ->stop() that must deal with already being stopped without
373 int (*add) (struct perf_event *event, int flags);
374 void (*del) (struct perf_event *event, int flags);
377 * Starts/Stops a counter present on the PMU.
379 * The PMI handler should stop the counter when perf_event_overflow()
380 * returns !0. ->start() will be used to continue.
382 * Also used to change the sample period.
384 * Called with IRQs disabled and the PMU disabled on the CPU the event
385 * is on -- will be called from NMI context with the PMU generates
388 * ->stop() with PERF_EF_UPDATE will read the counter and update
389 * period/count values like ->read() would.
391 * ->start() with PERF_EF_RELOAD will reprogram the counter
392 * value, must be preceded by a ->stop() with PERF_EF_UPDATE.
394 void (*start) (struct perf_event *event, int flags);
395 void (*stop) (struct perf_event *event, int flags);
398 * Updates the counter value of the event.
400 * For sampling capable PMUs this will also update the software period
401 * hw_perf_event::period_left field.
403 void (*read) (struct perf_event *event);
406 * Group events scheduling is treated as a transaction, add
407 * group events as a whole and perform one schedulability test.
408 * If the test fails, roll back the whole group
410 * Start the transaction, after this ->add() doesn't need to
411 * do schedulability tests.
415 void (*start_txn) (struct pmu *pmu, unsigned int txn_flags);
417 * If ->start_txn() disabled the ->add() schedulability test
418 * then ->commit_txn() is required to perform one. On success
419 * the transaction is closed. On error the transaction is kept
420 * open until ->cancel_txn() is called.
424 int (*commit_txn) (struct pmu *pmu);
426 * Will cancel the transaction, assumes ->del() is called
427 * for each successful ->add() during the transaction.
431 void (*cancel_txn) (struct pmu *pmu);
434 * Will return the value for perf_event_mmap_page::index for this event,
435 * if no implementation is provided it will default to: event->hw.idx + 1.
437 int (*event_idx) (struct perf_event *event); /*optional */
440 * context-switches callback
442 void (*sched_task) (struct perf_event_context *ctx,
446 * Kmem cache of PMU specific data
448 struct kmem_cache *task_ctx_cache;
451 * PMU specific parts of task perf event context (i.e. ctx->task_ctx_data)
452 * can be synchronized using this function. See Intel LBR callstack support
453 * implementation and Perf core context switch handling callbacks for usage
456 void (*swap_task_ctx) (struct perf_event_context *prev,
457 struct perf_event_context *next);
461 * Set up pmu-private data structures for an AUX area
463 void *(*setup_aux) (struct perf_event *event, void **pages,
464 int nr_pages, bool overwrite);
468 * Free pmu-private AUX data structures
470 void (*free_aux) (void *aux); /* optional */
473 * Take a snapshot of the AUX buffer without touching the event
474 * state, so that preempting ->start()/->stop() callbacks does
475 * not interfere with their logic. Called in PMI context.
477 * Returns the size of AUX data copied to the output handle.
481 long (*snapshot_aux) (struct perf_event *event,
482 struct perf_output_handle *handle,
486 * Validate address range filters: make sure the HW supports the
487 * requested configuration and number of filters; return 0 if the
488 * supplied filters are valid, -errno otherwise.
490 * Runs in the context of the ioctl()ing process and is not serialized
491 * with the rest of the PMU callbacks.
493 int (*addr_filters_validate) (struct list_head *filters);
497 * Synchronize address range filter configuration:
498 * translate hw-agnostic filters into hardware configuration in
499 * event::hw::addr_filters.
501 * Runs as a part of filter sync sequence that is done in ->start()
502 * callback by calling perf_event_addr_filters_sync().
504 * May (and should) traverse event::addr_filters::list, for which its
505 * caller provides necessary serialization.
507 void (*addr_filters_sync) (struct perf_event *event);
511 * Check if event can be used for aux_output purposes for
512 * events of this PMU.
514 * Runs from perf_event_open(). Should return 0 for "no match"
515 * or non-zero for "match".
517 int (*aux_output_match) (struct perf_event *event);
521 * Filter events for PMU-specific reasons.
523 int (*filter_match) (struct perf_event *event); /* optional */
526 * Check period value for PERF_EVENT_IOC_PERIOD ioctl.
528 int (*check_period) (struct perf_event *event, u64 value); /* optional */
531 enum perf_addr_filter_action_t {
532 PERF_ADDR_FILTER_ACTION_STOP = 0,
533 PERF_ADDR_FILTER_ACTION_START,
534 PERF_ADDR_FILTER_ACTION_FILTER,
538 * struct perf_addr_filter - address range filter definition
539 * @entry: event's filter list linkage
540 * @path: object file's path for file-based filters
541 * @offset: filter range offset
542 * @size: filter range size (size==0 means single address trigger)
543 * @action: filter/start/stop
545 * This is a hardware-agnostic filter configuration as specified by the user.
547 struct perf_addr_filter {
548 struct list_head entry;
550 unsigned long offset;
552 enum perf_addr_filter_action_t action;
556 * struct perf_addr_filters_head - container for address range filters
557 * @list: list of filters for this event
558 * @lock: spinlock that serializes accesses to the @list and event's
559 * (and its children's) filter generations.
560 * @nr_file_filters: number of file-based filters
562 * A child event will use parent's @list (and therefore @lock), so they are
563 * bundled together; see perf_event_addr_filters().
565 struct perf_addr_filters_head {
566 struct list_head list;
568 unsigned int nr_file_filters;
571 struct perf_addr_filter_range {
577 * enum perf_event_state - the states of an event:
579 enum perf_event_state {
580 PERF_EVENT_STATE_DEAD = -4,
581 PERF_EVENT_STATE_EXIT = -3,
582 PERF_EVENT_STATE_ERROR = -2,
583 PERF_EVENT_STATE_OFF = -1,
584 PERF_EVENT_STATE_INACTIVE = 0,
585 PERF_EVENT_STATE_ACTIVE = 1,
589 struct perf_sample_data;
591 typedef void (*perf_overflow_handler_t)(struct perf_event *,
592 struct perf_sample_data *,
593 struct pt_regs *regs);
596 * Event capabilities. For event_caps and groups caps.
598 * PERF_EV_CAP_SOFTWARE: Is a software event.
599 * PERF_EV_CAP_READ_ACTIVE_PKG: A CPU event (or cgroup event) that can be read
600 * from any CPU in the package where it is active.
601 * PERF_EV_CAP_SIBLING: An event with this flag must be a group sibling and
602 * cannot be a group leader. If an event with this flag is detached from the
603 * group it is scheduled out and moved into an unrecoverable ERROR state.
605 #define PERF_EV_CAP_SOFTWARE BIT(0)
606 #define PERF_EV_CAP_READ_ACTIVE_PKG BIT(1)
607 #define PERF_EV_CAP_SIBLING BIT(2)
609 #define SWEVENT_HLIST_BITS 8
610 #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
612 struct swevent_hlist {
613 struct hlist_head heads[SWEVENT_HLIST_SIZE];
614 struct rcu_head rcu_head;
617 #define PERF_ATTACH_CONTEXT 0x01
618 #define PERF_ATTACH_GROUP 0x02
619 #define PERF_ATTACH_TASK 0x04
620 #define PERF_ATTACH_TASK_DATA 0x08
621 #define PERF_ATTACH_ITRACE 0x10
622 #define PERF_ATTACH_SCHED_CB 0x20
623 #define PERF_ATTACH_CHILD 0x40
629 struct pmu_event_list {
631 struct list_head list;
634 #define for_each_sibling_event(sibling, event) \
635 if ((event)->group_leader == (event)) \
636 list_for_each_entry((sibling), &(event)->sibling_list, sibling_list)
639 * struct perf_event - performance event kernel representation:
642 #ifdef CONFIG_PERF_EVENTS
644 * entry onto perf_event_context::event_list;
645 * modifications require ctx->lock
646 * RCU safe iterations.
648 struct list_head event_entry;
651 * Locked for modification by both ctx->mutex and ctx->lock; holding
652 * either sufficies for read.
654 struct list_head sibling_list;
655 struct list_head active_list;
657 * Node on the pinned or flexible tree located at the event context;
659 struct rb_node group_node;
662 * We need storage to track the entries in perf_pmu_migrate_context; we
663 * cannot use the event_entry because of RCU and we want to keep the
664 * group in tact which avoids us using the other two entries.
666 struct list_head migrate_entry;
668 struct hlist_node hlist_entry;
669 struct list_head active_entry;
672 /* Not serialized. Only written during event initialization. */
674 /* The cumulative AND of all event_caps for events in this group. */
677 struct perf_event *group_leader;
681 enum perf_event_state state;
682 unsigned int attach_state;
684 atomic64_t child_count;
687 * These are the total time in nanoseconds that the event
688 * has been enabled (i.e. eligible to run, and the task has
689 * been scheduled in, if this is a per-task event)
690 * and running (scheduled onto the CPU), respectively.
692 u64 total_time_enabled;
693 u64 total_time_running;
697 * timestamp shadows the actual context timing but it can
698 * be safely used in NMI interrupt context. It reflects the
699 * context time as it was when the event was last scheduled in,
700 * or when ctx_sched_in failed to schedule the event because we
703 * ctx_time already accounts for ctx->timestamp. Therefore to
704 * compute ctx_time for a sample, simply add perf_clock().
708 struct perf_event_attr attr;
712 struct hw_perf_event hw;
714 struct perf_event_context *ctx;
715 atomic_long_t refcount;
718 * These accumulate total time (in nanoseconds) that children
719 * events have been enabled and running, respectively.
721 atomic64_t child_total_time_enabled;
722 atomic64_t child_total_time_running;
725 * Protect attach/detach and child_list:
727 struct mutex child_mutex;
728 struct list_head child_list;
729 struct perf_event *parent;
734 struct list_head owner_entry;
735 struct task_struct *owner;
738 struct mutex mmap_mutex;
741 struct perf_buffer *rb;
742 struct list_head rb_entry;
743 unsigned long rcu_batches;
747 wait_queue_head_t waitq;
748 struct fasync_struct *fasync;
750 /* delayed work for NMIs and such */
754 unsigned long pending_addr; /* SIGTRAP */
755 struct irq_work pending;
757 atomic_t event_limit;
759 /* address range filters */
760 struct perf_addr_filters_head addr_filters;
761 /* vma address array for file-based filders */
762 struct perf_addr_filter_range *addr_filter_ranges;
763 unsigned long addr_filters_gen;
765 /* for aux_output events */
766 struct perf_event *aux_event;
768 void (*destroy)(struct perf_event *);
769 struct rcu_head rcu_head;
771 struct pid_namespace *ns;
775 perf_overflow_handler_t overflow_handler;
776 void *overflow_handler_context;
777 #ifdef CONFIG_BPF_SYSCALL
778 perf_overflow_handler_t orig_overflow_handler;
779 struct bpf_prog *prog;
783 #ifdef CONFIG_EVENT_TRACING
784 struct trace_event_call *tp_event;
785 struct event_filter *filter;
786 #ifdef CONFIG_FUNCTION_TRACER
787 struct ftrace_ops ftrace_ops;
791 #ifdef CONFIG_CGROUP_PERF
792 struct perf_cgroup *cgrp; /* cgroup event is attach to */
795 #ifdef CONFIG_SECURITY
798 struct list_head sb_list;
799 #endif /* CONFIG_PERF_EVENTS */
803 struct perf_event_groups {
809 * struct perf_event_context - event context structure
811 * Used as a container for task events and CPU events as well:
813 struct perf_event_context {
816 * Protect the states of the events in the list,
817 * nr_active, and the list:
821 * Protect the list of events. Locking either mutex or lock
822 * is sufficient to ensure the list doesn't change; to change
823 * the list you need to lock both the mutex and the spinlock.
827 struct list_head active_ctx_list;
828 struct perf_event_groups pinned_groups;
829 struct perf_event_groups flexible_groups;
830 struct list_head event_list;
832 struct list_head pinned_active;
833 struct list_head flexible_active;
843 * Set when nr_events != nr_active, except tolerant to events not
844 * necessary to be active due to scheduling constraints, such as cgroups.
846 int rotate_necessary;
848 struct task_struct *task;
851 * Context clock, runs when context enabled.
857 * These fields let us detect when two contexts have both
858 * been cloned (inherited) from a common ancestor.
860 struct perf_event_context *parent_ctx;
864 #ifdef CONFIG_CGROUP_PERF
865 int nr_cgroups; /* cgroup evts */
867 void *task_ctx_data; /* pmu specific data */
868 struct rcu_head rcu_head;
872 * Number of contexts where an event can trigger:
873 * task, softirq, hardirq, nmi.
875 #define PERF_NR_CONTEXTS 4
878 * struct perf_event_cpu_context - per cpu event context structure
880 struct perf_cpu_context {
881 struct perf_event_context ctx;
882 struct perf_event_context *task_ctx;
886 raw_spinlock_t hrtimer_lock;
887 struct hrtimer hrtimer;
888 ktime_t hrtimer_interval;
889 unsigned int hrtimer_active;
891 #ifdef CONFIG_CGROUP_PERF
892 struct perf_cgroup *cgrp;
893 struct list_head cgrp_cpuctx_entry;
896 struct list_head sched_cb_entry;
901 * Per-CPU storage for iterators used in visit_groups_merge. The default
902 * storage is of size 2 to hold the CPU and any CPU event iterators.
905 struct perf_event **heap;
906 struct perf_event *heap_default[2];
909 struct perf_output_handle {
910 struct perf_event *event;
911 struct perf_buffer *rb;
912 unsigned long wakeup;
922 struct bpf_perf_event_data_kern {
923 bpf_user_pt_regs_t *regs;
924 struct perf_sample_data *data;
925 struct perf_event *event;
928 #ifdef CONFIG_CGROUP_PERF
931 * perf_cgroup_info keeps track of time_enabled for a cgroup.
932 * This is a per-cpu dynamically allocated data structure.
934 struct perf_cgroup_info {
940 struct cgroup_subsys_state css;
941 struct perf_cgroup_info __percpu *info;
945 * Must ensure cgroup is pinned (css_get) before calling
946 * this function. In other words, we cannot call this function
947 * if there is no cgroup event for the current CPU context.
949 static inline struct perf_cgroup *
950 perf_cgroup_from_task(struct task_struct *task, struct perf_event_context *ctx)
952 return container_of(task_css_check(task, perf_event_cgrp_id,
953 ctx ? lockdep_is_held(&ctx->lock)
955 struct perf_cgroup, css);
957 #endif /* CONFIG_CGROUP_PERF */
959 #ifdef CONFIG_PERF_EVENTS
961 extern void *perf_aux_output_begin(struct perf_output_handle *handle,
962 struct perf_event *event);
963 extern void perf_aux_output_end(struct perf_output_handle *handle,
965 extern int perf_aux_output_skip(struct perf_output_handle *handle,
967 extern void *perf_get_aux(struct perf_output_handle *handle);
968 extern void perf_aux_output_flag(struct perf_output_handle *handle, u64 flags);
969 extern void perf_event_itrace_started(struct perf_event *event);
971 extern int perf_pmu_register(struct pmu *pmu, const char *name, int type);
972 extern void perf_pmu_unregister(struct pmu *pmu);
974 extern void __perf_event_task_sched_in(struct task_struct *prev,
975 struct task_struct *task);
976 extern void __perf_event_task_sched_out(struct task_struct *prev,
977 struct task_struct *next);
978 extern int perf_event_init_task(struct task_struct *child, u64 clone_flags);
979 extern void perf_event_exit_task(struct task_struct *child);
980 extern void perf_event_free_task(struct task_struct *task);
981 extern void perf_event_delayed_put(struct task_struct *task);
982 extern struct file *perf_event_get(unsigned int fd);
983 extern const struct perf_event *perf_get_event(struct file *file);
984 extern const struct perf_event_attr *perf_event_attrs(struct perf_event *event);
985 extern void perf_event_print_debug(void);
986 extern void perf_pmu_disable(struct pmu *pmu);
987 extern void perf_pmu_enable(struct pmu *pmu);
988 extern void perf_sched_cb_dec(struct pmu *pmu);
989 extern void perf_sched_cb_inc(struct pmu *pmu);
990 extern int perf_event_task_disable(void);
991 extern int perf_event_task_enable(void);
993 extern void perf_pmu_resched(struct pmu *pmu);
995 extern int perf_event_refresh(struct perf_event *event, int refresh);
996 extern void perf_event_update_userpage(struct perf_event *event);
997 extern int perf_event_release_kernel(struct perf_event *event);
998 extern struct perf_event *
999 perf_event_create_kernel_counter(struct perf_event_attr *attr,
1001 struct task_struct *task,
1002 perf_overflow_handler_t callback,
1004 extern void perf_pmu_migrate_context(struct pmu *pmu,
1005 int src_cpu, int dst_cpu);
1006 int perf_event_read_local(struct perf_event *event, u64 *value,
1007 u64 *enabled, u64 *running);
1008 extern u64 perf_event_read_value(struct perf_event *event,
1009 u64 *enabled, u64 *running);
1012 struct perf_sample_data {
1014 * Fields set by perf_sample_data_init(), group so as to
1015 * minimize the cachelines touched.
1018 struct perf_raw_record *raw;
1019 struct perf_branch_stack *br_stack;
1021 union perf_sample_weight weight;
1023 union perf_mem_data_src data_src;
1026 * The other fields, optionally {set,used} by
1027 * perf_{prepare,output}_sample().
1042 struct perf_callchain_entry *callchain;
1045 struct perf_regs regs_user;
1046 struct perf_regs regs_intr;
1047 u64 stack_user_size;
1053 } ____cacheline_aligned;
1055 /* default value for data source */
1056 #define PERF_MEM_NA (PERF_MEM_S(OP, NA) |\
1057 PERF_MEM_S(LVL, NA) |\
1058 PERF_MEM_S(SNOOP, NA) |\
1059 PERF_MEM_S(LOCK, NA) |\
1060 PERF_MEM_S(TLB, NA))
1062 static inline void perf_sample_data_init(struct perf_sample_data *data,
1063 u64 addr, u64 period)
1065 /* remaining struct members initialized in perf_prepare_sample() */
1068 data->br_stack = NULL;
1069 data->period = period;
1070 data->weight.full = 0;
1071 data->data_src.val = PERF_MEM_NA;
1075 extern void perf_output_sample(struct perf_output_handle *handle,
1076 struct perf_event_header *header,
1077 struct perf_sample_data *data,
1078 struct perf_event *event);
1079 extern void perf_prepare_sample(struct perf_event_header *header,
1080 struct perf_sample_data *data,
1081 struct perf_event *event,
1082 struct pt_regs *regs);
1084 extern int perf_event_overflow(struct perf_event *event,
1085 struct perf_sample_data *data,
1086 struct pt_regs *regs);
1088 extern void perf_event_output_forward(struct perf_event *event,
1089 struct perf_sample_data *data,
1090 struct pt_regs *regs);
1091 extern void perf_event_output_backward(struct perf_event *event,
1092 struct perf_sample_data *data,
1093 struct pt_regs *regs);
1094 extern int perf_event_output(struct perf_event *event,
1095 struct perf_sample_data *data,
1096 struct pt_regs *regs);
1099 is_default_overflow_handler(struct perf_event *event)
1101 if (likely(event->overflow_handler == perf_event_output_forward))
1103 if (unlikely(event->overflow_handler == perf_event_output_backward))
1109 perf_event_header__init_id(struct perf_event_header *header,
1110 struct perf_sample_data *data,
1111 struct perf_event *event);
1113 perf_event__output_id_sample(struct perf_event *event,
1114 struct perf_output_handle *handle,
1115 struct perf_sample_data *sample);
1118 perf_log_lost_samples(struct perf_event *event, u64 lost);
1120 static inline bool event_has_any_exclude_flag(struct perf_event *event)
1122 struct perf_event_attr *attr = &event->attr;
1124 return attr->exclude_idle || attr->exclude_user ||
1125 attr->exclude_kernel || attr->exclude_hv ||
1126 attr->exclude_guest || attr->exclude_host;
1129 static inline bool is_sampling_event(struct perf_event *event)
1131 return event->attr.sample_period != 0;
1135 * Return 1 for a software event, 0 for a hardware event
1137 static inline int is_software_event(struct perf_event *event)
1139 return event->event_caps & PERF_EV_CAP_SOFTWARE;
1143 * Return 1 for event in sw context, 0 for event in hw context
1145 static inline int in_software_context(struct perf_event *event)
1147 return event->ctx->pmu->task_ctx_nr == perf_sw_context;
1150 static inline int is_exclusive_pmu(struct pmu *pmu)
1152 return pmu->capabilities & PERF_PMU_CAP_EXCLUSIVE;
1155 extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
1157 extern void ___perf_sw_event(u32, u64, struct pt_regs *, u64);
1158 extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
1160 #ifndef perf_arch_fetch_caller_regs
1161 static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
1165 * When generating a perf sample in-line, instead of from an interrupt /
1166 * exception, we lack a pt_regs. This is typically used from software events
1167 * like: SW_CONTEXT_SWITCHES, SW_MIGRATIONS and the tie-in with tracepoints.
1169 * We typically don't need a full set, but (for x86) do require:
1170 * - ip for PERF_SAMPLE_IP
1171 * - cs for user_mode() tests
1172 * - sp for PERF_SAMPLE_CALLCHAIN
1173 * - eflags for MISC bits and CALLCHAIN (see: perf_hw_regs())
1175 * NOTE: assumes @regs is otherwise already 0 filled; this is important for
1176 * things like PERF_SAMPLE_REGS_INTR.
1178 static inline void perf_fetch_caller_regs(struct pt_regs *regs)
1180 perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
1183 static __always_inline void
1184 perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
1186 if (static_key_false(&perf_swevent_enabled[event_id]))
1187 __perf_sw_event(event_id, nr, regs, addr);
1190 DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]);
1193 * 'Special' version for the scheduler, it hard assumes no recursion,
1194 * which is guaranteed by us not actually scheduling inside other swevents
1195 * because those disable preemption.
1197 static __always_inline void __perf_sw_event_sched(u32 event_id, u64 nr, u64 addr)
1199 struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
1201 perf_fetch_caller_regs(regs);
1202 ___perf_sw_event(event_id, nr, regs, addr);
1205 extern struct static_key_false perf_sched_events;
1207 static __always_inline bool __perf_sw_enabled(int swevt)
1209 return static_key_false(&perf_swevent_enabled[swevt]);
1212 static inline void perf_event_task_migrate(struct task_struct *task)
1214 if (__perf_sw_enabled(PERF_COUNT_SW_CPU_MIGRATIONS))
1215 task->sched_migrated = 1;
1218 static inline void perf_event_task_sched_in(struct task_struct *prev,
1219 struct task_struct *task)
1221 if (static_branch_unlikely(&perf_sched_events))
1222 __perf_event_task_sched_in(prev, task);
1224 if (__perf_sw_enabled(PERF_COUNT_SW_CPU_MIGRATIONS) &&
1225 task->sched_migrated) {
1226 __perf_sw_event_sched(PERF_COUNT_SW_CPU_MIGRATIONS, 1, 0);
1227 task->sched_migrated = 0;
1231 static inline void perf_event_task_sched_out(struct task_struct *prev,
1232 struct task_struct *next)
1234 if (__perf_sw_enabled(PERF_COUNT_SW_CONTEXT_SWITCHES))
1235 __perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0);
1237 #ifdef CONFIG_CGROUP_PERF
1238 if (__perf_sw_enabled(PERF_COUNT_SW_CGROUP_SWITCHES) &&
1239 perf_cgroup_from_task(prev, NULL) !=
1240 perf_cgroup_from_task(next, NULL))
1241 __perf_sw_event_sched(PERF_COUNT_SW_CGROUP_SWITCHES, 1, 0);
1244 if (static_branch_unlikely(&perf_sched_events))
1245 __perf_event_task_sched_out(prev, next);
1248 extern void perf_event_mmap(struct vm_area_struct *vma);
1250 extern void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,
1251 bool unregister, const char *sym);
1252 extern void perf_event_bpf_event(struct bpf_prog *prog,
1253 enum perf_bpf_event_type type,
1256 #ifdef CONFIG_GUEST_PERF_EVENTS
1257 extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
1259 DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
1260 DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
1261 DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
1263 static inline unsigned int perf_guest_state(void)
1265 return static_call(__perf_guest_state)();
1267 static inline unsigned long perf_guest_get_ip(void)
1269 return static_call(__perf_guest_get_ip)();
1271 static inline unsigned int perf_guest_handle_intel_pt_intr(void)
1273 return static_call(__perf_guest_handle_intel_pt_intr)();
1275 extern void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
1276 extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs);
1278 static inline unsigned int perf_guest_state(void) { return 0; }
1279 static inline unsigned long perf_guest_get_ip(void) { return 0; }
1280 static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
1281 #endif /* CONFIG_GUEST_PERF_EVENTS */
1283 extern void perf_event_exec(void);
1284 extern void perf_event_comm(struct task_struct *tsk, bool exec);
1285 extern void perf_event_namespaces(struct task_struct *tsk);
1286 extern void perf_event_fork(struct task_struct *tsk);
1287 extern void perf_event_text_poke(const void *addr,
1288 const void *old_bytes, size_t old_len,
1289 const void *new_bytes, size_t new_len);
1292 DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
1294 extern void perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
1295 extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
1296 extern struct perf_callchain_entry *
1297 get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
1298 u32 max_stack, bool crosstask, bool add_mark);
1299 extern struct perf_callchain_entry *perf_callchain(struct perf_event *event, struct pt_regs *regs);
1300 extern int get_callchain_buffers(int max_stack);
1301 extern void put_callchain_buffers(void);
1302 extern struct perf_callchain_entry *get_callchain_entry(int *rctx);
1303 extern void put_callchain_entry(int rctx);
1305 extern int sysctl_perf_event_max_stack;
1306 extern int sysctl_perf_event_max_contexts_per_stack;
1308 static inline int perf_callchain_store_context(struct perf_callchain_entry_ctx *ctx, u64 ip)
1310 if (ctx->contexts < sysctl_perf_event_max_contexts_per_stack) {
1311 struct perf_callchain_entry *entry = ctx->entry;
1312 entry->ip[entry->nr++] = ip;
1316 ctx->contexts_maxed = true;
1317 return -1; /* no more room, stop walking the stack */
1321 static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 ip)
1323 if (ctx->nr < ctx->max_stack && !ctx->contexts_maxed) {
1324 struct perf_callchain_entry *entry = ctx->entry;
1325 entry->ip[entry->nr++] = ip;
1329 return -1; /* no more room, stop walking the stack */
1333 extern int sysctl_perf_event_paranoid;
1334 extern int sysctl_perf_event_mlock;
1335 extern int sysctl_perf_event_sample_rate;
1336 extern int sysctl_perf_cpu_time_max_percent;
1338 extern void perf_sample_event_took(u64 sample_len_ns);
1340 int perf_proc_update_handler(struct ctl_table *table, int write,
1341 void *buffer, size_t *lenp, loff_t *ppos);
1342 int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
1343 void *buffer, size_t *lenp, loff_t *ppos);
1344 int perf_event_max_stack_handler(struct ctl_table *table, int write,
1345 void *buffer, size_t *lenp, loff_t *ppos);
1347 /* Access to perf_event_open(2) syscall. */
1348 #define PERF_SECURITY_OPEN 0
1350 /* Finer grained perf_event_open(2) access control. */
1351 #define PERF_SECURITY_CPU 1
1352 #define PERF_SECURITY_KERNEL 2
1353 #define PERF_SECURITY_TRACEPOINT 3
1355 static inline int perf_is_paranoid(void)
1357 return sysctl_perf_event_paranoid > -1;
1360 static inline int perf_allow_kernel(struct perf_event_attr *attr)
1362 if (sysctl_perf_event_paranoid > 1 && !perfmon_capable())
1365 return security_perf_event_open(attr, PERF_SECURITY_KERNEL);
1368 static inline int perf_allow_cpu(struct perf_event_attr *attr)
1370 if (sysctl_perf_event_paranoid > 0 && !perfmon_capable())
1373 return security_perf_event_open(attr, PERF_SECURITY_CPU);
1376 static inline int perf_allow_tracepoint(struct perf_event_attr *attr)
1378 if (sysctl_perf_event_paranoid > -1 && !perfmon_capable())
1381 return security_perf_event_open(attr, PERF_SECURITY_TRACEPOINT);
1384 extern void perf_event_init(void);
1385 extern void perf_tp_event(u16 event_type, u64 count, void *record,
1386 int entry_size, struct pt_regs *regs,
1387 struct hlist_head *head, int rctx,
1388 struct task_struct *task);
1389 extern void perf_bp_event(struct perf_event *event, void *data);
1391 #ifndef perf_misc_flags
1392 # define perf_misc_flags(regs) \
1393 (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
1394 # define perf_instruction_pointer(regs) instruction_pointer(regs)
1396 #ifndef perf_arch_bpf_user_pt_regs
1397 # define perf_arch_bpf_user_pt_regs(regs) regs
1400 static inline bool has_branch_stack(struct perf_event *event)
1402 return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
1405 static inline bool needs_branch_stack(struct perf_event *event)
1407 return event->attr.branch_sample_type != 0;
1410 static inline bool has_aux(struct perf_event *event)
1412 return event->pmu->setup_aux;
1415 static inline bool is_write_backward(struct perf_event *event)
1417 return !!event->attr.write_backward;
1420 static inline bool has_addr_filter(struct perf_event *event)
1422 return event->pmu->nr_addr_filters;
1426 * An inherited event uses parent's filters
1428 static inline struct perf_addr_filters_head *
1429 perf_event_addr_filters(struct perf_event *event)
1431 struct perf_addr_filters_head *ifh = &event->addr_filters;
1434 ifh = &event->parent->addr_filters;
1439 extern void perf_event_addr_filters_sync(struct perf_event *event);
1440 extern void perf_report_aux_output_id(struct perf_event *event, u64 hw_id);
1442 extern int perf_output_begin(struct perf_output_handle *handle,
1443 struct perf_sample_data *data,
1444 struct perf_event *event, unsigned int size);
1445 extern int perf_output_begin_forward(struct perf_output_handle *handle,
1446 struct perf_sample_data *data,
1447 struct perf_event *event,
1449 extern int perf_output_begin_backward(struct perf_output_handle *handle,
1450 struct perf_sample_data *data,
1451 struct perf_event *event,
1454 extern void perf_output_end(struct perf_output_handle *handle);
1455 extern unsigned int perf_output_copy(struct perf_output_handle *handle,
1456 const void *buf, unsigned int len);
1457 extern unsigned int perf_output_skip(struct perf_output_handle *handle,
1459 extern long perf_output_copy_aux(struct perf_output_handle *aux_handle,
1460 struct perf_output_handle *handle,
1461 unsigned long from, unsigned long to);
1462 extern int perf_swevent_get_recursion_context(void);
1463 extern void perf_swevent_put_recursion_context(int rctx);
1464 extern u64 perf_swevent_set_period(struct perf_event *event);
1465 extern void perf_event_enable(struct perf_event *event);
1466 extern void perf_event_disable(struct perf_event *event);
1467 extern void perf_event_disable_local(struct perf_event *event);
1468 extern void perf_event_disable_inatomic(struct perf_event *event);
1469 extern void perf_event_task_tick(void);
1470 extern int perf_event_account_interrupt(struct perf_event *event);
1471 extern int perf_event_period(struct perf_event *event, u64 value);
1472 extern u64 perf_event_pause(struct perf_event *event, bool reset);
1473 #else /* !CONFIG_PERF_EVENTS: */
1474 static inline void *
1475 perf_aux_output_begin(struct perf_output_handle *handle,
1476 struct perf_event *event) { return NULL; }
1478 perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
1481 perf_aux_output_skip(struct perf_output_handle *handle,
1482 unsigned long size) { return -EINVAL; }
1483 static inline void *
1484 perf_get_aux(struct perf_output_handle *handle) { return NULL; }
1486 perf_event_task_migrate(struct task_struct *task) { }
1488 perf_event_task_sched_in(struct task_struct *prev,
1489 struct task_struct *task) { }
1491 perf_event_task_sched_out(struct task_struct *prev,
1492 struct task_struct *next) { }
1493 static inline int perf_event_init_task(struct task_struct *child,
1494 u64 clone_flags) { return 0; }
1495 static inline void perf_event_exit_task(struct task_struct *child) { }
1496 static inline void perf_event_free_task(struct task_struct *task) { }
1497 static inline void perf_event_delayed_put(struct task_struct *task) { }
1498 static inline struct file *perf_event_get(unsigned int fd) { return ERR_PTR(-EINVAL); }
1499 static inline const struct perf_event *perf_get_event(struct file *file)
1501 return ERR_PTR(-EINVAL);
1503 static inline const struct perf_event_attr *perf_event_attrs(struct perf_event *event)
1505 return ERR_PTR(-EINVAL);
1507 static inline int perf_event_read_local(struct perf_event *event, u64 *value,
1508 u64 *enabled, u64 *running)
1512 static inline void perf_event_print_debug(void) { }
1513 static inline int perf_event_task_disable(void) { return -EINVAL; }
1514 static inline int perf_event_task_enable(void) { return -EINVAL; }
1515 static inline int perf_event_refresh(struct perf_event *event, int refresh)
1521 perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
1523 perf_bp_event(struct perf_event *event, void *data) { }
1525 static inline void perf_event_mmap(struct vm_area_struct *vma) { }
1527 typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data);
1528 static inline void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,
1529 bool unregister, const char *sym) { }
1530 static inline void perf_event_bpf_event(struct bpf_prog *prog,
1531 enum perf_bpf_event_type type,
1533 static inline void perf_event_exec(void) { }
1534 static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
1535 static inline void perf_event_namespaces(struct task_struct *tsk) { }
1536 static inline void perf_event_fork(struct task_struct *tsk) { }
1537 static inline void perf_event_text_poke(const void *addr,
1538 const void *old_bytes,
1540 const void *new_bytes,
1542 static inline void perf_event_init(void) { }
1543 static inline int perf_swevent_get_recursion_context(void) { return -1; }
1544 static inline void perf_swevent_put_recursion_context(int rctx) { }
1545 static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; }
1546 static inline void perf_event_enable(struct perf_event *event) { }
1547 static inline void perf_event_disable(struct perf_event *event) { }
1548 static inline int __perf_event_disable(void *info) { return -1; }
1549 static inline void perf_event_task_tick(void) { }
1550 static inline int perf_event_release_kernel(struct perf_event *event) { return 0; }
1551 static inline int perf_event_period(struct perf_event *event, u64 value)
1555 static inline u64 perf_event_pause(struct perf_event *event, bool reset)
1561 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
1562 extern void perf_restore_debug_store(void);
1564 static inline void perf_restore_debug_store(void) { }
1567 static __always_inline bool perf_raw_frag_last(const struct perf_raw_frag *frag)
1569 return frag->pad < sizeof(u64);
1572 #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
1574 struct perf_pmu_events_attr {
1575 struct device_attribute attr;
1577 const char *event_str;
1580 struct perf_pmu_events_ht_attr {
1581 struct device_attribute attr;
1583 const char *event_str_ht;
1584 const char *event_str_noht;
1587 struct perf_pmu_events_hybrid_attr {
1588 struct device_attribute attr;
1590 const char *event_str;
1594 struct perf_pmu_format_hybrid_attr {
1595 struct device_attribute attr;
1599 ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
1602 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
1603 static struct perf_pmu_events_attr _var = { \
1604 .attr = __ATTR(_name, 0444, _show, NULL), \
1608 #define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
1609 static struct perf_pmu_events_attr _var = { \
1610 .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \
1612 .event_str = _str, \
1615 #define PMU_EVENT_ATTR_ID(_name, _show, _id) \
1616 (&((struct perf_pmu_events_attr[]) { \
1617 { .attr = __ATTR(_name, 0444, _show, NULL), \
1621 #define PMU_FORMAT_ATTR(_name, _format) \
1623 _name##_show(struct device *dev, \
1624 struct device_attribute *attr, \
1627 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
1628 return sprintf(page, _format "\n"); \
1631 static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
1633 /* Performance counter hotplug functions */
1634 #ifdef CONFIG_PERF_EVENTS
1635 int perf_event_init_cpu(unsigned int cpu);
1636 int perf_event_exit_cpu(unsigned int cpu);
1638 #define perf_event_init_cpu NULL
1639 #define perf_event_exit_cpu NULL
1642 extern void __weak arch_perf_update_userpage(struct perf_event *event,
1643 struct perf_event_mmap_page *userpg,
1647 extern __weak u64 arch_perf_get_page_size(struct mm_struct *mm, unsigned long addr);
1651 * Snapshot branch stack on software events.
1653 * Branch stack can be very useful in understanding software events. For
1654 * example, when a long function, e.g. sys_perf_event_open, returns an
1655 * errno, it is not obvious why the function failed. Branch stack could
1656 * provide very helpful information in this type of scenarios.
1658 * On software event, it is necessary to stop the hardware branch recorder
1659 * fast. Otherwise, the hardware register/buffer will be flushed with
1660 * entries of the triggering event. Therefore, static call is used to
1661 * stop the hardware recorder.
1665 * cnt is the number of entries allocated for entries.
1666 * Return number of entries copied to .
1668 typedef int (perf_snapshot_branch_stack_t)(struct perf_branch_entry *entries,
1670 DECLARE_STATIC_CALL(perf_snapshot_branch_stack, perf_snapshot_branch_stack_t);
1672 #endif /* _LINUX_PERF_EVENT_H */