* sched_setaffinity() with > 1024 cpus on gcc-9
@ 2019-06-05 9:38 David Laight
0 siblings, 0 replies; only message in thread
From: David Laight @ 2019-06-05 9:38 UTC (permalink / raw)
To: linux-kernel
I suspect that if I compile the following using gcc-9 It'll bleat
about going beyond the end of the array:
#define _GNU_SOURCE
#include <sched.h>
#define MAX_CPU 2048
int fubar(void)
{
cpu_set_t *set = CPU_ALLOC(MAX_CPU);
CPU_SET_S(MAX_CPU - 2, CPU_ALLOC_SIZE(MAX_CPU), set);
return CPU_COUNT_S(CPU_ALLOC_SIZE(MAX_CPU), set);
}
I can't test since I don't have a copy of gcc-9.
The whole interface for > 1024 cpus looks horrid though.
Reading version 5.01 on the man page.
I'd have thought that if the application provided a short mask
to sched_setaffinity() the rest would be deemed to be zeros.
And that if an overlong mask is passed to sched_getaffinity()
the extra bytes/longs would either be zerod or unchanged.
Be aware that CPU_ALLOC(3) may allocate a slightly larger CPU set
than requested (because CPU sets are implemented as bit masks
allocated in units of sizeof(long)). Consequently,
sched_getaffinity() can set bits beyond the requested allocation
size, because the kernel sees a few additional bits. Therefore, the
caller should iterate over the bits in the returned set, counting
those which are set, and stop upon reaching the value returned by
CPU_COUNT(3) (rather than iterating over the number of bits requested
to be allocated).
A short mask to sched_getaffinity() should also do something
more sensible than just returning an error.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-06-05 9:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 9:38 sched_setaffinity() with > 1024 cpus on gcc-9 David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®