1433d6423SLionel Sambuc #include "syslib.h"
2433d6423SLionel Sambuc #include <assert.h>
3433d6423SLionel Sambuc #include <machine/archtypes.h>
4433d6423SLionel Sambuc #include <minix/timers.h>
5*685aa793SDavid van Moolenbroek #include <minix/sched.h>
6433d6423SLionel Sambuc #include <string.h>
7433d6423SLionel Sambuc
8433d6423SLionel Sambuc /*===========================================================================*
9433d6423SLionel Sambuc * sched_inherit *
10433d6423SLionel Sambuc *===========================================================================*/
sched_inherit(endpoint_t scheduler_e,endpoint_t schedulee_e,endpoint_t parent_e,unsigned maxprio,endpoint_t * newscheduler_e)11433d6423SLionel Sambuc int sched_inherit(endpoint_t scheduler_e,
12433d6423SLionel Sambuc endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio,
13433d6423SLionel Sambuc endpoint_t *newscheduler_e)
14433d6423SLionel Sambuc {
15433d6423SLionel Sambuc int rv;
16433d6423SLionel Sambuc message m;
17433d6423SLionel Sambuc
18433d6423SLionel Sambuc assert(_ENDPOINT_P(scheduler_e) >= 0);
19433d6423SLionel Sambuc assert(_ENDPOINT_P(schedulee_e) >= 0);
20433d6423SLionel Sambuc assert(_ENDPOINT_P(parent_e) >= 0);
21433d6423SLionel Sambuc assert(maxprio < NR_SCHED_QUEUES);
22433d6423SLionel Sambuc assert(newscheduler_e);
23433d6423SLionel Sambuc
24433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
25433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.endpoint = schedulee_e;
26433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.parent = parent_e;
27433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.maxprio = maxprio;
28433d6423SLionel Sambuc
29433d6423SLionel Sambuc /* Send the request to the scheduler */
30433d6423SLionel Sambuc if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) {
31433d6423SLionel Sambuc return rv;
32433d6423SLionel Sambuc }
33433d6423SLionel Sambuc
34433d6423SLionel Sambuc /* Store the process' scheduler. Note that this might not be the
35433d6423SLionel Sambuc * scheduler we sent the SCHEDULING_INHERIT message to. That scheduler
36433d6423SLionel Sambuc * might have forwarded the scheduling message on to another scheduler
37433d6423SLionel Sambuc * before returning the message.
38433d6423SLionel Sambuc */
39433d6423SLionel Sambuc *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
40433d6423SLionel Sambuc return (OK);
41433d6423SLionel Sambuc }
42433d6423SLionel Sambuc
43433d6423SLionel Sambuc /*===========================================================================*
44433d6423SLionel Sambuc * sched_start *
45433d6423SLionel Sambuc *===========================================================================*/
sched_start(endpoint_t scheduler_e,endpoint_t schedulee_e,endpoint_t parent_e,int maxprio,int quantum,int cpu,endpoint_t * newscheduler_e)46433d6423SLionel Sambuc int sched_start(endpoint_t scheduler_e,
47433d6423SLionel Sambuc endpoint_t schedulee_e,
48433d6423SLionel Sambuc endpoint_t parent_e,
49433d6423SLionel Sambuc int maxprio,
50433d6423SLionel Sambuc int quantum,
51433d6423SLionel Sambuc int cpu,
52433d6423SLionel Sambuc endpoint_t *newscheduler_e)
53433d6423SLionel Sambuc {
54433d6423SLionel Sambuc int rv;
55433d6423SLionel Sambuc message m;
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc /* No scheduler given? We are done. */
58433d6423SLionel Sambuc if(scheduler_e == NONE) {
59433d6423SLionel Sambuc return OK;
60433d6423SLionel Sambuc }
61433d6423SLionel Sambuc
62433d6423SLionel Sambuc assert(_ENDPOINT_P(schedulee_e) >= 0);
63433d6423SLionel Sambuc assert(_ENDPOINT_P(parent_e) >= 0);
64433d6423SLionel Sambuc assert(maxprio >= 0);
65433d6423SLionel Sambuc assert(maxprio < NR_SCHED_QUEUES);
66433d6423SLionel Sambuc assert(quantum > 0);
67433d6423SLionel Sambuc assert(newscheduler_e);
68433d6423SLionel Sambuc
69433d6423SLionel Sambuc /* The KERNEL must schedule this process. */
70433d6423SLionel Sambuc if(scheduler_e == KERNEL) {
71433d6423SLionel Sambuc if ((rv = sys_schedctl(SCHEDCTL_FLAG_KERNEL,
72433d6423SLionel Sambuc schedulee_e, maxprio, quantum, cpu)) != OK) {
73433d6423SLionel Sambuc return rv;
74433d6423SLionel Sambuc }
75433d6423SLionel Sambuc *newscheduler_e = scheduler_e;
76433d6423SLionel Sambuc return OK;
77433d6423SLionel Sambuc }
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc /* A user-space scheduler must schedule this process. */
80433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
81433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.endpoint = schedulee_e;
82433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.parent = parent_e;
83433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.maxprio = maxprio;
84433d6423SLionel Sambuc m.m_lsys_sched_scheduling_start.quantum = quantum;
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc /* Send the request to the scheduler */
87433d6423SLionel Sambuc if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) {
88433d6423SLionel Sambuc return rv;
89433d6423SLionel Sambuc }
90433d6423SLionel Sambuc
91433d6423SLionel Sambuc /* Store the process' scheduler. Note that this might not be the
92433d6423SLionel Sambuc * scheduler we sent the SCHEDULING_START message to. That scheduler
93433d6423SLionel Sambuc * might have forwarded the scheduling message on to another scheduler
94433d6423SLionel Sambuc * before returning the message.
95433d6423SLionel Sambuc */
96433d6423SLionel Sambuc *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
97433d6423SLionel Sambuc return (OK);
98433d6423SLionel Sambuc }
99