From: David Laight <David.Laight@ACULAB.COM>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: sched_setaffinity() with > 1024 cpus on gcc-9
Date: Wed, 5 Jun 2019 09:38:48 +0000 [thread overview]
Message-ID: <6b42c210ba704118b00d0f44742efddf@AcuMS.aculab.com> (raw)
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)
reply other threads:[~2019-06-05 9:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b42c210ba704118b00d0f44742efddf@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®