Take NUMA configuration into account for UST buffer allocation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 5 Nov 2017 12:45:02 +0000 (07:45 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 5 Nov 2017 13:26:54 +0000 (08:26 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
configure.ac
libringbuffer/Makefile.am
libringbuffer/ring_buffer_backend.c
libringbuffer/ring_buffer_frontend.c
libringbuffer/shm.c
libringbuffer/shm.h

index 08ca3b6587438405864385dcfaf96e78b0a69237..727e58f3d5538069df16bb2c702ca7969472615c 100644 (file)
@@ -247,6 +247,9 @@ AC_CHECK_LIB([urcu-bp], [synchronize_rcu_bp], [], [AC_MSG_ERROR([Cannot find lib
 # urcu - check that URCU lib is at least version 0.6
 AC_CHECK_LIB([urcu-bp], [call_rcu_bp], [], [AC_MSG_ERROR([liburcu 0.6 or newer is needed, please update your version or use [LDFLAGS]=-Ldir to specify the right location.])])
 
+# numa - check that numa lib is available
+AC_CHECK_LIB([numa], [numa_available], [], [AC_MSG_ERROR([libnuma is required, please install it (e.g. libnuma-dev) or use [LDFLAGS]=-Ldir to specify the right location.])])
+
 # optional linux/perf_event.h
 AC_CHECK_HEADERS([linux/perf_event.h], [have_perf_event=yes], [])
 
index 9c3b99380305186f62a33a2060709664eac505c2..34ad690753e65df98e55502d9a6623de8aadff8b 100644 (file)
@@ -15,6 +15,7 @@ libringbuffer_la_SOURCES = \
 
 libringbuffer_la_LIBADD = \
        -lpthread \
-       -lrt
+       -lrt \
+       -lnuma
 
 libringbuffer_la_CFLAGS = -DUST_COMPONENT="libringbuffer" $(AM_CFLAGS)
index 72c49102fc935e0995ac08982a1703118d87ac23..a0ef74461bd12606b9d3bd6eaa14ac2ae9f600ab 100644 (file)
@@ -351,7 +351,7 @@ int channel_backend_init(struct channel_backend *chanb,
                        struct shm_object *shmobj;
 
                        shmobj = shm_object_table_alloc(handle->table, shmsize,
-                                       SHM_OBJECT_SHM, stream_fds[i]);
+                                       SHM_OBJECT_SHM, stream_fds[i], i);
                        if (!shmobj)
                                goto end;
                        align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer));
@@ -370,7 +370,7 @@ int channel_backend_init(struct channel_backend *chanb,
                struct lttng_ust_lib_ring_buffer *buf;
 
                shmobj = shm_object_table_alloc(handle->table, shmsize,
-                                       SHM_OBJECT_SHM, stream_fds[0]);
+                                       SHM_OBJECT_SHM, stream_fds[0], -1);
                if (!shmobj)
                        goto end;
                align_shm(shmobj, __alignof__(struct lttng_ust_lib_ring_buffer));
index 396b0064b5b13dd59cc4488008c9df9e2f75c9fb..d822039330853a7bce60a65f0ab6efb502188dcd 100644 (file)
@@ -1014,7 +1014,7 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
 
        /* Allocate normal memory for channel (not shared) */
        shmobj = shm_object_table_alloc(handle->table, shmsize, SHM_OBJECT_MEM,
-                       -1);
+                       -1, -1);
        if (!shmobj)
                goto error_append;
        /* struct channel is at object 0, offset 0 (hardcoded) */
index ea946ea3f5e2a6d2e46d3297ebe925135164272e..135a2007b0e780221a0aa3cddeffe528a6e54733 100644 (file)
@@ -32,6 +32,7 @@
 #include <dirent.h>
 #include <lttng/align.h>
 #include <limits.h>
+#include <numa.h>
 #include <helper.h>
 #include <ust-fd.h>
 
@@ -243,18 +244,33 @@ alloc_error:
 struct shm_object *shm_object_table_alloc(struct shm_object_table *table,
                        size_t memory_map_size,
                        enum shm_object_type type,
-                       int stream_fd)
+                       int stream_fd,
+                       int cpu)
 {
+       int oldnode, node;
+       struct shm_object *shm_object;
+
+       oldnode = numa_preferred();
+       if (cpu >= 0) {
+               node = numa_node_of_cpu(cpu);
+               if (node >= 0)
+                       numa_set_preferred(node);
+       }
+       if (cpu < 0 || node < 0)
+               numa_set_localalloc();
        switch (type) {
        case SHM_OBJECT_SHM:
-               return _shm_object_table_alloc_shm(table, memory_map_size,
+               shm_object = _shm_object_table_alloc_shm(table, memory_map_size,
                                stream_fd);
+               break;
        case SHM_OBJECT_MEM:
-               return _shm_object_table_alloc_mem(table, memory_map_size);
+               shm_object = _shm_object_table_alloc_mem(table, memory_map_size);
+               break;
        default:
                assert(0);
        }
-       return NULL;
+       numa_set_preferred(oldnode);
+       return shm_object;
 }
 
 struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
index 355d4d98bf6d054a62fe001b9d430f10bc265d26..1f293e3847e44d70fb06f97cb361abf7a2832144 100644 (file)
@@ -89,7 +89,8 @@ struct shm_object_table *shm_object_table_create(size_t max_nb_obj);
 struct shm_object *shm_object_table_alloc(struct shm_object_table *table,
                        size_t memory_map_size,
                        enum shm_object_type type,
-                       const int stream_fd);
+                       const int stream_fd,
+                       int cpu);
 struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
                        int shm_fd, int wakeup_fd, uint32_t stream_nr,
                        size_t memory_map_size);
This page took 0.028697 seconds and 4 git commands to generate.