diff --git a/include/haproxy/activity.h b/include/haproxy/activity.h index 421697c00..42b0c8793 100644 --- a/include/haproxy/activity.h +++ b/include/haproxy/activity.h @@ -24,8 +24,6 @@ #include #include -#include -#include extern unsigned int profiling; extern unsigned long task_profiling_mask; @@ -34,32 +32,7 @@ extern struct sched_activity sched_activity[256]; void report_stolen_time(uint64_t stolen); void activity_count_runtime(); - -/* Computes the index of function pointer for use with sched_activity[] - * or any other similar array passed in , and returns a pointer to the - * entry after having atomically assigned it to this function pointer. Note - * that in case of collision, the first entry is returned instead ("other"). - */ -static inline struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func) -{ - uint64_t hash = XXH64_avalanche(XXH64_mergeRound((size_t)func, (size_t)func)); - struct sched_activity *ret; - const void *old = NULL; - - hash ^= (hash >> 32); - hash ^= (hash >> 16); - hash ^= (hash >> 8); - hash &= 0xff; - ret = &array[hash]; - - if (likely(ret->func == func)) - return ret; - - if (HA_ATOMIC_CAS(&ret->func, &old, func)) - return ret; - - return array; -} +struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func); #endif /* _HAPROXY_ACTIVITY_H */ diff --git a/src/activity.c b/src/activity.c index 90a1ef96b..c3010c5f3 100644 --- a/src/activity.c +++ b/src/activity.c @@ -19,6 +19,7 @@ #include #include #include +#include #if defined(DEBUG_MEM_STATS) /* these ones are macros in bug.h when DEBUG_MEM_STATS is set, and will @@ -558,6 +559,32 @@ static int cmp_memprof_addr(const void *a, const void *b) } #endif // USE_MEMORY_PROFILING +/* Computes the index of function pointer for use with sched_activity[] + * or any other similar array passed in , and returns a pointer to the + * entry after having atomically assigned it to this function pointer. Note + * that in case of collision, the first entry is returned instead ("other"). + */ +struct sched_activity *sched_activity_entry(struct sched_activity *array, const void *func) +{ + uint64_t hash = XXH64_avalanche(XXH64_mergeRound((size_t)func, (size_t)func)); + struct sched_activity *ret; + const void *old = NULL; + + hash ^= (hash >> 32); + hash ^= (hash >> 16); + hash ^= (hash >> 8); + hash &= 0xff; + ret = &array[hash]; + + if (likely(ret->func == func)) + return ret; + + if (HA_ATOMIC_CAS(&ret->func, &old, func)) + return ret; + + return array; +} + /* This function dumps all profiling settings. It returns 0 if the output * buffer is full and it needs to be called again, otherwise non-zero. * It dumps some parts depending on the following states: