1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #include	<stdio.h>
31*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
32*7c478bd9Sstevel@tonic-gate #include	<string.h>
33*7c478bd9Sstevel@tonic-gate #include	<unistd.h>
34*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
35*7c478bd9Sstevel@tonic-gate #include	<sys/priocntl.h>
36*7c478bd9Sstevel@tonic-gate #include	<sys/fxpriocntl.h>
37*7c478bd9Sstevel@tonic-gate #include	<sys/param.h>
38*7c478bd9Sstevel@tonic-gate #include	<errno.h>
39*7c478bd9Sstevel@tonic-gate #include	<sys/fx.h>
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include	"dispadmin.h"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * This file contains the class specific code implementing
45*7c478bd9Sstevel@tonic-gate  * the fixed-priority dispadmin sub-command.
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #define	BASENMSZ	16
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate extern char	*basename();
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate static void	get_fxdptbl(), set_fxdptbl();
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate static char usage[] = "usage:	dispadmin -l\n"
55*7c478bd9Sstevel@tonic-gate 			    "dispadmin -c FX -g [-r res]\n"
56*7c478bd9Sstevel@tonic-gate 			    "dispadmin -c FX -s infile\n";
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate static char	basenm[BASENMSZ];
59*7c478bd9Sstevel@tonic-gate static char	cmdpath[256];
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)63*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
64*7c478bd9Sstevel@tonic-gate {
65*7c478bd9Sstevel@tonic-gate 	int		c;
66*7c478bd9Sstevel@tonic-gate 	int		lflag, gflag, rflag, sflag;
67*7c478bd9Sstevel@tonic-gate 	ulong_t		res;
68*7c478bd9Sstevel@tonic-gate 	char		*infile;
69*7c478bd9Sstevel@tonic-gate 	char 		*endp;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	(void) strcpy(cmdpath, argv[0]);
72*7c478bd9Sstevel@tonic-gate 	(void) strcpy(basenm, basename(argv[0]));
73*7c478bd9Sstevel@tonic-gate 	lflag = gflag = rflag = sflag = 0;
74*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "lc:gr:s:")) != -1) {
75*7c478bd9Sstevel@tonic-gate 		switch (c) {
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 		case 'l':
78*7c478bd9Sstevel@tonic-gate 			lflag++;
79*7c478bd9Sstevel@tonic-gate 			break;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 		case 'c':
82*7c478bd9Sstevel@tonic-gate 			if (strcmp(optarg, "FX") != 0)
83*7c478bd9Sstevel@tonic-gate 				fatalerr("error: %s executed for %s class, "
84*7c478bd9Sstevel@tonic-gate 				    "%s is actually sub-command for FX class\n",
85*7c478bd9Sstevel@tonic-gate 				    cmdpath, optarg, cmdpath);
86*7c478bd9Sstevel@tonic-gate 			break;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 		case 'g':
89*7c478bd9Sstevel@tonic-gate 			gflag++;
90*7c478bd9Sstevel@tonic-gate 			break;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 		case 'r':
93*7c478bd9Sstevel@tonic-gate 			rflag++;
94*7c478bd9Sstevel@tonic-gate 			errno = 0;
95*7c478bd9Sstevel@tonic-gate 			res = strtoul(optarg, &endp, 10);
96*7c478bd9Sstevel@tonic-gate 			if (res == 0 || errno != 0 || *endp != '\0')
97*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Can't convert to requested "
98*7c478bd9Sstevel@tonic-gate 				    "resolution\n", basenm);
99*7c478bd9Sstevel@tonic-gate 			break;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 		case 's':
102*7c478bd9Sstevel@tonic-gate 			sflag++;
103*7c478bd9Sstevel@tonic-gate 			infile = optarg;
104*7c478bd9Sstevel@tonic-gate 			break;
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 		case '?':
107*7c478bd9Sstevel@tonic-gate 			fatalerr(usage);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 		default:
110*7c478bd9Sstevel@tonic-gate 			break;
111*7c478bd9Sstevel@tonic-gate 		}
112*7c478bd9Sstevel@tonic-gate 	}
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	if (lflag) {
116*7c478bd9Sstevel@tonic-gate 		if (gflag || rflag || sflag)
117*7c478bd9Sstevel@tonic-gate 			fatalerr(usage);
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 		(void) printf("FX\t(Fixed Priority)\n");
120*7c478bd9Sstevel@tonic-gate 		return (0);
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 	} else if (gflag) {
123*7c478bd9Sstevel@tonic-gate 		if (sflag)
124*7c478bd9Sstevel@tonic-gate 			fatalerr(usage);
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 		if (rflag == 0)
127*7c478bd9Sstevel@tonic-gate 			res = 1000;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 		get_fxdptbl(res);
130*7c478bd9Sstevel@tonic-gate 		return (0);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	} else if (sflag) {
133*7c478bd9Sstevel@tonic-gate 		if (rflag)
134*7c478bd9Sstevel@tonic-gate 			fatalerr(usage);
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 		set_fxdptbl(infile);
137*7c478bd9Sstevel@tonic-gate 		return (0);
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	} else {
140*7c478bd9Sstevel@tonic-gate 		fatalerr(usage);
141*7c478bd9Sstevel@tonic-gate 	}
142*7c478bd9Sstevel@tonic-gate 	return (1);
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate /*
147*7c478bd9Sstevel@tonic-gate  * Retrieve the current fx_dptbl from memory, convert the time quantum
148*7c478bd9Sstevel@tonic-gate  * values to the resolution specified by res and write the table to stdout.
149*7c478bd9Sstevel@tonic-gate  */
150*7c478bd9Sstevel@tonic-gate static void
get_fxdptbl(ulong_t res)151*7c478bd9Sstevel@tonic-gate get_fxdptbl(ulong_t res)
152*7c478bd9Sstevel@tonic-gate {
153*7c478bd9Sstevel@tonic-gate 	int		i;
154*7c478bd9Sstevel@tonic-gate 	int		fxdpsz;
155*7c478bd9Sstevel@tonic-gate 	pcinfo_t	pcinfo;
156*7c478bd9Sstevel@tonic-gate 	pcadmin_t	pcadmin;
157*7c478bd9Sstevel@tonic-gate 	fxadmin_t	fxadmin;
158*7c478bd9Sstevel@tonic-gate 	fxdpent_t	*fx_dptbl;
159*7c478bd9Sstevel@tonic-gate 	hrtimer_t	hrtime;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 	(void) strcpy(pcinfo.pc_clname, "FX");
162*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
163*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't get FX class ID, priocntl system call "
164*7c478bd9Sstevel@tonic-gate 		    "failed with errno %d\n", basenm, errno);
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate 	pcadmin.pc_cid = pcinfo.pc_cid;
167*7c478bd9Sstevel@tonic-gate 	pcadmin.pc_cladmin = (char *)&fxadmin;
168*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_cmd = FX_GETDPSIZE;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
171*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't get fx_dptbl size, priocntl system call "
172*7c478bd9Sstevel@tonic-gate 		    "failed with errno %d\n", basenm, errno);
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	fxdpsz = fxadmin.fx_ndpents * sizeof (fxdpent_t);
175*7c478bd9Sstevel@tonic-gate 	if ((fx_dptbl = (fxdpent_t *)malloc(fxdpsz)) == NULL)
176*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't allocate memory for fx_dptbl\n", basenm);
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_dpents = fx_dptbl;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_cmd = FX_GETDPTBL;
181*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
182*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't get fx_dptbl, priocntl system call "
183*7c478bd9Sstevel@tonic-gate 		    "failed with errno %d\n", basenm, errno);
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate 	(void) printf("# Fixed Priority Dispatcher Configuration\n");
186*7c478bd9Sstevel@tonic-gate 	(void) printf("RES=%ld\n\n", res);
187*7c478bd9Sstevel@tonic-gate 	(void) printf("# TIME QUANTUM                    PRIORITY\n");
188*7c478bd9Sstevel@tonic-gate 	(void) printf("# (fx_quantum)                      LEVEL\n");
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < fxadmin.fx_ndpents; i++) {
191*7c478bd9Sstevel@tonic-gate 		if (res != HZ && fx_dptbl[i].fx_quantum != FX_TQINF) {
192*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_secs = 0;
193*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_rem = fx_dptbl[i].fx_quantum;
194*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_res = HZ;
195*7c478bd9Sstevel@tonic-gate 			if (_hrtnewres(&hrtime, res, HRT_RNDUP) == -1)
196*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Can't convert to requested "
197*7c478bd9Sstevel@tonic-gate 				    "resolution\n", basenm);
198*7c478bd9Sstevel@tonic-gate 			if ((fx_dptbl[i].fx_quantum = hrtconvert(&hrtime))
199*7c478bd9Sstevel@tonic-gate 									== -1)
200*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Can't express time quantum in "
201*7c478bd9Sstevel@tonic-gate 				    "requested resolution,\n"
202*7c478bd9Sstevel@tonic-gate 				    "try coarser resolution\n", basenm);
203*7c478bd9Sstevel@tonic-gate 		}
204*7c478bd9Sstevel@tonic-gate 		(void) printf("%10d                    #      %3d\n",
205*7c478bd9Sstevel@tonic-gate 		    fx_dptbl[i].fx_quantum, i);
206*7c478bd9Sstevel@tonic-gate 	}
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate /*
211*7c478bd9Sstevel@tonic-gate  * Read the fx_dptbl values from infile, convert the time quantum values
212*7c478bd9Sstevel@tonic-gate  * to HZ resolution, do a little sanity checking and overwrite the table
213*7c478bd9Sstevel@tonic-gate  * in memory with the values from the file.
214*7c478bd9Sstevel@tonic-gate  */
215*7c478bd9Sstevel@tonic-gate static void
set_fxdptbl(char * infile)216*7c478bd9Sstevel@tonic-gate set_fxdptbl(char *infile)
217*7c478bd9Sstevel@tonic-gate {
218*7c478bd9Sstevel@tonic-gate 	int		i;
219*7c478bd9Sstevel@tonic-gate 	int		nfxdpents;
220*7c478bd9Sstevel@tonic-gate 	char		*tokp;
221*7c478bd9Sstevel@tonic-gate 	pcinfo_t	pcinfo;
222*7c478bd9Sstevel@tonic-gate 	pcadmin_t	pcadmin;
223*7c478bd9Sstevel@tonic-gate 	fxadmin_t	fxadmin;
224*7c478bd9Sstevel@tonic-gate 	fxdpent_t	*fx_dptbl;
225*7c478bd9Sstevel@tonic-gate 	int		linenum;
226*7c478bd9Sstevel@tonic-gate 	ulong_t		res;
227*7c478bd9Sstevel@tonic-gate 	hrtimer_t	hrtime;
228*7c478bd9Sstevel@tonic-gate 	FILE		*fp;
229*7c478bd9Sstevel@tonic-gate 	char		buf[512];
230*7c478bd9Sstevel@tonic-gate 	int		wslength;
231*7c478bd9Sstevel@tonic-gate 	char 		*endp;
232*7c478bd9Sstevel@tonic-gate 	char		name[512], value[512];
233*7c478bd9Sstevel@tonic-gate 	int		len;
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate 	(void) strcpy(pcinfo.pc_clname, "FX");
236*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
237*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't get FX class ID, priocntl system call "
238*7c478bd9Sstevel@tonic-gate 		    "failed with errno %d\n", basenm, errno);
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	pcadmin.pc_cid = pcinfo.pc_cid;
241*7c478bd9Sstevel@tonic-gate 	pcadmin.pc_cladmin = (char *)&fxadmin;
242*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_cmd = FX_GETDPSIZE;
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
245*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't get fx_dptbl size, priocntl system call "
246*7c478bd9Sstevel@tonic-gate 		    "failed with errno %d\n", basenm, errno);
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	nfxdpents = fxadmin.fx_ndpents;
249*7c478bd9Sstevel@tonic-gate 	if ((fx_dptbl =
250*7c478bd9Sstevel@tonic-gate 	    (fxdpent_t *)malloc(nfxdpents * sizeof (fxdpent_t))) == NULL)
251*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't allocate memory for fx_dptbl\n", basenm);
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	if ((fp = fopen(infile, "r")) == NULL)
254*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't open %s for input\n", basenm, infile);
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	linenum = 0;
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	/*
259*7c478bd9Sstevel@tonic-gate 	 * Find the first non-blank, non-comment line.  A comment line
260*7c478bd9Sstevel@tonic-gate 	 * is any line with '#' as the first non-white-space character.
261*7c478bd9Sstevel@tonic-gate 	 */
262*7c478bd9Sstevel@tonic-gate 	do {
263*7c478bd9Sstevel@tonic-gate 		if (fgets(buf, sizeof (buf), fp) == NULL)
264*7c478bd9Sstevel@tonic-gate 			fatalerr("%s: Too few lines in input table\n", basenm);
265*7c478bd9Sstevel@tonic-gate 		linenum++;
266*7c478bd9Sstevel@tonic-gate 	} while (buf[0] == '#' || buf[0] == '\0' ||
267*7c478bd9Sstevel@tonic-gate 	    (wslength = strspn(buf, " \t\n")) == strlen(buf) ||
268*7c478bd9Sstevel@tonic-gate 	    strchr(buf, '#') == buf + wslength);
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate 	/* LINTED - unbounded string specifier */
271*7c478bd9Sstevel@tonic-gate 	if (sscanf(buf, " %[^=]=%s \n%n", name, value, &len) == 2 &&
272*7c478bd9Sstevel@tonic-gate 	    name[0] != '\0' && value[0] != '\0' && len == strlen(buf)) {
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 		if (strcmp(name, "RES") == 0) {
275*7c478bd9Sstevel@tonic-gate 			errno = 0;
276*7c478bd9Sstevel@tonic-gate 			i = (int)strtol(value, &endp, 10);
277*7c478bd9Sstevel@tonic-gate 			if (errno != 0 || endp == value ||
278*7c478bd9Sstevel@tonic-gate 			    i < 0 || *endp != '\0')
279*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Bad RES specification, "
280*7c478bd9Sstevel@tonic-gate 				    "line %d of input file\n", basenm, linenum);
281*7c478bd9Sstevel@tonic-gate 			else
282*7c478bd9Sstevel@tonic-gate 				res = i;
283*7c478bd9Sstevel@tonic-gate 		} else {
284*7c478bd9Sstevel@tonic-gate 			fatalerr("%s: Bad RES specification, "
285*7c478bd9Sstevel@tonic-gate 			    "line %d of input file\n", basenm, linenum);
286*7c478bd9Sstevel@tonic-gate 		}
287*7c478bd9Sstevel@tonic-gate 	}
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	/*
290*7c478bd9Sstevel@tonic-gate 	 * The remainder of the input file should contain exactly enough
291*7c478bd9Sstevel@tonic-gate 	 * non-blank, non-comment lines to fill the table (fx_ndpents lines).
292*7c478bd9Sstevel@tonic-gate 	 * We assume that any non-blank, non-comment line is data for the
293*7c478bd9Sstevel@tonic-gate 	 * table and fail if we find more or less than we need.
294*7c478bd9Sstevel@tonic-gate 	 */
295*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < fxadmin.fx_ndpents; i++) {
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 		/*
298*7c478bd9Sstevel@tonic-gate 		 * Get the next non-blank, non-comment line.
299*7c478bd9Sstevel@tonic-gate 		 */
300*7c478bd9Sstevel@tonic-gate 		do {
301*7c478bd9Sstevel@tonic-gate 			if (fgets(buf, sizeof (buf), fp) == NULL)
302*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Too few lines in input table\n",
303*7c478bd9Sstevel@tonic-gate 				    basenm);
304*7c478bd9Sstevel@tonic-gate 			linenum++;
305*7c478bd9Sstevel@tonic-gate 		} while (buf[0] == '#' || buf[0] == '\0' ||
306*7c478bd9Sstevel@tonic-gate 		    (wslength = strspn(buf, " \t\n")) == strlen(buf) ||
307*7c478bd9Sstevel@tonic-gate 		    strchr(buf, '#') == buf + wslength);
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 		if ((tokp = strtok(buf, " \t")) == NULL)
310*7c478bd9Sstevel@tonic-gate 			fatalerr("%s: Too few values, line %d of input file\n",
311*7c478bd9Sstevel@tonic-gate 			    basenm, linenum);
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 		fx_dptbl[i].fx_quantum = atol(tokp);
314*7c478bd9Sstevel@tonic-gate 		if (fx_dptbl[i].fx_quantum <= 0) {
315*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: fx_quantum value out of "
316*7c478bd9Sstevel@tonic-gate 				    "valid range; line %d of input,\n"
317*7c478bd9Sstevel@tonic-gate 				    "table not overwritten\n", basenm, linenum);
318*7c478bd9Sstevel@tonic-gate 		} else if (res != HZ) {
319*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_secs = 0;
320*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_rem = fx_dptbl[i].fx_quantum;
321*7c478bd9Sstevel@tonic-gate 			hrtime.hrt_res = res;
322*7c478bd9Sstevel@tonic-gate 			if (_hrtnewres(&hrtime, HZ, HRT_RNDUP) == -1)
323*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: Can't convert specified "
324*7c478bd9Sstevel@tonic-gate 				    "resolution to ticks\n", basenm);
325*7c478bd9Sstevel@tonic-gate 			if ((fx_dptbl[i].fx_quantum =
326*7c478bd9Sstevel@tonic-gate 			    hrtconvert(&hrtime)) == -1)
327*7c478bd9Sstevel@tonic-gate 				fatalerr("%s: fx_quantum value out of "
328*7c478bd9Sstevel@tonic-gate 				    "valid range; line %d of input,\n"
329*7c478bd9Sstevel@tonic-gate 				    "table not overwritten\n", basenm, linenum);
330*7c478bd9Sstevel@tonic-gate 		}
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 		if ((tokp = strtok(NULL, " \t")) != NULL && tokp[0] != '#')
333*7c478bd9Sstevel@tonic-gate 			fatalerr("%s: Too many values, line %d of input file\n",
334*7c478bd9Sstevel@tonic-gate 			    basenm, linenum);
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	/*
338*7c478bd9Sstevel@tonic-gate 	 * We've read enough lines to fill the table.  We fail
339*7c478bd9Sstevel@tonic-gate 	 * if the input file contains any more.
340*7c478bd9Sstevel@tonic-gate 	 */
341*7c478bd9Sstevel@tonic-gate 	while (fgets(buf, sizeof (buf), fp) != NULL) {
342*7c478bd9Sstevel@tonic-gate 		if (buf[0] != '#' && buf[0] != '\0' &&
343*7c478bd9Sstevel@tonic-gate 		    (wslength = strspn(buf, " \t\n")) != strlen(buf) &&
344*7c478bd9Sstevel@tonic-gate 		    strchr(buf, '#') != buf + wslength)
345*7c478bd9Sstevel@tonic-gate 			fatalerr("%s: Too many lines in input table\n",
346*7c478bd9Sstevel@tonic-gate 				basenm);
347*7c478bd9Sstevel@tonic-gate 	}
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_dpents = fx_dptbl;
350*7c478bd9Sstevel@tonic-gate 	fxadmin.fx_cmd = FX_SETDPTBL;
351*7c478bd9Sstevel@tonic-gate 	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
352*7c478bd9Sstevel@tonic-gate 		fatalerr("%s: Can't set fx_dptbl, priocntl system call failed "
353*7c478bd9Sstevel@tonic-gate 		    "with errno %d\n", basenm, errno);
354*7c478bd9Sstevel@tonic-gate }
355