libpmc.c (183105) | libpmc.c (183107) |
---|---|
1/*- 2 * Copyright (c) 2003-2008 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003-2008 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 183105 2008-09-17 03:53:37Z jkoshy $"); | 28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 183107 2008-09-17 04:13:14Z jkoshy $"); |
29 30#include <sys/types.h> 31#include <sys/module.h> 32#include <sys/pmc.h> 33#include <sys/syscall.h> 34 35#include <ctype.h> 36#include <errno.h> --- 120 unchanged lines hidden (view full) --- 157pmc_parse_mask(const struct pmc_masks *pmask, char *p, uint32_t *evmask) 158{ 159 const struct pmc_masks *pm; 160 char *q, *r; 161 int c; 162 163 if (pmask == NULL) /* no mask keywords */ 164 return (-1); | 29 30#include <sys/types.h> 31#include <sys/module.h> 32#include <sys/pmc.h> 33#include <sys/syscall.h> 34 35#include <ctype.h> 36#include <errno.h> --- 120 unchanged lines hidden (view full) --- 157pmc_parse_mask(const struct pmc_masks *pmask, char *p, uint32_t *evmask) 158{ 159 const struct pmc_masks *pm; 160 char *q, *r; 161 int c; 162 163 if (pmask == NULL) /* no mask keywords */ 164 return (-1); |
165 q = strchr(p, '='); /* skip '=' */ | 165 q = strchr(p, '='); /* skip '=' */ |
166 if (*++q == '\0') /* no more data */ 167 return (-1); 168 c = 0; /* count of mask keywords seen */ 169 while ((r = strsep(&q, "+")) != NULL) { 170 for (pm = pmask; pm->pm_name && strcmp(r, pm->pm_name); pm++) 171 ; 172 if (pm->pm_name == NULL) /* not found */ 173 return (-1); --- 31 unchanged lines hidden (view full) --- 205#define K7_KW_OS "os" 206#define K7_KW_UNITMASK "unitmask" 207#define K7_KW_USR "usr" 208 209static int 210k7_allocate_pmc(enum pmc_event pe, char *ctrspec, 211 struct pmc_op_pmcallocate *pmc_config) 212{ | 166 if (*++q == '\0') /* no more data */ 167 return (-1); 168 c = 0; /* count of mask keywords seen */ 169 while ((r = strsep(&q, "+")) != NULL) { 170 for (pm = pmask; pm->pm_name && strcmp(r, pm->pm_name); pm++) 171 ; 172 if (pm->pm_name == NULL) /* not found */ 173 return (-1); --- 31 unchanged lines hidden (view full) --- 205#define K7_KW_OS "os" 206#define K7_KW_UNITMASK "unitmask" 207#define K7_KW_USR "usr" 208 209static int 210k7_allocate_pmc(enum pmc_event pe, char *ctrspec, 211 struct pmc_op_pmcallocate *pmc_config) 212{ |
213 char *e, *p, *q; 214 int c, has_unitmask; | 213 char *e, *p, *q; 214 int c, has_unitmask; |
215 uint32_t count, unitmask; 216 217 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 218 pmc_config->pm_caps |= PMC_CAP_READ; 219 220 if (pe == PMC_EV_TSC_TSC) { 221 /* TSC events must be unqualified. */ 222 if (ctrspec && *ctrspec != '\0') --- 87 unchanged lines hidden (view full) --- 310 311static struct pmc_event_alias k8_aliases[] = { 312 EV_ALIAS("branches", "k8-fr-retired-taken-branches"), 313 EV_ALIAS("branch-mispredicts", 314 "k8-fr-retired-taken-branches-mispredicted"), 315 EV_ALIAS("cycles", "tsc"), 316 EV_ALIAS("dc-misses", "k8-dc-miss"), 317 EV_ALIAS("ic-misses", "k8-ic-miss"), | 215 uint32_t count, unitmask; 216 217 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 218 pmc_config->pm_caps |= PMC_CAP_READ; 219 220 if (pe == PMC_EV_TSC_TSC) { 221 /* TSC events must be unqualified. */ 222 if (ctrspec && *ctrspec != '\0') --- 87 unchanged lines hidden (view full) --- 310 311static struct pmc_event_alias k8_aliases[] = { 312 EV_ALIAS("branches", "k8-fr-retired-taken-branches"), 313 EV_ALIAS("branch-mispredicts", 314 "k8-fr-retired-taken-branches-mispredicted"), 315 EV_ALIAS("cycles", "tsc"), 316 EV_ALIAS("dc-misses", "k8-dc-miss"), 317 EV_ALIAS("ic-misses", "k8-ic-miss"), |
318 EV_ALIAS("instructions", "k8-fr-retired-x86-instructions"), | 318 EV_ALIAS("instructions", "k8-fr-retired-x86-instructions"), |
319 EV_ALIAS("interrupts", "k8-fr-taken-hardware-interrupts"), 320 EV_ALIAS("unhalted-cycles", "k8-bu-cpu-clk-unhalted"), 321 EV_ALIAS(NULL, NULL) 322}; 323 324#define __K8MASK(N,V) PMCMASK(N,(1 << (V))) 325 326/* --- 158 unchanged lines hidden (view full) --- 485 __K8MASK(probe-hit-dirty-no-memory-cancel, 2), 486 __K8MASK(probe-hit-dirty-with-memory-cancel, 3), 487 NULLMASK 488}; 489 490/* nb hypertransport bus bandwidth */ 491static const struct pmc_masks k8_mask_nhbb[] = { /* HT bus bandwidth */ 492 __K8MASK(command, 0), | 319 EV_ALIAS("interrupts", "k8-fr-taken-hardware-interrupts"), 320 EV_ALIAS("unhalted-cycles", "k8-bu-cpu-clk-unhalted"), 321 EV_ALIAS(NULL, NULL) 322}; 323 324#define __K8MASK(N,V) PMCMASK(N,(1 << (V))) 325 326/* --- 158 unchanged lines hidden (view full) --- 485 __K8MASK(probe-hit-dirty-no-memory-cancel, 2), 486 __K8MASK(probe-hit-dirty-with-memory-cancel, 3), 487 NULLMASK 488}; 489 490/* nb hypertransport bus bandwidth */ 491static const struct pmc_masks k8_mask_nhbb[] = { /* HT bus bandwidth */ 492 __K8MASK(command, 0), |
493 __K8MASK(data, 1), | 493 __K8MASK(data, 1), |
494 __K8MASK(buffer-release, 2), 495 __K8MASK(nop, 3), 496 NULLMASK 497}; 498 499#undef __K8MASK 500 501#define K8_KW_COUNT "count" 502#define K8_KW_EDGE "edge" 503#define K8_KW_INV "inv" 504#define K8_KW_MASK "mask" 505#define K8_KW_OS "os" 506#define K8_KW_USR "usr" 507 508static int 509k8_allocate_pmc(enum pmc_event pe, char *ctrspec, 510 struct pmc_op_pmcallocate *pmc_config) 511{ | 494 __K8MASK(buffer-release, 2), 495 __K8MASK(nop, 3), 496 NULLMASK 497}; 498 499#undef __K8MASK 500 501#define K8_KW_COUNT "count" 502#define K8_KW_EDGE "edge" 503#define K8_KW_INV "inv" 504#define K8_KW_MASK "mask" 505#define K8_KW_OS "os" 506#define K8_KW_USR "usr" 507 508static int 509k8_allocate_pmc(enum pmc_event pe, char *ctrspec, 510 struct pmc_op_pmcallocate *pmc_config) 511{ |
512 char *e, *p, *q; 513 int n; | 512 char *e, *p, *q; 513 int n; |
514 uint32_t count, evmask; 515 const struct pmc_masks *pm, *pmask; 516 517 pmc_config->pm_caps |= PMC_CAP_READ; 518 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 519 520 if (pe == PMC_EV_TSC_TSC) { 521 /* TSC events must be unqualified. */ --- 496 unchanged lines hidden (view full) --- 1018 1019 pmask = NULL; 1020 evmask = 0; 1021 cccractivemask = 0x3; 1022 has_tag = has_busreqtype = 0; 1023 pmc_config->pm_caps |= PMC_CAP_WRITE; 1024 1025#define __P4SETMASK(M) do { \ | 514 uint32_t count, evmask; 515 const struct pmc_masks *pm, *pmask; 516 517 pmc_config->pm_caps |= PMC_CAP_READ; 518 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 519 520 if (pe == PMC_EV_TSC_TSC) { 521 /* TSC events must be unqualified. */ --- 496 unchanged lines hidden (view full) --- 1018 1019 pmask = NULL; 1020 evmask = 0; 1021 cccractivemask = 0x3; 1022 has_tag = has_busreqtype = 0; 1023 pmc_config->pm_caps |= PMC_CAP_WRITE; 1024 1025#define __P4SETMASK(M) do { \ |
1026 pmask = p4_mask_##M; \ | 1026 pmask = p4_mask_##M; \ |
1027} while (0) 1028 1029 switch (pe) { 1030 case PMC_EV_P4_TC_DELIVER_MODE: 1031 __P4SETMASK(tcdm); 1032 break; 1033 case PMC_EV_P4_BPU_FETCH_REQUEST: 1034 __P4SETMASK(bfr); --- 224 unchanged lines hidden (view full) --- 1259 if (evmask == 0) /* default:drdy-{drv,own}+dbsy{drv,own} */ 1260 evmask = 0x1D; 1261 break; 1262 case PMC_EV_P4_MACHINE_CLEAR: 1263 /* only one bit is allowed to be set */ 1264 if ((evmask & (evmask - 1)) != 0) 1265 return (-1); 1266 if (evmask == 0) { | 1027} while (0) 1028 1029 switch (pe) { 1030 case PMC_EV_P4_TC_DELIVER_MODE: 1031 __P4SETMASK(tcdm); 1032 break; 1033 case PMC_EV_P4_BPU_FETCH_REQUEST: 1034 __P4SETMASK(bfr); --- 224 unchanged lines hidden (view full) --- 1259 if (evmask == 0) /* default:drdy-{drv,own}+dbsy{drv,own} */ 1260 evmask = 0x1D; 1261 break; 1262 case PMC_EV_P4_MACHINE_CLEAR: 1263 /* only one bit is allowed to be set */ 1264 if ((evmask & (evmask - 1)) != 0) 1265 return (-1); 1266 if (evmask == 0) { |
1267 evmask = 0x1; /* 'CLEAR' */ | 1267 evmask = 0x1; /* 'CLEAR' */ |
1268 pmc_config->pm_caps |= PMC_CAP_QUALIFIER; 1269 } 1270 break; 1271 default: 1272 if (evmask == 0 && pmask) { 1273 for (pm = pmask; pm->pm_name; pm++) 1274 evmask |= pm->pm_value; 1275 pmc_config->pm_caps |= PMC_CAP_QUALIFIER; --- 176 unchanged lines hidden (view full) --- 1452 } 1453 1454 pmc_config->pm_caps |= PMC_CAP_WRITE; 1455 evmask = 0; 1456 1457#define P6MASKSET(M) pmask = p6_mask_ ## M 1458 1459 switch(pe) { | 1268 pmc_config->pm_caps |= PMC_CAP_QUALIFIER; 1269 } 1270 break; 1271 default: 1272 if (evmask == 0 && pmask) { 1273 for (pm = pmask; pm->pm_name; pm++) 1274 evmask |= pm->pm_value; 1275 pmc_config->pm_caps |= PMC_CAP_QUALIFIER; --- 176 unchanged lines hidden (view full) --- 1452 } 1453 1454 pmc_config->pm_caps |= PMC_CAP_WRITE; 1455 evmask = 0; 1456 1457#define P6MASKSET(M) pmask = p6_mask_ ## M 1458 1459 switch(pe) { |
1460 case PMC_EV_P6_L2_IFETCH: P6MASKSET(mesi); break; | 1460 case PMC_EV_P6_L2_IFETCH: P6MASKSET(mesi); break; |
1461 case PMC_EV_P6_L2_LD: P6MASKSET(mesi); break; 1462 case PMC_EV_P6_L2_ST: P6MASKSET(mesi); break; 1463 case PMC_EV_P6_L2_RQSTS: P6MASKSET(mesi); break; 1464 case PMC_EV_P6_BUS_DRDY_CLOCKS: 1465 case PMC_EV_P6_BUS_LOCK_CLOCKS: 1466 case PMC_EV_P6_BUS_TRAN_BRD: 1467 case PMC_EV_P6_BUS_TRAN_RFO: 1468 case PMC_EV_P6_BUS_TRANS_WB: --- 759 unchanged lines hidden --- | 1461 case PMC_EV_P6_L2_LD: P6MASKSET(mesi); break; 1462 case PMC_EV_P6_L2_ST: P6MASKSET(mesi); break; 1463 case PMC_EV_P6_L2_RQSTS: P6MASKSET(mesi); break; 1464 case PMC_EV_P6_BUS_DRDY_CLOCKS: 1465 case PMC_EV_P6_BUS_LOCK_CLOCKS: 1466 case PMC_EV_P6_BUS_TRAN_BRD: 1467 case PMC_EV_P6_BUS_TRAN_RFO: 1468 case PMC_EV_P6_BUS_TRANS_WB: --- 759 unchanged lines hidden --- |