/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/priocntl.h>
#include <sys/fsspriocntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <libgen.h>
#include <limits.h>
#include <errno.h>
#include "priocntl.h"
/*
* This file contains the class specific code implementing the fair-share
* scheduler priocntl sub-command.
*/
/*
* Control flags
*/
static void print_fssinfo(void);
static int print_fssprocs(void);
static char usage[] =
"usage: priocntl -l\n"
" priocntl -d [-d idtype] [idlist]\n"
" priocntl -s [-c FSS] [-m fssuprilim] [-p fssupri] [-i idtype] "
"[idlist]\n"
" priocntl -e [-c FSS] [-m fssuprilim] [-p fssupri] command [argument(s)]"
"\n";
int
{
int c;
char *idtypnm;
int idargc;
switch (c) {
case 'l':
lflag++;
break;
case 'd':
dflag++;
break;
case 's':
sflag++;
break;
case 'm':
mflag++;
if (errno)
fatalerr("%s: Specified user priority limit %s "
"out of configured range\n",
break;
case 'p':
pflag++;
if (errno)
fatalerr("%s: Specified user priority %s "
"out of configured range\n",
break;
case 'e':
eflag++;
break;
case 'c':
fatalerr("error: %s executed for %s class, %s "
"is actually sub-command for FSS class\n",
break;
case 'i':
iflag++;
break;
case '?':
default:
break;
}
}
if (lflag) {
} else if (dflag) {
return (print_fssprocs());
} else if (sflag) {
if (iflag) {
idtypnm);
} else {
}
if (mflag)
cflags |= FSS_DOUPRILIM;
else
idargc = 0;
fssuprilim, fssupri));
} else if (eflag) {
if (mflag)
cflags |= FSS_DOUPRILIM;
} else {
}
return (0);
}
/*
* Print our class name and the configured user priority range.
*/
static void
print_fssinfo(void)
{
(void) printf("FSS (Fair Share)\n");
fatalerr("\tCan't get configured FSS user priority range\n");
(void) printf("\tConfigured FSS User Priority Range: -%d through %d\n",
}
/*
* Read a list of pids from stdin and print the user priority and user
* priority limit for each of the corresponding processes.
*/
static int
print_fssprocs(void)
{
int i;
int error = 0;
/*
* Read a list of pids from stdin.
*/
(void) printf("FAIR SHARING PROCESSES:\n"
" PID FSSUPRILIM FSSUPRI\n");
if (numread == 0)
for (i = 0; i < numread; i++) {
(void) printf(" %5d %5d\n",
} else {
error = 1;
/*
* Process from some class other than fair
* sharing. It has probably changed class while
* priocntl command was executing (otherwise
* we wouldn't have been passed its pid).
* Print the little we know about it.
*/
(void) printf("\tChanged to class %s while"
" priocntl command executing\n", clname);
else
(void) printf("\tCan't get FSS user priority"
"\n");
}
}
return (error);
}
/*
* Call priocntl() with command codes PC_SETXPARMS or PC_GETXPARMS. The
* first parameter behind the command code is always the class name.
* Each parameter is headed by a key, which detemines the meanin of the
* following value. There is maximum FSS_KEYCNT == 2 of (key, value) pairs.
*/
static int
{
}
/*
* (if they aren't already fair-sharing) and set their user priority limit
* and user priority to those specified by fssuprilim and fssupri.
*/
static int
short fssuprilim, short fssupri)
{
int i;
int error = 0;
/*
* Get the fair sharing class ID and max configured user priority.
*/
fatalerr("%s: Can't get FSS class ID, priocntl system call "
/*
* Validate the fssuprilim and fssupri arguments.
*/
if ((cflags & FSS_DOUPRILIM) != 0) {
fatalerr("%s: Specified user priority limit %d out of "
}
if ((cflags & FSS_DOUPRI) != 0) {
fatalerr("%s: Specified user priority %d out of "
}
*argsp = 0;
"encountered on one or more processes.\n");
error = 1;
} else {
fatalerr("%s: Can't reset fair sharing "
"parameters\npriocntl system call failed "
}
FSS_DOUPRI) {
}
} else if (idargc == 0) {
args) == -1) {
"encountered on current %s.\n", idtypnm);
error = 1;
} else {
fatalerr("%s: Can't reset fair sharing "
"parameters\npriocntl system call failed "
}
}
} else {
for (i = 0; i < idargc; i++) {
fatalerr("%s: Invalid or unconfigured "
"class %s, priocntl system call "
"failed (%s)\n",
} else {
if (errno)
fatalerr("%s: Invalid id \"%s\"\n",
}
args) == -1) {
"error encountered on %s %s.\n",
error = 1;
} else {
fatalerr("%s: Can't reset fair sharing"
" parameters\npriocntl system call"
" failed (%s)\n",
}
FSS_DOUPRI) {
}
}
}
return (error);
}
/*
* Execute the command pointed to by cmdargv as a fair-sharing process
* with the user priority limit given by fssuprilim and user priority fssupri.
*/
static void
{
/*
* Get the fair sharing class ID and max configured user priority.
*/
fatalerr("%s: Can't get FSS class ID, priocntl system call "
if ((cflags & FSS_DOUPRILIM) != 0) {
fatalerr("%s: Specified user priority limit %d out of "
}
if ((cflags & FSS_DOUPRI) != 0) {
fatalerr("%s: Specified user priority %d out of "
}
*argsp = 0;
fatalerr("%s: Can't reset fair sharing parameters\n"
"priocntl system call failed (%s)\n",
"%s: Specified user priority %d exceeds"
" limit %d; set to %d (pid %d)\n",
}
fatalerr("%s: Can't execute %s, exec failed (%s)\n",
}