diff options
Diffstat (limited to 'tools/perf/util/pmu.c')
| -rw-r--r-- | tools/perf/util/pmu.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b10b35a63138..07cb2ac041d7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <linux/compiler.h> | 3 | #include <linux/compiler.h> |
| 4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
| 5 | #include <errno.h> | 5 | #include <errno.h> |
| 6 | #include <fcntl.h> | ||
| 6 | #include <sys/stat.h> | 7 | #include <sys/stat.h> |
| 7 | #include <unistd.h> | 8 | #include <unistd.h> |
| 8 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -541,16 +542,8 @@ char * __weak get_cpuid_str(void) | |||
| 541 | return NULL; | 542 | return NULL; |
| 542 | } | 543 | } |
| 543 | 544 | ||
| 544 | /* | 545 | static char *perf_pmu__getcpuid(void) |
| 545 | * From the pmu_events_map, find the table of PMU events that corresponds | ||
| 546 | * to the current running CPU. Then, add all PMU events from that table | ||
| 547 | * as aliases. | ||
| 548 | */ | ||
| 549 | static void pmu_add_cpu_aliases(struct list_head *head, const char *name) | ||
| 550 | { | 546 | { |
| 551 | int i; | ||
| 552 | struct pmu_events_map *map; | ||
| 553 | struct pmu_event *pe; | ||
| 554 | char *cpuid; | 547 | char *cpuid; |
| 555 | static bool printed; | 548 | static bool printed; |
| 556 | 549 | ||
| @@ -560,22 +553,50 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name) | |||
| 560 | if (!cpuid) | 553 | if (!cpuid) |
| 561 | cpuid = get_cpuid_str(); | 554 | cpuid = get_cpuid_str(); |
| 562 | if (!cpuid) | 555 | if (!cpuid) |
| 563 | return; | 556 | return NULL; |
| 564 | 557 | ||
| 565 | if (!printed) { | 558 | if (!printed) { |
| 566 | pr_debug("Using CPUID %s\n", cpuid); | 559 | pr_debug("Using CPUID %s\n", cpuid); |
| 567 | printed = true; | 560 | printed = true; |
| 568 | } | 561 | } |
| 562 | return cpuid; | ||
| 563 | } | ||
| 564 | |||
| 565 | struct pmu_events_map *perf_pmu__find_map(void) | ||
| 566 | { | ||
| 567 | struct pmu_events_map *map; | ||
| 568 | char *cpuid = perf_pmu__getcpuid(); | ||
| 569 | int i; | ||
| 569 | 570 | ||
| 570 | i = 0; | 571 | i = 0; |
| 571 | while (1) { | 572 | for (;;) { |
| 572 | map = &pmu_events_map[i++]; | 573 | map = &pmu_events_map[i++]; |
| 573 | if (!map->table) | 574 | if (!map->table) { |
| 574 | goto out; | 575 | map = NULL; |
| 576 | break; | ||
| 577 | } | ||
| 575 | 578 | ||
| 576 | if (!strcmp(map->cpuid, cpuid)) | 579 | if (!strcmp(map->cpuid, cpuid)) |
| 577 | break; | 580 | break; |
| 578 | } | 581 | } |
| 582 | free(cpuid); | ||
| 583 | return map; | ||
| 584 | } | ||
| 585 | |||
| 586 | /* | ||
| 587 | * From the pmu_events_map, find the table of PMU events that corresponds | ||
| 588 | * to the current running CPU. Then, add all PMU events from that table | ||
| 589 | * as aliases. | ||
| 590 | */ | ||
| 591 | static void pmu_add_cpu_aliases(struct list_head *head, const char *name) | ||
| 592 | { | ||
| 593 | int i; | ||
| 594 | struct pmu_events_map *map; | ||
| 595 | struct pmu_event *pe; | ||
| 596 | |||
| 597 | map = perf_pmu__find_map(); | ||
| 598 | if (!map) | ||
| 599 | return; | ||
| 579 | 600 | ||
| 580 | /* | 601 | /* |
| 581 | * Found a matching PMU events table. Create aliases | 602 | * Found a matching PMU events table. Create aliases |
| @@ -585,8 +606,11 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name) | |||
| 585 | const char *pname; | 606 | const char *pname; |
| 586 | 607 | ||
| 587 | pe = &map->table[i++]; | 608 | pe = &map->table[i++]; |
| 588 | if (!pe->name) | 609 | if (!pe->name) { |
| 610 | if (pe->metric_group || pe->metric_name) | ||
| 611 | continue; | ||
| 589 | break; | 612 | break; |
| 613 | } | ||
| 590 | 614 | ||
| 591 | pname = pe->pmu ? pe->pmu : "cpu"; | 615 | pname = pe->pmu ? pe->pmu : "cpu"; |
| 592 | if (strncmp(pname, name, strlen(pname))) | 616 | if (strncmp(pname, name, strlen(pname))) |
| @@ -600,9 +624,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name) | |||
| 600 | (char *)pe->metric_expr, | 624 | (char *)pe->metric_expr, |
| 601 | (char *)pe->metric_name); | 625 | (char *)pe->metric_name); |
| 602 | } | 626 | } |
| 603 | |||
| 604 | out: | ||
| 605 | free(cpuid); | ||
| 606 | } | 627 | } |
| 607 | 628 | ||
| 608 | struct perf_event_attr * __weak | 629 | struct perf_event_attr * __weak |
