sched_setaffinity (always EFAULTs) on Suse 2.6.4/5
Hi folks, I'm working with some guys at PGI/AMD to get some sched_setaffinity support in some runtime systems. We're having great difficulty getting sched_setaffinity working. The code below was constructed via the code in linux/kernel/sched.c, contrary to the prototypes and the like. Surely we must be doing something rather stupid, because we keep getting -EFAULT. The only thing I can guess is that the sizeof(cpumask) is different in kernel than it is in user land. Any help would be greatly appreciated... Phil #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <asm/cpumask.h> void set_affin(void) { cpumask_t mask = { 0, }; int retval; cpu_set(1,mask); retval = sched_setaffinity(0,sizeof(cpumask_t),&mask); printf("sched_setaffinity returns %d, errno %d\n",retval,errno); perror("ERROR MESSAGE"); } int main(int argc, char **argv) { set_affin(); sleep(1); exit(0); }
Hi again, Well, looks like a bug in the C library. Using the syscall directly produces the expected behavior, using the C library produces an error. Compile the following with -DBUG to see the buggy behavior. Comments? Phil #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <syscall.h> #include <asm/cpumask.h> void set_affin(void) { int retval; cpumask_t mask = { 0 }; cpu_set(0,mask); #ifdef BUG retval = sched_setaffinity(getpid(),sizeof(cpumask_t),&mask); #else retval = syscall(__NR_sched_setaffinity,getpid(),sizeof(cpumask_t),&mask); #endif printf("sched_setaffinity returns %d\n",retval); if (errno == -1) { printf("%d ",errno); perror("sched_setaffinity"); } } int main(int argc, char **argv) { set_affin(); sleep(1); exit(0); } On Tue, 2004-06-29 at 11:51, Philip J. Mucci wrote:
Hi folks,
I'm working with some guys at PGI/AMD to get some sched_setaffinity support in some runtime systems. We're having great difficulty getting sched_setaffinity working.
The code below was constructed via the code in linux/kernel/sched.c, contrary to the prototypes and the like. Surely we must be doing something rather stupid, because we keep getting -EFAULT.
The only thing I can guess is that the sizeof(cpumask) is different in kernel than it is in user land.
Any help would be greatly appreciated...
Phil
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <asm/cpumask.h>
void set_affin(void) { cpumask_t mask = { 0, }; int retval;
cpu_set(1,mask); retval = sched_setaffinity(0,sizeof(cpumask_t),&mask); printf("sched_setaffinity returns %d, errno %d\n",retval,errno); perror("ERROR MESSAGE"); } int main(int argc, char **argv) { set_affin(); sleep(1); exit(0); }
Hi, On Tue, 29 Jun 2004, Philip J. Mucci wrote:
Well, looks like a bug in the C library. Using the syscall directly produces the expected behavior, using the C library produces an error.
Yes, I think it's a bug in glibc somewhere. I couldn't see it immediately, so perhaps it only happen on 9.1 and is fixed meanwhile (couldn't test). Please use bugzilla.suse.de to report it, so the right person can look at it. Ciao, Michael.
tisdag 29 juni 2004 11:51 skrev Philip J. Mucci:
retval = sched_setaffinity(0,sizeof(cpumask_t),&mask);
A very quick peek at the man page for sched_affinity, reveals what should be parameter #1. Take a carefull look, then tell us what process has ID #0. NAME sched_setaffinity, sched_getaffinity - set and get a pro cess's CPU affinity mask SYNOPSIS #include <sched.h> int sched_setaffinity(pid_t pid, unsigned int len, unsigned long *mask); int sched_getaffinity(pid_t pid, unsigned int len, unsigned long *mask); ....
Sorry, but you should read more closely... ---snip--- DESCRIPTION sched_setaffinity sets the CPU affinity mask of the process denoted by pid. If pid is zero, then the current process is used. ---snip--- Furthermore, strace verifies that the libc is calling getpid when zero is passed. The bug persists with a getpid() replacement.
participants (3)
-
Michael Matz
-
Philip J. Mucci
-
Örn Hansen