/* This file contains some utility routines for SCHED. * * The entry points are: * no_sys: called for invalid system call numbers * sched_isokendpt: check the validity of an endpoint * sched_isemtyendpt check for validity and availability of endpoint slot * is_from_pm check whether message is originated from PM * nice_to_priority convert nice level to priority queue */ #include "sched.h" #include #include /* for PRIO_MAX & PRIO_MIN */ #include "kernel/proc.h" /* for queue constants */ #include "schedproc.h" /*===========================================================================* * no_sys * *===========================================================================*/ PUBLIC int no_sys(int who_e, int call_nr) { /* A system call number not implemented by PM has been requested. */ printf("SCHED: in no_sys, call nr %d from %d\n", call_nr, who_e); return(ENOSYS); } /*===========================================================================* * sched_isokendpt * *===========================================================================*/ PUBLIC int sched_isokendpt(int endpoint, int *proc) { *proc = _ENDPOINT_P(endpoint); if (*proc < 0) return (EBADSRCDST); /* Don't schedule tasks */ if(*proc >= NR_PROCS) return (EINVAL); if(endpoint != schedproc[*proc].endpoint) return (EDEADSRCDST); if(!(schedproc[*proc].flags & IN_USE)) return (EDEADSRCDST); return (OK); } /*===========================================================================* * sched_isemtyendpt * *===========================================================================*/ PUBLIC int sched_isemtyendpt(int endpoint, int *proc) { *proc = _ENDPOINT_P(endpoint); if (*proc < 0) return (EBADSRCDST); /* Don't schedule tasks */ if(*proc >= NR_PROCS) return (EINVAL); if(schedproc[*proc].flags & IN_USE) return (EDEADSRCDST); return (OK); } /*===========================================================================* * is_from_pm * *===========================================================================*/ PUBLIC int is_from_pm(message *m_ptr) { if (m_ptr->m_source == PM_PROC_NR) { return 1; } return 0; } /*===========================================================================* * nice_to_priority * *===========================================================================*/ PUBLIC int nice_to_priority(int nice, unsigned* new_q) { if (nice < PRIO_MIN || nice > PRIO_MAX) return(EINVAL); *new_q = MAX_USER_Q + (nice-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) / (PRIO_MAX-PRIO_MIN+1); if (*new_q < MAX_USER_Q) *new_q = MAX_USER_Q; /* shouldn't happen */ if (*new_q > MIN_USER_Q) *new_q = MIN_USER_Q; /* shouldn't happen */ return (OK); }