Deleted Added
full compact
cpuset.c (178093) cpuset.c (185435)
1/*
2 * Copyright (c) 2007, 2008 Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2008 Nokia Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*
2 * Copyright (c) 2007, 2008 Jeffrey Roberson <jeff@freebsd.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2008 Nokia Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/usr.bin/cpuset/cpuset.c 178093 2008-04-11 03:27:42Z jeff $");
31__FBSDID("$FreeBSD: head/usr.bin/cpuset/cpuset.c 185435 2008-11-29 14:32:14Z bz $");
32
33#include <sys/param.h>
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/resource.h>
37#include <sys/cpuset.h>
38
39#include <ctype.h>

--- 4 unchanged lines hidden (view full) ---

44#include <stdlib.h>
45#include <stdint.h>
46#include <unistd.h>
47#include <string.h>
48
49int cflag;
50int gflag;
51int iflag;
32
33#include <sys/param.h>
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/resource.h>
37#include <sys/cpuset.h>
38
39#include <ctype.h>

--- 4 unchanged lines hidden (view full) ---

44#include <stdlib.h>
45#include <stdint.h>
46#include <unistd.h>
47#include <string.h>
48
49int cflag;
50int gflag;
51int iflag;
52int jflag;
52int lflag;
53int pflag;
54int rflag;
55int sflag;
56int tflag;
57int xflag;
58id_t id;
59cpulevel_t level;

--- 88 unchanged lines hidden (view full) ---

148 once = 1;
149 } else
150 printf(", %d", cpu);
151 }
152 }
153 printf("\n");
154}
155
53int lflag;
54int pflag;
55int rflag;
56int sflag;
57int tflag;
58int xflag;
59id_t id;
60cpulevel_t level;

--- 88 unchanged lines hidden (view full) ---

149 once = 1;
150 } else
151 printf(", %d", cpu);
152 }
153 }
154 printf("\n");
155}
156
156const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq" };
157const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail" };
157const char *levelnames[] = { NULL, " root", " cpuset", "" };
158
159static void
160printaffinity(void)
161{
162 cpuset_t mask;
163
164 if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0)

--- 28 unchanged lines hidden (view full) ---

193 lwpid_t tid;
194 pid_t pid;
195 int ch;
196
197 CPU_ZERO(&mask);
198 level = CPU_LEVEL_WHICH;
199 which = CPU_WHICH_PID;
200 id = pid = tid = setid = -1;
158const char *levelnames[] = { NULL, " root", " cpuset", "" };
159
160static void
161printaffinity(void)
162{
163 cpuset_t mask;
164
165 if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0)

--- 28 unchanged lines hidden (view full) ---

194 lwpid_t tid;
195 pid_t pid;
196 int ch;
197
198 CPU_ZERO(&mask);
199 level = CPU_LEVEL_WHICH;
200 which = CPU_WHICH_PID;
201 id = pid = tid = setid = -1;
201 while ((ch = getopt(argc, argv, "cgil:p:rs:t:x:")) != -1) {
202 while ((ch = getopt(argc, argv, "cgij:l:p:rs:t:x:")) != -1) {
202 switch (ch) {
203 case 'c':
204 if (rflag)
205 usage();
206 cflag = 1;
207 level = CPU_LEVEL_CPUSET;
208 break;
209 case 'g':
210 gflag = 1;
211 break;
212 case 'i':
213 iflag = 1;
214 break;
203 switch (ch) {
204 case 'c':
205 if (rflag)
206 usage();
207 cflag = 1;
208 level = CPU_LEVEL_CPUSET;
209 break;
210 case 'g':
211 gflag = 1;
212 break;
213 case 'i':
214 iflag = 1;
215 break;
216 case 'j':
217 jflag = 1;
218 which = CPU_WHICH_JAIL;
219 id = atoi(optarg);
220 break;
215 case 'l':
216 lflag = 1;
217 parselist(optarg, &mask);
218 break;
219 case 'p':
220 pflag = 1;
221 which = CPU_WHICH_PID;
222 id = pid = atoi(optarg);

--- 24 unchanged lines hidden (view full) ---

247 }
248 }
249 argc -= optind;
250 argv += optind;
251 if (gflag) {
252 if (argc || lflag)
253 usage();
254 /* Only one identity specifier. */
221 case 'l':
222 lflag = 1;
223 parselist(optarg, &mask);
224 break;
225 case 'p':
226 pflag = 1;
227 which = CPU_WHICH_PID;
228 id = pid = atoi(optarg);

--- 24 unchanged lines hidden (view full) ---

253 }
254 }
255 argc -= optind;
256 argv += optind;
257 if (gflag) {
258 if (argc || lflag)
259 usage();
260 /* Only one identity specifier. */
255 if (xflag + sflag + pflag + tflag > 1)
261 if (jflag + xflag + sflag + pflag + tflag > 1)
256 usage();
257 if (iflag)
258 printsetid();
259 else
260 printaffinity();
261 exit(EXIT_SUCCESS);
262 }
263 if (iflag)
264 usage();
265 /*
266 * The user wants to run a command with a set and possibly cpumask.
267 */
268 if (argc) {
262 usage();
263 if (iflag)
264 printsetid();
265 else
266 printaffinity();
267 exit(EXIT_SUCCESS);
268 }
269 if (iflag)
270 usage();
271 /*
272 * The user wants to run a command with a set and possibly cpumask.
273 */
274 if (argc) {
269 if (pflag | rflag | tflag | xflag)
275 if (pflag | rflag | tflag | xflag | jflag)
270 usage();
271 if (sflag) {
272 if (cpuset_setid(CPU_WHICH_PID, -1, setid))
273 err(argc, "setid");
274 } else {
275 if (cpuset(&setid))
276 err(argc, "newid");
277 }

--- 9 unchanged lines hidden (view full) ---

287 /*
288 * We're modifying something that presently exists.
289 */
290 if (!lflag && (cflag || rflag))
291 usage();
292 if (!lflag && !sflag)
293 usage();
294 /* You can only set a mask on a thread. */
276 usage();
277 if (sflag) {
278 if (cpuset_setid(CPU_WHICH_PID, -1, setid))
279 err(argc, "setid");
280 } else {
281 if (cpuset(&setid))
282 err(argc, "newid");
283 }

--- 9 unchanged lines hidden (view full) ---

293 /*
294 * We're modifying something that presently exists.
295 */
296 if (!lflag && (cflag || rflag))
297 usage();
298 if (!lflag && !sflag)
299 usage();
300 /* You can only set a mask on a thread. */
295 if (tflag && (sflag | pflag | xflag))
301 if (tflag && (sflag | pflag | xflag | jflag))
296 usage();
297 /* You can only set a mask on an irq. */
302 usage();
303 /* You can only set a mask on an irq. */
298 if (xflag && (pflag | sflag | tflag))
304 if (xflag && (jflag | pflag | sflag | tflag))
299 usage();
300 if (pflag && sflag) {
301 if (cpuset_setid(CPU_WHICH_PID, pid, setid))
302 err(EXIT_FAILURE, "setid");
303 /*
304 * If the user specifies a set and a list we want the mask
305 * to effect the pid and not the set.
306 */

--- 13 unchanged lines hidden (view full) ---

320usage(void)
321{
322
323 fprintf(stderr,
324 "usage: cpuset [-l cpu-list] [-s setid] cmd ...\n");
325 fprintf(stderr,
326 " cpuset [-l cpu-list] [-s setid] -p pid\n");
327 fprintf(stderr,
305 usage();
306 if (pflag && sflag) {
307 if (cpuset_setid(CPU_WHICH_PID, pid, setid))
308 err(EXIT_FAILURE, "setid");
309 /*
310 * If the user specifies a set and a list we want the mask
311 * to effect the pid and not the set.
312 */

--- 13 unchanged lines hidden (view full) ---

326usage(void)
327{
328
329 fprintf(stderr,
330 "usage: cpuset [-l cpu-list] [-s setid] cmd ...\n");
331 fprintf(stderr,
332 " cpuset [-l cpu-list] [-s setid] -p pid\n");
333 fprintf(stderr,
328 " cpuset [-cr] [-l cpu-list] [-p pid | -t tid | -s setid | -x irq]\n");
334 " cpuset [-cr] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
329 fprintf(stderr,
335 fprintf(stderr,
330 " cpuset [-cgir] [-p pid | -t tid | -s setid | -x irq]\n");
336 " cpuset [-cgir] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
331 exit(1);
332}
337 exit(1);
338}