Namespace lttng/align.h macros
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 15 Oct 2020 21:50:50 +0000 (17:50 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 16 Oct 2020 20:27:39 +0000 (16:27 -0400)
These macros are part of the API and should have been namespaced
initialy. Namespace them and add backwards compatibility defines, make
sure to include the relevant system headers first for platforms that
have conflicting defines.

Change-Id: If2929ec2202dbde896614a25440ab200514ef4ad
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 files changed:
include/lttng/align.h
include/lttng/ringbuffer-config.h
liblttng-ust-ctl/ustctl.c
liblttng-ust-libc-wrapper/lttng-ust-malloc.c
liblttng-ust/lttng-filter-specialize.c
liblttng-ust/lttng-ring-buffer-client.h
liblttng-ust/lttng-ring-buffer-metadata-client.h
liblttng-ust/lttng-ust-comm.c
liblttng-ust/lttng-ust-elf.c
libringbuffer/ring_buffer_backend.c
libringbuffer/ring_buffer_frontend.c
libringbuffer/shm.c
tests/ust-basic-tracing/ust-basic-tracing.c
tests/ust-multi-test/ust-multi-test.c

index 8f227eb9ecb49b04cd4d48f1ef763c4a8d6acabb..3f43a3b4d8beb5a02e0c908e9a969ea8f26fabbd 100644 (file)
 #include <unistd.h>
 #include <limits.h>
 
-#ifndef PAGE_SIZE      /* Cygwin limits.h defines its own PAGE_SIZE */
-#define PAGE_SIZE              sysconf(_SC_PAGE_SIZE)
+#ifdef __FreeBSD__
+#include <machine/param.h>
 #endif
 
-#ifndef PAGE_MASK      /* FreeBSD and macOS defines their own PAGE_MASK. */
-#define PAGE_MASK              (~(PAGE_SIZE - 1))
+#ifdef _SC_PAGE_SIZE
+#define LTTNG_UST_PAGE_SIZE    sysconf(_SC_PAGE_SIZE)
+#elif defined(PAGE_SIZE)
+#define LTTNG_UST_PAGE_SIZE    PAGE_SIZE
+#else
+#error "Please add page size detection for your OS."
 #endif
-#define __ALIGN_MASK(v, mask)  (((v) + (mask)) & ~(mask))
-#ifndef ALIGN          /* FreeBSD and macOS defines their own ALIGN. */
-#define ALIGN(v, align)                __ALIGN_MASK(v, (__typeof__(v)) (align) - 1)
-#endif
-#define PAGE_ALIGN(addr)       ALIGN(addr, PAGE_SIZE)
+
+#define LTTNG_UST_PAGE_MASK    (~(LTTNG_UST_PAGE_SIZE - 1))
+
+#define __LTTNG_UST_ALIGN_MASK(v, mask)        (((v) + (mask)) & ~(mask))
+#define LTTNG_UST_ALIGN(v, align)      __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1)
+#define LTTNG_UST_PAGE_ALIGN(addr)     LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE)
 
 /**
- * offset_align - Calculate the offset needed to align an object on its natural
- *                alignment towards higher addresses.
+ * lttng_ust_offset_align - Calculate the offset needed to align an object on
+ *                its natural alignment towards higher addresses.
  * @align_drift:  object offset from an "alignment"-aligned address.
  * @alignment:    natural object alignment. Must be non-zero, power of 2.
  *
  * Returns the offset that must be added to align towards higher
  * addresses.
  */
-#define offset_align(align_drift, alignment)                                  \
+#define lttng_ust_offset_align(align_drift, alignment)                        \
        ({                                                                     \
                LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0                    \
                                   || ((alignment) & ((alignment) - 1)));      \
        })
 
 /**
- * offset_align_floor - Calculate the offset needed to align an object
- *                      on its natural alignment towards lower addresses.
+ * lttng_ust_offset_align_floor - Calculate the offset needed to align an
+ *                object on its natural alignment towards lower addresses.
  * @align_drift:  object offset from an "alignment"-aligned address.
  * @alignment:    natural object alignment. Must be non-zero, power of 2.
  *
  * Returns the offset that must be substracted to align towards lower addresses.
  */
-#define offset_align_floor(align_drift, alignment)                            \
+#define lttng_ust_offset_align_floor(align_drift, alignment)                  \
        ({                                                                     \
                LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0                    \
                                   || ((alignment) & ((alignment) - 1)));      \
                (((align_drift) - (alignment)) & ((alignment) - 1));           \
        })
 
+/*
+ * Non-namespaced defines for backwards compatibility,
+ * introduced in 2.13, should be removed in the future.
+ */
+
+/* Cygwin limits.h defines its own PAGE_SIZE */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE      LTTNG_UST_PAGE_SIZE
+#endif
+
+/* FreeBSD and macOS defines their own PAGE_MASK. */
+#ifndef PAGE_MASK
+#define PAGE_MASK      LTTNG_UST_PAGE_MASK
+#endif
+
+/* FreeBSD machine/param.h defines its own ALIGN */
+#ifndef ALIGN
+#define ALIGN          LTTNG_UST_ALIGN
+#endif
+
+#ifndef PAGE_ALIGN
+#define PAGE_ALIGN     LTTNG_UST_PAGE_ALIGN
+#endif
+
+#ifndef offset_align
+#define offset_align lttng_ust_offset_align
+#endif
+
+#ifndef offset_align_floor
+#define offset_align_floor lttng_ust_offset_align_floor
+#endif
+
 #endif /* _UST_ALIGN_H */
index 421a8637c5ca8fec432f3aa219527cdba12c92b6..8752e36993403ace30ba7c0efaaacd763dc32f68 100644 (file)
@@ -346,7 +346,7 @@ unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type);
 static inline
 unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type)
 {
-       return offset_align(align_drift, size_of_type);
+       return lttng_ust_offset_align(align_drift, size_of_type);
 }
 
 #else
index a6fb6d83380c5bb23fc0788c5249b913163a8ea0..01214eca60129650c12136205b294b9e1e1993c6 100644 (file)
@@ -1456,7 +1456,7 @@ int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
        chan = consumer_chan->chan->chan;
        *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
                consumer_chan->chan->handle);
-       *len = PAGE_ALIGN(*len);
+       *len = LTTNG_UST_PAGE_ALIGN(*len);
        return 0;
 }
 
index f9081a09d993e9090a7953cbff35927b2f9b56eb..1e9a25e5c89dbbefbf6ff819a3a37a2e7d8d8c24 100644 (file)
@@ -121,7 +121,7 @@ void *static_calloc_aligned(size_t nmemb, size_t size, size_t alignment)
        res_offset = CMM_LOAD_SHARED(static_calloc_buf_offset);
        do {
                prev_offset = res_offset;
-               aligned_offset = ALIGN(prev_offset + sizeof(size_t), alignment);
+               aligned_offset = LTTNG_UST_ALIGN(prev_offset + sizeof(size_t), alignment);
                new_offset = aligned_offset + nmemb * size;
                if (new_offset > sizeof(static_calloc_buf)) {
                        abort();
index ef45904fff9a84b080e4198e5c143cb112a34a41..ba46a103a253ae5b045660c1780a053e61eb344e 100644 (file)
@@ -74,7 +74,7 @@ static ssize_t bytecode_reserve_data(struct bytecode_runtime *runtime,
                size_t align, size_t len)
 {
        ssize_t ret;
-       size_t padding = offset_align(runtime->data_len, align);
+       size_t padding = lttng_ust_offset_align(runtime->data_len, align);
        size_t new_len = runtime->data_len + padding + len;
        size_t new_alloc_len = new_len;
        size_t old_alloc_len = runtime->data_alloc_len;
index 62d1ff82552fb8b04abc1d2ab8162bfe4c4bb9fb..3233f199a210c694a6e9c712f6198d1ce383363e 100644 (file)
@@ -474,7 +474,7 @@ static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t ts
        header->ctx.content_size =
                (uint64_t) data_size * CHAR_BIT;                /* in bits */
        header->ctx.packet_size =
-               (uint64_t) PAGE_ALIGN(data_size) * CHAR_BIT;    /* in bits */
+               (uint64_t) LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT;  /* in bits */
 
        records_lost += lib_ring_buffer_get_records_lost_full(&client_config, buf);
        records_lost += lib_ring_buffer_get_records_lost_wrap(&client_config, buf);
index 1ca8b580d19ba5ae3582851d9b1536642787019f..cdf48b3bdb5a3982b348ee0f3dc8a8c9e57963c7 100644 (file)
@@ -139,7 +139,7 @@ static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t ts
        if (!header)
                return;
        header->content_size = data_size * CHAR_BIT;            /* in bits */
-       header->packet_size = PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
+       header->packet_size = LTTNG_UST_PAGE_ALIGN(data_size) * CHAR_BIT; /* in bits */
        /*
         * We do not care about the records lost count, because the metadata
         * channel waits and retry.
index b265bcd3c61e254c9e8dc889d56fef389f2c18e1..4432a5da396d1a2f574ab74d5200e209ada277a3 100644 (file)
@@ -42,6 +42,7 @@
 #include <urcu/futex.h>
 #include <urcu/compiler.h>
 
+#include <lttng/align.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-abi.h>
 #include <lttng/ust.h>
@@ -1173,7 +1174,7 @@ void cleanup_sock_info(struct sock_info *sock_info, int exiting)
        if (sock_info->wait_shm_mmap) {
                long page_size;
 
-               page_size = sysconf(_SC_PAGE_SIZE);
+               page_size = LTTNG_UST_PAGE_SIZE;
                if (page_size <= 0) {
                        if (!page_size) {
                                errno = EINVAL;
index b7c0acb5d0d04c7def84ed4de4bfa85eadf3f0e3..a02ba8d9eb38e3eb418f02dd82f53c270694f03c 100644 (file)
@@ -449,7 +449,7 @@ int lttng_ust_elf_get_build_id_from_segment(
                size_t read_len;
 
                /* Align start of note entry */
-               offset += offset_align(offset, ELF_NOTE_ENTRY_ALIGN);
+               offset += lttng_ust_offset_align(offset, ELF_NOTE_ENTRY_ALIGN);
                if (offset >= segment_end) {
                        break;
                }
@@ -474,7 +474,7 @@ int lttng_ust_elf_get_build_id_from_segment(
 
                offset += sizeof(nhdr) + nhdr.n_namesz;
                /* Align start of desc entry */
-               offset += offset_align(offset, ELF_NOTE_DESC_ALIGN);
+               offset += lttng_ust_offset_align(offset, ELF_NOTE_DESC_ALIGN);
 
                if (nhdr.n_type != NT_GNU_BUILD_ID) {
                        /*
index 46df102b545facd94a8d2b7748f40b9dcdfe9420..412180bdfc8c16ab2252410ec12971cee7a075f6 100644 (file)
@@ -25,6 +25,7 @@
 #include <urcu/arch.h>
 #include <limits.h>
 
+#include <lttng/align.h>
 #include <lttng/ringbuffer-config.h>
 #include "vatomic.h"
 #include "backend.h"
@@ -64,7 +65,7 @@ int lib_ring_buffer_backend_allocate(const struct lttng_ust_lib_ring_buffer_conf
        if (extra_reader_sb)
                num_subbuf_alloc++;
 
-       page_size = sysconf(_SC_PAGE_SIZE);
+       page_size = LTTNG_UST_PAGE_SIZE;
        if (page_size <= 0) {
                goto page_size_error;
        }
@@ -281,7 +282,7 @@ int channel_backend_init(struct channel_backend *chanb,
        if (!name)
                return -EPERM;
 
-       page_size = sysconf(_SC_PAGE_SIZE);
+       page_size = LTTNG_UST_PAGE_SIZE;
        if (page_size <= 0) {
                return -ENOMEM;
        }
@@ -321,28 +322,28 @@ int channel_backend_init(struct channel_backend *chanb,
        memcpy(&chanb->config, config, sizeof(*config));
 
        /* Per-cpu buffer size: control (prior to backend) */
-       shmsize = offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer));
+       shmsize = lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer);
-       shmsize += offset_align(shmsize, __alignof__(struct commit_counters_hot));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct commit_counters_hot));
        shmsize += sizeof(struct commit_counters_hot) * num_subbuf;
-       shmsize += offset_align(shmsize, __alignof__(struct commit_counters_cold));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct commit_counters_cold));
        shmsize += sizeof(struct commit_counters_cold) * num_subbuf;
        /* Sampled timestamp end */
-       shmsize += offset_align(shmsize, __alignof__(uint64_t));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(uint64_t));
        shmsize += sizeof(uint64_t) * num_subbuf;
 
        /* Per-cpu buffer size: backend */
        /* num_subbuf + 1 is the worse case */
        num_subbuf_alloc = num_subbuf + 1;
-       shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages_shmp));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages_shmp));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_pages_shmp) * num_subbuf_alloc;
-       shmsize += offset_align(shmsize, page_size);
+       shmsize += lttng_ust_offset_align(shmsize, page_size);
        shmsize += subbuf_size * num_subbuf_alloc;
-       shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_pages));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_pages) * num_subbuf_alloc;
-       shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_subbuffer));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_subbuffer));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_subbuffer) * num_subbuf;
-       shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_counts));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_backend_counts));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer_backend_counts) * num_subbuf;
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
index 4f1af6d07d1444c13e703a8942a5cd65b555f9a7..3828a84b8a289ce2ee6bf4c34ba6ee27c9bd1935 100644 (file)
@@ -1022,11 +1022,11 @@ struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buff
 
        /* Calculate the shm allocation layout */
        shmsize = sizeof(struct channel);
-       shmsize += offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_shmp));
+       shmsize += lttng_ust_offset_align(shmsize, __alignof__(struct lttng_ust_lib_ring_buffer_shmp));
        shmsize += sizeof(struct lttng_ust_lib_ring_buffer_shmp) * nr_streams;
        chansize = shmsize;
        if (priv_data_align)
-               shmsize += offset_align(shmsize, priv_data_align);
+               shmsize += lttng_ust_offset_align(shmsize, priv_data_align);
        shmsize += priv_data_size;
 
        /* Allocate normal memory for channel (not shared) */
index 9bcc7d9f80c16d29f491f276e9eb0d81e9e13971..9160c2184f9874841e30802bab2288be30f36894 100644 (file)
@@ -518,6 +518,6 @@ struct shm_ref zalloc_shm(struct shm_object *obj, size_t len)
 
 void align_shm(struct shm_object *obj, size_t align)
 {
-       size_t offset_len = offset_align(obj->allocated_len, align);
+       size_t offset_len = lttng_ust_offset_align(obj->allocated_len, align);
        obj->allocated_len += offset_len;
 }
index e9b9ea6d17a5697e640d5ae7f3a18bdb1ba9effd..98be01b30504b9b6a1d959d7484c4f995c71a3b1 100644 (file)
@@ -252,7 +252,7 @@ int consume_stream(struct lttng_ust_shm_handle *handle, int cpu, char *outfile)
                }
                read_size = lib_ring_buffer_get_read_data_size(
                        &chan->backend.config, buf, handle);
-               read_size = PAGE_ALIGN(read_size);
+               read_size = LTTNG_UST_PAGE_ALIGN(read_size);
                ptr = lib_ring_buffer_read_offset_address(
                        &buf->backend, 0, handle);
                printf("WRITE: copy %lu bytes\n", read_size);
index eb047655ac68402b89be269f4834728e1a7c6186..161cc27a9de2fe036933465be5bc12ce0592908b 100644 (file)
@@ -259,7 +259,7 @@ int consume_stream(struct lttng_ust_shm_handle *handle, int cpu, char *outfile)
                }
                read_size = lib_ring_buffer_get_read_data_size(
                        &chan->backend.config, buf, handle);
-               read_size = PAGE_ALIGN(read_size);
+               read_size = LTTNG_UST_PAGE_ALIGN(read_size);
                ptr = lib_ring_buffer_read_offset_address(
                        &buf->backend, 0, handle);
                printf("WRITE: copy %lu bytes\n", read_size);
This page took 0.033459 seconds and 4 git commands to generate.