diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/arch/s390/util/header.c | 18 | ||||
| -rw-r--r-- | tools/perf/util/header.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/pmu.c | 47 |
3 files changed, 48 insertions, 18 deletions
diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c index a78064c25ced..231294b80dc4 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c | |||
| @@ -146,3 +146,21 @@ char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) | |||
| 146 | zfree(&buf); | 146 | zfree(&buf); |
| 147 | return buf; | 147 | return buf; |
| 148 | } | 148 | } |
| 149 | |||
| 150 | /* | ||
| 151 | * Compare the cpuid string returned by get_cpuid() function | ||
| 152 | * with the name generated by the jevents file read from | ||
| 153 | * pmu-events/arch/s390/mapfile.csv. | ||
| 154 | * | ||
| 155 | * Parameter mapcpuid is the cpuid as stored in the | ||
| 156 | * pmu-events/arch/s390/mapfile.csv. This is just the type number. | ||
| 157 | * Parameter cpuid is the cpuid returned by function get_cpuid(). | ||
| 158 | */ | ||
| 159 | int strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) | ||
| 160 | { | ||
| 161 | char *cp = strchr(cpuid, ','); | ||
| 162 | |||
| 163 | if (cp == NULL) | ||
| 164 | return -1; | ||
| 165 | return strncmp(cp + 1, mapcpuid, strlen(mapcpuid)); | ||
| 166 | } | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index f28aaaa3a440..942bdec6d70d 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
| @@ -174,4 +174,5 @@ int write_padded(struct feat_fd *fd, const void *bf, | |||
| 174 | int get_cpuid(char *buffer, size_t sz); | 174 | int get_cpuid(char *buffer, size_t sz); |
| 175 | 175 | ||
| 176 | char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); | 176 | char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused); |
| 177 | int strcmp_cpuid_str(const char *s1, const char *s2); | ||
| 177 | #endif /* __PERF_HEADER_H */ | 178 | #endif /* __PERF_HEADER_H */ |
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 57e38fdf0b34..1111d5bf15ca 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
| @@ -576,6 +576,34 @@ char * __weak get_cpuid_str(struct perf_pmu *pmu __maybe_unused) | |||
| 576 | return NULL; | 576 | return NULL; |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | /* Return zero when the cpuid from the mapfile.csv matches the | ||
| 580 | * cpuid string generated on this platform. | ||
| 581 | * Otherwise return non-zero. | ||
| 582 | */ | ||
| 583 | int __weak strcmp_cpuid_str(const char *mapcpuid, const char *cpuid) | ||
| 584 | { | ||
| 585 | regex_t re; | ||
| 586 | regmatch_t pmatch[1]; | ||
| 587 | int match; | ||
| 588 | |||
| 589 | if (regcomp(&re, mapcpuid, REG_EXTENDED) != 0) { | ||
| 590 | /* Warn unable to generate match particular string. */ | ||
| 591 | pr_info("Invalid regular expression %s\n", mapcpuid); | ||
| 592 | return 1; | ||
| 593 | } | ||
| 594 | |||
| 595 | match = !regexec(&re, cpuid, 1, pmatch, 0); | ||
| 596 | regfree(&re); | ||
| 597 | if (match) { | ||
| 598 | size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); | ||
| 599 | |||
| 600 | /* Verify the entire string matched. */ | ||
| 601 | if (match_len == strlen(cpuid)) | ||
| 602 | return 0; | ||
| 603 | } | ||
| 604 | return 1; | ||
| 605 | } | ||
| 606 | |||
| 579 | static char *perf_pmu__getcpuid(struct perf_pmu *pmu) | 607 | static char *perf_pmu__getcpuid(struct perf_pmu *pmu) |
| 580 | { | 608 | { |
| 581 | char *cpuid; | 609 | char *cpuid; |
| @@ -610,31 +638,14 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) | |||
| 610 | 638 | ||
| 611 | i = 0; | 639 | i = 0; |
| 612 | for (;;) { | 640 | for (;;) { |
| 613 | regex_t re; | ||
| 614 | regmatch_t pmatch[1]; | ||
| 615 | int match; | ||
| 616 | |||
| 617 | map = &pmu_events_map[i++]; | 641 | map = &pmu_events_map[i++]; |
| 618 | if (!map->table) { | 642 | if (!map->table) { |
| 619 | map = NULL; | 643 | map = NULL; |
| 620 | break; | 644 | break; |
| 621 | } | 645 | } |
| 622 | 646 | ||
| 623 | if (regcomp(&re, map->cpuid, REG_EXTENDED) != 0) { | 647 | if (!strcmp_cpuid_str(map->cpuid, cpuid)) |
| 624 | /* Warn unable to generate match particular string. */ | ||
| 625 | pr_info("Invalid regular expression %s\n", map->cpuid); | ||
| 626 | break; | 648 | break; |
| 627 | } | ||
| 628 | |||
| 629 | match = !regexec(&re, cpuid, 1, pmatch, 0); | ||
| 630 | regfree(&re); | ||
| 631 | if (match) { | ||
| 632 | size_t match_len = (pmatch[0].rm_eo - pmatch[0].rm_so); | ||
| 633 | |||
| 634 | /* Verify the entire string matched. */ | ||
| 635 | if (match_len == strlen(cpuid)) | ||
| 636 | break; | ||
| 637 | } | ||
| 638 | } | 649 | } |
| 639 | free(cpuid); | 650 | free(cpuid); |
| 640 | return map; | 651 | return map; |
