49#define sel_event_select perfevtsel.sel_event_select
50#define sel_unit_mask perfevtsel.sel_unit_mask
51#define sel_usr perfevtsel.sel_usr
52#define sel_os perfevtsel.sel_os
53#define sel_edge perfevtsel.sel_edge
54#define sel_pc perfevtsel.sel_pc
55#define sel_int perfevtsel.sel_int
56#define sel_any perfevtsel.sel_any
57#define sel_en perfevtsel.sel_en
58#define sel_inv perfevtsel.sel_inv
59#define sel_cnt_mask perfevtsel.sel_cnt_mask
98#define GEN_IA32_SEL_BASE 0x186
99#define GEN_IA32_CTR_BASE 0xc1
100#define GEN_IA32_FIXED_CTR_BASE 0x309
102#define FIXED_PMD_BASE 16
104#define PFMLIB_GEN_IA32_ALL_FLAGS \
105 (PFM_GEN_IA32_SEL_INV|PFM_GEN_IA32_SEL_EDGE|PFM_GEN_IA32_SEL_ANYTHR)
115static inline void cpuid(
unsigned int op,
unsigned int *eax,
unsigned int *ebx,
116 unsigned int *ecx,
unsigned int *edx)
124 __asm__(
"pushl %%ebx;cpuid; popl %%ebx"
129 __asm__(
"pushl %%ebx;cpuid; movl %%ebx, %%eax;popl %%ebx"
135static inline void cpuid(
unsigned int op,
unsigned int *eax,
unsigned int *ebx,
136 unsigned int *ecx,
unsigned int *edx)
163 for(
i=0; i < 7; i++, m>>=1) {
179 if ((m & 0x1) == 0) {
201 } eax, ecx, edx, ebx;
216 cpuid(0x0, &eax.val, &ebx.val, &ecx.val, &edx.val);
223 cpuid(0xa, &eax.val, &ebx.val, &ecx.val, &edx.val);
241 if (strcmp(buffer,
"GenuineIntel"))
260 } eax, ecx, edx, ebx;
261 unsigned int num_cnt,
i;
268 cpuid(0xa, &eax.val, &ebx.val, &ecx.val, &edx.val);
276 eax.eax.cnt_width = 40;
277 eax.eax.ebx_length = 0;
280 edx.edx.cnt_width = 40;
283 num_cnt = eax.eax.num_cnt;
289 for(
i=0;
i < num_cnt;
i++) {
303 if (edx.edx.num_cnt == 0)
306 for(
i=0;
i < edx.edx.num_cnt;
i++)
320 __pfm_vbprintf(
"Intel architected PMU: version=%d num_gen=%u num_fixed=%u pmc=%u pmd=%d\n",
345 unsigned int i, j, cnt, k, ucode, val;
356 for (j=0; j < cnt; j++) {
364 for(
i=0, j=0; j < cnt; j++) {
366 DPRINT(
"event=%d invalid plm=%d\n", e[j].event, e[j].plm);
371 DPRINT(
"event=%d invalid flags=0x%lx\n", e[j].event, e[j].flags);
376 DPRINT(
"event=%d anythread requires architectural perfmon v3", e[j].event);
393 for (j=0; j < cnt ; j++ ) {
403 ucode = (val >> 8) & 0xff;
406 ucode |=
gen_ia32_pe[e[j].event].pme_umasks[e[j].unit_masks[k]].pme_ucode;
427 if (cntrs[
i].cnt_mask > 255)
445 __pfm_vbprintf(
"[PERFEVTSEL%u(pmc%u)=0x%llx event_sel=0x%x umask=0x%x os=%d usr=%d en=%d int=%d inv=%d edge=%d cnt_mask=%d] %s\n",
469static const char *
fixed_event_names[]={
"INSTRUCTIONS_RETIRED",
"UNHALTED_CORE_CYCLES ",
"UNHALTED_REFERENCE_CYCLES " };
470#define MAX_EVENT_NAMES (sizeof(fixed_event_names)/sizeof(char *))
475#define HAS_OPTIONS(x) (cntrs && (cntrs[i].flags || cntrs[i].cnt_mask))
476#define is_fixed_pmc(a) (a > 15)
485 unsigned int fixed_ctr_mask;
486 unsigned int npc = 0;
487 unsigned int i, j, n, k, ucode;
489 unsigned int next_gen, last_gen;
510 for(j=0; j < n; j++) {
524 DPRINT(
"event=%d anythread requires architectural perfmon v3", e[j].event);
536 if (fixed_ctr_mask) {
537 for(
i=0;
i < n;
i++) {
549 fixed_ctr_mask &= ~(1<<j);
558 for(
i=0;
i < n;
i++) {
559 if (assign[
i] == -1) {
560 for(; next_gen <= last_gen; next_gen++) {
564 if (next_gen <= last_gen)
565 assign[
i] = next_gen++;
575 for (
i=0;
i < n ;
i++ ) {
612 (reg.
val >> (
i*4)) & 0x3ULL);
616 (reg.
val >> (
i*4)) & 0x3ULL,
618 !!((reg.
val >> (
i*4)) & 0x4ULL));
623 if ((fixed_ctr_mask & (0x1 <<
i)) == 0) {
634 for (
i=0;
i < n ;
i++ ) {
641 for (
i=0;
i < n ;
i++ ) {
655 ucode = (val >> 8) & 0xff;
658 ucode |=
gen_ia32_pe[e[
i].event].pme_umasks[e[
i].unit_masks[k]].pme_ucode;
679 if (cntrs[
i].cnt_mask > 255)
698 __pfm_vbprintf(
"[PERFEVTSEL%u(pmc%u)=0x%"PRIx64
" event_sel=0x%x umask=0x%x os=%d usr=%d en=%d int=%d inv=%d edge=%d cnt_mask=%d] %s\n",
713 __pfm_vbprintf(
"[PERFEVTSEL%u(pmc%u)=0x%"PRIx64
" event_sel=0x%x umask=0x%x os=%d usr=%d en=%d int=%d inv=%d edge=%d cnt_mask=%d anythr=%d] %s\n",
774 memset(counters, 0,
sizeof(*counters));
890 .
pmu_name =
"Intel architectural PMU",
static pme_gen_ia32_entry_t gen_ia32_all_pe[]
#define PME_GEN_IA32_INSTRUCTIONS_RETIRED
#define PME_GEN_IA32_UNHALTED_CORE_CYCLES
static int pfm_regmask_set(pfmlib_regmask_t *h, unsigned int b)
#define PFMLIB_ERR_TOOMANY
static int pfm_regmask_isset(pfmlib_regmask_t *h, unsigned int b)
#define PFMLIB_ERR_NOASSIGN
#define PFMLIB_ERR_NOTSUPP
#define PFMLIB_GEN_IA32_PMU
static int gen_ia32_inst_retired_event
#define GEN_IA32_FIXED_CTR_BASE
static pfmlib_regmask_t gen_ia32_impl_pmcs
static char * pfm_gen_ia32_get_event_mask_name(unsigned int ev, unsigned int midx)
static int pfm_gen_ia32_get_event_description(unsigned int ev, char **str)
static int create_arch_event_table(unsigned int mask)
static pme_gen_ia32_entry_t * gen_ia32_pe
static void pfm_gen_ia32_get_impl_counters(pfmlib_regmask_t *impl_counters)
static const char * fixed_event_names[]
static char * pfm_gen_ia32_get_event_name(unsigned int i)
#define PFMLIB_GEN_IA32_ALL_FLAGS
static int check_arch_pmu(int family)
static int pfm_gen_ia32_dispatch_events(pfmlib_input_param_t *inp, void *model_in, pfmlib_output_param_t *outp, void *model_out)
static unsigned int pfm_gen_ia32_get_num_event_masks(unsigned int ev)
#define GEN_IA32_CTR_BASE
static unsigned int num_gen_cnt
pfm_pmu_support_t * gen_support
static void pfm_gen_ia32_get_impl_pmcs(pfmlib_regmask_t *impl_pmcs)
static int pfm_gen_ia32_get_cycle_event(pfmlib_event_t *e)
static int gen_ia32_cycle_event
static void pfm_gen_ia32_get_hw_counter_width(unsigned int *width)
static int pfm_gen_ia32_get_event_code(unsigned int i, unsigned int cnt, int *code)
static int pfm_gen_ia32_init(void)
static int pfm_gen_ia32_get_event_mask_code(unsigned int ev, unsigned int midx, unsigned int *code)
static void pfm_gen_ia32_get_impl_pmds(pfmlib_regmask_t *impl_pmds)
static unsigned int num_fixed_cnt
static void pfm_gen_ia32_get_event_counters(unsigned int j, pfmlib_regmask_t *counters)
static int pfm_gen_ia32_get_inst_retired(pfmlib_event_t *e)
static int pfm_gen_ia32_dispatch_counters_v23(pfmlib_input_param_t *inp, pfmlib_gen_ia32_input_param_t *param, pfmlib_output_param_t *outp)
static int pfm_gen_ia32_dispatch_counters_v1(pfmlib_input_param_t *inp, pfmlib_gen_ia32_input_param_t *mod_in, pfmlib_output_param_t *outp)
static void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
static unsigned int pmu_version
#define GEN_IA32_SEL_BASE
pfm_pmu_support_t gen_ia32_support
static int pfm_gen_ia32_detect(void)
static pfmlib_regmask_t gen_ia32_impl_pmds
static int pfm_gen_ia32_get_event_mask_desc(unsigned int ev, unsigned int midx, char **str)
#define PFM_GEN_IA32_SEL_INV
#define PMU_GEN_IA32_MAX_COUNTERS
#define PFM_GEN_IA32_SEL_EDGE
#define PMU_GEN_IA32_COUNTER_WIDTH
#define PFM_GEN_IA32_SEL_ANYTHR
static const pme_power_entry_t * pe
int __pfm_getcpuinfo_attr(const char *attr, char *ret_buf, size_t maxlen)
void __pfm_vbprintf(const char *fmt,...)
#define DPRINT(fmt, a...)
pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
unsigned int pfp_pmc_count
unsigned int pfp_pmd_count
unsigned long long reg_value
unsigned long long reg_addr
pme_gen_ia32_umask_t pme_umasks[PFMLIB_GEN_IA32_MAX_UMASK]
unsigned long sel_event_select
unsigned long sel_cnt_mask
unsigned long sel_unit_mask