summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_cpuset.c
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2011-05-23 01:17:30 +0000
committerattilio <attilio@FreeBSD.org>2011-05-23 01:17:30 +0000
commit6d7371f9503a4d916171e610f74e6bcf20071227 (patch)
tree928f7851275f7cfa4af60866d7d7f52e1b172065 /sys/kern/kern_cpuset.c
parentb580be6dfd3bce7b7a252cf3446d750faca58427 (diff)
downloadFreeBSD-src-6d7371f9503a4d916171e610f74e6bcf20071227.zip
FreeBSD-src-6d7371f9503a4d916171e610f74e6bcf20071227.tar.gz
MFC
Diffstat (limited to 'sys/kern/kern_cpuset.c')
-rw-r--r--sys/kern/kern_cpuset.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/sys/kern/kern_cpuset.c b/sys/kern/kern_cpuset.c
index 3b2c653..5ca3be2 100644
--- a/sys/kern/kern_cpuset.c
+++ b/sys/kern/kern_cpuset.c
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <sys/cpuset.h>
#include <sys/sx.h>
#include <sys/queue.h>
+#include <sys/libkern.h>
#include <sys/limits.h>
#include <sys/bus.h>
#include <sys/interrupt.h>
@@ -660,6 +661,41 @@ cpusetobj_strprint(char *buf, const cpuset_t *set)
}
/*
+ * Build a valid cpuset_t object from a string representation.
+ * It expects an incoming buffer at least sized as CPUSETBUFSIZ.
+ */
+int
+cpusetobj_strscan(cpuset_t *set, const char *buf)
+{
+ u_int nwords;
+ int i;
+
+ if (strlen(buf) > CPUSETBUFSIZ - 1)
+ return (-1);
+
+ /* Allow to pass a shorter version of the mask when necessary. */
+ nwords = 1;
+ for (i = 0; buf[i] != '\0'; i++)
+ if (buf[i] == ',')
+ nwords++;
+ if (nwords > _NCPUWORDS)
+ return (-1);
+
+ CPU_ZERO(set);
+ for (i = nwords - 1; i > 0; i--) {
+ if (!sscanf(buf, "%lx, ", &set->__bits[i]))
+ return (-1);
+ buf = strstr(buf, " ");
+ if (buf == NULL)
+ return (-1);
+ buf++;
+ }
+ if (!sscanf(buf, "%lx", &set->__bits[0]))
+ return (-1);
+ return (0);
+}
+
+/*
* Apply an anonymous mask to a single thread.
*/
int
OpenPOWER on IntegriCloud