mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: 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>,
	Andi Kleen <ak@linux.intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Stephane Eranian <eranian@google.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH] perf test x86: address multiplexing in rdpmc test
Date: Fri, 20 Mar 2020 17:14:00 -0700	[thread overview]
Message-ID: <20200321001400.245121-1-irogers@google.com> (raw)

Counters may be being used for pinned or other events which inhibit the
instruction counter in the test from being scheduled - time_enabled > 0
but time_running == 0. This causes the test to fail with division by 0.
Add a sleep loop to ensure that the counter is run before computing
the count.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/arch/x86/tests/rdpmc.c | 45 ++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c
index 1ea916656a2d..0b0792ae67f7 100644
--- a/tools/perf/arch/x86/tests/rdpmc.c
+++ b/tools/perf/arch/x86/tests/rdpmc.c
@@ -34,19 +34,35 @@ static u64 rdtsc(void)
 	return low | ((u64)high) << 32;
 }
 
-static u64 mmap_read_self(void *addr)
+static u64 mmap_read_self(void *addr, bool *error)
 {
 	struct perf_event_mmap_page *pc = addr;
-	u32 seq, idx, time_mult = 0, time_shift = 0;
+	u32 seq, idx, time_mult = 0, time_shift = 0, sleep_count = 0;
 	u64 count, cyc = 0, time_offset = 0, enabled, running, delta;
 
+	*error = false;
 	do {
-		seq = pc->lock;
-		barrier();
-
-		enabled = pc->time_enabled;
-		running = pc->time_running;
-
+		do {
+			seq = pc->lock;
+			barrier();
+
+			enabled = pc->time_enabled;
+			running = pc->time_running;
+
+			if (running == 0) {
+				/*
+				 * Event hasn't run, this may be caused by
+				 * multiplexing.
+				 */
+				sleep_count++;
+				if (sleep_count > 60) {
+					pr_err("Event failed to run. Are higher priority counters being sampled by a different process?\n");
+					*error = true;
+					return 0;
+				}
+				sleep(1);
+			}
+		} while (running == 0);
 		if (enabled != running) {
 			cyc = rdtsc();
 			time_mult = pc->time_mult;
@@ -131,13 +147,22 @@ static int __test__rdpmc(void)
 
 	for (n = 0; n < 6; n++) {
 		u64 stamp, now, delta;
+		bool error;
 
-		stamp = mmap_read_self(addr);
+		stamp = mmap_read_self(addr, &error);
+		if (error) {
+			delta_sum = 0;
+			goto out_close;
+		}
 
 		for (i = 0; i < loops; i++)
 			tmp++;
 
-		now = mmap_read_self(addr);
+		now = mmap_read_self(addr, &error);
+		if (error) {
+			delta_sum = 0;
+			goto out_close;
+		}
 		loops *= 10;
 
 		delta = now - stamp;
-- 
2.25.1.696.g5e7596f4ac-goog


             reply	other threads:[~2020-03-21  0:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-21  0:14 Ian Rogers [this message]
2020-03-21 13:40 ` Peter Zijlstra
2020-03-21 17:44   ` Ian Rogers
2020-03-22  8:35     ` Peter Zijlstra

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=20200321001400.245121-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®