Skip to content

Commit c07d5c9

Browse files
John Garryacmel
authored andcommitted
perf pmu: Fix alias matching
Commit c47a559 ("perf tools: Fix pattern matching for same substring in different PMU type"), may have fixed some alias matching, but has broken some others. Firstly it cannot handle the simple scenario of PMU name in form pmu_name{digits} - it can only handle pmu_name_{digits}. Secondly it cannot handle more complex matching in the case where we have multiple tokens. In this scenario, the code failed to realise that we may examine multiple substrings in the PMU name. Fix in two ways: - Change perf_pmu__valid_suffix() to accept a PMU name without '_' in the suffix - Only pay attention to perf_pmu__valid_suffix() for the final token Also add const qualifiers as necessary to avoid casting. Fixes: c47a559 ("perf tools: Fix pattern matching for same substring in different PMU type") Signed-off-by: John Garry <[email protected]> Tested-by: Jin Yao <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 48e8a7b commit c07d5c9

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

tools/perf/util/pmu.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,13 @@ struct pmu_events_map *__weak pmu_events_map__find(void)
742742
return perf_pmu__find_map(NULL);
743743
}
744744

745-
static bool perf_pmu__valid_suffix(char *pmu_name, char *tok)
745+
/*
746+
* Suffix must be in form tok_{digits}, or tok{digits}, or same as pmu_name
747+
* to be valid.
748+
*/
749+
static bool perf_pmu__valid_suffix(const char *pmu_name, char *tok)
746750
{
747-
char *p;
751+
const char *p;
748752

749753
if (strncmp(pmu_name, tok, strlen(tok)))
750754
return false;
@@ -753,12 +757,16 @@ static bool perf_pmu__valid_suffix(char *pmu_name, char *tok)
753757
if (*p == 0)
754758
return true;
755759

756-
if (*p != '_')
757-
return false;
760+
if (*p == '_')
761+
++p;
758762

759-
++p;
760-
if (*p == 0 || !isdigit(*p))
761-
return false;
763+
/* Ensure we end in a number */
764+
while (1) {
765+
if (!isdigit(*p))
766+
return false;
767+
if (*(++p) == 0)
768+
break;
769+
}
762770

763771
return true;
764772
}
@@ -789,12 +797,19 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
789797
* match "socket" in "socketX_pmunameY" and then "pmuname" in
790798
* "pmunameY".
791799
*/
792-
for (; tok; name += strlen(tok), tok = strtok_r(NULL, ",", &tmp)) {
800+
while (1) {
801+
char *next_tok = strtok_r(NULL, ",", &tmp);
802+
793803
name = strstr(name, tok);
794-
if (!name || !perf_pmu__valid_suffix((char *)name, tok)) {
804+
if (!name ||
805+
(!next_tok && !perf_pmu__valid_suffix(name, tok))) {
795806
res = false;
796807
goto out;
797808
}
809+
if (!next_tok)
810+
break;
811+
tok = next_tok;
812+
name += strlen(tok);
798813
}
799814

800815
res = true;

0 commit comments

Comments
 (0)