Subject: Re: Syscalls to set CPU affinity
To: Mindaugas R. <>
From: Andrew Doran <>
List: tech-kern
Date: 09/12/2007 02:13:11
On Mon, Sep 10, 2007 at 02:06:25AM +0300, Mindaugas R. wrote:
> Hello,
> 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);

I'm not sure how any of these work or what they do. Is there somewhere we
can find a description? Affinity by PID seems odd, is that from before Linux
had NPTL?

> 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);

Are these for kernel-internal use only?