libpmc.c (198433) | libpmc.c (200928) |
---|---|
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 198433 2009-10-24 04:11:40Z jkoshy $"); | 28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 200928 2009-12-23 23:16:54Z rpaulo $"); |
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> --- 27 unchanged lines hidden (view full) --- 64 struct pmc_op_pmcallocate *_pmc_config); 65static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 66 struct pmc_op_pmcallocate *_pmc_config); 67#endif 68#if defined(__amd64__) || defined(__i386__) 69static int tsc_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 70 struct pmc_op_pmcallocate *_pmc_config); 71#endif | 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> --- 27 unchanged lines hidden (view full) --- 64 struct pmc_op_pmcallocate *_pmc_config); 65static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 66 struct pmc_op_pmcallocate *_pmc_config); 67#endif 68#if defined(__amd64__) || defined(__i386__) 69static int tsc_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 70 struct pmc_op_pmcallocate *_pmc_config); 71#endif |
72#if defined(__XSCALE__) 73static int xscale_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 74 struct pmc_op_pmcallocate *_pmc_config); 75#endif |
|
72 73#define PMC_CALL(cmd, params) \ 74 syscall(pmc_syscall, PMC_OP_##cmd, (params)) 75 76/* 77 * Event aliases provide a way for the user to ask for generic events 78 * like "cache-misses", or "instructions-retired". These aliases are 79 * mapped to the appropriate canonical event descriptions using a --- 47 unchanged lines hidden (view full) --- 127 } 128 129PMC_CLASSDEP_TABLE(iaf, IAF); 130PMC_CLASSDEP_TABLE(k7, K7); 131PMC_CLASSDEP_TABLE(k8, K8); 132PMC_CLASSDEP_TABLE(p4, P4); 133PMC_CLASSDEP_TABLE(p5, P5); 134PMC_CLASSDEP_TABLE(p6, P6); | 76 77#define PMC_CALL(cmd, params) \ 78 syscall(pmc_syscall, PMC_OP_##cmd, (params)) 79 80/* 81 * Event aliases provide a way for the user to ask for generic events 82 * like "cache-misses", or "instructions-retired". These aliases are 83 * mapped to the appropriate canonical event descriptions using a --- 47 unchanged lines hidden (view full) --- 131 } 132 133PMC_CLASSDEP_TABLE(iaf, IAF); 134PMC_CLASSDEP_TABLE(k7, K7); 135PMC_CLASSDEP_TABLE(k8, K8); 136PMC_CLASSDEP_TABLE(p4, P4); 137PMC_CLASSDEP_TABLE(p5, P5); 138PMC_CLASSDEP_TABLE(p6, P6); |
139PMC_CLASSDEP_TABLE(xscale, XSCALE); |
|
135 136#undef __PMC_EV_ALIAS 137#define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE }, 138 139static const struct pmc_event_descr atom_event_table[] = 140{ 141 __PMC_EV_ALIAS_ATOM() 142}; --- 28 unchanged lines hidden (view full) --- 171PMC_MDEP_TABLE(core, IAP, PMC_CLASS_TSC); 172PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC); 173PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC); 174PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC); 175PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC); 176PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC); 177PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC); 178PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC); | 140 141#undef __PMC_EV_ALIAS 142#define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE }, 143 144static const struct pmc_event_descr atom_event_table[] = 145{ 146 __PMC_EV_ALIAS_ATOM() 147}; --- 28 unchanged lines hidden (view full) --- 176PMC_MDEP_TABLE(core, IAP, PMC_CLASS_TSC); 177PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC); 178PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC); 179PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC); 180PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC); 181PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC); 182PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC); 183PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC); |
184PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE); |
|
179 180static const struct pmc_event_descr tsc_event_table[] = 181{ 182 __PMC_EV_TSC() 183}; 184 185#undef PMC_CLASS_TABLE_DESC 186#define PMC_CLASS_TABLE_DESC(NAME, CLASS, EVENTS, ALLOCATOR) \ --- 24 unchanged lines hidden (view full) --- 211#endif 212#if defined(__i386__) 213PMC_CLASS_TABLE_DESC(p5, P5, p5, p5); 214PMC_CLASS_TABLE_DESC(p6, P6, p6, p6); 215#endif 216#if defined(__i386__) || defined(__amd64__) 217PMC_CLASS_TABLE_DESC(tsc, TSC, tsc, tsc); 218#endif | 185 186static const struct pmc_event_descr tsc_event_table[] = 187{ 188 __PMC_EV_TSC() 189}; 190 191#undef PMC_CLASS_TABLE_DESC 192#define PMC_CLASS_TABLE_DESC(NAME, CLASS, EVENTS, ALLOCATOR) \ --- 24 unchanged lines hidden (view full) --- 217#endif 218#if defined(__i386__) 219PMC_CLASS_TABLE_DESC(p5, P5, p5, p5); 220PMC_CLASS_TABLE_DESC(p6, P6, p6, p6); 221#endif 222#if defined(__i386__) || defined(__amd64__) 223PMC_CLASS_TABLE_DESC(tsc, TSC, tsc, tsc); 224#endif |
225#if defined(__XSCALE__) 226PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale); 227#endif |
|
219 220#undef PMC_CLASS_TABLE_DESC 221 222static const struct pmc_class_descr **pmc_class_table; 223#define PMC_CLASS_TABLE_SIZE cpu_info.pm_nclass 224 225static const enum pmc_class *pmc_mdep_class_list; 226static size_t pmc_mdep_class_list_size; --- 1776 unchanged lines hidden (view full) --- 2003 2004 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 2005 pmc_config->pm_caps |= PMC_CAP_READ; 2006 2007 return (0); 2008} 2009#endif 2010 | 228 229#undef PMC_CLASS_TABLE_DESC 230 231static const struct pmc_class_descr **pmc_class_table; 232#define PMC_CLASS_TABLE_SIZE cpu_info.pm_nclass 233 234static const enum pmc_class *pmc_mdep_class_list; 235static size_t pmc_mdep_class_list_size; --- 1776 unchanged lines hidden (view full) --- 2012 2013 pmc_config->pm_md.pm_amd.pm_amd_config = 0; 2014 pmc_config->pm_caps |= PMC_CAP_READ; 2015 2016 return (0); 2017} 2018#endif 2019 |
2020#if defined(__XSCALE__) 2021 2022static struct pmc_event_alias xscale_aliases[] = { 2023 EV_ALIAS("branches", "BRANCH_RETIRED"), 2024 EV_ALIAS("branch-mispredicts", "BRANCH_MISPRED"), 2025 EV_ALIAS("dc-misses", "DC_MISS"), 2026 EV_ALIAS("ic-misses", "IC_MISS"), 2027 EV_ALIAS("instructions", "INSTR_RETIRED"), 2028 EV_ALIAS(NULL, NULL) 2029}; 2030static int 2031xscale_allocate_pmc(enum pmc_event pe, char *ctrspec __unused, 2032 struct pmc_op_pmcallocate *pmc_config __unused) 2033{ 2034 switch (pe) { 2035 default: 2036 break; 2037 } 2038 2039 return (0); 2040} 2041#endif 2042 |
|
2011/* 2012 * Match an event name `name' with its canonical form. 2013 * 2014 * Matches are case insensitive and spaces, periods, underscores and 2015 * hyphen characters are considered to match each other. 2016 * 2017 * Returns 1 for a match, 0 otherwise. 2018 */ --- 311 unchanged lines hidden (view full) --- 2330 case PMC_CLASS_P5: 2331 ev = p5_event_table; 2332 count = PMC_EVENT_TABLE_SIZE(p5); 2333 break; 2334 case PMC_CLASS_P6: 2335 ev = p6_event_table; 2336 count = PMC_EVENT_TABLE_SIZE(p6); 2337 break; | 2043/* 2044 * Match an event name `name' with its canonical form. 2045 * 2046 * Matches are case insensitive and spaces, periods, underscores and 2047 * hyphen characters are considered to match each other. 2048 * 2049 * Returns 1 for a match, 0 otherwise. 2050 */ --- 311 unchanged lines hidden (view full) --- 2362 case PMC_CLASS_P5: 2363 ev = p5_event_table; 2364 count = PMC_EVENT_TABLE_SIZE(p5); 2365 break; 2366 case PMC_CLASS_P6: 2367 ev = p6_event_table; 2368 count = PMC_EVENT_TABLE_SIZE(p6); 2369 break; |
2370 case PMC_CLASS_XSCALE: 2371 ev = xscale_event_table; 2372 count = PMC_EVENT_TABLE_SIZE(xscale); 2373 break; |
|
2338 default: 2339 errno = EINVAL; 2340 return (-1); 2341 } 2342 2343 if ((names = malloc(count * sizeof(const char *))) == NULL) 2344 return (-1); 2345 --- 169 unchanged lines hidden (view full) --- 2515 case PMC_CPU_INTEL_COREI7: 2516 PMC_MDEP_INIT_INTEL_V2(corei7); 2517 break; 2518 case PMC_CPU_INTEL_PIV: 2519 PMC_MDEP_INIT(p4); 2520 pmc_class_table[n] = &p4_class_table_descr; 2521 break; 2522#endif | 2374 default: 2375 errno = EINVAL; 2376 return (-1); 2377 } 2378 2379 if ((names = malloc(count * sizeof(const char *))) == NULL) 2380 return (-1); 2381 --- 169 unchanged lines hidden (view full) --- 2551 case PMC_CPU_INTEL_COREI7: 2552 PMC_MDEP_INIT_INTEL_V2(corei7); 2553 break; 2554 case PMC_CPU_INTEL_PIV: 2555 PMC_MDEP_INIT(p4); 2556 pmc_class_table[n] = &p4_class_table_descr; 2557 break; 2558#endif |
2559#if defined(__XSCALE__) 2560 case PMC_CPU_INTEL_XSCALE: 2561 PMC_MDEP_INIT(xscale); 2562 pmc_class_table[n] = &xscale_class_table_descr; 2563 break; 2564#endif |
|
2523 2524 2525 default: 2526 /* 2527 * Some kind of CPU this version of the library knows nothing 2528 * about. This shouldn't happen since the abi version check 2529 * should have caught this. 2530 */ --- 99 unchanged lines hidden (view full) --- 2630 ev = p4_event_table; 2631 evfence = p4_event_table + PMC_EVENT_TABLE_SIZE(p4); 2632 } else if (pe >= PMC_EV_P5_FIRST && pe <= PMC_EV_P5_LAST) { 2633 ev = p5_event_table; 2634 evfence = p5_event_table + PMC_EVENT_TABLE_SIZE(p5); 2635 } else if (pe >= PMC_EV_P6_FIRST && pe <= PMC_EV_P6_LAST) { 2636 ev = p6_event_table; 2637 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6); | 2565 2566 2567 default: 2568 /* 2569 * Some kind of CPU this version of the library knows nothing 2570 * about. This shouldn't happen since the abi version check 2571 * should have caught this. 2572 */ --- 99 unchanged lines hidden (view full) --- 2672 ev = p4_event_table; 2673 evfence = p4_event_table + PMC_EVENT_TABLE_SIZE(p4); 2674 } else if (pe >= PMC_EV_P5_FIRST && pe <= PMC_EV_P5_LAST) { 2675 ev = p5_event_table; 2676 evfence = p5_event_table + PMC_EVENT_TABLE_SIZE(p5); 2677 } else if (pe >= PMC_EV_P6_FIRST && pe <= PMC_EV_P6_LAST) { 2678 ev = p6_event_table; 2679 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6); |
2680 } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) { 2681 ev = xscale_event_table; 2682 evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale); |
|
2638 } else if (pe == PMC_EV_TSC_TSC) { 2639 ev = tsc_event_table; 2640 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc); 2641 } 2642 2643 for (; ev != evfence; ev++) 2644 if (pe == ev->pm_ev_code) 2645 return (ev->pm_ev_name); --- 199 unchanged lines hidden --- | 2683 } else if (pe == PMC_EV_TSC_TSC) { 2684 ev = tsc_event_table; 2685 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc); 2686 } 2687 2688 for (; ev != evfence; ev++) 2689 if (pe == ev->pm_ev_code) 2690 return (ev->pm_ev_name); --- 199 unchanged lines hidden --- |