Cleanup: libringbuffer: remove duplicate shmp() invocations in slow paths
[lttng-ust.git] / libringbuffer / ring_buffer_frontend.c
index bda0e1f497fecc786883726b6329ba51498240c9..e631ae3dc36340c1af5427c75551f68310602379 100644 (file)
@@ -52,6 +52,7 @@
  */
 
 #define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -1608,6 +1609,7 @@ void lib_ring_buffer_switch_old_start(struct lttng_ust_lib_ring_buffer *buf,
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
        unsigned long oldidx = subbuf_index(offsets->old, chan);
        unsigned long commit_count;
+       struct commit_counters_hot *cc_hot;
 
        config->cb.buffer_begin(buf, tsc, oldidx, handle);
 
@@ -1616,15 +1618,16 @@ void lib_ring_buffer_switch_old_start(struct lttng_ust_lib_ring_buffer *buf,
         * determine that the subbuffer is full.
         */
        cmm_smp_wmb();
+       cc_hot = shmp_index(handle, buf->commit_hot, oldidx);
        v_add(config, config->cb.subbuffer_header_size(),
-             &shmp_index(handle, buf->commit_hot, oldidx)->cc);
-       commit_count = v_read(config, &shmp_index(handle, buf->commit_hot, oldidx)->cc);
+             &cc_hot->cc);
+       commit_count = v_read(config, &cc_hot->cc);
        /* Check if the written buffer has to be delivered */
        lib_ring_buffer_check_deliver(config, buf, chan, offsets->old,
                                      commit_count, oldidx, handle, tsc);
-       lib_ring_buffer_write_commit_counter(config, buf, chan, oldidx,
+       lib_ring_buffer_write_commit_counter(config, buf, chan,
                        offsets->old + config->cb.subbuffer_header_size(),
-                       commit_count, handle);
+                       commit_count, handle, cc_hot);
 }
 
 /*
@@ -1645,6 +1648,7 @@ void lib_ring_buffer_switch_old_end(struct lttng_ust_lib_ring_buffer *buf,
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
        unsigned long oldidx = subbuf_index(offsets->old - 1, chan);
        unsigned long commit_count, padding_size, data_size;
+       struct commit_counters_hot *cc_hot;
 
        data_size = subbuf_offset(offsets->old - 1, chan) + 1;
        padding_size = chan->backend.subbuf_size - data_size;
@@ -1656,12 +1660,14 @@ void lib_ring_buffer_switch_old_end(struct lttng_ust_lib_ring_buffer *buf,
         * determine that the subbuffer is full.
         */
        cmm_smp_wmb();
-       v_add(config, padding_size, &shmp_index(handle, buf->commit_hot, oldidx)->cc);
-       commit_count = v_read(config, &shmp_index(handle, buf->commit_hot, oldidx)->cc);
+       cc_hot = shmp_index(handle, buf->commit_hot, oldidx);
+       v_add(config, padding_size, &cc_hot->cc);
+       commit_count = v_read(config, &cc_hot->cc);
        lib_ring_buffer_check_deliver(config, buf, chan, offsets->old - 1,
                                      commit_count, oldidx, handle, tsc);
-       lib_ring_buffer_write_commit_counter(config, buf, chan, oldidx,
-                       offsets->old + padding_size, commit_count, handle);
+       lib_ring_buffer_write_commit_counter(config, buf, chan,
+                       offsets->old + padding_size, commit_count, handle,
+                       cc_hot);
 }
 
 /*
@@ -1681,6 +1687,7 @@ void lib_ring_buffer_switch_new_start(struct lttng_ust_lib_ring_buffer *buf,
        const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
        unsigned long beginidx = subbuf_index(offsets->begin, chan);
        unsigned long commit_count;
+       struct commit_counters_hot *cc_hot;
 
        config->cb.buffer_begin(buf, tsc, beginidx, handle);
 
@@ -1691,13 +1698,14 @@ void lib_ring_buffer_switch_new_start(struct lttng_ust_lib_ring_buffer *buf,
        cmm_smp_wmb();
        v_add(config, config->cb.subbuffer_header_size(),
              &shmp_index(handle, buf->commit_hot, beginidx)->cc);
-       commit_count = v_read(config, &shmp_index(handle, buf->commit_hot, beginidx)->cc);
+       cc_hot = shmp_index(handle, buf->commit_hot, beginidx);
+       commit_count = v_read(config, &cc_hot->cc);
        /* Check if the written buffer has to be delivered */
        lib_ring_buffer_check_deliver(config, buf, chan, offsets->begin,
                                      commit_count, beginidx, handle, tsc);
-       lib_ring_buffer_write_commit_counter(config, buf, chan, beginidx,
+       lib_ring_buffer_write_commit_counter(config, buf, chan,
                        offsets->begin + config->cb.subbuffer_header_size(),
-                       commit_count, handle);
+                       commit_count, handle, cc_hot);
 }
 
 /*
@@ -2167,6 +2175,34 @@ void lib_ring_buffer_vmcore_check_deliver(const struct lttng_ust_lib_ring_buffer
                v_set(config, &shmp_index(handle, buf->commit_hot, idx)->seq, commit_count);
 }
 
+/*
+ * The ring buffer can count events recorded and overwritten per buffer,
+ * but it is disabled by default due to its performance overhead.
+ */
+#ifdef LTTNG_RING_BUFFER_COUNT_EVENTS
+static
+void deliver_count_events(const struct lttng_ust_lib_ring_buffer_config *config,
+               struct lttng_ust_lib_ring_buffer *buf,
+               unsigned long idx,
+               struct lttng_ust_shm_handle *handle)
+{
+       v_add(config, subbuffer_get_records_count(config,
+                       &buf->backend, idx, handle),
+               &buf->records_count);
+       v_add(config, subbuffer_count_records_overrun(config,
+                       &buf->backend, idx, handle),
+               &buf->records_overrun);
+}
+#else /* LTTNG_RING_BUFFER_COUNT_EVENTS */
+static
+void deliver_count_events(const struct lttng_ust_lib_ring_buffer_config *config,
+               struct lttng_ust_lib_ring_buffer *buf,
+               unsigned long idx,
+               struct lttng_ust_shm_handle *handle)
+{
+}
+#endif /* #else LTTNG_RING_BUFFER_COUNT_EVENTS */
+
 void lib_ring_buffer_check_deliver_slow(const struct lttng_ust_lib_ring_buffer_config *config,
                                   struct lttng_ust_lib_ring_buffer *buf,
                                   struct channel *chan,
@@ -2220,16 +2256,7 @@ void lib_ring_buffer_check_deliver_slow(const struct lttng_ust_lib_ring_buffer_c
                 * and any other writer trying to access this subbuffer
                 * in this state is required to drop records.
                 */
-               v_add(config,
-                     subbuffer_get_records_count(config,
-                                                 &buf->backend,
-                                                 idx, handle),
-                     &buf->records_count);
-               v_add(config,
-                     subbuffer_count_records_overrun(config,
-                                                     &buf->backend,
-                                                     idx, handle),
-                     &buf->records_overrun);
+               deliver_count_events(config, buf, idx, handle);
                config->cb.buffer_end(buf, tsc, idx,
                                      lib_ring_buffer_get_data_size(config,
                                                                buf,
This page took 0.026622 seconds and 4 git commands to generate.