diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:35:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:35:11 +0000 |
commit | da76459dc21b5af2449af2d36eb95226cb186ce2 (patch) | |
tree | 542ebb3c1e796fac2742495b8437331727bbbfa0 /src/cpuset.c | |
parent | Initial commit. (diff) | |
download | haproxy-da76459dc21b5af2449af2d36eb95226cb186ce2.tar.xz haproxy-da76459dc21b5af2449af2d36eb95226cb186ce2.zip |
Adding upstream version 2.6.12.upstream/2.6.12upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cpuset.c')
-rw-r--r-- | src/cpuset.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/cpuset.c b/src/cpuset.c new file mode 100644 index 0000000..f7b6602 --- /dev/null +++ b/src/cpuset.c @@ -0,0 +1,120 @@ +#define _GNU_SOURCE +#include <sched.h> + +#include <haproxy/compat.h> +#include <haproxy/cpuset.h> +#include <haproxy/intops.h> + +struct cpu_map cpu_map; + +void ha_cpuset_zero(struct hap_cpuset *set) +{ +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + CPU_ZERO(&set->cpuset); + +#elif defined(CPUSET_USE_ULONG) + set->cpuset = 0; +#endif +} + +int ha_cpuset_set(struct hap_cpuset *set, int cpu) +{ + if (cpu >= ha_cpuset_size()) + return 1; + +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + CPU_SET(cpu, &set->cpuset); + return 0; + +#elif defined(CPUSET_USE_ULONG) + set->cpuset |= (0x1 << cpu); + return 0; +#endif +} + +int ha_cpuset_clr(struct hap_cpuset *set, int cpu) +{ + if (cpu >= ha_cpuset_size()) + return 1; + +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + CPU_CLR(cpu, &set->cpuset); + return 0; + +#elif defined(CPUSET_USE_ULONG) + set->cpuset &= ~(0x1 << cpu); + return 0; +#endif +} + +void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src) +{ +#if defined(CPUSET_USE_CPUSET) + CPU_AND(&dst->cpuset, &dst->cpuset, &src->cpuset); + +#elif defined(CPUSET_USE_FREEBSD_CPUSET) + CPU_AND(&dst->cpuset, &src->cpuset); + +#elif defined(CPUSET_USE_ULONG) + dst->cpuset &= src->cpuset; +#endif +} + +int ha_cpuset_count(const struct hap_cpuset *set) +{ +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + return CPU_COUNT(&set->cpuset); + +#elif defined(CPUSET_USE_ULONG) + return my_popcountl(set->cpuset); +#endif +} + +int ha_cpuset_ffs(const struct hap_cpuset *set) +{ +#if defined(CPUSET_USE_CPUSET) + int n; + + if (!CPU_COUNT(&set->cpuset)) + return 0; + + for (n = 0; !CPU_ISSET(n, &set->cpuset); ++n) + ; + + return n + 1; + +#elif defined(CPUSET_USE_FREEBSD_CPUSET) + return CPU_FFS(&set->cpuset); + +#elif defined(CPUSET_USE_ULONG) + if (!set->cpuset) + return 0; + + return my_ffsl(set->cpuset); +#endif +} + +void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src) +{ +#if defined(CPUSET_USE_CPUSET) + CPU_ZERO(&dst->cpuset); + CPU_OR(&dst->cpuset, &dst->cpuset, &src->cpuset); + +#elif defined(CPUSET_USE_FREEBSD_CPUSET) + CPU_COPY(&src->cpuset, &dst->cpuset); + +#elif defined(CPUSET_USE_ULONG) + dst->cpuset = src->cpuset; +#endif +} + +int ha_cpuset_size() +{ +#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET) + return CPU_SETSIZE; + +#elif defined(CPUSET_USE_ULONG) + return LONGBITS; + +#endif +} |