hwlocality_cpubinding.3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. .TH "hwlocality_cpubinding" 3 "Thu Sep 7 2023" "Version 2.9.3" "Hardware Locality (hwloc)" \" -*- nroff -*-
  2. .ad l
  3. .nh
  4. .SH NAME
  5. hwlocality_cpubinding \- CPU binding
  6. .SH SYNOPSIS
  7. .br
  8. .PP
  9. .SS "Enumerations"
  10. .in +1c
  11. .ti -1c
  12. .RI "enum \fBhwloc_cpubind_flags_t\fP { \fBHWLOC_CPUBIND_PROCESS\fP, \fBHWLOC_CPUBIND_THREAD\fP, \fBHWLOC_CPUBIND_STRICT\fP, \fBHWLOC_CPUBIND_NOMEMBIND\fP }"
  13. .br
  14. .in -1c
  15. .SS "Functions"
  16. .in +1c
  17. .ti -1c
  18. .RI "int \fBhwloc_set_cpubind\fP (\fBhwloc_topology_t\fP topology, \fBhwloc_const_cpuset_t\fP set, int flags)"
  19. .br
  20. .ti -1c
  21. .RI "int \fBhwloc_get_cpubind\fP (\fBhwloc_topology_t\fP topology, \fBhwloc_cpuset_t\fP set, int flags)"
  22. .br
  23. .ti -1c
  24. .RI "int \fBhwloc_set_proc_cpubind\fP (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_const_cpuset_t\fP set, int flags)"
  25. .br
  26. .ti -1c
  27. .RI "int \fBhwloc_get_proc_cpubind\fP (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_cpuset_t\fP set, int flags)"
  28. .br
  29. .ti -1c
  30. .RI "int \fBhwloc_set_thread_cpubind\fP (\fBhwloc_topology_t\fP topology, hwloc_thread_t thread, \fBhwloc_const_cpuset_t\fP set, int flags)"
  31. .br
  32. .ti -1c
  33. .RI "int \fBhwloc_get_thread_cpubind\fP (\fBhwloc_topology_t\fP topology, hwloc_thread_t thread, \fBhwloc_cpuset_t\fP set, int flags)"
  34. .br
  35. .ti -1c
  36. .RI "int \fBhwloc_get_last_cpu_location\fP (\fBhwloc_topology_t\fP topology, \fBhwloc_cpuset_t\fP set, int flags)"
  37. .br
  38. .ti -1c
  39. .RI "int \fBhwloc_get_proc_last_cpu_location\fP (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_cpuset_t\fP set, int flags)"
  40. .br
  41. .in -1c
  42. .SH "Detailed Description"
  43. .PP
  44. Some operating systems only support binding threads or processes to a single PU\&. Others allow binding to larger sets such as entire Cores or Packages or even random sets of individual PUs\&. In such operating system, the scheduler is free to run the task on one of these PU, then migrate it to another PU, etc\&. It is often useful to call \fBhwloc_bitmap_singlify()\fP on the target CPU set before passing it to the binding function to avoid these expensive migrations\&. See the documentation of \fBhwloc_bitmap_singlify()\fP for details\&.
  45. .PP
  46. Some operating systems do not provide all hwloc-supported mechanisms to bind processes, threads, etc\&. \fBhwloc_topology_get_support()\fP may be used to query about the actual CPU binding support in the currently used operating system\&.
  47. .PP
  48. When the requested binding operation is not available and the \fBHWLOC_CPUBIND_STRICT\fP flag was passed, the function returns -1\&. \fCerrno\fP is set to \fCENOSYS\fP when it is not possible to bind the requested kind of object processes/threads\&. errno is set to \fCEXDEV\fP when the requested cpuset can not be enforced (e\&.g\&. some systems only allow one CPU, and some other systems only allow one NUMA node)\&.
  49. .PP
  50. If \fBHWLOC_CPUBIND_STRICT\fP was not passed, the function may fail as well, or the operating system may use a slightly different operation (with side-effects, smaller binding set, etc\&.) when the requested operation is not exactly supported\&.
  51. .PP
  52. The most portable version that should be preferred over the others, whenever possible, is the following one which just binds the current program, assuming it is single-threaded:
  53. .PP
  54. .PP
  55. .nf
  56. hwloc_set_cpubind(topology, set, 0),
  57. .fi
  58. .PP
  59. .PP
  60. If the program may be multithreaded, the following one should be preferred to only bind the current thread:
  61. .PP
  62. .PP
  63. .nf
  64. hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD),
  65. .fi
  66. .PP
  67. .PP
  68. \fBSee also\fP
  69. .RS 4
  70. Some example codes are available under doc/examples/ in the source tree\&.
  71. .RE
  72. .PP
  73. \fBNote\fP
  74. .RS 4
  75. To unbind, just call the binding function with either a full cpuset or a cpuset equal to the system cpuset\&.
  76. .PP
  77. On some operating systems, CPU binding may have effects on memory binding, see \fBHWLOC_CPUBIND_NOMEMBIND\fP
  78. .PP
  79. Running lstopo --top or hwloc-ps can be a very convenient tool to check how binding actually happened\&.
  80. .RE
  81. .PP
  82. .SH "Enumeration Type Documentation"
  83. .PP
  84. .SS "enum \fBhwloc_cpubind_flags_t\fP"
  85. .PP
  86. Process/Thread binding flags\&. These bit flags can be used to refine the binding policy\&.
  87. .PP
  88. The default (0) is to bind the current process, assumed to be single-threaded, in a non-strict way\&. This is the most portable way to bind as all operating systems usually provide it\&.
  89. .PP
  90. \fBNote\fP
  91. .RS 4
  92. Not all systems support all kinds of binding\&. See the 'Detailed Description' section of \fBCPU binding\fP for a description of errors that can occur\&.
  93. .RE
  94. .PP
  95. .PP
  96. \fBEnumerator\fP
  97. .in +1c
  98. .TP
  99. \fB\fIHWLOC_CPUBIND_PROCESS \fP\fP
  100. Bind all threads of the current (possibly) multithreaded process\&.
  101. .TP
  102. \fB\fIHWLOC_CPUBIND_THREAD \fP\fP
  103. Bind current thread of current process\&.
  104. .TP
  105. \fB\fIHWLOC_CPUBIND_STRICT \fP\fP
  106. Request for strict binding from the OS\&. By default, when the designated CPUs are all busy while other CPUs are idle, operating systems may execute the thread/process on those other CPUs instead of the designated CPUs, to let them progress anyway\&. Strict binding means that the thread/process will _never_ execute on other CPUs than the designated CPUs, even when those are busy with other tasks and other CPUs are idle\&.
  107. .PP
  108. \fBNote\fP
  109. .RS 4
  110. Depending on the operating system, strict binding may not be possible (e\&.g\&., the OS does not implement it) or not allowed (e\&.g\&., for an administrative reasons), and the function will fail in that case\&.
  111. .RE
  112. .PP
  113. When retrieving the binding of a process, this flag checks whether all its threads actually have the same binding\&. If the flag is not given, the binding of each thread will be accumulated\&.
  114. .PP
  115. \fBNote\fP
  116. .RS 4
  117. This flag is meaningless when retrieving the binding of a thread\&.
  118. .RE
  119. .PP
  120. .TP
  121. \fB\fIHWLOC_CPUBIND_NOMEMBIND \fP\fP
  122. Avoid any effect on memory binding\&. On some operating systems, some CPU binding function would also bind the memory on the corresponding NUMA node\&. It is often not a problem for the application, but if it is, setting this flag will make hwloc avoid using OS functions that would also bind memory\&. This will however reduce the support of CPU bindings, i\&.e\&. potentially return -1 with errno set to \fCENOSYS\fP in some cases\&.
  123. .PP
  124. This flag is only meaningful when used with functions that set the CPU binding\&. It is ignored when used with functions that get CPU binding information\&.
  125. .SH "Function Documentation"
  126. .PP
  127. .SS "int hwloc_get_cpubind (\fBhwloc_topology_t\fP topology, \fBhwloc_cpuset_t\fP set, int flags)"
  128. .PP
  129. Get current process or thread binding\&. The CPU-set \fCset\fP (previously allocated by the caller) is filled with the list of PUs which the process or thread (according to \fIflags\fP) was last bound to\&.
  130. .PP
  131. \fBReturns\fP
  132. .RS 4
  133. 0 on success, -1 on error\&.
  134. .RE
  135. .PP
  136. .SS "int hwloc_get_last_cpu_location (\fBhwloc_topology_t\fP topology, \fBhwloc_cpuset_t\fP set, int flags)"
  137. .PP
  138. Get the last physical CPU where the current process or thread ran\&. The CPU-set \fCset\fP (previously allocated by the caller) is filled with the list of PUs which the process or thread (according to \fIflags\fP) last ran on\&.
  139. .PP
  140. The operating system may move some tasks from one processor to another at any time according to their binding, so this function may return something that is already outdated\&.
  141. .PP
  142. \fCflags\fP can include either \fBHWLOC_CPUBIND_PROCESS\fP or \fBHWLOC_CPUBIND_THREAD\fP to specify whether the query should be for the whole process (union of all CPUs on which all threads are running), or only the current thread\&. If the process is single-threaded, flags can be set to zero to let hwloc use whichever method is available on the underlying OS\&.
  143. .PP
  144. \fBReturns\fP
  145. .RS 4
  146. 0 on success, -1 on error\&.
  147. .RE
  148. .PP
  149. .SS "int hwloc_get_proc_cpubind (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_cpuset_t\fP set, int flags)"
  150. .PP
  151. Get the current physical binding of process \fCpid\fP\&. The CPU-set \fCset\fP (previously allocated by the caller) is filled with the list of PUs which the process was last bound to\&.
  152. .PP
  153. \fBReturns\fP
  154. .RS 4
  155. 0 on success, -1 on error\&.
  156. .RE
  157. .PP
  158. \fBNote\fP
  159. .RS 4
  160. \fChwloc_pid_t\fP is \fCpid_t\fP on Unix platforms, and \fCHANDLE\fP on native Windows platforms\&.
  161. .PP
  162. As a special case on Linux, if a tid (thread ID) is supplied instead of a pid (process ID) and HWLOC_CPUBIND_THREAD is passed in flags, the binding for that specific thread is returned\&.
  163. .PP
  164. On non-Linux systems, HWLOC_CPUBIND_THREAD can not be used in \fCflags\fP\&.
  165. .RE
  166. .PP
  167. .SS "int hwloc_get_proc_last_cpu_location (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_cpuset_t\fP set, int flags)"
  168. .PP
  169. Get the last physical CPU where a process ran\&. The CPU-set \fCset\fP (previously allocated by the caller) is filled with the list of PUs which the process last ran on\&.
  170. .PP
  171. The operating system may move some tasks from one processor to another at any time according to their binding, so this function may return something that is already outdated\&.
  172. .PP
  173. \fBReturns\fP
  174. .RS 4
  175. 0 on success, -1 on error\&.
  176. .RE
  177. .PP
  178. \fBNote\fP
  179. .RS 4
  180. \fChwloc_pid_t\fP is \fCpid_t\fP on Unix platforms, and \fCHANDLE\fP on native Windows platforms\&.
  181. .PP
  182. As a special case on Linux, if a tid (thread ID) is supplied instead of a pid (process ID) and \fBHWLOC_CPUBIND_THREAD\fP is passed in flags, the last CPU location of that specific thread is returned\&.
  183. .PP
  184. On non-Linux systems, \fBHWLOC_CPUBIND_THREAD\fP can not be used in \fCflags\fP\&.
  185. .RE
  186. .PP
  187. .SS "int hwloc_get_thread_cpubind (\fBhwloc_topology_t\fP topology, hwloc_thread_t thread, \fBhwloc_cpuset_t\fP set, int flags)"
  188. .PP
  189. Get the current physical binding of thread \fCtid\fP\&. The CPU-set \fCset\fP (previously allocated by the caller) is filled with the list of PUs which the thread was last bound to\&.
  190. .PP
  191. \fBReturns\fP
  192. .RS 4
  193. 0 on success, -1 on error\&.
  194. .RE
  195. .PP
  196. \fBNote\fP
  197. .RS 4
  198. \fChwloc_thread_t\fP is \fCpthread_t\fP on Unix platforms, and \fCHANDLE\fP on native Windows platforms\&.
  199. .PP
  200. \fBHWLOC_CPUBIND_PROCESS\fP can not be used in \fCflags\fP\&.
  201. .RE
  202. .PP
  203. .SS "int hwloc_set_cpubind (\fBhwloc_topology_t\fP topology, \fBhwloc_const_cpuset_t\fP set, int flags)"
  204. .PP
  205. Bind current process or thread on CPUs given in physical bitmap \fCset\fP\&.
  206. .PP
  207. \fBReturns\fP
  208. .RS 4
  209. 0 on success\&.
  210. .PP
  211. -1 with errno set to \fCENOSYS\fP if the action is not supported\&.
  212. .PP
  213. -1 with errno set to \fCEXDEV\fP if the binding cannot be enforced\&.
  214. .RE
  215. .PP
  216. .SS "int hwloc_set_proc_cpubind (\fBhwloc_topology_t\fP topology, hwloc_pid_t pid, \fBhwloc_const_cpuset_t\fP set, int flags)"
  217. .PP
  218. Bind a process \fCpid\fP on CPUs given in physical bitmap \fCset\fP\&.
  219. .PP
  220. \fBReturns\fP
  221. .RS 4
  222. 0 on success, -1 on error\&.
  223. .RE
  224. .PP
  225. \fBNote\fP
  226. .RS 4
  227. \fChwloc_pid_t\fP is \fCpid_t\fP on Unix platforms, and \fCHANDLE\fP on native Windows platforms\&.
  228. .PP
  229. As a special case on Linux, if a tid (thread ID) is supplied instead of a pid (process ID) and \fBHWLOC_CPUBIND_THREAD\fP is passed in flags, the binding is applied to that specific thread\&.
  230. .PP
  231. On non-Linux systems, \fBHWLOC_CPUBIND_THREAD\fP can not be used in \fCflags\fP\&.
  232. .RE
  233. .PP
  234. .SS "int hwloc_set_thread_cpubind (\fBhwloc_topology_t\fP topology, hwloc_thread_t thread, \fBhwloc_const_cpuset_t\fP set, int flags)"
  235. .PP
  236. Bind a thread \fCthread\fP on CPUs given in physical bitmap \fCset\fP\&.
  237. .PP
  238. \fBReturns\fP
  239. .RS 4
  240. 0 on success, -1 on error\&.
  241. .RE
  242. .PP
  243. \fBNote\fP
  244. .RS 4
  245. \fChwloc_thread_t\fP is \fCpthread_t\fP on Unix platforms, and \fCHANDLE\fP on native Windows platforms\&.
  246. .PP
  247. \fBHWLOC_CPUBIND_PROCESS\fP can not be used in \fCflags\fP\&.
  248. .RE
  249. .PP
  250. .SH "Author"
  251. .PP
  252. Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code\&.