Manual Pages for Linux CentOS command on man pthread_getaffinity_np
MyWebUniversity

Manual Pages for Linux CentOS command on man pthread_getaffinity_np

PTHREADSETAFFINITYNP(3) Linux Programmer's Manual PTHREADSETAFFINITYNP(3)

NAME

pthreadsetaffinitynp, pthreadgetaffinitynp - set/get CPU affinity of a thread SYNOPSIS

#define GNUSOURCE /* See featuretestmacros(7) */

#include int pthreadsetaffinitynp(pthreadt thread, sizet cpusetsize, const cpusett *cpuset); int pthreadgetaffinitynp(pthreadt thread, sizet cpusetsize, cpusett *cpuset);

Compile and link with -pthread. DESCRIPTION The pthreadsetaffinitynp() function sets the CPU affinity mask of the thread thread to the CPU set pointed to by cpuset. If the call is suc‐ cessful, and the thread is not currently running on one of the CPUs in cpuset, then it is migrated to one of those CPUs. The pthreadgetaffinitynp() function returns the CPU affinity mask of the thread thread in the buffer pointed to by cpuset. For more details on CPU affinity masks, see schedsetaffinity(2). For a description of a set of macros that can be used to manipulate and inspect CPU sets, see CPUSET(3). The argument cpusetsize is the length (in bytes) of the buffer pointed to by cpuset. Typically, this argument would be specified as sizeof(cpusett). (It may be some other value, if using the macros described in CPUSET(3) for dynamically allocating a CPU set.) RETURN VALUE On success, these functions return 0; on error, they return a nonzero error number. ERRORS EFAULT A supplied memory address was invalid. EINVAL (pthreadsetaffinitynp()) The affinity bit mask mask contains no processors that are currently physically on the system and permitted to the thread according to any restrictions that may be imposed by the "cpuset" mechanism described in cpuset(7). EINVAL (pthreadsetaffinitynp()) cpuset specified a CPU that was out‐ side the set supported by the kernel. (The kernel configuration option CONFIGNRCPUS defines the range of the set supported by the kernel data type used to represent CPU sets.) EINVAL (pthreadgetaffinitynp()) cpusetsize is smaller than the size of the affinity mask used by the kernel. ESRCH No thread with the ID thread could be found. VERSIONS These functions are provided by glibc since version 2.3.4. ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). ┌──────────────────────────┬───────────────┬─────────┐ │Interface │ Attribute │ Value │ ├──────────────────────────┼───────────────┼─────────┤

│pthreadsetaffinitynp(), │ Thread safety │ MT-Safe │ │pthreadgetaffinitynp() │ │ │ └──────────────────────────┴───────────────┴─────────┘ CONFORMING TO These functions are nonstandard GNU extensions; hence the suffix "np" (nonportable) in the names. NOTES After a call to pthreadsetaffinitynp(), the set of CPUs on which the thread will actually run is the intersection of the set specified in the cpuset argument and the set of CPUs actually present on the system. The system may further restrict the set of CPUs on which the thread runs if the "cpuset" mechanism described in cpuset(7) is being used. These restrictions on the actual set of CPUs on which the thread will run are silently imposed by the kernel. These functions are implemented on top of the schedsetaffinity(2) and schedgetaffinity(2) system calls. In glibc 2.3.3 only, versions of these functions were provided that did not have a cpusetsize argument. Instead the CPU set size given to the underlying system calls was always sizeof(cpusett). A new thread created by pthreadcreate(3) inherits a copy of its cre‐ ator's CPU affinity mask. EXAMPLE In the following program, the main thread uses pthreadsetaffinitynp() to set its CPU affinity mask to include CPUs 0 to 7 (which may not all be available on the system), and then calls pthreadgetaffinitynp() to check the resulting CPU affinity mask of the thread.

#define GNUSOURCE

#include

#include

#include

#include

#define handleerroren(en, msg) \ do { errno = en; perror(msg); exit(EXITFAILURE); } while (0) int main(int argc, char *argv[]) { int s, j; cpusett cpuset; pthreadt thread; thread = pthreadself(); /* Set affinity mask to include CPUs 0 to 7 */ CPUZERO(&cpuset); for (j = 0; j < 8; j++) CPUSET(j, &cpuset); s = pthreadsetaffinitynp(thread, sizeof(cpusett), &cpuset); if (s != 0) handleerroren(s, "pthreadsetaffinitynp"); /* Check the actual affinity mask assigned to the thread */ s = pthreadgetaffinitynp(thread, sizeof(cpusett), &cpuset); if (s != 0) handleerroren(s, "pthreadgetaffinitynp"); printf("Set returned by pthreadgetaffinitynp() contained:\n"); for (j = 0; j < CPUSETSIZE; j++) if (CPUISSET(j, &cpuset))

printf(" CPU %d\n", j); exit(EXITSUCCESS); } SEE ALSO schedsetaffinity(2), schedsetscheduler(2), pthreadattrsetaffin‐ itynp(3), pthreadself(3), schedgetcpu(3), cpuset(7), pthreads(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2010-09-10 PTHREADSETAFFINITYNP(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™