Subject: Syscalls to set CPU affinity
To: None <>
From: Mindaugas R. <>
List: tech-kern
Date: 09/10/2007 02:06:25

I would like to discuss the API for setting and getting the affinity for
processes and threads, and operations with CPU sets. My suggestion would be
adopting the Solaris API, which looks flexible and good for compatibility:

int processor_bind(idtype_t idtype, id_t id, processorid_t processorid,
    processorid_t *obind);
int pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset);
int pset_create(psetid_t *newpset);
int pset_destroy(psetid_t pset);
int pset_assign(psetid_t pset, processorid_t cpu, psetid_t *opset);

Calls of Linux API can set affinity only for processes, however I think it
would be reasonable to have a support for Linux affinity calls in libpthread
for compatibility purposes:

int sched_setaffinity(pid_t pid, unsigned int cpusetsize, cpu_set_t *mask);
int sched_getaffinity(pid_t pid, unsigned int cpusetsize, cpu_set_t *mask);

Also, operations with CPU sets:

 void CPU_CLR(int cpu, cpu_set_t *set);
 int CPU_ISSET(int cpu, cpu_set_t *set);
 void CPU_SET(int cpu, cpu_set_t *set);
 void CPU_ZERO(cpu_set_t *set);

Any better suggestions? Thoughts?

Best regards,