perf x86/topdown: Make topdown metrics comparators be symmetric
PATCH 1/2 perf x86/topdown: Make topdown metrics comparators be symmetric
The commit "3b5edc0421e2 (perf x86/topdown: Don't move topdown metric
events in group)" modifies topdown metrics comparator to move topdown
metrics events which are not in same group with previous event. But it just modifies the 2nd comparator and causes the comparators become asymmetric.
Thus modify the 1st topdown metrics comparator and make the two comparators be symmetric, and refine the comments as well.
--- tools/perf/arch/x86/util/evlist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
tools/perf/arch/x86/util/evlist.c +9 -6
@@ -52,7 +52,7 @@ int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)* 3,015,058 cycles * <not supported> topdown-retiring * -* if slots event and topdown metrics events are in two groups, the group which +* If slots event and topdown metrics events are in two groups, the group which * has topdown metrics events must contain only the topdown metrics event, * otherwise topdown metrics event can't be regrouped correctly as well, e.g. *
@@ -69,13 +69,16 @@ int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)return -1 ;if (arch_is_topdown_slots (rhs))return 1 ; -/* Followed by topdown events. */ -if (arch_is_topdown_metrics (lhs) && !arch_is_topdown_metrics (rhs)) -return -1 ; +/* -* Move topdown events forward only when topdown events -* are not in same group with previous event. +* Move topdown metrics events forward only when topdown metrics +* events are not in same group with previous slots event. If +* topdown metrics events are already in same group with slots +* event, do nothing. */ +if (arch_is_topdown_metrics (lhs) && !arch_is_topdown_metrics (rhs) && + lhs->core.leader != rhs->core.leader) +return -1 ;if (!arch_is_topdown_metrics (lhs) &&arch_is_topdown_metrics (rhs) && lhs->core.leader != rhs->core.leader)return 1 ;
base-commit: 57fb40d40f9543213ffadb04d07cfb2ba46edc26
Signature · 1 line
2.40.1
PATCH 2/2 perf x86/topdown: Refine helper arch_is_topdown_metrics()
Leverage the existed function perf_pmu__name_from_config() to check if an event is topdown metrics event. perf_pmu__name_from_config() goes through the defined formats and figures out the config of pre-defined topdown events.
This avoids to figure out the config of topdown pre-defined events with hard-coded format strings "event=" and "umask=" and provides more flexibility.
--- tools/perf/arch/x86/util/topdown.c | 39 +++++++----------------------- 1 file changed, 9 insertions(+), 30 deletions(-)
tools/perf/arch/x86/util/topdown.c +9 -30
@@ -41,43 +41,22 @@ bool arch_is_topdown_slots(const struct evsel *evsel)return false; } -static int compare_topdown_event (void *vstate,struct pmu_event_info *info) -{ -int *config = vstate; -int event =0 ; -int umask =0 ; -char *str; - -if (!strcasestr (info->name,"topdown" )) -return 0 ; - - str =strcasestr (info->str,"event=" ); -if (str) -sscanf (str,"event=%x" , &event); - - str =strcasestr (info->str,"umask=" ); -if (str) -sscanf (str,"umask=%x" , &umask); - -if (event ==0 && *config == (event | umask <<8 )) -return 1 ; - -return 0 ; -} -bool arch_is_topdown_metrics (const struct evsel *evsel) { -struct perf_pmu *pmu =evsel__find_pmu (evsel);int config = evsel->core.attr.config; +const char *name_from_config; +struct perf_pmu *pmu; -if (!pmu || !pmu->is_core) +/* All topdown events have an event code of 0. */ +if ((config &0xFF ) !=0 )return false; -if (perf_pmu__for_each_event (pmu, false, &config, - compare_topdown_event)) -return true; + pmu =evsel__find_pmu (evsel); +if (!pmu || !pmu->is_core) +return false; -return false; + name_from_config =perf_pmu__name_from_config (pmu, config); +return name_from_config &&strcasestr (name_from_config,"topdown" ); }/*
Signature · 1 line
2.40.1
Namhyung Kim
maintainerRe: [PATCH 2/2] perf x86/topdown: Refine helper arch_is_topdown_metrics()
Hi Ian,
Quoted 11 lines · Dapeng Mi
Leverage the existed function
perf_pmu__name_from_config()to check if an event is topdown metrics event.perf_pmu__name_from_config()goes through the defined formats and figures out the config of pre-defined topdown events.This avoids to figure out the config of topdown pre-defined events with hard-coded format strings "event=" and "umask=" and provides more flexibility.
Suggested-by Ian Rogers <[email protected]>Signed-off-by Dapeng Mi <[email protected]>
Are you ok with this now?
Thanks,
Namhyung
Quoted 64 lines
--- tools/perf/arch/x86/util/topdown.c | 39 +++++++----------------------- 1 file changed, 9 insertions(+), 30 deletions(-)tools/perf/arch/x86/util/topdown.c +9
-30@@ -41,43 +41,22 @@ bool arch_is_topdown_slots(const struct evsel *evsel)return false; } -static int compare_topdown_event (void *vstate,struct pmu_event_info *info) -{ -int *config = vstate; -int event =0 ; -int umask =0 ; -char *str; - -if (!strcasestr (info->name,"topdown" )) -return 0 ; - - str =strcasestr (info->str,"event=" ); -if (str) -sscanf (str,"event=%x" , &event); - - str =strcasestr (info->str,"umask=" ); -if (str) -sscanf (str,"umask=%x" , &umask); - -if (event ==0 && *config == (event | umask <<8 )) -return 1 ; - -return 0 ; -} -bool arch_is_topdown_metrics (const struct evsel *evsel) { -struct perf_pmu *pmu =evsel__find_pmu (evsel);int config = evsel->core.attr.config; +const char *name_from_config; +struct perf_pmu *pmu; -if (!pmu || !pmu->is_core) +/* All topdown events have an event code of 0. */ +if ((config &0xFF ) !=0 )return false; -if (perf_pmu__for_each_event (pmu, false, &config, - compare_topdown_event)) -return true; + pmu =evsel__find_pmu (evsel); +if (!pmu || !pmu->is_core) +return false; -return false; + name_from_config =perf_pmu__name_from_config (pmu, config); +return name_from_config &&strcasestr (name_from_config,"topdown" ); }/* Signature · 1 line
2.40.1
Re: [PATCH 2/2] perf x86/topdown: Refine helper arch_is_topdown_metrics()
Quoted 9 lines · Namhyung Kim
Hi Ian,
Quoted 5 lines · Dapeng Mi
Leverage the existed function
perf_pmu__name_from_config()to check if an event is topdown metrics event.perf_pmu__name_from_config()goes through the defined formats and figures out the config of pre-defined topdown events.
Quoted 8 lines
Quoted 6 lines
This avoids to figure out the config of topdown pre-defined events with hard-coded format strings "event=" and "umask=" and provides more flexibility.
Suggested-by Ian Rogers <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Are you ok with this now?
Thanks,
Ian
Quoted 67 lines
Thanks,
NamhyungQuoted 64 lines
--- tools/perf/arch/x86/util/topdown.c | 39 +++++++----------------------- 1 file changed, 9 insertions(+), 30 deletions(-)tools/perf/arch/x86/util/topdown.c +9
-31@@ -41,43 +41,22 @@ bool arch_is_topdown_slots(const struct evsel *evsel)return false; } -static int compare_topdown_event (void *vstate,struct pmu_event_info *info) -{ -int *config = vstate; -int event =0 ; -int umask =0 ; -char *str; - -if (!strcasestr (info->name,"topdown" )) -return 0 ; - - str =strcasestr (info->str,"event=" ); -if (str) -sscanf (str,"event=%x" , &event); - - str =strcasestr (info->str,"umask=" ); -if (str) -sscanf (str,"umask=%x" , &umask); - -if (event ==0 && *config == (event | umask <<8 )) -return 1 ; - -return 0 ; -} -bool arch_is_topdown_metrics (const struct evsel *evsel) { -struct perf_pmu *pmu =evsel__find_pmu (evsel);int config = evsel->core.attr.config; +const char *name_from_config; +struct perf_pmu *pmu; -if (!pmu || !pmu->is_core) +/* All topdown events have an event code of 0. */ +if ((config &0xFF ) !=0 )return false; -if (perf_pmu__for_each_event (pmu, false, &config, - compare_topdown_event)) -return true; + pmu =evsel__find_pmu (evsel); +if (!pmu || !pmu->is_core) +return false; -return false; + name_from_config =perf_pmu__name_from_config (pmu, config); +return name_from_config &&strcasestr (name_from_config,"topdown" ); }/* -- 2.40.1
Quoted 7 lines · Dapeng Mi
The commit "
3b5edc0421e2(perf x86/topdown: Don't move topdown metric
events in group)" modifies topdown metrics comparator to move topdown
metrics events which are not in same group with previous event. But it just modifies the 2nd comparator and causes the comparators become asymmetric.
Quoted 5 lines
Thus modify the 1st topdown metrics comparator and make the two comparators be symmetric, and refine the comments as well.
Suggested-by Ian Rogers <[email protected]>Signed-off-by Dapeng Mi <[email protected]>
Thanks,
Ian
Quoted 44 lines
--- tools/perf/arch/x86/util/evlist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)tools/perf/arch/x86/util/evlist.c +9
-6@@ -52,7 +52,7 @@ int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)* 3,015,058 cycles * <not supported> topdown-retiring * -* if slots event and topdown metrics events are in two groups, the group which +* If slots event and topdown metrics events are in two groups, the group which * has topdown metrics events must contain only the topdown metrics event, * otherwise topdown metrics event can't be regrouped correctly as well, e.g. * @@ -69,13 +69,16 @@ int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs)return -1 ;if (arch_is_topdown_slots (rhs))return 1 ; -/* Followed by topdown events. */ -if (arch_is_topdown_metrics (lhs) && !arch_is_topdown_metrics (rhs)) -return -1 ; +/* -* Move topdown events forward only when topdown events -* are not in same group with previous event. +* Move topdown metrics events forward only when topdown metrics +* events are not in same group with previous slots event. If +* topdown metrics events are already in same group with slots +* event, do nothing. */ +if (arch_is_topdown_metrics (lhs) && !arch_is_topdown_metrics (rhs) && + lhs->core.leader != rhs->core.leader) +return -1 ;if (!arch_is_topdown_metrics (lhs) &&arch_is_topdown_metrics (rhs) && lhs->core.leader != rhs->core.leader)return 1 ;base-commit:
57fb40d40f9543213ffadb04d07cfb2ba46edc26--
2.40.1
Quoted 10 lines · Dapeng Mi
The commit "
3b5edc0421e2(perf x86/topdown: Don't move topdown metric
events in group)" modifies topdown metrics comparator to move topdown
metrics events which are not in same group with previous event. But it just modifies the 2nd comparator and causes the comparators become asymmetric.Thus modify the 1st topdown metrics comparator and make the two comparators be symmetric, and refine the comments as well.
[...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung