Warn and return on fd overflow fdt
[lttng-modules.git] / src / lib / ringbuffer / ring_buffer_frontend.c
index e12c70263ea1942b03509dd27320a87f18a3312d..df0705cbd4245f1f2221a00ed41e9884f7c1a5a6 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/percpu.h>
+#include <linux/percpu-defs.h>
 #include <asm/cacheflush.h>
 
 #include <ringbuffer/config.h>
@@ -50,7 +51,6 @@
 #include <ringbuffer/nohz.h>
 #include <wrapper/cpu.h>
 #include <wrapper/kref.h>
-#include <wrapper/percpu-defs.h>
 #include <wrapper/timer.h>
 #include <wrapper/vmalloc.h>
 
@@ -173,7 +173,7 @@ void lib_ring_buffer_reset(struct lttng_kernel_ring_buffer *buf)
        }
        atomic_long_set(&buf->consumed, 0);
        atomic_set(&buf->record_disabled, 0);
-       v_set(config, &buf->last_tsc, 0);
+       v_set(config, &buf->last_timestamp, 0);
        lib_ring_buffer_backend_reset(&buf->backend);
        /* Don't reset number of active readers */
        v_set(config, &buf->records_lost_full, 0);
@@ -232,7 +232,7 @@ int lib_ring_buffer_create(struct lttng_kernel_ring_buffer *buf,
        struct lttng_kernel_ring_buffer_channel *chan = container_of(chanb, struct lttng_kernel_ring_buffer_channel, backend);
        void *priv = chanb->priv;
        size_t subbuf_header_size;
-       u64 tsc;
+       u64 timestamp;
        int ret;
 
        /* Test for cpu hotplug */
@@ -294,8 +294,8 @@ int lib_ring_buffer_create(struct lttng_kernel_ring_buffer *buf,
        subbuf_header_size = config->cb.subbuffer_header_size();
        v_set(config, &buf->offset, subbuf_header_size);
        subbuffer_id_clear_noref(config, &buf->backend.buf_wsb[0].id);
-       tsc = config->cb.ring_buffer_clock_read(buf->backend.chan);
-       config->cb.buffer_begin(buf, tsc, 0);
+       timestamp = config->cb.ring_buffer_clock_read(buf->backend.chan);
+       config->cb.buffer_begin(buf, timestamp, 0);
        v_add(config, subbuf_header_size, &buf->commit_hot[0].cc);
 
        if (config->cb.buffer_create) {
@@ -652,16 +652,16 @@ static int notrace ring_buffer_tick_nohz_callback(struct notifier_block *nb,
                raw_spin_unlock(&buf->raw_tick_nohz_spinlock);
                break;
        case TICK_NOHZ_STOP:
-               spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
+               spin_lock(this_cpu_ptr(&ring_buffer_nohz_lock));
                lib_ring_buffer_stop_switch_timer(buf);
                lib_ring_buffer_stop_read_timer(buf);
-               spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
+               spin_unlock(this_cpu_ptr(&ring_buffer_nohz_lock));
                break;
        case TICK_NOHZ_RESTART:
-               spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
+               spin_lock(this_cpu_ptr(&ring_buffer_nohz_lock));
                lib_ring_buffer_start_read_timer(buf);
                lib_ring_buffer_start_switch_timer(buf);
-               spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
+               spin_unlock(this_cpu_ptr(&ring_buffer_nohz_lock));
                break;
        }
 
@@ -1210,6 +1210,16 @@ static void lib_ring_buffer_flush_read_subbuf_dcache(
        if (config->output != RING_BUFFER_MMAP)
                return;
 
+#ifdef cpu_dcache_is_aliasing
+       /*
+        * Some architectures implement flush_dcache_page() but don't
+        * actually have aliasing dcache. cpu_dcache_is_aliasing() was
+        * introduced in kernel v6.9 to query this more precisely.
+        */
+       if (!cpu_dcache_is_aliasing())
+               return;
+#endif
+
        /*
         * Architectures with caches aliased on virtual addresses may
         * use different cache lines for the linear mapping vs
@@ -1589,7 +1599,7 @@ void lib_ring_buffer_switch_old_start(struct lttng_kernel_ring_buffer *buf,
        unsigned long commit_count;
        struct commit_counters_hot *cc_hot;
 
-       config->cb.buffer_begin(buf, ctx->priv.tsc, oldidx);
+       config->cb.buffer_begin(buf, ctx->priv.timestamp, oldidx);
 
        /*
         * Order all writes to buffer before the commit count update that will
@@ -1648,7 +1658,7 @@ void lib_ring_buffer_switch_old_end(struct lttng_kernel_ring_buffer *buf,
         * postponed until the commit counter is incremented for the
         * current space reservation.
         */
-       *ts_end = ctx->priv.tsc;
+       *ts_end = ctx->priv.timestamp;
 
        /*
         * Order all writes to buffer and store to ts_end before the commit
@@ -1691,7 +1701,7 @@ void lib_ring_buffer_switch_new_start(struct lttng_kernel_ring_buffer *buf,
        unsigned long commit_count;
        struct commit_counters_hot *cc_hot;
 
-       config->cb.buffer_begin(buf, ctx->priv.tsc, beginidx);
+       config->cb.buffer_begin(buf, ctx->priv.timestamp, beginidx);
 
        /*
         * Order all writes to buffer before the commit count update that will
@@ -1747,7 +1757,7 @@ void lib_ring_buffer_switch_new_end(struct lttng_kernel_ring_buffer *buf,
         * postponed until the commit counter is incremented for the
         * current space reservation.
         */
-       *ts_end = ctx->priv.tsc;
+       *ts_end = ctx->priv.timestamp;
 }
 
 /*
@@ -1770,7 +1780,7 @@ int lib_ring_buffer_try_switch_slow(enum switch_mode mode,
        offsets->switch_old_start = 0;
        off = subbuf_offset(offsets->begin, chan);
 
-       ctx->priv.tsc = config->cb.ring_buffer_clock_read(chan);
+       ctx->priv.timestamp = config->cb.ring_buffer_clock_read(chan);
 
        /*
         * Ensure we flush the header of an empty subbuffer when doing the
@@ -1891,12 +1901,12 @@ void lib_ring_buffer_switch_slow(struct lttng_kernel_ring_buffer *buf, enum swit
                 != offsets.old);
 
        /*
-        * Atomically update last_tsc. This update races against concurrent
-        * atomic updates, but the race will always cause supplementary full TSC
-        * records, never the opposite (missing a full TSC record when it would
-        * be needed).
+        * Atomically update last_timestamp. This update races against concurrent
+        * atomic updates, but the race will always cause supplementary
+        * full timestamp records, never the opposite (missing a full
+        * timestamp record when it would be needed).
         */
-       save_last_tsc(config, buf, ctx.priv.tsc);
+       save_last_timestamp(config, buf, ctx.priv.timestamp);
 
        /*
         * Push the reader if necessary
@@ -2019,12 +2029,12 @@ retry:
        offsets->switch_old_end = 0;
        offsets->pre_header_padding = 0;
 
-       ctx->priv.tsc = config->cb.ring_buffer_clock_read(chan);
-       if ((int64_t) ctx->priv.tsc == -EIO)
+       ctx->priv.timestamp = config->cb.ring_buffer_clock_read(chan);
+       if ((int64_t) ctx->priv.timestamp == -EIO)
                return -EIO;
 
-       if (last_tsc_overflow(config, buf, ctx->priv.tsc))
-               ctx->priv.rflags |= RING_BUFFER_RFLAG_FULL_TSC;
+       if (last_timestamp_overflow(config, buf, ctx->priv.timestamp))
+               ctx->priv.rflags |= RING_BUFFER_RFLAG_FULL_TIMESTAMP;
 
        if (unlikely(subbuf_offset(offsets->begin, ctx->priv.chan) == 0)) {
                offsets->switch_new_start = 1;          /* For offsets->begin */
@@ -2211,12 +2221,12 @@ int lib_ring_buffer_reserve_slow(struct lttng_kernel_ring_buffer_ctx *ctx,
                          != offsets.old));
 
        /*
-        * Atomically update last_tsc. This update races against concurrent
-        * atomic updates, but the race will always cause supplementary full TSC
-        * records, never the opposite (missing a full TSC record when it would
-        * be needed).
+        * Atomically update last_timestamp. This update races against concurrent
+        * atomic updates, but the race will always cause supplementary
+        * full timestamp records, never the opposite (missing a full
+        * timestamp record when it would be needed).
         */
-       save_last_tsc(config, buf, ctx->priv.tsc);
+       save_last_timestamp(config, buf, ctx->priv.timestamp);
 
        /*
         * Push the reader if necessary
@@ -2406,6 +2416,7 @@ void lib_ring_buffer_check_deliver_slow(const struct lttng_kernel_ring_buffer_co
 }
 EXPORT_SYMBOL_GPL(lib_ring_buffer_check_deliver_slow);
 
+static
 int __init init_lib_ring_buffer_frontend(void)
 {
        int cpu;
@@ -2417,6 +2428,7 @@ int __init init_lib_ring_buffer_frontend(void)
 
 module_init(init_lib_ring_buffer_frontend);
 
+static
 void __exit exit_lib_ring_buffer_frontend(void)
 {
 }
This page took 0.029066 seconds and 4 git commands to generate.