1 #include "syslib.h"
2 #include <assert.h>
3 #include <machine/archtypes.h>
4 #include <minix/timers.h>
5 #include <minix/sched.h>
6 #include <string.h>
7
8 /*===========================================================================*
9 * sched_inherit *
10 *===========================================================================*/
sched_inherit(endpoint_t scheduler_e,endpoint_t schedulee_e,endpoint_t parent_e,unsigned maxprio,endpoint_t * newscheduler_e)11 int sched_inherit(endpoint_t scheduler_e,
12 endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio,
13 endpoint_t *newscheduler_e)
14 {
15 int rv;
16 message m;
17
18 assert(_ENDPOINT_P(scheduler_e) >= 0);
19 assert(_ENDPOINT_P(schedulee_e) >= 0);
20 assert(_ENDPOINT_P(parent_e) >= 0);
21 assert(maxprio < NR_SCHED_QUEUES);
22 assert(newscheduler_e);
23
24 memset(&m, 0, sizeof(m));
25 m.m_lsys_sched_scheduling_start.endpoint = schedulee_e;
26 m.m_lsys_sched_scheduling_start.parent = parent_e;
27 m.m_lsys_sched_scheduling_start.maxprio = maxprio;
28
29 /* Send the request to the scheduler */
30 if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) {
31 return rv;
32 }
33
34 /* Store the process' scheduler. Note that this might not be the
35 * scheduler we sent the SCHEDULING_INHERIT message to. That scheduler
36 * might have forwarded the scheduling message on to another scheduler
37 * before returning the message.
38 */
39 *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
40 return (OK);
41 }
42
43 /*===========================================================================*
44 * sched_start *
45 *===========================================================================*/
sched_start(endpoint_t scheduler_e,endpoint_t schedulee_e,endpoint_t parent_e,int maxprio,int quantum,int cpu,endpoint_t * newscheduler_e)46 int sched_start(endpoint_t scheduler_e,
47 endpoint_t schedulee_e,
48 endpoint_t parent_e,
49 int maxprio,
50 int quantum,
51 int cpu,
52 endpoint_t *newscheduler_e)
53 {
54 int rv;
55 message m;
56
57 /* No scheduler given? We are done. */
58 if(scheduler_e == NONE) {
59 return OK;
60 }
61
62 assert(_ENDPOINT_P(schedulee_e) >= 0);
63 assert(_ENDPOINT_P(parent_e) >= 0);
64 assert(maxprio >= 0);
65 assert(maxprio < NR_SCHED_QUEUES);
66 assert(quantum > 0);
67 assert(newscheduler_e);
68
69 /* The KERNEL must schedule this process. */
70 if(scheduler_e == KERNEL) {
71 if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL,
72 schedulee_e, maxprio, quantum, cpu)) != OK) {
73 return rv;
74 }
75 *newscheduler_e = scheduler_e;
76 return OK;
77 }
78
79 /* A user-space scheduler must schedule this process. */
80 memset(&m, 0, sizeof(m));
81 m.m_lsys_sched_scheduling_start.endpoint = schedulee_e;
82 m.m_lsys_sched_scheduling_start.parent = parent_e;
83 m.m_lsys_sched_scheduling_start.maxprio = maxprio;
84 m.m_lsys_sched_scheduling_start.quantum = quantum;
85
86 /* Send the request to the scheduler */
87 if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) {
88 return rv;
89 }
90
91 /* Store the process' scheduler. Note that this might not be the
92 * scheduler we sent the SCHEDULING_START message to. That scheduler
93 * might have forwarded the scheduling message on to another scheduler
94 * before returning the message.
95 */
96 *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
97 return (OK);
98 }
99