Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

affinity(3) [netbsd man page]

AFFINITY(3)						   BSD Library Functions Manual 					       AFFINITY(3)

NAME
pthread_setaffinity_np, pthread_getaffinity_np -- affinity of threads LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> #include <sched.h> int pthread_setaffinity_np(pthread_t thread, size_t size, cpuset_t *set); int pthread_getaffinity_np(pthread_t thread, size_t size, cpuset_t *set); DESCRIPTION
Thread affinity allows to run the thread on specified CPU or CPUs only. The pthread_setaffinity_np() function sets the affinity mask set for thread. At least one valid CPU must be set in the mask. The pthread_getaffinity_np() function gets the affinity mask of thread into set. Note that set must be created and initialized using the cpuset(3) functions. IMPLEMENTATION NOTES
Setting CPU pthread_setaffinity_np requires super-user privileges. Ordinary users can be allowed to control CPU affinity of their threads via the security.models.extensions.user_set_cpu_affinity sysctl(7). See secmodel_extensions(9). Portable applications should not use the pthread_setaffinity_np() and pthread_getaffinity_np() functions. RETURN VALUES
The pthread_setaffinity_np() and pthread_getaffinity_np() functions return 0 on success. Otherwise, an error number is returned to indicate the error. EXAMPLES
An example of code fragment, which sets the affinity for the current thread to the CPU whose ID is 0: cpuset_t *cset; pthread_t pth; cpuid_t ci; cset = cpuset_create(); if (cset == NULL) { err(EXIT_FAILURE, "cpuset_create"); } ci = 0; cpuset_set(ci, cset); pth = pthread_self(); error = pthread_setaffinity_np(pth, cpuset_size(cset), cset); if (error) { ... } cpuset_destroy(cset); COMPATIBILITY
Both functions are non-standard extensions. ERRORS
Both functions may fail if: [EINVAL] The specified set was invalid. [EPERM] The calling process lacks the appropriate privileges to perform the operation. [ESRCH] No thread could be found corresponding to the one specified by thread. NOTES
There is an alternative processor sets interface, see pset(3). However, thread affinity and processor sets are mutually exclusive, hence mixing of these interfaces is prohibited. SEE ALSO
cpuset(3), pset(3), pthread_getschedparam(3), pthread_setschedparam(3), sched(3), schedctl(8) BSD
December 4, 2011 BSD

Check Out this Related Man Page

PTHREAD_AFFINITY_NP(3)					   BSD Library Functions Manual 				    PTHREAD_AFFINITY_NP(3)

NAME
pthread_getaffinity_np, pthread_setaffinity_np -- manage CPU affinity LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread_np.h> int pthread_getaffinity_np(pthread_t td, size_t cpusetsize, cpuset_t *cpusetp); int pthread_setaffinity_np(pthread_t td, size_t cpusetsize, const cpuset_t *cpusetp); DESCRIPTION
pthread_getaffinity_np() and pthread_setaffinity_np() allow the manipulation of sets of CPUs available to the specified thread. Masks of type cpuset_t are composed using the CPU_SET macros. The kernel tolerates large sets as long as all CPUs specified in the set exist. Sets smaller than the kernel uses generate an error on calls to pthread_getaffinity_np() even if the result set would fit within the user supplied set. Calls to pthread_setaffinity_np() tolerate small sets with no restrictions. The supplied mask should have a size of cpusetsize bytes. This size is usually provided by calling sizeof(cpuset_t) which is ultimately determined by the value of CPU_SETSIZE as defined in <sys/cpuset.h>. pthread_getaffinity_np() retrieves the mask from the thread specified by td, and stores it in the space provided by cpusetp. pthread_setaffinity_np() attempts to set the mask for the thread specified by td to the value in cpusetp. RETURN VALUES
If successful, the pthread_getaffinity_np() and pthread_setaffinity_np() functions will return zero. Otherwise an error number will be returned to indicate the error. ERRORS
The pthread_getaffinity_np() and pthread_setaffinity_np() functions may fail if: [EDEADLK] The pthread_setaffinity_np() call would leave a thread without a valid CPU to run on because the set does not overlap with the thread's anonymous mask. [EFAULT] The cpusetp pointer passed was invalid. [ESRCH] The thread specified by the td argument could not be found. [ERANGE] The cpusetsize was either preposterously large or smaller than the kernel set size. [EPERM] The calling thread did not have the credentials required to complete the operation. SEE ALSO
cpuset(1), cpuset(2), cpuset_getid(2), cpuset_setid(2), pthread(3), pthread_attr_getaffinity_np(3), pthread_attr_setaffinity_np(3) STANDARDS
The pthread_getaffinity_np and pthread_setaffinity_np functions are non-standard FreeBSD extensions and may be not available on other operat- ing systems. HISTORY
The pthread_getaffinity_np and pthread_setaffinity_np function first appeared in FreeBSD 7.2. AUTHORS
The pthread_getaffinity_np and pthread_setaffinity_np functions were written by David Xu <davidxu@FreeBSD.org>, and this manpage was written by Xin LI <delphij@FreeBSD.org>. BSD
March 23, 2010 BSD
Man Page