perf_counter.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /*
  2. * Performance counters:
  3. *
  4. * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
  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_COUNTER_H
  15. #define _LINUX_PERF_COUNTER_H
  16. #include <linux/types.h>
  17. #include <linux/ioctl.h>
  18. #include <asm/byteorder.h>
  19. /*
  20. * User-space ABI bits:
  21. */
  22. /*
  23. * attr.type
  24. */
  25. enum perf_type_id {
  26. PERF_TYPE_HARDWARE = 0,
  27. PERF_TYPE_SOFTWARE = 1,
  28. PERF_TYPE_TRACEPOINT = 2,
  29. PERF_TYPE_HW_CACHE = 3,
  30. PERF_TYPE_RAW = 4,
  31. PERF_TYPE_MAX, /* non-ABI */
  32. };
  33. /*
  34. * Generalized performance counter event types, used by the
  35. * attr.event_id parameter of the sys_perf_counter_open()
  36. * syscall:
  37. */
  38. enum perf_hw_id {
  39. /*
  40. * Common hardware events, generalized by the kernel:
  41. */
  42. PERF_COUNT_HW_CPU_CYCLES = 0,
  43. PERF_COUNT_HW_INSTRUCTIONS = 1,
  44. PERF_COUNT_HW_CACHE_REFERENCES = 2,
  45. PERF_COUNT_HW_CACHE_MISSES = 3,
  46. PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
  47. PERF_COUNT_HW_BRANCH_MISSES = 5,
  48. PERF_COUNT_HW_BUS_CYCLES = 6,
  49. PERF_COUNT_HW_MAX, /* non-ABI */
  50. };
  51. /*
  52. * Generalized hardware cache counters:
  53. *
  54. * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x
  55. * { read, write, prefetch } x
  56. * { accesses, misses }
  57. */
  58. enum perf_hw_cache_id {
  59. PERF_COUNT_HW_CACHE_L1D = 0,
  60. PERF_COUNT_HW_CACHE_L1I = 1,
  61. PERF_COUNT_HW_CACHE_LL = 2,
  62. PERF_COUNT_HW_CACHE_DTLB = 3,
  63. PERF_COUNT_HW_CACHE_ITLB = 4,
  64. PERF_COUNT_HW_CACHE_BPU = 5,
  65. PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
  66. };
  67. enum perf_hw_cache_op_id {
  68. PERF_COUNT_HW_CACHE_OP_READ = 0,
  69. PERF_COUNT_HW_CACHE_OP_WRITE = 1,
  70. PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
  71. PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
  72. };
  73. enum perf_hw_cache_op_result_id {
  74. PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
  75. PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
  76. PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
  77. };
  78. /*
  79. * Special "software" counters provided by the kernel, even if the hardware
  80. * does not support performance counters. These counters measure various
  81. * physical and sw events of the kernel (and allow the profiling of them as
  82. * well):
  83. */
  84. enum perf_sw_ids {
  85. PERF_COUNT_SW_CPU_CLOCK = 0,
  86. PERF_COUNT_SW_TASK_CLOCK = 1,
  87. PERF_COUNT_SW_PAGE_FAULTS = 2,
  88. PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
  89. PERF_COUNT_SW_CPU_MIGRATIONS = 4,
  90. PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
  91. PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
  92. PERF_COUNT_SW_MAX, /* non-ABI */
  93. };
  94. /*
  95. * Bits that can be set in attr.sample_type to request information
  96. * in the overflow packets.
  97. */
  98. enum perf_counter_sample_format {
  99. PERF_SAMPLE_IP = 1U << 0,
  100. PERF_SAMPLE_TID = 1U << 1,
  101. PERF_SAMPLE_TIME = 1U << 2,
  102. PERF_SAMPLE_ADDR = 1U << 3,
  103. PERF_SAMPLE_GROUP = 1U << 4,
  104. PERF_SAMPLE_CALLCHAIN = 1U << 5,
  105. PERF_SAMPLE_ID = 1U << 6,
  106. PERF_SAMPLE_CPU = 1U << 7,
  107. PERF_SAMPLE_PERIOD = 1U << 8,
  108. PERF_SAMPLE_STREAM_ID = 1U << 9,
  109. PERF_SAMPLE_RAW = 1U << 10,
  110. PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
  111. };
  112. /*
  113. * Bits that can be set in attr.read_format to request that
  114. * reads on the counter should return the indicated quantities,
  115. * in increasing order of bit value, after the counter value.
  116. */
  117. enum perf_counter_read_format {
  118. PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
  119. PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  120. PERF_FORMAT_ID = 1U << 2,
  121. PERF_FORMAT_MAX = 1U << 3, /* non-ABI */
  122. };
  123. #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
  124. /*
  125. * Hardware event to monitor via a performance monitoring counter:
  126. */
  127. struct perf_counter_attr {
  128. /*
  129. * Major type: hardware/software/tracepoint/etc.
  130. */
  131. __u32 type;
  132. /*
  133. * Size of the attr structure, for fwd/bwd compat.
  134. */
  135. __u32 size;
  136. /*
  137. * Type specific configuration information.
  138. */
  139. __u64 config;
  140. union {
  141. __u64 sample_period;
  142. __u64 sample_freq;
  143. };
  144. __u64 sample_type;
  145. __u64 read_format;
  146. __u64 disabled : 1, /* off by default */
  147. inherit : 1, /* children inherit it */
  148. pinned : 1, /* must always be on PMU */
  149. exclusive : 1, /* only group on PMU */
  150. exclude_user : 1, /* don't count user */
  151. exclude_kernel : 1, /* ditto kernel */
  152. exclude_hv : 1, /* ditto hypervisor */
  153. exclude_idle : 1, /* don't count when idle */
  154. mmap : 1, /* include mmap data */
  155. comm : 1, /* include comm data */
  156. freq : 1, /* use freq, not period */
  157. inherit_stat : 1, /* per task counts */
  158. enable_on_exec : 1, /* next exec enables */
  159. task : 1, /* trace fork/exit */
  160. __reserved_1 : 50;
  161. __u32 wakeup_events; /* wakeup every n events */
  162. __u32 __reserved_2;
  163. __u64 __reserved_3;
  164. };
  165. /*
  166. * Ioctls that can be done on a perf counter fd:
  167. */
  168. #define PERF_COUNTER_IOC_ENABLE _IO ('$', 0)
  169. #define PERF_COUNTER_IOC_DISABLE _IO ('$', 1)
  170. #define PERF_COUNTER_IOC_REFRESH _IO ('$', 2)
  171. #define PERF_COUNTER_IOC_RESET _IO ('$', 3)
  172. #define PERF_COUNTER_IOC_PERIOD _IOW('$', 4, u64)
  173. enum perf_counter_ioc_flags {
  174. PERF_IOC_FLAG_GROUP = 1U << 0,
  175. };
  176. /*
  177. * Structure of the page that can be mapped via mmap
  178. */
  179. struct perf_counter_mmap_page {
  180. __u32 version; /* version number of this structure */
  181. __u32 compat_version; /* lowest version this is compat with */
  182. /*
  183. * Bits needed to read the hw counters in user-space.
  184. *
  185. * u32 seq;
  186. * s64 count;
  187. *
  188. * do {
  189. * seq = pc->lock;
  190. *
  191. * barrier()
  192. * if (pc->index) {
  193. * count = pmc_read(pc->index - 1);
  194. * count += pc->offset;
  195. * } else
  196. * goto regular_read;
  197. *
  198. * barrier();
  199. * } while (pc->lock != seq);
  200. *
  201. * NOTE: for obvious reason this only works on self-monitoring
  202. * processes.
  203. */
  204. __u32 lock; /* seqlock for synchronization */
  205. __u32 index; /* hardware counter identifier */
  206. __s64 offset; /* add to hardware counter value */
  207. __u64 time_enabled; /* time counter active */
  208. __u64 time_running; /* time counter on cpu */
  209. /*
  210. * Hole for extension of the self monitor capabilities
  211. */
  212. __u64 __reserved[123]; /* align to 1k */
  213. /*
  214. * Control data for the mmap() data buffer.
  215. *
  216. * User-space reading the @data_head value should issue an rmb(), on
  217. * SMP capable platforms, after reading this value -- see
  218. * perf_counter_wakeup().
  219. *
  220. * When the mapping is PROT_WRITE the @data_tail value should be
  221. * written by userspace to reflect the last read data. In this case
  222. * the kernel will not over-write unread data.
  223. */
  224. __u64 data_head; /* head in the data section */
  225. __u64 data_tail; /* user-space written tail */
  226. };
  227. #define PERF_EVENT_MISC_CPUMODE_MASK (3 << 0)
  228. #define PERF_EVENT_MISC_CPUMODE_UNKNOWN (0 << 0)
  229. #define PERF_EVENT_MISC_KERNEL (1 << 0)
  230. #define PERF_EVENT_MISC_USER (2 << 0)
  231. #define PERF_EVENT_MISC_HYPERVISOR (3 << 0)
  232. struct perf_event_header {
  233. __u32 type;
  234. __u16 misc;
  235. __u16 size;
  236. };
  237. enum perf_event_type {
  238. /*
  239. * The MMAP events record the PROT_EXEC mappings so that we can
  240. * correlate userspace IPs to code. They have the following structure:
  241. *
  242. * struct {
  243. * struct perf_event_header header;
  244. *
  245. * u32 pid, tid;
  246. * u64 addr;
  247. * u64 len;
  248. * u64 pgoff;
  249. * char filename[];
  250. * };
  251. */
  252. PERF_EVENT_MMAP = 1,
  253. /*
  254. * struct {
  255. * struct perf_event_header header;
  256. * u64 id;
  257. * u64 lost;
  258. * };
  259. */
  260. PERF_EVENT_LOST = 2,
  261. /*
  262. * struct {
  263. * struct perf_event_header header;
  264. *
  265. * u32 pid, tid;
  266. * char comm[];
  267. * };
  268. */
  269. PERF_EVENT_COMM = 3,
  270. /*
  271. * struct {
  272. * struct perf_event_header header;
  273. * u32 pid, ppid;
  274. * u32 tid, ptid;
  275. * };
  276. */
  277. PERF_EVENT_EXIT = 4,
  278. /*
  279. * struct {
  280. * struct perf_event_header header;
  281. * u64 time;
  282. * u64 id;
  283. * u64 stream_id;
  284. * };
  285. */
  286. PERF_EVENT_THROTTLE = 5,
  287. PERF_EVENT_UNTHROTTLE = 6,
  288. /*
  289. * struct {
  290. * struct perf_event_header header;
  291. * u32 pid, ppid;
  292. * u32 tid, ptid;
  293. * };
  294. */
  295. PERF_EVENT_FORK = 7,
  296. /*
  297. * struct {
  298. * struct perf_event_header header;
  299. * u32 pid, tid;
  300. * u64 value;
  301. * { u64 time_enabled; } && PERF_FORMAT_ENABLED
  302. * { u64 time_running; } && PERF_FORMAT_RUNNING
  303. * { u64 parent_id; } && PERF_FORMAT_ID
  304. * };
  305. */
  306. PERF_EVENT_READ = 8,
  307. /*
  308. * struct {
  309. * struct perf_event_header header;
  310. *
  311. * { u64 ip; } && PERF_SAMPLE_IP
  312. * { u32 pid, tid; } && PERF_SAMPLE_TID
  313. * { u64 time; } && PERF_SAMPLE_TIME
  314. * { u64 addr; } && PERF_SAMPLE_ADDR
  315. * { u64 id; } && PERF_SAMPLE_ID
  316. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  317. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  318. * { u64 period; } && PERF_SAMPLE_PERIOD
  319. *
  320. * { u64 nr;
  321. * { u64 id, val; } cnt[nr]; } && PERF_SAMPLE_GROUP
  322. *
  323. * { u64 nr,
  324. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  325. * { u32 size;
  326. * char data[size];}&& PERF_SAMPLE_RAW
  327. * };
  328. */
  329. PERF_EVENT_SAMPLE = 9,
  330. PERF_EVENT_MAX, /* non-ABI */
  331. };
  332. enum perf_callchain_context {
  333. PERF_CONTEXT_HV = (__u64)-32,
  334. PERF_CONTEXT_KERNEL = (__u64)-128,
  335. PERF_CONTEXT_USER = (__u64)-512,
  336. PERF_CONTEXT_GUEST = (__u64)-2048,
  337. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  338. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  339. PERF_CONTEXT_MAX = (__u64)-4095,
  340. };
  341. #ifdef __KERNEL__
  342. /*
  343. * Kernel-internal data types and definitions:
  344. */
  345. #ifdef CONFIG_PERF_COUNTERS
  346. # include <asm/perf_counter.h>
  347. #endif
  348. #include <linux/list.h>
  349. #include <linux/mutex.h>
  350. #include <linux/rculist.h>
  351. #include <linux/rcupdate.h>
  352. #include <linux/spinlock.h>
  353. #include <linux/hrtimer.h>
  354. #include <linux/fs.h>
  355. #include <linux/pid_namespace.h>
  356. #include <asm/atomic.h>
  357. #define PERF_MAX_STACK_DEPTH 255
  358. struct perf_callchain_entry {
  359. __u64 nr;
  360. __u64 ip[PERF_MAX_STACK_DEPTH];
  361. };
  362. struct perf_raw_record {
  363. u32 size;
  364. void *data;
  365. };
  366. struct task_struct;
  367. /**
  368. * struct hw_perf_counter - performance counter hardware details:
  369. */
  370. struct hw_perf_counter {
  371. #ifdef CONFIG_PERF_COUNTERS
  372. union {
  373. struct { /* hardware */
  374. u64 config;
  375. unsigned long config_base;
  376. unsigned long counter_base;
  377. int idx;
  378. };
  379. union { /* software */
  380. atomic64_t count;
  381. struct hrtimer hrtimer;
  382. };
  383. };
  384. atomic64_t prev_count;
  385. u64 sample_period;
  386. u64 last_period;
  387. atomic64_t period_left;
  388. u64 interrupts;
  389. u64 freq_count;
  390. u64 freq_interrupts;
  391. u64 freq_stamp;
  392. #endif
  393. };
  394. struct perf_counter;
  395. /**
  396. * struct pmu - generic performance monitoring unit
  397. */
  398. struct pmu {
  399. int (*enable) (struct perf_counter *counter);
  400. void (*disable) (struct perf_counter *counter);
  401. void (*read) (struct perf_counter *counter);
  402. void (*unthrottle) (struct perf_counter *counter);
  403. };
  404. /**
  405. * enum perf_counter_active_state - the states of a counter
  406. */
  407. enum perf_counter_active_state {
  408. PERF_COUNTER_STATE_ERROR = -2,
  409. PERF_COUNTER_STATE_OFF = -1,
  410. PERF_COUNTER_STATE_INACTIVE = 0,
  411. PERF_COUNTER_STATE_ACTIVE = 1,
  412. };
  413. struct file;
  414. struct perf_mmap_data {
  415. struct rcu_head rcu_head;
  416. int nr_pages; /* nr of data pages */
  417. int writable; /* are we writable */
  418. int nr_locked; /* nr pages mlocked */
  419. atomic_t poll; /* POLL_ for wakeups */
  420. atomic_t events; /* event limit */
  421. atomic_long_t head; /* write position */
  422. atomic_long_t done_head; /* completed head */
  423. atomic_t lock; /* concurrent writes */
  424. atomic_t wakeup; /* needs a wakeup */
  425. atomic_t lost; /* nr records lost */
  426. struct perf_counter_mmap_page *user_page;
  427. void *data_pages[0];
  428. };
  429. struct perf_pending_entry {
  430. struct perf_pending_entry *next;
  431. void (*func)(struct perf_pending_entry *);
  432. };
  433. /**
  434. * struct perf_counter - performance counter kernel representation:
  435. */
  436. struct perf_counter {
  437. #ifdef CONFIG_PERF_COUNTERS
  438. struct list_head list_entry;
  439. struct list_head event_entry;
  440. struct list_head sibling_list;
  441. int nr_siblings;
  442. struct perf_counter *group_leader;
  443. const struct pmu *pmu;
  444. enum perf_counter_active_state state;
  445. atomic64_t count;
  446. /*
  447. * These are the total time in nanoseconds that the counter
  448. * has been enabled (i.e. eligible to run, and the task has
  449. * been scheduled in, if this is a per-task counter)
  450. * and running (scheduled onto the CPU), respectively.
  451. *
  452. * They are computed from tstamp_enabled, tstamp_running and
  453. * tstamp_stopped when the counter is in INACTIVE or ACTIVE state.
  454. */
  455. u64 total_time_enabled;
  456. u64 total_time_running;
  457. /*
  458. * These are timestamps used for computing total_time_enabled
  459. * and total_time_running when the counter is in INACTIVE or
  460. * ACTIVE state, measured in nanoseconds from an arbitrary point
  461. * in time.
  462. * tstamp_enabled: the notional time when the counter was enabled
  463. * tstamp_running: the notional time when the counter was scheduled on
  464. * tstamp_stopped: in INACTIVE state, the notional time when the
  465. * counter was scheduled off.
  466. */
  467. u64 tstamp_enabled;
  468. u64 tstamp_running;
  469. u64 tstamp_stopped;
  470. struct perf_counter_attr attr;
  471. struct hw_perf_counter hw;
  472. struct perf_counter_context *ctx;
  473. struct file *filp;
  474. /*
  475. * These accumulate total time (in nanoseconds) that children
  476. * counters have been enabled and running, respectively.
  477. */
  478. atomic64_t child_total_time_enabled;
  479. atomic64_t child_total_time_running;
  480. /*
  481. * Protect attach/detach and child_list:
  482. */
  483. struct mutex child_mutex;
  484. struct list_head child_list;
  485. struct perf_counter *parent;
  486. int oncpu;
  487. int cpu;
  488. struct list_head owner_entry;
  489. struct task_struct *owner;
  490. /* mmap bits */
  491. struct mutex mmap_mutex;
  492. atomic_t mmap_count;
  493. struct perf_mmap_data *data;
  494. /* poll related */
  495. wait_queue_head_t waitq;
  496. struct fasync_struct *fasync;
  497. /* delayed work for NMIs and such */
  498. int pending_wakeup;
  499. int pending_kill;
  500. int pending_disable;
  501. struct perf_pending_entry pending;
  502. atomic_t event_limit;
  503. void (*destroy)(struct perf_counter *);
  504. struct rcu_head rcu_head;
  505. struct pid_namespace *ns;
  506. u64 id;
  507. #endif
  508. };
  509. /**
  510. * struct perf_counter_context - counter context structure
  511. *
  512. * Used as a container for task counters and CPU counters as well:
  513. */
  514. struct perf_counter_context {
  515. /*
  516. * Protect the states of the counters in the list,
  517. * nr_active, and the list:
  518. */
  519. spinlock_t lock;
  520. /*
  521. * Protect the list of counters. Locking either mutex or lock
  522. * is sufficient to ensure the list doesn't change; to change
  523. * the list you need to lock both the mutex and the spinlock.
  524. */
  525. struct mutex mutex;
  526. struct list_head counter_list;
  527. struct list_head event_list;
  528. int nr_counters;
  529. int nr_active;
  530. int is_active;
  531. int nr_stat;
  532. atomic_t refcount;
  533. struct task_struct *task;
  534. /*
  535. * Context clock, runs when context enabled.
  536. */
  537. u64 time;
  538. u64 timestamp;
  539. /*
  540. * These fields let us detect when two contexts have both
  541. * been cloned (inherited) from a common ancestor.
  542. */
  543. struct perf_counter_context *parent_ctx;
  544. u64 parent_gen;
  545. u64 generation;
  546. int pin_count;
  547. struct rcu_head rcu_head;
  548. };
  549. /**
  550. * struct perf_counter_cpu_context - per cpu counter context structure
  551. */
  552. struct perf_cpu_context {
  553. struct perf_counter_context ctx;
  554. struct perf_counter_context *task_ctx;
  555. int active_oncpu;
  556. int max_pertask;
  557. int exclusive;
  558. /*
  559. * Recursion avoidance:
  560. *
  561. * task, softirq, irq, nmi context
  562. */
  563. int recursion[4];
  564. };
  565. #ifdef CONFIG_PERF_COUNTERS
  566. /*
  567. * Set by architecture code:
  568. */
  569. extern int perf_max_counters;
  570. extern const struct pmu *hw_perf_counter_init(struct perf_counter *counter);
  571. extern void perf_counter_task_sched_in(struct task_struct *task, int cpu);
  572. extern void perf_counter_task_sched_out(struct task_struct *task,
  573. struct task_struct *next, int cpu);
  574. extern void perf_counter_task_tick(struct task_struct *task, int cpu);
  575. extern int perf_counter_init_task(struct task_struct *child);
  576. extern void perf_counter_exit_task(struct task_struct *child);
  577. extern void perf_counter_free_task(struct task_struct *task);
  578. extern void set_perf_counter_pending(void);
  579. extern void perf_counter_do_pending(void);
  580. extern void perf_counter_print_debug(void);
  581. extern void __perf_disable(void);
  582. extern bool __perf_enable(void);
  583. extern void perf_disable(void);
  584. extern void perf_enable(void);
  585. extern int perf_counter_task_disable(void);
  586. extern int perf_counter_task_enable(void);
  587. extern int hw_perf_group_sched_in(struct perf_counter *group_leader,
  588. struct perf_cpu_context *cpuctx,
  589. struct perf_counter_context *ctx, int cpu);
  590. extern void perf_counter_update_userpage(struct perf_counter *counter);
  591. struct perf_sample_data {
  592. struct pt_regs *regs;
  593. u64 addr;
  594. u64 period;
  595. struct perf_raw_record *raw;
  596. };
  597. extern int perf_counter_overflow(struct perf_counter *counter, int nmi,
  598. struct perf_sample_data *data);
  599. /*
  600. * Return 1 for a software counter, 0 for a hardware counter
  601. */
  602. static inline int is_software_counter(struct perf_counter *counter)
  603. {
  604. return (counter->attr.type != PERF_TYPE_RAW) &&
  605. (counter->attr.type != PERF_TYPE_HARDWARE) &&
  606. (counter->attr.type != PERF_TYPE_HW_CACHE);
  607. }
  608. extern atomic_t perf_swcounter_enabled[PERF_COUNT_SW_MAX];
  609. extern void __perf_swcounter_event(u32, u64, int, struct pt_regs *, u64);
  610. static inline void
  611. perf_swcounter_event(u32 event, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
  612. {
  613. if (atomic_read(&perf_swcounter_enabled[event]))
  614. __perf_swcounter_event(event, nr, nmi, regs, addr);
  615. }
  616. extern void __perf_counter_mmap(struct vm_area_struct *vma);
  617. static inline void perf_counter_mmap(struct vm_area_struct *vma)
  618. {
  619. if (vma->vm_flags & VM_EXEC)
  620. __perf_counter_mmap(vma);
  621. }
  622. extern void perf_counter_comm(struct task_struct *tsk);
  623. extern void perf_counter_fork(struct task_struct *tsk);
  624. extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
  625. extern int sysctl_perf_counter_paranoid;
  626. extern int sysctl_perf_counter_mlock;
  627. extern int sysctl_perf_counter_sample_rate;
  628. extern void perf_counter_init(void);
  629. extern void perf_tpcounter_event(int event_id, u64 addr, u64 count,
  630. void *record, int entry_size);
  631. #ifndef perf_misc_flags
  632. #define perf_misc_flags(regs) (user_mode(regs) ? PERF_EVENT_MISC_USER : \
  633. PERF_EVENT_MISC_KERNEL)
  634. #define perf_instruction_pointer(regs) instruction_pointer(regs)
  635. #endif
  636. #else
  637. static inline void
  638. perf_counter_task_sched_in(struct task_struct *task, int cpu) { }
  639. static inline void
  640. perf_counter_task_sched_out(struct task_struct *task,
  641. struct task_struct *next, int cpu) { }
  642. static inline void
  643. perf_counter_task_tick(struct task_struct *task, int cpu) { }
  644. static inline int perf_counter_init_task(struct task_struct *child) { return 0; }
  645. static inline void perf_counter_exit_task(struct task_struct *child) { }
  646. static inline void perf_counter_free_task(struct task_struct *task) { }
  647. static inline void perf_counter_do_pending(void) { }
  648. static inline void perf_counter_print_debug(void) { }
  649. static inline void perf_disable(void) { }
  650. static inline void perf_enable(void) { }
  651. static inline int perf_counter_task_disable(void) { return -EINVAL; }
  652. static inline int perf_counter_task_enable(void) { return -EINVAL; }
  653. static inline void
  654. perf_swcounter_event(u32 event, u64 nr, int nmi,
  655. struct pt_regs *regs, u64 addr) { }
  656. static inline void perf_counter_mmap(struct vm_area_struct *vma) { }
  657. static inline void perf_counter_comm(struct task_struct *tsk) { }
  658. static inline void perf_counter_fork(struct task_struct *tsk) { }
  659. static inline void perf_counter_init(void) { }
  660. #endif
  661. #endif /* __KERNEL__ */
  662. #endif /* _LINUX_PERF_COUNTER_H */