Skip to content

Commit

Permalink
Preemptive scheduling works, but ... yield doesn't work :(
Browse files Browse the repository at this point in the history
  • Loading branch information
pykello committed Jun 3, 2015
1 parent d62fae4 commit ce5de3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
17 changes: 4 additions & 13 deletions kernel/proc/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ static int round_robin_index;

void handle_timer(void)
{
//schedule();
kprintf("timer\n");
timer_clear_interrupt();
schedule();
}
Expand All @@ -26,32 +24,25 @@ void scheduler_init(void)
void schedule(void)
{
int i;
kprintf("schedule \n");
// mon_status(0, 0);
for (i = 0; i < PROCESS_COUNT_MAX; i++) {
struct Process *proc = NULL;

//kprintf("round_robin_index = %d\n", round_robin_index);
//kprintf("&round_robin_index = %x\n", &round_robin_index);

round_robin_index++;
if (round_robin_index == PROCESS_COUNT_MAX)
{
round_robin_index = 0;
}

proc = &process_table[round_robin_index];
kprintf("process[%d]->state = %d\n", round_robin_index, proc->state);

if (proc->state == READY) {
current_process = proc;
proc_start(proc);
}
}

/* no process is ready to run, run monitor */
set_translation_table_base((uint32_t) V2P(kernel_vm));
current_process = NULL;
__asm__ volatile("ldr sp, =kernel_stack_start");
enable_interrupts();
monitor();
/* no process? panic */
kprintf("PANIC");
while(1);
}
1 change: 1 addition & 0 deletions kernel/startup.S
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ syscall_entry:

irq_entry:
sub r14, r14, #4
ldr sp, =irq_stack_start
SAVE_CONTEXT

stmfd r13!, {r0-r12, r14}
Expand Down
6 changes: 3 additions & 3 deletions user/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ void _start()
{
int i = 0, j = 0;
fork();
//fork();
fork();

while (1) {
for (j = 0; j < 50000000; j++);
for (j = 0; j < 1000000; j++);
printf("step %d at pid %d\n", i, getpid());
//yield();
// yield();
i++;
}

Expand Down

0 comments on commit ce5de3c

Please sign in to comment.