| 1 | /* |
| 2 | * ltt/ltt-event-header.c |
| 3 | * |
| 4 | * (C) Copyright 2010 - Mathieu Desnoyers (mathieu.desnoyers@efficios.com) |
| 5 | * |
| 6 | * LTTng event header. |
| 7 | * |
| 8 | * Author: |
| 9 | * Mathieu Desnoyers (mathieu.desnoyers@efficios.com) |
| 10 | * |
| 11 | * Dual LGPL v2.1/GPL v2 license. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include "ltt-tracer.h" |
| 16 | |
| 17 | void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, |
| 18 | struct lib_ring_buffer_ctx *ctx, |
| 19 | u16 eID, u32 event_size) |
| 20 | { |
| 21 | struct event_header header; |
| 22 | u16 small_size; |
| 23 | |
| 24 | switch (ctx->rflags) { |
| 25 | case LTT_RFLAG_ID_SIZE_TSC: |
| 26 | header.id_time = 29 << LTT_TSC_BITS; |
| 27 | break; |
| 28 | case LTT_RFLAG_ID_SIZE: |
| 29 | header.id_time = 30 << LTT_TSC_BITS; |
| 30 | break; |
| 31 | case LTT_RFLAG_ID: |
| 32 | header.id_time = 31 << LTT_TSC_BITS; |
| 33 | break; |
| 34 | default: |
| 35 | WARN_ON_ONCE(1); |
| 36 | header.id_time = 0; |
| 37 | } |
| 38 | |
| 39 | header.id_time |= (u32)ctx->tsc & LTT_TSC_MASK; |
| 40 | lib_ring_buffer_write(config, ctx, &header, sizeof(header)); |
| 41 | |
| 42 | switch (ctx->rflags) { |
| 43 | case LTT_RFLAG_ID_SIZE_TSC: |
| 44 | small_size = (u16)min_t(u32, event_size, LTT_MAX_SMALL_SIZE); |
| 45 | lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); |
| 46 | lib_ring_buffer_write(config, ctx, &small_size, sizeof(u16)); |
| 47 | if (small_size == LTT_MAX_SMALL_SIZE) |
| 48 | lib_ring_buffer_write(config, ctx, &event_size, |
| 49 | sizeof(u32)); |
| 50 | lib_ring_buffer_align_ctx(ctx, sizeof(u64)); |
| 51 | lib_ring_buffer_write(config, ctx, &ctx->tsc, sizeof(u64)); |
| 52 | break; |
| 53 | case LTT_RFLAG_ID_SIZE: |
| 54 | small_size = (u16)min_t(u32, event_size, LTT_MAX_SMALL_SIZE); |
| 55 | lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); |
| 56 | lib_ring_buffer_write(config, ctx, &small_size, sizeof(u16)); |
| 57 | if (small_size == LTT_MAX_SMALL_SIZE) |
| 58 | lib_ring_buffer_write(config, ctx, &event_size, |
| 59 | sizeof(u32)); |
| 60 | break; |
| 61 | case LTT_RFLAG_ID: |
| 62 | lib_ring_buffer_write(config, ctx, &eID, sizeof(u16)); |
| 63 | break; |
| 64 | } |
| 65 | } |
| 66 | EXPORT_SYMBOL_GPL(ltt_write_event_header_slow); |