1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _LINUX_PERF_EVENT_H
15#define _LINUX_PERF_EVENT_H
16
17#include <uapi/linux/perf_event.h>
18
19
20
21
22
23#ifdef CONFIG_PERF_EVENTS
24# include <asm/perf_event.h>
25# include <asm/local64.h>
26#endif
27
28struct perf_guest_info_callbacks {
29 int (*is_in_guest)(void);
30 int (*is_user_mode)(void);
31 unsigned long (*get_guest_ip)(void);
32};
33
34#ifdef CONFIG_HAVE_HW_BREAKPOINT
35#include <asm/hw_breakpoint.h>
36#endif
37
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>
44#include <linux/fs.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>
58
59struct perf_callchain_entry {
60 __u64 nr;
61 __u64 ip[PERF_MAX_STACK_DEPTH];
62};
63
64struct perf_raw_record {
65 u32 size;
66 void *data;
67};
68
69
70
71
72
73
74
75
76
77
78struct perf_branch_stack {
79 __u64 nr;
80 struct perf_branch_entry entries[0];
81};
82
83struct task_struct;
84
85
86
87
88struct hw_perf_event_extra {
89 u64 config;
90 unsigned int reg;
91 int alloc;
92 int idx;
93};
94
95
96
97
98struct hw_perf_event {
99#ifdef CONFIG_PERF_EVENTS
100 union {
101 struct {
102 u64 config;
103 u64 last_tag;
104 unsigned long config_base;
105 unsigned long event_base;
106 int event_base_rdpmc;
107 int idx;
108 int last_cpu;
109 int flags;
110
111 struct hw_perf_event_extra extra_reg;
112 struct hw_perf_event_extra branch_reg;
113 };
114 struct {
115 struct hrtimer hrtimer;
116 };
117 struct {
118
119 struct list_head tp_list;
120 };
121 struct {
122 int cqm_state;
123 u32 cqm_rmid;
124 int is_group_event;
125 struct list_head cqm_events_entry;
126 struct list_head cqm_groups_entry;
127 struct list_head cqm_group_entry;
128 };
129 struct {
130 int itrace_started;
131 };
132 struct {
133 u64 pwr_acc;
134 u64 ptsc;
135 };
136#ifdef CONFIG_HAVE_HW_BREAKPOINT
137 struct {
138
139
140
141
142
143 struct arch_hw_breakpoint info;
144 struct list_head bp_list;
145 };
146#endif
147 };
148
149
150
151
152 struct task_struct *target;
153
154
155
156
157#define PERF_HES_STOPPED 0x01
158#define PERF_HES_UPTODATE 0x02
159#define PERF_HES_ARCH 0x04
160
161 int state;
162
163
164
165
166
167 local64_t prev_count;
168
169
170
171
172 u64 sample_period;
173
174
175
176
177 u64 last_period;
178
179
180
181
182
183
184 local64_t period_left;
185
186
187
188
189
190 u64 interrupts_seq;
191 u64 interrupts;
192
193
194
195
196
197 u64 freq_time_stamp;
198 u64 freq_count_stamp;
199#endif
200};
201
202struct perf_event;
203
204
205
206
207#define PERF_PMU_TXN_ADD 0x1
208#define PERF_PMU_TXN_READ 0x2
209
210
211
212
213#define PERF_PMU_CAP_NO_INTERRUPT 0x01
214#define PERF_PMU_CAP_NO_NMI 0x02
215#define PERF_PMU_CAP_AUX_NO_SG 0x04
216#define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08
217#define PERF_PMU_CAP_EXCLUSIVE 0x10
218#define PERF_PMU_CAP_ITRACE 0x20
219
220
221
222
223struct pmu {
224 struct list_head entry;
225
226 struct module *module;
227 struct device *dev;
228 const struct attribute_group **attr_groups;
229 const char *name;
230 int type;
231
232
233
234
235 int capabilities;
236
237 int * __percpu pmu_disable_count;
238 struct perf_cpu_context * __percpu pmu_cpu_context;
239 atomic_t exclusive_cnt;
240 int task_ctx_nr;
241 int hrtimer_interval_ms;
242
243
244
245
246
247 void (*pmu_enable) (struct pmu *pmu);
248 void (*pmu_disable) (struct pmu *pmu);
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266 int (*event_init) (struct perf_event *event);
267
268
269
270
271
272 void (*event_mapped) (struct perf_event *event);
273 void (*event_unmapped) (struct perf_event *event);
274
275
276
277
278
279#define PERF_EF_START 0x01
280#define PERF_EF_RELOAD 0x02
281#define PERF_EF_UPDATE 0x04
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301 int (*add) (struct perf_event *event, int flags);
302 void (*del) (struct perf_event *event, int flags);
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 void (*start) (struct perf_event *event, int flags);
323 void (*stop) (struct perf_event *event, int flags);
324
325
326
327
328
329
330
331 void (*read) (struct perf_event *event);
332
333
334
335
336
337
338
339
340
341
342
343 void (*start_txn) (struct pmu *pmu, unsigned int txn_flags);
344
345
346
347
348
349
350
351
352 int (*commit_txn) (struct pmu *pmu);
353
354
355
356
357
358
359 void (*cancel_txn) (struct pmu *pmu);
360
361
362
363
364
365 int (*event_idx) (struct perf_event *event);
366
367
368
369
370 void (*sched_task) (struct perf_event_context *ctx,
371 bool sched_in);
372
373
374
375 size_t task_ctx_size;
376
377
378
379
380
381 u64 (*count) (struct perf_event *event);
382
383
384
385
386 void *(*setup_aux) (int cpu, void **pages,
387 int nr_pages, bool overwrite);
388
389
390
391
392
393 void (*free_aux) (void *aux);
394
395
396
397
398 int (*filter_match) (struct perf_event *event);
399};
400
401
402
403
404enum perf_event_active_state {
405 PERF_EVENT_STATE_DEAD = -4,
406 PERF_EVENT_STATE_EXIT = -3,
407 PERF_EVENT_STATE_ERROR = -2,
408 PERF_EVENT_STATE_OFF = -1,
409 PERF_EVENT_STATE_INACTIVE = 0,
410 PERF_EVENT_STATE_ACTIVE = 1,
411};
412
413struct file;
414struct perf_sample_data;
415
416typedef void (*perf_overflow_handler_t)(struct perf_event *,
417 struct perf_sample_data *,
418 struct pt_regs *regs);
419
420enum perf_group_flag {
421 PERF_GROUP_SOFTWARE = 0x1,
422};
423
424#define SWEVENT_HLIST_BITS 8
425#define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
426
427struct swevent_hlist {
428 struct hlist_head heads[SWEVENT_HLIST_SIZE];
429 struct rcu_head rcu_head;
430};
431
432#define PERF_ATTACH_CONTEXT 0x01
433#define PERF_ATTACH_GROUP 0x02
434#define PERF_ATTACH_TASK 0x04
435#define PERF_ATTACH_TASK_DATA 0x08
436
437struct perf_cgroup;
438struct ring_buffer;
439
440
441
442
443struct perf_event {
444#ifdef CONFIG_PERF_EVENTS
445
446
447
448
449
450 struct list_head event_entry;
451
452
453
454
455
456
457
458
459
460 struct list_head group_entry;
461 struct list_head sibling_list;
462
463
464
465
466
467
468 struct list_head migrate_entry;
469
470 struct hlist_node hlist_entry;
471 struct list_head active_entry;
472 int nr_siblings;
473 int group_flags;
474 struct perf_event *group_leader;
475 struct pmu *pmu;
476 void *pmu_private;
477
478 enum perf_event_active_state state;
479 unsigned int attach_state;
480 local64_t count;
481 atomic64_t child_count;
482
483
484
485
486
487
488
489
490
491
492 u64 total_time_enabled;
493 u64 total_time_running;
494
495
496
497
498
499
500
501
502
503
504
505 u64 tstamp_enabled;
506 u64 tstamp_running;
507 u64 tstamp_stopped;
508
509
510
511
512
513
514
515
516
517 u64 shadow_ctx_time;
518
519 struct perf_event_attr attr;
520 u16 header_size;
521 u16 id_header_size;
522 u16 read_size;
523 struct hw_perf_event hw;
524
525 struct perf_event_context *ctx;
526 atomic_long_t refcount;
527
528
529
530
531
532 atomic64_t child_total_time_enabled;
533 atomic64_t child_total_time_running;
534
535
536
537
538 struct mutex child_mutex;
539 struct list_head child_list;
540 struct perf_event *parent;
541
542 int oncpu;
543 int cpu;
544
545 struct list_head owner_entry;
546 struct task_struct *owner;
547
548
549 struct mutex mmap_mutex;
550 atomic_t mmap_count;
551
552 struct ring_buffer *rb;
553 struct list_head rb_entry;
554 unsigned long rcu_batches;
555 int rcu_pending;
556
557
558 wait_queue_head_t waitq;
559 struct fasync_struct *fasync;
560
561
562 int pending_wakeup;
563 int pending_kill;
564 int pending_disable;
565 struct irq_work pending;
566
567 atomic_t event_limit;
568
569 void (*destroy)(struct perf_event *);
570 struct rcu_head rcu_head;
571
572 struct pid_namespace *ns;
573 u64 id;
574
575 u64 (*clock)(void);
576 perf_overflow_handler_t overflow_handler;
577 void *overflow_handler_context;
578
579#ifdef CONFIG_EVENT_TRACING
580 struct trace_event_call *tp_event;
581 struct event_filter *filter;
582#ifdef CONFIG_FUNCTION_TRACER
583 struct ftrace_ops ftrace_ops;
584#endif
585#endif
586
587#ifdef CONFIG_CGROUP_PERF
588 struct perf_cgroup *cgrp;
589 int cgrp_defer_enabled;
590#endif
591
592#endif
593};
594
595
596
597
598
599
600struct perf_event_context {
601 struct pmu *pmu;
602
603
604
605
606 raw_spinlock_t lock;
607
608
609
610
611
612 struct mutex mutex;
613
614 struct list_head active_ctx_list;
615 struct list_head pinned_groups;
616 struct list_head flexible_groups;
617 struct list_head event_list;
618 int nr_events;
619 int nr_active;
620 int is_active;
621 int nr_stat;
622 int nr_freq;
623 int rotate_disable;
624 atomic_t refcount;
625 struct task_struct *task;
626
627
628
629
630 u64 time;
631 u64 timestamp;
632
633
634
635
636
637 struct perf_event_context *parent_ctx;
638 u64 parent_gen;
639 u64 generation;
640 int pin_count;
641 int nr_cgroups;
642 void *task_ctx_data;
643 struct rcu_head rcu_head;
644};
645
646
647
648
649
650#define PERF_NR_CONTEXTS 4
651
652
653
654
655struct perf_cpu_context {
656 struct perf_event_context ctx;
657 struct perf_event_context *task_ctx;
658 int active_oncpu;
659 int exclusive;
660
661 raw_spinlock_t hrtimer_lock;
662 struct hrtimer hrtimer;
663 ktime_t hrtimer_interval;
664 unsigned int hrtimer_active;
665
666 struct pmu *unique_pmu;
667 struct perf_cgroup *cgrp;
668};
669
670struct perf_output_handle {
671 struct perf_event *event;
672 struct ring_buffer *rb;
673 unsigned long wakeup;
674 unsigned long size;
675 union {
676 void *addr;
677 unsigned long head;
678 };
679 int page;
680};
681
682#ifdef CONFIG_CGROUP_PERF
683
684
685
686
687
688struct perf_cgroup_info {
689 u64 time;
690 u64 timestamp;
691};
692
693struct perf_cgroup {
694 struct cgroup_subsys_state css;
695 struct perf_cgroup_info __percpu *info;
696};
697
698
699
700
701
702
703static inline struct perf_cgroup *
704perf_cgroup_from_task(struct task_struct *task, struct perf_event_context *ctx)
705{
706 return container_of(task_css_check(task, perf_event_cgrp_id,
707 ctx ? lockdep_is_held(&ctx->lock)
708 : true),
709 struct perf_cgroup, css);
710}
711#endif
712
713#ifdef CONFIG_PERF_EVENTS
714
715extern void *perf_aux_output_begin(struct perf_output_handle *handle,
716 struct perf_event *event);
717extern void perf_aux_output_end(struct perf_output_handle *handle,
718 unsigned long size, bool truncated);
719extern int perf_aux_output_skip(struct perf_output_handle *handle,
720 unsigned long size);
721extern void *perf_get_aux(struct perf_output_handle *handle);
722
723extern int perf_pmu_register(struct pmu *pmu, const char *name, int type);
724extern void perf_pmu_unregister(struct pmu *pmu);
725
726extern int perf_num_counters(void);
727extern const char *perf_pmu_name(void);
728extern void __perf_event_task_sched_in(struct task_struct *prev,
729 struct task_struct *task);
730extern void __perf_event_task_sched_out(struct task_struct *prev,
731 struct task_struct *next);
732extern int perf_event_init_task(struct task_struct *child);
733extern void perf_event_exit_task(struct task_struct *child);
734extern void perf_event_free_task(struct task_struct *task);
735extern void perf_event_delayed_put(struct task_struct *task);
736extern struct file *perf_event_get(unsigned int fd);
737extern const struct perf_event_attr *perf_event_attrs(struct perf_event *event);
738extern void perf_event_print_debug(void);
739extern void perf_pmu_disable(struct pmu *pmu);
740extern void perf_pmu_enable(struct pmu *pmu);
741extern void perf_sched_cb_dec(struct pmu *pmu);
742extern void perf_sched_cb_inc(struct pmu *pmu);
743extern int perf_event_task_disable(void);
744extern int perf_event_task_enable(void);
745extern int perf_event_refresh(struct perf_event *event, int refresh);
746extern void perf_event_update_userpage(struct perf_event *event);
747extern int perf_event_release_kernel(struct perf_event *event);
748extern struct perf_event *
749perf_event_create_kernel_counter(struct perf_event_attr *attr,
750 int cpu,
751 struct task_struct *task,
752 perf_overflow_handler_t callback,
753 void *context);
754extern void perf_pmu_migrate_context(struct pmu *pmu,
755 int src_cpu, int dst_cpu);
756extern u64 perf_event_read_local(struct perf_event *event);
757extern u64 perf_event_read_value(struct perf_event *event,
758 u64 *enabled, u64 *running);
759
760
761struct perf_sample_data {
762
763
764
765
766 u64 addr;
767 struct perf_raw_record *raw;
768 struct perf_branch_stack *br_stack;
769 u64 period;
770 u64 weight;
771 u64 txn;
772 union perf_mem_data_src data_src;
773
774
775
776
777
778 u64 type;
779 u64 ip;
780 struct {
781 u32 pid;
782 u32 tid;
783 } tid_entry;
784 u64 time;
785 u64 id;
786 u64 stream_id;
787 struct {
788 u32 cpu;
789 u32 reserved;
790 } cpu_entry;
791 struct perf_callchain_entry *callchain;
792
793
794
795
796
797 struct perf_regs regs_user;
798 struct pt_regs regs_user_copy;
799
800 struct perf_regs regs_intr;
801 u64 stack_user_size;
802} ____cacheline_aligned;
803
804
805#define PERF_MEM_NA (PERF_MEM_S(OP, NA) |\
806 PERF_MEM_S(LVL, NA) |\
807 PERF_MEM_S(SNOOP, NA) |\
808 PERF_MEM_S(LOCK, NA) |\
809 PERF_MEM_S(TLB, NA))
810
811static inline void perf_sample_data_init(struct perf_sample_data *data,
812 u64 addr, u64 period)
813{
814
815 data->addr = addr;
816 data->raw = NULL;
817 data->br_stack = NULL;
818 data->period = period;
819 data->weight = 0;
820 data->data_src.val = PERF_MEM_NA;
821 data->txn = 0;
822}
823
824extern void perf_output_sample(struct perf_output_handle *handle,
825 struct perf_event_header *header,
826 struct perf_sample_data *data,
827 struct perf_event *event);
828extern void perf_prepare_sample(struct perf_event_header *header,
829 struct perf_sample_data *data,
830 struct perf_event *event,
831 struct pt_regs *regs);
832
833extern int perf_event_overflow(struct perf_event *event,
834 struct perf_sample_data *data,
835 struct pt_regs *regs);
836
837extern void perf_event_output(struct perf_event *event,
838 struct perf_sample_data *data,
839 struct pt_regs *regs);
840
841extern void
842perf_event_header__init_id(struct perf_event_header *header,
843 struct perf_sample_data *data,
844 struct perf_event *event);
845extern void
846perf_event__output_id_sample(struct perf_event *event,
847 struct perf_output_handle *handle,
848 struct perf_sample_data *sample);
849
850extern void
851perf_log_lost_samples(struct perf_event *event, u64 lost);
852
853static inline bool is_sampling_event(struct perf_event *event)
854{
855 return event->attr.sample_period != 0;
856}
857
858
859
860
861static inline int is_software_event(struct perf_event *event)
862{
863 return event->pmu->task_ctx_nr == perf_sw_context;
864}
865
866extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
867
868extern void ___perf_sw_event(u32, u64, struct pt_regs *, u64);
869extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
870
871#ifndef perf_arch_fetch_caller_regs
872static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
873#endif
874
875
876
877
878
879
880
881
882
883static inline void perf_fetch_caller_regs(struct pt_regs *regs)
884{
885 memset(regs, 0, sizeof(*regs));
886
887 perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
888}
889
890static __always_inline void
891perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
892{
893 if (static_key_false(&perf_swevent_enabled[event_id]))
894 __perf_sw_event(event_id, nr, regs, addr);
895}
896
897DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]);
898
899
900
901
902
903
904static __always_inline void
905perf_sw_event_sched(u32 event_id, u64 nr, u64 addr)
906{
907 if (static_key_false(&perf_swevent_enabled[event_id])) {
908 struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
909
910 perf_fetch_caller_regs(regs);
911 ___perf_sw_event(event_id, nr, regs, addr);
912 }
913}
914
915extern struct static_key_false perf_sched_events;
916
917static __always_inline bool
918perf_sw_migrate_enabled(void)
919{
920 if (static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_CPU_MIGRATIONS]))
921 return true;
922 return false;
923}
924
925static inline void perf_event_task_migrate(struct task_struct *task)
926{
927 if (perf_sw_migrate_enabled())
928 task->sched_migrated = 1;
929}
930
931static inline void perf_event_task_sched_in(struct task_struct *prev,
932 struct task_struct *task)
933{
934 if (static_branch_unlikely(&perf_sched_events))
935 __perf_event_task_sched_in(prev, task);
936
937 if (perf_sw_migrate_enabled() && task->sched_migrated) {
938 struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
939
940 perf_fetch_caller_regs(regs);
941 ___perf_sw_event(PERF_COUNT_SW_CPU_MIGRATIONS, 1, regs, 0);
942 task->sched_migrated = 0;
943 }
944}
945
946static inline void perf_event_task_sched_out(struct task_struct *prev,
947 struct task_struct *next)
948{
949 perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0);
950
951 if (static_branch_unlikely(&perf_sched_events))
952 __perf_event_task_sched_out(prev, next);
953}
954
955static inline u64 __perf_event_count(struct perf_event *event)
956{
957 return local64_read(&event->count) + atomic64_read(&event->child_count);
958}
959
960extern void perf_event_mmap(struct vm_area_struct *vma);
961extern struct perf_guest_info_callbacks *perf_guest_cbs;
962extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
963extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
964
965extern void perf_event_exec(void);
966extern void perf_event_comm(struct task_struct *tsk, bool exec);
967extern void perf_event_fork(struct task_struct *tsk);
968
969
970DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
971
972extern void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs);
973extern void perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs);
974extern struct perf_callchain_entry *
975get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
976 bool crosstask, bool add_mark);
977extern int get_callchain_buffers(void);
978extern void put_callchain_buffers(void);
979
980static inline int perf_callchain_store(struct perf_callchain_entry *entry, u64 ip)
981{
982 if (entry->nr < PERF_MAX_STACK_DEPTH) {
983 entry->ip[entry->nr++] = ip;
984 return 0;
985 } else {
986 return -1;
987 }
988}
989
990extern int sysctl_perf_event_paranoid;
991extern int sysctl_perf_event_mlock;
992extern int sysctl_perf_event_sample_rate;
993extern int sysctl_perf_cpu_time_max_percent;
994
995extern void perf_sample_event_took(u64 sample_len_ns);
996
997extern int perf_proc_update_handler(struct ctl_table *table, int write,
998 void __user *buffer, size_t *lenp,
999 loff_t *ppos);
1000extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
1001 void __user *buffer, size_t *lenp,
1002 loff_t *ppos);
1003
1004
1005static inline bool perf_paranoid_tracepoint_raw(void)
1006{
1007 return sysctl_perf_event_paranoid > -1;
1008}
1009
1010static inline bool perf_paranoid_cpu(void)
1011{
1012 return sysctl_perf_event_paranoid > 0;
1013}
1014
1015static inline bool perf_paranoid_kernel(void)
1016{
1017 return sysctl_perf_event_paranoid > 1;
1018}
1019
1020extern void perf_event_init(void);
1021extern void perf_tp_event(u64 addr, u64 count, void *record,
1022 int entry_size, struct pt_regs *regs,
1023 struct hlist_head *head, int rctx,
1024 struct task_struct *task);
1025extern void perf_bp_event(struct perf_event *event, void *data);
1026
1027#ifndef perf_misc_flags
1028# define perf_misc_flags(regs) \
1029 (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
1030# define perf_instruction_pointer(regs) instruction_pointer(regs)
1031#endif
1032
1033static inline bool has_branch_stack(struct perf_event *event)
1034{
1035 return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
1036}
1037
1038static inline bool needs_branch_stack(struct perf_event *event)
1039{
1040 return event->attr.branch_sample_type != 0;
1041}
1042
1043static inline bool has_aux(struct perf_event *event)
1044{
1045 return event->pmu->setup_aux;
1046}
1047
1048extern int perf_output_begin(struct perf_output_handle *handle,
1049 struct perf_event *event, unsigned int size);
1050extern void perf_output_end(struct perf_output_handle *handle);
1051extern unsigned int perf_output_copy(struct perf_output_handle *handle,
1052 const void *buf, unsigned int len);
1053extern unsigned int perf_output_skip(struct perf_output_handle *handle,
1054 unsigned int len);
1055extern int perf_swevent_get_recursion_context(void);
1056extern void perf_swevent_put_recursion_context(int rctx);
1057extern u64 perf_swevent_set_period(struct perf_event *event);
1058extern void perf_event_enable(struct perf_event *event);
1059extern void perf_event_disable(struct perf_event *event);
1060extern void perf_event_disable_local(struct perf_event *event);
1061extern void perf_event_task_tick(void);
1062#else
1063static inline void *
1064perf_aux_output_begin(struct perf_output_handle *handle,
1065 struct perf_event *event) { return NULL; }
1066static inline void
1067perf_aux_output_end(struct perf_output_handle *handle, unsigned long size,
1068 bool truncated) { }
1069static inline int
1070perf_aux_output_skip(struct perf_output_handle *handle,
1071 unsigned long size) { return -EINVAL; }
1072static inline void *
1073perf_get_aux(struct perf_output_handle *handle) { return NULL; }
1074static inline void
1075perf_event_task_migrate(struct task_struct *task) { }
1076static inline void
1077perf_event_task_sched_in(struct task_struct *prev,
1078 struct task_struct *task) { }
1079static inline void
1080perf_event_task_sched_out(struct task_struct *prev,
1081 struct task_struct *next) { }
1082static inline int perf_event_init_task(struct task_struct *child) { return 0; }
1083static inline void perf_event_exit_task(struct task_struct *child) { }
1084static inline void perf_event_free_task(struct task_struct *task) { }
1085static inline void perf_event_delayed_put(struct task_struct *task) { }
1086static inline struct file *perf_event_get(unsigned int fd) { return ERR_PTR(-EINVAL); }
1087static inline const struct perf_event_attr *perf_event_attrs(struct perf_event *event)
1088{
1089 return ERR_PTR(-EINVAL);
1090}
1091static inline u64 perf_event_read_local(struct perf_event *event) { return -EINVAL; }
1092static inline void perf_event_print_debug(void) { }
1093static inline int perf_event_task_disable(void) { return -EINVAL; }
1094static inline int perf_event_task_enable(void) { return -EINVAL; }
1095static inline int perf_event_refresh(struct perf_event *event, int refresh)
1096{
1097 return -EINVAL;
1098}
1099
1100static inline void
1101perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
1102static inline void
1103perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) { }
1104static inline void
1105perf_bp_event(struct perf_event *event, void *data) { }
1106
1107static inline int perf_register_guest_info_callbacks
1108(struct perf_guest_info_callbacks *callbacks) { return 0; }
1109static inline int perf_unregister_guest_info_callbacks
1110(struct perf_guest_info_callbacks *callbacks) { return 0; }
1111
1112static inline void perf_event_mmap(struct vm_area_struct *vma) { }
1113static inline void perf_event_exec(void) { }
1114static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
1115static inline void perf_event_fork(struct task_struct *tsk) { }
1116static inline void perf_event_init(void) { }
1117static inline int perf_swevent_get_recursion_context(void) { return -1; }
1118static inline void perf_swevent_put_recursion_context(int rctx) { }
1119static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; }
1120static inline void perf_event_enable(struct perf_event *event) { }
1121static inline void perf_event_disable(struct perf_event *event) { }
1122static inline int __perf_event_disable(void *info) { return -1; }
1123static inline void perf_event_task_tick(void) { }
1124static inline int perf_event_release_kernel(struct perf_event *event) { return 0; }
1125#endif
1126
1127#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
1128extern void perf_restore_debug_store(void);
1129#else
1130static inline void perf_restore_debug_store(void) { }
1131#endif
1132
1133#define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
1134
1135
1136
1137
1138#define perf_cpu_notifier(fn) \
1139do { \
1140 static struct notifier_block fn##_nb = \
1141 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
1142 unsigned long cpu = smp_processor_id(); \
1143 unsigned long flags; \
1144 \
1145 cpu_notifier_register_begin(); \
1146 fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE, \
1147 (void *)(unsigned long)cpu); \
1148 local_irq_save(flags); \
1149 fn(&fn##_nb, (unsigned long)CPU_STARTING, \
1150 (void *)(unsigned long)cpu); \
1151 local_irq_restore(flags); \
1152 fn(&fn##_nb, (unsigned long)CPU_ONLINE, \
1153 (void *)(unsigned long)cpu); \
1154 __register_cpu_notifier(&fn##_nb); \
1155 cpu_notifier_register_done(); \
1156} while (0)
1157
1158
1159
1160
1161
1162#define __perf_cpu_notifier(fn) \
1163do { \
1164 static struct notifier_block fn##_nb = \
1165 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
1166 \
1167 __register_cpu_notifier(&fn##_nb); \
1168} while (0)
1169
1170struct perf_pmu_events_attr {
1171 struct device_attribute attr;
1172 u64 id;
1173 const char *event_str;
1174};
1175
1176ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
1177 char *page);
1178
1179#define PMU_EVENT_ATTR(_name, _var, _id, _show) \
1180static struct perf_pmu_events_attr _var = { \
1181 .attr = __ATTR(_name, 0444, _show, NULL), \
1182 .id = _id, \
1183};
1184
1185#define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
1186static struct perf_pmu_events_attr _var = { \
1187 .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \
1188 .id = 0, \
1189 .event_str = _str, \
1190};
1191
1192#define PMU_FORMAT_ATTR(_name, _format) \
1193static ssize_t \
1194_name##_show(struct device *dev, \
1195 struct device_attribute *attr, \
1196 char *page) \
1197{ \
1198 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
1199 return sprintf(page, _format "\n"); \
1200} \
1201 \
1202static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
1203
1204#endif
1205