1 /* 2 * Copyright (C) 2001-2003 Hewlett-Packard Co 3 * Stephane Eranian <eranian@hpl.hp.com> 4 */ 5 6 #ifndef _ASM_IA64_PERFMON_H 7 #define _ASM_IA64_PERFMON_H 8 9 /* 10 * perfmon comamnds supported on all CPU models 11 */ 12 #define PFM_WRITE_PMCS 0x01 13 #define PFM_WRITE_PMDS 0x02 14 #define PFM_READ_PMDS 0x03 15 #define PFM_STOP 0x04 16 #define PFM_START 0x05 17 #define PFM_ENABLE 0x06 18 #define PFM_DISABLE 0x07 19 #define PFM_CREATE_CONTEXT 0x08 20 #define PFM_DESTROY_CONTEXT 0x09 21 #define PFM_RESTART 0x0a 22 #define PFM_PROTECT_CONTEXT 0x0b 23 #define PFM_GET_FEATURES 0x0c 24 #define PFM_DEBUG 0x0d 25 #define PFM_UNPROTECT_CONTEXT 0x0e 26 #define PFM_GET_PMC_RESET_VAL 0x0f 27 28 29 /* 30 * CPU model specific commands (may not be supported on all models) 31 */ 32 #define PFM_WRITE_IBRS 0x20 33 #define PFM_WRITE_DBRS 0x21 34 35 /* 36 * context flags 37 */ 38 #define PFM_FL_INHERIT_NONE 0x00 /* never inherit a context across fork (default) */ 39 #define PFM_FL_INHERIT_ONCE 0x01 /* clone pfm_context only once across fork() */ 40 #define PFM_FL_INHERIT_ALL 0x02 /* always clone pfm_context across fork() */ 41 #define PFM_FL_NOTIFY_BLOCK 0x04 /* block task on user level notifications */ 42 #define PFM_FL_SYSTEM_WIDE 0x08 /* create a system wide context */ 43 #define PFM_FL_EXCL_IDLE 0x20 /* exclude idle task from system wide session */ 44 #define PFM_FL_UNSECURE 0x40 /* allow unsecure monitoring for non self-monitoring task */ 45 46 /* 47 * PMC flags 48 */ 49 #define PFM_REGFL_OVFL_NOTIFY 0x1 /* send notification on overflow */ 50 #define PFM_REGFL_RANDOM 0x2 /* randomize sampling interval */ 51 52 /* 53 * PMD/PMC/IBR/DBR return flags (ignored on input) 54 * 55 * Those flags are used on output and must be checked in case EAGAIN is returned 56 * by any of the calls using a pfarg_reg_t or pfarg_dbreg_t structure. 57 */ 58 #define PFM_REG_RETFL_NOTAVAIL (1U<<31) /* set if register is implemented but not available */ 59 #define PFM_REG_RETFL_EINVAL (1U<<30) /* set if register entry is invalid */ 60 #define PFM_REG_RETFL_MASK (PFM_REG_RETFL_NOTAVAIL|PFM_REG_RETFL_EINVAL) 61 62 #define PFM_REG_HAS_ERROR(flag) (((flag) & PFM_REG_RETFL_MASK) != 0) 63 64 /* 65 * Request structure used to define a context 66 */ 67 typedef struct { 68 unsigned long ctx_smpl_entries; /* how many entries in sampling buffer */ 69 unsigned long ctx_smpl_regs[4]; /* which pmds to record on overflow */ 70 71 pid_t ctx_notify_pid; /* which process to notify on overflow */ 72 int ctx_flags; /* noblock/block, inherit flags */ 73 void *ctx_smpl_vaddr; /* returns address of BTB buffer */ 74 75 unsigned long ctx_cpu_mask; /* on which CPU to enable perfmon (systemwide) */ 76 77 unsigned long reserved[8]; /* for future use */ 78 } pfarg_context_t; 79 80 /* 81 * Request structure used to write/read a PMC or PMD 82 */ 83 typedef struct { 84 unsigned int reg_num; /* which register */ 85 unsigned int reg_flags; /* PMC: notify/don't notify. PMD/PMC: return flags */ 86 unsigned long reg_value; /* configuration (PMC) or initial value (PMD) */ 87 88 unsigned long reg_long_reset; /* reset after sampling buffer overflow (large) */ 89 unsigned long reg_short_reset;/* reset after counter overflow (small) */ 90 91 unsigned long reg_reset_pmds[4]; /* which other counters to reset on overflow */ 92 unsigned long reg_random_seed; /* seed value when randomization is used */ 93 unsigned long reg_random_mask; /* bitmask used to limit random value */ 94 unsigned long reg_last_reset_value;/* last value used to reset the PMD (PFM_READ_PMDS) */ 95 96 unsigned long reserved[13]; /* for future use */ 97 } pfarg_reg_t; 98 99 typedef struct { 100 unsigned int dbreg_num; /* which register */ 101 unsigned int dbreg_flags; /* dbregs return flags */ 102 unsigned long dbreg_value; /* configuration (PMC) or initial value (PMD) */ 103 unsigned long reserved[6]; 104 } pfarg_dbreg_t; 105 106 typedef struct { 107 unsigned int ft_version; /* perfmon: major [16-31], minor [0-15] */ 108 unsigned int ft_smpl_version;/* sampling format: major [16-31], minor [0-15] */ 109 unsigned long reserved[4]; /* for future use */ 110 } pfarg_features_t; 111 112 /* 113 * Entry header in the sampling buffer. 114 * The header is directly followed with the PMDS saved in increasing index 115 * order: PMD4, PMD5, .... How many PMDs are present is determined by the 116 * user program during context creation. 117 * 118 * XXX: in this version of the entry, only up to 64 registers can be recorded 119 * This should be enough for quite some time. Always check sampling format 120 * before parsing entries! 121 * 122 * In the case where multiple counters overflow at the same time, the 123 * last_reset_value member indicates the initial value of the PMD with 124 * the smallest index. For instance, if PMD2 and PMD5 have overflowed, 125 * the last_reset_value member contains the initial value of PMD2. 126 */ 127 typedef struct { 128 int pid; /* identification of process */ 129 int cpu; /* which cpu was used */ 130 unsigned long last_reset_value;/* initial value of overflowed counter */ 131 unsigned long stamp; /* timestamp (unique per CPU) */ 132 unsigned long ip; /* where did the overflow interrupt happened */ 133 unsigned long regs; /* bitmask of which registers overflowed */ 134 unsigned long period; /* unused */ 135 } perfmon_smpl_entry_t; 136 137 /* 138 * This header is at the beginning of the sampling buffer returned to the user. 139 * It is exported as Read-Only at this point. It is directly followed by the 140 * first record. 141 */ 142 typedef struct { 143 unsigned int hdr_version; /* contains perfmon version (smpl format diffs) */ 144 unsigned int reserved; 145 unsigned long hdr_entry_size; /* size of one entry in bytes */ 146 unsigned long hdr_count; /* how many valid entries */ 147 unsigned long hdr_pmds[4]; /* which pmds are recorded */ 148 } perfmon_smpl_hdr_t; 149 150 /* 151 * Define the version numbers for both perfmon as a whole and the sampling buffer format. 152 */ 153 #define PFM_VERSION_MAJ 1U 154 #define PFM_VERSION_MIN 5U 155 #define PFM_VERSION (((PFM_VERSION_MAJ&0xffff)<<16)|(PFM_VERSION_MIN & 0xffff)) 156 157 #define PFM_SMPL_VERSION_MAJ 1U 158 #define PFM_SMPL_VERSION_MIN 0U 159 #define PFM_SMPL_VERSION (((PFM_SMPL_VERSION_MAJ&0xffff)<<16)|(PFM_SMPL_VERSION_MIN & 0xffff)) 160 161 162 #define PFM_VERSION_MAJOR(x) (((x)>>16) & 0xffff) 163 #define PFM_VERSION_MINOR(x) ((x) & 0xffff) 164 165 166 #ifdef __KERNEL__ 167 168 extern long perfmonctl(pid_t pid, int cmd, void *arg, int narg); 169 170 typedef struct { 171 void (*handler)(int irq, void *arg, struct pt_regs *regs); 172 } pfm_intr_handler_desc_t; 173 174 extern void pfm_save_regs (struct task_struct *); 175 extern void pfm_load_regs (struct task_struct *); 176 177 extern int pfm_inherit (struct task_struct *, struct pt_regs *); 178 extern void pfm_context_exit (struct task_struct *); 179 extern void pfm_flush_regs (struct task_struct *); 180 extern void pfm_cleanup_notifiers (struct task_struct *); 181 extern void pfm_cleanup_owners (struct task_struct *); 182 extern int pfm_use_debug_registers(struct task_struct *); 183 extern int pfm_release_debug_registers(struct task_struct *); 184 extern int pfm_cleanup_smpl_buf(struct task_struct *); 185 extern void pfm_syst_wide_update_task(struct task_struct *, unsigned long info, int is_ctxswin); 186 extern void pfm_init_percpu(void); 187 188 /* 189 * hooks to allow VTune/Prospect to cooperate with perfmon. 190 * (reserved for system wide monitoring modules only) 191 */ 192 extern int pfm_install_alternate_syswide_subsystem(pfm_intr_handler_desc_t *h); 193 extern int pfm_remove_alternate_syswide_subsystem(pfm_intr_handler_desc_t *h); 194 195 /* 196 * describe the content of the local_cpu_date->pfm_syst_info field 197 */ 198 #define PFM_CPUINFO_SYST_WIDE 0x1 /* if set a system wide session exist on the CPU */ 199 #define PFM_CPUINFO_DCR_PP 0x2 /* if set a system wide session started on the CPU */ 200 #define PFM_CPUINFO_EXCL_IDLE 0x4 /* system wide session excludes the idle task */ 201 202 /* 203 * macros to set the specific perfmon bits in each CPU's private data area 204 */ 205 #define PFM_CPUINFO_CLEAR(v) local_cpu_data->pfm_syst_info &= ~(v) 206 #define PFM_CPUINFO_SET(v) local_cpu_data->pfm_syst_info |= (v) 207 208 #endif /* __KERNEL__ */ 209 210 #endif /* _ASM_IA64_PERFMON_H */ 211