1 /* This file contains the main program of the SCHED scheduler. It will sit idle
2 * until asked, by PM, to take over scheduling a particular process.
5 /* The _MAIN def indicates that we want the schedproc structs to be created
6 * here. Used from within schedproc.h */
10 #include "schedproc.h"
12 /* Declare some local functions. */
13 static void reply(endpoint_t whom
, message
*m_ptr
);
14 static void sef_local_startup(void);
15 static int sef_cb_init_fresh(int type
, sef_init_info_t
*info
);
17 struct machine machine
; /* machine info */
19 /*===========================================================================*
21 *===========================================================================*/
24 /* Main routine of the scheduler. */
25 message m_in
; /* the incoming message itself is kept here. */
26 int call_nr
; /* system call number */
27 int who_e
; /* caller's endpoint */
28 int result
; /* result to system call */
31 /* SEF local startup. */
34 /* This is SCHED's main loop - get work and do it, forever and forever. */
38 /* Wait for the next message and extract useful information from it. */
39 if (sef_receive_status(ANY
, &m_in
, &ipc_status
) != OK
)
40 panic("SCHED sef_receive error");
41 who_e
= m_in
.m_source
; /* who sent the message */
42 call_nr
= m_in
.m_type
; /* system call number */
44 /* Check for system notifications first. Special cases. */
45 if (is_ipc_notify(ipc_status
)) {
54 continue; /* Don't reply. */
58 case SCHEDULING_INHERIT
:
59 case SCHEDULING_START
:
60 result
= do_start_scheduling(&m_in
);
63 result
= do_stop_scheduling(&m_in
);
65 case SCHEDULING_SET_NICE
:
66 result
= do_nice(&m_in
);
68 case SCHEDULING_NO_QUANTUM
:
69 /* This message was sent from the kernel, don't reply */
70 if (IPC_STATUS_FLAGS_TEST(ipc_status
,
71 IPC_FLG_MSG_FROM_KERNEL
)) {
72 if ((rv
= do_noquantum(&m_in
)) != (OK
)) {
73 printf("SCHED: Warning, do_noquantum "
74 "failed with %d\n", rv
);
76 continue; /* Don't reply */
79 printf("SCHED: process %d faked "
80 "SCHEDULING_NO_QUANTUM message!\n",
86 result
= no_sys(who_e
, call_nr
);
90 if (result
!= SUSPEND
) {
91 m_in
.m_type
= result
; /* build reply message */
92 reply(who_e
, &m_in
); /* send it away */
98 /*===========================================================================*
100 *===========================================================================*/
101 static void reply(endpoint_t who_e
, message
*m_ptr
)
103 int s
= ipc_send(who_e
, m_ptr
); /* send the message */
105 printf("SCHED: unable to send reply to %d: %d\n", who_e
, s
);
108 /*===========================================================================*
109 * sef_local_startup *
110 *===========================================================================*/
111 static void sef_local_startup(void)
113 /* Register init callbacks. */
114 sef_setcb_init_fresh(sef_cb_init_fresh
);
115 sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL
);
117 /* No signal callbacks for now. */
119 /* Let SEF perform startup. */
123 /*===========================================================================*
124 * sef_cb_init_fresh *
125 *===========================================================================*/
126 static int sef_cb_init_fresh(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
130 if (OK
!= (s
=sys_getmachine(&machine
)))
131 panic("couldn't get machine info: %d", s
);
132 /* Initialize scheduling timers, used for running balance_queues */