Deleted Added
full compact
libpmc.c (193809) libpmc.c (198433)
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 193809 2009-06-09 06:34:48Z jkoshy $");
28__FBSDID("$FreeBSD: head/lib/libpmc/libpmc.c 198433 2009-10-24 04:11:40Z 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>

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

437 EV_ALIAS("interrupts", "iap-core-hw-int-rx"),
438 EV_ALIAS("unhalted-cycles", "iap-unhalted-core-cycles"),
439 EV_ALIAS(NULL, NULL)
440};
441
442/*
443 * Intel Core2 (Family 6, Model F), Core2Extreme (Family 6, Model 17H)
444 * and Atom (Family 6, model 1CH) PMCs.
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>

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

437 EV_ALIAS("interrupts", "iap-core-hw-int-rx"),
438 EV_ALIAS("unhalted-cycles", "iap-unhalted-core-cycles"),
439 EV_ALIAS(NULL, NULL)
440};
441
442/*
443 * Intel Core2 (Family 6, Model F), Core2Extreme (Family 6, Model 17H)
444 * and Atom (Family 6, model 1CH) PMCs.
445 *
446 * We map aliases to events on the fixed-function counters if these
447 * are present. Note that not all CPUs in this family contain fixed-function
448 * counters.
445 */
446
447static struct pmc_event_alias core2_aliases[] = {
448 EV_ALIAS("branches", "iap-br-inst-retired.any"),
449 EV_ALIAS("branch-mispredicts", "iap-br-inst-retired.mispred"),
450 EV_ALIAS("cycles", "tsc-tsc"),
451 EV_ALIAS("ic-misses", "iap-l1i-misses"),
452 EV_ALIAS("instructions", "iaf-instr-retired.any"),
453 EV_ALIAS("interrupts", "iap-hw-int-rcv"),
454 EV_ALIAS("unhalted-cycles", "iaf-cpu-clk-unhalted.core"),
455 EV_ALIAS(NULL, NULL)
456};
449 */
450
451static struct pmc_event_alias core2_aliases[] = {
452 EV_ALIAS("branches", "iap-br-inst-retired.any"),
453 EV_ALIAS("branch-mispredicts", "iap-br-inst-retired.mispred"),
454 EV_ALIAS("cycles", "tsc-tsc"),
455 EV_ALIAS("ic-misses", "iap-l1i-misses"),
456 EV_ALIAS("instructions", "iaf-instr-retired.any"),
457 EV_ALIAS("interrupts", "iap-hw-int-rcv"),
458 EV_ALIAS("unhalted-cycles", "iaf-cpu-clk-unhalted.core"),
459 EV_ALIAS(NULL, NULL)
460};
457#define atom_aliases core2_aliases
458#define corei7_aliases core2_aliases
459
461
462static struct pmc_event_alias core2_aliases_without_iaf[] = {
463 EV_ALIAS("branches", "iap-br-inst-retired.any"),
464 EV_ALIAS("branch-mispredicts", "iap-br-inst-retired.mispred"),
465 EV_ALIAS("cycles", "tsc-tsc"),
466 EV_ALIAS("ic-misses", "iap-l1i-misses"),
467 EV_ALIAS("instructions", "iap-inst-retired.any_p"),
468 EV_ALIAS("interrupts", "iap-hw-int-rcv"),
469 EV_ALIAS("unhalted-cycles", "iap-cpu-clk-unhalted.core_p"),
470 EV_ALIAS(NULL, NULL)
471};
472
473#define atom_aliases core2_aliases
474#define atom_aliases_without_iaf core2_aliases_without_iaf
475#define corei7_aliases core2_aliases
476#define corei7_aliases_without_iaf core2_aliases_without_iaf
477
460#define IAF_KW_OS "os"
461#define IAF_KW_USR "usr"
462#define IAF_KW_ANYTHREAD "anythread"
463
464/*
465 * Parse an event specifier for Intel fixed function counters.
466 */
467static int

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

2374int
2375pmc_init(void)
2376{
2377 int error, pmc_mod_id;
2378 unsigned int n;
2379 uint32_t abi_version;
2380 struct module_stat pmc_modstat;
2381 struct pmc_op_getcpuinfo op_cpu_info;
478#define IAF_KW_OS "os"
479#define IAF_KW_USR "usr"
480#define IAF_KW_ANYTHREAD "anythread"
481
482/*
483 * Parse an event specifier for Intel fixed function counters.
484 */
485static int

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

2392int
2393pmc_init(void)
2394{
2395 int error, pmc_mod_id;
2396 unsigned int n;
2397 uint32_t abi_version;
2398 struct module_stat pmc_modstat;
2399 struct pmc_op_getcpuinfo op_cpu_info;
2400#if defined(__amd64__) || defined(__i386__)
2401 int cpu_has_iaf_counters;
2402 unsigned int t;
2403#endif
2382
2383 if (pmc_syscall != -1) /* already inited */
2384 return (0);
2385
2386 /* retrieve the system call number from the KLD */
2387 if ((pmc_mod_id = modfind(PMC_MODULE_NAME)) < 0)
2388 return (-1);
2389

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

2415 cpu_info.pm_classes[n] = op_cpu_info.pm_classes[n];
2416
2417 pmc_class_table = malloc(PMC_CLASS_TABLE_SIZE *
2418 sizeof(struct pmc_class_descr *));
2419
2420 if (pmc_class_table == NULL)
2421 return (-1);
2422
2404
2405 if (pmc_syscall != -1) /* already inited */
2406 return (0);
2407
2408 /* retrieve the system call number from the KLD */
2409 if ((pmc_mod_id = modfind(PMC_MODULE_NAME)) < 0)
2410 return (-1);
2411

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

2437 cpu_info.pm_classes[n] = op_cpu_info.pm_classes[n];
2438
2439 pmc_class_table = malloc(PMC_CLASS_TABLE_SIZE *
2440 sizeof(struct pmc_class_descr *));
2441
2442 if (pmc_class_table == NULL)
2443 return (-1);
2444
2445 for (n = 0; n < PMC_CLASS_TABLE_SIZE; n++)
2446 pmc_class_table[n] = NULL;
2423
2424 /*
2425 * Fill in the class table.
2426 */
2427 n = 0;
2428#if defined(__amd64__) || defined(__i386__)
2429 pmc_class_table[n++] = &tsc_class_table_descr;
2447
2448 /*
2449 * Fill in the class table.
2450 */
2451 n = 0;
2452#if defined(__amd64__) || defined(__i386__)
2453 pmc_class_table[n++] = &tsc_class_table_descr;
2454
2455 /*
2456 * Check if this CPU has fixed function counters.
2457 */
2458 cpu_has_iaf_counters = 0;
2459 for (t = 0; t < cpu_info.pm_nclass; t++)
2460 if (cpu_info.pm_classes[t].pm_class == PMC_CLASS_IAF)
2461 cpu_has_iaf_counters = 1;
2430#endif
2431
2432#define PMC_MDEP_INIT(C) do { \
2433 pmc_mdep_event_aliases = C##_aliases; \
2434 pmc_mdep_class_list = C##_pmc_classes; \
2435 pmc_mdep_class_list_size = \
2436 PMC_TABLE_SIZE(C##_pmc_classes); \
2437 } while (0)
2438
2462#endif
2463
2464#define PMC_MDEP_INIT(C) do { \
2465 pmc_mdep_event_aliases = C##_aliases; \
2466 pmc_mdep_class_list = C##_pmc_classes; \
2467 pmc_mdep_class_list_size = \
2468 PMC_TABLE_SIZE(C##_pmc_classes); \
2469 } while (0)
2470
2471#define PMC_MDEP_INIT_INTEL_V2(C) do { \
2472 PMC_MDEP_INIT(C); \
2473 if (cpu_has_iaf_counters) \
2474 pmc_class_table[n++] = &iaf_class_table_descr; \
2475 else \
2476 pmc_mdep_event_aliases = \
2477 C##_aliases_without_iaf; \
2478 pmc_class_table[n] = &C##_class_table_descr; \
2479 } while (0)
2480
2439 /* Configure the event name parser. */
2440 switch (cpu_info.pm_cputype) {
2441#if defined(__i386__)
2442 case PMC_CPU_AMD_K7:
2443 PMC_MDEP_INIT(k7);
2444 pmc_class_table[n] = &k7_class_table_descr;
2445 break;
2446 case PMC_CPU_INTEL_P5:

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

2456 break;
2457#endif
2458#if defined(__amd64__) || defined(__i386__)
2459 case PMC_CPU_AMD_K8:
2460 PMC_MDEP_INIT(k8);
2461 pmc_class_table[n] = &k8_class_table_descr;
2462 break;
2463 case PMC_CPU_INTEL_ATOM:
2481 /* Configure the event name parser. */
2482 switch (cpu_info.pm_cputype) {
2483#if defined(__i386__)
2484 case PMC_CPU_AMD_K7:
2485 PMC_MDEP_INIT(k7);
2486 pmc_class_table[n] = &k7_class_table_descr;
2487 break;
2488 case PMC_CPU_INTEL_P5:

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

2498 break;
2499#endif
2500#if defined(__amd64__) || defined(__i386__)
2501 case PMC_CPU_AMD_K8:
2502 PMC_MDEP_INIT(k8);
2503 pmc_class_table[n] = &k8_class_table_descr;
2504 break;
2505 case PMC_CPU_INTEL_ATOM:
2464 PMC_MDEP_INIT(atom);
2465 pmc_class_table[n++] = &iaf_class_table_descr;
2466 pmc_class_table[n] = &atom_class_table_descr;
2506 PMC_MDEP_INIT_INTEL_V2(atom);
2467 break;
2468 case PMC_CPU_INTEL_CORE:
2469 PMC_MDEP_INIT(core);
2507 break;
2508 case PMC_CPU_INTEL_CORE:
2509 PMC_MDEP_INIT(core);
2470 pmc_class_table[n] = &core_class_table_descr;
2471 break;
2472 case PMC_CPU_INTEL_CORE2:
2473 case PMC_CPU_INTEL_CORE2EXTREME:
2510 break;
2511 case PMC_CPU_INTEL_CORE2:
2512 case PMC_CPU_INTEL_CORE2EXTREME:
2474 PMC_MDEP_INIT(core2);
2475 pmc_class_table[n++] = &iaf_class_table_descr;
2476 pmc_class_table[n] = &core2_class_table_descr;
2513 PMC_MDEP_INIT_INTEL_V2(core2);
2477 break;
2478 case PMC_CPU_INTEL_COREI7:
2514 break;
2515 case PMC_CPU_INTEL_COREI7:
2479 PMC_MDEP_INIT(corei7);
2480 pmc_class_table[n++] = &iaf_class_table_descr;
2481 pmc_class_table[n] = &corei7_class_table_descr;
2516 PMC_MDEP_INIT_INTEL_V2(corei7);
2482 break;
2483 case PMC_CPU_INTEL_PIV:
2484 PMC_MDEP_INIT(p4);
2485 pmc_class_table[n] = &p4_class_table_descr;
2486 break;
2487#endif
2488
2489

--- 320 unchanged lines hidden ---
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
2523
2524

--- 320 unchanged lines hidden ---