This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
145 lines (127 loc) · 4 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* This file contains the main program of the SCHED scheduler. It will sit idle
* until asked, by PM, to take over scheduling a particular process.
*/
/* The _MAIN def indicates that we want the schedproc structs to be created
* here. Used from within schedproc.h */
#define _MAIN
#include "sched.h"
#include "schedproc.h"
/* Declare some local functions. */
static void reply(endpoint_t whom, message *m_ptr);
static void sef_local_startup(void);
static void init_scheduling(void);
struct machine machine; /* machine info */
struct M;
int do_start_scheduling(message *m_ptr);
int do_stop_scheduling(message *m_ptr);
int do_nice(message *m_ptr);
int do_noquantum(message *m_ptr);
int no_sys(int who_e, int call_nr);
/*===========================================================================*
* main *
*===========================================================================*/
int main(void)
{
/* Main routine of the scheduler. */
message m_in; /* the incoming message itself is kept here. */
int call_nr; /* system call number */
int who_e; /* caller's endpoint */
int result; /* result to system call */
int rv;
int s;
/* SEF local startup. */
sef_local_startup();
if (OK != (s=sys_getmachine(&machine)))
panic("couldn't get machine info: %d", s);
/* Initialize scheduling timers, used for running balance_queues */
init_scheduling();
/* This is SCHED's main loop - get work and do it, forever and forever. */
while (TRUE) {
int ipc_status;
/* Wait for the next message and extract useful information from it. */
if (sef_receive_status(ANY, &m_in, &ipc_status) != OK)
panic("SCHED sef_receive error");
who_e = m_in.m_source; /* who sent the message */
call_nr = m_in.m_type; /* system call number */
/* Check for system notifications first. Special cases. */
if (is_ipc_notify(ipc_status)) {
switch(who_e) {
case CLOCK:
expire_timers(m_in.NOTIFY_TIMESTAMP);
continue; /* don't reply */
default :
result = ENOSYS;
}
goto sendreply;
}
switch(call_nr) {
case SCHEDULING_INHERIT:
case SCHEDULING_START:
result = do_start_scheduling(&m_in);
break;
case SCHEDULING_STOP:
result = do_stop_scheduling(&m_in);
break;
case SCHEDULING_SET_NICE:
result = do_nice(&m_in);
break;
case SCHEDULING_NO_QUANTUM:
/* This message was sent from the kernel, don't reply */
if (IPC_STATUS_FLAGS_TEST(ipc_status,
IPC_FLG_MSG_FROM_KERNEL)) {
if ((rv = do_noquantum(&m_in)) != (OK)) {
printf("SCHED: Warning, do_noquantum "
"failed with %d\n", rv);
}
continue; /* Don't reply */
}
else {
printf("SCHED: process %d faked "
"SCHEDULING_NO_QUANTUM message!\n",
who_e);
result = EPERM;
}
break;
default:
result = no_sys(who_e, call_nr);
}
sendreply:
/* Send reply. */
if (result != SUSPEND) {
m_in.m_type = result; /* build reply message */
reply(who_e, &m_in); /* send it away */
}
}
return(OK);
}
/*===========================================================================*
* reply *
*===========================================================================*/
static void reply(endpoint_t who_e, message *m_ptr)
{
int s = send(who_e, m_ptr); /* send the message */
if (OK != s)
printf("SCHED: unable to send reply to %d: %d\n", who_e, s);
}
/*===========================================================================*
* sef_local_startup *
*===========================================================================*/
static void sef_local_startup(void)
{
/* No init callbacks for now. */
/* No live update support for now. */
/* No signal callbacks for now. */
/* Let SEF perform startup. */
sef_startup();
}
void init_scheduling(void)
{
}
int call_minix_sys_schedule(endpoint_t proc_ep, int priority, int quantum, int cpu)
{
return sys_schedule(proc_ep,priority,quantum,cpu);
}
int call_minix_sys_schedctl(unsigned flags, endpoint_t proc_ep, int priority, int quantum, int cpu)
{
return sys_schedctl(flags,proc_ep,priority,quantum,cpu);
}