On Tue, 29 Nov 2005, Jeff Squyres wrote:

Here's the problem: there are 3 different APIs for processor affinity
in Linux.

Could you please list them (at least the ones that you know about) ?

In the kernel source, in kernel/sched.c, the sys_sched_setaffinity function appears only in 2.6.0 (talking about stable kernels only). I can also see it back-ported by Red Hat in their RHEL3 (2.4.21-based) kernels, so I would like to know if others have back-ported it as well and if their functions differ.

Both the official 2.6.x and the Red Hat back-ported definition of this function is:

asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
                                      unsigned long __user *user_mask_ptr)

(the back-ported RHEL3 doesn't have the __user attribute to the last parameter, but that's cosmetic)

The glibc definitions of sched_setaffinity seem to change, I already found 2 of them in RHEL3 and RHEL4, but they both call the same underlying kernel function. So Open MPI could just bypass glibc and call the kernel function directly, for example:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <linux/unistd.h>

_syscall3(int, sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long 
*, user_mask_ptr)

int main(int argc, char **argv){
        unsigned long cpus = 1;
        int r;
        r = sched_setaffinity(0, sizeof(cpus), &cpus);
        if (r == -1) {
                perror("sched_setaffinity:");
        }
        return 0;
}

--
Bogdan Costescu

IWR - Interdisziplinaeres Zentrum fuer Wissenschaftliches Rechnen
Universitaet Heidelberg, INF 368, D-69120 Heidelberg, GERMANY
Telephone: +49 6221 54 8869, Telefax: +49 6221 54 8868
E-mail: bogdan.coste...@iwr.uni-heidelberg.de

Reply via email to