From 4e1f08f47c1837b09af74712c299c5169496591a Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 22 May 2011 01:16:50 -0400 Subject: [PATCH] Write event header Signed-off-by: Mathieu Desnoyers --- ltt-events.c | 2 +- ltt-events.h | 3 ++- ltt-ring-buffer-client.h | 28 +++++++++++++--------------- ltt-ring-buffer-metadata-client.h | 2 +- probes/lttng-events.h | 2 +- probes/lttng-ftrace.c | 2 +- probes/lttng-kprobes.c | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ltt-events.c b/ltt-events.c index 71fb8c70..46da1591 100644 --- a/ltt-events.c +++ b/ltt-events.c @@ -362,7 +362,7 @@ int lttng_metadata_printf(struct ltt_session *session, */ waitret = wait_event_interruptible_timeout(*chan->ops->get_reader_wait_queue(chan), ({ - ret = chan->ops->event_reserve(&ctx); + ret = chan->ops->event_reserve(&ctx, 0); ret != -ENOBUFS || !ret; }), msecs_to_jiffies(LTTNG_METADATA_TIMEOUT_MSEC)); diff --git a/ltt-events.h b/ltt-events.h index 5fd0b67a..859b43b7 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -180,7 +180,8 @@ struct ltt_channel_ops { void (*channel_destroy)(struct channel *chan); struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); void (*buffer_read_close)(struct lib_ring_buffer *buf); - int (*event_reserve)(struct lib_ring_buffer_ctx *ctx); + int (*event_reserve)(struct lib_ring_buffer_ctx *ctx, + uint16_t event_id); void (*event_commit)(struct lib_ring_buffer_ctx *ctx); void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, size_t len); diff --git a/ltt-ring-buffer-client.h b/ltt-ring-buffer-client.h index 0177d48b..e7bc4329 100644 --- a/ltt-ring-buffer-client.h +++ b/ltt-ring-buffer-client.h @@ -126,7 +126,7 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, extern void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx, - u16 eID, u32 event_size); + uint16_t event_id); /* * ltt_write_event_header @@ -135,13 +135,12 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, * * @config: ring buffer instance configuration * @ctx: reservation context - * @eID : event ID - * @event_size : size of the event, excluding the event header. + * @event_id: event ID */ static __inline__ void ltt_write_event_header(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx, - u16 eID, u32 event_size) + uint16_t event_id) { struct ltt_channel *ltt_chan = channel_get_private(ctx->chan); @@ -153,14 +152,13 @@ void ltt_write_event_header(const struct lib_ring_buffer_config *config, { uint32_t id_time = 0; - bt_bitfield_write(&id_time, uint32_t, 0, 5, eID); + bt_bitfield_write(&id_time, uint32_t, 0, 5, event_id); bt_bitfield_write(&id_time, uint32_t, 5, 27, ctx->tsc); lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time)); break; } case 2: /* large */ { - uint16_t event_id = eID; uint32_t timestamp = (uint32_t) ctx->tsc; lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id)); @@ -174,7 +172,7 @@ void ltt_write_event_header(const struct lib_ring_buffer_config *config, return; slow_path: - ltt_write_event_header_slow(config, ctx, eID, event_size); + ltt_write_event_header_slow(config, ctx, event_id); } /* @@ -182,7 +180,7 @@ slow_path: */ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx, - u16 eID, u32 event_size) + uint16_t event_id) { struct ltt_channel *ltt_chan = channel_get_private(ctx->chan); @@ -191,12 +189,12 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, if (!(ctx->rflags & RING_BUFFER_RFLAG_FULL_TSC)) { uint32_t id_time = 0; - bt_bitfield_write(&id_time, uint32_t, 0, 5, eID); + bt_bitfield_write(&id_time, uint32_t, 0, 5, event_id); bt_bitfield_write(&id_time, uint32_t, 5, 27, ctx->tsc); lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time)); } else { uint8_t id = 0; - uint32_t event_id = (uint32_t) eID; + uint32_t event_id = (uint32_t) event_id; uint64_t timestamp = ctx->tsc; bt_bitfield_write(&id, uint8_t, 0, 5, 31); @@ -211,7 +209,6 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, case 2: /* large */ { if (!(ctx->rflags & RING_BUFFER_RFLAG_FULL_TSC)) { - uint16_t event_id = eID; uint32_t timestamp = (uint32_t) ctx->tsc; lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id)); @@ -219,7 +216,7 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, lib_ring_buffer_write(config, ctx, ×tamp, sizeof(timestamp)); } else { uint16_t event_id = 65535; - uint32_t event_id_ext = (uint32_t) eID; + uint32_t event_id_ext = (uint32_t) event_id; uint64_t timestamp = ctx->tsc; lib_ring_buffer_write(config, ctx, &event_id, sizeof(event_id)); @@ -382,7 +379,8 @@ void ltt_buffer_read_close(struct lib_ring_buffer *buf) } static -int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx) +int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx, + uint16_t event_id) { int ret, cpu; @@ -394,8 +392,8 @@ int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx) ret = lib_ring_buffer_reserve(&client_config, ctx); if (ret) goto put; - return ret; - + ltt_write_event_header(&client_config, ctx, event_id); + return 0; put: lib_ring_buffer_put_cpu(&client_config); return ret; diff --git a/ltt-ring-buffer-metadata-client.h b/ltt-ring-buffer-metadata-client.h index c457aea2..17207f27 100644 --- a/ltt-ring-buffer-metadata-client.h +++ b/ltt-ring-buffer-metadata-client.h @@ -187,7 +187,7 @@ void ltt_buffer_read_close(struct lib_ring_buffer *buf) } static -int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx) +int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx, uint16_t event_id) { return lib_ring_buffer_reserve(&client_config, ctx); } diff --git a/probes/lttng-events.h b/probes/lttng-events.h index 8ffc23a2..422f9590 100644 --- a/probes/lttng-events.h +++ b/probes/lttng-events.h @@ -474,7 +474,7 @@ static void __event_probe__##_name(void *__data, _proto) \ __event_align = __event_get_align__##_name(_args); \ lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \ __event_align, -1); \ - __ret = __chan->ops->event_reserve(&ctx); \ + __ret = __chan->ops->event_reserve(&ctx, __event->id); \ if (__ret < 0) \ return; \ /* Control code (field ordering) */ \ diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index da6d79c1..7c4fc9f5 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -38,7 +38,7 @@ void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip, void **data return; lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, sizeof(payload), ltt_alignof(payload), -1); - ret = chan->ops->event_reserve(&ctx); + ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) return; payload.ip = ip; diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 87806e37..65c1d3ba 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -29,7 +29,7 @@ int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) return 0; lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, sizeof(data), ltt_alignof(data), -1); - ret = chan->ops->event_reserve(&ctx); + ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) return 0; lib_ring_buffer_align_ctx(&ctx, ltt_alignof(data)); -- 2.34.1