Willy Tarreau e65f54cf96 MINOR: cpuset: centralize a reliable bound cpu detection
Till now the CPUs that were bound were only retrieved in
thread_cpus_enabled() in order to count the number of CPUs allowed,
and it relied on arch-specific code.

Let's slightly arrange this into ha_cpuset_detect_bound() that
reuses the ha_cpuset struct and the accompanying code. This makes
the code much clearer without having to carry along some arch-specific
stuff out of this area.

Note that the macos-specific code used in thread.c to only count
online CPUs but not retrieve a mask, so for now we can't infer
anything from it and can't implement it.

In addition and more importantly, this function is reliable in that
it will only return a value when the detection is accurate, and will
not return incomplete sets on operating systems where we don't have
an exact list, such as online CPUs.
2023-09-04 19:39:17 +02:00

62 lines
1.8 KiB
C

#ifndef _HAPROXY_CPUSET_H
#define _HAPROXY_CPUSET_H
#include <haproxy/cpuset-t.h>
extern struct cpu_map cpu_map[MAX_TGROUPS];
/* Unset all indexes in <set>.
*/
void ha_cpuset_zero(struct hap_cpuset *set);
/* Set <cpu> index in <set> if not present.
* Returns 0 on success otherwise non-zero.
*/
int ha_cpuset_set(struct hap_cpuset *set, int cpu);
/* Clear <cpu> index in <set> if present.
* Returns 0 on success otherwise non-zero.
*/
int ha_cpuset_clr(struct hap_cpuset *set, int cpu);
/* Bitwise and equivalent operation between <src> and <dst> stored in <dst>.
*/
void ha_cpuset_and(struct hap_cpuset *dst, struct hap_cpuset *src);
/* Bitwise OR equivalent operation between <src> and <dst> stored in <dst>.
*/
void ha_cpuset_or(struct hap_cpuset *dst, struct hap_cpuset *src);
/* returns non-zero if CPU index <cpu> is set in <set>, otherwise 0. */
int ha_cpuset_isset(const struct hap_cpuset *set, int cpu);
/* Returns the count of set index in <set>.
*/
int ha_cpuset_count(const struct hap_cpuset *set);
/* Returns the first index set plus one in <set> starting from the lowest.
* Returns 0 if no index set.
* Do not forget to subtract the result by one if using it for set/clr.
*/
int ha_cpuset_ffs(const struct hap_cpuset *set);
/* Copy <src> set into <dst>.
*/
void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src);
/* Returns the biggest index plus one usable on the platform.
*/
int ha_cpuset_size(void);
/* Detects CPUs that are bound to the current process. Returns the number of
* CPUs detected or 0 if the detection failed.
*/
int ha_cpuset_detect_bound(struct hap_cpuset *set);
/* Returns true if at least one cpu-map directive was configured, otherwise
* false.
*/
int cpu_map_configured(void);
#endif /* _HAPROXY_CPUSET_H */