sys_sched_setaffinity  [kernel/sched.c]


Sets a process's CPU affinity mask

A process's CPU affinity mask determines the set of CPUs on which it is eligible to run. On a multiprocessor system, setting the CPU affinity mask can be used to obtain performance benefits. For example, by dedicating one CPU to a particular process (i.e., setting the affinity mask of that process to specify a single CPU, and setting the affinity mask of all other processes to exclude that CPU), it is possible to ensure maximum execution speed for that process. Restricting a process to run on a single CPU also prevents the performance cost caused by the cache invalidation that occurs when a process ceases to execute on one CPU and then recommences execution on a different CPU.

Arguments

eax 241
ebx PID of the process. If it's zero then the calling process is used.
If the process specified by ebx is not currently running on one of the CPUs specified in cpumask_t, then that process is migrated to one of the CPUs specified in cpumask_t.
ecx Length in bytes of the cpumask_t structure pointed to by edx.
edx Pointer to a buffer containing a properly initialized cpumask_t structure:
struc cpumask_t
{
bits rd ((NR_CPUS+31)/32)
}

Return values

If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:

-EFAULT A supplied memory address was invalid.
-EINVAL Size of the buffer pointed by edx is smaller than sizeof.cpumask_t.
-ESRCH The process whose ID is ebx could not be found.
-EPERM The calling process does not have appropriate privileges. The process calling sys_sched_setaffinity needs an effective user ID equal to the user ID or effective user ID of the process identified by ebx, or it must possess the CAP_SYS_NICE capability.

Remarks

The affinity mask is actually a per-thread attribute that can be adjusted independently for each of the threads in a thread group. The value returned from a call to sys_gettid can be passed in the argument ebx.

A child created via sys_fork inherits its parent's CPU affinity mask. The affinity mask is preserved across an sys_execve.

Compatibility

n/a