rtdispadmin.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/priocntl.h>
#include <sys/rtpriocntl.h>
#include "dispadmin.h"
/*
* This file contains the class specific code implementing
* the real-time dispadmin sub-command.
*/
#define BASENMSZ 16
extern char *basename();
static void get_rtdptbl(), set_rtdptbl();
static char usage[] = "usage: dispadmin -l\n"
"dispadmin -c RT -g [-r res]\n"
"dispadmin -c RT -s infile\n";
static char cmdpath[256];
int
{
extern char *optarg;
int c;
char *infile;
switch (c) {
case 'l':
lflag++;
break;
case 'c':
fatalerr("error: %s executed for %s class, "
"%s is actually sub-command for RT class\n",
break;
case 'g':
gflag++;
break;
case 'r':
rflag++;
break;
case 's':
sflag++;
break;
case '?':
default:
break;
}
}
if (lflag) {
(void) printf("RT\t(Real Time)\n");
return (0);
} else if (gflag) {
if (rflag == 0)
res = 1000;
return (0);
} else if (sflag) {
return (0);
} else {
}
return (1);
}
/*
* Retrieve the current rt_dptbl from memory, convert the time quantum
* values to the resolution specified by res and write the table to stdout.
*/
static void
{
int i;
int rtdpsz;
fatalerr("%s: Can't get RT class ID, priocntl system call "
fatalerr("%s: Can't get rt_dptbl size, priocntl system call "
fatalerr("%s: Can't get rt_dptbl, priocntl system call "
(void) printf("# Real Time Dispatcher Configuration\n");
(void) printf("# TIME QUANTUM PRIORITY\n");
(void) printf("# (rt_quantum) LEVEL\n");
for (i = 0; i < rtadmin.rt_ndpents; i++) {
fatalerr("%s: Can't convert to requested "
"resolution\n", basenm);
if ((rt_dptbl[i].rt_quantum =
fatalerr("%s: Can't express time quantum in "
"requested resolution,\n"
"try coarser resolution\n", basenm);
}
(void) printf("%10d # %3d\n",
rt_dptbl[i].rt_quantum, i);
}
}
/*
* Read the rt_dptbl values from infile, convert the time quantum values
* to HZ resolution, do a little sanity checking and overwrite the table
* in memory with the values from the file.
*/
static void
char *infile;
{
int i;
int nrtdpents;
char *tokp;
int linenum;
char buf[512];
int wslength;
fatalerr("%s: Can't get RT class ID, priocntl system call "
fatalerr("%s: Can't get rt_dptbl size, priocntl system call "
if ((rt_dptbl =
linenum = 0;
/*
* Find the first non-blank, non-comment line. A comment line
* is any line with '#' as the first non-white-space character.
*/
do {
linenum++;
fatalerr("%s: Bad RES specification, line %d of input file\n",
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
if (tokp[0] == '-')
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
fatalerr("%s: Bad RES specification, "
if (tokp[0] == '-')
fatalerr("%s: Bad RES specification, "
}
} else {
fatalerr("%s: Bad RES specification, line %d of input file\n",
}
/*
* The remainder of the input file should contain exactly enough
* non-blank, non-comment lines to fill the table (rt_ndpents lines).
* We assume that any non-blank, non-comment line is data for the
* table and fail if we find more or less than we need.
*/
for (i = 0; i < rtadmin.rt_ndpents; i++) {
/*
* Get the next non-blank, non-comment line.
*/
do {
fatalerr("%s: Too few lines in input table\n",
basenm);
linenum++;
fatalerr("%s: Too few values, line %d of input file\n",
if (rt_dptbl[i].rt_quantum <= 0) {
fatalerr("%s: rt_quantum value out of "
"valid range; line %d of input,\n"
fatalerr("%s: Can't convert specified "
"resolution to ticks\n", basenm);
if ((rt_dptbl[i].rt_quantum =
fatalerr("%s: rt_quantum value out of "
"valid range; line %d of input,\n"
}
fatalerr("%s: Too many values, line %d of input file\n",
}
/*
* We've read enough lines to fill the table. We fail
* if the input file contains any more.
*/
fatalerr("%s: Too many lines in input table\n",
basenm);
}
fatalerr("%s: Can't set rt_dptbl, priocntl system call failed "
}