1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
/*
* 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
* or http://www.opensolaris.org/os/licensing.
* 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/types.h>
#include <sys/priocntl.h>
#include <sys/iapriocntl.h>
#include <sys/param.h>
#include <sys/ia.h>
#include "dispadmin.h"
/*
* This file contains the class specific code implementing
* the interactive dispadmin sub-command.
*/
#define BASENMSZ 16
extern char *basename();
static void get_iadptbl(), set_iadptbl();
static char usage[] =
"usage: dispadmin -l\n\
dispadmin -c IA -g [-r res]\n\
dispadmin -c IA -s infile\n";
static char basenm[BASENMSZ];
static char cmdpath[256];
int
main(int argc, char **argv)
{
extern char *optarg;
int c;
int lflag, gflag, rflag, sflag;
ulong_t res;
char *infile;
(void) strcpy(cmdpath, argv[0]);
(void) strcpy(basenm, basename(argv[0]));
lflag = gflag = rflag = sflag = 0;
while ((c = getopt(argc, argv, "lc:gr:s:")) != -1) {
switch (c) {
case 'l':
lflag++;
break;
case 'c':
if (strcmp(optarg, "IA") != 0)
fatalerr("error: %s executed for %s class, "
"%s is actually sub-command for IA class\n",
cmdpath, optarg, cmdpath);
break;
case 'g':
gflag++;
break;
case 'r':
rflag++;
res = strtoul(optarg, (char **)NULL, 10);
break;
case 's':
sflag++;
infile = optarg;
break;
case '?':
fatalerr(usage);
default:
break;
}
}
if (lflag) {
if (gflag || rflag || sflag)
fatalerr(usage);
(void) printf("IA\t(Interactive)\n");
return (0);
} else if (gflag) {
if (lflag || sflag)
fatalerr(usage);
if (rflag == 0)
res = 1000;
get_iadptbl(res);
return (0);
} else if (sflag) {
if (lflag || gflag || rflag)
fatalerr(usage);
set_iadptbl(infile);
return (0);
} else {
fatalerr(usage);
}
return (1);
}
/*
* Retrieve the current ia_dptbl from memory, convert the time quantum
* values to the resolution specified by res and write the table to stdout.
*/
static void
get_iadptbl(ulong_t res)
{
int i;
int iadpsz;
pcinfo_t pcinfo;
pcadmin_t pcadmin;
iaadmin_t iaadmin;
iadpent_t *ia_dptbl;
hrtimer_t hrtime;
(void) strcpy(pcinfo.pc_clname, "IA");
if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
fatalerr("%s: Can't get IA class ID, priocntl system "
"call failed with errno %d\n",
basenm, errno);
pcadmin.pc_cid = pcinfo.pc_cid;
pcadmin.pc_cladmin = (char *)&iaadmin;
iaadmin.ia_cmd = IA_GETDPSIZE;
if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
fatalerr("%s: Can't get ia_dptbl size, priocntl system "
"call failed with errno %d\n",
basenm, errno);
iadpsz = iaadmin.ia_ndpents * sizeof (iadpent_t);
if ((ia_dptbl = (iadpent_t *)malloc(iadpsz)) == NULL)
fatalerr("%s: Can't allocate memory for ia_dptbl\n", basenm);
iaadmin.ia_dpents = ia_dptbl;
iaadmin.ia_cmd = IA_GETDPTBL;
if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
fatalerr("%s: Can't get ia_dptbl, priocntl system call "
"call failed with errno %d\n",
basenm, errno);
(void) printf("# Interactive Dispatcher Configuration\n");
(void) printf("RES=%ld\n\n", res);
(void) printf("# ia_quantum ia_tqexp ia_slpret ia_maxwait ia_lwait \
PRIORITY LEVEL\n");
for (i = 0; i < iaadmin.ia_ndpents; i++) {
if (res != HZ) {
hrtime.hrt_secs = 0;
hrtime.hrt_rem = ia_dptbl[i].ia_quantum;
hrtime.hrt_res = HZ;
if (_hrtnewres(&hrtime, res, HRT_RNDUP) == -1)
fatalerr("%s: Can't convert to requested "
"resolution\n", basenm);
if ((ia_dptbl[i].ia_quantum = hrtconvert(&hrtime))
== -1)
fatalerr("%s: Can't express time quantum in "
"requested resolution,\n"
"try coarser resolution\n",
basenm);
}
(void) printf("%10ld%10d%10d%12d%10d # %3d\n",
ia_dptbl[i].ia_quantum, ia_dptbl[i].ia_tqexp,
ia_dptbl[i].ia_slpret, ia_dptbl[i].ia_maxwait,
ia_dptbl[i].ia_lwait, i);
}
}
/*
* Read the ia_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
set_iadptbl(infile)
char *infile;
{
int i;
int niadpents;
char *tokp;
pcinfo_t pcinfo;
pcadmin_t pcadmin;
iaadmin_t iaadmin;
iadpent_t *ia_dptbl;
int linenum;
ulong_t res;
hrtimer_t hrtime;
FILE *fp;
char buf[512];
int wslength;
(void) strcpy(pcinfo.pc_clname, "IA");
if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
fatalerr("%s: Can't get IA class ID, priocntl system "
"call failed with errno %d\n", basenm, errno);
pcadmin.pc_cid = pcinfo.pc_cid;
pcadmin.pc_cladmin = (char *)&iaadmin;
iaadmin.ia_cmd = IA_GETDPSIZE;
if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
fatalerr("%s: Can't get ia_dptbl size, priocntl system "
"call failed with errno %d\n", basenm, errno);
niadpents = iaadmin.ia_ndpents;
if ((ia_dptbl =
(iadpent_t *)malloc(niadpents * sizeof (iadpent_t))) == NULL)
fatalerr("%s: Can't allocate memory for ia_dptbl\n", basenm);
if ((fp = fopen(infile, "r")) == NULL)
fatalerr("%s: Can't open %s for input\n", basenm, infile);
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 {
if (fgets(buf, sizeof (buf), fp) == NULL)
fatalerr("%s: Too few lines in input table\n", basenm);
linenum++;
} while (buf[0] == '#' || buf[0] == '\0' ||
(wslength = strspn(buf, " \t\n")) == strlen(buf) ||
strchr(buf, '#') == buf + wslength);
if ((tokp = strtok(buf, " \t")) == NULL)
fatalerr("%s: Bad RES specification, line %d of input file\n",
basenm, linenum);
if ((int)strlen(tokp) > 4) {
if (strncmp(tokp, "RES=", 4) != 0)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if (tokp[4] == '-')
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
res = strtoul(&tokp[4], (char **)NULL, 10);
} else if (strlen(tokp) == 4) {
if (strcmp(tokp, "RES=") != 0)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if (tokp[0] == '-')
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
res = strtoul(tokp, (char **)NULL, 10);
} else if (strlen(tokp) == 3) {
if (strcmp(tokp, "RES") != 0)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if ((int)strlen(tokp) > 1) {
if (strncmp(tokp, "=", 1) != 0)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if (tokp[1] == '-')
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
res = strtoul(&tokp[1], (char **)NULL, 10);
} else if (strlen(tokp) == 1) {
if ((tokp = strtok(NULL, " \t")) == NULL)
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
if (tokp[0] == '-')
fatalerr("%s: Bad RES specification, \
line %d of input file\n", basenm, linenum);
res = strtoul(tokp, (char **)NULL, 10);
}
} else {
fatalerr("%s: Bad RES specification, line %d of input file\n",
basenm, linenum);
}
/*
* The remainder of the input file should contain exactly enough
* non-blank, non-comment lines to fill the table (ia_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 < iaadmin.ia_ndpents; i++) {
/*
* Get the next non-blank, non-comment line.
*/
do {
if (fgets(buf, sizeof (buf), fp) == NULL)
fatalerr("%s: Too few lines in input table\n",
basenm);
linenum++;
} while (buf[0] == '#' || buf[0] == '\0' ||
(wslength = strspn(buf, " \t\n")) == strlen(buf) ||
strchr(buf, '#') == buf + wslength);
if ((tokp = strtok(buf, " \t")) == NULL)
fatalerr("%s: Too few values, line %d of input file\n",
basenm, linenum);
if (res != HZ) {
hrtime.hrt_secs = 0;
hrtime.hrt_rem = atol(tokp);
hrtime.hrt_res = res;
if (_hrtnewres(&hrtime, HZ, HRT_RNDUP) == -1)
fatalerr("%s: Can't convert specified \
resolution to ticks\n", basenm);
if ((ia_dptbl[i].ia_quantum = hrtconvert(&hrtime))
== -1)
fatalerr("%s: ia_quantum value out of "
"valid range; line %d of input,\n"
"table not overwritten\n",
basenm, linenum);
} else {
ia_dptbl[i].ia_quantum = atol(tokp);
}
if (ia_dptbl[i].ia_quantum <= 0)
fatalerr("%s: ia_quantum value out of valid range; "
"line %d of input,\ntable not overwritten\n",
basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
fatalerr("%s: Too few values, line %d of input file\n",
basenm, linenum);
ia_dptbl[i].ia_tqexp = (short)atoi(tokp);
if (ia_dptbl[i].ia_tqexp < 0 ||
ia_dptbl[i].ia_tqexp > iaadmin.ia_ndpents)
fatalerr("%s: ia_tqexp value out of valid range; "
"line %d of input,\ntable not overwritten\n",
basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
fatalerr("%s: Too few values, line %d of input file\n",
basenm, linenum);
ia_dptbl[i].ia_slpret = (short)atoi(tokp);
if (ia_dptbl[i].ia_slpret < 0 ||
ia_dptbl[i].ia_slpret > iaadmin.ia_ndpents)
fatalerr("%s: ia_slpret value out of valid range; "
"line %d of input,\ntable not overwritten\n",
basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
fatalerr("%s: Too few values, line %d of input file\n",
basenm, linenum);
ia_dptbl[i].ia_maxwait = (short)atoi(tokp);
if (ia_dptbl[i].ia_maxwait < 0)
fatalerr("%s: ia_maxwait value out of valid range; "
"line %d of input,\ntable not overwritten\n",
basenm, linenum);
if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
fatalerr("%s: Too few values, line %d of input file\n",
basenm, linenum);
ia_dptbl[i].ia_lwait = (short)atoi(tokp);
if (ia_dptbl[i].ia_lwait < 0 ||
ia_dptbl[i].ia_lwait > iaadmin.ia_ndpents)
fatalerr("%s: ia_lwait value out of valid range; "
"line %d of input,\ntable not overwritten\n",
basenm, linenum);
if ((tokp = strtok(NULL, " \t")) != NULL && tokp[0] != '#')
fatalerr("%s: Too many values, line %d of input file\n",
basenm, linenum);
}
/*
* We've read enough lines to fill the table. We fail
* if the input file contains any more.
*/
while (fgets(buf, sizeof (buf), fp) != NULL) {
if (buf[0] != '#' && buf[0] != '\0' &&
(wslength = strspn(buf, " \t\n")) != strlen(buf) &&
strchr(buf, '#') != buf + wslength)
fatalerr("%s: Too many lines in input table\n",
basenm);
}
iaadmin.ia_dpents = ia_dptbl;
iaadmin.ia_cmd = IA_SETDPTBL;
if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
fatalerr("%s: Can't set ia_dptbl, priocntl system call \
failed with errno %d\n", basenm, errno);
}
|