]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
perf metric: Add DCache_L2 to metric parse test
authorJiri Olsa <jolsa@kernel.org>
Sun, 19 Jul 2020 18:13:15 +0000 (20:13 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 30 Jul 2020 10:01:49 +0000 (07:01 -0300)
Adding test that compute DCache_L2 metrics with other related metrics in it.

Committer notes:

Fixed up this:

  tests/parse-metric.c:285:7: error: missing field 'val' initializer [-Werror,-Wmissing-field-initializers]
                  { 0 },
                      ^

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Michael Petlan <mpetlan@redhat.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/20200719181320.785305-15-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/parse-metric.c

index 47ad3278cf654f027618e18284327425b9d98e50..7a7dea833a6e7501995dfff85a4b7a482ce8f676 100644 (file)
@@ -36,6 +36,27 @@ static struct pmu_event pme_test[] = {
        .metric_expr    = "(dcache_miss_cpi + icache_miss_cycles)",
        .metric_name    = "cache_miss_cycles",
 },
+{
+       .metric_expr    = "l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit",
+       .metric_name    = "DCache_L2_All_Hits",
+},
+{
+       .metric_expr    = "max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + "
+                         "l2_rqsts.pf_miss + l2_rqsts.rfo_miss",
+       .metric_name    = "DCache_L2_All_Miss",
+},
+{
+       .metric_expr    = "dcache_l2_all_hits + dcache_l2_all_miss",
+       .metric_name    = "DCache_L2_All",
+},
+{
+       .metric_expr    = "d_ratio(dcache_l2_all_hits, dcache_l2_all)",
+       .metric_name    = "DCache_L2_Hits",
+},
+{
+       .metric_expr    = "d_ratio(dcache_l2_all_miss, dcache_l2_all)",
+       .metric_name    = "DCache_L2_Misses",
+},
 };
 
 static struct pmu_events_map map = {
@@ -194,10 +215,60 @@ static int test_cache_miss_cycles(void)
        return 0;
 }
 
+
+/*
+ * DCache_L2_All_Hits = l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hi
+ * DCache_L2_All_Miss = max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) +
+ *                      l2_rqsts.pf_miss + l2_rqsts.rfo_miss
+ * DCache_L2_All      = dcache_l2_all_hits + dcache_l2_all_miss
+ * DCache_L2_Hits     = d_ratio(dcache_l2_all_hits, dcache_l2_all)
+ * DCache_L2_Misses   = d_ratio(dcache_l2_all_miss, dcache_l2_all)
+ *
+ * l2_rqsts.demand_data_rd_hit = 100
+ * l2_rqsts.pf_hit             = 200
+ * l2_rqsts.rfo_hi             = 300
+ * l2_rqsts.all_demand_data_rd = 400
+ * l2_rqsts.pf_miss            = 500
+ * l2_rqsts.rfo_miss           = 600
+ *
+ * DCache_L2_All_Hits = 600
+ * DCache_L2_All_Miss = MAX(400 - 100, 0) + 500 + 600 = 1400
+ * DCache_L2_All      = 600 + 1400  = 2000
+ * DCache_L2_Hits     = 600 / 2000  = 0.3
+ * DCache_L2_Misses   = 1400 / 2000 = 0.7
+ */
+static int test_dcache_l2(void)
+{
+       double ratio;
+       struct value vals[] = {
+               { .event = "l2_rqsts.demand_data_rd_hit", .val = 100 },
+               { .event = "l2_rqsts.pf_hit",             .val = 200 },
+               { .event = "l2_rqsts.rfo_hit",            .val = 300 },
+               { .event = "l2_rqsts.all_demand_data_rd", .val = 400 },
+               { .event = "l2_rqsts.pf_miss",            .val = 500 },
+               { .event = "l2_rqsts.rfo_miss",           .val = 600 },
+               { .event = NULL, },
+       };
+
+       TEST_ASSERT_VAL("failed to compute metric",
+                       compute_metric("DCache_L2_Hits", vals, &ratio) == 0);
+
+       TEST_ASSERT_VAL("DCache_L2_Hits failed, wrong ratio",
+                       ratio == 0.3);
+
+       TEST_ASSERT_VAL("failed to compute metric",
+                       compute_metric("DCache_L2_Misses", vals, &ratio) == 0);
+
+       TEST_ASSERT_VAL("DCache_L2_Misses failed, wrong ratio",
+                       ratio == 0.7);
+       return 0;
+}
+
 int test__parse_metric(struct test *test __maybe_unused, int subtest __maybe_unused)
 {
        TEST_ASSERT_VAL("IPC failed", test_ipc() == 0);
        TEST_ASSERT_VAL("frontend failed", test_frontend() == 0);
        TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() == 0);
+       TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() == 0);
        return 0;
 }