Page MenuHomeFreeBSD

D27803.id81280.diff
No OneTemporary

D27803.id81280.diff

Index: lib/libc/sys/cpuset.2
===================================================================
--- lib/libc/sys/cpuset.2
+++ lib/libc/sys/cpuset.2
@@ -1,5 +1,6 @@
.\" Copyright (c) 2008 Christian Brueffer
.\" Copyright (c) 2008 Jeffrey Roberson
+.\" Copyright (c) 2020 Robert N. M. Watson
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -183,6 +184,36 @@
See those manual pages for more detail.
.Sh RETURN VALUES
.Rv -std
+.Sh EXAMPLES
+In this example, a new CPU set is created for the current process using
+.Xr cpuset 2 .
+A CPU set mask is configured to limit execution to the first CPU using
+.Xr CPU_CLR 9
+and
+.Xr CPU_SET 9 .
+Finally, the mask is applied to the CPU set of the current process using
+.Xr cpuset_setaffinity 2 .
+.Bd -literal -offset indent
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#include <sysexits.h>
+
+cpusetid_t cpuset_id;
+cpuset_t cpuset_mask;
+
+/* Create new cpuset for the currenfor t process. */
+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_WHICH, CPU_WHICH_PID, -1,
+ sizeof(cpuset_mask), &cpuset_mask) < 0)
+ err(EX_OSERR, "cpuset_setaffinity");
+.Ed
.Sh ERRORS
The following error codes may be set in
.Va errno :
@@ -226,6 +257,8 @@
.Xr cpuset_setdomain 2 ,
.Xr pthread_affinity_np 3 ,
.Xr pthread_attr_affinity_np 3 ,
+.Xr CPU_CLR 9 ,
+.Xr CPU_SET 9 ,
.Xr cpuset 9
.Sh HISTORY
The

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 13, 1:56 AM (9 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26897803
Default Alt Text
D27803.id81280.diff (1 KB)

Event Timeline