~lttng/lttng-ust/lttng-ust

« back to all changes in this revision

Viewing changes to src/common/ringbuffer/frontend_internal.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:
85
85
}
86
86
 
87
87
/*
88
 
 * Last TSC comparison functions. Check if the current TSC overflows tsc_bits
89
 
 * bits from the last TSC read. When overflows are detected, the full 64-bit
90
 
 * timestamp counter should be written in the record header. Reads and writes
91
 
 * last_tsc atomically.
 
88
 * Last timestamp comparison functions. Check if the current timestamp overflows
 
89
 * timestamp_bits bits from the last timestamp read. When overflows are
 
90
 * detected, the full 64-bit timestamp counter should be written in the record
 
91
 * header. Reads and writes last_timestamp atomically.
92
92
 */
93
93
 
94
94
#if (CAA_BITS_PER_LONG == 32)
95
95
static inline
96
 
void save_last_tsc(const struct lttng_ust_ring_buffer_config *config,
97
 
                   struct lttng_ust_ring_buffer *buf, uint64_t tsc)
 
96
void save_last_timestamp(const struct lttng_ust_ring_buffer_config *config,
 
97
                   struct lttng_ust_ring_buffer *buf, uint64_t timestamp)
98
98
{
99
 
        if (config->tsc_bits == 0 || config->tsc_bits == 64)
 
99
        if (config->timestamp_bits == 0 || config->timestamp_bits == 64)
100
100
                return;
101
101
 
102
102
        /*
103
103
         * Ensure the compiler performs this update in a single instruction.
104
104
         */
105
 
        v_set(config, &buf->last_tsc, (unsigned long)(tsc >> config->tsc_bits));
 
105
        v_set(config, &buf->last_timestamp, (unsigned long)(timestamp >> config->timestamp_bits));
106
106
}
107
107
 
108
108
static inline
109
 
int last_tsc_overflow(const struct lttng_ust_ring_buffer_config *config,
110
 
                      struct lttng_ust_ring_buffer *buf, uint64_t tsc)
 
109
int last_timestamp_overflow(const struct lttng_ust_ring_buffer_config *config,
 
110
                      struct lttng_ust_ring_buffer *buf, uint64_t timestamp)
111
111
{
112
 
        unsigned long tsc_shifted;
 
112
        unsigned long timestamp_shifted;
113
113
 
114
 
        if (config->tsc_bits == 0 || config->tsc_bits == 64)
 
114
        if (config->timestamp_bits == 0 || config->timestamp_bits == 64)
115
115
                return 0;
116
116
 
117
 
        tsc_shifted = (unsigned long)(tsc >> config->tsc_bits);
118
 
        if (caa_unlikely(tsc_shifted
119
 
                     - (unsigned long)v_read(config, &buf->last_tsc)))
 
117
        timestamp_shifted = (unsigned long)(timestamp >> config->timestamp_bits);
 
118
        if (caa_unlikely(timestamp_shifted
 
119
                     - (unsigned long)v_read(config, &buf->last_timestamp)))
120
120
                return 1;
121
121
        else
122
122
                return 0;
123
123
}
124
124
#else
125
125
static inline
126
 
void save_last_tsc(const struct lttng_ust_ring_buffer_config *config,
127
 
                   struct lttng_ust_ring_buffer *buf, uint64_t tsc)
 
126
void save_last_timestamp(const struct lttng_ust_ring_buffer_config *config,
 
127
                   struct lttng_ust_ring_buffer *buf, uint64_t timestamp)
128
128
{
129
 
        if (config->tsc_bits == 0 || config->tsc_bits == 64)
 
129
        if (config->timestamp_bits == 0 || config->timestamp_bits == 64)
130
130
                return;
131
131
 
132
 
        v_set(config, &buf->last_tsc, (unsigned long)tsc);
 
132
        v_set(config, &buf->last_timestamp, (unsigned long)timestamp);
133
133
}
134
134
 
135
135
static inline
136
 
int last_tsc_overflow(const struct lttng_ust_ring_buffer_config *config,
137
 
                      struct lttng_ust_ring_buffer *buf, uint64_t tsc)
 
136
int last_timestamp_overflow(const struct lttng_ust_ring_buffer_config *config,
 
137
                      struct lttng_ust_ring_buffer *buf, uint64_t timestamp)
138
138
{
139
 
        if (config->tsc_bits == 0 || config->tsc_bits == 64)
 
139
        if (config->timestamp_bits == 0 || config->timestamp_bits == 64)
140
140
                return 0;
141
141
 
142
 
        if (caa_unlikely((tsc - v_read(config, &buf->last_tsc))
143
 
                     >> config->tsc_bits))
 
142
        if (caa_unlikely((timestamp - v_read(config, &buf->last_timestamp))
 
143
                     >> config->timestamp_bits))
144
144
                return 1;
145
145
        else
146
146
                return 0;
287
287
}
288
288
 
289
289
/*
290
 
 * Receive end of subbuffer TSC as parameter. It has been read in the
 
290
 * Receive end of subbuffer timestamp as parameter. It has been read in the
291
291
 * space reservation loop of either reserve or switch, which ensures it
292
292
 * progresses monotonically with event records in the buffer. Therefore,
293
293
 * it ensures that the end timestamp of a subbuffer is <= begin