init commit of lab3_3

lab3_3_rrsched
Zhiyuan Shao 2 years ago
parent d75447ab6d
commit 448d994bba

@ -70,7 +70,7 @@ USER_OBJS := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(USER_CPPS)))
USER_TARGET := $(OBJ_DIR)/app_yield
USER_TARGET := $(OBJ_DIR)/app_two_long_loops
#------------------------targets------------------------
$(OBJ_DIR):
@-mkdir -p $(OBJ_DIR)

@ -86,6 +86,9 @@ typedef struct process_t {
struct process_t *parent;
// next queue element
struct process_t *queue_next;
// accounting. added @lab3_3
int tick_count;
}process;
// switch to run user app

@ -67,6 +67,18 @@ void handle_user_page_fault(uint64 mcause, uint64 sepc, uint64 stval) {
}
}
//
// implements round-robin scheduling. added @lab3_3
//
void rrsched() {
// TODO (lab3_3): implements round-robin scheduling.
// hint: increase the tick_count member of current process by one, if it is bigger than
// TIME_SLICE_LEN (means it has consumed its time slice), change its status into READY,
// place it in the rear of ready queue, and finally schedule next process to run.
panic( "You need to further implement the timer handling in lab3_3.\n" );
}
//
// kernel/smode_trap.S will pass control to smode_trap_handler, when a trap happens
// in S-mode.
@ -91,6 +103,8 @@ void smode_trap_handler(void) {
break;
case CAUSE_MTIMER_S_TRAP:
handle_mtimer_trap();
// invoke round-robin scheduler. added @lab3_3
rrsched();
break;
case CAUSE_STORE_PAGE_FAULT:
case CAUSE_LOAD_PAGE_FAULT:

@ -1,6 +1,6 @@
/*
* The application of lab3_2.
* parent and child processes intermittently give up their processors.
* The application of lab3_3.
* parent and child processes never give up their processor during execution.
*/
#include "user/user_lib.h"
@ -8,22 +8,18 @@
int main(void) {
uint64 pid = fork();
uint64 rounds = 0xffff;
uint64 rounds = 100000000;
uint64 interval = 10000000;
uint64 a = 0;
if (pid == 0) {
printu("Child: Hello world! \n");
for (uint64 i = 0; i < rounds; ++i) {
if (i % 10000 == 0) {
printu("Child running %ld \n", i);
yield();
}
if (i % interval == 0) printu("Child running %ld \n", i);
}
} else {
printu("Parent: Hello world! \n");
for (uint64 i = 0; i < rounds; ++i) {
if (i % 10000 == 0) {
printu("Parent running %ld \n", i);
yield();
}
if (i % interval == 0) printu("Parent running %ld \n", i);
}
}
Loading…
Cancel
Save