Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/sys/cpuset.2
.\" Copyright (c) 2008 Christian Brueffer | .\" Copyright (c) 2008 Christian Brueffer | |||||||||||||||||||||
.\" Copyright (c) 2008 Jeffrey Roberson | .\" Copyright (c) 2008 Jeffrey Roberson | |||||||||||||||||||||
.\" Copyright (c) 2020 Robert N. M. Watson | ||||||||||||||||||||||
jrtc27: and now 2021 :) | ||||||||||||||||||||||
.\" All rights reserved. | .\" All rights reserved. | |||||||||||||||||||||
.\" | .\" | |||||||||||||||||||||
.\" Redistribution and use in source and binary forms, with or without | .\" Redistribution and use in source and binary forms, with or without | |||||||||||||||||||||
.\" modification, are permitted provided that the following conditions | .\" modification, are permitted provided that the following conditions | |||||||||||||||||||||
.\" are met: | .\" are met: | |||||||||||||||||||||
.\" 1. Redistributions of source code must retain the above copyright | .\" 1. Redistributions of source code must retain the above copyright | |||||||||||||||||||||
.\" notice, this list of conditions and the following disclaimer. | .\" notice, this list of conditions and the following disclaimer. | |||||||||||||||||||||
.\" 2. Redistributions in binary form must reproduce the above copyright | .\" 2. Redistributions in binary form must reproduce the above copyright | |||||||||||||||||||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | ||||||||||||||||||||||
with a process or thread is unsupported since | with a process or thread is unsupported since | |||||||||||||||||||||
this references the unnumbered anonymous mask. | this references the unnumbered anonymous mask. | |||||||||||||||||||||
.Pp | .Pp | |||||||||||||||||||||
The actual contents of the sets may be retrieved or manipulated using | The actual contents of the sets may be retrieved or manipulated using | |||||||||||||||||||||
.Xr cpuset_getaffinity 2 , | .Xr cpuset_getaffinity 2 , | |||||||||||||||||||||
.Xr cpuset_setaffinity 2 , | .Xr cpuset_setaffinity 2 , | |||||||||||||||||||||
.Xr cpuset_getdomain 2 , and | .Xr cpuset_getdomain 2 , and | |||||||||||||||||||||
.Xr cpuset_setdomain 2 . | .Xr cpuset_setdomain 2 . | |||||||||||||||||||||
The | ||||||||||||||||||||||
.Xr cpuset 9 | ||||||||||||||||||||||
macros may be used to manipulate masks of type | ||||||||||||||||||||||
.Ft cpuset_t | ||||||||||||||||||||||
get and set using those APIs. | ||||||||||||||||||||||
See those manual pages for more detail. | See those manual pages for more detail. | |||||||||||||||||||||
.Sh RETURN VALUES | .Sh RETURN VALUES | |||||||||||||||||||||
.Rv -std | .Rv -std | |||||||||||||||||||||
.Sh EXAMPLES | ||||||||||||||||||||||
In this example, a CPU set mask is configured to limit execution to the first | ||||||||||||||||||||||
CPU using | ||||||||||||||||||||||
Done Inline ActionsMissing "the"? jrtc27: Missing "the"? | ||||||||||||||||||||||
Done Inline ActionsHmm. I'm not seeing this one. Possibly you've not spotted the comma in ".Xr CPU_SET 9 ,"? Or, I'm just not seeing it due to staring at mandoc too much, and you should be more specific :-). rwatson: Hmm. I'm not seeing this one. Possibly you've not spotted the comma in ".Xr CPU_SET 9 ,"? Or… | ||||||||||||||||||||||
Done Inline ActionsOh, yes, I had missed the comma. jrtc27: Oh, yes, I had missed the comma. | ||||||||||||||||||||||
.Xr CPU_ZERO 9 | ||||||||||||||||||||||
and | ||||||||||||||||||||||
Done Inline ActionsMinor nit: you ended up using CPU_ZERO() instead; another good example could be to create a new set, grab the affinity, then clear half of the cpus; we can defer on that one, though. kevans: Minor nit: you ended up using CPU_ZERO() instead; another good example could be to create a new… | ||||||||||||||||||||||
.Xr CPU_SET 9 , | ||||||||||||||||||||||
members of the | ||||||||||||||||||||||
.Xr cpuset 9 | ||||||||||||||||||||||
programming interface. | ||||||||||||||||||||||
Then, the mask is applied to a new anonymous CPU set associated with the | ||||||||||||||||||||||
current process using | ||||||||||||||||||||||
.Xr cpuset_setaffinity 2 . | ||||||||||||||||||||||
This mask will be used by the current process, and inherited by any new | ||||||||||||||||||||||
children processes. | ||||||||||||||||||||||
Done Inline ActionsNoun adjuncts are generally singular jrtc27: Noun adjuncts are generally singular | ||||||||||||||||||||||
.Bd -literal -offset indent | ||||||||||||||||||||||
#include <sys/param.h> | ||||||||||||||||||||||
#include <sys/cpuset.h> | ||||||||||||||||||||||
#include <sysexits.h> | ||||||||||||||||||||||
Done Inline Actions
Typo. 0mp: Typo. | ||||||||||||||||||||||
Done Inline Actionsstyle(9) wants a blank line between kernel and user headers. Don't know if that should be adhered to here or not. jrtc27: style(9) wants a blank line between kernel and user headers. Don't know if that should be… | ||||||||||||||||||||||
cpuset_t cpuset_mask; | ||||||||||||||||||||||
/* Initialize a CPU mask and enable CPU 0. */ | ||||||||||||||||||||||
CPU_ZERO(&cpuset_mask); | ||||||||||||||||||||||
CPU_SET(1, &cpuset_mask); | ||||||||||||||||||||||
/* Set affinity for the CPU set for the current process. */ | ||||||||||||||||||||||
if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, | ||||||||||||||||||||||
sizeof(cpuset_mask), &cpuset_mask) < 0) | ||||||||||||||||||||||
err(EX_OSERR, "cpuset_setaffinity"); | ||||||||||||||||||||||
Done Inline Actions
jrtc27: | ||||||||||||||||||||||
.Ed | ||||||||||||||||||||||
.Pp | ||||||||||||||||||||||
In the next example, a named CPU set is created containing the current | ||||||||||||||||||||||
process, and its affinity similarly configured. | ||||||||||||||||||||||
The resulting CPU set ID ccan then be used for further external management of | ||||||||||||||||||||||
Done Inline Actions
jrtc27: | ||||||||||||||||||||||
the affinity of the set. | ||||||||||||||||||||||
.Bd -literal -offset indent | ||||||||||||||||||||||
#include <sys/param.h> | ||||||||||||||||||||||
#include <sys/cpuset.h> | ||||||||||||||||||||||
#include <sysexits.h> | ||||||||||||||||||||||
Done Inline ActionsDitto jrtc27: Ditto | ||||||||||||||||||||||
cpusetid_t cpuset_id; | ||||||||||||||||||||||
cpuset_t cpuset_mask; | ||||||||||||||||||||||
/* Create new cpuset for the currenfor t process. */ | ||||||||||||||||||||||
Done Inline Actions
jrtc27: | ||||||||||||||||||||||
if (cpuset(&cpuset_id) < 0) | ||||||||||||||||||||||
err(EX_OSERR, "cpuset"); | ||||||||||||||||||||||
/* Initialize a CPU mask and enable CPU 0. */ | ||||||||||||||||||||||
CPU_ZERO(&cpuset_mask); | ||||||||||||||||||||||
CPU_SET(1, &cpuset_mask); | ||||||||||||||||||||||
/* Set affinity for the CPU set for the current process. */ | ||||||||||||||||||||||
if (cpuset_setaffinity(CPU_LEVEL_SET, CPU_WHICH_CPUSET, cpuset_id, | ||||||||||||||||||||||
sizeof(cpuset_mask), &cpuset_mask) < 0) | ||||||||||||||||||||||
err(EX_OSERR, "cpuset_setaffinity"); | ||||||||||||||||||||||
.Ed | ||||||||||||||||||||||
.Sh ERRORS | .Sh ERRORS | |||||||||||||||||||||
The following error codes may be set in | The following error codes may be set in | |||||||||||||||||||||
.Va errno : | .Va errno : | |||||||||||||||||||||
.Bl -tag -width Er | .Bl -tag -width Er | |||||||||||||||||||||
.It Bq Er EINVAL | .It Bq Er EINVAL | |||||||||||||||||||||
The | The | |||||||||||||||||||||
.Fa which | .Fa which | |||||||||||||||||||||
or | or | |||||||||||||||||||||
Show All 27 Lines | ||||||||||||||||||||||
.Sh SEE ALSO | .Sh SEE ALSO | |||||||||||||||||||||
.Xr cpuset 1 , | .Xr cpuset 1 , | |||||||||||||||||||||
.Xr cpuset_getaffinity 2 , | .Xr cpuset_getaffinity 2 , | |||||||||||||||||||||
.Xr cpuset_getdomain 2 , | .Xr cpuset_getdomain 2 , | |||||||||||||||||||||
.Xr cpuset_setaffinity 2 , | .Xr cpuset_setaffinity 2 , | |||||||||||||||||||||
.Xr cpuset_setdomain 2 , | .Xr cpuset_setdomain 2 , | |||||||||||||||||||||
.Xr pthread_affinity_np 3 , | .Xr pthread_affinity_np 3 , | |||||||||||||||||||||
.Xr pthread_attr_affinity_np 3 , | .Xr pthread_attr_affinity_np 3 , | |||||||||||||||||||||
.Xr CPU_SET 9 , | ||||||||||||||||||||||
.Xr CPU_ZERO 9 , | ||||||||||||||||||||||
Done Inline ActionsI'd leave CPU_CLR in as an xref even if the example didn't end up using it and add CPU_ZERO to this list; all three are useful to point out. kevans: I'd leave CPU_CLR in as an xref even if the example didn't end up using it and add CPU_ZERO to… | ||||||||||||||||||||||
.Xr cpuset 9 | .Xr cpuset 9 | |||||||||||||||||||||
.Sh HISTORY | .Sh HISTORY | |||||||||||||||||||||
The | The | |||||||||||||||||||||
.Nm | .Nm | |||||||||||||||||||||
family of system calls first appeared in | family of system calls first appeared in | |||||||||||||||||||||
.Fx 7.1 . | .Fx 7.1 . | |||||||||||||||||||||
.Sh AUTHORS | .Sh AUTHORS | |||||||||||||||||||||
.An Jeffrey Roberson Aq Mt jeff@FreeBSD.org | .An Jeffrey Roberson Aq Mt jeff@FreeBSD.org |
and now 2021 :)