2021-04-14 13:03:51 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
#include <haproxy/compat.h>
|
|
|
|
#include <haproxy/cpuset.h>
|
|
|
|
#include <haproxy/intops.h>
|
|
|
|
|
2022-07-08 07:38:30 +00:00
|
|
|
struct cpu_map cpu_map[MAX_TGROUPS];
|
2021-04-27 08:46:36 +00:00
|
|
|
|
2021-04-14 13:03:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:10:52 +00:00
|
|
|
void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src)
|
2021-04-14 13:03:51 +00:00
|
|
|
{
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:10:52 +00:00
|
|
|
void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src)
|
2021-04-14 13:03:51 +00:00
|
|
|
{
|
|
|
|
#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()
|
|
|
|
{
|
2021-10-15 13:22:31 +00:00
|
|
|
#if defined(CPUSET_USE_CPUSET) || defined(CPUSET_USE_FREEBSD_CPUSET)
|
2021-04-14 13:03:51 +00:00
|
|
|
return CPU_SETSIZE;
|
|
|
|
|
|
|
|
#elif defined(CPUSET_USE_ULONG)
|
|
|
|
return LONGBITS;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|