Cleanup: namespace 'align' macros
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Jul 2021 17:58:10 +0000 (13:58 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Oct 2021 19:14:28 +0000 (15:14 -0400)
Remove the duplicate ALIGN() and ALIGN_TO() macro and replace them with
namespaced variants 'lttng_align_ceil()' and  'lttng_align_floor()'.

Change-Id: I683baccb4e97874e647cf557bad9653a336f4a6d
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/align.h
src/common/bytecode/bytecode.c
src/common/consumer/consumer.c
src/common/kernel-ctl/kernel-ctl.c
src/common/macros.h
src/common/userspace-probe.c
src/lib/lttng-ctl/lttng-ctl.c

index 81b92f86193d0501286212b3cd9211b13c14bc7b..024faf7fb5d9e32b6a39114d484e42c27d1ee9e4 100644 (file)
 #define PAGE_SIZE              sysconf(_SC_PAGE_SIZE)
 #endif
 
-#ifndef PAGE_MASK      /* macOS defines its own PAGE_MASK. */
-#define PAGE_MASK              (~(PAGE_SIZE - 1))
-#endif
-
-#define __ALIGN_MASK(v, mask)  (((v) + (mask)) & ~(mask))
 
-#ifndef ALIGN          /* macOS defines its own ALIGN. */
-#define ALIGN(v, align)                __ALIGN_MASK(v, (__typeof__(v)) (align) - 1)
-#endif
+/*
+ * Align value to the next multiple of align. Returns val if it already is a
+ * multiple of align. Align must be a power of two.
+ */
+#define __lttng_align_ceil_mask(v, mask)       (((v) + (mask)) & ~(mask))
 
-#define __ALIGN_FLOOR_MASK(v, mask)    ((v) & ~(mask))
+#define lttng_align_ceil(v, align) \
+       __lttng_align_ceil_mask(v, (__typeof__(v)) (align) - 1)
 
-#ifndef ALIGN_FLOOR
-#define ALIGN_FLOOR(v, align)  __ALIGN_FLOOR_MASK(v, (__typeof__(v)) (align) - 1)
-#endif
+/*
+ * Align value to the previous multiple of align. Returns val if it already is a
+ * multiple of align. Align must be a power of two.
+ */
+#define __lttng_align_floor_mask(v, mask)      ((v) & ~(mask))
 
-#define PAGE_ALIGN(addr)       ALIGN(addr, PAGE_SIZE)
+#define lttng_align_floor(v, align) \
+       __lttng_align_floor_mask(v, (__typeof__(v)) (align) - 1)
 
 /**
- * offset_align - Calculate the offset needed to align an object on its natural
+ * lttng_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.
@@ -43,7 +44,7 @@
  * Returns the offset that must be added to align towards higher
  * addresses.
  */
-#define offset_align(align_drift, alignment)                                  \
+#define lttng_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
+ * lttng_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_offset_align_floor(align_drift, alignment)                              \
        ({                                                                     \
                LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0                    \
                                   || ((alignment) & ((alignment) - 1)));      \
index 1798f9ba27b3fc035c6aa0af594a261e55f7b7a1..aadfc17a173ccf528182a023532b701f8c73e716 100644 (file)
@@ -42,7 +42,7 @@ static
 int32_t bytecode_reserve(struct lttng_bytecode_alloc **fb, uint32_t align, uint32_t len)
 {
        int32_t ret;
-       uint32_t padding = offset_align((*fb)->b.len, align);
+       uint32_t padding = lttng_offset_align((*fb)->b.len, align);
        uint32_t new_len = (*fb)->b.len + padding + len;
        uint32_t new_alloc_len = sizeof(struct lttng_bytecode_alloc) + new_len;
        uint32_t old_alloc_len = (*fb)->alloc_len;
index e3a873a0f3c8f44b4a0f687cce2d099407b532b9..84fdbcaaa6902e076476489c3ab4e6b1aa7a1c9a 100644 (file)
@@ -3950,7 +3950,7 @@ unsigned long consumer_get_consume_start_pos(unsigned long consumed_pos,
        if (!nb_packets_per_stream) {
                return consumed_pos;    /* Grab everything */
        }
-       start_pos = produced_pos - offset_align_floor(produced_pos, max_sb_size);
+       start_pos = produced_pos - lttng_offset_align_floor(produced_pos, max_sb_size);
        start_pos -= max_sb_size * nb_packets_per_stream;
        if ((long) (start_pos - consumed_pos) < 0) {
                return consumed_pos;    /* Grab everything */
@@ -4171,7 +4171,7 @@ int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel,
                 * Align produced position on the start-of-packet boundary of the first
                 * packet going into the next trace chunk.
                 */
-               produced_pos = ALIGN_FLOOR(produced_pos, stream->max_sb_size);
+               produced_pos = lttng_align_floor(produced_pos, stream->max_sb_size);
                if (consumed_pos == produced_pos) {
                        DBG("Set rotate ready for stream %" PRIu64 " produced = %lu consumed = %lu",
                                        stream->key, produced_pos, consumed_pos);
index 34d3356e99967e68271aa00d460d63bf3103331c..c535054cc1ca9d09b7a21d56b0f67c38fc18a896 100644 (file)
@@ -179,7 +179,7 @@ int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits)
                goto end;
        }
 
-       array_alloc_len = ALIGN(kmask_len.len, 8) >> 3;
+       array_alloc_len = lttng_align_ceil(kmask_len.len, 8) >> 3;
 
        kmask = zmalloc(sizeof(*kmask) + array_alloc_len);
        if (!kmask) {
index e9dc190aac3f00c0235d272d375c950632013a26..874501ef1749325b38ba6d4214990da1396cd74a 100644 (file)
@@ -97,12 +97,6 @@ void *zmalloc(size_t len)
 
 #define is_signed(type) (((type) -1) < (type) 1)
 
-/*
- * Align value to the next multiple of align. Returns val if it already is a
- * multiple of align. Align must be a power of two.
- */
-#define ALIGN_TO(value, align) ((value + (align - 1)) & ~(align - 1))
-
 #define member_sizeof(type, field)     sizeof(((type *) 0)->field)
 
 #define ASSERT_LOCKED(lock) LTTNG_ASSERT(pthread_mutex_trylock(&lock))
index 9ce212ef26f04d987da506d56de8ccb94618d571..f5ed86367066b3504dadab91d04810c4d69e441b 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "lttng/lttng-error.h"
 #include <common/compat/string.h>
+#include <common/align.h>
 #include <common/error.h>
 #include <common/hashtable/hashtable.h>
 #include <common/hashtable/utils.h>
@@ -1634,7 +1635,7 @@ int lttng_userspace_probe_location_function_flatten(
         * the next structure in the buffer probably needs to be
         * aligned too (depending on the arch).
         */
-       padding_needed = ALIGN_TO(storage_needed, sizeof(uint64_t)) - storage_needed;
+       padding_needed = lttng_align_ceil(storage_needed, sizeof(uint64_t)) - storage_needed;
        storage_needed += padding_needed;
 
        if (location->lookup_method) {
@@ -1762,7 +1763,7 @@ int lttng_userspace_probe_location_tracepoint_flatten(
         * the next structure in the buffer probably needs to be
         * aligned too (depending on the arch).
         */
-       padding_needed = ALIGN_TO(storage_needed, sizeof(uint64_t)) - storage_needed;
+       padding_needed = lttng_align_ceil(storage_needed, sizeof(uint64_t)) - storage_needed;
        storage_needed += padding_needed;
 
        if (location->lookup_method) {
index 239ed8f33b9472c814937d2323f12614acbc2f8c..47887c0293645b61aa324e2164c10d86c1cc4b30 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 
 #include <common/bytecode/bytecode.h>
+#include <common/align.h>
 #include <common/common.h>
 #include <common/compat/errno.h>
 #include <common/compat/string.h>
@@ -2456,7 +2457,7 @@ int lttng_list_events(struct lttng_handle *handle,
                        storage_req += ext_comm->nb_exclusions *
                                        LTTNG_SYMBOL_NAME_LEN;
                        /* Padding to ensure the flat probe is aligned. */
-                       storage_req = ALIGN_TO(storage_req, sizeof(uint64_t));
+                       storage_req = lttng_align_ceil(storage_req, sizeof(uint64_t));
                        storage_req += probe_storage_req;
                }
        }
@@ -2547,7 +2548,7 @@ int lttng_list_events(struct lttng_handle *handle,
 
                        /* Insert padding to align to 64-bits. */
                        ret = lttng_dynamic_buffer_set_size(&listing,
-                                       ALIGN_TO(listing.size,
+                                       lttng_align_ceil(listing.size,
                                                        sizeof(uint64_t)));
                        if (ret) {
                                ret = -LTTNG_ERR_NOMEM;
This page took 0.029902 seconds and 4 git commands to generate.