1 #include "kernel/system.h"
2 #include <minix/endpoint.h>
3
4 /*===========================================================================*
5 * do_schedctl *
6 *===========================================================================*/
do_schedctl(struct proc * caller,message * m_ptr)7 int do_schedctl(struct proc * caller, message * m_ptr)
8 {
9 struct proc *p;
10 uint32_t flags;
11 int priority, quantum, cpu;
12 int proc_nr;
13 int r;
14
15 /* check parameter validity */
16 flags = m_ptr->m_lsys_krn_schedctl.flags;
17 if (flags & ~SCHEDCTL_FLAG_KERNEL) {
18 printf("do_schedctl: flags 0x%x invalid, caller=%d\n",
19 flags, caller - proc);
20 return EINVAL;
21 }
22
23 if (!isokendpt(m_ptr->m_lsys_krn_schedctl.endpoint, &proc_nr))
24 return EINVAL;
25
26 p = proc_addr(proc_nr);
27
28 if ((flags & SCHEDCTL_FLAG_KERNEL) == SCHEDCTL_FLAG_KERNEL) {
29 /* the kernel becomes the scheduler and starts
30 * scheduling the process.
31 */
32 priority = m_ptr->m_lsys_krn_schedctl.priority;
33 quantum = m_ptr->m_lsys_krn_schedctl.quantum;
34 cpu = m_ptr->m_lsys_krn_schedctl.cpu;
35
36 /* Try to schedule the process. */
37 if((r = sched_proc(p, priority, quantum, cpu, FALSE)) != OK)
38 return r;
39 p->p_scheduler = NULL;
40 } else {
41 /* the caller becomes the scheduler */
42 p->p_scheduler = caller;
43 }
44
45 return(OK);
46 }
47