perf_counter.h 17.0 KB
Newer Older
T
Thomas Gleixner 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 *  Performance counters:
 *
 *   Copyright(C) 2008, Thomas Gleixner <tglx@linutronix.de>
 *   Copyright(C) 2008, Red Hat, Inc., Ingo Molnar
 *
 *  Data type definitions, declarations, prototypes.
 *
 *  Started by: Thomas Gleixner and Ingo Molnar
 *
 *  For licencing details see kernel-base/COPYING
 */
#ifndef _LINUX_PERF_COUNTER_H
#define _LINUX_PERF_COUNTER_H

16 17
#include <linux/types.h>
#include <linux/ioctl.h>
18
#include <asm/byteorder.h>
T
Thomas Gleixner 已提交
19 20

/*
I
Ingo Molnar 已提交
21 22 23 24
 * User-space ABI bits:
 */

/*
25
 * attr.type
T
Thomas Gleixner 已提交
26
 */
P
Peter Zijlstra 已提交
27
enum perf_type_id {
28 29 30
	PERF_TYPE_HARDWARE		= 0,
	PERF_TYPE_SOFTWARE		= 1,
	PERF_TYPE_TRACEPOINT		= 2,
31
	PERF_TYPE_HW_CACHE		= 3,
P
Peter Zijlstra 已提交
32
	PERF_TYPE_RAW			= 4,
33

P
Peter Zijlstra 已提交
34
	PERF_TYPE_MAX,			/* non ABI */
35
};
36

37
/*
38
 * Generalized performance counter event types, used by the attr.event_id
39 40
 * parameter of the sys_perf_counter_open() syscall:
 */
P
Peter Zijlstra 已提交
41
enum perf_hw_id {
I
Ingo Molnar 已提交
42
	/*
43
	 * Common hardware events, generalized by the kernel:
I
Ingo Molnar 已提交
44
	 */
45 46 47 48 49 50 51 52 53
	PERF_COUNT_HW_CPU_CYCLES		= 0,
	PERF_COUNT_HW_INSTRUCTIONS		= 1,
	PERF_COUNT_HW_CACHE_REFERENCES		= 2,
	PERF_COUNT_HW_CACHE_MISSES		= 3,
	PERF_COUNT_HW_BRANCH_INSTRUCTIONS	= 4,
	PERF_COUNT_HW_BRANCH_MISSES		= 5,
	PERF_COUNT_HW_BUS_CYCLES		= 6,

	PERF_COUNT_HW_MAX,		/* non ABI */
54
};
55

56 57 58
/*
 * Generalized hardware cache counters:
 *
59
 *       { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x
60 61 62
 *       { read, write, prefetch } x
 *       { accesses, misses }
 */
P
Peter Zijlstra 已提交
63 64 65
enum perf_hw_cache_id {
	PERF_COUNT_HW_CACHE_L1D		= 0,
	PERF_COUNT_HW_CACHE_L1I		= 1,
66
	PERF_COUNT_HW_CACHE_LL		= 2,
P
Peter Zijlstra 已提交
67 68 69 70 71
	PERF_COUNT_HW_CACHE_DTLB	= 3,
	PERF_COUNT_HW_CACHE_ITLB	= 4,
	PERF_COUNT_HW_CACHE_BPU		= 5,

	PERF_COUNT_HW_CACHE_MAX,	/* non ABI */
72 73
};

P
Peter Zijlstra 已提交
74 75 76 77
enum perf_hw_cache_op_id {
	PERF_COUNT_HW_CACHE_OP_READ	= 0,
	PERF_COUNT_HW_CACHE_OP_WRITE	= 1,
	PERF_COUNT_HW_CACHE_OP_PREFETCH	= 2,
78

P
Peter Zijlstra 已提交
79
	PERF_COUNT_HW_CACHE_OP_MAX,	/* non ABI */
80 81
};

P
Peter Zijlstra 已提交
82 83 84
enum perf_hw_cache_op_result_id {
	PERF_COUNT_HW_CACHE_RESULT_ACCESS	= 0,
	PERF_COUNT_HW_CACHE_RESULT_MISS		= 1,
85

P
Peter Zijlstra 已提交
86
	PERF_COUNT_HW_CACHE_RESULT_MAX,		/* non ABI */
87 88
};

89 90 91 92 93 94
/*
 * Special "software" counters provided by the kernel, even if the hardware
 * does not support performance counters. These counters measure various
 * physical and sw events of the kernel (and allow the profiling of them as
 * well):
 */
P
Peter Zijlstra 已提交
95
enum perf_sw_ids {
96 97 98 99 100 101 102 103 104
	PERF_COUNT_SW_CPU_CLOCK		= 0,
	PERF_COUNT_SW_TASK_CLOCK	= 1,
	PERF_COUNT_SW_PAGE_FAULTS	= 2,
	PERF_COUNT_SW_CONTEXT_SWITCHES	= 3,
	PERF_COUNT_SW_CPU_MIGRATIONS	= 4,
	PERF_COUNT_SW_PAGE_FAULTS_MIN	= 5,
	PERF_COUNT_SW_PAGE_FAULTS_MAJ	= 6,

	PERF_COUNT_SW_MAX,		/* non ABI */
T
Thomas Gleixner 已提交
105 106
};

107
/*
108
 * Bits that can be set in attr.sample_type to request information
109 110
 * in the overflow packets.
 */
111 112 113 114 115 116 117
enum perf_counter_sample_format {
	PERF_SAMPLE_IP			= 1U << 0,
	PERF_SAMPLE_TID			= 1U << 1,
	PERF_SAMPLE_TIME		= 1U << 2,
	PERF_SAMPLE_ADDR		= 1U << 3,
	PERF_SAMPLE_GROUP		= 1U << 4,
	PERF_SAMPLE_CALLCHAIN		= 1U << 5,
118
	PERF_SAMPLE_ID			= 1U << 6,
119
	PERF_SAMPLE_CPU			= 1U << 7,
120
	PERF_SAMPLE_PERIOD		= 1U << 8,
121 122
};

123
/*
124
 * Bits that can be set in attr.read_format to request that
125 126 127 128
 * reads on the counter should return the indicated quantities,
 * in increasing order of bit value, after the counter value.
 */
enum perf_counter_read_format {
129 130 131
	PERF_FORMAT_TOTAL_TIME_ENABLED	=  1U << 0,
	PERF_FORMAT_TOTAL_TIME_RUNNING	=  1U << 1,
	PERF_FORMAT_ID			=  1U << 2,
132 133
};

I
Ingo Molnar 已提交
134 135 136
/*
 * Hardware event to monitor via a performance monitoring counter:
 */
137
struct perf_counter_attr {
138
	/*
139 140 141 142 143 144 145
	 * Major type: hardware/software/tracepoint/etc.
	 */
	__u32			type;
	__u32			__reserved_1;

	/*
	 * Type specific configuration information.
146 147
	 */
	__u64			config;
I
Ingo Molnar 已提交
148

149
	union {
150 151
		__u64		sample_period;
		__u64		sample_freq;
152 153
	};

154 155
	__u64			sample_type;
	__u64			read_format;
I
Ingo Molnar 已提交
156

157
	__u64			disabled       :  1, /* off by default        */
158 159 160 161 162 163
				inherit	       :  1, /* children inherit it   */
				pinned	       :  1, /* must always be on PMU */
				exclusive      :  1, /* only group on PMU     */
				exclude_user   :  1, /* don't count user      */
				exclude_kernel :  1, /* ditto kernel          */
				exclude_hv     :  1, /* ditto hypervisor      */
164
				exclude_idle   :  1, /* don't count when idle */
165
				mmap           :  1, /* include mmap data     */
166
				comm	       :  1, /* include comm data     */
167
				freq           :  1, /* use freq, not period  */
168

169
				__reserved_2   : 53;
170

P
Peter Zijlstra 已提交
171
	__u32			wakeup_events;	/* wakeup every n events */
172
	__u32			__reserved_3;
I
Ingo Molnar 已提交
173

174
	__u64			__reserved_4;
175 176
};

177 178 179
/*
 * Ioctls that can be done on a perf counter fd:
 */
180 181 182 183 184
#define PERF_COUNTER_IOC_ENABLE		_IO ('$', 0)
#define PERF_COUNTER_IOC_DISABLE	_IO ('$', 1)
#define PERF_COUNTER_IOC_REFRESH	_IO ('$', 2)
#define PERF_COUNTER_IOC_RESET		_IO ('$', 3)
#define PERF_COUNTER_IOC_PERIOD		_IOW('$', 4, u64)
P
Peter Zijlstra 已提交
185 186 187 188

enum perf_counter_ioc_flags {
	PERF_IOC_FLAG_GROUP		= 1U << 0,
};
189

190 191 192 193 194 195
/*
 * Structure of the page that can be mapped via mmap
 */
struct perf_counter_mmap_page {
	__u32	version;		/* version number of this structure */
	__u32	compat_version;		/* lowest version this is compat with */
196 197 198 199

	/*
	 * Bits needed to read the hw counters in user-space.
	 *
200 201
	 *   u32 seq;
	 *   s64 count;
202
	 *
203 204
	 *   do {
	 *     seq = pc->lock;
205
	 *
206 207 208 209 210 211
	 *     barrier()
	 *     if (pc->index) {
	 *       count = pmc_read(pc->index - 1);
	 *       count += pc->offset;
	 *     } else
	 *       goto regular_read;
212
	 *
213 214
	 *     barrier();
	 *   } while (pc->lock != seq);
215
	 *
216 217
	 * NOTE: for obvious reason this only works on self-monitoring
	 *       processes.
218
	 */
219 220 221
	__u32	lock;			/* seqlock for synchronization */
	__u32	index;			/* hardware counter identifier */
	__s64	offset;			/* add to hardware counter value */
222

223 224 225 226 227 228
	/*
	 * Control data for the mmap() data buffer.
	 *
	 * User-space reading this value should issue an rmb(), on SMP capable
	 * platforms, after reading this value -- see perf_counter_wakeup().
	 */
229
	__u64   data_head;		/* head in the data section */
230 231
};

232 233
#define PERF_EVENT_MISC_CPUMODE_MASK	(3 << 0)
#define PERF_EVENT_MISC_CPUMODE_UNKNOWN	(0 << 0)
234
#define PERF_EVENT_MISC_KERNEL		(1 << 0)
235 236
#define PERF_EVENT_MISC_USER		(2 << 0)
#define PERF_EVENT_MISC_HYPERVISOR	(3 << 0)
237
#define PERF_EVENT_MISC_OVERFLOW	(1 << 2)
238

P
Peter Zijlstra 已提交
239 240
struct perf_event_header {
	__u32	type;
241 242
	__u16	misc;
	__u16	size;
P
Peter Zijlstra 已提交
243 244 245
};

enum perf_event_type {
246

247 248 249 250 251
	/*
	 * The MMAP events record the PROT_EXEC mappings so that we can
	 * correlate userspace IPs to code. They have the following structure:
	 *
	 * struct {
I
Ingo Molnar 已提交
252
	 *	struct perf_event_header	header;
253
	 *
I
Ingo Molnar 已提交
254 255 256 257 258
	 *	u32				pid, tid;
	 *	u64				addr;
	 *	u64				len;
	 *	u64				pgoff;
	 *	char				filename[];
259 260
	 * };
	 */
261
	PERF_EVENT_MMAP			= 1,
262

263 264
	/*
	 * struct {
I
Ingo Molnar 已提交
265
	 *	struct perf_event_header	header;
266
	 *
I
Ingo Molnar 已提交
267 268
	 *	u32				pid, tid;
	 *	char				comm[];
269 270 271 272
	 * };
	 */
	PERF_EVENT_COMM			= 3,

273 274
	/*
	 * struct {
I
Ingo Molnar 已提交
275 276
	 *	struct perf_event_header	header;
	 *	u64				time;
277
	 *	u64				id;
278
	 *	u64				sample_period;
279 280 281 282
	 * };
	 */
	PERF_EVENT_PERIOD		= 4,

283 284
	/*
	 * struct {
I
Ingo Molnar 已提交
285 286
	 *	struct perf_event_header	header;
	 *	u64				time;
287 288 289 290 291
	 * };
	 */
	PERF_EVENT_THROTTLE		= 5,
	PERF_EVENT_UNTHROTTLE		= 6,

P
Peter Zijlstra 已提交
292 293
	/*
	 * struct {
294 295
	 *	struct perf_event_header	header;
	 *	u32				pid, ppid;
P
Peter Zijlstra 已提交
296 297 298 299
	 * };
	 */
	PERF_EVENT_FORK			= 7,

300
	/*
301 302
	 * When header.misc & PERF_EVENT_MISC_OVERFLOW the event_type field
	 * will be PERF_RECORD_*
303 304
	 *
	 * struct {
I
Ingo Molnar 已提交
305
	 *	struct perf_event_header	header;
306
	 *
I
Ingo Molnar 已提交
307 308 309 310 311 312
	 *	{ u64			ip;	  } && PERF_RECORD_IP
	 *	{ u32			pid, tid; } && PERF_RECORD_TID
	 *	{ u64			time;     } && PERF_RECORD_TIME
	 *	{ u64			addr;     } && PERF_RECORD_ADDR
	 *	{ u64			config;   } && PERF_RECORD_CONFIG
	 *	{ u32			cpu, res; } && PERF_RECORD_CPU
313
	 *
I
Ingo Molnar 已提交
314
	 *	{ u64			nr;
315
	 *	  { u64 id, val; }	cnt[nr];  } && PERF_RECORD_GROUP
316
	 *
I
Ingo Molnar 已提交
317 318 319 320 321
	 *	{ u16			nr,
	 *				hv,
	 *				kernel,
	 *				user;
	 *	  u64			ips[nr];  } && PERF_RECORD_CALLCHAIN
322
	 * };
323
	 */
P
Peter Zijlstra 已提交
324 325
};

326
#ifdef __KERNEL__
I
Ingo Molnar 已提交
327
/*
328
 * Kernel-internal data types and definitions:
I
Ingo Molnar 已提交
329 330
 */

331 332 333 334 335 336 337 338 339
#ifdef CONFIG_PERF_COUNTERS
# include <asm/perf_counter.h>
#endif

#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/spinlock.h>
340
#include <linux/hrtimer.h>
P
Peter Zijlstra 已提交
341
#include <linux/fs.h>
342
#include <linux/pid_namespace.h>
343 344 345 346
#include <asm/atomic.h>

struct task_struct;

T
Thomas Gleixner 已提交
347
/**
I
Ingo Molnar 已提交
348
 * struct hw_perf_counter - performance counter hardware details:
T
Thomas Gleixner 已提交
349 350
 */
struct hw_perf_counter {
351
#ifdef CONFIG_PERF_COUNTERS
352 353 354 355 356
	union {
		struct { /* hardware */
			u64				config;
			unsigned long			config_base;
			unsigned long			counter_base;
357
			int				idx;
358 359 360 361 362 363
		};
		union { /* software */
			atomic64_t			count;
			struct hrtimer			hrtimer;
		};
	};
364
	atomic64_t			prev_count;
365
	u64				sample_period;
366
	u64				last_period;
367
	atomic64_t			period_left;
368
	u64				interrupts;
369 370 371

	u64				freq_count;
	u64				freq_interrupts;
372
	u64				freq_stamp;
373
#endif
T
Thomas Gleixner 已提交
374 375
};

I
Ingo Molnar 已提交
376 377 378
struct perf_counter;

/**
379
 * struct pmu - generic performance monitoring unit
I
Ingo Molnar 已提交
380
 */
381
struct pmu {
382
	int (*enable)			(struct perf_counter *counter);
I
Ingo Molnar 已提交
383 384
	void (*disable)			(struct perf_counter *counter);
	void (*read)			(struct perf_counter *counter);
385
	void (*unthrottle)		(struct perf_counter *counter);
I
Ingo Molnar 已提交
386 387
};

388 389 390 391
/**
 * enum perf_counter_active_state - the states of a counter
 */
enum perf_counter_active_state {
392
	PERF_COUNTER_STATE_ERROR	= -2,
393 394 395 396 397
	PERF_COUNTER_STATE_OFF		= -1,
	PERF_COUNTER_STATE_INACTIVE	=  0,
	PERF_COUNTER_STATE_ACTIVE	=  1,
};

398 399
struct file;

400 401
struct perf_mmap_data {
	struct rcu_head			rcu_head;
P
Peter Zijlstra 已提交
402
	int				nr_pages;	/* nr of data pages  */
403
	int				nr_locked;	/* nr pages mlocked  */
P
Peter Zijlstra 已提交
404

405
	atomic_t			poll;		/* POLL_ for wakeups */
P
Peter Zijlstra 已提交
406 407
	atomic_t			events;		/* event limit       */

408 409 410
	atomic_long_t			head;		/* write position    */
	atomic_long_t			done_head;	/* completed head    */

411 412
	atomic_t			lock;		/* concurrent writes */

413 414
	atomic_t			wakeup;		/* needs a wakeup    */

415
	struct perf_counter_mmap_page   *user_page;
I
Ingo Molnar 已提交
416
	void				*data_pages[0];
417 418
};

419 420 421
struct perf_pending_entry {
	struct perf_pending_entry *next;
	void (*func)(struct perf_pending_entry *);
422 423
};

T
Thomas Gleixner 已提交
424 425 426 427
/**
 * struct perf_counter - performance counter kernel representation:
 */
struct perf_counter {
428
#ifdef CONFIG_PERF_COUNTERS
429
	struct list_head		list_entry;
P
Peter Zijlstra 已提交
430
	struct list_head		event_entry;
431
	struct list_head		sibling_list;
I
Ingo Molnar 已提交
432
	int				nr_siblings;
433
	struct perf_counter		*group_leader;
434
	const struct pmu		*pmu;
435

436
	enum perf_counter_active_state	state;
T
Thomas Gleixner 已提交
437
	atomic64_t			count;
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
	/*
	 * These are the total time in nanoseconds that the counter
	 * has been enabled (i.e. eligible to run, and the task has
	 * been scheduled in, if this is a per-task counter)
	 * and running (scheduled onto the CPU), respectively.
	 *
	 * They are computed from tstamp_enabled, tstamp_running and
	 * tstamp_stopped when the counter is in INACTIVE or ACTIVE state.
	 */
	u64				total_time_enabled;
	u64				total_time_running;

	/*
	 * These are timestamps used for computing total_time_enabled
	 * and total_time_running when the counter is in INACTIVE or
	 * ACTIVE state, measured in nanoseconds from an arbitrary point
	 * in time.
	 * tstamp_enabled: the notional time when the counter was enabled
	 * tstamp_running: the notional time when the counter was scheduled on
	 * tstamp_stopped: in INACTIVE state, the notional time when the
	 *	counter was scheduled off.
	 */
	u64				tstamp_enabled;
	u64				tstamp_running;
	u64				tstamp_stopped;

465
	struct perf_counter_attr	attr;
T
Thomas Gleixner 已提交
466 467 468
	struct hw_perf_counter		hw;

	struct perf_counter_context	*ctx;
469
	struct file			*filp;
T
Thomas Gleixner 已提交
470

471 472 473 474 475 476 477
	/*
	 * These accumulate total time (in nanoseconds) that children
	 * counters have been enabled and running, respectively.
	 */
	atomic64_t			child_total_time_enabled;
	atomic64_t			child_total_time_running;

T
Thomas Gleixner 已提交
478
	/*
479
	 * Protect attach/detach and child_list:
T
Thomas Gleixner 已提交
480
	 */
481 482 483
	struct mutex			child_mutex;
	struct list_head		child_list;
	struct perf_counter		*parent;
T
Thomas Gleixner 已提交
484 485 486 487

	int				oncpu;
	int				cpu;

488 489 490
	struct list_head		owner_entry;
	struct task_struct		*owner;

491 492 493 494
	/* mmap bits */
	struct mutex			mmap_mutex;
	atomic_t			mmap_count;
	struct perf_mmap_data		*data;
495

496
	/* poll related */
T
Thomas Gleixner 已提交
497
	wait_queue_head_t		waitq;
P
Peter Zijlstra 已提交
498
	struct fasync_struct		*fasync;
499 500 501

	/* delayed work for NMIs and such */
	int				pending_wakeup;
502
	int				pending_kill;
503
	int				pending_disable;
504
	struct perf_pending_entry	pending;
P
Peter Zijlstra 已提交
505

506 507
	atomic_t			event_limit;

508
	void (*destroy)(struct perf_counter *);
P
Peter Zijlstra 已提交
509
	struct rcu_head			rcu_head;
510 511

	struct pid_namespace		*ns;
512
	u64				id;
513
#endif
T
Thomas Gleixner 已提交
514 515 516 517 518 519 520 521 522
};

/**
 * struct perf_counter_context - counter context structure
 *
 * Used as a container for task counters and CPU counters as well:
 */
struct perf_counter_context {
	/*
523 524
	 * Protect the states of the counters in the list,
	 * nr_active, and the list:
T
Thomas Gleixner 已提交
525 526
	 */
	spinlock_t		lock;
527 528 529 530 531 532
	/*
	 * Protect the list of counters.  Locking either mutex or lock
	 * is sufficient to ensure the list doesn't change; to change
	 * the list you need to lock both the mutex and the spinlock.
	 */
	struct mutex		mutex;
533 534

	struct list_head	counter_list;
P
Peter Zijlstra 已提交
535
	struct list_head	event_list;
T
Thomas Gleixner 已提交
536 537
	int			nr_counters;
	int			nr_active;
538
	int			is_active;
539
	atomic_t		refcount;
T
Thomas Gleixner 已提交
540
	struct task_struct	*task;
541 542

	/*
543
	 * Context clock, runs when context enabled.
544
	 */
545 546
	u64			time;
	u64			timestamp;
547 548 549 550 551 552

	/*
	 * These fields let us detect when two contexts have both
	 * been cloned (inherited) from a common ancestor.
	 */
	struct perf_counter_context *parent_ctx;
553 554
	u64			parent_gen;
	u64			generation;
555
	int			pin_count;
556
	struct rcu_head		rcu_head;
T
Thomas Gleixner 已提交
557 558 559 560 561 562 563 564 565 566
};

/**
 * struct perf_counter_cpu_context - per cpu counter context structure
 */
struct perf_cpu_context {
	struct perf_counter_context	ctx;
	struct perf_counter_context	*task_ctx;
	int				active_oncpu;
	int				max_pertask;
567
	int				exclusive;
P
Peter Zijlstra 已提交
568 569 570 571 572 573

	/*
	 * Recursion avoidance:
	 *
	 * task, softirq, irq, nmi context
	 */
574
	int				recursion[4];
T
Thomas Gleixner 已提交
575 576
};

577 578
#ifdef CONFIG_PERF_COUNTERS

T
Thomas Gleixner 已提交
579 580 581 582 583
/*
 * Set by architecture code:
 */
extern int perf_max_counters;

584
extern const struct pmu *hw_perf_counter_init(struct perf_counter *counter);
I
Ingo Molnar 已提交
585

T
Thomas Gleixner 已提交
586
extern void perf_counter_task_sched_in(struct task_struct *task, int cpu);
587 588
extern void perf_counter_task_sched_out(struct task_struct *task,
					struct task_struct *next, int cpu);
T
Thomas Gleixner 已提交
589
extern void perf_counter_task_tick(struct task_struct *task, int cpu);
590
extern int perf_counter_init_task(struct task_struct *child);
591
extern void perf_counter_exit_task(struct task_struct *child);
592
extern void perf_counter_free_task(struct task_struct *task);
593
extern void perf_counter_do_pending(void);
T
Thomas Gleixner 已提交
594
extern void perf_counter_print_debug(void);
595 596 597 598
extern void __perf_disable(void);
extern bool __perf_enable(void);
extern void perf_disable(void);
extern void perf_enable(void);
599 600
extern int perf_counter_task_disable(void);
extern int perf_counter_task_enable(void);
601 602 603
extern int hw_perf_group_sched_in(struct perf_counter *group_leader,
	       struct perf_cpu_context *cpuctx,
	       struct perf_counter_context *ctx, int cpu);
604
extern void perf_counter_update_userpage(struct perf_counter *counter);
605

606
struct perf_sample_data {
607 608 609
	struct pt_regs		*regs;
	u64			addr;
	u64			period;
610 611 612 613 614
};

extern int perf_counter_overflow(struct perf_counter *counter, int nmi,
				 struct perf_sample_data *data);

615 616 617 618 619
/*
 * Return 1 for a software counter, 0 for a hardware counter
 */
static inline int is_software_counter(struct perf_counter *counter)
{
620 621
	return (counter->attr.type != PERF_TYPE_RAW) &&
		(counter->attr.type != PERF_TYPE_HARDWARE);
622 623
}

624
extern void perf_swcounter_event(u32, u64, int, struct pt_regs *, u64);
625

626 627 628 629 630 631 632
extern void __perf_counter_mmap(struct vm_area_struct *vma);

static inline void perf_counter_mmap(struct vm_area_struct *vma)
{
	if (vma->vm_flags & VM_EXEC)
		__perf_counter_mmap(vma);
}
633

634
extern void perf_counter_comm(struct task_struct *tsk);
P
Peter Zijlstra 已提交
635
extern void perf_counter_fork(struct task_struct *tsk);
636

637 638
extern void perf_counter_task_migration(struct task_struct *task, int cpu);

639
#define MAX_STACK_DEPTH		255
640 641

struct perf_callchain_entry {
642
	u16	nr, hv, kernel, user;
643 644 645 646 647
	u64	ip[MAX_STACK_DEPTH];
};

extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);

648
extern int sysctl_perf_counter_paranoid;
649
extern int sysctl_perf_counter_mlock;
650
extern int sysctl_perf_counter_sample_rate;
651

652 653
extern void perf_counter_init(void);

654 655 656 657 658 659
#ifndef perf_misc_flags
#define perf_misc_flags(regs)	(user_mode(regs) ? PERF_EVENT_MISC_USER : \
				 PERF_EVENT_MISC_KERNEL)
#define perf_instruction_pointer(regs)	instruction_pointer(regs)
#endif

T
Thomas Gleixner 已提交
660 661 662 663
#else
static inline void
perf_counter_task_sched_in(struct task_struct *task, int cpu)		{ }
static inline void
664 665
perf_counter_task_sched_out(struct task_struct *task,
			    struct task_struct *next, int cpu)		{ }
T
Thomas Gleixner 已提交
666 667
static inline void
perf_counter_task_tick(struct task_struct *task, int cpu)		{ }
668
static inline int perf_counter_init_task(struct task_struct *child)	{ return 0; }
669
static inline void perf_counter_exit_task(struct task_struct *child)	{ }
670
static inline void perf_counter_free_task(struct task_struct *task)	{ }
671
static inline void perf_counter_do_pending(void)			{ }
T
Thomas Gleixner 已提交
672
static inline void perf_counter_print_debug(void)			{ }
673 674
static inline void perf_disable(void)					{ }
static inline void perf_enable(void)					{ }
675 676
static inline int perf_counter_task_disable(void)	{ return -EINVAL; }
static inline int perf_counter_task_enable(void)	{ return -EINVAL; }
677

678
static inline void
679 680
perf_swcounter_event(u32 event, u64 nr, int nmi,
		     struct pt_regs *regs, u64 addr)			{ }
681

682
static inline void perf_counter_mmap(struct vm_area_struct *vma)	{ }
683
static inline void perf_counter_comm(struct task_struct *tsk)		{ }
P
Peter Zijlstra 已提交
684
static inline void perf_counter_fork(struct task_struct *tsk)		{ }
685
static inline void perf_counter_init(void)				{ }
686 687
static inline void perf_counter_task_migration(struct task_struct *task,
					       int cpu)			{ }
T
Thomas Gleixner 已提交
688 689
#endif

690
#endif /* __KERNEL__ */
T
Thomas Gleixner 已提交
691
#endif /* _LINUX_PERF_COUNTER_H */