~lttng/lttng-ust/lttng-ust

« back to all changes in this revision

Viewing changes to src/common/ringbuffer-clients/template.h

  • Committer: Mathieu Desnoyers
  • Date: 2024-05-03 19:32:50 UTC
  • Revision ID: git-v1:373ea80ac0db5072e995140f1dbdbf4f0b1bdaad
Rename "tsc" to "timestamp"

Naming timestamps "TSC" or "tsc" is an historical artefact dating from
the implementation of libringbuffer, where the initial intent was to use
the x86 "rdtsc" instruction directly, which ended up not being what was
done in reality.

Rename uses of "TSC" and "tsc" to "timestamp" to clarify things and
don't require reviewers to be fluent in x86 instruction set.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I8e7e2ad9cd2d2427485fc6adbc340fccde14ca2f

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "common/clock.h"
20
20
#include "common/ringbuffer/frontend_types.h"
21
21
 
22
 
#define LTTNG_COMPACT_EVENT_BITS       5
23
 
#define LTTNG_COMPACT_TSC_BITS         27
 
22
#define LTTNG_COMPACT_EVENT_BITS        5
 
23
#define LTTNG_COMPACT_TIMESTAMP_BITS    27
24
24
 
25
25
/*
26
26
 * Keep the natural field alignment for _each field_ within this structure if
156
156
        case 1: /* compact */
157
157
                padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
158
158
                offset += padding;
159
 
                if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
 
159
                if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TIMESTAMP | LTTNG_RFLAG_EXTENDED))) {
160
160
                        offset += sizeof(uint32_t);     /* id and timestamp */
161
161
                } else {
162
162
                        /* Minimum space taken by LTTNG_COMPACT_EVENT_BITS id */
172
172
                padding = lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint16_t));
173
173
                offset += padding;
174
174
                offset += sizeof(uint16_t);
175
 
                if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
 
175
                if (!(ctx->priv->rflags & (RING_BUFFER_RFLAG_FULL_TIMESTAMP | LTTNG_RFLAG_EXTENDED))) {
176
176
                        offset += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t));
177
177
                        offset += sizeof(uint32_t);     /* timestamp */
178
178
                } else {
235
235
                                event_id);
236
236
                bt_bitfield_write(&id_time, uint32_t,
237
237
                                LTTNG_COMPACT_EVENT_BITS,
238
 
                                LTTNG_COMPACT_TSC_BITS,
239
 
                                ctx->priv->tsc);
 
238
                                LTTNG_COMPACT_TIMESTAMP_BITS,
 
239
                                ctx->priv->timestamp);
240
240
                lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
241
241
                break;
242
242
        }
243
243
        case 2: /* large */
244
244
        {
245
 
                uint32_t timestamp = (uint32_t) ctx->priv->tsc;
 
245
                uint32_t timestamp = (uint32_t) ctx->priv->timestamp;
246
246
                uint16_t id = event_id;
247
247
 
248
248
                lib_ring_buffer_write(config, ctx, &id, sizeof(id));
275
275
 
276
276
        switch (lttng_chan->priv->header_type) {
277
277
        case 1: /* compact */
278
 
                if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
 
278
                if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TIMESTAMP | LTTNG_RFLAG_EXTENDED))) {
279
279
                        uint32_t id_time = 0;
280
280
 
281
281
                        bt_bitfield_write(&id_time, uint32_t,
284
284
                                        event_id);
285
285
                        bt_bitfield_write(&id_time, uint32_t,
286
286
                                        LTTNG_COMPACT_EVENT_BITS,
287
 
                                        LTTNG_COMPACT_TSC_BITS,
288
 
                                        ctx_private->tsc);
 
287
                                        LTTNG_COMPACT_TIMESTAMP_BITS,
 
288
                                        ctx_private->timestamp);
289
289
                        lib_ring_buffer_write(config, ctx, &id_time, sizeof(id_time));
290
290
                } else {
291
291
                        uint8_t id = 0;
292
 
                        uint64_t timestamp = ctx_private->tsc;
 
292
                        uint64_t timestamp = ctx_private->timestamp;
293
293
 
294
294
                        bt_bitfield_write(&id, uint8_t,
295
295
                                        0,
305
305
                break;
306
306
        case 2: /* large */
307
307
        {
308
 
                if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TSC | LTTNG_RFLAG_EXTENDED))) {
309
 
                        uint32_t timestamp = (uint32_t) ctx_private->tsc;
 
308
                if (!(ctx_private->rflags & (RING_BUFFER_RFLAG_FULL_TIMESTAMP | LTTNG_RFLAG_EXTENDED))) {
 
309
                        uint32_t timestamp = (uint32_t) ctx_private->timestamp;
310
310
                        uint16_t id = event_id;
311
311
 
312
312
                        lib_ring_buffer_write(config, ctx, &id, sizeof(id));
314
314
                        lib_ring_buffer_write(config, ctx, &timestamp, sizeof(timestamp));
315
315
                } else {
316
316
                        uint16_t id = 65535;
317
 
                        uint64_t timestamp = ctx_private->tsc;
 
317
                        uint64_t timestamp = ctx_private->timestamp;
318
318
 
319
319
                        lib_ring_buffer_write(config, ctx, &id, sizeof(id));
320
320
                        /* Align extended struct on largest member */
364
364
        return offsetof(struct packet_header, ctx.header_end);
365
365
}
366
366
 
367
 
static void client_buffer_begin(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
 
367
static void client_buffer_begin(struct lttng_ust_ring_buffer *buf, uint64_t timestamp,
368
368
                                unsigned int subbuf_idx,
369
369
                                struct lttng_ust_shm_handle *handle)
370
370
{
384
384
        memcpy(header->uuid, lttng_chan->priv->uuid, sizeof(lttng_chan->priv->uuid));
385
385
        header->stream_id = lttng_chan->priv->id;
386
386
        header->stream_instance_id = buf->backend.cpu;
387
 
        header->ctx.timestamp_begin = tsc;
 
387
        header->ctx.timestamp_begin = timestamp;
388
388
        header->ctx.timestamp_end = 0;
389
389
        header->ctx.content_size = ~0ULL; /* for debugging */
390
390
        header->ctx.packet_size = ~0ULL;
397
397
 * offset is assumed to never be 0 here : never deliver a completely empty
398
398
 * subbuffer. data_size is between 1 and subbuf_size.
399
399
 */
400
 
static void client_buffer_end(struct lttng_ust_ring_buffer *buf, uint64_t tsc,
 
400
static void client_buffer_end(struct lttng_ust_ring_buffer *buf, uint64_t timestamp,
401
401
                              unsigned int subbuf_idx, unsigned long data_size,
402
402
                              struct lttng_ust_shm_handle *handle,
403
403
                              const struct lttng_ust_ring_buffer_ctx *ctx)
413
413
        assert(header);
414
414
        if (!header)
415
415
                return;
416
 
        header->ctx.timestamp_end = tsc;
 
416
        header->ctx.timestamp_end = timestamp;
417
417
        header->ctx.content_size =
418
418
                (uint64_t) data_size * CHAR_BIT;                /* in bits */
419
419
        header->ctx.packet_size =
614
614
        .cb.content_size_field = client_content_size_field,
615
615
        .cb.packet_size_field = client_packet_size_field,
616
616
 
617
 
        .tsc_bits = LTTNG_COMPACT_TSC_BITS,
 
617
        .timestamp_bits = LTTNG_COMPACT_TIMESTAMP_BITS,
618
618
        .alloc = RING_BUFFER_ALLOC_PER_CPU,
619
619
        .sync = RING_BUFFER_SYNC_GLOBAL,
620
620
        .mode = RING_BUFFER_MODE_TEMPLATE,