Processor affinity calls

Linux-specific processor affinity calls are provided, which help the threads define on which CPU(s) they want to run. By default, every thread inherits the processor affinity of its parent, but it can define its affinity mask to determine its processor affinity. On many-core systems, CPU affinity calls help in enhancing the performance, by helping the process stick to one core (Linux however attempts to keep a thread on one CPU). The affinity bitmask information is contained in the cpu_allowed field of struct task_struct. The affinity calls are as follows:

sched_setaffinity(pid_t pid, size_t cpusetsize, const cpu_set_t *mask)

It sets the CPU affinity mask of the thread (pid) to the value mentioned by mask. If the thread (pid) is not running in one of the specified CPU's queues, it is migrated to the specified cpu. On success, it returns zero.

sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask)

This fetches the affinity mask of the thread (pid) into the cpusetsize structure, pointed to by mask. If the pid is zero, the mask of the calling thread is returned. On success, it returns zero.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.182.45