diff options
Diffstat (limited to 'usr.bin/cpuset')
-rw-r--r-- | usr.bin/cpuset/cpuset.1 | 17 | ||||
-rw-r--r-- | usr.bin/cpuset/cpuset.c | 31 |
2 files changed, 43 insertions, 5 deletions
diff --git a/usr.bin/cpuset/cpuset.1 b/usr.bin/cpuset/cpuset.1 index 88e8c98..17d9ce9 100644 --- a/usr.bin/cpuset/cpuset.1 +++ b/usr.bin/cpuset/cpuset.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 29, 2008 +.Dd January 14, 2011 .Dt CPUSET 1 .Os .Sh NAME @@ -41,6 +41,11 @@ .Op Fl s Ar setid .Fl p Ar pid .Nm +.Op Fl c +.Op Fl l Ar cpu-list +.Fl C +.Fl p Ar pid +.Nm .Op Fl cr .Op Fl l Ar cpu-list .Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq @@ -98,6 +103,8 @@ for the thread. .Pp The options are as follows: .Bl -tag -width ".Fl l Ar cpu-list" +.It Fl C +Create a new cpuset and assign the target process to that set. .It Fl c The requested operation should reference the cpuset available via the target specifier. @@ -117,6 +124,9 @@ Specifies a jail id as the target of the operation. Specifies a list of CPUs to apply to a target. Specification may include numbers separated by '-' for ranges and commas separating individual numbers. +A special list of +.Dq all +may be specified in which case the list includes all CPUs from the root set. .It Fl p Ar pid Specifies a pid as the target of the operation. .It Fl s Ar setid @@ -168,6 +178,11 @@ into the specified cpuset .Ar setid so it may be managed with other pids in that set: .Dl cpuset -s <setid> -p <pid> +.Pp +Create a new cpuset that is restricted to CPUs 0 and 2 and move +.Ar pid +into the new set: +.Dl cpuset -C -c -l 0,2 -p <pid> .Sh SEE ALSO .Xr cpuset 2 .Sh HISTORY diff --git a/usr.bin/cpuset/cpuset.c b/usr.bin/cpuset/cpuset.c index 35b13af..0c0a2f2 100644 --- a/usr.bin/cpuset/cpuset.c +++ b/usr.bin/cpuset/cpuset.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <string.h> +int Cflag; int cflag; int gflag; int iflag; @@ -72,6 +73,12 @@ parselist(char *list, cpuset_t *mask) int curnum; char *l; + if (strcasecmp(list, "all") == 0) { + if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, -1, + sizeof(*mask), mask) != 0) + err(EXIT_FAILURE, "getaffinity"); + return; + } state = NONE; curnum = lastnum = 0; for (l = list; *l != '\0';) { @@ -199,8 +206,11 @@ main(int argc, char *argv[]) level = CPU_LEVEL_WHICH; which = CPU_WHICH_PID; id = pid = tid = setid = -1; - while ((ch = getopt(argc, argv, "cgij:l:p:rs:t:x:")) != -1) { + while ((ch = getopt(argc, argv, "Ccgij:l:p:rs:t:x:")) != -1) { switch (ch) { + case 'C': + Cflag = 1; + break; case 'c': if (rflag) usage(); @@ -255,7 +265,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; if (gflag) { - if (argc || lflag) + if (argc || Cflag || lflag) usage(); /* Only one identity specifier. */ if (jflag + xflag + sflag + pflag + tflag > 1) @@ -272,7 +282,7 @@ main(int argc, char *argv[]) * The user wants to run a command with a set and possibly cpumask. */ if (argc) { - if (pflag | rflag | tflag | xflag | jflag) + if (Cflag | pflag | rflag | tflag | xflag | jflag) usage(); if (sflag) { if (cpuset_setid(CPU_WHICH_PID, -1, setid)) @@ -293,9 +303,11 @@ main(int argc, char *argv[]) /* * We're modifying something that presently exists. */ + if (Cflag && (sflag || rflag || !pflag || tflag || xflag || jflag)) + usage(); if (!lflag && (cflag || rflag)) usage(); - if (!lflag && !sflag) + if (!lflag && !(Cflag || sflag)) usage(); /* You can only set a mask on a thread. */ if (tflag && (sflag | pflag | xflag | jflag)) @@ -303,6 +315,15 @@ main(int argc, char *argv[]) /* You can only set a mask on an irq. */ if (xflag && (jflag | pflag | sflag | tflag)) usage(); + if (Cflag) { + /* + * Create a new cpuset and move the specified process + * into the set. + */ + if (cpuset(&setid) < 0) + err(EXIT_FAILURE, "newid"); + sflag = 1; + } if (pflag && sflag) { if (cpuset_setid(CPU_WHICH_PID, pid, setid)) err(EXIT_FAILURE, "setid"); @@ -331,6 +352,8 @@ usage(void) fprintf(stderr, " cpuset [-l cpu-list] [-s setid] -p pid\n"); fprintf(stderr, + " cpuset [-c] [-l cpu-list] -C -p pid\n"); + fprintf(stderr, " cpuset [-cr] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n"); fprintf(stderr, " cpuset [-cgir] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n"); |