/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
*/
/*
* psrset - create and manage processor sets
*/
#include <sys/processor.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <locale.h>
#include <string.h>
#include <limits.h>
#include <procfs.h>
#include <libproc.h>
#include <stdarg.h>
#include <zone.h>
#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
#endif
static char *progname;
static int errors;
static char cflag;
static char dflag;
static char aflag;
static char rflag;
static char iflag;
static char bflag;
static char uflag;
static char Uflag;
static char qflag;
static char Qflag;
static char pflag;
static char nflag;
static char fflag;
static char Fflag;
static char eflag;
static char zflag;
static const char *zname;
/*PRINTFLIKE1*/
static void
{
}
/*PRINTFLIKE1*/
static void
{
}
static struct ps_prochandle *
{
int ret;
return (NULL);
}
return (Pr);
}
static void
{
return;
}
static void
{
char *msg;
switch (pset) {
case PS_NONE:
break;
case PS_QUERY:
break;
default:
break;
}
else if (lwpid == -1)
else
}
/*
* Output for create.
*/
static void
{
}
/*
* Output for assign.
*/
static void
{
" now not assigned\n"), cpu);
else
} else {
else
}
}
/*
* Output for query.
*/
static void
{
char *proclwp;
if (lwpid == -1) {
proclwp = "process";
} else {
proclwp = "lwp";
}
else
}
/*
* Output for info.
*/
static void
{
int i;
else
if (numcpus == 0)
else if (numcpus > 1)
else
for (i = 0; i < numcpus; i++)
(void) printf("\n");
}
/*
* Output for print.
*/
static void
{
else
}
/*
* Output for bind.
*/
static void
{
char *proclwp;
if (lwpid == -1) {
proclwp = "process";
} else {
proclwp = "lwp";
}
else
} else {
else
}
}
static void
{
}
if (qflag)
else
}
}
static int
{
int err;
return (EINVAL);
switch (pset) {
case PS_NONE:
break;
case PS_QUERY:
break;
default:
break;
}
return (err);
}
if (print)
else
return (0);
}
static int
{
int err;
int found_one = 0;
found_one = 1;
}
}
return (error);
}
static int
{
int type;
cpus = (processorid_t *)
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_OK);
}
static int
{
if (pset_destroy(pset) != 0) {
return (ERR_FAIL);
}
return (ERR_OK);
}
static int
{
cpus = (processorid_t *)
return (ERR_FAIL);
}
"cannot set interrupt status for processor set %d"), pset);
return (ERR_FAIL);
}
for (i = 0; i < numcpus; i++) {
}
}
}
return (error);
}
/*
* Query the type and CPUs for all active processor sets in the system.
*/
static int
info_all(void)
{
int i;
return (1);
}
for (;;) {
return (ERR_FAIL);
}
return (ERR_FAIL);
}
break;
}
for (i = 0; i < npsets; i++) {
}
return (errors);
}
/*
* Query the processor set assignments for all CPUs in the system.
*/
static int
print_all(void)
{
}
}
return (errors);
}
/*ARGSUSED*/
static int
{
/*
* Ignore search errors. The process may have exited
* since we read the directory.
*/
return (0);
return (0);
}
return (0);
}
static int
{
return (0);
}
void
{
return;
}
}
int
usage(void)
{
"usage: \n"
"\t%1$s -c [-F] [processor_id ...]\n"
"\t%1$s -d processor_set_id ...\n"
"\t%1$s -n processor_set_id\n"
"\t%1$s -f processor_set_id\n"
"\t%1$s -e processor_set_id command [argument(s)...]\n"
"\t%1$s -a [-F] processor_set_id processor_id ...\n"
"\t%1$s -r [-F] processor_id ...\n"
"\t%1$s -p [processorid ...]\n"
"\t%1$s -b processor_set_id pid[/lwpids] ...\n"
"\t%1$s -b -z zonename processor_set_id\n"
"\t%1$s -u pid[/lwpids] ...\n"
"\t%1$s -q [pid[/lwpids] ...]\n"
"\t%1$s -U [processor_set_id] ...\n"
"\t%1$s -Q [processor_set_id] ...\n"
"\t%1$s [-i] [processor_set_id ...]\n"),
progname);
return (ERR_USAGE);
}
/*
* Query, set, or clear bindings for the range of LWPs in the given process.
*/
static int
{
/*
* Report bindings for LWPs in process 'pid'.
*/
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
found = 0;
/*LINTED ALIGNMENT*/
continue;
found++;
else if (binding != PBIND_NONE)
}
if (found == 0) {
"No matching LWPs found\n"),
return (ERR_FAIL);
}
return (ERR_OK);
}
int
{
extern int optind;
int c;
char *errptr;
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'c':
cflag = 1;
break;
case 'd':
dflag = 1;
break;
case 'e':
eflag = 1;
break;
case 'a':
aflag = 1;
break;
case 'r':
rflag = 1;
break;
case 'p':
pflag = 1;
break;
case 'i':
iflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'u':
uflag = 1;
break;
case 'U':
Uflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'Q':
Qflag = 1;
break;
case 'f':
fflag = 1;
break;
case 'F':
Fflag = 1;
break;
case 'n':
nflag = 1;
break;
case 'z':
if (!bflag) {
return (usage());
}
if (zflag) {
"once\n"));
return (usage());
}
zflag = 1;
break;
default:
return (usage());
}
}
/*
* Make sure that at most one of the options was specified.
*/
if (c < 1) { /* nothing specified */
} else if (c > 1) {
return (usage());
}
return (usage());
errors = 0;
if (argc == 0) {
/*
* Handle single option cases.
*/
if (qflag) {
return (errors);
}
if (Qflag) {
return (errors);
}
if (Uflag) {
}
if (pflag)
return (print_all());
if (iflag)
return (info_all());
}
/*
* Get processor set id.
*/
if (argc < 1) {
/* must specify processor set */
return (usage());
}
return (ERR_FAIL);
}
argv++;
argc--;
}
if (cflag) {
if (pset_create(&pset) != 0) {
return (ERR_FAIL);
} else {
if (argc == 0)
return (ERR_OK);
}
if (argc == 0) {
"processor set\n"));
return (usage());
}
/*
* Go through listed processor sets.
*/
*argv);
continue;
}
if (iflag) {
} else {
}
}
} else if (nflag) {
} else if (fflag) {
} else if (eflag) {
if (argc == 0) {
return (usage());
}
/* if returning, must have had an error */
return (ERR_USAGE);
}
/*
* Perform function for each processor specified.
*/
if (argc == 0) {
return (usage());
}
/*
* Go through listed processors.
*/
/* individual processor id */
"ID %s\n"), *argv);
continue;
}
} else {
/* range of processors */
first = (processorid_t)
if (*errptr++ != '-') {
"invalid processor range %s\n"),
*argv);
continue;
}
last = (processorid_t)
"invalid processor range %s\n"),
*argv);
continue;
}
}
}
/*
*/
return (usage());
return (usage());
}
if (zflag) {
if (zid < 0) {
zname);
&old_pset) < 0) {
} else {
}
}
/*
* Go through listed processes/lwp_ranges.
*/
if (errno != 0 ||
*errptr != '/')) {
*argv);
continue;
}
int ret;
/*
* Handle lwp range case
*/
if (*lwps == '\0' ||
proc_lwp_range_valid(lwps) != 0) {
"for pid %d\n"), (int)pid);
continue;
}
if (!qflag)
(void) proc_initstdio();
if (!qflag)
(void) proc_finistdio();
} else {
/*
* Handle whole process case.
*/
&old_pset) < 0) {
continue;
}
if (qflag)
else
}
}
}
/*
* Go through listed processor set IDs.
*/
errno = 0;
if (errno != 0 ||
continue;
}
if (Qflag) {
(void) proc_walk(query_all_lwp,
&pset, PR_WALK_LWP);
continue;
}
if (Uflag) {
&old_pset) != 0) {
"processor set %d"), (int)pset);
}
continue;
}
}
}
return (errors);
}