4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/types.h>
37 #include <sys/priocntl.h>
38 #include <sys/fxpriocntl.h>
39 #include <sys/param.h>
43 #include "dispadmin.h"
46 * This file contains the class specific code implementing
47 * the fixed-priority dispadmin sub-command.
52 extern char *basename();
54 static void get_fxdptbl(), set_fxdptbl();
56 static char usage
[] = "usage: dispadmin -l\n"
57 "dispadmin -c FX -g [-r res]\n"
58 "dispadmin -c FX -s infile\n";
60 static char basenm
[BASENMSZ
];
61 static char cmdpath
[256];
65 main(int argc
, char **argv
)
68 int lflag
, gflag
, rflag
, sflag
;
73 (void) strcpy(cmdpath
, argv
[0]);
74 (void) strcpy(basenm
, basename(argv
[0]));
75 lflag
= gflag
= rflag
= sflag
= 0;
76 while ((c
= getopt(argc
, argv
, "lc:gr:s:")) != -1) {
84 if (strcmp(optarg
, "FX") != 0)
85 fatalerr("error: %s executed for %s class, "
86 "%s is actually sub-command for FX class\n",
87 cmdpath
, optarg
, cmdpath
);
97 res
= strtoul(optarg
, &endp
, 10);
98 if (res
== 0 || errno
!= 0 || *endp
!= '\0')
99 fatalerr("%s: Can't convert to requested "
100 "resolution\n", basenm
);
118 if (gflag
|| rflag
|| sflag
)
121 (void) printf("FX\t(Fixed Priority)\n");
149 * Retrieve the current fx_dptbl from memory, convert the time quantum
150 * values to the resolution specified by res and write the table to stdout.
153 get_fxdptbl(ulong_t res
)
163 (void) strcpy(pcinfo
.pc_clname
, "FX");
164 if (priocntl(0, 0, PC_GETCID
, (caddr_t
)&pcinfo
) == -1)
165 fatalerr("%s: Can't get FX class ID, priocntl system call "
166 "failed with errno %d\n", basenm
, errno
);
168 pcadmin
.pc_cid
= pcinfo
.pc_cid
;
169 pcadmin
.pc_cladmin
= (char *)&fxadmin
;
170 fxadmin
.fx_cmd
= FX_GETDPSIZE
;
172 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
173 fatalerr("%s: Can't get fx_dptbl size, priocntl system call "
174 "failed with errno %d\n", basenm
, errno
);
176 fxdpsz
= fxadmin
.fx_ndpents
* sizeof (fxdpent_t
);
177 if ((fx_dptbl
= (fxdpent_t
*)malloc(fxdpsz
)) == NULL
)
178 fatalerr("%s: Can't allocate memory for fx_dptbl\n", basenm
);
180 fxadmin
.fx_dpents
= fx_dptbl
;
182 fxadmin
.fx_cmd
= FX_GETDPTBL
;
183 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
184 fatalerr("%s: Can't get fx_dptbl, priocntl system call "
185 "failed with errno %d\n", basenm
, errno
);
187 (void) printf("# Fixed Priority Dispatcher Configuration\n");
188 (void) printf("RES=%ld\n\n", res
);
189 (void) printf("# TIME QUANTUM PRIORITY\n");
190 (void) printf("# (fx_quantum) LEVEL\n");
192 for (i
= 0; i
< fxadmin
.fx_ndpents
; i
++) {
193 if (res
!= HZ
&& fx_dptbl
[i
].fx_quantum
!= FX_TQINF
) {
195 hrtime
.hrt_rem
= fx_dptbl
[i
].fx_quantum
;
197 if (_hrtnewres(&hrtime
, res
, HRT_RNDUP
) == -1)
198 fatalerr("%s: Can't convert to requested "
199 "resolution\n", basenm
);
200 if ((fx_dptbl
[i
].fx_quantum
= hrtconvert(&hrtime
))
202 fatalerr("%s: Can't express time quantum in "
203 "requested resolution,\n"
204 "try coarser resolution\n", basenm
);
206 (void) printf("%10d # %3d\n",
207 fx_dptbl
[i
].fx_quantum
, i
);
213 * Read the fx_dptbl values from infile, convert the time quantum values
214 * to HZ resolution, do a little sanity checking and overwrite the table
215 * in memory with the values from the file.
218 set_fxdptbl(char *infile
)
234 char name
[512], value
[512];
237 (void) strcpy(pcinfo
.pc_clname
, "FX");
238 if (priocntl(0, 0, PC_GETCID
, (caddr_t
)&pcinfo
) == -1)
239 fatalerr("%s: Can't get FX class ID, priocntl system call "
240 "failed with errno %d\n", basenm
, errno
);
242 pcadmin
.pc_cid
= pcinfo
.pc_cid
;
243 pcadmin
.pc_cladmin
= (char *)&fxadmin
;
244 fxadmin
.fx_cmd
= FX_GETDPSIZE
;
246 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
247 fatalerr("%s: Can't get fx_dptbl size, priocntl system call "
248 "failed with errno %d\n", basenm
, errno
);
250 nfxdpents
= fxadmin
.fx_ndpents
;
252 (fxdpent_t
*)malloc(nfxdpents
* sizeof (fxdpent_t
))) == NULL
)
253 fatalerr("%s: Can't allocate memory for fx_dptbl\n", basenm
);
255 if ((fp
= fopen(infile
, "r")) == NULL
)
256 fatalerr("%s: Can't open %s for input\n", basenm
, infile
);
261 * Find the first non-blank, non-comment line. A comment line
262 * is any line with '#' as the first non-white-space character.
265 if (fgets(buf
, sizeof (buf
), fp
) == NULL
)
266 fatalerr("%s: Too few lines in input table\n", basenm
);
268 } while (buf
[0] == '#' || buf
[0] == '\0' ||
269 (wslength
= strspn(buf
, " \t\n")) == strlen(buf
) ||
270 strchr(buf
, '#') == buf
+ wslength
);
272 /* LINTED - unbounded string specifier */
273 if (sscanf(buf
, " %[^=]=%s \n%n", name
, value
, &len
) == 2 &&
274 name
[0] != '\0' && value
[0] != '\0' && len
== strlen(buf
)) {
276 if (strcmp(name
, "RES") == 0) {
278 i
= (int)strtol(value
, &endp
, 10);
279 if (errno
!= 0 || endp
== value
||
280 i
< 0 || *endp
!= '\0')
281 fatalerr("%s: Bad RES specification, "
282 "line %d of input file\n", basenm
, linenum
);
286 fatalerr("%s: Bad RES specification, "
287 "line %d of input file\n", basenm
, linenum
);
292 * The remainder of the input file should contain exactly enough
293 * non-blank, non-comment lines to fill the table (fx_ndpents lines).
294 * We assume that any non-blank, non-comment line is data for the
295 * table and fail if we find more or less than we need.
297 for (i
= 0; i
< fxadmin
.fx_ndpents
; i
++) {
300 * Get the next non-blank, non-comment line.
303 if (fgets(buf
, sizeof (buf
), fp
) == NULL
)
304 fatalerr("%s: Too few lines in input table\n",
307 } while (buf
[0] == '#' || buf
[0] == '\0' ||
308 (wslength
= strspn(buf
, " \t\n")) == strlen(buf
) ||
309 strchr(buf
, '#') == buf
+ wslength
);
311 if ((tokp
= strtok(buf
, " \t")) == NULL
)
312 fatalerr("%s: Too few values, line %d of input file\n",
315 fx_dptbl
[i
].fx_quantum
= atol(tokp
);
316 if (fx_dptbl
[i
].fx_quantum
<= 0) {
317 fatalerr("%s: fx_quantum value out of "
318 "valid range; line %d of input,\n"
319 "table not overwritten\n", basenm
, linenum
);
320 } else if (res
!= HZ
) {
322 hrtime
.hrt_rem
= fx_dptbl
[i
].fx_quantum
;
323 hrtime
.hrt_res
= res
;
324 if (_hrtnewres(&hrtime
, HZ
, HRT_RNDUP
) == -1)
325 fatalerr("%s: Can't convert specified "
326 "resolution to ticks\n", basenm
);
327 if ((fx_dptbl
[i
].fx_quantum
=
328 hrtconvert(&hrtime
)) == -1)
329 fatalerr("%s: fx_quantum value out of "
330 "valid range; line %d of input,\n"
331 "table not overwritten\n", basenm
, linenum
);
334 if ((tokp
= strtok(NULL
, " \t")) != NULL
&& tokp
[0] != '#')
335 fatalerr("%s: Too many values, line %d of input file\n",
340 * We've read enough lines to fill the table. We fail
341 * if the input file contains any more.
343 while (fgets(buf
, sizeof (buf
), fp
) != NULL
) {
344 if (buf
[0] != '#' && buf
[0] != '\0' &&
345 (wslength
= strspn(buf
, " \t\n")) != strlen(buf
) &&
346 strchr(buf
, '#') != buf
+ wslength
)
347 fatalerr("%s: Too many lines in input table\n",
351 fxadmin
.fx_dpents
= fx_dptbl
;
352 fxadmin
.fx_cmd
= FX_SETDPTBL
;
353 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
354 fatalerr("%s: Can't set fx_dptbl, priocntl system call failed "
355 "with errno %d\n", basenm
, errno
);