public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* sched_setaffinity usability
@ 2004-03-18  8:05 Ulrich Drepper
  2004-03-18  8:12 ` Tim Hockin
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Ulrich Drepper @ 2004-03-18  8:05 UTC (permalink / raw)
  To: Linux Kernel, Andrew Morton, Linus Torvalds

The sched_setaffinity syscall currently has a usability problem.  The
size of cpumask_t is not visible outside the kernel and might change
from kernel to kernel.  So, if the user uses a large CPU bitset and
passes it to the kernel it is not known at all whether all the bits
provided in the bitmap are used.  The kernel simply copies the first
bytes, enough to fill in the cpumask_t object and ignores the rest.

A simple check for a too large bitset is not good.  Programs which are
portable (to different kernels) and future safe should use large bitmap
sizes.  Instead the user should only be notified about the size problem
if any nonzero bit is ignored.

Doing this in the kernel isn't good.  It would require copying all the
bitmap into the kernel address space.  So do it at userlevel.

But how?  The userlevel code does not know the size of the type the
kernel used.  In the getaffinity call this is handled nicely: the
syscall returns the size of the type.

I think we should do the same for setaffinity.  Something like this:

--- kernel/sched.c      2004-03-16 20:57:25.000000000 -0800
+++ kernel/sched.c-new  2004-03-17 23:52:25.000000000 -0800
@@ -2328,6 +2328,8 @@ asmlinkage long sys_sched_setaffinity(pi
                goto out_unlock;

        retval = set_cpus_allowed(p, new_mask);
+       if (retval == 0)
+               retval = sizeof(new_mask);

 out_unlock:
        put_task_struct(p);


The userlevel code could then check whether the remaining words in the
bitset contain any set bits.

The interface change is limited to the kernel only.  We can arrange for
the sched_setaffinity/pthread_setaffinity calls to still return zero in
case of success (in fact, that's the desirable solution).  Additionally,
we could hardcode a size for the case when the syscall returns zero to
handle old kernels.


Is this acceptable?

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 28+ messages in thread
[parent not found: <1B0Ls-lY-27@gated-at.bofh.it>]

end of thread, other threads:[~2004-03-21  9:50 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-18  8:05 sched_setaffinity usability Ulrich Drepper
2004-03-18  8:12 ` Tim Hockin
2004-03-18  8:22   ` Ulrich Drepper
2004-03-18  8:47     ` Ulrich Drepper
2004-03-18  9:45 ` Andrew Morton
2004-03-18 10:10   ` Andrew Morton
2004-03-18 11:29 ` Ingo Molnar
2004-03-18 12:07   ` Christoph Hellwig
2004-03-18 12:31     ` Ingo Molnar
2004-03-19  8:05       ` Ulrich Drepper
2004-03-18 15:55     ` Linus Torvalds
2004-03-18 18:24       ` Ingo Molnar
2004-03-18 18:33         ` Andrew Morton
2004-03-18 18:39           ` Ingo Molnar
2004-03-18 18:55             ` Ingo Molnar
2004-03-18 20:01             ` Andrea Arcangeli
2004-03-18 20:28               ` Ingo Molnar
2004-03-18 20:49         ` David Lang
2004-03-18 20:57           ` Randy.Dunlap
2004-03-18 21:06           ` Ingo Molnar
2004-03-18 21:07         ` Davide Libenzi
2004-03-18 21:46           ` Ingo Molnar
2004-03-19  1:37             ` Davide Libenzi
2004-03-19  9:02         ` Helge Hafting
2004-03-21  9:51           ` Ingo Molnar
2004-03-19  0:00       ` Paul Jackson
2004-03-18 17:47 ` sched_setaffinity usability -- other issue Chris Friesen
     [not found] <1B0Ls-lY-27@gated-at.bofh.it>
     [not found] ` <1B42z-3Lx-5@gated-at.bofh.it>
     [not found]   ` <1B4Fh-4sQ-3@gated-at.bofh.it>
     [not found]     ` <1B86P-8gq-69@gated-at.bofh.it>
     [not found]       ` <1Bars-2s6-29@gated-at.bofh.it>
     [not found]         ` <1BaKU-2Lg-49@gated-at.bofh.it>
     [not found]           ` <1BaKX-2Lg-61@gated-at.bofh.it>
     [not found]             ` <1BaUR-2V0-41@gated-at.bofh.it>
2004-03-18 21:23               ` sched_setaffinity usability Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox