From: Keith Packard Date: Sun, 13 Nov 2022 06:47:00 +0000 (-0800) Subject: altos: Avoid modulus in task queue on parts without idiv X-Git-Tag: 1.9.13~1^2~26^2~8 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=8c0a7dfa4ba4b46dabce0ac7daecf0edd5fb6b62 altos: Avoid modulus in task queue on parts without idiv Cortex-M0 parts don't have a hardware divide, so doing a modulus to compute task hash indexes is super slow. Avoid that by making the sleep queue a power of two. Signed-off-by: Keith Packard --- diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index dd278bde..b5045416 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -57,7 +57,17 @@ static inline void ao_check_stack(void) { #endif #ifndef SLEEP_HASH_SIZE +#ifdef __ARM_FEATURE_IDIV__ #define SLEEP_HASH_SIZE 17 +#else +#define SLEEP_HASH_SIZE 16 +#endif +#endif + +#if SLEEP_HASH_SIZE & (SLEEP_HASH_SIZE - 1) +#define SLEEP_HASH_SHIFT 0 +#else +#define SLEEP_HASH_SHIFT 2 #endif static struct ao_list run_queue; @@ -75,7 +85,7 @@ _ao_task_to_run_queue(struct ao_task *task) static struct ao_list * ao_task_sleep_queue(void *wchan) { - return &ao_sleep_queue[(uintptr_t) wchan % SLEEP_HASH_SIZE]; + return &ao_sleep_queue[(((uintptr_t) wchan) >> SLEEP_HASH_SHIFT) % SLEEP_HASH_SIZE]; } static void