From: Linus Torvalds <torvalds@osdl.org>
To: Paul Jackson <pj@sgi.com>
Cc: ak@muc.de, akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix argument checking in sched_setaffinity
Date: Sat, 4 Sep 2004 18:38:28 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0409041827280.2331@ppc970.osdl.org> (raw)
In-Reply-To: <20040904180548.2dcdd488.pj@sgi.com>
On Sat, 4 Sep 2004, Paul Jackson wrote:
>
> My understanding of "asking for it" requires at present a user code
> loop, to probe for the size that works.
Yeah, or just make a frigging big area, and asking the kernel for it ;)
Something like
/* We just assume that 8k CPU's aren't going to happen */
#define MAX_CPUMASK_BYTES (1024)
void *cpumask = malloc(MAX_CPUMASK_BYTES);
int real_size = sched_getaffinity(0, cpumask, MAX_CPUMASK_BYTES);
and no loop needed.
> But my user code already does
> that, and the first thing for which I audit any changes to this kernel
> code is not breaking my sizing loop code in user space.
I don't think you can reasonably use the "setaffinity()" call for sizing,
since that historically just refused to use anything but the exact size.
Sure, you could loop over every byte value known to man, but it's just a
lot easier to do the "getaffinity" thing - if it fails, you can double the
size of your buffer and try again. O(log(n)) rather than O(n) ;)
(And the "just start high enough" approach means that you can basically
make it O(1) if you don't care about the theoretical possibility of a
8k-CPU monster machine).
> I'd mildly prefer adding a kernel/user API for explicitly providing the
> two values:
>
> sizeof(cpumask_t)
> sizeof(nodemask_t)
>
> This might help reduce the unending confusions in the user and library
> code sitting on top of us.
I don't know how to sanely expose the damn things. Maybe in the vsyscall
page or something. Adding YAEAE (yet another ELF aux entry) could be done,
of course.
> We could two phase this:
> 1) add an obvious way to size these masks, and then
> 2) six months later, require sizes to match in all these calls.
Well, historically we _have_ required sizes to match. You can pass in
larger sizes to the "get" functions (and they'll tell you how much you
got), but the "set" functions required the user to know exactly what the
size was. Which is easy, see above.
Linus
next prev parent reply other threads:[~2004-09-05 1:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-31 14:30 Andi Kleen
2004-09-01 1:36 ` Paul Jackson
2004-09-01 1:59 ` Anton Blanchard
2004-09-02 9:33 ` Paul Jackson
2004-09-04 13:40 ` Andi Kleen
2004-09-05 14:27 ` Anton Blanchard
2004-09-04 13:37 ` Andi Kleen
[not found] ` <20040904171417.67649169.pj@sgi.com>
2004-09-05 0:18 ` Linus Torvalds
2004-09-05 1:05 ` Paul Jackson
2004-09-05 1:38 ` Linus Torvalds [this message]
2004-09-05 3:48 ` Paul Jackson
2004-09-05 3:57 ` Linus Torvalds
2004-09-05 4:17 ` Paul Jackson
2004-09-05 4:52 ` Paul Jackson
2004-09-06 18:23 ` Andi Kleen
2004-09-06 18:48 ` Linus Torvalds
2004-09-06 21:11 ` Paul Jackson
2004-09-07 8:07 ` Andi Kleen
2004-09-06 13:16 ` Andi Kleen
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=Pine.LNX.4.58.0409041827280.2331@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=ak@muc.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pj@sgi.com \
/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®