Skip to content

Commit

Permalink
Preemptive scheduling, although with memory corruption ...
Browse files Browse the repository at this point in the history
  • Loading branch information
pykello committed Jun 3, 2015
1 parent e46c6ea commit d62fae4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <types.h>

typedef void (*entry_function)(void);
#define PROCESS_COUNT_MAX 32
#define PROCESS_COUNT_MAX 10

enum ProcessState {
UNUSED,
Expand Down
10 changes: 7 additions & 3 deletions kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <kalloc.h>
#include <monitor.h>
#include <proc.h>
#include <timer.h>

/*
* Kernel starts executing C code here. Before entring this function, some
Expand All @@ -19,7 +20,10 @@ void c_entry(void)
KERNEL_BASE + TOTAL_MEMORY_SIZE);
scheduler_init();

/* start the kernel monitor, which should run forever */
monitor();

/* start the first program */
{
struct Process *proc = proc_create();
proc_load_program(proc, 0);
schedule();
}
}
18 changes: 18 additions & 0 deletions kernel/proc/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@
#include <monitor.h>
#include <system.h>
#include <klib.h>
#include <timer.h>
#include <vm.h>
#include <irq.h>

static int round_robin_index;

void handle_timer(void)
{
//schedule();
kprintf("timer\n");
timer_clear_interrupt();
schedule();
}

void scheduler_init(void)
{
round_robin_index = 0;
timer_set_interval(100000);
register_interrupt_handler(0x5, handle_timer);
}

void schedule(void)
{
int i;
kprintf("schedule \n");
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);
Expand Down
7 changes: 5 additions & 2 deletions user/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ USER_CFLAGS = -mcpu=arm1176jz-s -marm -g0 \
-Iinclude

OBJS += user/user_programs.o
USER_PROGRAMS = user/hello user/fork_test user/exec_test \
user/concurrency_test
USER_PROGRAMS = user/shell \
user/hello \
user/fork_test \
user/exec_test \
user/concurrency_test
EXTRA_CLEAN += $(USER_PROGRAMS) user/base16 user/user_programs.c

user/%: user/%.c lib/libarunos.a
Expand Down
18 changes: 18 additions & 0 deletions user/shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <lib/stdio.h>
#include <lib/syscall.h>

void _start()
{
int i = 0, j = 0;
fork();
//fork();

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

exit(0);
}

0 comments on commit d62fae4

Please sign in to comment.