2 * Copyright (C) 2001-2003 Hewlett-Packard Co
3 * Stephane Eranian <eranian@hpl.hp.com>
6 #ifndef _ASM_IA64_PERFMON_H
7 #define _ASM_IA64_PERFMON_H
10 * perfmon comamnds supported on all CPU models
12 #define PFM_WRITE_PMCS 0x01
13 #define PFM_WRITE_PMDS 0x02
14 #define PFM_READ_PMDS 0x03
16 #define PFM_START 0x05
17 #define PFM_ENABLE 0x06 /* obsolete */
18 #define PFM_DISABLE 0x07 /* obsolete */
19 #define PFM_CREATE_CONTEXT 0x08
20 #define PFM_DESTROY_CONTEXT 0x09 /* obsolete use close() */
21 #define PFM_RESTART 0x0a
22 #define PFM_PROTECT_CONTEXT 0x0b /* obsolete */
23 #define PFM_GET_FEATURES 0x0c
24 #define PFM_DEBUG 0x0d
25 #define PFM_UNPROTECT_CONTEXT 0x0e /* obsolete */
26 #define PFM_GET_PMC_RESET_VAL 0x0f
27 #define PFM_LOAD_CONTEXT 0x10
28 #define PFM_UNLOAD_CONTEXT 0x11
31 * PMU model specific commands (may not be supported on all PMU models)
33 #define PFM_WRITE_IBRS 0x20
34 #define PFM_WRITE_DBRS 0x21
39 #define PFM_FL_NOTIFY_BLOCK 0x01 /* block task on user level notifications */
40 #define PFM_FL_SYSTEM_WIDE 0x02 /* create a system wide context */
41 #define PFM_FL_UNSECURE 0x04 /* allow unsecure monitoring for non self-monitoring task */
42 #define PFM_FL_OVFL_NO_MSG 0x80 /* do not post overflow/end messages for notification */
47 #define PFM_SETFL_EXCL_IDLE 0x01 /* exclude idle task (syswide only) XXX: DO NOT USE YET */
52 #define PFM_REGFL_OVFL_NOTIFY 0x1 /* send notification on overflow */
53 #define PFM_REGFL_RANDOM 0x2 /* randomize sampling interval */
56 * PMD/PMC/IBR/DBR return flags (ignored on input)
58 * Those flags are used on output and must be checked in case EAGAIN is returned
59 * by any of the calls using a pfarg_reg_t or pfarg_dbreg_t structure.
61 #define PFM_REG_RETFL_NOTAVAIL (1UL<<31) /* set if register is implemented but not available */
62 #define PFM_REG_RETFL_EINVAL (1UL<<30) /* set if register entry is invalid */
63 #define PFM_REG_RETFL_MASK (PFM_REG_RETFL_NOTAVAIL|PFM_REG_RETFL_EINVAL)
65 #define PFM_REG_HAS_ERROR(flag) (((flag) & PFM_REG_RETFL_MASK) != 0)
67 typedef unsigned char pfm_uuid_t[16]; /* custom sampling buffer identifier type */
70 * Request structure used to define a context
73 pfm_uuid_t ctx_smpl_buf_id; /* which buffer format to use (if needed) */
74 unsigned long ctx_flags; /* noblock/block */
75 unsigned int ctx_nextra_sets; /* number of extra event sets (you always get 1) */
76 int ctx_fd; /* return arg: unique identification for context */
77 void *ctx_smpl_vaddr; /* return arg: virtual address of sampling buffer, is used */
78 unsigned long ctx_reserved[11]; /* for future use */
82 * Request structure used to write/read a PMC or PMD
85 unsigned int reg_num; /* which register */
86 unsigned int reg_set; /* event set for this register */
88 unsigned long reg_value; /* initial pmc/pmd value */
89 unsigned long reg_flags; /* input: pmc/pmd flags, return: reg error */
91 unsigned long reg_long_reset; /* reset after buffer overflow notification */
92 unsigned long reg_short_reset; /* reset after counter overflow */
94 unsigned long reg_reset_pmds[4]; /* which other counters to reset on overflow */
95 unsigned long reg_random_seed; /* seed value when randomization is used */
96 unsigned long reg_random_mask; /* bitmask used to limit random value */
97 unsigned long reg_last_reset_val;/* return: PMD last reset value */
99 unsigned long reg_smpl_pmds[4]; /* which pmds are accessed when PMC overflows */
100 unsigned long reg_smpl_eventid; /* opaque sampling event identifier */
102 unsigned long reserved[3]; /* for future use */
106 unsigned int dbreg_num; /* which debug register */
107 unsigned int dbreg_set; /* event set for this register */
108 unsigned long dbreg_value; /* value for debug register */
109 unsigned long dbreg_flags; /* return: dbreg error */
110 unsigned long dbreg_reserved[1]; /* for future use */
114 unsigned int ft_version; /* perfmon: major [16-31], minor [0-15] */
115 unsigned int ft_reserved; /* reserved for future use */
116 unsigned long reserved[4]; /* for future use */
120 pid_t load_pid; /* process to load the context into */
121 unsigned int load_set; /* first event set to load */
122 unsigned long load_reserved[2]; /* for future use */
126 int msg_type; /* generic message header */
127 int msg_ctx_fd; /* generic message header */
128 unsigned long msg_tstamp; /* for perf tuning */
129 unsigned int msg_active_set; /* active set at the time of overflow */
130 unsigned long msg_ovfl_pmds[4]; /* which PMDs overflowed */
134 int msg_type; /* generic message header */
135 int msg_ctx_fd; /* generic message header */
136 unsigned long msg_tstamp; /* for perf tuning */
140 int msg_type; /* type of the message */
141 int msg_ctx_fd; /* unique identifier for the context */
142 unsigned long msg_tstamp; /* for perf tuning */
145 #define PFM_MSG_OVFL 1 /* an overflow happened */
146 #define PFM_MSG_END 2 /* task to which context was attached ended */
149 pfm_ovfl_msg_t pfm_ovfl_msg;
150 pfm_end_msg_t pfm_end_msg;
151 pfm_gen_msg_t pfm_gen_msg;
155 * Define the version numbers for both perfmon as a whole and the sampling buffer format.
157 #define PFM_VERSION_MAJ 2U
158 #define PFM_VERSION_MIN 0U
159 #define PFM_SMPL_HDR_VERSION_MAJ 2U
160 #define PFM_SMPL_HDR_VERSION_MIN 0U
161 #define PFM_VERSION (((PFM_VERSION_MAJ&0xffff)<<16)|(PFM_VERSION_MIN & 0xffff))
162 #define PFM_VERSION_MAJOR(x) (((x)>>16) & 0xffff)
163 #define PFM_VERSION_MINOR(x) ((x) & 0xffff)
167 * miscellaneous architected definitions
169 #define PMU_FIRST_COUNTER 4 /* first counting monitor (PMC/PMD) */
170 #define PMU_MAX_PMCS 256 /* maximum architected number of PMC registers */
171 #define PMU_MAX_PMDS 256 /* maximum architected number of PMD registers */
175 extern long perfmonctl(int fd, int cmd, void *arg, int narg);
177 extern void pfm_save_regs (struct task_struct *);
178 extern void pfm_load_regs (struct task_struct *);
180 extern void pfm_exit_thread(struct task_struct *);
181 extern int pfm_use_debug_registers(struct task_struct *);
182 extern int pfm_release_debug_registers(struct task_struct *);
183 extern void pfm_syst_wide_update_task(struct task_struct *, unsigned long info, int is_ctxswin);
184 extern void pfm_inherit(struct task_struct *task, struct pt_regs *regs);
185 extern void pfm_init_percpu(void);
186 extern void pfm_handle_work(void);
189 * Reset PMD register flags
191 #define PFM_PMD_NO_RESET 0
192 #define PFM_PMD_LONG_RESET 1
193 #define PFM_PMD_SHORT_RESET 2
196 unsigned int notify_user:1; /* notify user program of overflow */
197 unsigned int reset_pmds :2; /* PFM_PMD_NO_RESET, PFM_PMD_LONG_RESET, PFM_PMD_SHORT_RESET */
198 unsigned int block:1; /* block monitored task on kernel exit */
199 unsigned int stop_monitoring:1; /* will mask monitoring via PMCx.plm */
200 unsigned int reserved:26; /* for future use */
204 unsigned long ovfl_pmds[4]; /* bitmask of overflowed pmds */
205 unsigned long ovfl_notify[4]; /* bitmask of overflow pmds which asked for notification */
206 unsigned long pmd_value; /* current 64-bit value of 1st pmd which overflowed */
207 unsigned long pmd_last_reset; /* last reset value of 1st pmd which overflowed */
208 unsigned long pmd_eventid; /* eventid associated with 1st pmd which overflowed */
209 unsigned int active_set; /* event set active at the time of the overflow */
210 unsigned int reserved1;
211 unsigned long smpl_pmds[4];
212 unsigned long smpl_pmds_values[PMU_MAX_PMDS];
213 pfm_ovfl_ctrl_t ovfl_ctrl; /* return: perfmon controls to set by handler */
217 typedef struct _pfm_buffer_fmt_t {
221 unsigned long fmt_flags;
223 int (*fmt_validate)(struct task_struct *task, unsigned int flags, int cpu, void *arg);
224 int (*fmt_getsize)(struct task_struct *task, unsigned int flags, int cpu, void *arg, unsigned long *size);
225 int (*fmt_init)(struct task_struct *task, void *buf, unsigned int flags, int cpu, void *arg);
226 int (*fmt_handler)(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct pt_regs *regs);
227 int (*fmt_restart)(struct task_struct *task, pfm_ovfl_ctrl_t *ctrl, void *buf, struct pt_regs *regs);
228 int (*fmt_restart_active)(struct task_struct *task, pfm_ovfl_ctrl_t *ctrl, void *buf, struct pt_regs *regs);
229 int (*fmt_exit)(struct task_struct *task, void *buf, struct pt_regs *regs);
231 struct _pfm_buffer_fmt_t *fmt_next;
232 struct _pfm_buffer_fmt_t *fmt_prev;
235 extern int pfm_register_buffer_fmt(pfm_buffer_fmt_t *fmt);
236 extern int pfm_unregister_buffer_fmt(pfm_uuid_t uuid);
239 * perfmon interface exported to modules
241 extern long pfm_mod_fast_read_pmds(struct task_struct *, unsigned long mask[4], unsigned long *addr, struct pt_regs *regs);
242 extern long pfm_mod_read_pmds(struct task_struct *, pfarg_reg_t *req, unsigned int nreq, struct pt_regs *regs);
243 extern long pfm_mod_write_pmcs(struct task_struct *, pfarg_reg_t *req, unsigned int nreq, struct pt_regs *regs);
246 * describe the content of the local_cpu_date->pfm_syst_info field
248 #define PFM_CPUINFO_SYST_WIDE 0x1 /* if set a system wide session exists */
249 #define PFM_CPUINFO_DCR_PP 0x2 /* if set the system wide session has started */
250 #define PFM_CPUINFO_EXCL_IDLE 0x4 /* the system wide session excludes the idle task */
252 #endif /* __KERNEL__ */
254 #endif /* _ASM_IA64_PERFMON_H */