This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What *is* the API for sched_getaffinity? Should sched_getaffinity always succeed when using cpu_set_t?


Hi

There are 3 ways to determine the correct size of the possible
cpu mask size:

(a) Read it from sysfs /sys/devices/system/cpu/online, which
has the actual number of possibly online cpus.

(b) Interpret /proc/cpuinfo or /proc/stat.

(c) Call the kernel syscall sched_getaffinity with increasingly
larger values for cpusetsize in an attempt to manually
determine the cpu mask size.

Methods (a) and (b) are already used by sysconf(_SC_PROCESSORS_ONLN)
to determine the value to return.

Nit.

sysconf(_SC_NPROCESSORS_ONLN) returns number of online cpus. not possible cpus.

online cpus: number of _now_ onlined cpus
possible cpus: number of maximum cpus on the system. (i.e. depend on arch and
firmware and ACPI table)

/sys/devices/system/cpu/possible returns possible cpu mask. AFAIK, unfortunately,
sysconf() doesn't support to get possible cpus.


Static applications can't easily be fixed to work around
this problem. The only solution there is to have the kernel
stop returning EINVAL and instead do what glibc does which
is to copy only the part of the buffer that the user requested.
However, doing that would break existing glibc's which rely
on EINVAL to compute the mask size. Therefore changing the
kernel semantics are not a good solution (except on a
system-by-system basis in the extreme case where a single
static application was being supported).

Step (s3) ensures that using a fixed cpu_set_t size works
when you are booted on hardware that has more than 1024
possible cpus.

Unfortunately it breaks the recommended pattern of using
sched_getaffinity and looking for EINVAL to determine the
size of the mask, but this was never a method that glibc
documented or supported. The patched man page has the
starting buffer size of 1024, so at least such a pattern
would allow access to the first 1024 cpus. It is strongly
recommended that users use sysconf to determine the number
of possible cpus. This patch to the linux kernel man pages
has been removed in future versions of RHEL.

If glibc need any kernel change, I'd like to handle it. Please
let me know if needed.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]