Introduce LTTNG_UST_MAP_POPULATE_POLICY environment variable
[lttng-ust.git] / src / common / ringbuffer / ring_buffer_frontend.c
index 91c69b7697d9e7f1bd1b06a518a66049a8ce210c..f3f82e828d4ee598775e1b36ae7d4676224978bb 100644 (file)
@@ -63,6 +63,7 @@
 #include "shm.h"
 #include "rb-init.h"
 #include "common/compat/errno.h"       /* For ENODATA */
+#include "common/populate.h"
 
 /* Print DBG() messages about events lost only every 1048576 hits */
 #define DBG_PRINT_NR_LOST      (1UL << 20)
@@ -980,9 +981,10 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_ring_buffer_c
        struct shm_object *shmobj;
        unsigned int nr_streams;
        int64_t blocking_timeout_ms;
+       bool populate = lttng_ust_map_populate_is_enabled();
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU)
-               nr_streams = num_possible_cpus();
+               nr_streams = get_possible_cpus_array_len();
        else
                nr_streams = 1;
 
@@ -1006,12 +1008,12 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_ring_buffer_c
                                         read_timer_interval))
                return NULL;
 
-       handle = zmalloc(sizeof(struct lttng_ust_shm_handle));
+       handle = zmalloc_populate(sizeof(struct lttng_ust_shm_handle), populate);
        if (!handle)
                return NULL;
 
        /* Allocate table for channel + per-cpu buffers */
-       handle->table = shm_object_table_create(1 + num_possible_cpus());
+       handle->table = shm_object_table_create(1 + get_possible_cpus_array_len(), populate);
        if (!handle->table)
                goto error_table_alloc;
 
@@ -1026,7 +1028,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_ring_buffer_c
 
        /* Allocate normal memory for channel (not shared) */
        shmobj = shm_object_table_alloc(handle->table, shmsize, SHM_OBJECT_MEM,
-                       -1, -1);
+                       -1, -1, populate);
        if (!shmobj)
                goto error_append;
        /* struct lttng_ust_ring_buffer_channel is at object 0, offset 0 (hardcoded) */
@@ -1089,13 +1091,14 @@ struct lttng_ust_shm_handle *channel_handle_create(void *data,
 {
        struct lttng_ust_shm_handle *handle;
        struct shm_object *object;
+       bool populate = lttng_ust_map_populate_is_enabled();
 
-       handle = zmalloc(sizeof(struct lttng_ust_shm_handle));
+       handle = zmalloc_populate(sizeof(struct lttng_ust_shm_handle), populate);
        if (!handle)
                return NULL;
 
        /* Allocate table for channel + per-cpu buffers */
-       handle->table = shm_object_table_create(1 + num_possible_cpus());
+       handle->table = shm_object_table_create(1 + get_possible_cpus_array_len(), populate);
        if (!handle->table)
                goto error_table_alloc;
        /* Add channel object */
@@ -1124,7 +1127,7 @@ int channel_handle_add_stream(struct lttng_ust_shm_handle *handle,
        /* Add stream object */
        object = shm_object_table_append_shm(handle->table,
                        shm_fd, wakeup_fd, stream_nr,
-                       memory_map_size);
+                       memory_map_size, lttng_ust_map_populate_cpu_is_enabled(stream_nr));
        if (!object)
                return -EINVAL;
        return 0;
@@ -1190,7 +1193,7 @@ struct lttng_ust_ring_buffer *channel_get_ring_buffer(
        if (config->alloc == RING_BUFFER_ALLOC_GLOBAL) {
                cpu = 0;
        } else {
-               if (cpu >= num_possible_cpus())
+               if (cpu >= get_possible_cpus_array_len())
                        return NULL;
        }
        ref = &chan->backend.buf[cpu].shmp._ref;
@@ -1235,7 +1238,7 @@ int ring_buffer_stream_close_wait_fd(const struct lttng_ust_ring_buffer_config *
        if (config->alloc == RING_BUFFER_ALLOC_GLOBAL) {
                cpu = 0;
        } else {
-               if (cpu >= num_possible_cpus())
+               if (cpu >= get_possible_cpus_array_len())
                        return -EINVAL;
        }
        ref = &chan->backend.buf[cpu].shmp._ref;
@@ -1253,7 +1256,7 @@ int ring_buffer_stream_close_wakeup_fd(const struct lttng_ust_ring_buffer_config
        if (config->alloc == RING_BUFFER_ALLOC_GLOBAL) {
                cpu = 0;
        } else {
-               if (cpu >= num_possible_cpus())
+               if (cpu >= get_possible_cpus_array_len())
                        return -EINVAL;
        }
        ref = &chan->backend.buf[cpu].shmp._ref;
@@ -2582,7 +2585,7 @@ void lib_ring_buffer_check_deliver_slow(const struct lttng_ust_ring_buffer_confi
  */
 void lttng_ringbuffer_alloc_tls(void)
 {
-       asm volatile ("" : : "m" (URCU_TLS(lib_ring_buffer_nesting)));
+       __asm__ __volatile__ ("" : : "m" (URCU_TLS(lib_ring_buffer_nesting)));
 }
 
 void lib_ringbuffer_signal_init(void)
This page took 0.025178 seconds and 4 git commands to generate.