From 4b68c31f1859175d2bd4e1b42f1b7d301e84760f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 5 Nov 2017 07:45:02 -0500 Subject: [PATCH] Take NUMA configuration into account for UST buffer allocation Signed-off-by: Mathieu Desnoyers --- configure.ac | 3 +++ libringbuffer/Makefile.am | 3 ++- libringbuffer/ring_buffer_backend.c | 4 ++-- libringbuffer/ring_buffer_frontend.c | 2 +- libringbuffer/shm.c | 24 ++++++++++++++++++++---- libringbuffer/shm.h | 3 ++- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 08ca3b65..727e58f3 100644 --- a/configure.ac +++ b/configure.ac @@ -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], []) diff --git a/libringbuffer/Makefile.am b/libringbuffer/Makefile.am index 9c3b9938..34ad6907 100644 --- a/libringbuffer/Makefile.am +++ b/libringbuffer/Makefile.am @@ -15,6 +15,7 @@ libringbuffer_la_SOURCES = \ libringbuffer_la_LIBADD = \ -lpthread \ - -lrt + -lrt \ + -lnuma libringbuffer_la_CFLAGS = -DUST_COMPONENT="libringbuffer" $(AM_CFLAGS) diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 72c49102..a0ef7446 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -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)); diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 396b0064..d8220393 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -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) */ diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index ea946ea3..135a2007 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -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, diff --git a/libringbuffer/shm.h b/libringbuffer/shm.h index 355d4d98..1f293e38 100644 --- a/libringbuffer/shm.h +++ b/libringbuffer/shm.h @@ -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); -- 2.34.1