From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [PATCH 14/21] perf tests: Adding event group toggling test
Date: Wed, 25 Sep 2013 14:50:40 +0200 [thread overview]
Message-ID: <1380113447-17144-15-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1380113447-17144-1-git-send-email-jolsa@redhat.com>
Adding ioctl toggle test to measure instructions
enclosed within following syscall groups:
geteuid
openat
--> measure instructions
close
getppid
To show/test we could chain multiple togglers.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Makefile | 1 +
tools/perf/tests/builtin-test.c | 4 +
tools/perf/tests/tests.h | 1 +
tools/perf/tests/toggle-event-group.c | 195 ++++++++++++++++++++++++++++++++++
4 files changed, 201 insertions(+)
create mode 100644 tools/perf/tests/toggle-event-group.c
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2072389..90d7127 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -399,6 +399,7 @@ LIB_OBJS += $(OUTPUT)tests/code-reading.o
LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
LIB_OBJS += $(OUTPUT)tests/toggle-event-raw.o
+LIB_OBJS += $(OUTPUT)tests/toggle-event-group.o
ifeq ($(RAW_ARCH),x86_64)
LIB_OBJS += $(OUTPUT)arch/x86/tests/toggle-event-raw-64.o
endif
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index db9d924b..7e96550 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -120,6 +120,10 @@ static struct test {
.func = test__toggle_event_raw,
},
{
+ .desc = "Toggle event group",
+ .func = test__toggle_event_group,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 4f2a8a1..db692bf 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -41,5 +41,6 @@ int test__sample_parsing(void);
int test__keep_tracking(void);
int test__parse_no_sample_id_all(void);
int test__toggle_event_raw(void);
+int test__toggle_event_group(void);
#endif /* TESTS_H */
diff --git a/tools/perf/tests/toggle-event-group.c b/tools/perf/tests/toggle-event-group.c
new file mode 100644
index 0000000..e781b30
--- /dev/null
+++ b/tools/perf/tests/toggle-event-group.c
@@ -0,0 +1,195 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <traceevent/event-parse.h>
+#include "thread_map.h"
+#include "evsel.h"
+#include "debug.h"
+#include "tests.h"
+
+/*
+ * We want to toggle instructions on/off only after chained
+ * execution of defined tracepoints, like:
+ *
+ * getuid();
+ * openat();
+ * instructions to count
+ * close();
+ * getppid();
+ *
+ * This test creates following events:
+ *
+ * 1) tracepoint sys_enter_getuid
+ * 2) tracepoint sys_enter_getppid
+ * 3) tracepoint sys_enter_openat
+ * 4) tracepoint sys_enter_close
+ * 5) HW event instruction
+ *
+ *
+ * Events 3) and 4) are created as a group with 3) as the leader.
+ * Events 3) and 4) toggle ON and OFF respectively event 5).
+ * Events 1) and 2) toggle ON and OFF respectively event 3).
+ *
+ * This means:
+ * - when the workload executes getuid(), the group (events 3
+ * and 4) is toggled ON.
+ * - when the workload executes close, the group (events 3
+ * and 4) is toggled OFF.
+ * - when the workload executes started events 3) and 4) they
+ * toggle ON and OFF respectively instructions event.
+ *
+ */
+
+extern int test__toggle_event_raw_arch(void);
+
+static int get_tp_id(const char *name)
+{
+ struct event_format *tp_format = event_format__new("syscalls", name);
+ u64 id = 0;
+
+ if (tp_format) {
+ id = tp_format->id;
+ pevent_free_format(tp_format);
+ }
+
+ return id;
+}
+
+#ifndef __x86_64__
+int test__toggle_event_group(void)
+{
+ pr_err("The toggle event test not implemented for arch.\n");
+ return 0;
+}
+#else
+
+static int test(void)
+{
+ int instr;
+
+ getuid();
+ instr = test__toggle_event_raw_arch();
+ getppid();
+ return instr;
+}
+
+#ifndef PERF_EVENT_IOC_SET_TOGGLE
+#define PERF_EVENT_IOC_SET_TOGGLE 1074275336
+#endif
+
+static int toggle_event(int fd_event, int flag, int fd_toggled)
+{
+ u64 args[2] = { fd_toggled, flag };
+ return ioctl(fd_event, PERF_EVENT_IOC_SET_TOGGLE, args);
+}
+
+int test__toggle_event_group(void)
+{
+ struct perf_event_attr attr_group_on = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .config = get_tp_id("sys_enter_getuid"),
+ .sample_period = 1,
+ };
+ struct perf_event_attr attr_group_off = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .config = get_tp_id("sys_enter_getppid"),
+ .sample_period = 1,
+ };
+ struct perf_event_attr attr_on = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .config = get_tp_id("sys_enter_openat"),
+ .sample_period = 1,
+ .paused = 1,
+ };
+ struct perf_event_attr attr_off = {
+ .type = PERF_TYPE_TRACEPOINT,
+ .config = get_tp_id("sys_enter_close"),
+ .sample_period = 1,
+ .paused = 1,
+ };
+ struct perf_event_attr attr_instr = {
+ .type = PERF_TYPE_HARDWARE,
+ .config = PERF_COUNT_HW_INSTRUCTIONS,
+ .paused = 1,
+ .exclude_kernel = 1,
+ .exclude_hv = 1,
+ };
+ int fd_group_on, fd_group_off, fd_on, fd_off, fd_instr;
+ __u64 value, instr;
+
+ fd_instr = sys_perf_event_open(&attr_instr, 0, -1, -1, 0);
+ if (fd_instr < 0) {
+ pr_err("failed to open instruction event, errno %d\n", errno);
+ return -1;
+ }
+
+ fd_on = sys_perf_event_open(&attr_on, 0, -1, -1, 0);
+ if (fd_on < 0) {
+ pr_err("failed to open 'on' event, errno %d\n", errno);
+ return -1;
+ }
+
+ fd_off = sys_perf_event_open(&attr_off, 0, -1, fd_on, 0);
+ if (fd_off < 0) {
+ pr_err("failed to open 'off' event, errno %d\n", errno);
+ return -1;
+ }
+
+ if (toggle_event(fd_on, PERF_FLAG_TOGGLE_ON, fd_instr)) {
+ pr_err("failed to set toggle 'on', errno %d\n", errno);
+ return -1;
+ }
+
+ if (toggle_event(fd_off, PERF_FLAG_TOGGLE_OFF, fd_instr)) {
+ pr_err("failed to set toggle 'off', errno %d\n", errno);
+ return -1;
+ }
+
+ fd_group_on = sys_perf_event_open(&attr_group_on, 0, -1,
+ fd_on, PERF_FLAG_TOGGLE_ON);
+ if (fd_group_on < 0) {
+ pr_err("failed to open 'group_on' event, errno %d\n", errno);
+ return -1;
+ }
+
+ fd_group_off = sys_perf_event_open(&attr_group_off, 0, -1,
+ fd_on, PERF_FLAG_TOGGLE_OFF);
+ if (fd_group_off < 0) {
+ pr_err("failed to open 'group_off' event, errno %d\n", errno);
+ return -1;
+ }
+
+#define READ(i, exp) \
+do { \
+ if (sizeof(value) != read(fd_instr, &value, sizeof(value))) { \
+ pr_err("failed to read instruction event, errno %d\n", errno); \
+ return -1; \
+ } \
+ pr_debug("%d got count %llu vs %lu\n", i, value, (unsigned long) exp); \
+} while (0)
+
+
+ READ(1, 0);
+
+ test__toggle_event_raw_arch();
+
+ READ(2, 0);
+
+ instr = test();
+
+ READ(3, instr);
+
+ test__toggle_event_raw_arch();
+
+ READ(4, instr);
+
+ close(fd_on);
+ close(fd_off);
+ close(fd_group_on);
+ close(fd_group_off);
+
+ READ(5, instr);
+
+ close(fd_instr);
+ return instr != value;
+}
+#endif /* __x86_64__ */
--
1.7.11.7
next prev parent reply other threads:[~2013-09-25 12:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-25 12:50 [RFC 00/21] perf tools: Add toggling events support Jiri Olsa
2013-09-25 12:50 ` [PATCH 01/21] perf tools: Introduce perf_evlist__wait_workload function Jiri Olsa
2013-09-25 12:50 ` [PATCH 02/21] perf tools: Separate sys_perf_event_open call into evsel_open Jiri Olsa
2013-09-25 12:50 ` [PATCH 03/21] perf x86: Update event count properly for read syscall Jiri Olsa
2013-09-25 12:50 ` [PATCH 04/21] perf: Move event state initialization before/behind the pmu add/del calls Jiri Olsa
2013-09-25 12:50 ` [PATCH 05/21] perf: Add event toggle sys_perf_event_open interface Jiri Olsa
2013-09-25 22:36 ` Sukadev Bhattiprolu
2013-09-26 12:27 ` Jiri Olsa
2013-09-25 12:50 ` [PATCH 06/21] perf: Add event toggle ioctl interface Jiri Olsa
2013-09-25 19:46 ` Vince Weaver
2013-09-26 12:30 ` Jiri Olsa
2013-09-26 13:03 ` Vince Weaver
2013-09-25 12:50 ` [PATCH 07/21] perf: Toggle whole group in toggle event overflow Jiri Olsa
2013-09-25 12:50 ` [PATCH 08/21] perf: Add new 'paused' attribute Jiri Olsa
2013-09-25 22:41 ` Sukadev Bhattiprolu
2013-09-26 12:24 ` Jiri Olsa
2013-09-25 12:50 ` [PATCH 09/21] perf: Account toggle masters for toggled event Jiri Olsa
2013-09-25 12:50 ` [PATCH 10/21] perf: Be more specific on pmu related event init naming Jiri Olsa
2013-09-25 12:50 ` [PATCH 11/21] perf: Split allocation and initialization code Jiri Olsa
2013-09-25 12:50 ` [PATCH 12/21] perf: Support event inheritance for toggle feature Jiri Olsa
2013-09-25 12:50 ` [PATCH 13/21] perf tests: Adding event simple toggling test Jiri Olsa
2013-09-25 12:50 ` Jiri Olsa [this message]
2013-09-25 12:50 ` [PATCH 15/21] perf tests: Adding event inherit " Jiri Olsa
2013-09-25 12:50 ` [PATCH 16/21] perf tools: Allow numeric event to change name via name term Jiri Olsa
2013-09-25 12:50 ` [PATCH 17/21] perf tools: Add event_config_optional parsing rule Jiri Olsa
2013-09-25 12:50 ` [PATCH 18/21] perf tools: Rename term related parsing function/variable properly Jiri Olsa
2013-09-25 12:50 ` [PATCH 19/21] perf tools: Carry term string value for symbols events Jiri Olsa
2013-09-25 12:50 ` [PATCH 20/21] perf tools: Add support to parse event on/off toggle terms Jiri Olsa
2013-09-25 12:50 ` [PATCH 21/21] perf tools: Add record/stat support for toggling events Jiri Olsa
2013-09-25 19:12 ` [RFC 00/21] perf tools: Add toggling events support Andi Kleen
2013-09-26 7:03 ` Ingo Molnar
2013-09-26 15:45 ` Andi Kleen
2013-09-26 12:11 ` Jiri Olsa
2013-09-26 11:31 ` Stephane Eranian
2013-09-26 12:20 ` 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=1380113447-17144-15-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.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;
as well as URLs for NNTP newsgroup(s).