mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-27 00:31:22 +02:00
The man page indicates that CPU_AND() and CPU_ASSIGN() take a variable, not a const on the source, even though it doesn't make much sense. But with older libcs, this triggers a build warning: src/cpuset.c: In function 'ha_cpuset_and': src/cpuset.c:53: warning: initialization discards qualifiers from pointer target type src/cpuset.c: In function 'ha_cpuset_assign': src/cpuset.c:101: warning: initialization discards qualifiers from pointer target type Better stick stricter to the documented API as this is really harmless here. There's no need to backport it (unless build issues are reported, which is quite unlikely).
121 lines
2.3 KiB
C
121 lines
2.3 KiB
C
#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
|
|
}
|