From owner-svn-src-all@FreeBSD.ORG Fri Jan 28 20:06:51 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6DA6F1065675; Fri, 28 Jan 2011 20:06:51 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5C6F18FC0C; Fri, 28 Jan 2011 20:06:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p0SK6pZX098272; Fri, 28 Jan 2011 20:06:51 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p0SK6pEq098269; Fri, 28 Jan 2011 20:06:51 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201101282006.p0SK6pEq098269@svn.freebsd.org> From: John Baldwin Date: Fri, 28 Jan 2011 20:06:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218034 - stable/7/usr.bin/cpuset X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2011 20:06:51 -0000 Author: jhb Date: Fri Jan 28 20:06:51 2011 New Revision: 218034 URL: http://svn.freebsd.org/changeset/base/218034 Log: MFC 217416: 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. Modified: stable/7/usr.bin/cpuset/cpuset.1 stable/7/usr.bin/cpuset/cpuset.c Directory Properties: stable/7/usr.bin/cpuset/ (props changed) Modified: stable/7/usr.bin/cpuset/cpuset.1 ============================================================================== --- stable/7/usr.bin/cpuset/cpuset.1 Fri Jan 28 20:06:39 2011 (r218033) +++ stable/7/usr.bin/cpuset/cpuset.1 Fri Jan 28 20:06:51 2011 (r218034) @@ -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 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 -p +.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 .Sh SEE ALSO .Xr cpuset 2 .Sh HISTORY Modified: stable/7/usr.bin/cpuset/cpuset.c ============================================================================== --- stable/7/usr.bin/cpuset/cpuset.c Fri Jan 28 20:06:39 2011 (r218033) +++ stable/7/usr.bin/cpuset/cpuset.c Fri Jan 28 20:06:51 2011 (r218034) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include +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");