From: Michael Jeanson Date: Fri, 16 Jul 2021 17:58:10 +0000 (-0400) Subject: Cleanup: namespace 'align' macros X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=1cbd136b2479ef142bfb339b13d3d25aa772dda5 Cleanup: namespace 'align' macros 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 Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/align.h b/src/common/align.h index 81b92f861..024faf7fb 100644 --- a/src/common/align.h +++ b/src/common/align.h @@ -16,26 +16,27 @@ #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))); \ @@ -51,14 +52,14 @@ }) /** - * 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))); \ diff --git a/src/common/bytecode/bytecode.c b/src/common/bytecode/bytecode.c index 1798f9ba2..aadfc17a1 100644 --- a/src/common/bytecode/bytecode.c +++ b/src/common/bytecode/bytecode.c @@ -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; diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index e3a873a0f..84fdbcaaa 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -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); diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index 34d3356e9..c535054cc 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -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) { diff --git a/src/common/macros.h b/src/common/macros.h index e9dc190aa..874501ef1 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -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)) diff --git a/src/common/userspace-probe.c b/src/common/userspace-probe.c index 9ce212ef2..f5ed86367 100644 --- a/src/common/userspace-probe.c +++ b/src/common/userspace-probe.c @@ -7,6 +7,7 @@ #include "lttng/lttng-error.h" #include +#include #include #include #include @@ -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) { diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 239ed8f33..47887c029 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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;