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"
32 #include <sys/types.h>
33 #include <sys/param.h>
35 #include <sys/priocntl.h>
36 #include <sys/fsspriocntl.h>
42 #include "dispadmin.h"
45 * This file contains the class specific code implementing the fair-share
46 * scheduler dispadmin sub-command.
51 extern char *basename();
52 static void getadmin(), setadmin();
54 static char usage
[] = "usage: dispadmin -l\n"
55 "dispadmin -c FSS -g [-r res]\n"
56 "dispadmin -c FSS -s infile\n";
58 static char basenm
[BASENMSZ
];
59 static char cmdpath
[256];
62 main(int argc
, char **argv
)
65 int lflag
, gflag
, rflag
, sflag
;
70 (void) strcpy(cmdpath
, argv
[0]);
71 (void) strcpy(basenm
, basename(argv
[0]));
72 lflag
= gflag
= rflag
= sflag
= 0;
73 while ((c
= getopt(argc
, argv
, "lc:gr:s:")) != -1) {
81 if (strcmp(optarg
, "FSS") != 0)
82 fatalerr("error: %s executed for %s class, "
83 "%s is actually sub-command for FSS "
84 "class\n", cmdpath
, optarg
, cmdpath
);
94 res
= strtoul(optarg
, &endp
, 10);
95 if (res
== 0 || errno
!= 0 || *endp
!= '\0')
96 fatalerr("%s: Can't convert to requested "
97 "resolution\n", basenm
);
114 if (gflag
|| rflag
|| sflag
)
117 (void) printf("FSS\t(Fair Share)\n");
131 if (lflag
|| gflag
|| rflag
)
144 * Retrieve the current settings from kernel, convert the time quantum
145 * value to the resolution specified by res and print out the results.
148 getadmin(ulong_t res
)
156 (void) strcpy(pcinfo
.pc_clname
, "FSS");
157 if (priocntl(0, 0, PC_GETCID
, (caddr_t
)&pcinfo
) == -1)
158 fatalerr("%s: Can't get FSS class ID, priocntl system call "
159 "failed (%s)\n", basenm
, strerror(errno
));
161 pcadmin
.pc_cid
= pcinfo
.pc_cid
;
162 pcadmin
.pc_cladmin
= (char *)&fssadmin
;
163 fssadmin
.fss_cmd
= FSS_GETADMIN
;
165 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
166 fatalerr("%s: Can't get scheduler configuration, priocntl "
167 "system call failed (%s)\n", basenm
, strerror(errno
));
170 hrtime
.hrt_rem
= fssadmin
.fss_quantum
;
172 if (_hrtnewres(&hrtime
, res
, HRT_RNDUP
) == -1)
173 fatalerr("%s: Can't convert to requested resolution\n", basenm
);
174 if ((fss_quantum
= hrtconvert(&hrtime
)) == -1)
175 fatalerr("%s: Can't express time quantum in "
176 "requested resolution,\n"
177 "try coarser resolution\n", basenm
);
179 (void) printf("#\n# Fair Share Scheduler Configuration\n#\n");
180 (void) printf("RES=%ld\n", res
);
181 (void) printf("#\n# Time Quantum\n#\n");
182 (void) printf("QUANTUM=%ld\n", fss_quantum
);
186 * Read the scheduler settings from infile, convert the time quantum values
187 * to HZ resolution, do a little sanity checking and overwrite kernel settings
188 * with the values from the file.
191 setadmin(char *infile
)
206 (void) strcpy(pcinfo
.pc_clname
, "FSS");
207 if (priocntl(0, 0, PC_GETCID
, (caddr_t
)&pcinfo
) == -1)
208 fatalerr("%s: Can't get FSS class ID, priocntl system call "
209 "failed (%s)\n", basenm
, strerror(errno
));
211 if ((fp
= fopen(infile
, "r")) == NULL
)
212 fatalerr("%s: Can't open %s for input\n", basenm
, infile
);
214 for (line
= 1; fgets(buf
, sizeof (buf
), fp
) != NULL
; line
++) {
215 char name
[512], value
[512];
218 if (buf
[0] == '#' || buf
[0] == '\n')
221 * Look for "name=value", with optional whitespaces on either
222 * side, terminated by a newline, and consuming the whole line.
224 /* LINTED - unbounded string specifier */
225 if (sscanf(buf
, " %[^=]=%s \n%n", name
, value
, &len
) == 2 &&
226 name
[0] != '\0' && value
[0] != '\0' && len
== strlen(buf
)) {
228 if (strcmp(name
, "RES") == 0) {
230 i
= (int)strtol(value
, &endp
, 10);
231 if (errno
!= 0 || endp
== value
||
232 i
< 0 || *endp
!= '\0')
233 fatalerr("%s, line %d: illegal "
234 "resolution value\n", infile
, line
);
238 } else if (strcmp(name
, "QUANTUM") == 0) {
240 i
= (int)strtol(value
, &endp
, 10);
241 if (errno
!= 0 || endp
== value
||
242 i
< 0 || *endp
!= '\0')
243 fatalerr("%s, line %d: illegal time "
244 "quantum value\n", infile
, line
);
249 fatalerr("%s, line %d: invalid token\n",
253 fatalerr("%s, line %d: syntax error\n", infile
, line
);
256 if (line
== 1 || nparams
< 2)
257 fatalerr("cannot read settings from %s\n", infile
);
260 hrtime
.hrt_rem
= fss_quantum
;
261 hrtime
.hrt_res
= res
;
262 if (_hrtnewres(&hrtime
, HZ
, HRT_RNDUP
) == -1)
263 fatalerr("%s: Can't convert specified "
264 "resolution to ticks\n", basenm
);
265 if ((fssadmin
.fss_quantum
= hrtconvert(&hrtime
)) == -1)
266 fatalerr("%s, line %d: time quantum value out of "
267 "valid range\n", infile
, line
);
269 fssadmin
.fss_quantum
= (short)fss_quantum
;
272 pcadmin
.pc_cid
= pcinfo
.pc_cid
;
273 pcadmin
.pc_cladmin
= (char *)&fssadmin
;
274 fssadmin
.fss_cmd
= FSS_SETADMIN
;
276 if (priocntl(0, 0, PC_ADMIN
, (caddr_t
)&pcadmin
) == -1)
277 fatalerr("%s: Can't set scheduler parameters, priocntl "
278 "system call failed (%s)\n", basenm
, strerror(errno
));