perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu
Ian Rogers
reviewerv5 cover perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu
The mrvl_ddr_pmu is uncore and has a hexadecimal address suffix. Current PMU sorting/merging code assumes uncore PMU names start with uncore_ and have a decimal suffix. Add support for hexadecimal suffixes and add tests.
v5. In pmus.h remove needless addition of #include list.h but add
stddef.h for size_t.
v4. Workaround GCC build error by using unsigned types. Don't consider
short hex suffixes as suffixes (e.g. cpum_cf) and test this behavior.
v3. Rebase and move tests from pmus.c to the existing pmu.c.
Ian Rogers (2):
perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu perf tests: Add some pmu core functionality tests
tools/perf/tests/pmu.c | 99 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.c | 17 ++++---- tools/perf/util/pmus.c | 67 ++++++++++++++++------------ tools/perf/util/pmus.h | 7 ++- 4 files changed, 152 insertions(+), 38 deletions(-)
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
Ian Rogers
reviewerPATCH v5 1/2 perf pmus: Sort/merge/aggregate PMUs like mrvl_ddr_pmu
The mrvl_ddr_pmu is uncore and has a hexadecimal address suffix while the previous PMU sorting/merging code assumes uncore PMU names start with uncore_ and have a decimal suffix. Because of the previous assumption it isn't possible to wildcard the mrvl_ddr_pmu.
Modify pmu_name_len_no_suffix but also remove the suffix number out argument, this is because we don't know if a suffix number of say 100 is in hexadecimal or decimal. As the only use of the suffix number is in comparisons, it is safe there to compare the values as hexadecimal.
Only allow hexadecimal suffixes to be greater than length 2 (ie 3 or more) so that S390's cpum_cf PMU doesn't lose its suffix.
Change the return type of pmu_name_len_no_suffix to size_t to workaround GCC incorrectly determining the result could be negative.
--- tools/perf/util/pmu.c | 17 +++++------ tools/perf/util/pmus.c | 67 ++++++++++++++++++++++++------------------ tools/perf/util/pmus.h | 7 ++++- 3 files changed, 53 insertions(+), 38 deletions(-)
tools/perf/util/pmu.c +8 -9
@@ -1788,10 +1788,10 @@ static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, const struct perf_pmu_alias *alias, bool skip_duplicate_pmus) {struct parse_events_term *term; -int pmu_name_len = skip_duplicate_pmus - ?pmu_name_len_no_suffix (pmu->name,/*num=*/ NULL ) - : (int )strlen (pmu->name); -int used =snprintf (buf, len,"%.*s/%s" , pmu_name_len, pmu->name, alias->name); +size_t pmu_name_len = skip_duplicate_pmus + ?pmu_name_len_no_suffix (pmu->name) + :strlen (pmu->name); +int used =snprintf (buf, len,"%.*s/%s" , (int )pmu_name_len, pmu->name, alias->name);list_for_each_entry (term, &alias->terms.terms, list) {if (term->type_val ==PARSE_EVENTS__TERM_TYPE_STR )
@@ -1828,13 +1828,12 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,pmu_aliases_parse (pmu);pmu_add_cpu_aliases (pmu);list_for_each_entry (event, &pmu->aliases, list) { -size_t buf_used; -int pmu_name_len; +size_t buf_used, pmu_name_len; info.pmu_name = event->pmu_name ?: pmu->name; pmu_name_len = skip_duplicate_pmus - ?pmu_name_len_no_suffix (info.pmu_name,/*num=*/ NULL ) - : (int )strlen (info.pmu_name); + ?pmu_name_len_no_suffix (info.pmu_name) + :strlen (info.pmu_name); info.alias =NULL ;if (event->desc) { info.name = event->name;
@@ -1859,7 +1858,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, info.encoding_desc = buf + buf_used;parse_events_terms__to_strbuf (&event->terms, &sb); buf_used +=snprintf (buf + buf_used,sizeof (buf) - buf_used, -"%.*s/%s/" , pmu_name_len, info.pmu_name, sb.buf) +1 ; +"%.*s/%s/" , (int )pmu_name_len, info.pmu_name, sb.buf) +1 ; info.topic = event->topic; info.str = sb.buf; info.deprecated = event->deprecated;
tools/perf/util/pmus.c +39 -28
115 lines not on this page · raw message
tools/perf/util/pmus.h +6 -1
@@ -2,10 +2,15 @@#ifndef __PMUS_H#define __PMUS_H +#include <stdbool.h> +#include <stddef.h> +struct perf_pmu ;struct print_callbacks ; -int pmu_name_len_no_suffix (const char *str,unsigned long *num); +size_t pmu_name_len_no_suffix (const char *str); +/* Exposed for testing only. */ +int pmu_name_cmp (const char *lhs_pmu_name,const char *rhs_pmu_name);void perf_pmus__destroy (void );
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog
Ian Rogers
reviewerPATCH v5 2/2 perf tests: Add some pmu core functionality tests
In reply to Ian RogersTest behavior of PMU names and comparisons wrt suffixes using Intel uncore_cha, marvell mrvl_ddr_pmu and S390's cpum_cf as examples.
--- tools/perf/tests/pmu.c | 99 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
tools/perf/tests/pmu.c +99 -0
@@ -3,6 +3,7 @@#include "evsel.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "tests.h" #include "debug.h" #include "fncache.h"
@@ -340,10 +341,108 @@ static int test__pmu_event_names(struct test_suite *test __maybe_unused,return ret; } +static const char *const uncore_chas[] = { +"uncore_cha_0" , +"uncore_cha_1" , +"uncore_cha_2" , +"uncore_cha_3" , +"uncore_cha_4" , +"uncore_cha_5" , +"uncore_cha_6" , +"uncore_cha_7" , +"uncore_cha_8" , +"uncore_cha_9" , +"uncore_cha_10" , +"uncore_cha_11" , +"uncore_cha_12" , +"uncore_cha_13" , +"uncore_cha_14" , +"uncore_cha_15" , +"uncore_cha_16" , +"uncore_cha_17" , +"uncore_cha_18" , +"uncore_cha_19" , +"uncore_cha_20" , +"uncore_cha_21" , +"uncore_cha_22" , +"uncore_cha_23" , +"uncore_cha_24" , +"uncore_cha_25" , +"uncore_cha_26" , +"uncore_cha_27" , +"uncore_cha_28" , +"uncore_cha_29" , +"uncore_cha_30" , +"uncore_cha_31" , +}; + +static const char *const mrvl_ddrs[] = { +"mrvl_ddr_pmu_87e1b0000000" , +"mrvl_ddr_pmu_87e1b1000000" , +"mrvl_ddr_pmu_87e1b2000000" , +"mrvl_ddr_pmu_87e1b3000000" , +"mrvl_ddr_pmu_87e1b4000000" , +"mrvl_ddr_pmu_87e1b5000000" , +"mrvl_ddr_pmu_87e1b6000000" , +"mrvl_ddr_pmu_87e1b7000000" , +"mrvl_ddr_pmu_87e1b8000000" , +"mrvl_ddr_pmu_87e1b9000000" , +"mrvl_ddr_pmu_87e1ba000000" , +"mrvl_ddr_pmu_87e1bb000000" , +"mrvl_ddr_pmu_87e1bc000000" , +"mrvl_ddr_pmu_87e1bd000000" , +"mrvl_ddr_pmu_87e1be000000" , +"mrvl_ddr_pmu_87e1bf000000" , +}; + +static int test__name_len (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) +{ +TEST_ASSERT_VAL ("cpu" ,pmu_name_len_no_suffix ("cpu" ) ==strlen ("cpu" )); +TEST_ASSERT_VAL ("i915" ,pmu_name_len_no_suffix ("i915" ) ==strlen ("i915" )); +TEST_ASSERT_VAL ("cpum_cf" ,pmu_name_len_no_suffix ("cpum_cf" ) ==strlen ("cpum_cf" )); +for (size_t i =0 ; i <ARRAY_SIZE (uncore_chas); i++) { +TEST_ASSERT_VAL ("Strips uncore_cha suffix" , +pmu_name_len_no_suffix (uncore_chas[i]) == +strlen ("uncore_cha" )); + } +for (size_t i =0 ; i <ARRAY_SIZE (mrvl_ddrs); i++) { +TEST_ASSERT_VAL ("Strips mrvl_ddr_pmu suffix" , +pmu_name_len_no_suffix (mrvl_ddrs[i]) == +strlen ("mrvl_ddr_pmu" )); + } +return TEST_OK ; +} + +static int test__name_cmp (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) +{ +TEST_ASSERT_EQUAL ("cpu" ,pmu_name_cmp ("cpu" ,"cpu" ),0 ); +TEST_ASSERT_EQUAL ("i915" ,pmu_name_cmp ("i915" ,"i915" ),0 ); +TEST_ASSERT_EQUAL ("cpum_cf" ,pmu_name_cmp ("cpum_cf" ,"cpum_cf" ),0 ); +TEST_ASSERT_VAL ("i915" ,pmu_name_cmp ("cpu" ,"i915" ) <0 ); +TEST_ASSERT_VAL ("i915" ,pmu_name_cmp ("i915" ,"cpu" ) >0 ); +TEST_ASSERT_VAL ("cpum_cf" ,pmu_name_cmp ("cpum_cf" ,"cpum_ce" ) >0 ); +TEST_ASSERT_VAL ("cpum_cf" ,pmu_name_cmp ("cpum_cf" ,"cpum_d0" ) <0 ); +for (size_t i =1 ; i <ARRAY_SIZE (uncore_chas); i++) { +TEST_ASSERT_VAL ("uncore_cha suffixes ordered lt" , +pmu_name_cmp (uncore_chas[i-1 ], uncore_chas[i]) <0 ); +TEST_ASSERT_VAL ("uncore_cha suffixes ordered gt" , +pmu_name_cmp (uncore_chas[i], uncore_chas[i-1 ]) >0 ); + } +for (size_t i =1 ; i <ARRAY_SIZE (mrvl_ddrs); i++) { +TEST_ASSERT_VAL ("mrvl_ddr_pmu suffixes ordered lt" , +pmu_name_cmp (mrvl_ddrs[i-1 ], mrvl_ddrs[i]) <0 ); +TEST_ASSERT_VAL ("mrvl_ddr_pmu suffixes ordered gt" , +pmu_name_cmp (mrvl_ddrs[i], mrvl_ddrs[i-1 ]) >0 ); + } +return TEST_OK ; +} +static struct test_case tests__pmu[] = {TEST_CASE ("Parsing with PMU format directory" , pmu_format),TEST_CASE ("Parsing with PMU event" , pmu_events),TEST_CASE ("PMU event names" , pmu_event_names), +TEST_CASE ("PMU name combining" , name_len), +TEST_CASE ("PMU name comparison" , name_cmp), { .name =NULL , } };
Signature · 1 line
2.45.0.rc1.225.g2a3ae87e7f-goog