lkml.org 
[lkml]   [2010]   [Nov]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/6] perf: Add timestamp to READ and LOST events
Date
From: Ian Munsie <imunsie@au1.ibm.com>

This patch adds timestamps to the remaining events previously missing
them (PERF_RECORD_READ and PERF_RECORD_LOST) if requested by the
all_timed flag in the event attributes when opening the event.

This is not strictly necessary to fix any known bugs, but it is
foreseeable that knowing the timestamp of these events may be desirable
in the future and if we are going to add a timestamp to them, we may as
well do it now while we are changing the ABI to add timestamps to COMM
and MMAP events anyway.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
---
include/linux/perf_event.h | 2 +
kernel/perf_event.c | 56 +++++++++++++++++++++++++++++++++-----------
2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ef99af4..8b646aa 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -347,6 +347,7 @@ enum perf_event_type {
/*
* struct {
* struct perf_event_header header;
+ * { u64 time; } && all_timed
* u64 id;
* u64 lost;
* };
@@ -398,6 +399,7 @@ enum perf_event_type {
/*
* struct {
* struct perf_event_header header;
+ * { u64 time; } && all_timed
* u32 pid, tid;
*
* struct read_format values;
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index c8ebab2..310b54a 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -3310,10 +3310,14 @@ int perf_output_begin(struct perf_output_handle *handle,
struct perf_buffer *buffer;
unsigned long tail, offset, head;
int have_lost;
+ unsigned int lostsize;
struct {
struct perf_event_header header;
- u64 id;
- u64 lost;
+ u64 time; /* && all_timed */
+ struct {
+ u64 id;
+ u64 lost;
+ } event_id;
} lost_event;

rcu_read_lock();
@@ -3336,8 +3340,14 @@ int perf_output_begin(struct perf_output_handle *handle,
goto out;

have_lost = local_read(&buffer->lost);
- if (have_lost)
- size += sizeof(lost_event);
+ if (have_lost) {
+ lostsize = sizeof(lost_event.header) + sizeof(lost_event.event_id);
+ if (event->attr.all_timed) {
+ lostsize += sizeof(u64);
+ lost_event.time = perf_clock();
+ }
+ size += lostsize;
+ }

perf_output_get_handle(handle);

@@ -3368,11 +3378,14 @@ int perf_output_begin(struct perf_output_handle *handle,
if (have_lost) {
lost_event.header.type = PERF_RECORD_LOST;
lost_event.header.misc = 0;
- lost_event.header.size = sizeof(lost_event);
- lost_event.id = event->id;
- lost_event.lost = local_xchg(&buffer->lost, 0);
+ lost_event.header.size = lostsize;
+ lost_event.event_id.id = event->id;
+ lost_event.event_id.lost = local_xchg(&buffer->lost, 0);

- perf_output_put(handle, lost_event);
+ perf_output_put(handle, lost_event.header);
+ if (event->attr.all_timed)
+ perf_output_put(handle, lost_event.time);
+ perf_output_put(handle, lost_event.event_id);
}

return 0;
@@ -3710,9 +3723,12 @@ exit:

struct perf_read_event {
struct perf_event_header header;
+ u64 time; /* && all_timed */

- u32 pid;
- u32 tid;
+ struct {
+ u32 pid;
+ u32 tid;
+ } event_id;
};

static void
@@ -3724,18 +3740,30 @@ perf_event_read_event(struct perf_event *event,
.header = {
.type = PERF_RECORD_READ,
.misc = 0,
- .size = sizeof(read_event) + perf_event_read_size(event),
+ .size = sizeof(read_event.header) + sizeof(read_event.event_id)
+ + perf_event_read_size(event),
+ },
+ /* .time && all_timed */
+ .event_id = {
+ .pid = perf_event_pid(event, task),
+ .tid = perf_event_tid(event, task),
},
- .pid = perf_event_pid(event, task),
- .tid = perf_event_tid(event, task),
};
int ret;

+ if (event->attr.all_timed) {
+ read_event.header.size += sizeof(u64);
+ read_event.time = perf_clock();
+ }
+
ret = perf_output_begin(&handle, event, read_event.header.size, 0, 0);
if (ret)
return;

- perf_output_put(&handle, read_event);
+ perf_output_put(&handle, read_event.header);
+ if (event->attr.all_timed)
+ perf_output_put(&handle, read_event.time);
+ perf_output_put(&handle, read_event.event_id);
perf_output_read(&handle, event);

perf_output_end(&handle);
--
1.7.2.3


\
 
 \ /
  Last update: 2010-11-23 06:39    [W:0.452 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site