示例#1
0
/*
 * 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
get_rtdptbl(ulong_t res)
{
	int		i;
	int		rtdpsz;
	pcinfo_t	pcinfo;
	pcadmin_t	pcadmin;
	rtadmin_t	rtadmin;
	rtdpent_t	*rt_dptbl;
	hrtimer_t	hrtime;

	(void) strcpy(pcinfo.pc_clname, "RT");
	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
		fatalerr("%s: Can't get RT class ID, priocntl system call "
		    "failed with errno %d\n", basenm, errno);

	pcadmin.pc_cid = pcinfo.pc_cid;
	pcadmin.pc_cladmin = (char *)&rtadmin;
	rtadmin.rt_cmd = RT_GETDPSIZE;

	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
		fatalerr("%s: Can't get rt_dptbl size, priocntl system call "
		    "failed with errno %d\n", basenm, errno);

	rtdpsz = rtadmin.rt_ndpents * sizeof (rtdpent_t);
	if ((rt_dptbl = (rtdpent_t *)malloc(rtdpsz)) == NULL)
		fatalerr("%s: Can't allocate memory for rt_dptbl\n", basenm);

	rtadmin.rt_dpents = rt_dptbl;

	rtadmin.rt_cmd = RT_GETDPTBL;
	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
		fatalerr("%s: Can't get rt_dptbl, priocntl system call "
		    "failed with errno %d\n", basenm, errno);

	(void) printf("# Real Time Dispatcher Configuration\n");
	(void) printf("RES=%ld\n\n", res);
	(void) printf("# TIME QUANTUM                    PRIORITY\n");
	(void) printf("# (rt_quantum)                      LEVEL\n");

	for (i = 0; i < rtadmin.rt_ndpents; i++) {
		if (res != HZ && rt_dptbl[i].rt_quantum != RT_TQINF) {
			hrtime.hrt_secs = 0;
			hrtime.hrt_rem = rt_dptbl[i].rt_quantum;
			hrtime.hrt_res = HZ;
			if (_hrtnewres(&hrtime, res, HRT_RNDUP) == -1)
				fatalerr("%s: Can't convert to requested "
				    "resolution\n", basenm);
			if ((rt_dptbl[i].rt_quantum =
			    hrtconvert(&hrtime)) == -1)
				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);
	}
}
示例#2
0
/*
 * Execute the command pointed to by cmdargv as a real-time process
 * with real time priority rtpri, quantum tqntm/res and quantum signal rtqsig.
 */
static void
exec_rtcmd(char **cmdargv, uint_t cflags, pri_t rtpri, long tqntm, long res,
	int rtqsig)
{
	pcinfo_t	pcinfo;
	uintptr_t	args[2*RT_KEYCNT+1];
	uintptr_t	*argsp = &args[0];
	pri_t		maxrtpri;
	hrtimer_t	hrtime;

	/*
	 * Get the real time class ID and max configured RT priority.
	 */
	(void) strcpy(pcinfo.pc_clname, "RT");
	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
		fatalerr("%s: Can't get RT class ID, priocntl system call"
		    " failed with errno %d\n", basenm, errno);
	maxrtpri = ((rtinfo_t *)pcinfo.pc_clinfo)->rt_maxpri;

	if ((cflags & RT_DOPRI) != 0) {
		if (rtpri > maxrtpri || rtpri < 0)
			fatalerr("%s: Specified real time priority %d out of"
			    " configured range\n", basenm, rtpri);
		ADDKEYVAL(argsp, RT_KY_PRI, rtpri);
	}

	if ((cflags & RT_DOTQ) != 0) {
		hrtime.hrt_secs = 0;
		hrtime.hrt_rem = tqntm;
		hrtime.hrt_res = res;
		if (_hrtnewres(&hrtime, NANOSEC, HRT_RNDUP) == -1)
			fatalerr("%s: Can't convert resolution.\n", basenm);
		ADDKEYVAL(argsp, RT_KY_TQSECS, hrtime.hrt_secs);
		ADDKEYVAL(argsp, RT_KY_TQNSECS, hrtime.hrt_rem);
	}

	if ((cflags & RT_DOSIG) != 0)
		ADDKEYVAL(argsp, RT_KY_TQSIG, rtqsig);
	*argsp = 0;

	if (rt_priocntl(P_PID, P_MYID, PC_SETXPARMS, "RT", args) == -1)
		fatalerr("%s: Can't reset real time parameters\n"
		    "priocntl system call failed with errno %d\n",
		    basenm, errno);

	(void) execvp(cmdargv[0], cmdargv);
	fatalerr("%s: Can't execute %s, exec failed with errno %d\n",
	    basenm, cmdargv[0], errno);
}
示例#3
0
/*
 * Read the fx_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_fxdptbl(char *infile)
{
	int		i;
	int		nfxdpents;
	char		*tokp;
	pcinfo_t	pcinfo;
	pcadmin_t	pcadmin;
	fxadmin_t	fxadmin;
	fxdpent_t	*fx_dptbl;
	int		linenum;
	ulong_t		res;
	hrtimer_t	hrtime;
	FILE		*fp;
	char		buf[512];
	int		wslength;
	char 		*endp;
	char		name[512], value[512];
	int		len;

	(void) strcpy(pcinfo.pc_clname, "FX");
	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
		fatalerr("%s: Can't get FX class ID, priocntl system call "
		    "failed with errno %d\n", basenm, errno);

	pcadmin.pc_cid = pcinfo.pc_cid;
	pcadmin.pc_cladmin = (char *)&fxadmin;
	fxadmin.fx_cmd = FX_GETDPSIZE;

	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
		fatalerr("%s: Can't get fx_dptbl size, priocntl system call "
		    "failed with errno %d\n", basenm, errno);

	nfxdpents = fxadmin.fx_ndpents;
	if ((fx_dptbl =
	    (fxdpent_t *)malloc(nfxdpents * sizeof (fxdpent_t))) == NULL)
		fatalerr("%s: Can't allocate memory for fx_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);

	/* LINTED - unbounded string specifier */
	if (sscanf(buf, " %[^=]=%s \n%n", name, value, &len) == 2 &&
	    name[0] != '\0' && value[0] != '\0' && len == strlen(buf)) {

		if (strcmp(name, "RES") == 0) {
			errno = 0;
			i = (int)strtol(value, &endp, 10);
			if (errno != 0 || endp == value ||
			    i < 0 || *endp != '\0')
				fatalerr("%s: Bad RES specification, "
				    "line %d of input file\n", basenm, linenum);
			else
				res = i;
		} 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 (fx_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 < fxadmin.fx_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);

		fx_dptbl[i].fx_quantum = atol(tokp);
		if (fx_dptbl[i].fx_quantum <= 0) {
				fatalerr("%s: fx_quantum value out of "
				    "valid range; line %d of input,\n"
				    "table not overwritten\n", basenm, linenum);
		} else if (res != HZ) {
			hrtime.hrt_secs = 0;
			hrtime.hrt_rem = fx_dptbl[i].fx_quantum;
			hrtime.hrt_res = res;
			if (_hrtnewres(&hrtime, HZ, HRT_RNDUP) == -1)
				fatalerr("%s: Can't convert specified "
				    "resolution to ticks\n", basenm);
			if ((fx_dptbl[i].fx_quantum =
			    hrtconvert(&hrtime)) == -1)
				fatalerr("%s: fx_quantum value out of "
				    "valid range; line %d of input,\n"
				    "table 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);
	}

	fxadmin.fx_dpents = fx_dptbl;
	fxadmin.fx_cmd = FX_SETDPTBL;
	if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
		fatalerr("%s: Can't set fx_dptbl, priocntl system call failed "
		    "with errno %d\n", basenm, errno);
}
示例#4
0
/*
 * Set all processes in the set specified by idtype/idargv to real time
 * (if they aren't already real time) and set their real-time priority,
 * real-time quantum and real-time quantum signal to those specified by
 * rtpri, tqntm/res and rtqsig.
 */
static int
set_rtprocs(idtype_t idtype, int idargc, char **idargv, uint_t cflags,
	pri_t rtpri, long tqntm, long res, int rtqsig)
{
	pcinfo_t	pcinfo;
	uintptr_t	args[2*RT_KEYCNT+1];
	uintptr_t	*argsp = &args[0];
	pri_t		maxrtpri;
	hrtimer_t	hrtime;
	char		idtypnm[PC_IDTYPNMSZ];
	int		i;
	id_t		id;
	int		error = 0;


	/*
	 * Get the real time class ID and max configured RT priority.
	 */
	(void) strcpy(pcinfo.pc_clname, "RT");
	if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
		fatalerr("%s: Can't get RT class ID, priocntl system call"
		    " failed with errno %d\n", basenm, errno);
	maxrtpri = ((rtinfo_t *)pcinfo.pc_clinfo)->rt_maxpri;

	/*
	 * Validate the rtpri and res arguments.
	 */
	if ((cflags & RT_DOPRI) != 0) {
		if (rtpri > maxrtpri || rtpri < 0)
			fatalerr("%s: Specified real time priority %d out of"
			    " configured range\n", basenm, rtpri);
		ADDKEYVAL(argsp, RT_KY_PRI, rtpri);
	}

	if ((cflags & RT_DOTQ) != 0) {
		hrtime.hrt_secs = 0;
		hrtime.hrt_rem = tqntm;
		hrtime.hrt_res = res;
		if (_hrtnewres(&hrtime, NANOSEC, HRT_RNDUP) == -1)
			fatalerr("%s: Can't convert resolution.\n", basenm);
		ADDKEYVAL(argsp, RT_KY_TQSECS, hrtime.hrt_secs);
		ADDKEYVAL(argsp, RT_KY_TQNSECS, hrtime.hrt_rem);
	}

	if ((cflags & RT_DOSIG) != 0)
		ADDKEYVAL(argsp, RT_KY_TQSIG, rtqsig);
	*argsp = 0;

	if (idtype == P_ALL) {
		if (rt_priocntl(P_ALL, 0, PC_SETXPARMS, "RT", args) == -1) {
			if (errno == EPERM) {
				(void) fprintf(stderr,
				    "Permissions error encountered"
				    " on one or more processes.\n");
				error = 1;
			} else {
				fatalerr("%s: Can't reset real time parameters"
				    "\npriocntl system call failed with"
				    " errno %d\n", basenm, errno);
			}
		}
	} else if (idargc == 0) {
		if (rt_priocntl(idtype, P_MYID, PC_SETXPARMS, "RT",
		    args) == -1) {
			if (errno == EPERM) {
				(void) idtyp2str(idtype, idtypnm);
				(void) fprintf(stderr, "Permissions error"
				    " encountered on current %s.\n", idtypnm);
				error = 1;
			} else {
				fatalerr("%s: Can't reset real time parameters"
				    "\npriocntl system call failed with"
				    " errno %d\n", basenm, errno);
			}
		}
	} else {
		(void) idtyp2str(idtype, idtypnm);
		for (i = 0; i < idargc; i++) {
			if (idtype == P_CID) {
				(void) strcpy(pcinfo.pc_clname, idargv[i]);
				if (priocntl(0, 0, PC_GETCID,
				    (caddr_t)&pcinfo) == -1)
					fatalerr("%s: Invalid or unconfigured"
					    " class %s, priocntl system call"
					    " failed with errno %d\n",
					    basenm, pcinfo.pc_clname, errno);
				id = pcinfo.pc_cid;
			} else {
				id = (id_t)str2num(idargv[i], INT_MIN, INT_MAX);
				if (errno)
					fatalerr("%s: Invalid id \"%s\"\n",
					    basenm, idargv[i]);
			}

			if (rt_priocntl(idtype, id, PC_SETXPARMS, "RT",
			    args) == -1) {
				if (errno == EPERM) {
					(void) fprintf(stderr,
					    "Permissions error encountered on"
					    " %s %s.\n", idtypnm, idargv[i]);
					error = 1;
				} else {
					fatalerr("%s: Can't reset real time"
					    " parameters\npriocntl system call"
					    " failed with errno %d\n",
					    basenm, errno);
				}
			}
		}
	}

	return (error);
}