]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
treewide: utilize _Alignas, as it's standard C11 docs-develop-rrl-8r8r8r/deployments/4353
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 14 Jun 2024 09:12:16 +0000 (11:12 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 14 Jun 2024 09:12:16 +0000 (11:12 +0200)
daemon/defer.c
daemon/ratelimiting.c
daemon/ratelimiting.test/tests.inc.c
lib/generic/lru.h
lib/kru.h
lib/kru.inc.c

index 5d0ad222982eda98963fba5f9421522cc4b522c3..7c09751c13c2ee8712d8a8abf862007b0eeae687 100644 (file)
@@ -24,7 +24,7 @@ struct defer {
        size_t capacity;
        kru_price_t max_decay;
        bool using_avx2;
-       uint8_t kru[] ALIGNED(64);
+       _Alignas(64) uint8_t kru[];
 };
 struct defer *defer = NULL;
 struct mmapped defer_mmapped = {0};
@@ -46,7 +46,7 @@ static bool using_avx2(void)
 
 /// Increment KRU counters by given time.
 void defer_account(uint64_t nsec, union kr_sockaddr addr) {
-       uint8_t key[16] ALIGNED(16) = {0, };
+       _Alignas(16) uint8_t key[16] = {0, };
        uint16_t max_load = 0;
        if (defer_sample_state.addr.ip.sa_family == AF_INET6) {
                struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)&defer_sample_state.addr.ip;
@@ -86,7 +86,7 @@ static enum protolayer_iter_cb_result pl_defer_unwrap(
 
        defer_sample_addr((const union kr_sockaddr *)ctx->comm->comm_addr);
 
-       uint8_t key[16] ALIGNED(16) = {0, };
+       _Alignas(16) uint8_t key[16] = {0, };
        uint16_t max_load = 0;
        if (ctx->comm->comm_addr->sa_family == AF_INET6) {
                struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)ctx->comm->comm_addr;
index e6b134308ad867dfd7cb8251545545622907a7d2..cd15dc8c55e8ed8edc4e2810d475ebaae1608762 100644 (file)
@@ -22,7 +22,7 @@ struct ratelimiting {
        bool using_avx2;
        kru_price_t v4_prices[V4_PREFIXES_CNT];
        kru_price_t v6_prices[V6_PREFIXES_CNT];
-       uint8_t kru[] ALIGNED(64);
+       _Alignas(64) uint8_t kru[];
 };
 struct ratelimiting *ratelimiting = NULL;
 struct mmapped ratelimiting_mmapped = {0};
@@ -107,7 +107,7 @@ bool ratelimiting_request_begin(struct kr_request *req)
                return false;  // don't consider internal requests
        uint8_t limited = 0;  // 0: not limited, 1: truncated, 2: no answer
        if (ratelimiting) {
-               uint8_t key[16] ALIGNED(16) = {0, };
+               _Alignas(16) uint8_t key[16] = {0, };
                uint8_t limited_prefix;
                uint16_t max_final_load = 0;
                if (req->qsource.addr->sa_family == AF_INET6) {
index 157da55872af34753736dc5d5e4fc1043a184692..467473c02012a5a69e946755c1662e573a67dbd1 100644 (file)
@@ -68,7 +68,7 @@ struct kru_generic {
        // ...
 };
 struct kru_avx2 {
-       char hash_key[48] ALIGNED(32);
+       _Alignas(32) char hash_key[48];
        // ...
 };
 
index 1c1dd81ace9467d828a1286a2d91a86aab3b98ca..b78888fcb1a2aee9cc55c7324c62aef4f4caf2c3 100644 (file)
@@ -172,11 +172,7 @@ enum lru_apply_do {
        enum lru_apply_do (*(name))(const char *key, uint len, val_type *val, void *baton)
 typedef lru_apply_fun_g(lru_apply_fun, void);
 
-#if __GNUC__ >= 4
-       #define CACHE_ALIGNED __attribute__((aligned(64)))
-#else
-       #define CACHE_ALIGNED
-#endif
+#define CACHE_ALIGNED _Alignas(64)
 
 struct lru;
 void lru_free_items_impl(struct lru *lru);
@@ -198,10 +194,11 @@ struct lru_item;
 #define LRU_TRACKED ((64 - sizeof(size_t) * LRU_ASSOC) / 4 - 1)
 
 struct lru_group {
+       CACHE_ALIGNED
        uint16_t counts[LRU_TRACKED+1]; /*!< Occurrence counters; the last one is special. */
        uint16_t hashes[LRU_TRACKED+1]; /*!< Top halves of hashes; the last one is unused. */
        struct lru_item *items[LRU_ASSOC]; /*!< The full items. */
-} CACHE_ALIGNED;
+};
 
 /* The sizes are chosen so lru_group just fits into a single x86 cache line. */
 static_assert(64 == sizeof(struct lru_group)
@@ -213,7 +210,7 @@ struct lru {
                *mm_array; /**< Memory context to use for this structure itself. */
        uint log_groups; /**< Logarithm of the number of LRU groups. */
        uint val_alignment; /**< Alignment for the values. */
-       struct lru_group groups[] CACHE_ALIGNED; /**< The groups of items. */
+       CACHE_ALIGNED struct lru_group groups[]; /**< The groups of items. */
 };
 
 /** @internal See lru_free. */
index a443e419294782d374543137ae45d21d4db95687..0a3a8e8092fd0d8cf29ff6c70318fbe787c58755 100644 (file)
--- a/lib/kru.h
+++ b/lib/kru.h
 #include <stddef.h>
 #include <stdint.h>
 
-#if __GNUC__ >= 4 || __clang_major__ >= 4
-       #define ALIGNED_CPU_CACHE __attribute__((aligned(64)))
-       #define ALIGNED(_bytes)   __attribute__((aligned(_bytes)))
-#else
-       #define ALIGNED_CPU_CACHE
-       #define ALIGNED(_bytes)
-#endif
+#define ALIGNED_CPU_CACHE _Alignas(64)
 
 // An unsigned integral type used for prices, blocking occurs when sum of prices overflows.
 // Greater than 16-bit type enables randomized fractional incrementing as the internal counters are still 16-bit.
index 9909cfd785e108a43693fd65084c75c5d5ddaea9..b67d3237decb4cc81703b0883b22db06963235b7 100644 (file)
@@ -74,11 +74,12 @@ typedef uint64_t hash_t;
 /// Block of loads sharing the same time, so that we're more space-efficient.
 /// It's exactly a single cache line.
 struct load_cl {
+       ALIGNED_CPU_CACHE
        _Atomic uint32_t time;
        #define LOADS_LEN 15
        uint16_t ids[LOADS_LEN];
        uint16_t loads[LOADS_LEN];
-} ALIGNED_CPU_CACHE;
+};
 static_assert(64 == sizeof(struct load_cl), "bad size of struct load_cl");
 
 /// Parametrization for speed of decay.
@@ -96,7 +97,7 @@ struct kru {
 #if USE_AES
        /// Hashing secret.  Random but shared by all users of the table.
        /// Let's not make it too large, so that header fits into 64 Bytes.
-       char hash_key[48] ALIGNED(32);
+       _Alignas(32) char hash_key[48];
 #else
        /// Hashing secret.  Random but shared by all users of the table.
        SIPHASH_KEY hash_key;