[PATCH 4/6] perf_counter: optionally provide the pid/tid of the sampled task

From: Peter Zijlstra
Date: Wed Mar 25 2009 - 07:40:37 EST


Allow cpu wide counters to profile userspace by providing what process
the sample belongs to.

This raises the first issue with the output type, lots of these
options: group, tid, callchain, etc.. are non-exclusive and could be
combined, suggesting a bitfield.

However, things like the mmap() data stream doesn't fit in that.

How to split the type field...

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
---
include/linux/perf_counter.h | 5 ++++-
kernel/perf_counter.c | 18 ++++++++++++++++--
2 files changed, 20 insertions(+), 3 deletions(-)

Index: linux-2.6/include/linux/perf_counter.h
===================================================================
--- linux-2.6.orig/include/linux/perf_counter.h
+++ linux-2.6/include/linux/perf_counter.h
@@ -127,8 +127,9 @@ struct perf_counter_hw_event {
exclude_kernel : 1, /* ditto kernel */
exclude_hv : 1, /* ditto hypervisor */
exclude_idle : 1, /* don't count when idle */
+ include_tid : 1, /* include the tid */

- __reserved_1 : 55;
+ __reserved_1 : 54;

__u32 extra_config_len;
__u32 __reserved_4;
@@ -164,6 +165,8 @@ struct perf_event_header {
enum perf_event_type {
PERF_EVENT_IP = 0,
PERF_EVENT_GROUP = 1,
+
+ __PERF_EVENT_TID = 0x100,
};

#ifdef __KERNEL__
Index: linux-2.6/kernel/perf_counter.c
===================================================================
--- linux-2.6.orig/kernel/perf_counter.c
+++ linux-2.6/kernel/perf_counter.c
@@ -1521,16 +1521,30 @@ out:
static void perf_output_simple(struct perf_counter *counter,
int nmi, struct pt_regs *regs)
{
+ unsigned int size;
struct {
struct perf_event_header header;
u64 ip;
+ u32 pid, tid;
} event;

event.header.type = PERF_EVENT_IP;
- event.header.size = sizeof(event);
event.ip = instruction_pointer(regs);

- perf_output_write(counter, nmi, &event, sizeof(event));
+ size = sizeof(event);
+
+ if (counter->hw_event.include_tid) {
+ /* namespace issues */
+ event.pid = current->group_leader->pid;
+ event.tid = current->pid;
+
+ event.header.type |= __PERF_EVENT_TID;
+ } else
+ size -= sizeof(u64);
+
+ event.header.size = size;
+
+ perf_output_write(counter, nmi, &event, size);
}

static void perf_output_group(struct perf_counter *counter, int nmi)

--

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