Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jan 2011 20:06:51 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r218034 - stable/7/usr.bin/cpuset
Message-ID:  <201101282006.p0SK6pEq098269@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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

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 <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");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101282006.p0SK6pEq098269>