libpmc.c (147219) | libpmc.c (147759) |
---|---|
1/*- 2 * Copyright (c) 2003-2005 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-2005 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 147219 2005-06-10 03:45:04Z jkoshy $"); | 28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 147759 2005-07-03 16:33:22Z 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> --- 5 unchanged lines hidden (view full) --- 42#include <strings.h> 43#include <unistd.h> 44 45/* Function prototypes */ 46#if defined(__i386__) 47static int k7_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 48 struct pmc_op_pmcallocate *_pmc_config); 49#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> --- 5 unchanged lines hidden (view full) --- 42#include <strings.h> 43#include <unistd.h> 44 45/* Function prototypes */ 46#if defined(__i386__) 47static int k7_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 48 struct pmc_op_pmcallocate *_pmc_config); 49#endif |
50#if defined(__amd64__) | 50#if defined(__amd64__) || defined(__i386__) |
51static int k8_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 52 struct pmc_op_pmcallocate *_pmc_config); | 51static int k8_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 52 struct pmc_op_pmcallocate *_pmc_config); |
53#endif 54#if defined(__i386__) | |
55static int p4_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 56 struct pmc_op_pmcallocate *_pmc_config); | 53static int p4_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 54 struct pmc_op_pmcallocate *_pmc_config); |
55#endif 56#if defined(__i386__) |
|
57static int p5_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 58 struct pmc_op_pmcallocate *_pmc_config); 59static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 60 struct pmc_op_pmcallocate *_pmc_config); 61#endif 62 63#define PMC_CALL(cmd, params) \ 64 syscall(pmc_syscall, PMC_OP_##cmd, (params)) --- 84 unchanged lines hidden (view full) --- 149/* Event masks for events */ 150struct pmc_masks { 151 const char *pm_name; 152 const uint32_t pm_value; 153}; 154#define PMCMASK(N,V) { .pm_name = #N, .pm_value = (V) } 155#define NULLMASK PMCMASK(NULL,0) 156 | 57static int p5_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 58 struct pmc_op_pmcallocate *_pmc_config); 59static int p6_allocate_pmc(enum pmc_event _pe, char *_ctrspec, 60 struct pmc_op_pmcallocate *_pmc_config); 61#endif 62 63#define PMC_CALL(cmd, params) \ 64 syscall(pmc_syscall, PMC_OP_##cmd, (params)) --- 84 unchanged lines hidden (view full) --- 149/* Event masks for events */ 150struct pmc_masks { 151 const char *pm_name; 152 const uint32_t pm_value; 153}; 154#define PMCMASK(N,V) { .pm_name = #N, .pm_value = (V) } 155#define NULLMASK PMCMASK(NULL,0) 156 |
157#if defined(__i386__) || defined(__amd64__) | 157#if defined(__amd64__) || defined(__i386__) |
158static int 159pmc_parse_mask(const struct pmc_masks *pmask, char *p, uint32_t *evmask) 160{ 161 const struct pmc_masks *pm; 162 char *q, *r; 163 int c; 164 165 if (pmask == NULL) /* no mask keywords */ --- 130 unchanged lines hidden (view full) --- 296 } 297 298 return 0; 299 300} 301 302#endif 303 | 158static int 159pmc_parse_mask(const struct pmc_masks *pmask, char *p, uint32_t *evmask) 160{ 161 const struct pmc_masks *pm; 162 char *q, *r; 163 int c; 164 165 if (pmask == NULL) /* no mask keywords */ --- 130 unchanged lines hidden (view full) --- 296 } 297 298 return 0; 299 300} 301 302#endif 303 |
304#if defined(__amd64__) | 304#if defined(__amd64__) || defined(__i386__) |
305 306/* 307 * AMD K8 PMCs. 308 * 309 * These are very similar to AMD K7 PMCs, but support more kinds of 310 * events. 311 */ 312 --- 352 unchanged lines hidden (view full) --- 665 pmc_config->pm_md.pm_amd.pm_amd_config = 666 AMD_PMC_TO_UNITMASK(evmask); 667 668 return 0; 669} 670 671#endif 672 | 305 306/* 307 * AMD K8 PMCs. 308 * 309 * These are very similar to AMD K7 PMCs, but support more kinds of 310 * events. 311 */ 312 --- 352 unchanged lines hidden (view full) --- 665 pmc_config->pm_md.pm_amd.pm_amd_config = 666 AMD_PMC_TO_UNITMASK(evmask); 667 668 return 0; 669} 670 671#endif 672 |
673#if defined(__i386__) | 673#if defined(__amd64__) || defined(__i386__) |
674 675/* 676 * Intel P4 PMCs 677 */ 678 679static struct pmc_event_alias p4_aliases[] = { 680 EV_ALIAS("branches", "p4-branch-retired,mask=mmtp+mmtm"), 681 EV_ALIAS("branch-mispredicts", "p4-mispred-branch-retired"), --- 596 unchanged lines hidden (view full) --- 1278 } 1279 1280 pmc_config->pm_md.pm_p4.pm_p4_escrconfig = 1281 P4_ESCR_TO_EVENT_MASK(evmask); 1282 1283 return 0; 1284} 1285 | 674 675/* 676 * Intel P4 PMCs 677 */ 678 679static struct pmc_event_alias p4_aliases[] = { 680 EV_ALIAS("branches", "p4-branch-retired,mask=mmtp+mmtm"), 681 EV_ALIAS("branch-mispredicts", "p4-mispred-branch-retired"), --- 596 unchanged lines hidden (view full) --- 1278 } 1279 1280 pmc_config->pm_md.pm_p4.pm_p4_escrconfig = 1281 P4_ESCR_TO_EVENT_MASK(evmask); 1282 1283 return 0; 1284} 1285 |
1286#endif 1287 1288#if defined(__i386__) 1289 |
|
1286/* 1287 * Pentium style PMCs 1288 */ 1289 1290static struct pmc_event_alias p5_aliases[] = { 1291 EV_ALIAS("cycles", "tsc"), 1292 EV_ALIAS(NULL, NULL) 1293}; --- 651 unchanged lines hidden (view full) --- 1945 break; 1946 case PMC_CPU_INTEL_P6: /* P6 ... Pentium M CPUs have */ 1947 case PMC_CPU_INTEL_PII: /* similar PMCs. */ 1948 case PMC_CPU_INTEL_PIII: 1949 case PMC_CPU_INTEL_PM: 1950 pmc_mdep_event_aliases = p6_aliases; 1951 pmc_mdep_allocate_pmc = p6_allocate_pmc; 1952 break; | 1290/* 1291 * Pentium style PMCs 1292 */ 1293 1294static struct pmc_event_alias p5_aliases[] = { 1295 EV_ALIAS("cycles", "tsc"), 1296 EV_ALIAS(NULL, NULL) 1297}; --- 651 unchanged lines hidden (view full) --- 1949 break; 1950 case PMC_CPU_INTEL_P6: /* P6 ... Pentium M CPUs have */ 1951 case PMC_CPU_INTEL_PII: /* similar PMCs. */ 1952 case PMC_CPU_INTEL_PIII: 1953 case PMC_CPU_INTEL_PM: 1954 pmc_mdep_event_aliases = p6_aliases; 1955 pmc_mdep_allocate_pmc = p6_allocate_pmc; 1956 break; |
1957#endif 1958#if defined(__amd64__) || defined(__i386__) |
|
1953 case PMC_CPU_INTEL_PIV: 1954 pmc_mdep_event_aliases = p4_aliases; 1955 pmc_mdep_allocate_pmc = p4_allocate_pmc; 1956 break; | 1959 case PMC_CPU_INTEL_PIV: 1960 pmc_mdep_event_aliases = p4_aliases; 1961 pmc_mdep_allocate_pmc = p4_allocate_pmc; 1962 break; |
1957#elif defined(__amd64__) | |
1958 case PMC_CPU_AMD_K8: 1959 pmc_mdep_event_aliases = k8_aliases; 1960 pmc_mdep_allocate_pmc = k8_allocate_pmc; 1961 break; 1962#endif 1963 1964 default: 1965 /* --- 264 unchanged lines hidden --- | 1963 case PMC_CPU_AMD_K8: 1964 pmc_mdep_event_aliases = k8_aliases; 1965 pmc_mdep_allocate_pmc = k8_allocate_pmc; 1966 break; 1967#endif 1968 1969 default: 1970 /* --- 264 unchanged lines hidden --- |