hwloc-bind.1 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. .\" -*- nroff -*-
  2. .\" Copyright © 2009-2023 Inria. All rights reserved.
  3. .\" Copyright © 2010 Université of Bordeaux
  4. .\" Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved.
  5. .\" See COPYING in top-level directory.
  6. .TH HWLOC-BIND "1" "Sep 07, 2023" "2.9.3" "hwloc"
  7. .SH NAME
  8. hwloc-bind \- Launch a command that is bound to specific processors
  9. and/or memory, or consult the binding of an existing program
  10. .
  11. .\" **************************
  12. .\" Synopsis Section
  13. .\" **************************
  14. .SH SYNOPSIS
  15. .
  16. .B hwloc-bind
  17. [\fItopology options\fR] [\fIoptions\fR] \fI<location1> [<location2> [...] ] [--] <command> \fR...
  18. .
  19. .PP
  20. Note that hwloc(7) provides a detailed explanation of the hwloc system
  21. and of valid <location> formats;
  22. it should be read before reading this man page.
  23. .\" **************************
  24. .\" Options Section
  25. .\" **************************
  26. .SH TOPOLOGY OPTIONS
  27. .
  28. All topology options must be given before all other options.
  29. .
  30. .TP 10
  31. \fB\-\-no\-smt\fR, \fB\-\-no\-smt=<N>\fR
  32. Only keep the first PU per core before binding.
  33. If \fI<N>\fR is specified, keep the <N>-th instead, if any.
  34. PUs are ordered by physical index during this filtering.
  35. Note that this option is applied after searching locations.
  36. Hence \fB\-\-no\-smt pu:2-5\fR will first select the PUs #2
  37. to #5 in the machine before binding on one of them per core.
  38. To rather bind on PUs #2 to #5 after filtering one per core,
  39. you should combine with hwloc-calc:
  40. hwloc-bind $(hwloc-calc --restrict $(hwloc-calc --no-smt all) pu:2-5) -- echo hello
  41. .TP
  42. \fB\-\-restrict\fR <cpuset>
  43. Restrict the topology to the given cpuset.
  44. This removes some PUs and their now-child-less parents.
  45. Beware that restricting the PUs in a topology may change the
  46. logical indexes of many objects, including NUMA nodes.
  47. .TP
  48. \fB\-\-restrict\fR nodeset=<nodeset>
  49. Restrict the topology to the given nodeset
  50. (unless \fB\-\-restrict\-flags\fR specifies something different).
  51. This removes some NUMA nodes and their now-child-less parents.
  52. Beware that restricting the NUMA nodes in a topology may change the
  53. logical indexes of many objects, including PUs.
  54. .TP
  55. \fB\-\-restrict\-flags\fR <flags>
  56. Enforce flags when restricting the topology.
  57. Flags may be given as numeric values or as a comma-separated list of flag names
  58. that are passed to \fIhwloc_topology_restrict()\fR.
  59. Those names may be substrings of actual flag names as long as a single one matches,
  60. for instance \fBbynodeset,memless\fR.
  61. The default is \fB0\fR (or \fBnone\fR).
  62. .TP
  63. \fB\-\-disallowed\fR
  64. Include objects disallowed by administrative limitations.
  65. .TP
  66. \fB\-\-best\-memattr\fR <name>
  67. Select the best NUMA node among the given memory binding set by looking
  68. at the memory attribute given by \fI<name>\fR (or as an index).
  69. If the memory attribute values depend on the initiator, the CPU binding
  70. set is used as the initiator.
  71. Standard attribute names are \fICapacity\fR, \fILocality\fR,
  72. \fIBandwidth\fR, and \fILatency\fR.
  73. All existing attributes in the current topology may be listed with
  74. $ lstopo --memattrs
  75. .TP
  76. \fB\-\-hbm\fR
  77. Only take high bandwidth memory nodes (Intel Xeon Phi MCDRAM)
  78. in account when looking for NUMA nodes in the input locations.
  79. This option must be combined with NUMA node locations,
  80. such as \fI--hbm numa:1\fR for binding on the second HBM node.
  81. It may also be written as \fIhbm:1\fR.
  82. .TP
  83. \fB\-\-no\-hbm\fR
  84. Ignore high bandwidth memory nodes (Intel Xeon Phi MCDRAM)
  85. when looking for NUMA nodes in the input locations.
  86. .
  87. .SH OPTIONS
  88. .
  89. All these options must be given after all topology options above.
  90. .
  91. .TP 10
  92. \fB\-\-cpubind\fR
  93. Use following arguments for CPU binding (default).
  94. .TP
  95. \fB\-\-membind\fR
  96. Use following arguments for memory binding.
  97. If \fB\-\-mempolicy\fR is not also given,
  98. the default policy is bind.
  99. .TP
  100. \fB\-\-mempolicy\fR <policy>
  101. Change the memory binding policy.
  102. This option is only meaningful when an actual binding is also given
  103. with \fB\-\-membind\fR.
  104. If \fB\-\-membind\fR is given without \fB\-\-mempolicy\fR,
  105. the default policy is bind.
  106. The available policies are \fBdefault\fR, \fBfirsttouch\fR,
  107. \fBbind\fR, \fBinterleave\fR and \fBnexttouch\fR.
  108. See hwloc.h for details about these policies.
  109. Note that hwloc's memory binding policies may be slightly different
  110. from operating system policies.
  111. For instance, the hwloc \fBbind\fR policy uses Linux \fIMPOL_PREFERRED_MANY\fR
  112. (or \fIMPOL_PREFERRED\fR) by default, but it switches to Linux \fIMPOL_BIND\fR
  113. if the hwloc strict option or flag is also given.
  114. .TP
  115. \fB\-\-get\fR
  116. Report the current bindings.
  117. The output is an opaque bitmask that may be translated into objects with hwloc-calc
  118. (see EXAMPLES below).
  119. .TP
  120. \
  121. When a command is given, the binding is displayed before executing
  122. the command. When no command is given, the program exits after
  123. displaying the current binding.
  124. .TP
  125. \
  126. When combined with \fB\-\-membind\fR, report the memory binding
  127. instead of CPU binding.
  128. .TP
  129. \
  130. No location may be given since no binding is performed.
  131. .TP
  132. \fB\-\-nodeset\fR
  133. Report binding as a NUMA memory node set instead of a CPU set
  134. if \-\-get was given.
  135. This is useful for manipulating CPU-less NUMA nodes since their
  136. cpuset is empty while their nodeset is correct.
  137. .TP
  138. \
  139. Also parse input bitmasks as nodesets instead of cpusets.
  140. .TP
  141. \
  142. When this option is not passed, individual input bitmasks may
  143. still be parsed as nodesets if they are prefixed with \fInodeset=\fR.
  144. .TP
  145. \fB\-e\fR \fB\-\-get\-last\-cpu\-location\fR
  146. Report the last processors where the process ran.
  147. The output is an opaque bitmask that may be translated into objects with hwloc-calc
  148. (see EXAMPLES below).
  149. .TP
  150. \
  151. Note that the result may already be outdated when reported since
  152. the operating system may move the process to other processors
  153. at any time according to the binding.
  154. .TP
  155. \
  156. When a command is given, the last processors is displayed before
  157. executing the command. When no command is given, the program exits
  158. after displaying the last processors.
  159. .TP
  160. \
  161. This option cannot be combined with \fB\-\-membind\fR.
  162. .TP
  163. \
  164. No location may be given since no binding is performed.
  165. .TP
  166. \fB\-\-single\fR
  167. Bind on a single CPU to prevent migration.
  168. .TP
  169. \fB\-\-strict\fR
  170. Require strict binding.
  171. .TP
  172. \fB\-\-pid\fR <pid>
  173. Operate on pid <pid>
  174. .TP
  175. \fB\-\-tid\fR <tid>
  176. Operate on thread <tid> instead of on an entire process.
  177. The feature is only supported on Linux for thread CPU binding,
  178. or for reporting the last processor where the thread ran if \fB\-e\fR was also passed.
  179. .TP
  180. \fB\-p\fR \fB\-\-physical\fR
  181. Interpret input locations with OS/physical indexes instead of logical indexes.
  182. This option does not apply to the output, see \fB\-\-get\fR above.
  183. .TP
  184. \fB\-l\fR \fB\-\-logical\fR
  185. Interpret input locations with logical indexes instead of physical/OS indexes (default).
  186. This option does not apply to the output, see \fB\-\-get\fR above.
  187. .TP
  188. \fB\-\-taskset\fR
  189. Display CPU set strings in the format recognized by the taskset command-line
  190. program instead of hwloc-specific CPU set string format.
  191. This option has no impact on the format of input CPU set strings,
  192. both formats are always accepted.
  193. .TP
  194. \fB\-f\fR \fB\-\-force\fR
  195. Launch the executable even if binding failed.
  196. .TP
  197. \fB\-q\fR \fB\-\-quiet\fR
  198. Hide non-fatal error messages.
  199. It includes locations pointing to non-existing objects,
  200. as well as failure to bind.
  201. This is usually useful in addition to \fB\-\-force\fR.
  202. .TP
  203. \fB\-v\fR \fB\-\-verbose\fR
  204. Verbose output.
  205. .TP
  206. \fB\-\-version\fR
  207. Report version and exit.
  208. .TP
  209. \fB\-h\fR \fB\-\-help\fR
  210. Display help message and exit.
  211. .
  212. .\" **************************
  213. .\" Description Section
  214. .\" **************************
  215. .SH DESCRIPTION
  216. .
  217. hwloc-bind execs an executable (with optional command line arguments)
  218. that is bound to the specified location (or list of locations).
  219. Location specification is described in hwloc(7).
  220. Upon successful execution, hwloc-bind simply sets bindings and then execs
  221. the executable over itself.
  222. .
  223. .PP
  224. If a bitmask location is given with prefix \fInodeset=\fR, then it
  225. is considered a nodeset instead of a CPU set. See also \fB\-\-nodeset\fR.
  226. .
  227. .PP
  228. If multiple locations are given, they are combined in the sense that
  229. the binding will be wider. The process will be allowed to run on every
  230. location inside the combination.
  231. .
  232. .PP
  233. The list of input locations may be explicitly ended with "--".
  234. .
  235. .PP
  236. If binding fails, or if the binding set is empty, and \fB\-\-force\fR
  237. was not given, hwloc-bind returns with an error instead of launching
  238. the executable.
  239. .
  240. .PP
  241. .B NOTE:
  242. It is highly recommended that you read the hwloc(7) overview page
  243. before reading this man page. Most of the concepts described in
  244. hwloc(7) directly apply to the hwloc-bind utility.
  245. .
  246. .
  247. .\" **************************
  248. .\" Examples Section
  249. .\" **************************
  250. .SH EXAMPLES
  251. .PP
  252. hwloc-bind's operation is best described through several examples.
  253. More details about how locations are specified on the hwloc-bind
  254. command line are described in hwloc(7).
  255. .
  256. .PP
  257. To run the echo command on the first logical processor of the second
  258. package:
  259. $ hwloc-bind package:1.pu:0 -- echo hello
  260. which is exactly equivalent to the following line as long as there is
  261. no ambiguity between hwloc-bind option names and the executed command name:
  262. $ hwloc-bind package:1.pu:0 echo hello
  263. To bind the "echo" command to the first core of the second package and
  264. the second core of the first package:
  265. $ hwloc-bind package:1.core:0 package:0.core:1 -- echo hello
  266. To bind on the first PU of all cores of the first package:
  267. $ hwloc-bind package:0.core:all.pu:0 -- echo hello
  268. $ hwloc-bind --no-smt package:0 -- echo hello
  269. To bind on the memory node local to a PU with largest capacity:
  270. $ hwloc-bind --best-memattr capacity --cpubind pu:23 --membind pu:23 -- echo hello
  271. To bind memory on the first high-bandwidth memory node on Intel Xeon Phi:
  272. $ hwloc-bind --membind hbm:0 -- echo hello
  273. $ hwloc-bind --hbm --membind numa:0 -- echo hello
  274. Note that binding the "echo" command to multiple processors is
  275. probably meaningless (because "echo" is likely implemented as a
  276. single-threaded application); these examples just serve to show what
  277. hwloc-bind can do.
  278. .
  279. .PP
  280. To run on the first three packages on the second and third nodes:
  281. $ hwloc-bind node:1-2.package:0:3 -- echo hello
  282. which is also equivalent to:
  283. $ hwloc-bind node:1-2.package:0-2 -- echo hello
  284. Note that if you attempt to bind to objects that do not exist,
  285. hwloc-bind will not warn unless
  286. .I -v
  287. was specified.
  288. To run on processor with physical index 2 in package with physical index 1:
  289. $ hwloc-bind --physical package:1.core:2 -- echo hello
  290. To run on odd cores within even packages:
  291. $ hwloc-bind package:even.core:odd -- echo hello
  292. To run on the first package, except on its second and fifth cores:
  293. $ hwloc-bind package:0 ~package:0.core:1 ~package:0.core:4 -- echo hello
  294. To run anywhere except on the first package:
  295. $ hwloc-bind all ~package:0 -- echo hello
  296. To run on a core near the network interface named eth0:
  297. $ hwloc-bind os=eth0 -- echo hello
  298. To run on a core near the PCI device whose bus ID is 0000:01:02.0:
  299. $ hwloc-bind pci=0000:01:02.0 -- echo hello
  300. To bind memory on second memory node and run on first node (when supported by the OS):
  301. $ hwloc-bind --cpubind node:1 --membind node:0 -- echo hello
  302. hwloc-bind does not have an option to select a kind of CPU core but it may
  303. be combined with hwloc-calc to do so. For instance, to bind on the first two
  304. cores whose kind matches CoreType=IntelAtom:
  305. $ hwloc-bind $(hwloc-calc --restrict $(hwloc-calc --cpukind CoreType=IntelAtom all) core:0-1) -- echo hello
  306. The --get option can report current bindings. This example shows
  307. nesting hwloc-bind invocations to set a binding and then report it:
  308. $ hwloc-bind node:1.package:2 -- hwloc-bind --get
  309. 0x00004444,0x44000000
  310. hwloc-calc can also be used to convert cpu mask strings to
  311. human-readable package/core/PU strings; see the description of -H in
  312. hwloc-calc(1) for more details. The following example binds to all
  313. the PUs in a specific core, uses the --get option to retrieve where
  314. the process was actually bound, and then uses hwloc-calc to display
  315. the resulting cpu mask in space-delimited list of human-readable
  316. locations:
  317. $ hwloc-bind package:1.core:2 -- hwloc-bind --get | hwloc-calc -H package.core.pu
  318. Package:1.Core:2.PU:0 Package:1.Core:2.PU:1
  319. hwloc-calc may convert this output into actual objects, either with logical or physical indexes:
  320. $ hwloc-calc --physical -I pu `hwloc-bind --get`
  321. 26,30,34,38,42,46
  322. $ hwloc-calc --logical -I pu `hwloc-bind --get` --sep " "
  323. 24 25 26 27 28 29
  324. .
  325. .PP
  326. Locations may also be specified as a hex bit mask (typically generated
  327. by hwloc-calc). For example:
  328. $ hwloc-bind 0x00004444,0x44000000 -- echo hello
  329. $ hwloc-bind `hwloc-calc node:1.package:2` -- echo hello
  330. The current memory binding may also be reported:
  331. $ hwloc-bind --membind node:1 --mempolicy interleave -- hwloc-bind --get --membind
  332. 0x000000f0 (interleave)
  333. .SH HINT
  334. If the graphics-enabled lstopo is available, use for instance
  335. $ hwloc-bind core:2 -- lstopo --pid 0
  336. to check what the result of your binding command actually is.
  337. lstopo will graphically show where it is bound to by hwloc-bind.
  338. .
  339. .\" **************************
  340. .\" Return value section
  341. .\" **************************
  342. .SH RETURN VALUE
  343. Upon successful execution, hwloc-bind execs the command over itself.
  344. The return value is therefore whatever the return value of the command
  345. is.
  346. .
  347. .PP
  348. hwloc-bind will return nonzero if any kind of error occurs, such as
  349. (but not limited to): failure to parse the command line, failure to
  350. retrieve process bindings, or lack of a command to execute.
  351. .
  352. .\" **************************
  353. .\" See also section
  354. .\" **************************
  355. .SH SEE ALSO
  356. .
  357. .ft R
  358. hwloc(7), lstopo(1), hwloc-calc(1), hwloc-distrib(1)
  359. .sp