From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Paul Mackerras <paulus@samba.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v3 1/5] perf_event: introduce 'inject' event and get HZ
Date: Tue, 29 Dec 2009 13:21:05 +0800 [thread overview]
Message-ID: <4B3991C1.6060303@cn.fujitsu.com> (raw)
In-Reply-To: <20091228075417.GB20039@elte.hu>
'inject' event is a very useful feature and it's suggested by Ingo
[ See http://lkml.org/lkml/2009/12/28/31 ]
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
include/linux/perf_event.h | 13 +++++++++++
kernel/perf_event.c | 47 +++++++++++++++++++++++++++++++++++++++++++
tools/perf/builtin-record.c | 13 +++++++++++
tools/perf/util/session.c | 5 ++++
tools/perf/util/session.h | 3 +-
5 files changed, 80 insertions(+), 1 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 9a1d276..6c93f88 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -228,6 +228,7 @@ struct perf_event_attr {
#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
+#define PERF_EVENT_IOC_INJECT _IO ('$', 7)
enum perf_event_ioc_flags {
PERF_IOC_FLAG_GROUP = 1U << 0,
@@ -413,10 +414,22 @@ enum perf_event_type {
* };
*/
PERF_RECORD_SAMPLE = 9,
+ /*
+ * struct {
+ * struct perf_event_header header;
+ * u32 inject_event_id;
+ * u64 value;
+ * };
+ */
+ PERF_RECORD_INJECT = 10,
PERF_RECORD_MAX, /* non-ABI */
};
+enum perf_inject_event {
+ PERF_INJECT_HZ = 0x01,
+};
+
enum perf_callchain_context {
PERF_CONTEXT_HV = (__u64)-32,
PERF_CONTEXT_KERNEL = (__u64)-128,
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 8984afd..9343c6c 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -2012,6 +2012,50 @@ unlock:
return ret;
}
+static int perf_inject_get_hz(u64 *hz)
+{
+ *hz = HZ;
+ return 0;
+}
+
+static int perf_inject_event(struct perf_event *event, u32 inject_event_id,
+ int (*get_value)(u64 *))
+{
+ struct perf_output_handle handle;
+ struct perf_inject_event {
+ struct perf_event_header header;
+ u32 inject_event_id;
+ u64 value;
+ } inject_event;
+ int ret = 0;
+
+ inject_event.header.type = PERF_RECORD_INJECT;
+ inject_event.header.misc = 0;
+ inject_event.header.size = sizeof(inject_event);
+ inject_event.inject_event_id = inject_event_id;
+
+ ret = get_value(&inject_event.value);
+ if (ret)
+ goto exit;
+
+ ret = perf_output_begin(&handle, event, inject_event.header.size, 0, 0);
+ if (ret)
+ goto exit;
+
+ perf_output_put(&handle, inject_event);
+ perf_output_end(&handle);
+exit:
+ return ret;
+}
+
+static int perf_inject_ioctl(struct perf_event *event, unsigned int arg)
+{
+ if (!arg || arg & ~PERF_INJECT_HZ)
+ return -EINVAL;
+
+ return perf_inject_event(event, PERF_INJECT_HZ, perf_inject_get_hz);
+}
+
static int perf_event_set_output(struct perf_event *event, int output_fd);
static int perf_event_set_filter(struct perf_event *event, void __user *arg);
@@ -2044,6 +2088,9 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case PERF_EVENT_IOC_SET_FILTER:
return perf_event_set_filter(event, (void __user *)arg);
+ case PERF_EVENT_IOC_INJECT:
+ return perf_inject_ioctl(event, arg);
+
default:
return -ENOTTY;
}
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2654253..d13601d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -65,6 +65,8 @@ static int file_new = 1;
static struct perf_session *session;
+u32 inject_events;
+
struct mmap_data {
int counter;
void *base;
@@ -381,6 +383,17 @@ try_again:
}
}
+ if (inject_events) {
+ ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_INJECT,
+ inject_events);
+ if (ret) {
+ error("failed to inject event(%u) with %d (%s)\n",
+ inject_events, errno, strerror(errno));
+ exit(-1);
+ }
+ inject_events = 0;
+ }
+
ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7f0537d..74f43af 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -179,6 +179,8 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
handler->throttle = process_event_stub;
if (handler->unthrottle == NULL)
handler->unthrottle = process_event_stub;
+ if (handler->inject == NULL)
+ handler->inject = process_event_stub;
}
static const char *event__name[] = {
@@ -192,6 +194,7 @@ static const char *event__name[] = {
[PERF_RECORD_FORK] = "FORK",
[PERF_RECORD_READ] = "READ",
[PERF_RECORD_SAMPLE] = "SAMPLE",
+ [PERF_RECORD_INJECT] = "INJECT",
};
unsigned long event__total[PERF_RECORD_MAX];
@@ -239,6 +242,8 @@ static int perf_session__process_event(struct perf_session *self,
return ops->throttle(event, self);
case PERF_RECORD_UNTHROTTLE:
return ops->unthrottle(event, self);
+ case PERF_RECORD_INJECT:
+ return ops->inject(event, self);
default:
self->unknown_events++;
return -1;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 77c5ee2..8742354 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -40,7 +40,8 @@ struct perf_event_ops {
lost,
read,
throttle,
- unthrottle;
+ unthrottle,
+ inject;
};
struct perf_session *perf_session__new(const char *filename, int mode, bool force);
--
1.6.1.2
next prev parent reply other threads:[~2009-12-29 5:22 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-15 11:17 [PATCH 0/4] perf_event: introduce 'perf timer' to analyze timer's behavior Xiao Guangrong
2009-12-15 11:19 ` [PATCH 1/4] trace_event: record task' real_timer in itimer_state tracepoint Xiao Guangrong
2009-12-15 11:20 ` [PATCH 2/4] perf_event: fix getting point Xiao Guangrong
2009-12-15 11:21 ` [PATCH 3/4] perf/timer: add document Xiao Guangrong
2009-12-15 11:22 ` [PATCH 4/4] perf/timer: 'perf timer' core code Xiao Guangrong
2009-12-15 17:44 ` Thomas Gleixner
2009-12-16 5:56 ` Xiao Guangrong
2009-12-16 15:59 ` Thomas Gleixner
2009-12-17 7:26 ` Xiao Guangrong
2009-12-15 13:58 ` [PATCH 2/4] perf_event: fix getting point Frederic Weisbecker
2009-12-16 1:03 ` Xiao Guangrong
2009-12-16 1:22 ` Frederic Weisbecker
2009-12-16 1:32 ` Xiao Guangrong
2009-12-15 14:15 ` [PATCH 0/4] perf_event: introduce 'perf timer' to analyze timer's behavior Frederic Weisbecker
2009-12-16 1:19 ` Xiao Guangrong
2009-12-16 7:32 ` Ingo Molnar
2009-12-16 7:40 ` Xiao Guangrong
2009-12-16 7:46 ` Ingo Molnar
2009-12-15 14:23 ` Frederic Weisbecker
2009-12-22 13:00 ` [PATCH v2 0/5] " Xiao Guangrong
2009-12-22 13:01 ` [PATCH v2 1/5] perf_event: fix getting point Xiao Guangrong
2009-12-22 13:03 ` [PATCH v2 2/5]: trace_event: export HZ in timer's tracepoint format Xiao Guangrong
2009-12-22 13:20 ` Xiao Guangrong
2009-12-28 7:54 ` Ingo Molnar
2009-12-28 10:40 ` Xiao Guangrong
2009-12-29 5:20 ` [PATCH v3 0/5] perf tools: introduce 'perf timer' to analyze timer's behavior Xiao Guangrong
2009-12-29 5:21 ` Xiao Guangrong [this message]
2009-12-30 9:19 ` [PATCH v3 1/5] perf_event: introduce 'inject' event and get HZ Peter Zijlstra
2009-12-30 9:28 ` Ingo Molnar
2009-12-30 9:36 ` Peter Zijlstra
2009-12-30 9:44 ` Ingo Molnar
2009-12-30 10:06 ` Peter Zijlstra
2009-12-30 11:30 ` Ingo Molnar
2009-12-30 9:37 ` Xiao Guangrong
2009-12-30 9:45 ` Peter Zijlstra
2009-12-29 5:21 ` [PATCH v3 2/5] trace_event: record task' real_timer in itimer_state tracepoint Xiao Guangrong
2009-12-29 5:21 ` [PATCH v3 3/5] perf tools: fix getting point Xiao Guangrong
2009-12-29 5:21 ` [PATCH v3 4/5] perf timer: add document for 'perf timer' Xiao Guangrong
2009-12-29 5:22 ` [PATCH v3 5/5] perf timer: add 'perf timer' core code Xiao Guangrong
2009-12-22 13:04 ` [PATCH v2 3/5] trace_event: record task' real_timer in itimer_state tracepoint Xiao Guangrong
2009-12-22 13:06 ` [PATCH v2 4/5] perf/timer: add document for 'perf timer' Xiao Guangrong
2009-12-22 13:08 ` [PATCH v2 5/5] perf/timer: add 'perf timer' core code Xiao Guangrong
-- strict thread matches above, loose matches on Subject: below --
2009-12-29 10:49 [PATCH v3 1/5] perf_event: introduce 'inject' event and get HZ Stijn Devriendt
2009-12-29 11:34 ` Xiao Guangrong
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=4B3991C1.6060303@cn.fujitsu.com \
--to=xiaoguangrong@cn.fujitsu.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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