X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ltt-ring-buffer-client.h;h=aa763837a974271d9df6932f23771a82bc8e840d;hb=d793d5e111fe1436fb8e15daa5d7fb1be8987bb4;hp=5ce710cef7285c3da0000d11012ad5fd72f416d1;hpb=f3bc08c50e1b302bceea699027d889fd6d9af525;p=deliverable%2Flttng-modules.git diff --git a/ltt-ring-buffer-client.h b/ltt-ring-buffer-client.h index 5ce710ce..aa763837 100644 --- a/ltt-ring-buffer-client.h +++ b/ltt-ring-buffer-client.h @@ -10,10 +10,203 @@ #include #include +#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ #include "wrapper/trace-clock.h" #include "ltt-events.h" #include "ltt-tracer.h" +/* + * Keep the natural field alignment for _each field_ within this structure if + * you ever add/remove a field from this header. Packed attribute is not used + * because gcc generates poor code on at least powerpc and mips. Don't ever + * let gcc add padding between the structure elements. + */ +struct packet_header { + uint32_t magic; /* + * Trace magic number. + * contains endianness information. + */ + uint8_t trace_uuid[16]; + uint32_t stream_id; + uint64_t timestamp_begin; /* Cycle count at subbuffer start */ + uint64_t timestamp_end; /* Cycle count at subbuffer end */ + uint32_t content_size; /* Size of data in subbuffer */ + uint32_t packet_size; /* Subbuffer size (include padding) */ + uint32_t events_lost; /* + * Events lost in this subbuffer since + * the beginning of the trace. + * (may overflow) + */ +#if 0 + uint64_t start_time_sec; /* NTP-corrected start time */ + uint64_t start_time_usec; + uint64_t start_freq; /* + * Frequency at trace start, + * used all along the trace. + */ + uint32_t freq_scale; /* Frequency scaling (divisor) */ +#endif //0 + uint8_t header_end[0]; /* End of header */ +}; + + +static inline notrace u64 lib_ring_buffer_clock_read(struct channel *chan) +{ + return trace_clock_read64(); +} + +/* + * record_header_size - Calculate the header size and padding necessary. + * @config: ring buffer instance configuration + * @chan: channel + * @offset: offset in the write buffer + * @data_size: size of the payload + * @pre_header_padding: padding to add before the header (output) + * @rflags: reservation flags + * @ctx: reservation context + * + * Returns the event header size (including padding). + * + * Important note : + * The event header must be 32-bits. The total offset calculated here : + * + * 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 == LTT_MAX_SMALL_SIZE, has ext. event size) + * + (opt) u32 (ext. event size) + * + (opt) u64 full TSC (aligned on min(64-bits, arch size)) + * + * The payload must itself determine its own alignment from the biggest type it + * contains. + */ +static __inline__ +unsigned char record_header_size(const struct lib_ring_buffer_config *config, + struct channel *chan, size_t offset, + size_t data_size, size_t *pre_header_padding, + unsigned int rflags, + struct lib_ring_buffer_ctx *ctx) +{ + size_t orig_offset = offset; + size_t padding; + + BUILD_BUG_ON(sizeof(struct event_header) != sizeof(u32)); + + padding = lib_ring_buffer_align(offset, + sizeof(struct event_header)); + offset += padding; + offset += sizeof(struct event_header); + + if (unlikely(rflags)) { + switch (rflags) { + case LTT_RFLAG_ID_SIZE_TSC: + offset += sizeof(u16) + sizeof(u16); + if (data_size >= LTT_MAX_SMALL_SIZE) + offset += sizeof(u32); + offset += lib_ring_buffer_align(offset, sizeof(u64)); + offset += sizeof(u64); + break; + case LTT_RFLAG_ID_SIZE: + offset += sizeof(u16) + sizeof(u16); + if (data_size >= LTT_MAX_SMALL_SIZE) + offset += sizeof(u32); + break; + case LTT_RFLAG_ID: + offset += sizeof(u16); + break; + } + } + + *pre_header_padding = padding; + return offset - orig_offset; +} + +#include "wrapper/ringbuffer/api.h" + +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); + +/* + * ltt_write_event_header + * + * Writes the event header to the offset (already aligned on 32-bits). + * + * @config: ring buffer instance configuration + * @ctx: reservation context + * @eID : event ID + * @event_size : size of the event, excluding the event header. + */ +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) +{ + struct event_header header; + + if (unlikely(ctx->rflags)) + goto slow_path; + + header.id_time = eID << LTT_TSC_BITS; + header.id_time |= (u32)ctx->tsc & LTT_TSC_MASK; + lib_ring_buffer_write(config, ctx, &header, sizeof(header)); + +slow_path: + ltt_write_event_header_slow(config, ctx, eID, event_size); +} + +void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, + struct lib_ring_buffer_ctx *ctx, + u16 eID, u32 event_size) +{ + struct event_header header; + u16 small_size; + + switch (ctx->rflags) { + case LTT_RFLAG_ID_SIZE_TSC: + header.id_time = 29 << LTT_TSC_BITS; + break; + case LTT_RFLAG_ID_SIZE: + header.id_time = 30 << LTT_TSC_BITS; + break; + case LTT_RFLAG_ID: + header.id_time = 31 << LTT_TSC_BITS; + break; + default: + WARN_ON_ONCE(1); + header.id_time = 0; + } + + header.id_time |= (u32)ctx->tsc & LTT_TSC_MASK; + lib_ring_buffer_write(config, ctx, &header, sizeof(header)); + + switch (ctx->rflags) { + case LTT_RFLAG_ID_SIZE_TSC: + small_size = (u16)min_t(u32, event_size, LTT_MAX_SMALL_SIZE); + lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); + lib_ring_buffer_write(config, ctx, &small_size, sizeof(u16)); + if (small_size == LTT_MAX_SMALL_SIZE) + lib_ring_buffer_write(config, ctx, &event_size, + sizeof(u32)); + lib_ring_buffer_align_ctx(ctx, sizeof(u64)); + lib_ring_buffer_write(config, ctx, &ctx->tsc, sizeof(u64)); + break; + case LTT_RFLAG_ID_SIZE: + small_size = (u16)min_t(u32, event_size, LTT_MAX_SMALL_SIZE); + lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); + lib_ring_buffer_write(config, ctx, &small_size, sizeof(u16)); + if (small_size == LTT_MAX_SMALL_SIZE) + lib_ring_buffer_write(config, ctx, &event_size, + sizeof(u32)); + break; + case LTT_RFLAG_ID: + lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); + break; + } +} + static const struct lib_ring_buffer_config client_config; static u64 client_ring_buffer_clock_read(struct channel *chan) @@ -53,10 +246,21 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc, (struct packet_header *) lib_ring_buffer_offset_address(&buf->backend, subbuf_idx * chan->backend.subbuf_size); + struct ltt_session *session = channel_get_private(chan); + header->magic = CTF_MAGIC_NUMBER; + memcpy(header->trace_uuid, session->uuid.b, sizeof(session->uuid)); header->timestamp_begin = tsc; + header->timestamp_end = 0; header->content_size = 0xFFFFFFFF; /* for debugging */ - write_trace_header(&client_config, header); + header->packet_size = 0xFFFFFFFF; + header->events_lost = 0; +#if 0 + header->start_time_sec = ltt_chan->session->start_time.tv_sec; + header->start_time_usec = ltt_chan->session->start_time.tv_usec; + header->start_freq = ltt_chan->session->start_freq; + header->freq_scale = ltt_chan->session->freq_scale; +#endif //0 } /* @@ -73,9 +277,9 @@ static void client_buffer_end(struct lib_ring_buffer *buf, u64 tsc, subbuf_idx * chan->backend.subbuf_size); unsigned long records_lost = 0; + header->timestamp_end = tsc; header->content_size = data_size; header->packet_size = PAGE_ALIGN(data_size); - header->timestamp_end = tsc; records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf); records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf); records_lost += lib_ring_buffer_get_records_lost_big(&client_config, buf); @@ -151,6 +355,7 @@ void ltt_buffer_read_close(struct lib_ring_buffer *buf) } +static int ltt_event_reserve(struct lib_ring_buffer_ctx *ctx) { int ret, cpu; @@ -170,18 +375,26 @@ put: return ret; } +static void ltt_event_commit(struct lib_ring_buffer_ctx *ctx) { lib_ring_buffer_commit(&client_config, ctx); lib_ring_buffer_put_cpu(&client_config); } +static void ltt_event_write(struct lib_ring_buffer_ctx *ctx, const void *src, size_t len) { lib_ring_buffer_write(&client_config, ctx, src, len); } +static +wait_queue_head_t *ltt_get_reader_wait_queue(struct ltt_channel *chan) +{ + return &chan->chan->read_wait; +} + static struct ltt_transport ltt_relay_transport = { .name = "relay-" RING_BUFFER_MODE_TEMPLATE_STRING, .owner = THIS_MODULE, @@ -193,11 +406,17 @@ static struct ltt_transport ltt_relay_transport = { .event_reserve = ltt_event_reserve, .event_commit = ltt_event_commit, .event_write = ltt_event_write, + .get_reader_wait_queue = ltt_get_reader_wait_queue, }, }; static int __init ltt_ring_buffer_client_init(void) { + /* + * This vmalloc sync all also takes care of the lib ring buffer + * vmalloc'd module pages when it is built as a module into LTTng. + */ + wrapper_vmalloc_sync_all(); printk(KERN_INFO "LTT : ltt ring buffer client init\n"); ltt_transport_register(<t_relay_transport); return 0;