1 /* 2 * Performance events: 3 * 4 * Copyright (C) 2008-2009, Thomas Gleixner <[email protected]> 5 * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar 6 * Copyright (C) 2008-2009, Red Hat, Inc., Peter Zijlstra 7 * 8 * Data type definitions, declarations, prototypes. 9 * 10 * Started by: Thomas Gleixner and Ingo Molnar 11 * 12 * For licencing details see kernel-base/COPYING 13 */ 14 #ifndef _LINUX_PERF_EVENT_H 15 #define _LINUX_PERF_EVENT_H 16 17 #include <linux/types.h> 18 #include <linux/ioctl.h> 19 #include <asm/byteorder.h> 20 21 #ifdef CONFIG_HAVE_HW_BREAKPOINT 22 #include <asm/hw_breakpoint.h> 23 #endif 24 25 /* 26 * User-space ABI bits: 27 */ 28 29 /* 30 * attr.type 31 */ 32 enum perf_type_id { 33 PERF_TYPE_HARDWARE = 0, 34 PERF_TYPE_SOFTWARE = 1, 35 PERF_TYPE_TRACEPOINT = 2, 36 PERF_TYPE_HW_CACHE = 3, 37 PERF_TYPE_RAW = 4, 38 PERF_TYPE_BREAKPOINT = 5, 39 40 PERF_TYPE_MAX, /* non-ABI */ 41 }; 42 43 /* 44 * Generalized performance event event_id types, used by the 45 * attr.event_id parameter of the sys_perf_event_open() 46 * syscall: 47 */ 48 enum perf_hw_id { 49 /* 50 * Common hardware events, generalized by the kernel: 51 */ 52 PERF_COUNT_HW_CPU_CYCLES = 0, 53 PERF_COUNT_HW_INSTRUCTIONS = 1, 54 PERF_COUNT_HW_CACHE_REFERENCES = 2, 55 PERF_COUNT_HW_CACHE_MISSES = 3, 56 PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4, 57 PERF_COUNT_HW_BRANCH_MISSES = 5, 58 PERF_COUNT_HW_BUS_CYCLES = 6, 59 60 PERF_COUNT_HW_MAX, /* non-ABI */ 61 }; 62 63 /* 64 * Generalized hardware cache events: 65 * 66 * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x 67 * { read, write, prefetch } x 68 * { accesses, misses } 69 */ 70 enum perf_hw_cache_id { 71 PERF_COUNT_HW_CACHE_L1D = 0, 72 PERF_COUNT_HW_CACHE_L1I = 1, 73 PERF_COUNT_HW_CACHE_LL = 2, 74 PERF_COUNT_HW_CACHE_DTLB = 3, 75 PERF_COUNT_HW_CACHE_ITLB = 4, 76 PERF_COUNT_HW_CACHE_BPU = 5, 77 78 PERF_COUNT_HW_CACHE_MAX, /* non-ABI */ 79 }; 80 81 enum perf_hw_cache_op_id { 82 PERF_COUNT_HW_CACHE_OP_READ = 0, 83 PERF_COUNT_HW_CACHE_OP_WRITE = 1, 84 PERF_COUNT_HW_CACHE_OP_PREFETCH = 2, 85 86 PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */ 87 }; 88 89 enum perf_hw_cache_op_result_id { 90 PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0, 91 PERF_COUNT_HW_CACHE_RESULT_MISS = 1, 92 93 PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */ 94 }; 95 96 /* 97 * Special "software" events provided by the kernel, even if the hardware 98 * does not support performance events. These events measure various 99 * physical and sw events of the kernel (and allow the profiling of them as 100 * well): 101 */ 102 enum perf_sw_ids { 103 PERF_COUNT_SW_CPU_CLOCK = 0, 104 PERF_COUNT_SW_TASK_CLOCK = 1, 105 PERF_COUNT_SW_PAGE_FAULTS = 2, 106 PERF_COUNT_SW_CONTEXT_SWITCHES = 3, 107 PERF_COUNT_SW_CPU_MIGRATIONS = 4, 108 PERF_COUNT_SW_PAGE_FAULTS_MIN = 5, 109 PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6, 110 111 PERF_COUNT_SW_MAX, /* non-ABI */ 112 }; 113 114 /* 115 * Bits that can be set in attr.sample_type to request information 116 * in the overflow packets. 117 */ 118 enum perf_event_sample_format { 119 PERF_SAMPLE_IP = 1U << 0, 120 PERF_SAMPLE_TID = 1U << 1, 121 PERF_SAMPLE_TIME = 1U << 2, 122 PERF_SAMPLE_ADDR = 1U << 3, 123 PERF_SAMPLE_READ = 1U << 4, 124 PERF_SAMPLE_CALLCHAIN = 1U << 5, 125 PERF_SAMPLE_ID = 1U << 6, 126 PERF_SAMPLE_CPU = 1U << 7, 127 PERF_SAMPLE_PERIOD = 1U << 8, 128 PERF_SAMPLE_STREAM_ID = 1U << 9, 129 PERF_SAMPLE_RAW = 1U << 10, 130 131 PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */ 132 }; 133 134 /* 135 * The format of the data returned by read() on a perf event fd, 136 * as specified by attr.read_format: 137 * 138 * struct read_format { 139 * { u64 value; 140 * { u64 time_enabled; } && PERF_FORMAT_ENABLED 141 * { u64 time_running; } && PERF_FORMAT_RUNNING 142 * { u64 id; } && PERF_FORMAT_ID 143 * } && !PERF_FORMAT_GROUP 144 * 145 * { u64 nr; 146 * { u64 time_enabled; } && PERF_FORMAT_ENABLED 147 * { u64 time_running; } && PERF_FORMAT_RUNNING 148 * { u64 value; 149 * { u64 id; } && PERF_FORMAT_ID 150 * } cntr[nr]; 151 * } && PERF_FORMAT_GROUP 152 * }; 153 */ 154 enum perf_event_read_format { 155 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0, 156 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, 157 PERF_FORMAT_ID = 1U << 2, 158 PERF_FORMAT_GROUP = 1U << 3, 159 160 PERF_FORMAT_MAX = 1U << 4, /* non-ABI */ 161 }; 162 163 #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */ 164 165 /* 166 * Hardware event_id to monitor via a performance monitoring event: 167 */ 168 struct perf_event_attr { 169 170 /* 171 * Major type: hardware/software/tracepoint/etc. 172 */ 173 __u32 type; 174 175 /* 176 * Size of the attr structure, for fwd/bwd compat. 177 */ 178 __u32 size; 179 180 /* 181 * Type specific configuration information. 182 */ 183 __u64 config; 184 185 union { 186 __u64 sample_period; 187 __u64 sample_freq; 188 }; 189 190 __u64 sample_type; 191 __u64 read_format; 192 193 __u64 disabled : 1, /* off by default */ 194 inherit : 1, /* children inherit it */ 195 pinned : 1, /* must always be on PMU */ 196 exclusive : 1, /* only group on PMU */ 197 exclude_user : 1, /* don't count user */ 198 exclude_kernel : 1, /* ditto kernel */ 199 exclude_hv : 1, /* ditto hypervisor */ 200 exclude_idle : 1, /* don't count when idle */ 201 mmap : 1, /* include mmap data */ 202 comm : 1, /* include comm data */ 203 freq : 1, /* use freq, not period */ 204 inherit_stat : 1, /* per task counts */ 205 enable_on_exec : 1, /* next exec enables */ 206 task : 1, /* trace fork/exit */ 207 watermark : 1, /* wakeup_watermark */ 208 209 __reserved_1 : 49; 210 211 union { 212 __u32 wakeup_events; /* wakeup every n events */ 213 __u32 wakeup_watermark; /* bytes before wakeup */ 214 }; 215 216 union { 217 struct { /* Hardware breakpoint info */ 218 __u64 bp_addr; 219 __u32 bp_type; 220 __u32 bp_len; 221 }; 222 }; 223 224 __u32 __reserved_2; 225 226 __u64 __reserved_3; 227 }; 228 229 /* 230 * Ioctls that can be done on a perf event fd: 231 */ 232 #define PERF_EVENT_IOC_ENABLE _IO ('$', 0) 233 #define PERF_EVENT_IOC_DISABLE _IO ('$', 1) 234 #define PERF_EVENT_IOC_REFRESH _IO ('$', 2) 235 #define PERF_EVENT_IOC_RESET _IO ('$', 3) 236 #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, u64) 237 #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5) 238 #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *) 239 240 enum perf_event_ioc_flags { 241 PERF_IOC_FLAG_GROUP = 1U << 0, 242 }; 243 244 /* 245 * Structure of the page that can be mapped via mmap 246 */ 247 struct perf_event_mmap_page { 248 __u32 version; /* version number of this structure */ 249 __u32 compat_version; /* lowest version this is compat with */ 250 251 /* 252 * Bits needed to read the hw events in user-space. 253 * 254 * u32 seq; 255 * s64 count; 256 * 257 * do { 258 * seq = pc->lock; 259 * 260 * barrier() 261 * if (pc->index) { 262 * count = pmc_read(pc->index - 1); 263 * count += pc->offset; 264 * } else 265 * goto regular_read; 266 * 267 * barrier(); 268 * } while (pc->lock != seq); 269 * 270 * NOTE: for obvious reason this only works on self-monitoring 271 * processes. 272 */ 273 __u32 lock; /* seqlock for synchronization */ 274 __u32 index; /* hardware event identifier */ 275 __s64 offset; /* add to hardware event value */ 276 __u64 time_enabled; /* time event active */ 277 __u64 time_running; /* time event on cpu */ 278 279 /* 280 * Hole for extension of the self monitor capabilities 281 */ 282 283 __u64 __reserved[123]; /* align to 1k */ 284 285 /* 286 * Control data for the mmap() data buffer. 287 * 288 * User-space reading the @data_head value should issue an rmb(), on 289 * SMP capable platforms, after reading this value -- see 290 * perf_event_wakeup(). 291 * 292 * When the mapping is PROT_WRITE the @data_tail value should be 293 * written by userspace to reflect the last read data. In this case 294 * the kernel will not over-write unread data. 295 */ 296 __u64 data_head; /* head in the data section */ 297 __u64 data_tail; /* user-space written tail */ 298 }; 299 300 #define PERF_RECORD_MISC_CPUMODE_MASK (3 << 0) 301 #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0) 302 #define PERF_RECORD_MISC_KERNEL (1 << 0) 303 #define PERF_RECORD_MISC_USER (2 << 0) 304 #define PERF_RECORD_MISC_HYPERVISOR (3 << 0) 305 306 struct perf_event_header { 307 __u32 type; 308 __u16 misc; 309 __u16 size; 310 }; 311 312 enum perf_event_type { 313 314 /* 315 * The MMAP events record the PROT_EXEC mappings so that we can 316 * correlate userspace IPs to code. They have the following structure: 317 * 318 * struct { 319 * struct perf_event_header header; 320 * 321 * u32 pid, tid; 322 * u64 addr; 323 * u64 len; 324 * u64 pgoff; 325 * char filename[]; 326 * }; 327 */ 328 PERF_RECORD_MMAP = 1, 329 330 /* 331 * struct { 332 * struct perf_event_header header; 333 * u64 id; 334 * u64 lost; 335 * }; 336 */ 337 PERF_RECORD_LOST = 2, 338 339 /* 340 * struct { 341 * struct perf_event_header header; 342 * 343 * u32 pid, tid; 344 * char comm[]; 345 * }; 346 */ 347 PERF_RECORD_COMM = 3, 348 349 /* 350 * struct { 351 * struct perf_event_header header; 352 * u32 pid, ppid; 353 * u32 tid, ptid; 354 * u64 time; 355 * }; 356 */ 357 PERF_RECORD_EXIT = 4, 358 359 /* 360 * struct { 361 * struct perf_event_header header; 362 * u64 time; 363 * u64 id; 364 * u64 stream_id; 365 * }; 366 */ 367 PERF_RECORD_THROTTLE = 5, 368 PERF_RECORD_UNTHROTTLE = 6, 369 370 /* 371 * struct { 372 * struct perf_event_header header; 373 * u32 pid, ppid; 374 * u32 tid, ptid; 375 * u64 time; 376 * }; 377 */ 378 PERF_RECORD_FORK = 7, 379 380 /* 381 * struct { 382 * struct perf_event_header header; 383 * u32 pid, tid; 384 * 385 * struct read_format values; 386 * }; 387 */ 388 PERF_RECORD_READ = 8, 389 390 /* 391 * struct { 392 * struct perf_event_header header; 393 * 394 * { u64 ip; } && PERF_SAMPLE_IP 395 * { u32 pid, tid; } && PERF_SAMPLE_TID 396 * { u64 time; } && PERF_SAMPLE_TIME 397 * { u64 addr; } && PERF_SAMPLE_ADDR 398 * { u64 id; } && PERF_SAMPLE_ID 399 * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID 400 * { u32 cpu, res; } && PERF_SAMPLE_CPU 401 * { u64 period; } && PERF_SAMPLE_PERIOD 402 * 403 * { struct read_format values; } && PERF_SAMPLE_READ 404 * 405 * { u64 nr, 406 * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN 407 * 408 * # 409 * # The RAW record below is opaque data wrt the ABI 410 * # 411 * # That is, the ABI doesn't make any promises wrt to 412 * # the stability of its content, it may vary depending 413 * # on event, hardware, kernel version and phase of 414 * # the moon. 415 * # 416 * # In other words, PERF_SAMPLE_RAW contents are not an ABI. 417 * # 418 * 419 * { u32 size; 420 * char data[size];}&& PERF_SAMPLE_RAW 421 * }; 422 */ 423 PERF_RECORD_SAMPLE = 9, 424 425 PERF_RECORD_MAX, /* non-ABI */ 426 }; 427 428 enum perf_callchain_context { 429 PERF_CONTEXT_HV = (__u64)-32, 430 PERF_CONTEXT_KERNEL = (__u64)-128, 431 PERF_CONTEXT_USER = (__u64)-512, 432 433 PERF_CONTEXT_GUEST = (__u64)-2048, 434 PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176, 435 PERF_CONTEXT_GUEST_USER = (__u64)-2560, 436 437 PERF_CONTEXT_MAX = (__u64)-4095, 438 }; 439 440 #define PERF_FLAG_FD_NO_GROUP (1U << 0) 441 #define PERF_FLAG_FD_OUTPUT (1U << 1) 442 443 #ifdef __KERNEL__ 444 /* 445 * Kernel-internal data types and definitions: 446 */ 447 448 #ifdef CONFIG_PERF_EVENTS 449 # include <asm/perf_event.h> 450 #endif 451 452 #include <linux/list.h> 453 #include <linux/mutex.h> 454 #include <linux/rculist.h> 455 #include <linux/rcupdate.h> 456 #include <linux/spinlock.h> 457 #include <linux/hrtimer.h> 458 #include <linux/fs.h> 459 #include <linux/pid_namespace.h> 460 #include <linux/workqueue.h> 461 #include <asm/atomic.h> 462 463 #define PERF_MAX_STACK_DEPTH 255 464 465 struct perf_callchain_entry { 466 __u64 nr; 467 __u64 ip[PERF_MAX_STACK_DEPTH]; 468 }; 469 470 struct perf_raw_record { 471 u32 size; 472 void *data; 473 }; 474 475 struct task_struct; 476 477 /** 478 * struct hw_perf_event - performance event hardware details: 479 */ 480 struct hw_perf_event { 481 #ifdef CONFIG_PERF_EVENTS 482 union { 483 struct { /* hardware */ 484 u64 config; 485 unsigned long config_base; 486 unsigned long event_base; 487 int idx; 488 }; 489 union { /* software */ 490 atomic64_t count; 491 struct hrtimer hrtimer; 492 }; 493 #ifdef CONFIG_HAVE_HW_BREAKPOINT 494 union { /* breakpoint */ 495 struct arch_hw_breakpoint info; 496 }; 497 #endif 498 }; 499 atomic64_t prev_count; 500 u64 sample_period; 501 u64 last_period; 502 atomic64_t period_left; 503 u64 interrupts; 504 505 u64 freq_count; 506 u64 freq_interrupts; 507 u64 freq_stamp; 508 #endif 509 }; 510 511 struct perf_event; 512 513 /** 514 * struct pmu - generic performance monitoring unit 515 */ 516 struct pmu { 517 int (*enable) (struct perf_event *event); 518 void (*disable) (struct perf_event *event); 519 void (*read) (struct perf_event *event); 520 void (*unthrottle) (struct perf_event *event); 521 }; 522 523 /** 524 * enum perf_event_active_state - the states of a event 525 */ 526 enum perf_event_active_state { 527 PERF_EVENT_STATE_ERROR = -2, 528 PERF_EVENT_STATE_OFF = -1, 529 PERF_EVENT_STATE_INACTIVE = 0, 530 PERF_EVENT_STATE_ACTIVE = 1, 531 }; 532 533 struct file; 534 535 struct perf_mmap_data { 536 struct rcu_head rcu_head; 537 #ifdef CONFIG_PERF_USE_VMALLOC 538 struct work_struct work; 539 #endif 540 int data_order; 541 int nr_pages; /* nr of data pages */ 542 int writable; /* are we writable */ 543 int nr_locked; /* nr pages mlocked */ 544 545 atomic_t poll; /* POLL_ for wakeups */ 546 atomic_t events; /* event_id limit */ 547 548 atomic_long_t head; /* write position */ 549 atomic_long_t done_head; /* completed head */ 550 551 atomic_t lock; /* concurrent writes */ 552 atomic_t wakeup; /* needs a wakeup */ 553 atomic_t lost; /* nr records lost */ 554 555 long watermark; /* wakeup watermark */ 556 557 struct perf_event_mmap_page *user_page; 558 void *data_pages[0]; 559 }; 560 561 struct perf_pending_entry { 562 struct perf_pending_entry *next; 563 void (*func)(struct perf_pending_entry *); 564 }; 565 566 typedef void (*perf_callback_t)(struct perf_event *, void *); 567 568 /** 569 * struct perf_event - performance event kernel representation: 570 */ 571 struct perf_event { 572 #ifdef CONFIG_PERF_EVENTS 573 struct list_head group_entry; 574 struct list_head event_entry; 575 struct list_head sibling_list; 576 int nr_siblings; 577 struct perf_event *group_leader; 578 struct perf_event *output; 579 const struct pmu *pmu; 580 581 enum perf_event_active_state state; 582 atomic64_t count; 583 584 /* 585 * These are the total time in nanoseconds that the event 586 * has been enabled (i.e. eligible to run, and the task has 587 * been scheduled in, if this is a per-task event) 588 * and running (scheduled onto the CPU), respectively. 589 * 590 * They are computed from tstamp_enabled, tstamp_running and 591 * tstamp_stopped when the event is in INACTIVE or ACTIVE state. 592 */ 593 u64 total_time_enabled; 594 u64 total_time_running; 595 596 /* 597 * These are timestamps used for computing total_time_enabled 598 * and total_time_running when the event is in INACTIVE or 599 * ACTIVE state, measured in nanoseconds from an arbitrary point 600 * in time. 601 * tstamp_enabled: the notional time when the event was enabled 602 * tstamp_running: the notional time when the event was scheduled on 603 * tstamp_stopped: in INACTIVE state, the notional time when the 604 * event was scheduled off. 605 */ 606 u64 tstamp_enabled; 607 u64 tstamp_running; 608 u64 tstamp_stopped; 609 610 struct perf_event_attr attr; 611 struct hw_perf_event hw; 612 613 struct perf_event_context *ctx; 614 struct file *filp; 615 616 /* 617 * These accumulate total time (in nanoseconds) that children 618 * events have been enabled and running, respectively. 619 */ 620 atomic64_t child_total_time_enabled; 621 atomic64_t child_total_time_running; 622 623 /* 624 * Protect attach/detach and child_list: 625 */ 626 struct mutex child_mutex; 627 struct list_head child_list; 628 struct perf_event *parent; 629 630 int oncpu; 631 int cpu; 632 633 struct list_head owner_entry; 634 struct task_struct *owner; 635 636 /* mmap bits */ 637 struct mutex mmap_mutex; 638 atomic_t mmap_count; 639 struct perf_mmap_data *data; 640 641 /* poll related */ 642 wait_queue_head_t waitq; 643 struct fasync_struct *fasync; 644 645 /* delayed work for NMIs and such */ 646 int pending_wakeup; 647 int pending_kill; 648 int pending_disable; 649 struct perf_pending_entry pending; 650 651 atomic_t event_limit; 652 653 void (*destroy)(struct perf_event *); 654 struct rcu_head rcu_head; 655 656 struct pid_namespace *ns; 657 u64 id; 658 659 #ifdef CONFIG_EVENT_PROFILE 660 struct event_filter *filter; 661 #endif 662 663 perf_callback_t callback; 664 665 perf_callback_t event_callback; 666 667 #endif /* CONFIG_PERF_EVENTS */ 668 }; 669 670 /** 671 * struct perf_event_context - event context structure 672 * 673 * Used as a container for task events and CPU events as well: 674 */ 675 struct perf_event_context { 676 /* 677 * Protect the states of the events in the list, 678 * nr_active, and the list: 679 */ 680 spinlock_t lock; 681 /* 682 * Protect the list of events. Locking either mutex or lock 683 * is sufficient to ensure the list doesn't change; to change 684 * the list you need to lock both the mutex and the spinlock. 685 */ 686 struct mutex mutex; 687 688 struct list_head group_list; 689 struct list_head event_list; 690 int nr_events; 691 int nr_active; 692 int is_active; 693 int nr_stat; 694 atomic_t refcount; 695 struct task_struct *task; 696 697 /* 698 * Context clock, runs when context enabled. 699 */ 700 u64 time; 701 u64 timestamp; 702 703 /* 704 * These fields let us detect when two contexts have both 705 * been cloned (inherited) from a common ancestor. 706 */ 707 struct perf_event_context *parent_ctx; 708 u64 parent_gen; 709 u64 generation; 710 int pin_count; 711 struct rcu_head rcu_head; 712 }; 713 714 /** 715 * struct perf_event_cpu_context - per cpu event context structure 716 */ 717 struct perf_cpu_context { 718 struct perf_event_context ctx; 719 struct perf_event_context *task_ctx; 720 int active_oncpu; 721 int max_pertask; 722 int exclusive; 723 724 /* 725 * Recursion avoidance: 726 * 727 * task, softirq, irq, nmi context 728 */ 729 int recursion[4]; 730 }; 731 732 struct perf_output_handle { 733 struct perf_event *event; 734 struct perf_mmap_data *data; 735 unsigned long head; 736 unsigned long offset; 737 int nmi; 738 int sample; 739 int locked; 740 unsigned long flags; 741 }; 742 743 #ifdef CONFIG_PERF_EVENTS 744 745 /* 746 * Set by architecture code: 747 */ 748 extern int perf_max_events; 749 750 extern const struct pmu *hw_perf_event_init(struct perf_event *event); 751 752 extern void perf_event_task_sched_in(struct task_struct *task, int cpu); 753 extern void perf_event_task_sched_out(struct task_struct *task, 754 struct task_struct *next, int cpu); 755 extern void perf_event_task_tick(struct task_struct *task, int cpu); 756 extern int perf_event_init_task(struct task_struct *child); 757 extern void perf_event_exit_task(struct task_struct *child); 758 extern void perf_event_free_task(struct task_struct *task); 759 extern void set_perf_event_pending(void); 760 extern void perf_event_do_pending(void); 761 extern void perf_event_print_debug(void); 762 extern void __perf_disable(void); 763 extern bool __perf_enable(void); 764 extern void perf_disable(void); 765 extern void perf_enable(void); 766 extern int perf_event_task_disable(void); 767 extern int perf_event_task_enable(void); 768 extern int hw_perf_group_sched_in(struct perf_event *group_leader, 769 struct perf_cpu_context *cpuctx, 770 struct perf_event_context *ctx, int cpu); 771 extern void perf_event_update_userpage(struct perf_event *event); 772 extern int perf_event_release_kernel(struct perf_event *event); 773 extern struct perf_event * 774 perf_event_create_kernel_counter(struct perf_event_attr *attr, 775 int cpu, 776 pid_t pid, 777 perf_callback_t callback); 778 extern u64 perf_event_read_value(struct perf_event *event); 779 780 struct perf_sample_data { 781 u64 type; 782 783 u64 ip; 784 struct { 785 u32 pid; 786 u32 tid; 787 } tid_entry; 788 u64 time; 789 u64 addr; 790 u64 id; 791 u64 stream_id; 792 struct { 793 u32 cpu; 794 u32 reserved; 795 } cpu_entry; 796 u64 period; 797 struct perf_callchain_entry *callchain; 798 struct perf_raw_record *raw; 799 }; 800 801 extern void perf_output_sample(struct perf_output_handle *handle, 802 struct perf_event_header *header, 803 struct perf_sample_data *data, 804 struct perf_event *event); 805 extern void perf_prepare_sample(struct perf_event_header *header, 806 struct perf_sample_data *data, 807 struct perf_event *event, 808 struct pt_regs *regs); 809 810 extern int perf_event_overflow(struct perf_event *event, int nmi, 811 struct perf_sample_data *data, 812 struct pt_regs *regs); 813 814 /* 815 * Return 1 for a software event, 0 for a hardware event 816 */ 817 static inline int is_software_event(struct perf_event *event) 818 { 819 return (event->attr.type != PERF_TYPE_RAW) && 820 (event->attr.type != PERF_TYPE_HARDWARE) && 821 (event->attr.type != PERF_TYPE_HW_CACHE); 822 } 823 824 extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX]; 825 826 extern void __perf_sw_event(u32, u64, int, struct pt_regs *, u64); 827 828 static inline void 829 perf_sw_event(u32 event_id, u64 nr, int nmi, struct pt_regs *regs, u64 addr) 830 { 831 if (atomic_read(&perf_swevent_enabled[event_id])) 832 __perf_sw_event(event_id, nr, nmi, regs, addr); 833 } 834 835 extern void __perf_event_mmap(struct vm_area_struct *vma); 836 837 static inline void perf_event_mmap(struct vm_area_struct *vma) 838 { 839 if (vma->vm_flags & VM_EXEC) 840 __perf_event_mmap(vma); 841 } 842 843 extern void perf_event_comm(struct task_struct *tsk); 844 extern void perf_event_fork(struct task_struct *tsk); 845 846 extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs); 847 848 extern int sysctl_perf_event_paranoid; 849 extern int sysctl_perf_event_mlock; 850 extern int sysctl_perf_event_sample_rate; 851 852 extern void perf_event_init(void); 853 extern void perf_tp_event(int event_id, u64 addr, u64 count, 854 void *record, int entry_size); 855 extern void perf_bp_event(struct perf_event *event, void *data); 856 857 #ifndef perf_misc_flags 858 #define perf_misc_flags(regs) (user_mode(regs) ? PERF_RECORD_MISC_USER : \ 859 PERF_RECORD_MISC_KERNEL) 860 #define perf_instruction_pointer(regs) instruction_pointer(regs) 861 #endif 862 863 extern int perf_output_begin(struct perf_output_handle *handle, 864 struct perf_event *event, unsigned int size, 865 int nmi, int sample); 866 extern void perf_output_end(struct perf_output_handle *handle); 867 extern void perf_output_copy(struct perf_output_handle *handle, 868 const void *buf, unsigned int len); 869 #else 870 static inline void 871 perf_event_task_sched_in(struct task_struct *task, int cpu) { } 872 static inline void 873 perf_event_task_sched_out(struct task_struct *task, 874 struct task_struct *next, int cpu) { } 875 static inline void 876 perf_event_task_tick(struct task_struct *task, int cpu) { } 877 static inline int perf_event_init_task(struct task_struct *child) { return 0; } 878 static inline void perf_event_exit_task(struct task_struct *child) { } 879 static inline void perf_event_free_task(struct task_struct *task) { } 880 static inline void perf_event_do_pending(void) { } 881 static inline void perf_event_print_debug(void) { } 882 static inline void perf_disable(void) { } 883 static inline void perf_enable(void) { } 884 static inline int perf_event_task_disable(void) { return -EINVAL; } 885 static inline int perf_event_task_enable(void) { return -EINVAL; } 886 887 static inline void 888 perf_sw_event(u32 event_id, u64 nr, int nmi, 889 struct pt_regs *regs, u64 addr) { } 890 static inline void 891 perf_bp_event(struct perf_event *event, void *data) { } 892 893 static inline void perf_event_mmap(struct vm_area_struct *vma) { } 894 static inline void perf_event_comm(struct task_struct *tsk) { } 895 static inline void perf_event_fork(struct task_struct *tsk) { } 896 static inline void perf_event_init(void) { } 897 898 #endif 899 900 #define perf_output_put(handle, x) \ 901 perf_output_copy((handle), &(x), sizeof(x)) 902 903 #endif /* __KERNEL__ */ 904 #endif /* _LINUX_PERF_EVENT_H */ 905