[ltt-dev] [PATCH take2 03/13] read event header from ltt-relay buffer
Lai Jiangshan
laijs at cn.fujitsu.com
Wed Feb 4 22:31:18 EST 2009
we implement ltt_read_event_header() read event header from ltt-relay
buffer. it does the work oppositely to ltt_write_event_header().
Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
---
diff --git a/include/linux/ltt-tracer.h b/include/linux/ltt-tracer.h
index ef91456..42fc47d 100644
--- a/include/linux/ltt-tracer.h
+++ b/include/linux/ltt-tracer.h
@@ -290,6 +290,8 @@ struct ltt_event_header {
#define LTT_RFLAG_ID_SIZE (1 << 1)
#define LTT_RFLAG_ID_SIZE_TSC (1 << 2)
+#define LTT_MAX_SMALL_SIZE 0xFFFFU
+
/*
* We use asm/timex.h : cpu_khz/HZ variable in here : we might have to deal
* specifically with CPU frequency scaling someday, so using an interpolation
@@ -359,7 +361,8 @@ static inline size_t ltt_subbuffer_header_size(void)
* Alignment of header struct on 32 bits (min arch size, header size)
* + sizeof(header struct) (32-bits)
* + (opt) u16 (ext. event id)
- * + (opt) u16 (event_size) (if event_size == 0xFFFFUL, has ext. event size)
+ * + (opt) u16 (event_size)
+ * (if event_size == LTT_MAX_SMALL_SIZE, has ext. event size)
* + (opt) u32 (ext. event size)
* + (opt) u64 full TSC (aligned on min(64-bits, arch size))
*
@@ -385,14 +388,14 @@ static inline unsigned char ltt_get_header_size(
switch (rflags) {
case LTT_RFLAG_ID_SIZE_TSC:
offset += sizeof(u16) + sizeof(u16);
- if (data_size >= 0xFFFFU)
+ if (data_size >= LTT_MAX_SMALL_SIZE)
offset += sizeof(u32);
offset += ltt_align(offset, sizeof(u64));
offset += sizeof(u64);
break;
case LTT_RFLAG_ID_SIZE:
offset += sizeof(u16) + sizeof(u16);
- if (data_size >= 0xFFFFU)
+ if (data_size >= LTT_MAX_SMALL_SIZE)
offset += sizeof(u32);
break;
case LTT_RFLAG_ID:
@@ -449,14 +452,14 @@ static inline size_t ltt_write_event_header(struct ltt_trace_struct *trace,
switch (rflags) {
case LTT_RFLAG_ID_SIZE_TSC:
- small_size = min_t(size_t, event_size, 0xFFFFU);
+ small_size = min_t(size_t, event_size, LTT_MAX_SMALL_SIZE);
ltt_relay_write(buf, buf_offset,
(u16[]){ (u16)eID }, sizeof(u16));
buf_offset += sizeof(u16);
ltt_relay_write(buf, buf_offset,
(u16[]){ (u16)small_size }, sizeof(u16));
buf_offset += sizeof(u16);
- if (small_size == 0xFFFFU) {
+ if (small_size == LTT_MAX_SMALL_SIZE) {
ltt_relay_write(buf, buf_offset,
(u32[]){ (u32)event_size }, sizeof(u32));
buf_offset += sizeof(u32);
@@ -467,14 +470,14 @@ static inline size_t ltt_write_event_header(struct ltt_trace_struct *trace,
buf_offset += sizeof(u64);
break;
case LTT_RFLAG_ID_SIZE:
- small_size = min_t(size_t, event_size, 0xFFFFU);
+ small_size = min_t(size_t, event_size, LTT_MAX_SMALL_SIZE);
ltt_relay_write(buf, buf_offset,
(u16[]){ (u16)eID }, sizeof(u16));
buf_offset += sizeof(u16);
ltt_relay_write(buf, buf_offset,
(u16[]){ (u16)small_size }, sizeof(u16));
buf_offset += sizeof(u16);
- if (small_size == 0xFFFFU) {
+ if (small_size == LTT_MAX_SMALL_SIZE) {
ltt_relay_write(buf, buf_offset,
(u32[]){ (u32)event_size }, sizeof(u32));
buf_offset += sizeof(u32);
@@ -492,6 +495,67 @@ static inline size_t ltt_write_event_header(struct ltt_trace_struct *trace,
return buf_offset;
}
+/*
+ * ltt_read_event_header
+ * buf_offset must aligned on 32 bits
+ */
+static inline size_t ltt_read_event_header(struct rchan_buf *buf,
+ long buf_offset, u64 *tsc, u32 *event_size, u16 *eID,
+ unsigned int *rflags)
+{
+ struct ltt_event_header header;
+ u16 small_size;
+
+ ltt_relay_read(buf, buf_offset, &header, sizeof(header));
+ buf_offset += sizeof(header);
+
+ *event_size = INT_MAX;
+ *eID = header.id_time >> LTT_TSC_BITS;
+ *tsc = header.id_time & LTT_TSC_MASK;
+
+ switch (*eID) {
+ case 29:
+ *rflags = LTT_RFLAG_ID_SIZE_TSC;
+ ltt_relay_read(buf, buf_offset, eID, sizeof(u16));
+ buf_offset += sizeof(u16);
+ ltt_relay_read(buf, buf_offset, &small_size, sizeof(u16));
+ buf_offset += sizeof(u16);
+ if (small_size == LTT_MAX_SMALL_SIZE) {
+ ltt_relay_read(buf, buf_offset, event_size,
+ sizeof(u32));
+ buf_offset += sizeof(u32);
+ } else
+ *event_size = small_size;
+ buf_offset += ltt_align(buf_offset, sizeof(u64));
+ ltt_relay_read(buf, buf_offset, tsc, sizeof(u64));
+ buf_offset += sizeof(u64);
+ break;
+ case 30:
+ *rflags = LTT_RFLAG_ID_SIZE;
+ ltt_relay_read(buf, buf_offset, eID, sizeof(u16));
+ buf_offset += sizeof(u16);
+ ltt_relay_read(buf, buf_offset, &small_size, sizeof(u16));
+ buf_offset += sizeof(u16);
+ if (small_size == LTT_MAX_SMALL_SIZE) {
+ ltt_relay_read(buf, buf_offset, event_size,
+ sizeof(u32));
+ buf_offset += sizeof(u32);
+ } else
+ *event_size = small_size;
+ break;
+ case 31:
+ *rflags = LTT_RFLAG_ID;
+ ltt_relay_read(buf, buf_offset, eID, sizeof(u16));
+ buf_offset += sizeof(u16);
+ break;
+ default:
+ *rflags = 0;
+ break;
+ }
+
+ return buf_offset;
+}
+
/* Lockless LTTng */
/* Buffer offset macros */
More information about the lttng-dev
mailing list