Deleted Added
full compact
libpmc.c (228557) libpmc.c (228869)
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 228557 2011-12-16 00:13:43Z dim $");
28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 228869 2011-12-24 19:34:52Z jhibbits $");
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>

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

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

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

78 struct pmc_op_pmcallocate *_pmc_config);
79#endif
80
81#if defined(__mips__)
82static int mips24k_allocate_pmc(enum pmc_event _pe, char* ctrspec,
83 struct pmc_op_pmcallocate *_pmc_config);
84#endif /* __mips__ */
85
86#if defined(__powerpc__)
87static int ppc7450_allocate_pmc(enum pmc_event _pe, char* ctrspec,
88 struct pmc_op_pmcallocate *_pmc_config);
89#endif /* __powerpc__ */
86
87#define PMC_CALL(cmd, params) \
88 syscall(pmc_syscall, PMC_OP_##cmd, (params))
89
90/*
91 * Event aliases provide a way for the user to ask for generic events
92 * like "cache-misses", or "instructions-retired". These aliases are
93 * mapped to the appropriate canonical event descriptions using a

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

144PMC_CLASSDEP_TABLE(k7, K7);
145PMC_CLASSDEP_TABLE(k8, K8);
146PMC_CLASSDEP_TABLE(p4, P4);
147PMC_CLASSDEP_TABLE(p5, P5);
148PMC_CLASSDEP_TABLE(p6, P6);
149PMC_CLASSDEP_TABLE(xscale, XSCALE);
150PMC_CLASSDEP_TABLE(mips24k, MIPS24K);
151PMC_CLASSDEP_TABLE(ucf, UCF);
90
91#define PMC_CALL(cmd, params) \
92 syscall(pmc_syscall, PMC_OP_##cmd, (params))
93
94/*
95 * Event aliases provide a way for the user to ask for generic events
96 * like "cache-misses", or "instructions-retired". These aliases are
97 * mapped to the appropriate canonical event descriptions using a

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

148PMC_CLASSDEP_TABLE(k7, K7);
149PMC_CLASSDEP_TABLE(k8, K8);
150PMC_CLASSDEP_TABLE(p4, P4);
151PMC_CLASSDEP_TABLE(p5, P5);
152PMC_CLASSDEP_TABLE(p6, P6);
153PMC_CLASSDEP_TABLE(xscale, XSCALE);
154PMC_CLASSDEP_TABLE(mips24k, MIPS24K);
155PMC_CLASSDEP_TABLE(ucf, UCF);
156PMC_CLASSDEP_TABLE(ppc7450, PPC7450);
152
153#undef __PMC_EV_ALIAS
154#define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE },
155
156static const struct pmc_event_descr atom_event_table[] =
157{
158 __PMC_EV_ALIAS_ATOM()
159};

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

206PMC_MDEP_TABLE(westmere, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
207PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC);
208PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC);
209PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC);
210PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC);
211PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC);
212PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE);
213PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_MIPS24K);
157
158#undef __PMC_EV_ALIAS
159#define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE },
160
161static const struct pmc_event_descr atom_event_table[] =
162{
163 __PMC_EV_ALIAS_ATOM()
164};

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

211PMC_MDEP_TABLE(westmere, IAP, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
212PMC_MDEP_TABLE(k7, K7, PMC_CLASS_TSC);
213PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC);
214PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC);
215PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC);
216PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC);
217PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE);
218PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_MIPS24K);
219PMC_MDEP_TABLE(ppc7450, PPC7450, PMC_CLASS_PPC7450);
214
215static const struct pmc_event_descr tsc_event_table[] =
216{
217 __PMC_EV_TSC()
218};
219
220#undef PMC_CLASS_TABLE_DESC
221#define PMC_CLASS_TABLE_DESC(NAME, CLASS, EVENTS, ALLOCATOR) \

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

258#if defined(__XSCALE__)
259PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale);
260#endif
261
262#if defined(__mips__)
263PMC_CLASS_TABLE_DESC(mips24k, MIPS24K, mips24k, mips24k);
264#endif /* __mips__ */
265
220
221static const struct pmc_event_descr tsc_event_table[] =
222{
223 __PMC_EV_TSC()
224};
225
226#undef PMC_CLASS_TABLE_DESC
227#define PMC_CLASS_TABLE_DESC(NAME, CLASS, EVENTS, ALLOCATOR) \

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

264#if defined(__XSCALE__)
265PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale);
266#endif
267
268#if defined(__mips__)
269PMC_CLASS_TABLE_DESC(mips24k, MIPS24K, mips24k, mips24k);
270#endif /* __mips__ */
271
272#if defined(__powerpc__)
273PMC_CLASS_TABLE_DESC(ppc7450, PPC7450, ppc7450, ppc7450);
274#endif
275
266#undef PMC_CLASS_TABLE_DESC
267
268static const struct pmc_class_descr **pmc_class_table;
269#define PMC_CLASS_TABLE_SIZE cpu_info.pm_nclass
270
271static const enum pmc_class *pmc_mdep_class_list;
272static size_t pmc_mdep_class_list_size;
273

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

2207 else
2208 return (-1);
2209 }
2210
2211 return (0);
2212}
2213#endif /* __mips__ */
2214
276#undef PMC_CLASS_TABLE_DESC
277
278static const struct pmc_class_descr **pmc_class_table;
279#define PMC_CLASS_TABLE_SIZE cpu_info.pm_nclass
280
281static const enum pmc_class *pmc_mdep_class_list;
282static size_t pmc_mdep_class_list_size;
283

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

2217 else
2218 return (-1);
2219 }
2220
2221 return (0);
2222}
2223#endif /* __mips__ */
2224
2225#if defined(__powerpc__)
2215
2226
2227static struct pmc_event_alias ppc7450_aliases[] = {
2228 EV_ALIAS("instructions", "INSTR_COMPLETED"),
2229 EV_ALIAS("branches", "BRANCHES_COMPLETED"),
2230 EV_ALIAS("branch-mispredicts", "MISPREDICTED_BRANCHES"),
2231 EV_ALIAS(NULL, NULL)
2232};
2233
2234#define PPC7450_KW_OS "os"
2235#define PPC7450_KW_USR "usr"
2236#define PPC7450_KW_ANYTHREAD "anythread"
2237
2238static int
2239ppc7450_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
2240 struct pmc_op_pmcallocate *pmc_config __unused)
2241{
2242 char *p;
2243
2244 (void) pe;
2245
2246 pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
2247
2248 while ((p = strsep(&ctrspec, ",")) != NULL) {
2249 if (KWMATCH(p, PPC7450_KW_OS))
2250 pmc_config->pm_caps |= PMC_CAP_SYSTEM;
2251 else if (KWMATCH(p, PPC7450_KW_USR))
2252 pmc_config->pm_caps |= PMC_CAP_USER;
2253 else if (KWMATCH(p, PPC7450_KW_ANYTHREAD))
2254 pmc_config->pm_caps |= (PMC_CAP_USER | PMC_CAP_SYSTEM);
2255 else
2256 return (-1);
2257 }
2258
2259 return (0);
2260}
2261#endif /* __powerpc__ */
2262
2263
2216/*
2217 * Match an event name `name' with its canonical form.
2218 *
2219 * Matches are case insensitive and spaces, periods, underscores and
2220 * hyphen characters are considered to match each other.
2221 *
2222 * Returns 1 for a match, 0 otherwise.
2223 */

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

2568 case PMC_CLASS_XSCALE:
2569 ev = xscale_event_table;
2570 count = PMC_EVENT_TABLE_SIZE(xscale);
2571 break;
2572 case PMC_CLASS_MIPS24K:
2573 ev = mips24k_event_table;
2574 count = PMC_EVENT_TABLE_SIZE(mips24k);
2575 break;
2264/*
2265 * Match an event name `name' with its canonical form.
2266 *
2267 * Matches are case insensitive and spaces, periods, underscores and
2268 * hyphen characters are considered to match each other.
2269 *
2270 * Returns 1 for a match, 0 otherwise.
2271 */

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

2616 case PMC_CLASS_XSCALE:
2617 ev = xscale_event_table;
2618 count = PMC_EVENT_TABLE_SIZE(xscale);
2619 break;
2620 case PMC_CLASS_MIPS24K:
2621 ev = mips24k_event_table;
2622 count = PMC_EVENT_TABLE_SIZE(mips24k);
2623 break;
2624 case PMC_CLASS_PPC7450:
2625 ev = ppc7450_event_table;
2626 count = PMC_EVENT_TABLE_SIZE(ppc7450);
2627 break;
2576 default:
2577 errno = EINVAL;
2578 return (-1);
2579 }
2580
2581 if ((names = malloc(count * sizeof(const char *))) == NULL)
2582 return (-1);
2583

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

2779 break;
2780#endif
2781#if defined(__mips__)
2782 case PMC_CPU_MIPS_24K:
2783 PMC_MDEP_INIT(mips24k);
2784 pmc_class_table[n] = &mips24k_class_table_descr;
2785 break;
2786#endif /* __mips__ */
2628 default:
2629 errno = EINVAL;
2630 return (-1);
2631 }
2632
2633 if ((names = malloc(count * sizeof(const char *))) == NULL)
2634 return (-1);
2635

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

2831 break;
2832#endif
2833#if defined(__mips__)
2834 case PMC_CPU_MIPS_24K:
2835 PMC_MDEP_INIT(mips24k);
2836 pmc_class_table[n] = &mips24k_class_table_descr;
2837 break;
2838#endif /* __mips__ */
2839#if defined(__powerpc__)
2840 case PMC_CPU_PPC_7450:
2841 PMC_MDEP_INIT(ppc7450);
2842 pmc_class_table[n] = &ppc7450_class_table_descr;
2843 break;
2844#endif
2787 default:
2788 /*
2789 * Some kind of CPU this version of the library knows nothing
2790 * about. This shouldn't happen since the abi version check
2791 * should have caught this.
2792 */
2793 errno = ENXIO;
2794 return (pmc_syscall = -1);

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

2919 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6);
2920 } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) {
2921 ev = xscale_event_table;
2922 evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale);
2923 } else if (pe >= PMC_EV_MIPS24K_FIRST && pe <= PMC_EV_MIPS24K_LAST) {
2924 ev = mips24k_event_table;
2925 evfence = mips24k_event_table + PMC_EVENT_TABLE_SIZE(mips24k
2926);
2845 default:
2846 /*
2847 * Some kind of CPU this version of the library knows nothing
2848 * about. This shouldn't happen since the abi version check
2849 * should have caught this.
2850 */
2851 errno = ENXIO;
2852 return (pmc_syscall = -1);

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

2977 evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6);
2978 } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) {
2979 ev = xscale_event_table;
2980 evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale);
2981 } else if (pe >= PMC_EV_MIPS24K_FIRST && pe <= PMC_EV_MIPS24K_LAST) {
2982 ev = mips24k_event_table;
2983 evfence = mips24k_event_table + PMC_EVENT_TABLE_SIZE(mips24k
2984);
2985 } else if (pe >= PMC_EV_PPC7450_FIRST && pe <= PMC_EV_PPC7450_LAST) {
2986 ev = ppc7450_event_table;
2987 evfence = ppc7450_event_table + PMC_EVENT_TABLE_SIZE(ppc7450
2988);
2927 } else if (pe == PMC_EV_TSC_TSC) {
2928 ev = tsc_event_table;
2929 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
2930 }
2931
2932 for (; ev != evfence; ev++)
2933 if (pe == ev->pm_ev_code)
2934 return (ev->pm_ev_name);

--- 199 unchanged lines hidden ---
2989 } else if (pe == PMC_EV_TSC_TSC) {
2990 ev = tsc_event_table;
2991 evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
2992 }
2993
2994 for (; ev != evfence; ev++)
2995 if (pe == ev->pm_ev_code)
2996 return (ev->pm_ev_name);

--- 199 unchanged lines hidden ---