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};
/// 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;
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;
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};
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) {
// ...
};
struct kru_avx2 {
- char hash_key[48] ALIGNED(32);
+ _Alignas(32) char hash_key[48];
// ...
};
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);
#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)
*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. */
#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.
/// 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.
#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;