diff options
author | jhb <jhb@FreeBSD.org> | 2011-01-14 19:57:28 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2011-01-14 19:57:28 +0000 |
commit | 5e29e07a8194515a467fb0cf8ecd2df710270422 (patch) | |
tree | c21c125df11721f4b9cfc1f7eb84c90409cfb63e /usr.bin/cpuset/cpuset.c | |
parent | fd260e63f5e201178daf5a59f86d43dd12a4179a (diff) | |
download | FreeBSD-src-5e29e07a8194515a467fb0cf8ecd2df710270422.zip FreeBSD-src-5e29e07a8194515a467fb0cf8ecd2df710270422.tar.gz |
Add two more features to cpuset(1):
- Add a new -C flag to create a new cpuset and move an existing pid into
that set.
- Allow 'all' to be specified for a cpu list (e.g. cpuset -s 1 -l all)
which maps to the list of all CPUs in the system.
MFC after: 2 weeks
Diffstat (limited to 'usr.bin/cpuset/cpuset.c')
-rw-r--r-- | usr.bin/cpuset/cpuset.c | 31 |
1 files changed, 27 insertions, 4 deletions
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"); |