1#ifndef _LINUX_KERNPROF_H
2#define _LINUX_KERNPROF_H
3
4#include <linux/ioctl.h>
5
6#define CG_MAX_ARCS (1 << (8 * sizeof(short)))
7
8#define PROF_BACKTRACE_BUFSIZE	4096  /* must be a power of 2 */
9#define PROF_BACKTRACE_MAX_LEN	24
10
11typedef unsigned int PC_sample_count_t;
12
13/* profiling ioctl requests */
14#define PROF_START		_IO(0xAF, 0)
15#define PROF_STOP		_IO(0xAF, 1)
16#define PROF_RESET		_IO(0xAF, 2)
17#define PROF_SET_SAMPLE_FREQ	_IOW(0xAF, 3, int)
18#define PROF_GET_SAMPLE_FREQ	_IOR(0xAF, 4, int)
19#define PROF_GET_PC_RES		_IOR(0xAF, 5, int)
20#define PROF_GET_ON_OFF_STATE	_IOR(0xAF, 6, int)
21#define PROF_SET_DOMAIN		_IOW(0xAF, 7, int)
22#define PROF_GET_DOMAIN		_IOR(0xAF, 8, int)
23#define PROF_SET_MODE		_IOW(0xAF, 9, int)
24#define PROF_GET_MODE		_IOR(0xAF, 10, int)
25#define PROF_SET_PERFCTR_EVENT	_IOW(0xAF, 11, int)
26#define PROF_GET_PERFCTR_EVENT	_IOR(0xAF, 12, int)
27/* PROF_*_ENABLE_MAP and PROF_GET_MAPPING ioctl requests are defined below */
28#define PROF_SET_PID		_IOW(0xAF, 16, int)
29#define PROF_GET_PID		_IOR(0xAF, 17, int)
30
31enum {
32	PROF_MODE_PC_SAMPLING = 1,
33	PROF_MODE_CALL_GRAPH = 2,
34	PROF_MODE_BACKTRACE = 4,
35	PROF_MODE_CALL_COUNT = 8,
36	PROF_MODE_SCHEDULER_CALL_GRAPH = 16
37};
38
39enum {
40	PROF_DOMAIN_TIME,
41	PROF_DOMAIN_PERFCTR
42};
43
44#if defined(CONFIG_KERNPROF) || defined(CONFIG_MCOUNT)
45/*
46 * To allow for profiling of loaded modules, this structure
47 * describes the layout of the buckets used to collect samples.
48 */
49
50typedef struct prof_mem_map
51{
52   unsigned long     kernel_buckets;   /* number of kernel buckets */
53   unsigned long     module_buckets;   /* number of module buckets */
54   unsigned long     nr_cpus;          /* number of processors whether profiled or not */
55   unsigned long     cg_from_size;     /* size of one cg_from array */
56   unsigned long     cg_to_size;       /* size of one cg_to array */
57   unsigned long     cg_to_offset;     /* offset of cg_to array */
58   unsigned long     kernel_start;     /* lowest text address in kernel */
59   unsigned long     kernel_end;       /* highest text address in kernel */
60   unsigned long     module_start;     /* lowest text address in all modules */
61   unsigned long     module_end;       /* highest text address in all modules */
62} prof_mem_map_t;
63#endif /* CONFIG_KERNPROF or CONFIG_MCOUNT */
64
65#ifdef __KERNEL__
66
67#include <asm/atomic.h>
68#include <asm/ptrace.h>
69
70/*
71 * We don't export this to user space because its pointers may be of different
72 * size.  If user space needs this it should define its own version making sure
73 * that individual fields are of the same size as in the kernel definition.
74 */
75struct cg_arc_dest {
76	unsigned long address;
77	atomic_t count;
78	unsigned short link;
79	unsigned short pad;
80};
81
82/*
83 * We do not export these ioctl requests to user space because it may have
84 * longs of different size.
85 */
86#define PROF_SET_ENABLE_MAP	_IOW(0xAF, 13, long)
87#define PROF_GET_ENABLE_MAP	_IOR(0xAF, 14, long)
88#define PROF_GET_MAPPING	_IOR(0xAF, 15, long)
89
90
91typedef void (*prof_hook_p)(struct pt_regs *);
92typedef void (*mcount_hook_p)(unsigned long, unsigned long);
93typedef void (*wakeup_hook_p)(unsigned long, unsigned long, unsigned long);
94
95extern char _stext, _etext;
96extern prof_hook_p prof_timer_hook;
97extern prof_hook_p prof_perfctr_hook;
98extern mcount_hook_p prof_scheduler_hook;
99extern wakeup_hook_p prof_wakeup_hook;
100extern mcount_hook_p mcount_hook;
101
102extern int prof_have_frameptr, prof_have_mcount;
103
104extern void USER(void);            /* these can not be in a module */
105extern void UNKNOWN_KERNEL(void);
106extern void FIRMWARE(void);
107extern void STALLED(void);
108extern void SLEEPING(void);
109extern void MODULE(void);
110
111#define pc_out_of_range(pc)	\
112	((pc) < (unsigned long) &_stext || (pc) >= (unsigned long) &_etext)
113
114/* might be overridden by arch-specific redefinition */
115#define FUNCTIONPC(func)	(unsigned long) &(func)
116
117#endif /* __KERNEL__ */
118
119#endif /* !_LINUX_KERNPROF_H */
120