svn commit: r192592 - in user/kmacy/releng_7_2_fcs: lib/libpmc
sys/amd64/include sys/i386/include
Kip Macy
kmacy at FreeBSD.org
Fri May 22 18:19:21 UTC 2009
Author: kmacy
Date: Fri May 22 18:19:20 2009
New Revision: 192592
URL: http://svn.freebsd.org/changeset/base/192592
Log:
fix pmc tools build
Modified:
user/kmacy/releng_7_2_fcs/lib/libpmc/libpmc.c
user/kmacy/releng_7_2_fcs/sys/amd64/include/pmc_mdep.h
user/kmacy/releng_7_2_fcs/sys/i386/include/pmc_mdep.h
Modified: user/kmacy/releng_7_2_fcs/lib/libpmc/libpmc.c
==============================================================================
--- user/kmacy/releng_7_2_fcs/lib/libpmc/libpmc.c Fri May 22 18:10:39 2009 (r192591)
+++ user/kmacy/releng_7_2_fcs/lib/libpmc/libpmc.c Fri May 22 18:19:20 2009 (r192592)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2003-2006 Joseph Koshy
+ * Copyright (c) 2003-2008 Joseph Koshy
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -65,6 +65,10 @@ static int p5_allocate_pmc(enum pmc_even
static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
struct pmc_op_pmcallocate *_pmc_config);
#endif
+#if defined(__amd64__) || defined(__i386__)
+static int tsc_allocate_pmc(enum pmc_event _pe, char *_ctrspec,
+ struct pmc_op_pmcallocate *_pmc_config);
+#endif
#define PMC_CALL(cmd, params) \
syscall(pmc_syscall, PMC_OP_##cmd, (params))
@@ -75,7 +79,6 @@ static int p6_allocate_pmc(enum pmc_even
* mapped to the appropriate canonical event descriptions using a
* lookup table.
*/
-
struct pmc_event_alias {
const char *pm_alias;
const char *pm_spec;
@@ -84,14 +87,12 @@ struct pmc_event_alias {
static const struct pmc_event_alias *pmc_mdep_event_aliases;
/*
- * The pmc_event_descr table maps symbolic names known to the user
+ * The pmc_event_descr structure maps symbolic names known to the user
* to integer codes used by the PMC KLD.
*/
-
struct pmc_event_descr {
const char *pm_ev_name;
enum pmc_event pm_ev_code;
- enum pmc_class pm_ev_class;
};
/*
@@ -151,6 +152,11 @@ static const struct pmc_event_descr core
__PMC_EV_ALIAS_CORE2()
};
+static const struct pmc_event_descr corei7_event_table[] =
+{
+ __PMC_EV_ALIAS_COREI7()
+};
+
/*
* PMC_MDEP_TABLE(NAME, PRIMARYCLASS, ADDITIONAL_CLASSES...)
*
@@ -164,6 +170,7 @@ static const struct pmc_event_descr core
PMC_MDEP_TABLE(atom, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(core, IAP, PMC_CLASS_TSC);
PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC);
+PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC);
PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC);
PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC);
@@ -172,9 +179,7 @@ PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC);
static const struct pmc_event_descr tsc_event_table[] =
{
-#undef __PMC_EV
-#define __PMC_EV(C,N,EV) { #EV, PMC_EV_ ## C ## _ ## N, PMC_CLASS_ ## C },
- __PMC_EVENTS()
+ __PMC_EV_TSC()
};
#undef PMC_CLASS_TABLE_DESC
@@ -195,6 +200,7 @@ PMC_CLASS_TABLE_DESC(iaf, IAF, iaf, iaf)
PMC_CLASS_TABLE_DESC(atom, IAP, atom, iap);
PMC_CLASS_TABLE_DESC(core, IAP, core, iap);
PMC_CLASS_TABLE_DESC(core2, IAP, core2, iap);
+PMC_CLASS_TABLE_DESC(corei7, IAP, corei7, iap);
#endif
#if defined(__i386__)
PMC_CLASS_TABLE_DESC(k7, K7, k7, k7);
@@ -236,9 +242,14 @@ static const char * pmc_class_names[] =
__PMC_CLASSES()
};
-static const char * pmc_cputype_names[] = {
+struct pmc_cputype_map {
+ enum pmc_class pm_cputype;
+ const char *pm_name;
+};
+
+static const struct pmc_cputype_map pmc_cputype_names[] = {
#undef __PMC_CPU
-#define __PMC_CPU(S, D) #S ,
+#define __PMC_CPU(S, V, D) { .pm_cputype = PMC_CPU_##S, .pm_name = #S } ,
__PMC_CPUS()
};
@@ -264,11 +275,6 @@ static int pmc_syscall = -1; /* filled
static struct pmc_cpuinfo cpu_info; /* filled in by pmc_init() */
-
-/* Architecture dependent event parsing */
-static int (*pmc_mdep_allocate_pmc)(enum pmc_event _pe, char *_ctrspec,
- struct pmc_op_pmcallocate *_pmc_config);
-
/* Event masks for events */
struct pmc_masks {
const char *pm_name;
@@ -286,20 +292,21 @@ pmc_parse_mask(const struct pmc_masks *p
int c;
if (pmask == NULL) /* no mask keywords */
- return -1;
- q = strchr(p, '='); /* skip '=' */
+ return (-1);
+ q = strchr(p, '='); /* skip '=' */
if (*++q == '\0') /* no more data */
- return -1;
+ return (-1);
c = 0; /* count of mask keywords seen */
while ((r = strsep(&q, "+")) != NULL) {
- for (pm = pmask; pm->pm_name && strcmp(r, pm->pm_name); pm++)
+ for (pm = pmask; pm->pm_name && strcasecmp(r, pm->pm_name);
+ pm++)
;
if (pm->pm_name == NULL) /* not found */
- return -1;
+ return (-1);
*evmask |= pm->pm_value;
c++;
}
- return c;
+ return (c);
}
#endif
@@ -317,7 +324,7 @@ static struct pmc_event_alias k7_aliases
EV_ALIAS("branches", "k7-retired-branches"),
EV_ALIAS("branch-mispredicts", "k7-retired-branches-mispredicted"),
EV_ALIAS("cycles", "tsc"),
- EV_ALIAS("dc-misses", "k7-dc-misses,mask=moesi"),
+ EV_ALIAS("dc-misses", "k7-dc-misses"),
EV_ALIAS("ic-misses", "k7-ic-misses"),
EV_ALIAS("instructions", "k7-retired-instructions"),
EV_ALIAS("interrupts", "k7-hardware-interrupts"),
@@ -335,19 +342,12 @@ static int
k7_allocate_pmc(enum pmc_event pe, char *ctrspec,
struct pmc_op_pmcallocate *pmc_config)
{
- char *e, *p, *q;
- int c, has_unitmask;
+ char *e, *p, *q;
+ int c, has_unitmask;
uint32_t count, unitmask;
pmc_config->pm_md.pm_amd.pm_amd_config = 0;
- pmc_config->pm_caps |= PMC_CAP_READ;
-
- if (pe == PMC_EV_TSC_TSC) {
- /* TSC events must be unqualified. */
- if (ctrspec && *ctrspec != '\0')
- return -1;
- return 0;
- }
+ pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
if (pe == PMC_EV_K7_DC_REFILLS_FROM_L2 ||
pe == PMC_EV_K7_DC_REFILLS_FROM_SYSTEM ||
@@ -357,17 +357,15 @@ k7_allocate_pmc(enum pmc_event pe, char
} else
unitmask = has_unitmask = 0;
- pmc_config->pm_caps |= PMC_CAP_WRITE;
-
while ((p = strsep(&ctrspec, ",")) != NULL) {
if (KWPREFIXMATCH(p, K7_KW_COUNT "=")) {
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_THRESHOLD;
pmc_config->pm_md.pm_amd.pm_amd_config |=
@@ -381,11 +379,11 @@ k7_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_caps |= PMC_CAP_SYSTEM;
} else if (KWPREFIXMATCH(p, K7_KW_UNITMASK "=")) {
if (has_unitmask == 0)
- return -1;
+ return (-1);
unitmask = 0;
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
while ((c = tolower(*q++)) != 0)
if (c == 'm')
@@ -401,15 +399,15 @@ k7_allocate_pmc(enum pmc_event pe, char
else if (c == '+')
continue;
else
- return -1;
+ return (-1);
if (unitmask == 0)
- return -1;
+ return (-1);
} else if (KWMATCH(p, K7_KW_USR)) {
pmc_config->pm_caps |= PMC_CAP_USER;
} else
- return -1;
+ return (-1);
}
if (has_unitmask) {
@@ -418,7 +416,7 @@ k7_allocate_pmc(enum pmc_event pe, char
AMD_PMC_TO_UNITMASK(unitmask);
}
- return 0;
+ return (0);
}
@@ -457,6 +455,7 @@ static struct pmc_event_alias core2_alia
EV_ALIAS(NULL, NULL)
};
#define atom_aliases core2_aliases
+#define corei7_aliases core2_aliases
#define IAF_KW_OS "os"
#define IAF_KW_USR "usr"
@@ -613,7 +612,8 @@ iap_allocate_pmc(enum pmc_event pe, char
return (-1);
} else if (cpu_info.pm_cputype == PMC_CPU_INTEL_ATOM ||
cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2 ||
- cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2EXTREME) {
+ cpu_info.pm_cputype == PMC_CPU_INTEL_CORE2EXTREME ||
+ cpu_info.pm_cputype == PMC_CPU_INTEL_COREI7) {
if (KWMATCH(p, IAP_KW_SNOOPRESPONSE)) {
n = pmc_parse_mask(iap_snoopresponse_mask, p,
&evmask);
@@ -672,7 +672,7 @@ static struct pmc_event_alias k8_aliases
EV_ALIAS("cycles", "tsc"),
EV_ALIAS("dc-misses", "k8-dc-miss"),
EV_ALIAS("ic-misses", "k8-ic-miss"),
- EV_ALIAS("instructions", "k8-fr-retired-x86-instructions"),
+ EV_ALIAS("instructions", "k8-fr-retired-x86-instructions"),
EV_ALIAS("interrupts", "k8-fr-taken-hardware-interrupts"),
EV_ALIAS("unhalted-cycles", "k8-bu-cpu-clk-unhalted"),
EV_ALIAS(NULL, NULL)
@@ -847,7 +847,7 @@ static const struct pmc_masks k8_mask_np
/* nb hypertransport bus bandwidth */
static const struct pmc_masks k8_mask_nhbb[] = { /* HT bus bandwidth */
__K8MASK(command, 0),
- __K8MASK(data, 1),
+ __K8MASK(data, 1),
__K8MASK(buffer-release, 2),
__K8MASK(nop, 3),
NULLMASK
@@ -866,21 +866,14 @@ static int
k8_allocate_pmc(enum pmc_event pe, char *ctrspec,
struct pmc_op_pmcallocate *pmc_config)
{
- char *e, *p, *q;
- int n;
+ char *e, *p, *q;
+ int n;
uint32_t count, evmask;
const struct pmc_masks *pm, *pmask;
- pmc_config->pm_caps |= PMC_CAP_READ;
+ pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
pmc_config->pm_md.pm_amd.pm_amd_config = 0;
- if (pe == PMC_EV_TSC_TSC) {
- /* TSC events must be unqualified. */
- if (ctrspec && *ctrspec != '\0')
- return -1;
- return 0;
- }
-
pmask = NULL;
evmask = 0;
@@ -954,17 +947,15 @@ k8_allocate_pmc(enum pmc_event pe, char
break; /* no options defined */
}
- pmc_config->pm_caps |= PMC_CAP_WRITE;
-
while ((p = strsep(&ctrspec, ",")) != NULL) {
if (KWPREFIXMATCH(p, K8_KW_COUNT "=")) {
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_THRESHOLD;
pmc_config->pm_md.pm_amd.pm_amd_config |=
@@ -976,18 +967,17 @@ k8_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_caps |= PMC_CAP_INVERT;
} else if (KWPREFIXMATCH(p, K8_KW_MASK "=")) {
if ((n = pmc_parse_mask(pmask, p, &evmask)) < 0)
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_QUALIFIER;
} else if (KWMATCH(p, K8_KW_OS)) {
pmc_config->pm_caps |= PMC_CAP_SYSTEM;
} else if (KWMATCH(p, K8_KW_USR)) {
pmc_config->pm_caps |= PMC_CAP_USER;
} else
- return -1;
+ return (-1);
}
/* other post processing */
-
switch (pe) {
case PMC_EV_K8_FP_DISPATCHED_FPU_OPS:
case PMC_EV_K8_FP_CYCLES_WITH_NO_FPU_OPS_RETIRED:
@@ -1003,7 +993,7 @@ k8_allocate_pmc(enum pmc_event pe, char
case PMC_EV_K8_LS_LOCKED_OPERATION:
/* XXX CPU Rev A,B evmask is to be zero */
if (evmask & (evmask - 1)) /* > 1 bit set */
- return -1;
+ return (-1);
if (evmask == 0) {
evmask = 0x01; /* Rev C and later: #instrs */
pmc_config->pm_caps |= PMC_CAP_QUALIFIER;
@@ -1021,7 +1011,7 @@ k8_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_md.pm_amd.pm_amd_config =
AMD_PMC_TO_UNITMASK(evmask);
- return 0;
+ return (0);
}
#endif
@@ -1363,25 +1353,17 @@ p4_allocate_pmc(enum pmc_event pe, char
uint32_t evmask, cccractivemask;
const struct pmc_masks *pm, *pmask;
- pmc_config->pm_caps |= PMC_CAP_READ;
+ pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
pmc_config->pm_md.pm_p4.pm_p4_cccrconfig =
pmc_config->pm_md.pm_p4.pm_p4_escrconfig = 0;
- if (pe == PMC_EV_TSC_TSC) {
- /* TSC must not be further qualified */
- if (ctrspec && *ctrspec != '\0')
- return -1;
- return 0;
- }
-
pmask = NULL;
evmask = 0;
cccractivemask = 0x3;
has_tag = has_busreqtype = 0;
- pmc_config->pm_caps |= PMC_CAP_WRITE;
#define __P4SETMASK(M) do { \
- pmask = p4_mask_##M; \
+ pmask = p4_mask_##M; \
} while (0)
switch (pe) {
@@ -1514,7 +1496,7 @@ p4_allocate_pmc(enum pmc_event pe, char
__P4SETMASK(machclr);
break;
default:
- return -1;
+ return (-1);
}
/* process additional flags */
@@ -1522,30 +1504,30 @@ p4_allocate_pmc(enum pmc_event pe, char
if (KWPREFIXMATCH(p, P4_KW_ACTIVE)) {
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
- if (strcmp(q, P4_KW_ACTIVE_NONE) == 0)
+ if (strcasecmp(q, P4_KW_ACTIVE_NONE) == 0)
cccractivemask = 0x0;
- else if (strcmp(q, P4_KW_ACTIVE_SINGLE) == 0)
+ else if (strcasecmp(q, P4_KW_ACTIVE_SINGLE) == 0)
cccractivemask = 0x1;
- else if (strcmp(q, P4_KW_ACTIVE_BOTH) == 0)
+ else if (strcasecmp(q, P4_KW_ACTIVE_BOTH) == 0)
cccractivemask = 0x2;
- else if (strcmp(q, P4_KW_ACTIVE_ANY) == 0)
+ else if (strcasecmp(q, P4_KW_ACTIVE_ANY) == 0)
cccractivemask = 0x3;
else
- return -1;
+ return (-1);
} else if (KWPREFIXMATCH(p, P4_KW_BUSREQTYPE)) {
if (has_busreqtype == 0)
- return -1;
+ return (-1);
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
evmask = (evmask & ~0x1F) | (count & 0x1F);
} else if (KWMATCH(p, P4_KW_CASCADE))
pmc_config->pm_caps |= PMC_CAP_CASCADE;
@@ -1555,7 +1537,7 @@ p4_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_caps |= PMC_CAP_INVERT;
else if (KWPREFIXMATCH(p, P4_KW_MASK "=")) {
if ((n = pmc_parse_mask(pmask, p, &evmask)) < 0)
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_QUALIFIER;
} else if (KWMATCH(p, P4_KW_OS))
pmc_config->pm_caps |= PMC_CAP_SYSTEM;
@@ -1563,15 +1545,15 @@ p4_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_caps |= PMC_CAP_PRECISE;
else if (KWPREFIXMATCH(p, P4_KW_TAG "=")) {
if (has_tag == 0)
- return -1;
+ return (-1);
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_TAGGING;
pmc_config->pm_md.pm_p4.pm_p4_escrconfig |=
@@ -1579,11 +1561,11 @@ p4_allocate_pmc(enum pmc_event pe, char
} else if (KWPREFIXMATCH(p, P4_KW_THRESHOLD "=")) {
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_THRESHOLD;
pmc_config->pm_md.pm_p4.pm_p4_cccrconfig &=
@@ -1593,7 +1575,7 @@ p4_allocate_pmc(enum pmc_event pe, char
} else if (KWMATCH(p, P4_KW_USR))
pmc_config->pm_caps |= PMC_CAP_USER;
else
- return -1;
+ return (-1);
}
/* other post processing */
@@ -1613,16 +1595,16 @@ p4_allocate_pmc(enum pmc_event pe, char
case PMC_EV_P4_FSB_DATA_ACTIVITY:
if ((evmask & 0x06) == 0x06 ||
(evmask & 0x18) == 0x18)
- return -1; /* can't have own+other bits together */
+ return (-1); /* can't have own+other bits together */
if (evmask == 0) /* default:drdy-{drv,own}+dbsy{drv,own} */
evmask = 0x1D;
break;
case PMC_EV_P4_MACHINE_CLEAR:
/* only one bit is allowed to be set */
if ((evmask & (evmask - 1)) != 0)
- return -1;
+ return (-1);
if (evmask == 0) {
- evmask = 0x1; /* 'CLEAR' */
+ evmask = 0x1; /* 'CLEAR' */
pmc_config->pm_caps |= PMC_CAP_QUALIFIER;
}
break;
@@ -1637,7 +1619,7 @@ p4_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_md.pm_p4.pm_p4_escrconfig =
P4_ESCR_TO_EVENT_MASK(evmask);
- return 0;
+ return (0);
}
#endif
@@ -1649,7 +1631,14 @@ p4_allocate_pmc(enum pmc_event pe, char
*/
static struct pmc_event_alias p5_aliases[] = {
- EV_ALIAS("cycles", "tsc"),
+ EV_ALIAS("branches", "p5-taken-branches"),
+ EV_ALIAS("cycles", "tsc"),
+ EV_ALIAS("dc-misses", "p5-data-read-miss-or-write-miss"),
+ EV_ALIAS("ic-misses", "p5-code-cache-miss"),
+ EV_ALIAS("instructions", "p5-instructions-executed"),
+ EV_ALIAS("interrupts", "p5-hardware-interrupts"),
+ EV_ALIAS("unhalted-cycles",
+ "p5-number-of-cycles-not-in-halt-state"),
EV_ALIAS(NULL, NULL)
};
@@ -1657,7 +1646,7 @@ static int
p5_allocate_pmc(enum pmc_event pe, char *ctrspec,
struct pmc_op_pmcallocate *pmc_config)
{
- return -1 || pe || ctrspec || pmc_config; /* shut up gcc */
+ return (-1 || pe || ctrspec || pmc_config); /* shut up gcc */
}
/*
@@ -1793,22 +1782,15 @@ p6_allocate_pmc(enum pmc_event pe, char
int count, n;
const struct pmc_masks *pm, *pmask;
- pmc_config->pm_caps |= PMC_CAP_READ;
+ pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
pmc_config->pm_md.pm_ppro.pm_ppro_config = 0;
- if (pe == PMC_EV_TSC_TSC) {
- if (ctrspec && *ctrspec != '\0')
- return -1;
- return 0;
- }
-
- pmc_config->pm_caps |= PMC_CAP_WRITE;
evmask = 0;
#define P6MASKSET(M) pmask = p6_mask_ ## M
switch(pe) {
- case PMC_EV_P6_L2_IFETCH: P6MASKSET(mesi); break;
+ case PMC_EV_P6_L2_IFETCH: P6MASKSET(mesi); break;
case PMC_EV_P6_L2_LD: P6MASKSET(mesi); break;
case PMC_EV_P6_L2_ST: P6MASKSET(mesi); break;
case PMC_EV_P6_L2_RQSTS: P6MASKSET(mesi); break;
@@ -1868,10 +1850,10 @@ p6_allocate_pmc(enum pmc_event pe, char
if (KWPREFIXMATCH(p, P6_KW_CMASK "=")) {
q = strchr(p, '=');
if (*++q == '\0') /* skip '=' */
- return -1;
+ return (-1);
count = strtol(q, &e, 0);
if (e == q || *e != '\0')
- return -1;
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_THRESHOLD;
pmc_config->pm_md.pm_ppro.pm_ppro_config |=
P6_EVSEL_TO_CMASK(count);
@@ -1884,7 +1866,7 @@ p6_allocate_pmc(enum pmc_event pe, char
} else if (KWPREFIXMATCH(p, P6_KW_UMASK "=")) {
evmask = 0;
if ((n = pmc_parse_mask(pmask, p, &evmask)) < 0)
- return -1;
+ return (-1);
if ((pe == PMC_EV_P6_BUS_DRDY_CLOCKS ||
pe == PMC_EV_P6_BUS_LOCK_CLOCKS ||
pe == PMC_EV_P6_BUS_TRAN_BRD ||
@@ -1908,13 +1890,13 @@ p6_allocate_pmc(enum pmc_event pe, char
pe == PMC_EV_P6_EMON_SSE_SSE2_COMP_INST_RETIRED ||
pe == PMC_EV_P6_EMON_SSE_SSE2_INST_RETIRED ||
pe == PMC_EV_P6_FP_MMX_TRANS)
- && (n > 1))
- return -1; /* only one mask keyword allowed */
+ && (n > 1)) /* Only one mask keyword is allowed. */
+ return (-1);
pmc_config->pm_caps |= PMC_CAP_QUALIFIER;
} else if (KWMATCH(p, P6_KW_USR)) {
pmc_config->pm_caps |= PMC_CAP_USER;
} else
- return -1;
+ return (-1);
}
/* post processing */
@@ -1967,12 +1949,10 @@ p6_allocate_pmc(enum pmc_event pe, char
break;
default:
-
/*
* For all other events, set the default event mask
* to a logical OR of all the allowed event mask bits.
*/
-
if (evmask == 0 && pmask) {
for (pm = pmask; pm->pm_name; pm++)
evmask |= pm->pm_value;
@@ -1986,11 +1966,30 @@ p6_allocate_pmc(enum pmc_event pe, char
pmc_config->pm_md.pm_ppro.pm_ppro_config |=
P6_EVSEL_TO_UMASK(evmask);
- return 0;
+ return (0);
}
#endif
+#if defined(__i386__) || defined(__amd64__)
+static int
+tsc_allocate_pmc(enum pmc_event pe, char *ctrspec,
+ struct pmc_op_pmcallocate *pmc_config)
+{
+ if (pe != PMC_EV_TSC_TSC)
+ return (-1);
+
+ /* TSC events must be unqualified. */
+ if (ctrspec && *ctrspec != '\0')
+ return (-1);
+
+ pmc_config->pm_md.pm_amd.pm_amd_config = 0;
+ pmc_config->pm_caps |= PMC_CAP_READ;
+
+ return (0);
+}
+#endif
+
/*
* Match an event name `name' with its canonical form.
*
@@ -2064,17 +2063,18 @@ pmc_mdep_is_compatible_class(enum pmc_cl
* API entry points
*/
-
int
pmc_allocate(const char *ctrspec, enum pmc_mode mode,
uint32_t flags, int cpu, pmc_id_t *pmcid)
{
+ size_t n;
int retval;
- enum pmc_event pe;
char *r, *spec_copy;
const char *ctrname;
- const struct pmc_event_alias *p;
+ const struct pmc_event_descr *ev;
+ const struct pmc_event_alias *alias;
struct pmc_op_pmcallocate pmc_config;
+ const struct pmc_class_descr *pcd;
spec_copy = NULL;
retval = -1;
@@ -2087,9 +2087,9 @@ pmc_allocate(const char *ctrspec, enum p
/* replace an event alias with the canonical event specifier */
if (pmc_mdep_event_aliases)
- for (p = pmc_mdep_event_aliases; p->pm_alias; p++)
- if (!strcmp(ctrspec, p->pm_alias)) {
- spec_copy = strdup(p->pm_spec);
+ for (alias = pmc_mdep_event_aliases; alias->pm_alias; alias++)
+ if (!strcasecmp(ctrspec, alias->pm_alias)) {
+ spec_copy = strdup(alias->pm_spec);
break;
}
@@ -2115,6 +2115,8 @@ pmc_allocate(const char *ctrspec, enum p
goto out;
}
break;
+ }
+ }
/*
* Otherwise, search for this event in all compatible PMC
@@ -2132,8 +2134,8 @@ pmc_allocate(const char *ctrspec, enum p
}
bzero(&pmc_config, sizeof(pmc_config));
- pmc_config.pm_ev = pmc_event_table[pe].pm_ev_code;
- pmc_config.pm_class = pmc_event_table[pe].pm_ev_class;
+ pmc_config.pm_ev = ev->pm_ev_code;
+ pmc_config.pm_class = pcd->pm_evc_class;
pmc_config.pm_cpu = cpu;
pmc_config.pm_mode = mode;
pmc_config.pm_flags = flags;
@@ -2141,7 +2143,7 @@ pmc_allocate(const char *ctrspec, enum p
if (PMC_IS_SAMPLING_MODE(mode))
pmc_config.pm_caps |= PMC_CAP_INTERRUPT;
- if (pmc_mdep_allocate_pmc(pe, r, &pmc_config) < 0) {
+ if (pcd->pm_evc_allocate_pmc(ev->pm_ev_code, r, &pmc_config) < 0) {
errno = EINVAL;
goto out;
}
@@ -2157,7 +2159,7 @@ pmc_allocate(const char *ctrspec, enum p
if (spec_copy)
free(spec_copy);
- return retval;
+ return (retval);
}
int
@@ -2168,7 +2170,7 @@ pmc_attach(pmc_id_t pmc, pid_t pid)
pmc_attach_args.pm_pmc = pmc;
pmc_attach_args.pm_pid = pid;
- return PMC_CALL(PMCATTACH, &pmc_attach_args);
+ return (PMC_CALL(PMCATTACH, &pmc_attach_args));
}
int
@@ -2181,9 +2183,10 @@ pmc_capabilities(pmc_id_t pmcid, uint32_
for (i = 0; i < cpu_info.pm_nclass; i++)
if (cpu_info.pm_classes[i].pm_class == cl) {
*caps = cpu_info.pm_classes[i].pm_caps;
- return 0;
+ return (0);
}
- return EINVAL;
+ errno = EINVAL;
+ return (-1);
}
int
@@ -2193,8 +2196,8 @@ pmc_configure_logfile(int fd)
cla.pm_logfd = fd;
if (PMC_CALL(CONFIGURELOG, &cla) < 0)
- return -1;
- return 0;
+ return (-1);
+ return (0);
}
int
@@ -2202,11 +2205,11 @@ pmc_cpuinfo(const struct pmc_cpuinfo **p
{
if (pmc_syscall == -1) {
errno = ENXIO;
- return -1;
+ return (-1);
}
*pci = &cpu_info;
- return 0;
+ return (0);
}
int
@@ -2216,8 +2219,7 @@ pmc_detach(pmc_id_t pmc, pid_t pid)
pmc_detach_args.pm_pmc = pmc;
pmc_detach_args.pm_pid = pid;
-
- return PMC_CALL(PMCDETACH, &pmc_detach_args);
+ return (PMC_CALL(PMCDETACH, &pmc_detach_args));
}
int
@@ -2228,7 +2230,7 @@ pmc_disable(int cpu, int pmc)
ssa.pm_cpu = cpu;
ssa.pm_pmc = pmc;
ssa.pm_state = PMC_STATE_DISABLED;
- return PMC_CALL(PMCADMIN, &ssa);
+ return (PMC_CALL(PMCADMIN, &ssa));
}
int
@@ -2239,7 +2241,7 @@ pmc_enable(int cpu, int pmc)
ssa.pm_cpu = cpu;
ssa.pm_pmc = pmc;
ssa.pm_state = PMC_STATE_FREE;
- return PMC_CALL(PMCADMIN, &ssa);
+ return (PMC_CALL(PMCADMIN, &ssa));
}
/*
@@ -2251,7 +2253,6 @@ pmc_enable(int cpu, int pmc)
* The space for 'eventnames' is allocated using malloc(3). The caller
* is responsible for freeing this space when done.
*/
-
int
pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
int *nevents)
@@ -2286,52 +2287,56 @@ pmc_event_names_of_class(enum pmc_class
ev = core2_event_table;
count = PMC_EVENT_TABLE_SIZE(core2);
break;
+ case PMC_CPU_INTEL_COREI7:
+ ev = corei7_event_table;
+ count = PMC_EVENT_TABLE_SIZE(corei7);
+ break;
}
break;
case PMC_CLASS_TSC:
- ev = &pmc_event_table[PMC_EV_TSC_TSC];
- count = 1;
+ ev = tsc_event_table;
+ count = PMC_EVENT_TABLE_SIZE(tsc);
break;
case PMC_CLASS_K7:
- ev = &pmc_event_table[PMC_EV_K7_FIRST];
- count = PMC_EV_K7_LAST - PMC_EV_K7_FIRST + 1;
+ ev = k7_event_table;
+ count = PMC_EVENT_TABLE_SIZE(k7);
break;
case PMC_CLASS_K8:
- ev = &pmc_event_table[PMC_EV_K8_FIRST];
- count = PMC_EV_K8_LAST - PMC_EV_K8_FIRST + 1;
+ ev = k8_event_table;
+ count = PMC_EVENT_TABLE_SIZE(k8);
+ break;
+ case PMC_CLASS_P4:
+ ev = p4_event_table;
+ count = PMC_EVENT_TABLE_SIZE(p4);
break;
case PMC_CLASS_P5:
- ev = &pmc_event_table[PMC_EV_P5_FIRST];
- count = PMC_EV_P5_LAST - PMC_EV_P5_FIRST + 1;
+ ev = p5_event_table;
+ count = PMC_EVENT_TABLE_SIZE(p5);
break;
case PMC_CLASS_P6:
- ev = &pmc_event_table[PMC_EV_P6_FIRST];
- count = PMC_EV_P6_LAST - PMC_EV_P6_FIRST + 1;
- break;
- case PMC_CLASS_P4:
- ev = &pmc_event_table[PMC_EV_P4_FIRST];
- count = PMC_EV_P4_LAST - PMC_EV_P4_FIRST + 1;
+ ev = p6_event_table;
+ count = PMC_EVENT_TABLE_SIZE(p6);
break;
default:
errno = EINVAL;
- return -1;
+ return (-1);
}
if ((names = malloc(count * sizeof(const char *))) == NULL)
- return -1;
+ return (-1);
*eventnames = names;
*nevents = count;
for (;count--; ev++, names++)
*names = ev->pm_ev_name;
- return 0;
+ return (0);
}
int
pmc_flush_logfile(void)
{
- return PMC_CALL(FLUSHLOG,0);
+ return (PMC_CALL(FLUSHLOG,0));
}
int
@@ -2340,7 +2345,7 @@ pmc_get_driver_stats(struct pmc_driverst
struct pmc_op_getdriverstats gms;
if (PMC_CALL(GETDRIVERSTATS, &gms) < 0)
- return -1;
+ return (-1);
/* copy out fields in the current userland<->library interface */
ds->pm_intr_ignored = gms.pm_intr_ignored;
@@ -2351,8 +2356,7 @@ pmc_get_driver_stats(struct pmc_driverst
ds->pm_buffer_requests = gms.pm_buffer_requests;
ds->pm_buffer_requests_failed = gms.pm_buffer_requests_failed;
ds->pm_log_sweeps = gms.pm_log_sweeps;
-
- return 0;
+ return (0);
}
int
@@ -2362,9 +2366,9 @@ pmc_get_msr(pmc_id_t pmc, uint32_t *msr)
gm.pm_pmcid = pmc;
if (PMC_CALL(PMCGETMSR, &gm) < 0)
- return -1;
+ return (-1);
*msr = gm.pm_msr;
- return 0;
+ return (0);
}
int
@@ -2377,15 +2381,15 @@ pmc_init(void)
struct pmc_op_getcpuinfo op_cpu_info;
if (pmc_syscall != -1) /* already inited */
- return 0;
+ return (0);
/* retrieve the system call number from the KLD */
if ((pmc_mod_id = modfind(PMC_MODULE_NAME)) < 0)
- return -1;
+ return (-1);
pmc_modstat.version = sizeof(struct module_stat);
if ((error = modstat(pmc_mod_id, &pmc_modstat)) < 0)
- return -1;
+ return (-1);
pmc_syscall = pmc_modstat.data.intval;
@@ -2436,24 +2440,18 @@ pmc_init(void)
switch (cpu_info.pm_cputype) {
#if defined(__i386__)
case PMC_CPU_AMD_K7:
- pmc_mdep_event_aliases = k7_aliases;
- pmc_mdep_allocate_pmc = k7_allocate_pmc;
- pmc_class_table[n] = &k7_class_table_descr;
+ PMC_MDEP_INIT(k7);
pmc_class_table[n] = &k7_class_table_descr;
break;
case PMC_CPU_INTEL_P5:
- pmc_mdep_event_aliases = p5_aliases;
- pmc_mdep_allocate_pmc = p5_allocate_pmc;
- pmc_class_table[n] = &p5_class_table_descr;
+ PMC_MDEP_INIT(p5);
pmc_class_table[n] = &p5_class_table_descr;
break;
case PMC_CPU_INTEL_P6: /* P6 ... Pentium M CPUs have */
case PMC_CPU_INTEL_PII: /* similar PMCs. */
case PMC_CPU_INTEL_PIII:
case PMC_CPU_INTEL_PM:
- pmc_mdep_event_aliases = p6_aliases;
- pmc_mdep_allocate_pmc = p6_allocate_pmc;
- pmc_class_table[n] = &p6_class_table_descr;
+ PMC_MDEP_INIT(p6);
pmc_class_table[n] = &p6_class_table_descr;
break;
#endif
@@ -2477,16 +2475,15 @@ pmc_init(void)
pmc_class_table[n++] = &iaf_class_table_descr;
pmc_class_table[n] = &core2_class_table_descr;
break;
+ case PMC_CPU_INTEL_COREI7:
+ PMC_MDEP_INIT(corei7);
+ pmc_class_table[n++] = &iaf_class_table_descr;
+ pmc_class_table[n] = &corei7_class_table_descr;
+ break;
case PMC_CPU_INTEL_PIV:
- pmc_mdep_event_aliases = p4_aliases;
- pmc_mdep_allocate_pmc = p4_allocate_pmc;
- pmc_class_table[n] = &p4_class_table_descr;
+ PMC_MDEP_INIT(p4);
pmc_class_table[n] = &p4_class_table_descr;
break;
- case PMC_CPU_AMD_K8:
- pmc_mdep_event_aliases = k8_aliases;
- pmc_mdep_allocate_pmc = k8_allocate_pmc;
- break;
#endif
@@ -2500,7 +2497,7 @@ pmc_init(void)
return (pmc_syscall = -1);
}
- return 0;
+ return (0);
}
const char *
@@ -2512,16 +2509,14 @@ pmc_name_of_capability(enum pmc_caps cap
* 'cap' should have a single bit set and should be in
* range.
*/
-
if ((cap & (cap - 1)) || cap < PMC_CAP_FIRST ||
cap > PMC_CAP_LAST) {
errno = EINVAL;
- return NULL;
+ return (NULL);
}
i = ffs(cap);
-
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-user
mailing list