X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libringbuffer%2Fring_buffer_backend.c;h=e949a5e292d2048f306760f329f64d668a0c30cd;hb=12bcbbdbd7eb6b3cb111ab91b316b14ac210ceb2;hp=50cb1938a63ca9bf017887c43b72873c38e81354;hpb=b5a3dfa5923801ddeea22ce70758d1e61200eac2;p=lttng-ust.git diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 50cb1938..e949a5e2 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -6,11 +6,12 @@ * Dual LGPL v2.1/GPL v2 license. */ +#define _GNU_SOURCE #include +#include -#include "ust/core.h" - -#include +#include +#include "vatomic.h" #include "backend.h" #include "frontend.h" #include "smp.h" @@ -129,14 +130,6 @@ int lib_ring_buffer_backend_create(struct lttng_ust_lib_ring_buffer_backend *buf handle, shmobj); } -void lib_ring_buffer_backend_free(struct lttng_ust_lib_ring_buffer_backend *bufb) -{ - /* bufb->buf_wsb will be freed by shm teardown */ - /* bufb->array[i] will be freed by shm teardown */ - /* bufb->array will be freed by shm teardown */ - bufb->allocated = 0; -} - void lib_ring_buffer_backend_reset(struct lttng_ust_lib_ring_buffer_backend *bufb, struct lttng_ust_shm_handle *handle) { @@ -190,7 +183,6 @@ void channel_backend_reset(struct channel_backend *chanb) * @chanb: channel backend * @name: channel name * @config: client ring buffer configuration - * @priv: client private data * @parent: dentry of parent directory, %NULL for root directory * @subbuf_size: size of sub-buffers (> PAGE_SIZE, power of 2) * @num_subbuf: number of sub-buffers (power of 2) @@ -207,7 +199,7 @@ void channel_backend_reset(struct channel_backend *chanb) int channel_backend_init(struct channel_backend *chanb, const char *name, const struct lttng_ust_lib_ring_buffer_config *config, - void *priv, size_t subbuf_size, size_t num_subbuf, + size_t subbuf_size, size_t num_subbuf, struct lttng_ust_shm_handle *handle) { struct channel *chan = caa_container_of(chanb, struct channel, backend); @@ -226,16 +218,18 @@ int channel_backend_init(struct channel_backend *chanb, return -EINVAL; /* - * Make sure the number of subbuffers and subbuffer size are power of 2. + * Make sure the number of subbuffers and subbuffer size are + * power of 2, and nonzero. */ - CHAN_WARN_ON(chanb, hweight32(subbuf_size) != 1); - CHAN_WARN_ON(chanb, hweight32(num_subbuf) != 1); + if (!subbuf_size || (subbuf_size & (subbuf_size - 1))) + return -EINVAL; + if (!num_subbuf || (num_subbuf & (num_subbuf - 1))) + return -EINVAL; ret = subbuffer_id_check_index(config, num_subbuf); if (ret) return ret; - chanb->priv = priv; chanb->buf_size = num_subbuf * subbuf_size; chanb->subbuf_size = subbuf_size; chanb->buf_size_order = get_count_order(chanb->buf_size); @@ -303,6 +297,7 @@ int channel_backend_init(struct channel_backend *chanb, buf = shmp(handle, chanb->buf[0].shmp); if (!buf) goto end; + set_shmp(buf->self, chanb->buf[0].shmp._ref); ret = lib_ring_buffer_create(buf, chanb, -1, handle, shmobj); if (ret) @@ -313,15 +308,6 @@ int channel_backend_init(struct channel_backend *chanb, return 0; free_bufs: - if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) { - for_each_possible_cpu(i) { - struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[i].shmp); - - if (!buf->backend.allocated) - continue; - lib_ring_buffer_free(buf, handle); - } - } /* We only free the buffer data upon shm teardown */ end: return -ENOMEM; @@ -336,24 +322,7 @@ end: void channel_backend_free(struct channel_backend *chanb, struct lttng_ust_shm_handle *handle) { - const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config; - unsigned int i; - - if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) { - for_each_possible_cpu(i) { - struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[i].shmp); - - if (!buf->backend.allocated) - continue; - lib_ring_buffer_free(buf, handle); - } - } else { - struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[0].shmp); - - CHAN_WARN_ON(chanb, !buf->backend.allocated); - lib_ring_buffer_free(buf, handle); - } - /* We only free the buffer data upon shm teardown */ + /* SHM teardown takes care of everything */ } /**