From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, hpa@zytor.com,
mingo@redhat.com, a.p.zijlstra@chello.nl, efault@gmx.de,
arjan@infradead.org, tglx@linutronix.de, fengguang.wu@intel.com,
mingo@elte.hu
Subject: [tip:perfcounters/core] perf_counter: output objects
Date: Wed, 25 Mar 2009 12:06:36 GMT [thread overview]
Message-ID: <tip-cc1383cf4762fa39ba7ca6864e150422eb405a33@git.kernel.org> (raw)
In-Reply-To: <20090325113316.831607932@chello.nl>
Commit-ID: cc1383cf4762fa39ba7ca6864e150422eb405a33
Gitweb: http://git.kernel.org/tip/cc1383cf4762fa39ba7ca6864e150422eb405a33
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Wed, 25 Mar 2009 12:30:23 +0100
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 25 Mar 2009 13:02:51 +0100
perf_counter: output objects
Provide a {type,size} header for each output entry.
This should provide extensible output, and the ability to mix multiple streams.
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>
LKML-Reference: <20090325113316.831607932@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/perf_counter.h | 11 ++++++++
kernel/perf_counter.c | 53 ++++++++++++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 48212c1..c256635 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -156,6 +156,16 @@ struct perf_counter_mmap_page {
__u32 data_head; /* head in the data section */
};
+struct perf_event_header {
+ __u32 type;
+ __u32 size;
+};
+
+enum perf_event_type {
+ PERF_EVENT_IP = 0,
+ PERF_EVENT_GROUP = 1,
+};
+
#ifdef __KERNEL__
/*
* Kernel-internal data types and definitions:
@@ -260,6 +270,7 @@ struct perf_counter {
struct list_head list_entry;
struct list_head event_entry;
struct list_head sibling_list;
+ int nr_siblings;
struct perf_counter *group_leader;
const struct hw_perf_counter_ops *hw_ops;
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 0422fd9..d76e311 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -75,8 +75,10 @@ list_add_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
*/
if (counter->group_leader == counter)
list_add_tail(&counter->list_entry, &ctx->counter_list);
- else
+ else {
list_add_tail(&counter->list_entry, &group_leader->sibling_list);
+ group_leader->nr_siblings++;
+ }
list_add_rcu(&counter->event_entry, &ctx->event_list);
}
@@ -89,6 +91,9 @@ list_del_counter(struct perf_counter *counter, struct perf_counter_context *ctx)
list_del_init(&counter->list_entry);
list_del_rcu(&counter->event_entry);
+ if (counter->group_leader != counter)
+ counter->group_leader->nr_siblings--;
+
/*
* If this was a group counter with sibling counters then
* upgrade the siblings to singleton counters by adding them
@@ -381,9 +386,11 @@ static int is_software_only_group(struct perf_counter *leader)
if (!is_software_counter(leader))
return 0;
+
list_for_each_entry(counter, &leader->sibling_list, list_entry)
if (!is_software_counter(counter))
return 0;
+
return 1;
}
@@ -1480,6 +1487,9 @@ static void perf_output_copy(struct perf_output_handle *handle,
handle->offset = offset;
}
+#define perf_output_put(handle, x) \
+ perf_output_copy((handle), &(x), sizeof(x))
+
static void perf_output_end(struct perf_output_handle *handle, int nmi)
{
if (handle->wakeup) {
@@ -1514,34 +1524,53 @@ out:
static void perf_output_simple(struct perf_counter *counter,
int nmi, struct pt_regs *regs)
{
- u64 entry;
+ struct {
+ struct perf_event_header header;
+ u64 ip;
+ } event;
- entry = instruction_pointer(regs);
+ event.header.type = PERF_EVENT_IP;
+ event.header.size = sizeof(event);
+ event.ip = instruction_pointer(regs);
- perf_output_write(counter, nmi, &entry, sizeof(entry));
+ perf_output_write(counter, nmi, &event, sizeof(event));
}
-struct group_entry {
- u64 event;
- u64 counter;
-};
-
static void perf_output_group(struct perf_counter *counter, int nmi)
{
+ struct perf_output_handle handle;
+ struct perf_event_header header;
struct perf_counter *leader, *sub;
+ unsigned int size;
+ struct {
+ u64 event;
+ u64 counter;
+ } entry;
+ int ret;
+
+ size = sizeof(header) + counter->nr_siblings * sizeof(entry);
+
+ ret = perf_output_begin(&handle, counter, size);
+ if (ret)
+ return;
+
+ header.type = PERF_EVENT_GROUP;
+ header.size = size;
+
+ perf_output_put(&handle, header);
leader = counter->group_leader;
list_for_each_entry(sub, &leader->sibling_list, list_entry) {
- struct group_entry entry;
-
if (sub != counter)
sub->hw_ops->read(sub);
entry.event = sub->hw_event.config;
entry.counter = atomic64_read(&sub->count);
- perf_output_write(counter, nmi, &entry, sizeof(entry));
+ perf_output_put(&handle, entry);
}
+
+ perf_output_end(&handle, nmi);
}
void perf_counter_output(struct perf_counter *counter,
next prev parent reply other threads:[~2009-03-25 12:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-25 11:30 [PATCH 0/6] perf_counter: new output ABI Peter Zijlstra
2009-03-25 11:30 ` [PATCH 1/6] perf_counter: more elaborate write API Peter Zijlstra
2009-03-25 12:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 2/6] perf_counter: output objects Peter Zijlstra
2009-03-25 12:06 ` Peter Zijlstra [this message]
2009-03-25 11:30 ` [PATCH 3/6] perf_counter: sanity check on the output API Peter Zijlstra
2009-03-25 12:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 4/6] perf_counter: optionally provide the pid/tid of the sampled task Peter Zijlstra
2009-03-25 12:06 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 11:30 ` [PATCH 5/6] perf_counter: kerneltop: mmap_pages argument Peter Zijlstra
2009-03-25 12:07 ` [tip:perfcounters/core] " Peter Zijlstra
2009-03-25 12:18 ` [PATCH 5/6] " Ingo Molnar
2009-03-25 12:27 ` Peter Zijlstra
2009-03-25 12:35 ` Ingo Molnar
2009-03-25 12:41 ` Peter Zijlstra
2009-03-25 12:54 ` Ingo Molnar
2009-03-25 12:57 ` Peter Zijlstra
2009-03-25 14:52 ` Peter Zijlstra
2009-03-25 17:16 ` Ingo Molnar
2009-03-25 21:18 ` Peter Zijlstra
2009-03-26 2:22 ` Paul Mackerras
2009-03-25 11:30 ` [PATCH 6/6] perf_counter: kerneltop: output event support Peter Zijlstra
2009-03-25 12:07 ` [tip:perfcounters/core] " Peter Zijlstra
2009-04-04 0:21 ` [PATCH 6/6] " Corey Ashford
2009-04-04 12:17 ` Peter Zijlstra
2009-04-04 18:10 ` Corey Ashford
2009-03-25 12:05 ` [PATCH 0/6] perf_counter: new output ABI Ingo Molnar
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=tip-cc1383cf4762fa39ba7ca6864e150422eb405a33@git.kernel.org \
--to=a.p.zijlstra@chello.nl \
--cc=arjan@infradead.org \
--cc=efault@gmx.de \
--cc=fengguang.wu@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.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