X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libringbuffer%2Fbackend_internal.h;h=b8a1699046ff293fc8fc0c2df447fd419753e7a5;hb=071dec4386ff4c89d8b0f92ab1a8dbf079abd50c;hp=9edd2e59f8b348bc5f8352e589d3499fcb0f476d;hpb=15500a1bb134d6bbd409da5568308c2a41291928;p=lttng-ust.git diff --git a/libringbuffer/backend_internal.h b/libringbuffer/backend_internal.h index 9edd2e59..b8a16990 100644 --- a/libringbuffer/backend_internal.h +++ b/libringbuffer/backend_internal.h @@ -1,28 +1,16 @@ -#ifndef _LTTNG_RING_BUFFER_BACKEND_INTERNAL_H -#define _LTTNG_RING_BUFFER_BACKEND_INTERNAL_H - /* - * libringbuffer/backend_internal.h - * - * Ring buffer backend (internal helpers). + * SPDX-License-Identifier: LGPL-2.1-only * * Copyright (C) 2005-2012 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Ring buffer backend (internal helpers). */ +#ifndef _LTTNG_RING_BUFFER_BACKEND_INTERNAL_H +#define _LTTNG_RING_BUFFER_BACKEND_INTERNAL_H + +#include +#include #include #include @@ -30,33 +18,44 @@ #include "backend_types.h" #include "frontend_types.h" #include "shm.h" +#include "ust-helper.h" /* Ring buffer backend API presented to the frontend */ /* Ring buffer and channel backend create/free */ +LTTNG_HIDDEN int lib_ring_buffer_backend_create(struct lttng_ust_lib_ring_buffer_backend *bufb, struct channel_backend *chan, int cpu, struct lttng_ust_shm_handle *handle, struct shm_object *shmobj); +LTTNG_HIDDEN void channel_backend_unregister_notifiers(struct channel_backend *chanb); +LTTNG_HIDDEN void lib_ring_buffer_backend_free(struct lttng_ust_lib_ring_buffer_backend *bufb); +LTTNG_HIDDEN int channel_backend_init(struct channel_backend *chanb, const char *name, const struct lttng_ust_lib_ring_buffer_config *config, size_t subbuf_size, size_t num_subbuf, struct lttng_ust_shm_handle *handle, const int *stream_fds); +LTTNG_HIDDEN void channel_backend_free(struct channel_backend *chanb, struct lttng_ust_shm_handle *handle); +LTTNG_HIDDEN void lib_ring_buffer_backend_reset(struct lttng_ust_lib_ring_buffer_backend *bufb, struct lttng_ust_shm_handle *handle); +LTTNG_HIDDEN void channel_backend_reset(struct channel_backend *chanb); +LTTNG_HIDDEN int lib_ring_buffer_backend_init(void); +LTTNG_HIDDEN void lib_ring_buffer_backend_exit(void); +LTTNG_HIDDEN extern void _lib_ring_buffer_write(struct lttng_ust_lib_ring_buffer_backend *bufb, size_t offset, const void *src, size_t len, ssize_t pagecpy); @@ -196,6 +195,53 @@ int subbuffer_id_check_index(const struct lttng_ust_lib_ring_buffer_config *conf return 0; } +static inline +int lib_ring_buffer_backend_get_pages(const struct lttng_ust_lib_ring_buffer_config *config, + struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_ust_lib_ring_buffer_backend_pages **backend_pages) +{ + struct lttng_ust_lib_ring_buffer_backend *bufb = &ctx->buf->backend; + struct channel_backend *chanb = &ctx->chan->backend; + struct lttng_ust_shm_handle *handle = ctx->handle; + size_t sbidx; + size_t offset = ctx->buf_offset; + struct lttng_ust_lib_ring_buffer_backend_subbuffer *wsb; + struct lttng_ust_lib_ring_buffer_backend_pages_shmp *rpages; + unsigned long sb_bindex, id; + struct lttng_ust_lib_ring_buffer_backend_pages *_backend_pages; + + offset &= chanb->buf_size - 1; + sbidx = offset >> chanb->subbuf_size_order; + wsb = shmp_index(handle, bufb->buf_wsb, sbidx); + if (caa_unlikely(!wsb)) + return -1; + id = wsb->id; + sb_bindex = subbuffer_id_get_index(config, id); + rpages = shmp_index(handle, bufb->array, sb_bindex); + if (caa_unlikely(!rpages)) + return -1; + CHAN_WARN_ON(ctx->chan, + config->mode == RING_BUFFER_OVERWRITE + && subbuffer_id_is_noref(config, id)); + _backend_pages = shmp(handle, rpages->shmp); + if (caa_unlikely(!_backend_pages)) + return -1; + *backend_pages = _backend_pages; + return 0; +} + +/* Get backend pages from cache. */ +static inline +struct lttng_ust_lib_ring_buffer_backend_pages * + lib_ring_buffer_get_backend_pages_from_ctx(const struct lttng_ust_lib_ring_buffer_config *config, + struct lttng_ust_lib_ring_buffer_ctx *ctx) +{ + if (caa_unlikely(ctx->ctx_len + < sizeof(struct lttng_ust_lib_ring_buffer_ctx))) + return NULL; + return ctx->backend_pages; +} + /* * The ring buffer can count events recorded and overwritten per buffer, * but it is disabled by default due to its performance overhead. @@ -545,6 +591,28 @@ int update_read_sb_index(const struct lttng_ust_lib_ring_buffer_config *config, #define inline_memcpy(dest, src, n) memcpy(dest, src, n) #endif +static inline __attribute__((always_inline)) +void lttng_inline_memcpy(void *dest, const void *src, + unsigned long len) +{ + switch (len) { + case 1: + *(uint8_t *) dest = *(const uint8_t *) src; + break; + case 2: + *(uint16_t *) dest = *(const uint16_t *) src; + break; + case 4: + *(uint32_t *) dest = *(const uint32_t *) src; + break; + case 8: + *(uint64_t *) dest = *(const uint64_t *) src; + break; + default: + inline_memcpy(dest, src, len); + } +} + /* * Use the architecture-specific memcpy implementation for constant-sized * inputs, but rely on an inline memcpy for length statically unknown. @@ -556,7 +624,7 @@ do { \ if (__builtin_constant_p(len)) \ memcpy(dest, src, __len); \ else \ - inline_memcpy(dest, src, __len); \ + lttng_inline_memcpy(dest, src, __len); \ } while (0) /*