All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	"Namhyung Kim" <namhyung@kernel.org>,
	kajoljain <kjain@linux.ibm.com>,
	LKML <linux-kernel@vger.kernel.org>, <linuxarm@openeuler.org>,
	Joakim Zhang <qiangqing.zhang@nxp.com>
Subject: Re: [PATCH] perf metricgroup: Fix for metrics containing duration_time
Date: Thu, 21 Jan 2021 17:14:07 +0000	[thread overview]
Message-ID: <4f8d8e1f-c37b-5ba4-7fe4-b46398cf6578@huawei.com> (raw)
In-Reply-To: <CAP-5=fX3C8v02ZbXPGWs1eKrbO5YAddegJuig2B755=Ubd1w1Q@mail.gmail.com>


>      >
>      >
>      > Thanks for this, it should be fairly easy to add a test. Could we
>     do this?
> 
>     I don't mind following up with that.

How about this:

---- >8 ----

 From 38e9d5aa07588d552378d97760b6b79f19d59bbd Mon Sep 17 00:00:00 2001
From: John Garry <john.garry@huawei.com>
Date: Thu, 21 Jan 2021 16:55:17 +0000
Subject: [PATCH] perf test: Add parse-metric memory bandwidth testcase

Event duration_time in a metric expression requires special handling.

Improve test coverage by including a metric whose expression includes
duration_time. The actual metric is copied from the L1D_Cache_Fill_BW
metric on my broadwell machine.

Signed-off-by: John Garry <john.garry@huawei.com>

diff --git a/tools/perf/tests/parse-metric.c 
b/tools/perf/tests/parse-metric.c
index ce7be37f0d88..98b9570c6194 100644
--- a/tools/perf/tests/parse-metric.c
+++ b/tools/perf/tests/parse-metric.c
@@ -11,6 +11,7 @@
  #include "debug.h"
  #include "expr.h"
  #include "stat.h"
+#include <math.h>

  static struct pmu_event pme_test[] = {
  {
@@ -69,6 +70,10 @@ static struct pmu_event pme_test[] = {
  	.metric_expr	= "1/m3",
  	.metric_name	= "M3",
  },
+{
+	.metric_expr	= "64 * l1d.replacement / 1000000000 / duration_time",
+	.metric_name	= "L1D_Cache_Fill_BW",
+},
  {
  	.name	= NULL,
  }
@@ -107,6 +112,8 @@ static void load_runtime_stat(struct runtime_stat 
*st, struct evlist *evlist,
  	evlist__for_each_entry(evlist, evsel) {
  		count = find_value(evsel->name, vals);
  		perf_stat__update_shadow_stats(evsel, count, 0, st);
+		if (!strcmp(evsel->name, "duration_time"))
+			update_stats(&walltime_nsecs_stats, count);
  	}
  }

@@ -321,6 +328,24 @@ static int test_recursion_fail(void)
  	return 0;
  }

+static int test_memory_bandwidth(void)
+{
+	double ratio;
+	struct value vals[] = {
+		{ .event = "l1d.replacement", .val = 304334545 },
+		{ .event = "duration_time",  .val = 1001057587 },
+		{ .event = NULL, },
+	};
+
+	TEST_ASSERT_VAL("failed to compute metric",
+			compute_metric("L1D_Cache_Fill_BW", vals, &ratio) == 0);
+
+	TEST_ASSERT_VAL("L1D_Cache_Fill_BW, wrong ratio",
+			fabs(ratio - 19.45) < 0.01);
+
+	return 0;
+}
+
  static int test_metric_group(void)
  {
  	double ratio1, ratio2;
@@ -353,5 +378,6 @@ int test__parse_metric(struct test *test 
__maybe_unused, int subtest __maybe_unu
  	TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() == 0);
  	TEST_ASSERT_VAL("recursion fail failed", test_recursion_fail() == 0);
  	TEST_ASSERT_VAL("test metric group", test_metric_group() == 0);
+	TEST_ASSERT_VAL("Memory bandwidth", test_memory_bandwidth() == 0);
  	return 0;
  }
-- 
2.26.2

Cheers,
John

  parent reply	other threads:[~2021-01-21 17:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 16:18 [PATCH] perf metricgroup: Fix for metrics containing duration_time John Garry
     [not found] ` <CAP-5=fVr0pFpqpev0DW6MMYB1VouH4rL0_wY3_OsbQLS=deJag@mail.gmail.com>
2021-01-20 17:08   ` John Garry
     [not found]     ` <CAP-5=fX3C8v02ZbXPGWs1eKrbO5YAddegJuig2B755=Ubd1w1Q@mail.gmail.com>
2021-01-21 17:14       ` John Garry [this message]
2021-01-20 21:35 ` Jiri Olsa
2021-01-21 20:02   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f8d8e1f-c37b-5ba4-7fe4-b46398cf6578@huawei.com \
    --to=john.garry@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=kjain@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@openeuler.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qiangqing.zhang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.