etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libsys / sched_start.c
blob6cce480f48076c59abf443460bd3439612bcf67c
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>
8 /*===========================================================================*
9 * sched_inherit *
10 *===========================================================================*/
11 int sched_inherit(endpoint_t scheduler_e,
12 endpoint_t schedulee_e, endpoint_t parent_e, unsigned maxprio,
13 endpoint_t *newscheduler_e)
15 int rv;
16 message m;
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);
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;
29 /* Send the request to the scheduler */
30 if ((rv = _taskcall(scheduler_e, SCHEDULING_INHERIT, &m))) {
31 return rv;
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.
39 *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
40 return (OK);
43 /*===========================================================================*
44 * sched_start *
45 *===========================================================================*/
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)
54 int rv;
55 message m;
57 /* No scheduler given? We are done. */
58 if(scheduler_e == NONE) {
59 return OK;
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);
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;
75 *newscheduler_e = scheduler_e;
76 return OK;
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;
86 /* Send the request to the scheduler */
87 if ((rv = _taskcall(scheduler_e, SCHEDULING_START, &m))) {
88 return rv;
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.
96 *newscheduler_e = m.m_sched_lsys_scheduling_start.scheduler;
97 return (OK);