Re: sched_setaffinity usability
From: Ingo Molnar
Date: Thu Mar 18 2004 - 06:30:31 EST
* Ulrich Drepper <drepper@xxxxxxxxxx> wrote:
> 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.
how about adding a new syscall, sys_sched_get_affinity_span(), which
would be called by glibc first time one of the affinity syscalls are
called.
This syscall would be a prime target to be optimized away via the
vsyscall DSO, so there's no overhead worry.
something like the attached patch.
or, maybe it would be better to introduce some sort of 'system
constants' syscall that would be a generic umbrella for such things -
and could easily be converted into a vsyscall. Or we could make it part
of the .data section of the VDSO - thus no copying overhead, only one
symbol lookup.
Ingo
--- linux/arch/i386/kernel/entry.S.orig
+++ linux/arch/i386/kernel/entry.S
@@ -908,5 +908,6 @@ ENTRY(sys_call_table)
.long sys_utimes
.long sys_fadvise64_64
.long sys_ni_syscall /* sys_vserver */
+ .long sys_sched_get_affinity_span
syscall_table_size=(.-sys_call_table)
--- linux/kernel/sched.c.orig
+++ linux/kernel/sched.c
@@ -2793,6 +2793,17 @@ out_unlock:
}
/**
+ * sys_sched_affinity_span - get the cpu affinity mask size possible
+ *
+ * returns the size of cpumask_t. Note that this is a hard upper limit
+ * for the # of CPUs.
+ */
+asmlinkage long sys_sched_get_affinity_span(void)
+{
+ return sizeof(cpumask_t);
+}
+
+/**
* sys_sched_yield - yield the current processor to other threads.
*
* this function yields the current CPU by moving the calling thread
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/