lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20130311131036.GA13679@krava.brq.redhat.com>
Date:	Mon, 11 Mar 2013 14:10:36 +0100
From:	Jiri Olsa <jolsa@...hat.com>
To:	Namhyung Kim <namhyung@...nel.org>
Cc:	Arnaldo Carvalho de Melo <acme@...stprotocols.net>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Mackerras <paulus@...ba.org>,
	Ingo Molnar <mingo@...nel.org>,
	LKML <linux-kernel@...r.kernel.org>,
	Stephane Eranian <eranian@...gle.com>,
	Namhyung Kim <namhyung.kim@....com>,
	Vince Weaver <vince@...ter.net>,
	Frederic Weisbecker <fweisbec@...il.com>
Subject: [PATCH] perf tests: Add automated test for mixed type event groups

On Thu, Mar 07, 2013 at 01:19:50PM +0900, Namhyung Kim wrote:
> From: Namhyung Kim <namhyung.kim@....com>
> 
> There's a problem with mixed hw/sw group when the leader is a software
> event.  For instance:
> 
>   $ perf stat -e '{task-clock,cycles,faults}' sleep 1
> 
>    Performance counter stats for 'sleep 1':
> 
>             0.273436 task-clock                #    0.000 CPUs utilized
>              962,965 cycles                    #    3.522 GHz
>      <not supported> faults
> 
>          1.000804279 seconds time elapsed
> 

as discussed on irc, here's automated test for this,
feel free to change it in any way

jirka


---
Adding automated test for mixed type event groups.

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
---
 tools/perf/Makefile             |    1 +
 tools/perf/tests/builtin-test.c |    4 ++
 tools/perf/tests/mixed-groups.c |  104 +++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |    1 +
 4 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 tools/perf/tests/mixed-groups.c

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index a2108ca..6eb5930 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -497,6 +497,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
 LIB_OBJS += $(OUTPUT)tests/pmu.o
 LIB_OBJS += $(OUTPUT)tests/hists_link.o
 LIB_OBJS += $(OUTPUT)tests/python-use.o
+LIB_OBJS += $(OUTPUT)tests/mixed-groups.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 acb98e0..aaec91d 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -78,6 +78,10 @@ static struct test {
 		.func = test__python_use,
 	},
 	{
+		.desc = "Test event mixed groups",
+		.func = test__mixed_groups,
+	},
+	{
 		.func = NULL,
 	},
 };
diff --git a/tools/perf/tests/mixed-groups.c b/tools/perf/tests/mixed-groups.c
new file mode 100644
index 0000000..fe55354
--- /dev/null
+++ b/tools/perf/tests/mixed-groups.c
@@ -0,0 +1,104 @@
+
+#include <linux/compiler.h>
+#include "tests.h"
+#include "debug.h"
+
+#define EVENTS 4
+static int ret;
+
+static int event(int hw, int group)
+{
+	struct perf_event_attr pe;
+	u32 type = hw ? PERF_TYPE_HARDWARE : PERF_TYPE_SOFTWARE;
+	u64 config = hw ? PERF_COUNT_HW_CPU_CYCLES : PERF_COUNT_SW_CPU_CLOCK;
+	int fd;
+
+	memset(&pe, 0, sizeof(struct perf_event_attr));
+	pe.type   = type;
+	pe.config = config;
+	pe.size   = sizeof(struct perf_event_attr);
+
+	pe.disabled = group == -1 ? 1 : 0;
+	pe.exclude_hv = 1;
+
+	fd = sys_perf_event_open(&pe, 0, -1, group, 0);
+
+	pr_debug("%s(%d) ", hw ? "H" : "S", fd);
+
+	return fd;
+}
+
+static long long count(int fd)
+{
+	long long c;
+	int err;
+
+	if (fd < 0)
+		return 0;
+
+	err = read(fd, &c, sizeof(c));
+	if (err != sizeof(c)) {
+		pr_err("failed to read: %d\n", err);
+		ret = TEST_FAIL;
+	}
+
+	return c;
+}
+
+static void __test__mixed_groups(int events)
+{
+#define group fd[0]
+	int fd[EVENTS] = { -1 };
+	int i;
+
+	for (i = 0; i < EVENTS; i++) {
+		int hw = (1 << i) & events;
+
+		fd[i] = event(hw, group);
+		if (!hw && fd[i] < 0) {
+			pr_debug("\n");
+			ret = TEST_FAIL;
+			goto out;
+		}
+	}
+
+	pr_debug("\n  counts: ");
+
+	ioctl(group, PERF_EVENT_IOC_ENABLE, 0);
+
+	while(i++);
+
+	ioctl(group, PERF_EVENT_IOC_DISABLE, 0);
+
+	for (i = 0; i < EVENTS; i++) {
+		int hw = (1 << i) & events;
+		long long c;
+
+		c = count(fd[i]);
+
+		pr_debug("%d(%lld) ", fd[i], c);
+		if (!hw && !c) {
+			pr_debug("no count for SW event");
+			ret = TEST_FAIL;
+			break;
+		}
+	}
+
+	pr_debug("\n");
+
+ out:
+	for (i = 0; i < EVENTS; i++)
+		close(fd[i]);
+#undef group
+}
+
+int test__mixed_groups(void)
+{
+	int i;
+
+	for (i = 0; i < (1 << EVENTS); i++)
+		__test__mixed_groups(i);
+
+	pr_debug("ret %d\n", ret);
+	return ret;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 5de0be1..c4a2f05 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -23,5 +23,6 @@ int test__dso_data(void);
 int test__parse_events(void);
 int test__hists_link(void);
 int test__python_use(void);
+int test__mixed_groups(void);
 
 #endif /* TESTS_H */
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ