Move to kernel style SPDX license identifiers
[lttng-ust.git] / libringbuffer / backend.h
index 2dec003883c7536ce3912b94b4a9987cc5d3b777..98c194ca5bf988603646071b778ac936b1add00d 100644 (file)
@@ -1,31 +1,18 @@
-#ifndef _LTTNG_RING_BUFFER_BACKEND_H
-#define _LTTNG_RING_BUFFER_BACKEND_H
-
 /*
- * libringbuffer/backend.h
- *
- * Ring buffer backend (API).
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
  * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * 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 (API).
  *
  * Credits to Steven Rostedt for proposing to use an extra-subbuffer owned by
  * the reader in flight recorder mode.
  */
 
+#ifndef _LTTNG_RING_BUFFER_BACKEND_H
+#define _LTTNG_RING_BUFFER_BACKEND_H
+
+#include <stddef.h>
 #include <unistd.h>
 
 /* Internal helpers */
@@ -71,41 +58,29 @@ lib_ring_buffer_read_offset_address(struct lttng_ust_lib_ring_buffer_backend *bu
  * backend-specific memcpy() operation. Calls the slow path (_ring_buffer_write)
  * if copy is crossing a page boundary.
  */
-static inline
+static inline __attribute__((always_inline))
 void lib_ring_buffer_write(const struct lttng_ust_lib_ring_buffer_config *config,
                           struct lttng_ust_lib_ring_buffer_ctx *ctx,
                           const void *src, size_t len)
 {
-       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_pages_shmp *rpages;
-       unsigned long sb_bindex, id;
        struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages;
        void *p;
 
        if (caa_unlikely(!len))
                return;
-       offset &= chanb->buf_size - 1;
-       sbidx = offset >> chanb->subbuf_size_order;
-       id = shmp_index(handle, bufb->buf_wsb, sbidx)->id;
-       sb_bindex = subbuffer_id_get_index(config, id);
-       rpages = shmp_index(handle, bufb->array, sb_bindex);
-       if (caa_unlikely(!rpages))
-               return;
-       CHAN_WARN_ON(ctx->chan,
-                    config->mode == RING_BUFFER_OVERWRITE
-                    && subbuffer_id_is_noref(config, id));
        /*
         * Underlying layer should never ask for writes across
         * subbuffers.
         */
-       CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
-       backend_pages = shmp(handle, rpages->shmp);
-       if (caa_unlikely(!backend_pages))
-               return;
+       CHAN_WARN_ON(chanb, (offset & (chanb->buf_size - 1)) + len > chanb->buf_size);
+       backend_pages = lib_ring_buffer_get_backend_pages_from_ctx(config, ctx);
+       if (caa_unlikely(!backend_pages)) {
+               if (lib_ring_buffer_backend_get_pages(config, ctx, &backend_pages))
+                       return;
+       }
        p = shmp_index(handle, backend_pages->p, offset & (chanb->subbuf_size - 1));
        if (caa_unlikely(!p))
                return;
@@ -118,7 +93,7 @@ void lib_ring_buffer_write(const struct lttng_ust_lib_ring_buffer_config *config
  * terminating character is found in @src. Returns the number of bytes
  * copied. Does *not* terminate @dest with NULL terminating character.
  */
-static inline
+static inline __attribute__((always_inline))
 size_t lib_ring_buffer_do_strcpy(const struct lttng_ust_lib_ring_buffer_config *config,
                char *dest, const char *src, size_t len)
 {
@@ -154,52 +129,51 @@ size_t lib_ring_buffer_do_strcpy(const struct lttng_ust_lib_ring_buffer_config *
  * character is found in @src before @len - 1 characters are copied, pad
  * the buffer with @pad characters (e.g. '#').
  */
-static inline
+static inline __attribute__((always_inline))
 void lib_ring_buffer_strcpy(const struct lttng_ust_lib_ring_buffer_config *config,
                           struct lttng_ust_lib_ring_buffer_ctx *ctx,
                           const char *src, size_t len, int pad)
 {
-       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, count;
+       size_t count;
        size_t offset = ctx->buf_offset;
-       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;
+       void *p;
 
        if (caa_unlikely(!len))
                return;
-       offset &= chanb->buf_size - 1;
-       sbidx = offset >> chanb->subbuf_size_order;
-       id = shmp_index(handle, bufb->buf_wsb, sbidx)->id;
-       sb_bindex = subbuffer_id_get_index(config, id);
-       rpages = shmp_index(handle, bufb->array, sb_bindex);
-       CHAN_WARN_ON(ctx->chan,
-                    config->mode == RING_BUFFER_OVERWRITE
-                    && subbuffer_id_is_noref(config, id));
        /*
         * Underlying layer should never ask for writes across
         * subbuffers.
         */
-       CHAN_WARN_ON(chanb, offset >= chanb->buf_size);
-       count = lib_ring_buffer_do_strcpy(config,
-                       shmp_index(handle, shmp(handle, rpages->shmp)->p,
-                               offset & (chanb->subbuf_size - 1)),
-                       src, len - 1);
+       CHAN_WARN_ON(chanb, (offset & (chanb->buf_size - 1)) + len > chanb->buf_size);
+       backend_pages = lib_ring_buffer_get_backend_pages_from_ctx(config, ctx);
+       if (caa_unlikely(!backend_pages)) {
+               if (lib_ring_buffer_backend_get_pages(config, ctx, &backend_pages))
+                       return;
+       }
+       p = shmp_index(handle, backend_pages->p, offset & (chanb->subbuf_size - 1));
+       if (caa_unlikely(!p))
+               return;
+
+       count = lib_ring_buffer_do_strcpy(config, p, src, len - 1);
        offset += count;
        /* Padding */
        if (caa_unlikely(count < len - 1)) {
                size_t pad_len = len - 1 - count;
 
-               lib_ring_buffer_do_memset(shmp_index(handle, shmp(handle, rpages->shmp)->p,
-                               offset & (chanb->subbuf_size - 1)),
-                       pad, pad_len);
+               p = shmp_index(handle, backend_pages->p, offset & (chanb->subbuf_size - 1));
+               if (caa_unlikely(!p))
+                       return;
+               lib_ring_buffer_do_memset(p, pad, pad_len);
                offset += pad_len;
        }
        /* Final '\0' */
-       lib_ring_buffer_do_memset(shmp_index(handle, shmp(handle, rpages->shmp)->p,
-                               offset & (chanb->subbuf_size - 1)),
-                       '\0', 1);
+       p = shmp_index(handle, backend_pages->p, offset & (chanb->subbuf_size - 1));
+       if (caa_unlikely(!p))
+               return;
+       lib_ring_buffer_do_memset(p, '\0', 1);
        ctx->buf_offset += len;
 }
 
This page took 0.027484 seconds and 4 git commands to generate.