From: Cristiano Giuffrida Date: Tue, 13 Jul 2010 15:30:17 +0000 (+0000) Subject: Scheduling parameters out of the kernel. X-Git-Tag: v3.1.8~248 X-Git-Url: http://zhaoyanbai.com/repos/%22../static/icons/man.3.ps?a=commitdiff_plain;h=8cedace2f578d4ed546224d6c7282f7a0cd3c2c1;p=minix.git Scheduling parameters out of the kernel. --- diff --git a/include/Makefile b/include/Makefile index f17616515..b6958d67e 100644 --- a/include/Makefile +++ b/include/Makefile @@ -20,7 +20,7 @@ INCS+= minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \ minix/fslib.h minix/ioctl.h minix/ipc.h minix/ipcconst.h \ minix/keymap.h minix/minlib.h minix/mq.h \ minix/netdriver.h minix/partition.h minix/paths.h \ - minix/portio.h minix/profile.h minix/queryparam.h \ + minix/portio.h minix/priv.h minix/profile.h minix/queryparam.h \ minix/rs.h minix/safecopies.h minix/sched.h minix/sef.h minix/sound.h \ minix/spin.h minix/sys_config.h minix/sysinfo.h minix/syslib.h \ minix/sysutil.h minix/timers.h minix/tty.h minix/type.h minix/types.h \ diff --git a/include/minix/com.h b/include/minix/com.h index 8f7b95934..8596ba853 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -668,12 +668,14 @@ #define SYS_STATE_CLEAR_IPC_REFS 1 /* clear IPC references */ /* Subfunctions for SYS_SCHEDCTL */ -#define SCHEDCTL_FLAGS m1_i1 /* flags for setting the scheduler */ +#define SCHEDCTL_FLAGS m9_l1 /* flags for setting the scheduler */ # define SCHEDCTL_FLAG_KERNEL 1 /* mark kernel scheduler and remove * RTS_NO_QUANTUM; otherwise caller is * marked scheduler */ -#define SCHEDCTL_ENDPOINT m1_i2 /* endpt of process to be scheduled */ +#define SCHEDCTL_ENDPOINT m9_l2 /* endpt of process to be scheduled */ +#define SCHEDCTL_QUANTUM m9_l3 /* current scheduling quantum */ +#define SCHEDCTL_PRIORITY m9_s4 /* current scheduling priority */ /*===========================================================================* * Messages for the Reincarnation Server * diff --git a/include/minix/config.h b/include/minix/config.h index 923316596..1e78739e5 100644 --- a/include/minix/config.h +++ b/include/minix/config.h @@ -63,6 +63,28 @@ /* This feature enable the counting of system calls in PM and FS */ #define ENABLE_SYSCALL_STATS 0 +/* Max. number of I/O ranges that can be assigned to a process */ +#define NR_IO_RANGE 64 + +/* Max. number of device memory ranges that can be assigned to a process */ +#define NR_MEM_RANGE 20 + +/* Max. number of IRQs that can be assigned to a process */ +#define NR_IRQ 8 + +/* Scheduling priorities. Values must start at zero (highest + * priority) and increment. + */ +#define NR_SCHED_QUEUES 16 /* MUST equal minimum priority + 1 */ +#define TASK_Q 0 /* highest, used for kernel tasks */ +#define MAX_USER_Q 0 /* highest priority for user processes */ +#define USER_Q ((MIN_USER_Q - MAX_USER_Q) / 2 + MAX_USER_Q) /* default + (should correspond to nice 0) */ +#define MIN_USER_Q (NR_SCHED_QUEUES - 1) /* minimum priority for user + processes */ +/* default scheduling quanta */ +#define USER_QUANTUM 200 + /*===========================================================================* * There are no user-settable parameters after this line * *===========================================================================*/ diff --git a/include/minix/priv.h b/include/minix/priv.h new file mode 100644 index 000000000..e58589eb9 --- /dev/null +++ b/include/minix/priv.h @@ -0,0 +1,24 @@ +/* Privilege-related definitions. */ + +#ifndef _MINIX_PRIV_H +#define _MINIX_PRIV_H + +#include +#include + +/* scheduler */ +#define SRV_SCH KERNEL /* system services */ +#define DSRV_SCH SCHED_PROC_NR /* dynamic system services */ +#define USR_SCH NONE /* user processes */ + +/* scheduling priority queue. */ +#define SRV_Q USER_Q /* system services */ +#define DSRV_Q USER_Q /* dynamic system services */ +#define USR_Q USER_Q /* user processes */ + +/* scheduling quantum. */ +#define SRV_QT USER_QUANTUM /* system services */ +#define DSRV_QT USER_QUANTUM /* dynamic system services */ +#define USR_QT USER_QUANTUM /* user processes */ + +#endif /* _MINIX_PRIV_H */ diff --git a/include/minix/syslib.h b/include/minix/syslib.h index 5cc9670cd..36f4a33df 100644 --- a/include/minix/syslib.h +++ b/include/minix/syslib.h @@ -45,7 +45,8 @@ _PROTOTYPE( int sys_exit, (void)); _PROTOTYPE( int sys_trace, (int req, endpoint_t proc_ep, long addr, long *data_p)); _PROTOTYPE( int sys_schedule, (endpoint_t proc_ep, unsigned priority, unsigned quantum)); -_PROTOTYPE( int sys_schedctl, (unsigned flags, endpoint_t proc_ep)); +_PROTOTYPE( int sys_schedctl, (unsigned flags, endpoint_t proc_ep, + unsigned priority, unsigned quantum)); /* Shorthands for sys_runctl() system call. */ #define sys_stop(proc_ep) sys_runctl(proc_ep, RC_STOP, 0) diff --git a/kernel/main.c b/kernel/main.c index b08a52b03..3fc62c582 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -53,6 +53,9 @@ PUBLIC int main(void) rp->p_magic = PMAGIC; rp->p_nr = i; /* proc number from ptr */ rp->p_endpoint = _ENDPOINT(0, rp->p_nr); /* generation no. 0 */ + rp->p_scheduler = NULL; /* no user space scheduler */ + rp->p_priority = 0; /* no priority */ + rp->p_quantum_size_ms = 0; /* no quantum size */ } for (sp = BEG_PRIV_ADDR, i = 0; sp < END_PRIV_ADDR; ++sp, ++i) { sp->s_proc_nr = NONE; /* initialize as free */ @@ -82,9 +85,6 @@ PUBLIC int main(void) DEBUGEXTRA(("initializing %s... ", ip->proc_name)); rp = proc_addr(ip->proc_nr); /* get process pointer */ ip->endpoint = rp->p_endpoint; /* ipc endpoint */ - rp->p_scheduler = NULL; /* no user space scheduler */ - rp->p_priority = ip->priority; /* current priority */ - rp->p_quantum_size_ms = ip->quantum; /* quantum size */ make_zero64(rp->p_cpu_time_left); strncpy(rp->p_name, ip->proc_name, P_NAME_LEN); /* set process name */ @@ -119,6 +119,8 @@ PUBLIC int main(void) kcalls = RSYS_KC; /* allowed kernel calls */ priv(rp)->s_sig_mgr = RSYS_SM; /* signal manager */ priv(rp)->s_bak_sig_mgr = NONE; /* backup signal manager */ + rp->p_priority = SRV_Q; /* priority queue */ + rp->p_quantum_size_ms = SRV_QT; /* quantum size */ } /* Priviliges for ordinary process. */ else { diff --git a/kernel/priv.h b/kernel/priv.h index 297cc5141..66e5531eb 100644 --- a/kernel/priv.h +++ b/kernel/priv.h @@ -14,18 +14,10 @@ */ #include #include +#include #include "const.h" #include "type.h" -/* Max. number of I/O ranges that can be assigned to a process */ -#define NR_IO_RANGE 64 - -/* Max. number of device memory ranges that can be assigned to a process */ -#define NR_MEM_RANGE 20 - -/* Max. number of IRQs that can be assigned to a process */ -#define NR_IRQ 8 - struct priv { proc_nr_t s_proc_nr; /* number of associated process */ sys_id_t s_id; /* index of this system structure */ @@ -156,8 +148,4 @@ EXTERN struct priv *ppriv_addr[NR_SYS_PROCS]; /* direct slot pointers */ #define RSYS_SM SELF /* root system proc */ #define DEF_SYS_SM ROOT_SYS_PROC_NR /* default sys proc */ -/* scheduler */ -#define KERN_SCH KERNEL /* scheduled by kernel */ -#define USER_SCH SCHED_PROC_NR /* scheduled in userland */ - #endif /* PRIV_H */ diff --git a/kernel/proc.h b/kernel/proc.h index 45da12c9e..5ce97d379 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -225,22 +225,6 @@ struct proc { * regs are significant (initialized)*/ #define MF_SENDING_FROM_KERNEL 0x2000 /* message of this process is from kernel */ -/* Scheduling priorities for p_priority. Values must start at zero (highest - * priority) and increment. Priorities of the processes in the boot image - * can be set in table.c. - */ -#define NR_SCHED_QUEUES 16 /* MUST equal minimum priority + 1 */ -#define TASK_Q 0 /* highest, used for kernel tasks */ -#define MAX_USER_Q 0 /* highest priority for user processes */ -#define USER_Q ((MIN_USER_Q - MAX_USER_Q) / 2 + MAX_USER_Q) /* default - (should correspond to nice 0) */ -#define MIN_USER_Q (NR_SCHED_QUEUES - 1) /* minimum priority for user - processes */ -/* default scheduling quanta */ -#define USER_QUANTUM 200 -#define DRIV_QUANTUM 50 -#define SERV_QUANTUM 500 - /* Magic process table addresses. */ #define BEG_PROC_ADDR (&proc[0]) #define BEG_USER_ADDR (&proc[NR_TASKS]) diff --git a/kernel/proto.h b/kernel/proto.h index f54f33809..4f71d7c94 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -78,6 +78,8 @@ _PROTOTYPE( void clear_endpoint, (struct proc *rc) ); _PROTOTYPE( void clear_ipc_refs, (struct proc *rc, int caller_ret) ); _PROTOTYPE( phys_bytes umap_bios, (vir_bytes vir_addr, vir_bytes bytes)); _PROTOTYPE( void kernel_call_resume, (struct proc *p)); +_PROTOTYPE( int sched_proc, (struct proc *rp, + unsigned priority, unsigned quantum)); /* system/do_newmap.c */ _PROTOTYPE( int newmap, (struct proc * caller, struct proc *rp, diff --git a/kernel/system.c b/kernel/system.c index fe45bcbfe..3f18a3187 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -21,6 +21,7 @@ * umap_bios: map virtual address in BIOS_SEG to physical * get_randomness: accumulate randomness in a buffer * clear_endpoint: remove a process' ability to send and receive messages + * sched_proc: schedule a process * * Changes: * Nov 22, 2009 get_priv supports static priv ids (Cristiano Giuffrida) @@ -36,6 +37,7 @@ #include "system.h" #include "proc.h" #include "vm.h" +#include "kernel/clock.h" #include #include #include @@ -632,3 +634,34 @@ PUBLIC void kernel_call_resume(struct proc *caller) caller->p_misc_flags &= ~MF_KCALL_RESUME; kernel_call_finish(caller, &caller->p_vmrequest.saved.reqmsg, result); } + +/*===========================================================================* + * sched_proc * + *===========================================================================*/ +PUBLIC int sched_proc(struct proc *rp, unsigned priority, unsigned quantum) +{ + /* Make sure the priority number given is within the allowed range.*/ + if (priority < TASK_Q || priority > NR_SCHED_QUEUES) + return EINVAL; + + /* Make sure the quantum given is within the allowed range.*/ + if(quantum <= 0) + return EINVAL; + + /* In some cases, we might be rescheduling a runnable process. In such + * a case (i.e. if we are updating the priority) we set the NO_QUANTUM + * flag before the generic unset to dequeue/enqueue the process + */ + if (proc_is_runnable(rp)) + RTS_SET(rp, RTS_NO_QUANTUM); + + /* Clear the scheduling bit and enqueue the process */ + rp->p_priority = priority; + rp->p_quantum_size_ms = quantum; + rp->p_cpu_time_left = ms_2_cpu_time(quantum); + + RTS_UNSET(rp, RTS_NO_QUANTUM); + + return OK; +} + diff --git a/kernel/system/do_schedctl.c b/kernel/system/do_schedctl.c index 5dfe9c25a..8a40e1e09 100644 --- a/kernel/system/do_schedctl.c +++ b/kernel/system/do_schedctl.c @@ -8,11 +8,9 @@ PUBLIC int do_schedctl(struct proc * caller, message * m_ptr) { struct proc *p; unsigned flags; + unsigned priority, quantum; int proc_nr; - - /* Only system processes can change process schedulers */ - if (! (priv(caller)->s_flags & SYS_PROC)) - return(EPERM); + int r; /* check parameter validity */ flags = (unsigned) m_ptr->SCHEDCTL_FLAGS; @@ -29,11 +27,15 @@ PUBLIC int do_schedctl(struct proc * caller, message * m_ptr) if ((flags & SCHEDCTL_FLAG_KERNEL) == SCHEDCTL_FLAG_KERNEL) { /* the kernel becomes the scheduler and starts - * scheduling the process; RTS_NO_QUANTUM which was - * previously set by sys_fork is removed + * scheduling the process. */ + priority = (unsigned) m_ptr->SCHEDCTL_PRIORITY; + quantum = (unsigned) m_ptr->SCHEDCTL_QUANTUM; + + /* Try to schedule the process. */ + if((r = sched_proc(p, priority, quantum) != OK)) + return r; p->p_scheduler = NULL; - RTS_UNSET(p, RTS_NO_QUANTUM); } else { /* the caller becomes the scheduler */ p->p_scheduler = caller; diff --git a/kernel/system/do_schedule.c b/kernel/system/do_schedule.c index 40d50c7c1..d4935c755 100644 --- a/kernel/system/do_schedule.c +++ b/kernel/system/do_schedule.c @@ -9,6 +9,7 @@ PUBLIC int do_schedule(struct proc * caller, message * m_ptr) { struct proc *p; int proc_nr; + unsigned priority, quantum; if (!isokendpt(m_ptr->SCHEDULING_ENDPOINT, &proc_nr)) return EINVAL; @@ -19,24 +20,8 @@ PUBLIC int do_schedule(struct proc * caller, message * m_ptr) if (caller != p->p_scheduler) return(EPERM); - /* Make sure the priority number given is within the allowed range.*/ - if (m_ptr->SCHEDULING_PRIORITY < TASK_Q || - m_ptr->SCHEDULING_PRIORITY > NR_SCHED_QUEUES) - return(EINVAL); - - /* In some cases, we might be rescheduling a runnable process. In such - * a case (i.e. if we are updating the priority) we set the NO_QUANTUM - * flag before the generic unset to dequeue/enqueue the process - */ - if (proc_is_runnable(p)) - RTS_SET(p, RTS_NO_QUANTUM); - - /* Clear the scheduling bit and enqueue the process */ - p->p_priority = m_ptr->SCHEDULING_PRIORITY; - p->p_quantum_size_ms = m_ptr->SCHEDULING_QUANTUM; - p->p_cpu_time_left = ms_2_cpu_time(m_ptr->SCHEDULING_QUANTUM); - - RTS_UNSET(p, RTS_NO_QUANTUM); - - return(OK); + /* Try to schedule the process. */ + priority = (unsigned) m_ptr->SCHEDULING_PRIORITY; + quantum = (unsigned) m_ptr->SCHEDULING_QUANTUM; + return sched_proc(p, priority, quantum); } diff --git a/kernel/table.c b/kernel/table.c index 86b297368..98f955111 100644 --- a/kernel/table.c +++ b/kernel/table.c @@ -69,25 +69,25 @@ PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)]; */ PUBLIC struct boot_image image[] = { -/* process nr, flags, ms, queue, stack, name */ -{IDLE, 0, 0, 0, IDL_S, "idle" }, -{CLOCK, 0, 0, 0, IDL_S, "clock" }, -{SYSTEM, 0, 0, 0, IDL_S, "system"}, -{HARDWARE, 0, 0, 0, HRD_S, "kernel"}, - -{DS_PROC_NR, BVM_F, DRIV_QUANTUM, 4, 0, "ds" }, -{RS_PROC_NR, 0, DRIV_QUANTUM, 4, 0, "rs" }, - -{PM_PROC_NR, OVM_F, SERV_QUANTUM, 4, 0, "pm" }, -{SCHED_PROC_NR,OVM_F, SERV_QUANTUM, 4, 0, "sched" }, -{VFS_PROC_NR, OVM_F, SERV_QUANTUM, 5, 0, "vfs" }, -{MEM_PROC_NR, BVM_F, DRIV_QUANTUM, 3, 0, "memory"}, -{LOG_PROC_NR, BVM_F, DRIV_QUANTUM, 2, 0, "log" }, -{TTY_PROC_NR, BVM_F, DRIV_QUANTUM, 1, 0, "tty" }, -{MFS_PROC_NR, BVM_F, SERV_QUANTUM, 5, 0, "mfs" }, -{VM_PROC_NR, 0, SERV_QUANTUM, 2, 0, "vm" }, -{PFS_PROC_NR, BVM_F, SERV_QUANTUM, 5, 0, "pfs" }, -{INIT_PROC_NR, BVM_F, USER_QUANTUM, USER_Q, 0, "init" }, +/* process nr, flags, stack, name */ +{IDLE, 0, IDL_S, "idle" }, +{CLOCK, 0, IDL_S, "clock" }, +{SYSTEM, 0, IDL_S, "system"}, +{HARDWARE, 0, HRD_S, "kernel"}, + +{DS_PROC_NR, BVM_F, 0, "ds" }, +{RS_PROC_NR, 0, 0, "rs" }, + +{PM_PROC_NR, OVM_F, 0, "pm" }, +{SCHED_PROC_NR,OVM_F, 0, "sched" }, +{VFS_PROC_NR, OVM_F, 0, "vfs" }, +{MEM_PROC_NR, BVM_F, 0, "memory"}, +{LOG_PROC_NR, BVM_F, 0, "log" }, +{TTY_PROC_NR, BVM_F, 0, "tty" }, +{MFS_PROC_NR, BVM_F, 0, "mfs" }, +{VM_PROC_NR, 0, 0, "vm" }, +{PFS_PROC_NR, BVM_F, 0, "pfs" }, +{INIT_PROC_NR, BVM_F, 0, "init" }, }; /* Verify the size of the system image table at compile time. Also verify that diff --git a/kernel/type.h b/kernel/type.h index 41c271e4e..664e503e1 100644 --- a/kernel/type.h +++ b/kernel/type.h @@ -14,8 +14,6 @@ typedef struct { /* bitmap for system indexes */ struct boot_image { proc_nr_t proc_nr; /* process number to use */ int flags; /* process flags */ - unsigned quantum; /* time quantum in ms */ - int priority; /* scheduling priority */ int stksize; /* stack size for tasks */ char proc_name[P_NAME_LEN]; /* name in process table */ endpoint_t endpoint; /* endpoint number when started */ diff --git a/lib/libc/other/rss_nice.c b/lib/libc/other/rss_nice.c index cb2363253..dbcb0ae5a 100644 --- a/lib/libc/other/rss_nice.c +++ b/lib/libc/other/rss_nice.c @@ -79,7 +79,7 @@ PUBLIC int rss_nice_decode(int nice, endpoint_t *scheduler, *quantum = DECODE(nice, QUANTUM_SHIFT, QUANTUM_BITS); } else { /* old ABI, not useful so just take defaults */ - *scheduler = USER_SCH; + *scheduler = SCHED_PROC_NR; *priority = USER_Q; *quantum = USER_QUANTUM; } diff --git a/lib/libsys/sched_start.c b/lib/libsys/sched_start.c index a617d350a..4a41b013a 100644 --- a/lib/libsys/sched_start.c +++ b/lib/libsys/sched_start.c @@ -53,14 +53,29 @@ PUBLIC int sched_start(endpoint_t scheduler_e, endpoint_t schedulee_e, int rv; message m; - assert(_ENDPOINT_P(scheduler_e) >= 0); + /* No scheduler given? We are done. */ + if(scheduler_e == NONE) { + return OK; + } + assert(_ENDPOINT_P(schedulee_e) >= 0); assert(_ENDPOINT_P(parent_e) >= 0); assert(maxprio >= 0); assert(maxprio < NR_SCHED_QUEUES); assert(quantum > 0); assert(newscheduler_e); - + + /* The KERNEL must schedule this process. */ + if(scheduler_e == KERNEL) { + if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL, + schedulee_e, maxprio, quantum)) != OK) { + return rv; + } + *newscheduler_e = scheduler_e; + return OK; + } + + /* A user-space scheduler must schedule this process. */ m.SCHEDULING_ENDPOINT = schedulee_e; m.SCHEDULING_PARENT = parent_e; m.SCHEDULING_MAXPRIO = (int) maxprio; diff --git a/lib/libsys/sys_schedctl.c b/lib/libsys/sys_schedctl.c index 59f013d71..46ef5f1bb 100644 --- a/lib/libsys/sys_schedctl.c +++ b/lib/libsys/sys_schedctl.c @@ -1,10 +1,13 @@ #include "syslib.h" -PUBLIC int sys_schedctl(unsigned flags, endpoint_t proc_ep) +PUBLIC int sys_schedctl(unsigned flags, endpoint_t proc_ep, unsigned priority, + unsigned quantum) { message m; m.SCHEDCTL_FLAGS = (int) flags; m.SCHEDCTL_ENDPOINT = proc_ep; + m.SCHEDCTL_PRIORITY = priority; + m.SCHEDCTL_QUANTUM = quantum; return(_kernel_call(SYS_SCHEDCTL, &m)); } diff --git a/servers/is/dmp_kernel.c b/servers/is/dmp_kernel.c index 3c610f5c7..a69f1161d 100644 --- a/servers/is/dmp_kernel.c +++ b/servers/is/dmp_kernel.c @@ -220,12 +220,12 @@ PUBLIC void image_dmp() return; } printf("Image table dump showing all processes included in system image.\n"); - printf("---name- -nr- flags -qs- -queue- -stack-\n"); + printf("---name- -nr- flags -stack-\n"); for (m=0; mproc_name, ip->proc_nr, - boot_flags_str(ip->flags), ip->quantum, ip->priority, ip->stksize); + boot_flags_str(ip->flags), ip->stksize); } printf("\n"); } diff --git a/servers/pm/main.c b/servers/pm/main.c index 6c7e89fd1..3032ff22a 100644 --- a/servers/pm/main.c +++ b/servers/pm/main.c @@ -239,7 +239,6 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) /* Set process details found in the image table. */ rmp = &mproc[ip->proc_nr]; strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN); - rmp->mp_nice = get_nice_value(ip->priority); (void) sigemptyset(&rmp->mp_ignore); (void) sigemptyset(&rmp->mp_sigmask); (void) sigemptyset(&rmp->mp_catch); @@ -255,6 +254,7 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) /* Set scheduling info */ rmp->mp_scheduler = KERNEL; + rmp->mp_nice = get_nice_value(USR_Q); } else { /* system process */ if(ip->proc_nr == RS_PROC_NR) { @@ -268,6 +268,7 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) /* RS schedules this process */ rmp->mp_scheduler = NONE; + rmp->mp_nice = get_nice_value(SRV_Q); } /* Get kernel endpoint identifier. */ diff --git a/servers/rs/const.h b/servers/rs/const.h index ce05735a7..aba3d20a8 100644 --- a/servers/rs/const.h +++ b/servers/rs/const.h @@ -93,6 +93,9 @@ #define SRV_DF (DRV_FORCED) /* system services */ #define DSRV_DF (SRV_DF) /* dynamic system services */ +/* Shorthands. */ +#define SRV_OR_USR(rp, X, Y) (rp->r_priv.s_flags & SYS_PROC ? X : Y) + /* Reply flags. */ #define RS_DONTREPLY 0 #define RS_REPLY 1 diff --git a/servers/rs/inc.h b/servers/rs/inc.h index 794bd26d7..0a7e2dd10 100644 --- a/servers/rs/inc.h +++ b/servers/rs/inc.h @@ -54,3 +54,4 @@ #include "type.h" #include "glo.h" +EXTERN _PROTOTYPE( int do_sef_lu_request, (message *m_ptr) ); diff --git a/servers/rs/main.c b/servers/rs/main.c index 7aa41d8e2..c719aca9f 100644 --- a/servers/rs/main.c +++ b/servers/rs/main.c @@ -160,7 +160,7 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the reincarnation server. */ struct boot_image *ip; - int s,i,j, usersched; + int s,i,j; int nr_image_srvs, nr_image_priv_srvs, nr_uncaught_init_srvs; struct rproc *rp; struct rproc *replica_rp; @@ -170,7 +170,6 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) struct boot_image_priv *boot_image_priv; struct boot_image_sys *boot_image_sys; struct boot_image_dev *boot_image_dev; - message m; int pid, replica_pid; endpoint_t replica_endpoint; @@ -311,10 +310,12 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) fill_call_mask(boot_image_priv->vm_calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE); + /* Scheduling parameters. */ + rp->r_scheduler = SRV_OR_USR(rp, SRV_SCH, USR_SCH); + rp->r_priority = SRV_OR_USR(rp, SRV_Q, USR_Q); + rp->r_quantum = SRV_OR_USR(rp, SRV_QT, USR_QT); + /* Get some settings from the boot image table. */ - rp->r_scheduler = boot_image_priv->sched; - rp->r_priority = ip->priority; - rp->r_quantum = ip->quantum; rpub->endpoint = ip->endpoint; /* Set some defaults. */ @@ -338,13 +339,8 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) rpub->in_use = TRUE; } - /* - Step 2: allow every system service in the boot image to run. - * first start kernel-scheduled servers, including the PM and the - * scheduler which are needed to be able to start the - * user-space-scheduled processes - */ + /* - Step 2: allow every system service in the boot image to run. */ nr_uncaught_init_srvs = 0; - for (usersched=0; usersched <= 1; usersched++) { for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; @@ -353,11 +349,6 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) continue; } - /* Kernel-scheduled processes first */ - if ((boot_image_priv->sched == KERNEL) ? usersched : !usersched) { - continue; - } - /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; @@ -403,7 +394,6 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) catch_boot_init_ready(ANY); nr_uncaught_init_srvs--; } - } /* - Step 4: all the system services in the boot image are now running. * Complete the initialization of the system process table in collaboration diff --git a/servers/rs/table.c b/servers/rs/table.c index c8dcdf7d1..7beb421de 100644 --- a/servers/rs/table.c +++ b/servers/rs/table.c @@ -58,24 +58,23 @@ PRIVATE int /* Definition of the boot image priv table. The order of entries in this table * reflects the order boot system services are made runnable and initialized - * at boot time, except for the fact that kernel-scheduled services are - * handled before user-scheduled ones. + * at boot time. */ PUBLIC struct boot_image_priv boot_image_priv_table[] = { -/*endpoint, label, flags, traps, ipcto, sigmgr, sched, kcalls, vmcalls */ -{RS_PROC_NR, "rs", RSYS_F, RSYS_T, RSYS_M, RSYS_SM, KERN_SCH, rs_kc, rs_vmc }, -{VM_PROC_NR, "vm", VM_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, vm_kc, vm_vmc }, -{PM_PROC_NR, "pm", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, pm_kc, pm_vmc }, -{SCHED_PROC_NR,"sched", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, sched_kc, sched_vmc }, -{VFS_PROC_NR, "vfs", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, vfs_kc, vfs_vmc }, -{DS_PROC_NR, "ds", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, ds_kc, ds_vmc }, -{TTY_PROC_NR, "tty", SRV_F, SRV_T, SRV_M, SRV_SM, USER_SCH, tty_kc, tty_vmc }, -{MEM_PROC_NR, "memory", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, mem_kc, mem_vmc }, -{LOG_PROC_NR, "log", SRV_F, SRV_T, SRV_M, SRV_SM, USER_SCH, log_kc, log_vmc }, -{MFS_PROC_NR,"fs_imgrd", SRV_F, SRV_T, SRV_M, SRV_SM, KERN_SCH, mfs_kc, mfs_vmc }, -{PFS_PROC_NR, "pfs", SRV_F, SRV_T, SRV_M, SRV_SM, USER_SCH, pfs_kc, pfs_vmc }, -{INIT_PROC_NR, "init", RUSR_F, RUSR_T, RUSR_M, RUSR_SM, NONE, rusr_kc, rusr_vmc }, -{NULL_BOOT_NR, "", 0, 0, 0, 0, 0, no_kc, no_vmc } +/*endpoint, label, flags, traps, ipcto, sigmgr, kcalls, vmcalls */ +{RS_PROC_NR, "rs", RSYS_F, RSYS_T, RSYS_M, RSYS_SM, rs_kc, rs_vmc }, +{VM_PROC_NR, "vm", VM_F, SRV_T, SRV_M, SRV_SM, vm_kc, vm_vmc }, +{PM_PROC_NR, "pm", SRV_F, SRV_T, SRV_M, SRV_SM, pm_kc, pm_vmc }, +{SCHED_PROC_NR,"sched", SRV_F, SRV_T, SRV_M, SRV_SM, sched_kc, sched_vmc }, +{VFS_PROC_NR, "vfs", SRV_F, SRV_T, SRV_M, SRV_SM, vfs_kc, vfs_vmc }, +{DS_PROC_NR, "ds", SRV_F, SRV_T, SRV_M, SRV_SM, ds_kc, ds_vmc }, +{TTY_PROC_NR, "tty", SRV_F, SRV_T, SRV_M, SRV_SM, tty_kc, tty_vmc }, +{MEM_PROC_NR, "memory", SRV_F, SRV_T, SRV_M, SRV_SM, mem_kc, mem_vmc }, +{LOG_PROC_NR, "log", SRV_F, SRV_T, SRV_M, SRV_SM, log_kc, log_vmc }, +{MFS_PROC_NR,"fs_imgrd", SRV_F, SRV_T, SRV_M, SRV_SM, mfs_kc, mfs_vmc }, +{PFS_PROC_NR, "pfs", SRV_F, SRV_T, SRV_M, SRV_SM, pfs_kc, pfs_vmc }, +{INIT_PROC_NR, "init", RUSR_F, RUSR_T, RUSR_M, RUSR_SM, rusr_kc, rusr_vmc }, +{NULL_BOOT_NR, "", 0, 0, 0, 0, no_kc, no_vmc } }; /* Definition of the boot image sys table. */ diff --git a/servers/rs/type.h b/servers/rs/type.h index 5f170ab4f..ec23beeba 100644 --- a/servers/rs/type.h +++ b/servers/rs/type.h @@ -12,7 +12,6 @@ struct boot_image_priv { short trap_mask; /* allowed system call traps */ int ipc_to; /* send mask protection */ endpoint_t sig_mgr; /* signal manager */ - endpoint_t sched; /* scheduler */ int *k_calls; /* allowed kernel calls */ int *vm_calls; /* allowed vm calls */ }; diff --git a/servers/rs/utility.c b/servers/rs/utility.c index fae9ca15d..03921ab8a 100644 --- a/servers/rs/utility.c +++ b/servers/rs/utility.c @@ -195,36 +195,22 @@ PUBLIC int rs_isokendpt(endpoint_t endpoint, int *proc) *===========================================================================*/ PUBLIC int sched_init_proc(struct rproc *rp) { - int s; - - switch (rp->r_scheduler) { - - case NONE: - /* don't touch user processes, PM deals with them */ - assert(!(rp->r_priv.s_flags & SYS_PROC)); - break; - - case KERNEL: - /* Confirm kernel scheduler to remove RTS_NO_QUANTUM */ - assert(rp->r_priv.s_flags & SYS_PROC); - if ((s = sys_schedctl(SCHEDCTL_FLAG_KERNEL, - rp->r_pub->endpoint)) != OK) { - panic("unable to kernel-schedule service: %d", s); - } - break; - - default: - /* tell scheduler to schedule this one */ - assert(rp->r_priv.s_flags & SYS_PROC); - if ((s = sched_start(rp->r_scheduler, rp->r_pub->endpoint, - RS_PROC_NR, rp->r_priority, rp->r_quantum, - &rp->r_scheduler)) != OK) { - return s; - } - break; - } - - return OK; + int s; + int is_usr_proc; + + /* Make sure user processes have no scheduler. PM deals with them. */ + is_usr_proc = !(rp->r_priv.s_flags & SYS_PROC); + if(is_usr_proc) assert(rp->r_scheduler == NONE); + if(!is_usr_proc) assert(rp->r_scheduler != NONE); + + /* Start scheduling for the given process. */ + if ((s = sched_start(rp->r_scheduler, rp->r_pub->endpoint, + RS_PROC_NR, rp->r_priority, rp->r_quantum, + &rp->r_scheduler)) != OK) { + return s; + } + + return s; } /*===========================================================================* diff --git a/servers/sched/schedule.c b/servers/sched/schedule.c index be904c12c..6846477b8 100644 --- a/servers/sched/schedule.c +++ b/servers/sched/schedule.c @@ -134,7 +134,7 @@ PUBLIC int do_start_scheduling(message *m_ptr) /* Take over scheduling the process. The kernel reply message populates * the processes current priority and its time slice */ - if ((rv = sys_schedctl(0, rmp->endpoint)) != OK) { + if ((rv = sys_schedctl(0, rmp->endpoint, 0, 0)) != OK) { printf("Sched: Error taking over scheduling for %d, kernel said %d\n", rmp->endpoint, rv); return rv;