2020-03-17 19:02:16 +08:00
// SPDX-License-Identifier: GPL-2.0
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
# include "math.h"
2020-03-17 19:02:16 +08:00
# include "parse-events.h"
# include "pmu.h"
# include "tests.h"
# include <errno.h>
# include <stdio.h>
# include <linux/kernel.h>
2020-03-17 19:02:19 +08:00
# include <linux/zalloc.h>
2020-03-17 19:02:16 +08:00
# include "debug.h"
# include "../pmu-events/pmu-events.h"
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
# include "util/evlist.h"
# include "util/expr.h"
# include "util/parse-events.h"
2021-04-07 18:32:46 +08:00
# include "metricgroup.h"
2020-03-17 19:02:16 +08:00
struct perf_pmu_test_event {
2020-10-22 19:02:27 +08:00
/* used for matching against events from generated pmu-events.c */
2020-03-17 19:02:16 +08:00
struct pmu_event event ;
2020-03-17 19:02:19 +08:00
2020-10-22 19:02:27 +08:00
/* used for matching against event aliases */
2020-03-17 19:02:19 +08:00
/* extra events for aliases */
const char * alias_str ;
/*
* Note : For when PublicDescription does not exist in the JSON , we
* will have no long_desc in pmu_event . long_desc , but long_desc may
* be set in the alias .
*/
const char * alias_long_desc ;
2021-07-29 21:56:22 +08:00
/* PMU which we should match against */
const char * matching_pmu ;
} ;
struct perf_pmu_test_pmu {
struct perf_pmu pmu ;
struct perf_pmu_test_event const * aliases [ 10 ] ;
2020-03-17 19:02:16 +08:00
} ;
2020-03-17 19:02:19 +08:00
2021-07-29 21:56:18 +08:00
static const struct perf_pmu_test_event bp_l1_btb_correct = {
. event = {
. name = " bp_l1_btb_correct " ,
. event = " event=0x8a " ,
. desc = " L1 BTB Correction " ,
. topic = " branch " ,
2020-03-17 19:02:16 +08:00
} ,
2021-07-29 21:56:18 +08:00
. alias_str = " event=0x8a " ,
. alias_long_desc = " L1 BTB Correction " ,
} ;
static const struct perf_pmu_test_event bp_l2_btb_correct = {
. event = {
. name = " bp_l2_btb_correct " ,
. event = " event=0x8b " ,
. desc = " L2 BTB Correction " ,
. topic = " branch " ,
2020-03-17 19:02:16 +08:00
} ,
2021-07-29 21:56:18 +08:00
. alias_str = " event=0x8b " ,
. alias_long_desc = " L2 BTB Correction " ,
} ;
static const struct perf_pmu_test_event segment_reg_loads_any = {
. event = {
. name = " segment_reg_loads.any " ,
. event = " umask=0x80,period=200000,event=0x6 " ,
. desc = " Number of segment register loads " ,
. topic = " other " ,
2020-03-17 19:02:16 +08:00
} ,
2021-09-16 20:34:21 +08:00
. alias_str = " umask=0x80,period=0x30d40,event=0x6 " ,
2021-07-29 21:56:18 +08:00
. alias_long_desc = " Number of segment register loads " ,
} ;
static const struct perf_pmu_test_event dispatch_blocked_any = {
. event = {
. name = " dispatch_blocked.any " ,
. event = " umask=0x20,period=200000,event=0x9 " ,
. desc = " Memory cluster signals to block micro-op dispatch for any reason " ,
. topic = " other " ,
2020-03-17 19:02:16 +08:00
} ,
2021-09-16 20:34:21 +08:00
. alias_str = " umask=0x20,period=0x30d40,event=0x9 " ,
2021-07-29 21:56:18 +08:00
. alias_long_desc = " Memory cluster signals to block micro-op dispatch for any reason " ,
} ;
static const struct perf_pmu_test_event eist_trans = {
. event = {
. name = " eist_trans " ,
. event = " umask=0x0,period=200000,event=0x3a " ,
. desc = " Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions " ,
. topic = " other " ,
2020-10-22 19:02:27 +08:00
} ,
2021-09-16 20:34:21 +08:00
. alias_str = " umask=0,period=0x30d40,event=0x3a " ,
2021-07-29 21:56:18 +08:00
. alias_long_desc = " Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions " ,
} ;
static const struct perf_pmu_test_event l3_cache_rd = {
. event = {
. name = " l3_cache_rd " ,
. event = " event=0x40 " ,
. desc = " L3 cache access, read " ,
. long_desc = " Attributable Level 3 cache access, read " ,
. topic = " cache " ,
2020-03-17 19:02:16 +08:00
} ,
2021-07-29 21:56:18 +08:00
. alias_str = " event=0x40 " ,
. alias_long_desc = " Attributable Level 3 cache access, read " ,
2020-03-17 19:02:16 +08:00
} ;
2021-07-29 21:56:18 +08:00
static const struct perf_pmu_test_event * core_events [ ] = {
& bp_l1_btb_correct ,
& bp_l2_btb_correct ,
& segment_reg_loads_any ,
& dispatch_blocked_any ,
& eist_trans ,
& l3_cache_rd ,
NULL
} ;
static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = {
. event = {
. name = " uncore_hisi_ddrc.flux_wcmd " ,
. event = " event=0x2 " ,
. desc = " DDRC write commands. Unit: hisi_sccl,ddrc " ,
. topic = " uncore " ,
. long_desc = " DDRC write commands " ,
. pmu = " hisi_sccl,ddrc " ,
2020-03-17 19:02:16 +08:00
} ,
2021-07-29 21:56:18 +08:00
. alias_str = " event=0x2 " ,
. alias_long_desc = " DDRC write commands " ,
2021-07-29 21:56:22 +08:00
. matching_pmu = " hisi_sccl1_ddrc2 " ,
2021-07-29 21:56:18 +08:00
} ;
static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = {
. event = {
. name = " unc_cbo_xsnp_response.miss_eviction " ,
. event = " umask=0x81,event=0x22 " ,
. desc = " Unit: uncore_cbox A cross-core snoop resulted from L3 Eviction which misses in some processor core " ,
. topic = " uncore " ,
. long_desc = " A cross-core snoop resulted from L3 Eviction which misses in some processor core " ,
. pmu = " uncore_cbox " ,
2020-03-17 19:02:16 +08:00
} ,
2021-07-29 21:56:18 +08:00
. alias_str = " umask=0x81,event=0x22 " ,
. alias_long_desc = " A cross-core snoop resulted from L3 Eviction which misses in some processor core " ,
2021-07-29 21:56:22 +08:00
. matching_pmu = " uncore_cbox_0 " ,
2020-03-17 19:02:16 +08:00
} ;
2021-07-29 21:56:23 +08:00
static const struct perf_pmu_test_event uncore_hisi_l3c_rd_hit_cpipe = {
. event = {
. name = " uncore_hisi_l3c.rd_hit_cpipe " ,
2021-09-16 20:34:23 +08:00
. event = " event=0x7 " ,
2021-07-29 21:56:23 +08:00
. desc = " Total read hits. Unit: hisi_sccl,l3c " ,
. topic = " uncore " ,
. long_desc = " Total read hits " ,
. pmu = " hisi_sccl,l3c " ,
} ,
. alias_str = " event=0x7 " ,
. alias_long_desc = " Total read hits " ,
. matching_pmu = " hisi_sccl3_l3c7 " ,
} ;
static const struct perf_pmu_test_event uncore_imc_free_running_cache_miss = {
. event = {
. name = " uncore_imc_free_running.cache_miss " ,
. event = " event=0x12 " ,
. desc = " Total cache misses. Unit: uncore_imc_free_running " ,
. topic = " uncore " ,
. long_desc = " Total cache misses " ,
. pmu = " uncore_imc_free_running " ,
} ,
. alias_str = " event=0x12 " ,
. alias_long_desc = " Total cache misses " ,
. matching_pmu = " uncore_imc_free_running_0 " ,
} ;
static const struct perf_pmu_test_event uncore_imc_cache_hits = {
. event = {
. name = " uncore_imc.cache_hits " ,
. event = " event=0x34 " ,
. desc = " Total cache hits. Unit: uncore_imc " ,
. topic = " uncore " ,
. long_desc = " Total cache hits " ,
. pmu = " uncore_imc " ,
} ,
. alias_str = " event=0x34 " ,
. alias_long_desc = " Total cache hits " ,
. matching_pmu = " uncore_imc_0 " ,
} ;
2021-07-29 21:56:18 +08:00
static const struct perf_pmu_test_event * uncore_events [ ] = {
& uncore_hisi_ddrc_flux_wcmd ,
& unc_cbo_xsnp_response_miss_eviction ,
2021-07-29 21:56:23 +08:00
& uncore_hisi_l3c_rd_hit_cpipe ,
& uncore_imc_free_running_cache_miss ,
& uncore_imc_cache_hits ,
2021-07-29 21:56:18 +08:00
NULL
} ;
2020-03-17 19:02:16 +08:00
2021-07-29 21:56:26 +08:00
static const struct perf_pmu_test_event sys_ddr_pmu_write_cycles = {
. event = {
. name = " sys_ddr_pmu.write_cycles " ,
. event = " event=0x2b " ,
. desc = " ddr write-cycles event. Unit: uncore_sys_ddr_pmu " ,
. topic = " uncore " ,
. pmu = " uncore_sys_ddr_pmu " ,
. compat = " v8 " ,
} ,
. alias_str = " event=0x2b " ,
. alias_long_desc = " ddr write-cycles event. Unit: uncore_sys_ddr_pmu " ,
. matching_pmu = " uncore_sys_ddr_pmu " ,
} ;
2021-09-16 20:34:24 +08:00
static const struct perf_pmu_test_event sys_ccn_pmu_read_cycles = {
. event = {
. name = " sys_ccn_pmu.read_cycles " ,
. event = " config=0x2c " ,
. desc = " ccn read-cycles event. Unit: uncore_sys_ccn_pmu " ,
. topic = " uncore " ,
. pmu = " uncore_sys_ccn_pmu " ,
. compat = " 0x01 " ,
} ,
. alias_str = " config=0x2c " ,
. alias_long_desc = " ccn read-cycles event. Unit: uncore_sys_ccn_pmu " ,
. matching_pmu = " uncore_sys_ccn_pmu " ,
} ;
2021-07-29 21:56:26 +08:00
static const struct perf_pmu_test_event * sys_events [ ] = {
& sys_ddr_pmu_write_cycles ,
2021-09-16 20:34:24 +08:00
& sys_ccn_pmu_read_cycles ,
2021-07-29 21:56:26 +08:00
NULL
} ;
2020-03-17 19:02:16 +08:00
static bool is_same ( const char * reference , const char * test )
{
if ( ! reference & & ! test )
return true ;
if ( reference & & ! test )
return false ;
if ( ! reference & & test )
return false ;
return ! strcmp ( reference , test ) ;
}
static struct pmu_events_map * __test_pmu_get_events_map ( void )
{
struct pmu_events_map * map ;
for ( map = & pmu_events_map [ 0 ] ; map - > cpuid ; map + + ) {
if ( ! strcmp ( map - > cpuid , " testcpu " ) )
return map ;
}
pr_err ( " could not find test events map \n " ) ;
return NULL ;
}
2021-07-29 21:56:26 +08:00
static struct pmu_event * __test_pmu_get_sys_events_table ( void )
{
struct pmu_sys_events * tables = & pmu_sys_event_tables [ 0 ] ;
for ( ; tables - > name ; tables + + ) {
if ( ! strcmp ( " pme_test_soc_sys " , tables - > name ) )
return tables - > table ;
}
return NULL ;
}
2021-07-29 21:56:16 +08:00
static int compare_pmu_events ( struct pmu_event * e1 , const struct pmu_event * e2 )
{
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > name , e2 - > name ) ) {
pr_debug2 ( " testing event e1 %s: mismatched name string, %s vs %s \n " ,
e1 - > name , e1 - > name , e2 - > name ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > compat , e2 - > compat ) ) {
pr_debug2 ( " testing event e1 %s: mismatched compat string, %s vs %s \n " ,
e1 - > name , e1 - > compat , e2 - > compat ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > event , e2 - > event ) ) {
pr_debug2 ( " testing event e1 %s: mismatched event, %s vs %s \n " ,
e1 - > name , e1 - > event , e2 - > event ) ;
return - 1 ;
}
2021-07-29 21:56:16 +08:00
if ( ! is_same ( e1 - > desc , e2 - > desc ) ) {
pr_debug2 ( " testing event e1 %s: mismatched desc, %s vs %s \n " ,
e1 - > name , e1 - > desc , e2 - > desc ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > topic , e2 - > topic ) ) {
pr_debug2 ( " testing event e1 %s: mismatched topic, %s vs %s \n " ,
e1 - > name , e1 - > topic , e2 - > topic ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > long_desc , e2 - > long_desc ) ) {
pr_debug2 ( " testing event e1 %s: mismatched long_desc, %s vs %s \n " ,
e1 - > name , e1 - > long_desc , e2 - > long_desc ) ;
return - 1 ;
}
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > pmu , e2 - > pmu ) ) {
pr_debug2 ( " testing event e1 %s: mismatched pmu string, %s vs %s \n " ,
e1 - > name , e1 - > pmu , e2 - > pmu ) ;
return - 1 ;
}
2021-07-29 21:56:16 +08:00
if ( ! is_same ( e1 - > unit , e2 - > unit ) ) {
pr_debug2 ( " testing event e1 %s: mismatched unit, %s vs %s \n " ,
e1 - > name , e1 - > unit , e2 - > unit ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > perpkg , e2 - > perpkg ) ) {
pr_debug2 ( " testing event e1 %s: mismatched perpkg, %s vs %s \n " ,
e1 - > name , e1 - > perpkg , e2 - > perpkg ) ;
return - 1 ;
}
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > aggr_mode , e2 - > aggr_mode ) ) {
pr_debug2 ( " testing event e1 %s: mismatched aggr_mode, %s vs %s \n " ,
e1 - > name , e1 - > aggr_mode , e2 - > aggr_mode ) ;
return - 1 ;
}
2021-07-29 21:56:16 +08:00
if ( ! is_same ( e1 - > metric_expr , e2 - > metric_expr ) ) {
pr_debug2 ( " testing event e1 %s: mismatched metric_expr, %s vs %s \n " ,
e1 - > name , e1 - > metric_expr , e2 - > metric_expr ) ;
return - 1 ;
}
if ( ! is_same ( e1 - > metric_name , e2 - > metric_name ) ) {
pr_debug2 ( " testing event e1 %s: mismatched metric_name, %s vs %s \n " ,
e1 - > name , e1 - > metric_name , e2 - > metric_name ) ;
return - 1 ;
}
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > metric_group , e2 - > metric_group ) ) {
pr_debug2 ( " testing event e1 %s: mismatched metric_group, %s vs %s \n " ,
e1 - > name , e1 - > metric_group , e2 - > metric_group ) ;
2021-07-29 21:56:16 +08:00
return - 1 ;
}
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > deprecated , e2 - > deprecated ) ) {
pr_debug2 ( " testing event e1 %s: mismatched deprecated, %s vs %s \n " ,
e1 - > name , e1 - > deprecated , e2 - > deprecated ) ;
2021-07-29 21:56:16 +08:00
return - 1 ;
}
2021-09-16 20:34:23 +08:00
if ( ! is_same ( e1 - > metric_constraint , e2 - > metric_constraint ) ) {
pr_debug2 ( " testing event e1 %s: mismatched metric_constant, %s vs %s \n " ,
e1 - > name , e1 - > metric_constraint , e2 - > metric_constraint ) ;
2021-07-29 21:56:16 +08:00
return - 1 ;
}
return 0 ;
}
2021-07-29 21:56:19 +08:00
static int compare_alias_to_test_event ( struct perf_pmu_alias * alias ,
struct perf_pmu_test_event const * test_event ,
char const * pmu_name )
{
struct pmu_event const * event = & test_event - > event ;
/* An alias was found, ensure everything is in order */
if ( ! is_same ( alias - > name , event - > name ) ) {
pr_debug ( " testing aliases PMU %s: mismatched name, %s vs %s \n " ,
pmu_name , alias - > name , event - > name ) ;
return - 1 ;
}
if ( ! is_same ( alias - > desc , event - > desc ) ) {
pr_debug ( " testing aliases PMU %s: mismatched desc, %s vs %s \n " ,
pmu_name , alias - > desc , event - > desc ) ;
return - 1 ;
}
if ( ! is_same ( alias - > long_desc , test_event - > alias_long_desc ) ) {
pr_debug ( " testing aliases PMU %s: mismatched long_desc, %s vs %s \n " ,
pmu_name , alias - > long_desc ,
test_event - > alias_long_desc ) ;
return - 1 ;
}
if ( ! is_same ( alias - > topic , event - > topic ) ) {
pr_debug ( " testing aliases PMU %s: mismatched topic, %s vs %s \n " ,
pmu_name , alias - > topic , event - > topic ) ;
return - 1 ;
}
if ( ! is_same ( alias - > str , test_event - > alias_str ) ) {
pr_debug ( " testing aliases PMU %s: mismatched str, %s vs %s \n " ,
pmu_name , alias - > str , test_event - > alias_str ) ;
return - 1 ;
}
if ( ! is_same ( alias - > long_desc , test_event - > alias_long_desc ) ) {
pr_debug ( " testing aliases PMU %s: mismatched long desc, %s vs %s \n " ,
pmu_name , alias - > str , test_event - > alias_long_desc ) ;
return - 1 ;
}
if ( ! is_same ( alias - > pmu_name , test_event - > event . pmu ) ) {
pr_debug ( " testing aliases PMU %s: mismatched pmu_name, %s vs %s \n " ,
pmu_name , alias - > pmu_name , test_event - > event . pmu ) ;
return - 1 ;
}
return 0 ;
}
2021-07-29 21:56:18 +08:00
/* Verify generated events from pmu-events.c are as expected */
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static int test_pmu_event_table ( void )
2020-03-17 19:02:16 +08:00
{
2021-07-29 21:56:26 +08:00
struct pmu_event * sys_event_tables = __test_pmu_get_sys_events_table ( ) ;
2020-03-17 19:02:16 +08:00
struct pmu_events_map * map = __test_pmu_get_events_map ( ) ;
struct pmu_event * table ;
int map_events = 0 , expected_events ;
2021-07-29 21:56:26 +08:00
/* ignore 3x sentinels */
2021-07-29 21:56:18 +08:00
expected_events = ARRAY_SIZE ( core_events ) +
2021-07-29 21:56:26 +08:00
ARRAY_SIZE ( uncore_events ) +
ARRAY_SIZE ( sys_events ) - 3 ;
2020-03-17 19:02:16 +08:00
2021-07-29 21:56:26 +08:00
if ( ! map | | ! sys_event_tables )
2020-03-17 19:02:16 +08:00
return - 1 ;
for ( table = map - > table ; table - > name ; table + + ) {
2021-07-29 21:56:18 +08:00
struct perf_pmu_test_event const * * test_event_table ;
2020-03-17 19:02:16 +08:00
bool found = false ;
if ( table - > pmu )
2021-07-29 21:56:18 +08:00
test_event_table = & uncore_events [ 0 ] ;
2020-03-17 19:02:16 +08:00
else
2021-07-29 21:56:18 +08:00
test_event_table = & core_events [ 0 ] ;
2020-03-17 19:02:16 +08:00
2021-07-29 21:56:18 +08:00
for ( ; * test_event_table ; test_event_table + + ) {
struct perf_pmu_test_event const * test_event = * test_event_table ;
struct pmu_event const * event = & test_event - > event ;
2020-03-17 19:02:16 +08:00
2021-07-29 21:56:18 +08:00
if ( strcmp ( table - > name , event - > name ) )
2020-03-17 19:02:16 +08:00
continue ;
found = true ;
map_events + + ;
2021-07-29 21:56:18 +08:00
if ( compare_pmu_events ( table , event ) )
2020-03-17 19:02:16 +08:00
return - 1 ;
pr_debug ( " testing event table %s: pass \n " , table - > name ) ;
}
if ( ! found ) {
pr_err ( " testing event table: could not find event %s \n " ,
table - > name ) ;
return - 1 ;
}
}
2021-07-29 21:56:26 +08:00
for ( table = sys_event_tables ; table - > name ; table + + ) {
struct perf_pmu_test_event const * * test_event_table ;
bool found = false ;
test_event_table = & sys_events [ 0 ] ;
for ( ; * test_event_table ; test_event_table + + ) {
struct perf_pmu_test_event const * test_event = * test_event_table ;
struct pmu_event const * event = & test_event - > event ;
if ( strcmp ( table - > name , event - > name ) )
continue ;
found = true ;
map_events + + ;
if ( compare_pmu_events ( table , event ) )
return - 1 ;
pr_debug ( " testing sys event table %s: pass \n " , table - > name ) ;
}
if ( ! found ) {
pr_debug ( " testing event table: could not find event %s \n " ,
table - > name ) ;
return - 1 ;
}
}
2020-03-17 19:02:16 +08:00
if ( map_events ! = expected_events ) {
pr_err ( " testing event table: found %d, but expected %d \n " ,
map_events , expected_events ) ;
return - 1 ;
}
return 0 ;
}
2020-03-17 19:02:19 +08:00
static struct perf_pmu_alias * find_alias ( const char * test_event , struct list_head * aliases )
{
struct perf_pmu_alias * alias ;
list_for_each_entry ( alias , aliases , list )
if ( ! strcmp ( test_event , alias - > name ) )
return alias ;
return NULL ;
}
/* Verify aliases are as expected */
2021-07-29 21:56:20 +08:00
static int __test_core_pmu_event_aliases ( char * pmu_name , int * count )
2020-03-17 19:02:19 +08:00
{
2021-07-29 21:56:18 +08:00
struct perf_pmu_test_event const * * test_event_table ;
2020-03-17 19:02:19 +08:00
struct perf_pmu * pmu ;
LIST_HEAD ( aliases ) ;
int res = 0 ;
struct pmu_events_map * map = __test_pmu_get_events_map ( ) ;
2020-09-15 12:18:18 +09:00
struct perf_pmu_alias * a , * tmp ;
2020-03-17 19:02:19 +08:00
if ( ! map )
return - 1 ;
2021-07-29 21:56:20 +08:00
test_event_table = & core_events [ 0 ] ;
2020-03-17 19:02:19 +08:00
pmu = zalloc ( sizeof ( * pmu ) ) ;
if ( ! pmu )
return - 1 ;
pmu - > name = pmu_name ;
pmu_add_cpu_aliases_map ( & aliases , pmu , map ) ;
2021-07-29 21:56:18 +08:00
for ( ; * test_event_table ; test_event_table + + ) {
struct perf_pmu_test_event const * test_event = * test_event_table ;
struct pmu_event const * event = & test_event - > event ;
struct perf_pmu_alias * alias = find_alias ( event - > name , & aliases ) ;
2020-03-17 19:02:19 +08:00
if ( ! alias ) {
2021-07-29 21:56:20 +08:00
pr_debug ( " testing aliases core PMU %s: no alias, alias_table->name=%s \n " ,
2021-07-29 21:56:18 +08:00
pmu_name , event - > name ) ;
2020-03-17 19:02:19 +08:00
res = - 1 ;
break ;
}
2021-07-29 21:56:19 +08:00
if ( compare_alias_to_test_event ( alias , test_event , pmu_name ) ) {
2020-03-17 19:02:19 +08:00
res = - 1 ;
break ;
}
( * count ) + + ;
2021-07-29 21:56:20 +08:00
pr_debug2 ( " testing aliases core PMU %s: matched event %s \n " ,
2020-03-17 19:02:19 +08:00
pmu_name , alias - > name ) ;
}
2020-09-15 12:18:18 +09:00
list_for_each_entry_safe ( a , tmp , & aliases , list ) {
list_del ( & a - > list ) ;
perf_pmu_free_alias ( a ) ;
}
2020-03-17 19:02:19 +08:00
free ( pmu ) ;
return res ;
}
2021-07-29 21:56:22 +08:00
static int __test_uncore_pmu_event_aliases ( struct perf_pmu_test_pmu * test_pmu )
{
int alias_count = 0 , to_match_count = 0 , matched_count = 0 ;
struct perf_pmu_test_event const * * table ;
struct perf_pmu * pmu = & test_pmu - > pmu ;
const char * pmu_name = pmu - > name ;
struct perf_pmu_alias * a , * tmp , * alias ;
struct pmu_events_map * map ;
LIST_HEAD ( aliases ) ;
int res = 0 ;
map = __test_pmu_get_events_map ( ) ;
if ( ! map )
return - 1 ;
pmu_add_cpu_aliases_map ( & aliases , pmu , map ) ;
2021-07-29 21:56:26 +08:00
pmu_add_sys_aliases ( & aliases , pmu ) ;
2021-07-29 21:56:22 +08:00
/* Count how many aliases we generated */
list_for_each_entry ( alias , & aliases , list )
alias_count + + ;
/* Count how many aliases we expect from the known table */
for ( table = & test_pmu - > aliases [ 0 ] ; * table ; table + + )
to_match_count + + ;
if ( alias_count ! = to_match_count ) {
pr_debug ( " testing aliases uncore PMU %s: mismatch expected aliases (%d) vs found (%d) \n " ,
pmu_name , to_match_count , alias_count ) ;
res = - 1 ;
goto out ;
}
list_for_each_entry ( alias , & aliases , list ) {
bool matched = false ;
for ( table = & test_pmu - > aliases [ 0 ] ; * table ; table + + ) {
struct perf_pmu_test_event const * test_event = * table ;
struct pmu_event const * event = & test_event - > event ;
if ( ! strcmp ( event - > name , alias - > name ) ) {
if ( compare_alias_to_test_event ( alias ,
test_event ,
pmu_name ) ) {
continue ;
}
matched = true ;
matched_count + + ;
}
}
if ( matched = = false ) {
pr_debug ( " testing aliases uncore PMU %s: could not match alias %s \n " ,
pmu_name , alias - > name ) ;
res = - 1 ;
goto out ;
}
}
if ( alias_count ! = matched_count ) {
pr_debug ( " testing aliases uncore PMU %s: mismatch found aliases (%d) vs matched (%d) \n " ,
pmu_name , matched_count , alias_count ) ;
res = - 1 ;
}
out :
list_for_each_entry_safe ( a , tmp , & aliases , list ) {
list_del ( & a - > list ) ;
perf_pmu_free_alias ( a ) ;
}
return res ;
}
static struct perf_pmu_test_pmu test_pmus [ ] = {
{
. pmu = {
. name = ( char * ) " hisi_sccl1_ddrc2 " ,
. is_uncore = 1 ,
} ,
. aliases = {
& uncore_hisi_ddrc_flux_wcmd ,
} ,
} ,
{
. pmu = {
. name = ( char * ) " uncore_cbox_0 " ,
. is_uncore = 1 ,
} ,
. aliases = {
& unc_cbo_xsnp_response_miss_eviction ,
} ,
} ,
2021-07-29 21:56:23 +08:00
{
. pmu = {
. name = ( char * ) " hisi_sccl3_l3c7 " ,
. is_uncore = 1 ,
} ,
. aliases = {
& uncore_hisi_l3c_rd_hit_cpipe ,
} ,
} ,
{
. pmu = {
. name = ( char * ) " uncore_imc_free_running_0 " ,
. is_uncore = 1 ,
} ,
. aliases = {
& uncore_imc_free_running_cache_miss ,
} ,
} ,
{
. pmu = {
. name = ( char * ) " uncore_imc_0 " ,
. is_uncore = 1 ,
} ,
. aliases = {
& uncore_imc_cache_hits ,
} ,
} ,
2021-07-29 21:56:26 +08:00
{
. pmu = {
. name = ( char * ) " uncore_sys_ddr_pmu0 " ,
. is_uncore = 1 ,
. id = ( char * ) " v8 " ,
} ,
. aliases = {
& sys_ddr_pmu_write_cycles ,
} ,
} ,
2021-09-16 20:34:24 +08:00
{
. pmu = {
. name = ( char * ) " uncore_sys_ccn_pmu4 " ,
. is_uncore = 1 ,
. id = ( char * ) " 0x01 " ,
} ,
. aliases = {
& sys_ccn_pmu_read_cycles ,
} ,
} ,
2021-07-29 21:56:22 +08:00
} ;
2020-10-22 19:02:27 +08:00
/* Test that aliases generated are as expected */
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static int test_aliases ( void )
2020-03-17 19:02:16 +08:00
{
2020-03-17 19:02:19 +08:00
struct perf_pmu * pmu = NULL ;
2021-07-29 21:56:22 +08:00
unsigned long i ;
2020-03-17 19:02:19 +08:00
while ( ( pmu = perf_pmu__scan ( pmu ) ) ! = NULL ) {
int count = 0 ;
2021-07-29 21:56:20 +08:00
if ( ! is_pmu_core ( pmu - > name ) )
continue ;
2020-03-17 19:02:19 +08:00
if ( list_empty ( & pmu - > format ) ) {
2021-07-29 21:56:20 +08:00
pr_debug2 ( " skipping testing core PMU %s \n " , pmu - > name ) ;
2020-03-17 19:02:19 +08:00
continue ;
}
2021-07-29 21:56:20 +08:00
if ( __test_core_pmu_event_aliases ( pmu - > name , & count ) ) {
pr_debug ( " testing core PMU %s aliases: failed \n " , pmu - > name ) ;
2020-03-17 19:02:19 +08:00
return - 1 ;
}
2021-07-29 21:56:20 +08:00
if ( count = = 0 ) {
pr_debug ( " testing core PMU %s aliases: no events to match \n " ,
2020-03-17 19:02:19 +08:00
pmu - > name ) ;
2021-07-29 21:56:20 +08:00
return - 1 ;
}
pr_debug ( " testing core PMU %s aliases: pass \n " , pmu - > name ) ;
2020-03-17 19:02:19 +08:00
}
2021-07-29 21:56:22 +08:00
for ( i = 0 ; i < ARRAY_SIZE ( test_pmus ) ; i + + ) {
int res = __test_uncore_pmu_event_aliases ( & test_pmus [ i ] ) ;
if ( res )
return res ;
}
2020-03-17 19:02:16 +08:00
return 0 ;
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static bool is_number ( const char * str )
{
char * end_ptr ;
double v ;
errno = 0 ;
v = strtod ( str , & end_ptr ) ;
( void ) v ; // We're not interested in this value, only if it is valid
return errno = = 0 & & end_ptr ! = str ;
}
2020-06-03 12:51:15 -03:00
static int check_parse_id ( const char * id , struct parse_events_error * error ,
struct perf_pmu * fake_pmu )
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
{
struct evlist * evlist ;
int ret ;
/* Numbers are always valid. */
if ( is_number ( id ) )
return 0 ;
evlist = evlist__new ( ) ;
2020-06-02 23:47:31 +02:00
if ( ! evlist )
return - ENOMEM ;
2020-06-03 12:51:15 -03:00
ret = __parse_events ( evlist , id , error , fake_pmu ) ;
2020-06-02 23:47:31 +02:00
evlist__delete ( evlist ) ;
return ret ;
}
static int check_parse_cpu ( const char * id , bool same_cpu , struct pmu_event * pe )
{
struct parse_events_error error = { . idx = 0 , } ;
2020-06-03 12:51:15 -03:00
int ret = check_parse_id ( id , & error , NULL ) ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
if ( ret & & same_cpu ) {
pr_warning ( " Parse event failed metric '%s' id '%s' expr '%s' \n " ,
pe - > metric_name , id , pe - > metric_expr ) ;
pr_warning ( " Error string '%s' help '%s' \n " , error . str ,
error . help ) ;
} else if ( ret ) {
pr_debug3 ( " Parse event failed, but for an event that may not be supported by this CPU. \n id '%s' metric '%s' expr '%s' \n " ,
id , pe - > metric_name , pe - > metric_expr ) ;
ret = 0 ;
}
free ( error . str ) ;
free ( error . help ) ;
free ( error . first_str ) ;
free ( error . first_help ) ;
return ret ;
}
2020-06-03 12:51:15 -03:00
static int check_parse_fake ( const char * id )
{
struct parse_events_error error = { . idx = 0 , } ;
int ret = check_parse_id ( id , & error , & perf_pmu__fake ) ;
free ( error . str ) ;
free ( error . help ) ;
free ( error . first_str ) ;
free ( error . first_help ) ;
return ret ;
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static void expr_failure ( const char * msg ,
const struct pmu_events_map * map ,
const struct pmu_event * pe )
{
pr_debug ( " %s for map %s %s %s \n " ,
msg , map - > cpuid , map - > version , map - > type ) ;
pr_debug ( " On metric %s \n " , pe - > metric_name ) ;
pr_debug ( " On expression %s \n " , pe - > metric_expr ) ;
}
2021-04-07 18:32:46 +08:00
struct metric {
struct list_head list ;
struct metric_ref metric_ref ;
} ;
static int resolve_metric_simple ( struct expr_parse_ctx * pctx ,
struct list_head * compound_list ,
struct pmu_events_map * map ,
const char * metric_name )
{
struct hashmap_entry * cur , * cur_tmp ;
struct metric * metric , * tmp ;
size_t bkt ;
bool all ;
int rc ;
do {
all = true ;
2021-09-23 00:46:04 -07:00
hashmap__for_each_entry_safe ( pctx - > ids , cur , cur_tmp , bkt ) {
2021-04-07 18:32:46 +08:00
struct metric_ref * ref ;
struct pmu_event * pe ;
pe = metricgroup__find_metric ( cur - > key , map ) ;
if ( ! pe )
continue ;
if ( ! strcmp ( metric_name , ( char * ) cur - > key ) ) {
pr_warning ( " Recursion detected for metric %s \n " , metric_name ) ;
rc = - 1 ;
goto out_err ;
}
all = false ;
/* The metric key itself needs to go out.. */
expr__del_id ( pctx , cur - > key ) ;
metric = malloc ( sizeof ( * metric ) ) ;
if ( ! metric ) {
rc = - ENOMEM ;
goto out_err ;
}
ref = & metric - > metric_ref ;
ref - > metric_name = pe - > metric_name ;
ref - > metric_expr = pe - > metric_expr ;
list_add_tail ( & metric - > list , compound_list ) ;
rc = expr__find_other ( pe - > metric_expr , NULL , pctx , 0 ) ;
if ( rc )
goto out_err ;
break ; /* The hashmap has been modified, so restart */
}
} while ( ! all ) ;
return 0 ;
out_err :
list_for_each_entry_safe ( metric , tmp , compound_list , list )
free ( metric ) ;
return rc ;
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static int test_parsing ( void )
{
2021-04-07 18:32:47 +08:00
struct pmu_events_map * cpus_map = pmu_events_map__find ( ) ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
struct pmu_events_map * map ;
struct pmu_event * pe ;
int i , j , k ;
int ret = 0 ;
2021-09-23 00:46:04 -07:00
struct expr_parse_ctx * ctx ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
double result ;
2021-09-23 00:46:04 -07:00
ctx = expr__ctx_new ( ) ;
if ( ! ctx ) {
pr_debug ( " expr__ctx_new failed " ) ;
return TEST_FAIL ;
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
i = 0 ;
for ( ; ; ) {
map = & pmu_events_map [ i + + ] ;
if ( ! map - > table )
break ;
j = 0 ;
for ( ; ; ) {
2021-04-07 18:32:46 +08:00
struct metric * metric , * tmp ;
2020-05-15 15:17:32 -07:00
struct hashmap_entry * cur ;
2021-04-07 18:32:46 +08:00
LIST_HEAD ( compound_list ) ;
2020-05-15 15:17:32 -07:00
size_t bkt ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
pe = & map - > table [ j + + ] ;
if ( ! pe - > name & & ! pe - > metric_group & & ! pe - > metric_name )
break ;
if ( ! pe - > metric_expr )
continue ;
2021-09-23 00:46:04 -07:00
expr__ctx_clear ( ctx ) ;
if ( expr__find_other ( pe - > metric_expr , NULL , ctx , 0 )
2020-05-15 15:17:32 -07:00
< 0 ) {
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
expr_failure ( " Parse other failed " , map , pe ) ;
ret + + ;
continue ;
}
2021-09-23 00:46:04 -07:00
if ( resolve_metric_simple ( ctx , & compound_list , map ,
2021-04-07 18:32:46 +08:00
pe - > metric_name ) ) {
expr_failure ( " Could not resolve metrics " , map , pe ) ;
ret + + ;
goto exit ; /* Don't tolerate errors due to severity */
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
/*
* Add all ids with a made up value . The value may
* trigger divide by zero when subtracted and so try to
* make them unique .
*/
2020-05-15 15:17:32 -07:00
k = 1 ;
2021-09-23 00:46:04 -07:00
hashmap__for_each_entry ( ctx - > ids , cur , bkt )
expr__add_id_val ( ctx , strdup ( cur - > key ) , k + + ) ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
2021-09-23 00:46:04 -07:00
hashmap__for_each_entry ( ctx - > ids , cur , bkt ) {
2020-06-02 23:47:31 +02:00
if ( check_parse_cpu ( cur - > key , map = = cpus_map ,
2020-05-15 15:17:32 -07:00
pe ) )
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
ret + + ;
}
2021-04-07 18:32:46 +08:00
list_for_each_entry_safe ( metric , tmp , & compound_list , list ) {
2021-09-23 00:46:04 -07:00
expr__add_ref ( ctx , & metric - > metric_ref ) ;
2021-04-07 18:32:46 +08:00
free ( metric ) ;
}
2021-09-23 00:46:04 -07:00
if ( expr__parse ( & result , ctx , pe - > metric_expr , 0 ) ) {
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
expr_failure ( " Parse failed " , map , pe ) ;
ret + + ;
}
}
}
2021-09-23 00:46:04 -07:00
expr__ctx_free ( ctx ) ;
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
/* TODO: fail when not ok */
2021-04-07 18:32:46 +08:00
exit :
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
return ret = = 0 ? TEST_OK : TEST_SKIP ;
}
2020-06-03 12:51:15 -03:00
struct test_metric {
const char * str ;
} ;
static struct test_metric metrics [ ] = {
{ " (unc_p_power_state_occupancy.cores_c0 / unc_p_clockticks) * 100. " } ,
{ " imx8_ddr0@read \\ -cycles@ * 4 * 4 " , } ,
{ " imx8_ddr0@axid \\ -read \\ ,axi_mask \\ =0xffff \\ ,axi_id \\ =0x0000@ * 4 " , } ,
{ " (cstate_pkg@c2 \\ -residency@ / msr@tsc@) * 100 " , } ,
{ " (imx8_ddr0@read \\ -cycles@ + imx8_ddr0@write \\ -cycles@) " , } ,
} ;
static int metric_parse_fake ( const char * str )
{
2021-09-23 00:46:04 -07:00
struct expr_parse_ctx * ctx ;
2020-06-03 12:51:15 -03:00
struct hashmap_entry * cur ;
double result ;
int ret = - 1 ;
size_t bkt ;
int i ;
pr_debug ( " parsing '%s' \n " , str ) ;
2021-09-23 00:46:04 -07:00
ctx = expr__ctx_new ( ) ;
if ( ! ctx ) {
pr_debug ( " expr__ctx_new failed " ) ;
return TEST_FAIL ;
}
if ( expr__find_other ( str , NULL , ctx , 0 ) < 0 ) {
2020-06-03 12:51:15 -03:00
pr_err ( " expr__find_other failed \n " ) ;
return - 1 ;
}
/*
* Add all ids with a made up value . The value may
* trigger divide by zero when subtracted and so try to
* make them unique .
*/
i = 1 ;
2021-09-23 00:46:04 -07:00
hashmap__for_each_entry ( ctx - > ids , cur , bkt )
expr__add_id_val ( ctx , strdup ( cur - > key ) , i + + ) ;
2020-06-03 12:51:15 -03:00
2021-09-23 00:46:04 -07:00
hashmap__for_each_entry ( ctx - > ids , cur , bkt ) {
2020-06-03 12:51:15 -03:00
if ( check_parse_fake ( cur - > key ) ) {
pr_err ( " check_parse_fake failed \n " ) ;
goto out ;
}
}
2021-09-23 00:46:04 -07:00
if ( expr__parse ( & result , ctx , str , 0 ) )
2020-06-03 12:51:15 -03:00
pr_err ( " expr__parse failed \n " ) ;
else
ret = 0 ;
out :
2021-09-23 00:46:04 -07:00
expr__ctx_free ( ctx ) ;
2020-06-03 12:51:15 -03:00
return ret ;
}
/*
* Parse all the metrics for current architecture ,
* or all defined cpus via the ' fake_pmu '
* in parse_events .
*/
static int test_parsing_fake ( void )
{
struct pmu_events_map * map ;
struct pmu_event * pe ;
unsigned int i , j ;
int err = 0 ;
for ( i = 0 ; i < ARRAY_SIZE ( metrics ) ; i + + ) {
err = metric_parse_fake ( metrics [ i ] . str ) ;
if ( err )
return err ;
}
i = 0 ;
for ( ; ; ) {
map = & pmu_events_map [ i + + ] ;
if ( ! map - > table )
break ;
j = 0 ;
for ( ; ; ) {
pe = & map - > table [ j + + ] ;
if ( ! pe - > name & & ! pe - > metric_group & & ! pe - > metric_name )
break ;
if ( ! pe - > metric_expr )
continue ;
err = metric_parse_fake ( pe - > metric_expr ) ;
if ( err )
return err ;
}
}
return 0 ;
}
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
static const struct {
int ( * func ) ( void ) ;
const char * desc ;
} pmu_events_testcase_table [ ] = {
{
. func = test_pmu_event_table ,
. desc = " PMU event table sanity " ,
} ,
{
. func = test_aliases ,
. desc = " PMU event map aliases " ,
} ,
{
. func = test_parsing ,
. desc = " Parsing of PMU event table metrics " ,
} ,
2020-06-03 12:51:15 -03:00
{
. func = test_parsing_fake ,
. desc = " Parsing of PMU event table metrics with fake PMUs " ,
} ,
perf test: Improve pmu event metric testing
Break pmu-events test into 2 and add a test to verify that all pmu
metric expressions simply parse. Try to parse all metric ids/events,
skip/warn if metrics for the current architecture fail to parse. To
support warning for a skip, and an ability for a subtest to describe why
it skips.
Tested on power9, skylakex, haswell, broadwell, westmere, sandybridge and
ivybridge.
May skip/warn on other architectures if metrics are invalid. In
particular s390 is untested, but its expressions are trivial. The
untested architectures with expressions are power8, cascadelakex,
tremontx, skylake, jaketown, ivytown and variants of haswell and
broadwell.
v3. addresses review comments from John Garry <john.garry@huawei.com>,
Jiri Olsa <jolsa@redhat.com> and Arnaldo Carvalho de Melo
<acme@kernel.org>.
v2. changes the commit message as event parsing errors no longer cause
the test to fail.
Committer notes:
Check the return value of strtod() to fix the build in systems where
that function is declared with attribute warn_unused_result.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200513212933.41273-1-irogers@google.com
[ split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-13 14:29:33 -07:00
} ;
const char * test__pmu_events_subtest_get_desc ( int subtest )
{
if ( subtest < 0 | |
subtest > = ( int ) ARRAY_SIZE ( pmu_events_testcase_table ) )
return NULL ;
return pmu_events_testcase_table [ subtest ] . desc ;
}
const char * test__pmu_events_subtest_skip_reason ( int subtest )
{
if ( subtest < 0 | |
subtest > = ( int ) ARRAY_SIZE ( pmu_events_testcase_table ) )
return NULL ;
if ( pmu_events_testcase_table [ subtest ] . func ! = test_parsing )
return NULL ;
return " some metrics failed " ;
}
int test__pmu_events_subtest_get_nr ( void )
{
return ( int ) ARRAY_SIZE ( pmu_events_testcase_table ) ;
}
int test__pmu_events ( struct test * test __maybe_unused , int subtest )
{
if ( subtest < 0 | |
subtest > = ( int ) ARRAY_SIZE ( pmu_events_testcase_table ) )
return TEST_FAIL ;
return pmu_events_testcase_table [ subtest ] . func ( ) ;
}