sched.c revision f841f6ad96ea6675d6c6b35c749eaac601799fdf
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "synonyms.h"
#include "mtlib.h"
#include <sched.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <sys/priocntl.h>
#include <sys/rtpriocntl.h>
#include <sys/tspriocntl.h>
#include <thread.h>
#include <string.h>
#include <stdlib.h>
#include "rtsched.h"
/*
* The following variables are used for caching information
* for priocntl scheduling classes.
*/
typedef struct { /* type definition for generic class-specific parameters */
int pc_clparms[PC_CLINFOSZ];
} pc_clparms_t;
static int map_gp_to_rtpri(pri_t);
/*
* cache priocntl information on scheduling classes by policy
*/
int
get_info_by_policy(int policy)
{
char *pccname;
if (policy < 0) {
return (-1);
}
switch (policy) {
case SCHED_FIFO:
case SCHED_RR:
pccname = "RT";
break;
case SCHED_OTHER:
pccname = "TS";
break;
case SCHED_SYS:
pccname = "sys";
break;
case SCHED_IA:
pccname = "IA";
break;
default:
return (policy);
}
}
/* get class's info */
return (-1);
/* get RT class dispatch table in rt_dptbl */
return (-1);
return (-1);
}
return (-1);
pccp->pcc_primin = 0;
} else if (policy == SCHED_OTHER) {
} else {
/* non-RT scheduling class */
/* need RT class info before we can translate priorities */
if (get_info_by_policy(SCHED_FIFO) < 0)
return (-1);
/*
* get class's global priority's min, max, and
* translate them into RT priority level (index) via rt_dptbl.
*/
return (-1);
}
return (1);
}
/*
* Translate global scheduling priority to RT class's user priority.
* Use the gp values in the rt_dptbl to do a reverse mapping
* of a given gpri value relative to the index range of rt_dptbl.
*/
static int
{
} else {
;
--pri;
}
return (pri);
}
/*
* Translate RT class's user priority to global scheduling priority.
*/
{
(void) get_info_by_policy(SCHED_FIFO);
/* First case is the default case, other two are seldomly taken */
} else {
;
--gpri;
}
return (gpri);
}
static int
{
/* determine if we already know this classid */
return (1);
return (1);
return (1);
return (1);
if (classid == 0) /* no kernel info for sys class */
return (get_info_by_policy(SCHED_SYS));
return (-1);
}
return (get_info_by_policy(SCHED_FIFO));
return (get_info_by_policy(SCHED_OTHER));
return (get_info_by_policy(SCHED_IA));
return (1);
}
int
{
int scale;
if (pid < 0) {
return (-1);
}
if (pid == 0)
/* get process's current scheduling policy */
return (-1);
return (-1);
/* SCHED_FIFO or SCHED_RR policy */
return (-1);
}
/* SCHED_OTHER policy */
} else {
/*
* policy is not defined by POSIX.4.
* just pass parameter data through to priocntl.
* param should contain an image of class-specific parameters
* (after the sched_priority member).
*/
}
}
int
{
int scale;
if (pid < 0) {
return (-1);
}
if (pid == 0)
return (-1);
return (-1);
if (scale == 0)
param->sched_priority = 0;
else
} else {
/*
* policy is not defined by POSIX.4
* just return a copy of pcparams_t image in param.
*/
}
return (0);
}
int
{
int oldpolicy;
int scale;
return (-1);
if (pid == 0)
if (get_info_by_policy(policy) < 0) {
return (-1);
}
switch (policy) {
case SCHED_FIFO:
case SCHED_RR:
return (-1);
}
break;
case SCHED_OTHER:
break;
default:
switch (policy) {
case SCHED_SYS:
break;
case SCHED_IA:
break;
default:
break;
}
/*
* policy is not defined by POSIX.4.
* just pass parameter data through to priocntl.
* param should contain an image of class-specific parameters
* (after the sched_priority member).
*/
}
/* setting scheduling policy & parameters for the process */
return (-1);
return (oldpolicy);
}
int
{
int policy;
if (pid < 0) {
return (-1);
}
if (pid == 0)
/* get scheduling policy & parameters for the process */
return (-1);
return (-1);
else {
/*
* policy is not defined by POSIX.4
* return a unique dot4 policy id.
*/
}
return (policy);
}
int
sched_yield(void)
{
thr_yield();
return (0);
}
int
{
if (get_info_by_policy(policy) < 0)
return (-1);
return (rt_class.pcc_primax);
else if (policy == SCHED_OTHER)
return (ts_class.pcc_primax);
return (sys_class.pcc_primax);
return (ia_class.pcc_primax);
else { /* policy not in POSIX.4 */
}
return (-1);
}
int
{
if (get_info_by_policy(policy) < 0)
return (-1);
return (rt_class.pcc_primin);
else if (policy == SCHED_OTHER)
return (ts_class.pcc_primin);
return (sys_class.pcc_primin);
return (ia_class.pcc_primin);
else { /* policy not in POSIX.4 */
}
return (-1);
}
int
{
if (pid < 0) {
return (-1);
}
if (pid == 0)
if (get_info_by_policy(SCHED_RR) < 0)
return (-1);
return (-1);
/* SCHED_RR */
return (0);
}
return (-1);
}