Deleted Added
sdiff udiff text old ( 202157 ) new ( 204635 )
full compact
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 $");
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#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);
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);
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
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
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;
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
2566
2567
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);
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 ---