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);
16 struct machine machine
; /* machine info */
18 /*===========================================================================*
20 *===========================================================================*/
23 /* Main routine of the scheduler. */
24 message m_in
; /* the incoming message itself is kept here. */
25 int call_nr
; /* system call number */
26 int who_e
; /* caller's endpoint */
27 int result
; /* result to system call */
31 /* SEF local startup. */
34 if (OK
!= (s
=sys_getmachine(&machine
)))
35 panic("couldn't get machine info: %d", s
);
36 /* Initialize scheduling timers, used for running balance_queues */
39 /* This is SCHED's main loop - get work and do it, forever and forever. */
43 /* Wait for the next message and extract useful information from it. */
44 if (sef_receive_status(ANY
, &m_in
, &ipc_status
) != OK
)
45 panic("SCHED sef_receive error");
46 who_e
= m_in
.m_source
; /* who sent the message */
47 call_nr
= m_in
.m_type
; /* system call number */
49 /* Check for system notifications first. Special cases. */
50 if (is_ipc_notify(ipc_status
)) {
53 expire_timers(m_in
.NOTIFY_TIMESTAMP
);
54 continue; /* don't reply */
63 case SCHEDULING_INHERIT
:
64 case SCHEDULING_START
:
65 result
= do_start_scheduling(&m_in
);
68 result
= do_stop_scheduling(&m_in
);
70 case SCHEDULING_SET_NICE
:
71 result
= do_nice(&m_in
);
73 case SCHEDULING_NO_QUANTUM
:
74 /* This message was sent from the kernel, don't reply */
75 if (IPC_STATUS_FLAGS_TEST(ipc_status
,
76 IPC_FLG_MSG_FROM_KERNEL
)) {
77 if ((rv
= do_noquantum(&m_in
)) != (OK
)) {
78 printf("SCHED: Warning, do_noquantum "
79 "failed with %d\n", rv
);
81 continue; /* Don't reply */
84 printf("SCHED: process %d faked "
85 "SCHEDULING_NO_QUANTUM message!\n",
91 result
= no_sys(who_e
, call_nr
);
96 if (result
!= SUSPEND
) {
97 m_in
.m_type
= result
; /* build reply message */
98 reply(who_e
, &m_in
); /* send it away */
104 /*===========================================================================*
106 *===========================================================================*/
107 static void reply(endpoint_t who_e
, message
*m_ptr
)
109 int s
= send(who_e
, m_ptr
); /* send the message */
111 printf("SCHED: unable to send reply to %d: %d\n", who_e
, s
);
114 /*===========================================================================*
115 * sef_local_startup *
116 *===========================================================================*/
117 static void sef_local_startup(void)
119 /* No init callbacks for now. */
120 /* No live update support for now. */
121 /* No signal callbacks for now. */
123 /* Let SEF perform startup. */