Deleted Added
full compact
libpmc.c (202157) libpmc.c (204635)
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 202157 2010-01-12 17:03:55Z jkoshy $");
28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 204635 2010-03-03 15:05:58Z gnn $");
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>

--- 32 unchanged lines hidden (view full) ---

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
76
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>

--- 32 unchanged lines hidden (view full) ---

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
76
77#if defined(__mips__)
78static int mips24k_allocate_pmc(enum pmc_event _pe, char* ctrspec,
79 struct pmc_op_pmcallocate *_pmc_config);
80#endif /* __mips__ */
81
82
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
84 * lookup table.

--- 47 unchanged lines hidden (view full) ---

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);
83#define PMC_CALL(cmd, params) \
84 syscall(pmc_syscall, PMC_OP_##cmd, (params))
85
86/*
87 * Event aliases provide a way for the user to ask for generic events
88 * like "cache-misses", or "instructions-retired". These aliases are
89 * mapped to the appropriate canonical event descriptions using a
90 * lookup table.

--- 47 unchanged lines hidden (view full) ---

138
139PMC_CLASSDEP_TABLE(iaf, IAF);
140PMC_CLASSDEP_TABLE(k7, K7);
141PMC_CLASSDEP_TABLE(k8, K8);
142PMC_CLASSDEP_TABLE(p4, P4);
143PMC_CLASSDEP_TABLE(p5, P5);
144PMC_CLASSDEP_TABLE(p6, P6);
145PMC_CLASSDEP_TABLE(xscale, XSCALE);
146PMC_CLASSDEP_TABLE(mips24k, MIPS24K);
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};

--- 29 unchanged lines hidden (view full) ---

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);
147
148#undef __PMC_EV_ALIAS
149#define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE },
150
151static const struct pmc_event_descr atom_event_table[] =
152{
153 __PMC_EV_ALIAS_ATOM()
154};

--- 29 unchanged lines hidden (view full) ---

184PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC);
185PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC);
186PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC);
187PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC);
188PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC);
189PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC);
190PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC);
191PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE);
192PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_MIPS24K);
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) \

--- 28 unchanged lines hidden (view full) ---

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
228
193
194static const struct pmc_event_descr tsc_event_table[] =
195{
196 __PMC_EV_TSC()
197};
198
199#undef PMC_CLASS_TABLE_DESC
200#define PMC_CLASS_TABLE_DESC(NAME, CLASS, EVENTS, ALLOCATOR) \

--- 28 unchanged lines hidden (view full) ---

229#endif
230#if defined(__i386__) || defined(__amd64__)
231PMC_CLASS_TABLE_DESC(tsc, TSC, tsc, tsc);
232#endif
233#if defined(__XSCALE__)
234PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale);
235#endif
236
237#if defined(__mips__)
238PMC_CLASS_TABLE_DESC(mips24k, MIPS24K, mips24k, mips24k);
239#endif /* __mips__ */
240
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;
236

--- 1798 unchanged lines hidden (view full) ---

2035 default:
2036 break;
2037 }
2038
2039 return (0);
2040}
2041#endif
2042
241#undef PMC_CLASS_TABLE_DESC
242
243static const struct pmc_class_descr **pmc_class_table;
244#define PMC_CLASS_TABLE_SIZE cpu_info.pm_nclass
245
246static const enum pmc_class *pmc_mdep_class_list;
247static size_t pmc_mdep_class_list_size;
248

--- 1798 unchanged lines hidden (view full) ---

2047 default:
2048 break;
2049 }
2050
2051 return (0);
2052}
2053#endif
2054
2055#if defined(__mips__)
2056
2057static struct pmc_event_alias mips24k_aliases[] = {
2058 EV_ALIAS("instructions", "INSTR_EXECUTED"),
2059 EV_ALIAS("branches", "BRANCH_COMPLETED"),
2060 EV_ALIAS("branch-mispredicts", "BRANCH_MISPRED"),
2061 EV_ALIAS(NULL, NULL)
2062};
2063
2064#define MIPS24K_KW_OS "os"
2065#define MIPS24K_KW_USR "usr"
2066#define MIPS24K_KW_ANYTHREAD "anythread"
2067
2068static int
2069mips24k_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
2070 struct pmc_op_pmcallocate *pmc_config __unused)
2071{
2072 char *p;
2073
2074 (void) pe;
2075
2076 pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
2077
2078 while ((p = strsep(&ctrspec, ",")) != NULL) {
2079 if (KWMATCH(p, MIPS24K_KW_OS))
2080 pmc_config->pm_caps |= PMC_CAP_SYSTEM;
2081 else if (KWMATCH(p, MIPS24K_KW_USR))
2082 pmc_config->pm_caps |= PMC_CAP_USER;
2083 else if (KWMATCH(p, MIPS24K_KW_ANYTHREAD))
2084 pmc_config->pm_caps |= (PMC_CAP_USER | PMC_CAP_SYSTEM);
2085 else
2086 return (-1);
2087 }
2088
2089 return (0);
2090}
2091#endif /* __mips__ */
2092
2093
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 */

--- 315 unchanged lines hidden (view full) ---

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;
2094/*
2095 * Match an event name `name' with its canonical form.
2096 *
2097 * Matches are case insensitive and spaces, periods, underscores and
2098 * hyphen characters are considered to match each other.
2099 *
2100 * Returns 1 for a match, 0 otherwise.
2101 */

--- 315 unchanged lines hidden (view full) ---

2417 case PMC_CLASS_P6:
2418 ev = p6_event_table;
2419 count = PMC_EVENT_TABLE_SIZE(p6);
2420 break;
2421 case PMC_CLASS_XSCALE:
2422 ev = xscale_event_table;
2423 count = PMC_EVENT_TABLE_SIZE(xscale);
2424 break;
2425 case PMC_CLASS_MIPS24K:
2426 ev = mips24k_event_table;
2427 count = PMC_EVENT_TABLE_SIZE(mips24k);
2428 break;
2374 default:
2375 errno = EINVAL;
2376 return (-1);
2377 }
2378
2379 if ((names = malloc(count * sizeof(const char *))) == NULL)
2380 return (-1);
2381

--- 176 unchanged lines hidden (view full) ---

2558 break;
2559#endif
2560#if defined(__XSCALE__)
2561 case PMC_CPU_INTEL_XSCALE:
2562 PMC_MDEP_INIT(xscale);
2563 pmc_class_table[n] = &xscale_class_table_descr;
2564 break;
2565#endif
2429 default:
2430 errno = EINVAL;
2431 return (-1);
2432 }
2433
2434 if ((names = malloc(count * sizeof(const char *))) == NULL)
2435 return (-1);
2436

--- 176 unchanged lines hidden (view full) ---

2613 break;
2614#endif
2615#if defined(__XSCALE__)
2616 case PMC_CPU_INTEL_XSCALE:
2617 PMC_MDEP_INIT(xscale);
2618 pmc_class_table[n] = &xscale_class_table_descr;
2619 break;
2620#endif
2566
2567
2621#if defined(__mips__)
2622 case PMC_CPU_MIPS_24K:
2623 PMC_MDEP_INIT(mips24k);
2624 pmc_class_table[n] = &mips24k_class_table_descr;
2625 break;
2626#endif /* __mips__ */
2568 default:
2569 /*
2570 * Some kind of CPU this version of the library knows nothing
2571 * about. This shouldn't happen since the abi version check
2572 * should have caught this.
2573 */
2574 errno = ENXIO;
2575 return (pmc_syscall = -1);

--- 100 unchanged lines hidden (view full) ---

2676 ev = p5_event_table;
2677 evfence = p5_event_table + PMC_EVENT_TABLE_SIZE(p5);
2678 } else if (pe >= PMC_EV_P6_FIRST && pe <= PMC_EV_P6_LAST) {
2679 ev = p6_event_table;
2680 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6);
2681 } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) {
2682 ev = xscale_event_table;
2683 evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale);
2627 default:
2628 /*
2629 * Some kind of CPU this version of the library knows nothing
2630 * about. This shouldn't happen since the abi version check
2631 * should have caught this.
2632 */
2633 errno = ENXIO;
2634 return (pmc_syscall = -1);

--- 100 unchanged lines hidden (view full) ---

2735 ev = p5_event_table;
2736 evfence = p5_event_table + PMC_EVENT_TABLE_SIZE(p5);
2737 } else if (pe >= PMC_EV_P6_FIRST && pe <= PMC_EV_P6_LAST) {
2738 ev = p6_event_table;
2739 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6);
2740 } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) {
2741 ev = xscale_event_table;
2742 evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale);
2743 } else if (pe >= PMC_EV_MIPS24K_FIRST && pe <= PMC_EV_MIPS24K_LAST) {
2744 ev = mips24k_event_table;
2745 evfence = mips24k_event_table + PMC_EVENT_TABLE_SIZE(mips24k
2746);
2684 } else if (pe == PMC_EV_TSC_TSC) {
2685 ev = tsc_event_table;
2686 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
2687 }
2688
2689 for (; ev != evfence; ev++)
2690 if (pe == ev->pm_ev_code)
2691 return (ev->pm_ev_name);

--- 199 unchanged lines hidden ---
2747 } else if (pe == PMC_EV_TSC_TSC) {
2748 ev = tsc_event_table;
2749 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
2750 }
2751
2752 for (; ev != evfence; ev++)
2753 if (pe == ev->pm_ev_code)
2754 return (ev->pm_ev_name);

--- 199 unchanged lines hidden ---