linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
	linux-kernel@vger.kernel.org, Andi Kleen <andi@firstfloor.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@kernel.org>,
	"Jen-Cheng(Tommy) Huang" <tommy24@gatech.edu>,
	Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 1/9] perf: Remove redundant parent context check from context_equiv
Date: Wed, 10 Sep 2014 16:35:35 +0200	[thread overview]
Message-ID: <20140910143535.GD2409@krava.brq.redhat.com> (raw)
In-Reply-To: <20140910135709.GB4783@worktop.ger.corp.intel.com>

On Wed, Sep 10, 2014 at 03:57:09PM +0200, Peter Zijlstra wrote:
> On Mon, Sep 08, 2014 at 06:45:24PM +0200, Jiri Olsa wrote:
> > 
> > now I need to recall what I used to test this ;-)
> > 
> 
> Hint, if you'd mentioned that in the changelog.... :-)

will try much better this time.. perf test attached ;-)
seems like the child state fix is a good one

jirka


---
>From dc1068c627b332b2a5feb4deedfd96db8e056b5f Mon Sep 17 00:00:00 2001
From: Jiri Olsa <jolsa@redhat.com>
Date: Wed, 10 Sep 2014 16:23:51 +0200
Subject: [PATCH] perf tests: Add test for optimized sched switch bug

---
 tools/perf/Makefile.perf            |    1 +
 tools/perf/tests/builtin-test.c     |    4 +
 tools/perf/tests/optimized_switch.c |  169 +++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h            |    1 +
 4 files changed, 175 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/tests/optimized_switch.c

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index da8fc07..75603ac 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -427,6 +427,7 @@ LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o
 LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o
 LIB_OBJS += $(OUTPUT)tests/switch-tracking.o
 LIB_OBJS += $(OUTPUT)tests/xyarray.o
+LIB_OBJS += $(OUTPUT)tests/optimized_switch.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 5c90326..e092d17 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -162,6 +162,10 @@ static struct test {
 		.func = test__xyarray,
 	},
 	{
+		.desc = "Test optimized switch",
+		.func = test__optimized_switch,
+	},
+	{
 		.func = NULL,
 	},
 };
diff --git a/tools/perf/tests/optimized_switch.c b/tools/perf/tests/optimized_switch.c
new file mode 100644
index 0000000..68f8705
--- /dev/null
+++ b/tools/perf/tests/optimized_switch.c
@@ -0,0 +1,169 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/prctl.h>
+#include <linux/compiler.h>
+#include "tests.h"
+#include "debug.h"
+#include "evsel.h"
+#include "evlist.h"
+#include "thread_map.h"
+
+#define GROUPS	10
+#define WORKERS	10
+#define BYTES	100
+
+struct worker {
+	union {
+		int pipefd[2];
+		struct {
+			int read;
+			int write;
+		} fd;
+	};
+};
+
+#define pr_errsys(s) \
+	pr_err(s " failed: %s\n", strerror(errno))
+
+static void worker(int fd)
+{
+	unsigned char c = 0;
+	int cnt = BYTES;
+	ssize_t r;
+
+	while (cnt--) {
+		r = read(fd, &c, sizeof(c));
+		if (r != 1) {
+			pr_errsys("read");
+			exit(-1);
+		}
+	}
+
+	prctl(0, 0, 0, 0, 0);
+	exit(0);
+}
+
+static void write_round(struct worker *workers)
+{
+	unsigned char c = 0;
+	ssize_t r;
+	int i, j;
+
+	for (j = 0; j < BYTES; j++) {
+		for (i = 0; i < WORKERS; i++) {
+			struct worker *w = &workers[i];
+
+			r = write(w->fd.write, &c, sizeof(c));
+			if (r != 1) {
+				pr_errsys("write");
+				exit(-1);
+			}
+		}
+	}
+}
+
+static int group(void)
+{
+	struct worker workers[WORKERS];
+	int i;
+
+	for (i = 0; i < WORKERS; i++) {
+		struct worker *w = &workers[i];
+		int pid;
+
+		if (pipe(w->pipefd)) {
+			pr_errsys("pipe");
+			return -1;
+		}
+
+		pid = fork();
+		if (pid == -1) {
+			pr_errsys("fork");
+			return -1;
+		} else if (!pid) {
+			worker(w->fd.read);
+		}
+	}
+
+	write_round(workers);
+
+	for (i = 0; i < WORKERS; i++)
+		wait(NULL);
+
+	return 0;
+}
+
+static int child(void)
+{
+	int i;
+
+	for (i = 0; i < GROUPS; i++)
+		TEST_ASSERT_VAL("group failed", !group());
+
+	return 0;
+}
+
+int test__optimized_switch(void)
+{
+	ssize_t r __maybe_unused;
+	unsigned char c = 0;
+	int ready[2], pid;
+	struct thread_map *threads;
+	struct perf_evsel *evsel;
+	u64 total;
+
+	if (pipe(ready)) {
+		pr_errsys("pipe");
+		return -1;
+	}
+
+	pid = fork();
+	if (pid == -1) {
+		pr_errsys("fork");
+		return -1;
+	}
+
+	if (!pid) {
+		r = read(ready[0], &c, sizeof(c));
+		if (r != 1) {
+			pr_errsys("read");
+			exit(-1);
+		}
+
+		exit(child());
+	}
+
+	threads = thread_map__new(-1, pid, UINT_MAX);
+
+	evsel = perf_evsel__newtp("syscalls", "sys_enter_prctl");
+	if (evsel == NULL) {
+		pr_debug("perf_evsel__open_per_thread failed\n");
+		return -1;
+	}
+
+	evsel->attr.inherit = 1;
+
+	if (perf_evsel__open_per_thread(evsel, threads) < 0) {
+		pr_err("perf_evsel__newtp failed\n");
+		return -1;
+	}
+
+	r = write(ready[1], &c, sizeof(c));
+	if (r != 1) {
+		pr_errsys("write");
+		return -1;
+	}
+
+	wait(NULL);
+
+	if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) {
+		pr_err("perf_evsel__read_on_cpu failed\n");
+		return -1;
+	}
+
+	total = evsel->counts->cpu[0].val;
+
+	pr_debug("total count %lu, expected count %d\n", total, GROUPS * WORKERS);
+	TEST_ASSERT_VAL("wrong count", total == GROUPS * WORKERS);
+	return 0;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 8c3e7d1..466184b 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -50,6 +50,7 @@ int test__hists_output(void);
 int test__hists_cumulate(void);
 int test__switch_tracking(void);
 int test__xyarray(void);
+int test__optimized_switch(void);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__arm__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
-- 
1.7.7.6


  reply	other threads:[~2014-09-10 14:36 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-25 14:45 [RFCv2 0/9] perf: Allow leader sampling on inherited events Jiri Olsa
2014-08-25 14:45 ` [PATCH 1/9] perf: Remove redundant parent context check from context_equiv Jiri Olsa
2014-09-02 10:50   ` Peter Zijlstra
2014-09-08  9:43     ` Jiri Olsa
2014-09-08  9:45       ` Peter Zijlstra
2014-09-08  9:48         ` Peter Zijlstra
2014-09-08 10:01           ` Peter Zijlstra
2014-09-08 11:39             ` Peter Zijlstra
2014-09-08 12:19               ` Jiri Olsa
2014-09-08 13:20                 ` Peter Zijlstra
2014-09-08 12:32               ` Jiri Olsa
2014-09-08 12:01             ` Jiri Olsa
2014-09-08 13:34               ` Peter Zijlstra
2014-09-08 15:13                 ` Peter Zijlstra
2014-09-08 16:45                   ` Jiri Olsa
2014-09-09 10:20                     ` Peter Zijlstra
2014-09-10 13:57                     ` Peter Zijlstra
2014-09-10 14:35                       ` Jiri Olsa [this message]
2014-09-24 14:58                         ` [tip:perf/core] Revert "perf: Do not allow optimized switch for non-cloned events" tip-bot for Jiri Olsa
2014-08-25 14:45 ` [PATCH 2/9] perf: Deny optimized switch for events read by PERF_SAMPLE_READ Jiri Olsa
2014-09-02 10:52   ` Peter Zijlstra
2014-09-08 10:00     ` Jiri Olsa
2014-09-08 10:11       ` Peter Zijlstra
2014-09-08 16:39         ` Jiri Olsa
2014-08-25 14:45 ` [PATCH 3/9] perf: Allow PERF_FORMAT_GROUP format on inherited events Jiri Olsa
2014-08-25 14:45 ` [PATCH 4/9] perf tools: Add support to traverse xyarrays Jiri Olsa
2014-08-25 14:45 ` [PATCH 5/9] perf tools: Add pr_warning_once debug macro Jiri Olsa
2014-08-25 14:45 ` [PATCH 6/9] perf tools: Add hash of periods for struct perf_sample_id Jiri Olsa
2014-08-25 14:45 ` [PATCH 7/9] perf tools: Allow PERF_FORMAT_GROUP for inherited events Jiri Olsa
2014-08-25 14:45 ` [PATCH 8/9] perf script: Add period data column Jiri Olsa
2014-08-27 14:33   ` David Ahern
2014-10-17 16:10     ` Jiri Olsa
2014-10-17 18:22       ` Arnaldo Carvalho de Melo
2014-10-18  7:07   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2014-08-25 14:45 ` [PATCH 9/9] perf script: Add period as a default output column Jiri Olsa
2014-08-27 14:40   ` David Ahern
2014-10-17 16:11     ` Jiri Olsa
2014-10-18  7:07   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2014-08-25 14:51 ` [RFCv2 0/9] perf: Allow leader sampling on inherited events Jiri Olsa

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=20140910143535.GD2409@krava.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tommy24@gatech.edu \
    /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;
as well as URLs for NNTP newsgroup(s).