Fix: header size larger than 256 bytes
[lttng-modules.git] / lttng-ring-buffer-client.h
index 288cc32509dcde332f3aa3d9eab7b2a39b9b2f32..e882f4936316eb95e9bbc3a74dc64c89bec00133 100644 (file)
@@ -57,6 +57,7 @@ struct packet_header {
                                         */
        uint8_t uuid[16];
        uint32_t stream_id;
+       uint64_t stream_instance_id;
 
        struct {
                /* Stream packet context */
@@ -64,6 +65,7 @@ struct packet_header {
                uint64_t timestamp_end;         /* Cycle count at subbuffer end */
                uint64_t content_size;          /* Size of data in subbuffer */
                uint64_t packet_size;           /* Subbuffer size (include padding) */
+               uint64_t packet_seq_num;        /* Packet sequence number */
                unsigned long events_discarded; /*
                                                 * Events lost in this subbuffer since
                                                 * the beginning of the trace.
@@ -88,6 +90,7 @@ size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)
 
        if (likely(!ctx))
                return 0;
+       offset += lib_ring_buffer_align(offset, ctx->largest_align);
        for (i = 0; i < ctx->nr_fields; i++)
                offset += ctx->fields[i].get_size(offset);
        return offset - orig_offset;
@@ -102,6 +105,7 @@ void ctx_record(struct lib_ring_buffer_ctx *bufctx,
 
        if (likely(!ctx))
                return;
+       lib_ring_buffer_align_ctx(bufctx, ctx->largest_align);
        for (i = 0; i < ctx->nr_fields; i++)
                ctx->fields[i].record(&ctx->fields[i], bufctx, chan);
 }
@@ -120,7 +124,7 @@ void ctx_record(struct lib_ring_buffer_ctx *bufctx,
  * contains.
  */
 static __inline__
-unsigned char record_header_size(const struct lib_ring_buffer_config *config,
+size_t record_header_size(const struct lib_ring_buffer_config *config,
                                 struct channel *chan, size_t offset,
                                 size_t *pre_header_padding,
                                 struct lib_ring_buffer_ctx *ctx)
@@ -349,10 +353,14 @@ static void client_buffer_begin(struct lib_ring_buffer *buf, u64 tsc,
        header->magic = CTF_MAGIC_NUMBER;
        memcpy(header->uuid, session->uuid.b, sizeof(session->uuid));
        header->stream_id = lttng_chan->id;
+       header->stream_instance_id = buf->backend.cpu;
        header->ctx.timestamp_begin = tsc;
        header->ctx.timestamp_end = 0;
        header->ctx.content_size = ~0ULL; /* for debugging */
        header->ctx.packet_size = ~0ULL;
+       header->ctx.packet_seq_num = chan->backend.num_subbuf * \
+                                    buf->backend.buf_cnt[subbuf_idx].seq_cnt + \
+                                    subbuf_idx;
        header->ctx.events_discarded = 0;
        header->ctx.cpu_id = buf->backend.cpu;
 }
@@ -468,6 +476,28 @@ static int client_current_timestamp(const struct lib_ring_buffer_config *config,
        return 0;
 }
 
+static int client_sequence_number(const struct lib_ring_buffer_config *config,
+                       struct lib_ring_buffer *buf,
+                       uint64_t *seq)
+{
+       struct packet_header *header = client_packet_header(config, buf);
+
+       *seq = header->ctx.packet_seq_num;
+
+       return 0;
+}
+
+static
+int client_instance_id(const struct lib_ring_buffer_config *config,
+               struct lib_ring_buffer *buf,
+               uint64_t *id)
+{
+       struct packet_header *header = client_packet_header(config, buf);
+       *id = header->stream_instance_id;
+
+       return 0;
+}
+
 static const struct lib_ring_buffer_config client_config = {
        .cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
        .cb.record_header_size = client_record_header_size,
@@ -628,6 +658,21 @@ void lttng_event_memset(struct lib_ring_buffer_ctx *ctx,
        lib_ring_buffer_memset(&client_config, ctx, c, len);
 }
 
+static
+void lttng_event_strcpy(struct lib_ring_buffer_ctx *ctx, const char *src,
+               size_t len)
+{
+       lib_ring_buffer_strcpy(&client_config, ctx, src, len, '#');
+}
+
+static
+void lttng_event_strcpy_from_user(struct lib_ring_buffer_ctx *ctx,
+               const char __user *src, size_t len)
+{
+       lib_ring_buffer_strcpy_from_user_inatomic(&client_config, ctx, src,
+                       len, '#');
+}
+
 static
 wait_queue_head_t *lttng_get_writer_buf_wait_queue(struct channel *chan, int cpu)
 {
@@ -669,6 +714,8 @@ static struct lttng_transport lttng_relay_transport = {
                .event_write = lttng_event_write,
                .event_write_from_user = lttng_event_write_from_user,
                .event_memset = lttng_event_memset,
+               .event_strcpy = lttng_event_strcpy,
+               .event_strcpy_from_user = lttng_event_strcpy_from_user,
                .packet_avail_size = NULL,      /* Would be racy anyway */
                .get_writer_buf_wait_queue = lttng_get_writer_buf_wait_queue,
                .get_hp_wait_queue = lttng_get_hp_wait_queue,
@@ -681,6 +728,8 @@ static struct lttng_transport lttng_relay_transport = {
                .packet_size = client_packet_size,
                .stream_id = client_stream_id,
                .current_timestamp = client_current_timestamp,
+               .sequence_number = client_sequence_number,
+               .instance_id = client_instance_id,
        },
 };
 
This page took 0.024488 seconds and 4 git commands to generate.