mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-19 20:27:01 +00:00
MINOR: cpuset: centralize 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.
This commit is contained in:
parent
b5809a4a52
commit
f14975c74a
@ -48,6 +48,11 @@ void ha_cpuset_assign(struct hap_cpuset *dst, struct hap_cpuset *src);
|
||||
*/
|
||||
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);
|
||||
|
||||
/* Parse cpu sets. Each CPU set is either a unique number between 0 and
|
||||
* ha_cpuset_size() - 1 or a range with two such numbers delimited by a dash
|
||||
* ('-'). Each CPU set can be a list of unique numbers or ranges separated by
|
||||
|
24
src/cpuset.c
24
src/cpuset.c
@ -149,6 +149,30 @@ int ha_cpuset_size()
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
ha_cpuset_zero(set);
|
||||
|
||||
/* detect bound CPUs depending on the OS's API */
|
||||
if (0
|
||||
#if defined(__linux__)
|
||||
|| sched_getaffinity(0, sizeof(set->cpuset), &set->cpuset) != 0
|
||||
#elif defined(__FreeBSD__)
|
||||
|| cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1, sizeof(set->cpuset), &set->cpuset) != 0
|
||||
#else
|
||||
|| 1 // unhandled platform
|
||||
#endif
|
||||
) {
|
||||
/* detection failed */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ha_cpuset_count(set);
|
||||
}
|
||||
|
||||
/* Parse cpu sets. Each CPU set is either a unique number between 0 and
|
||||
* ha_cpuset_size() - 1 or a range with two such numbers delimited by a dash
|
||||
* ('-'). Each CPU set can be a list of unique numbers or ranges separated by
|
||||
|
Loading…
Reference in New Issue
Block a user