Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[e77732]: elks / kernel / sched.c Maximize Restore History

Download this file

sched.c    296 lines (234 with data), 6.3 kB

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* kernel/sched.c
* (C) 1995 Chad Page
*
* This is the main scheduler - hopefully simpler than Linux's at present.
*
*
*/
/* Commnent in below to use the old scheduler which uses counters */
#include <linuxmt/kernel.h>
#include <linuxmt/sched.h>
#include <linuxmt/timer.h>
#include <linuxmt/string.h>
#include <arch/irq.h>
#define init_task task[0]
__task task[MAX_TASKS];
unsigned char nr_running;
__ptask current, previous;
extern int intr_count;
static void run_timer_list();
void add_to_runqueue(register struct task_struct *p)
{
nr_running++;
(p->prev_run = init_task.prev_run)->next_run = p;
p->next_run = &init_task;
init_task.prev_run = p;
}
void del_from_runqueue(register struct task_struct *p)
{
#if 0 /* sanity tests */
if (!p->next_run || !p->prev_run) {
printk("task %d not on run-queue (state=%d)\n", p->pid, p->state);
return;
}
#endif
if (p == &init_task) {
printk("idle task may not sleep\n");
return;
}
nr_running--;
(p->next_run->prev_run = p->prev_run)->next_run = p->next_run;
p->next_run = p->prev_run = NULL;
#ifdef CONFIG_SWAP
p->last_running = jiffies;
#endif
}
static void process_timeout(int __data)
{
register struct task_struct *p = (struct task_struct *) __data;
#if 0
printk("process_timeout called! data=%x, waking task %d\n", __data,
p->pid);
#endif
p->timeout = 0UL;
wake_up_process(p);
}
/*
* Schedule a task. On entry current is the task, which will
* vanish quietly for a while and someone elses thread will return
* from here.
*/
void schedule(void)
{
register __ptask prev;
register __ptask next;
jiff_t timeout = 0UL;
prev = current;
next = prev->next_run;
if (prev->t_kstackm != KSTACK_MAGIC)
panic("Process %d exceeded kernel stack limit! magic %x\n",
prev->pid, prev->t_kstackm);
/* We have to let a task exit! */
if (prev->state == TASK_EXITING)
return;
clr_irq();
switch (prev->state) {
case TASK_INTERRUPTIBLE:
if (prev->signal /* & ~prev->blocked */ )
goto makerunnable;
timeout = prev->timeout;
if (prev->timeout && (prev->timeout <= jiffies)) {
prev->timeout = timeout = 0UL;
makerunnable:
prev->state = TASK_RUNNING;
break;
}
default:
del_from_runqueue(prev);
/*break; */
case TASK_RUNNING:
break;
}
set_irq();
if(next == &init_task)
next = next->next_run;
if (intr_count > 0)
goto scheduling_in_interrupt;
if (next != prev) {
struct timer_list timer;
if (timeout) {
init_timer(&timer);
timer.tl_expires = timeout;
timer.tl_data = (int) prev;
timer.tl_function = process_timeout;
add_timer(&timer);
}
#ifdef CONFIG_SWAP
if(do_swapper_run(next) == -1){
printk("Can't become runnable %d\n", next->pid);
panic("");
}
#endif
previous = prev;
current = next;
tswitch(); /* Won't return for a new task */
if (timeout) {
del_timer(&timer);
}
}
return;
scheduling_in_interrupt:
/* Taking a timer IRQ during another IRQ or while in kernel space is
* quite legal. We just dont switch then */
/* if (intr_count > 0) */
printk("Aiee: scheduling in interrupt %d - %d %d\n",
intr_count, next->pid, prev->pid);
}
struct timer_list tl_list = { NULL, NULL, 0L, 0, NULL };
static int detach_timer(struct timer_list *timer)
{
register struct timer_list *next;
register struct timer_list *prev;
next = timer->tl_next;
prev = timer->tl_prev;
if (next) {
next->tl_prev = prev;
}
if (prev) {
prev->tl_next = next;
return 1;
}
return 0;
}
int del_timer(register struct timer_list *timer)
{
int ret;
flag_t flags;
save_flags(flags);
clr_irq();
ret = detach_timer(timer);
timer->tl_next = timer->tl_prev = 0;
restore_flags(flags);
return ret;
}
void init_timer(register struct timer_list *timer)
{
timer->tl_next = timer->tl_prev = NULL;
}
void add_timer(register struct timer_list *timer)
{
flag_t flags;
register struct timer_list *next = &tl_list;
struct timer_list *prev;
save_flags(flags);
clr_irq();
do {
prev = next;
} while((next = next->tl_next) && (next->tl_expires < timer->tl_expires));
(timer->tl_prev = prev)->tl_next = timer;
if((timer->tl_next = next))
next->tl_prev = timer;
restore_flags(flags);
}
static void run_timer_list(void)
{
register struct timer_list *timer;
clr_irq();
while ((timer = tl_list.tl_next) && timer->tl_expires <= jiffies) {
detach_timer(timer);
timer->tl_next = timer->tl_prev = NULL;
set_irq();
timer->tl_function(timer->tl_data);
clr_irq();
}
set_irq();
}
/* maybe someday I'll implement these profiling things -PL */
#if 0
static void do_it_prof(struct task_struct *p, jiff_t ticks)
{
jiff_t it_prof = p->it_prof_value;
if (it_prof) {
if (it_prof <= ticks) {
it_prof = ticks + p->it_prof_incr;
send_sig(SIGPROF, p, 1);
}
p->it_prof_value = it_prof - ticks;
}
}
static void update_one_process(struct taks_struct *p,
jiff_t ticks, jiff_t user, jiff_t system)
{
do_process_times(p, user, system);
do_it_virt(p, user);
do_it_prof(p, ticks);
}
#endif
void do_timer(struct pt_regs *regs)
{
jiffies++;
#ifdef NEED_RESCHED /* need_resched is not checked anywhere */
if (!((int) jiffies & 7))
need_resched = 1; /* how primitive can you get? */
#endif
run_timer_list();
}
void sched_init(void)
{
register struct task_struct *taskp;
/*
* Now create task 0 to be ourself.
*/
taskp = &init_task;
memset(taskp, 0, sizeof(struct task_struct));
taskp->state = TASK_RUNNING;
taskp->next_run = taskp->prev_run = taskp;
current = taskp;
/* nr_running = 0;*/
/*
* Mark tasks 1-31 as not in use.
*/
while(++taskp < &task[MAX_TASKS])
taskp->state=TASK_UNUSED;
}