init commit of lab3_2
This commit is contained in:
parent
24cbe04af7
commit
22309fdb73
2
Makefile
2
Makefile
|
@ -70,7 +70,7 @@ USER_OBJS := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(USER_CPPS)))
|
|||
|
||||
|
||||
|
||||
USER_TARGET := $(OBJ_DIR)/app_naive_fork
|
||||
USER_TARGET := $(OBJ_DIR)/app_yield
|
||||
#------------------------targets------------------------
|
||||
$(OBJ_DIR):
|
||||
@-mkdir -p $(OBJ_DIR)
|
||||
|
|
|
@ -68,6 +68,19 @@ ssize_t sys_user_fork() {
|
|||
return do_fork( current );
|
||||
}
|
||||
|
||||
//
|
||||
// kerenl entry point of yield
|
||||
//
|
||||
ssize_t sys_user_yield() {
|
||||
// TODO (lab3_2): implment the syscall of yield.
|
||||
// hint: the functionality of yield is to give up the processor. therefore,
|
||||
// we should set the status of currently running process to READY, insert it in
|
||||
// the rear of ready queue, and finally, schedule a READY process to run.
|
||||
panic( "You need to implement the yield syscall in lab3_2.\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// [a0]: the syscall number; [a1] ... [a7]: arguments to the syscalls.
|
||||
// returns the code of success, (e.g., 0 means success, fail for otherwise)
|
||||
|
@ -84,6 +97,8 @@ long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, long a6, l
|
|||
return sys_user_free_page(a1);
|
||||
case SYS_user_fork:
|
||||
return sys_user_fork();
|
||||
case SYS_user_yield:
|
||||
return sys_user_yield();
|
||||
default:
|
||||
panic("Unknown syscall %ld \n", a0);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#define SYS_user_allocate_page (SYS_user_base + 2)
|
||||
#define SYS_user_free_page (SYS_user_base + 3)
|
||||
#define SYS_user_fork (SYS_user_base + 4)
|
||||
#define SYS_user_yield (SYS_user_base + 5)
|
||||
|
||||
long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7);
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* The application of lab3_1.
|
||||
* it simply forks a child process.
|
||||
*/
|
||||
|
||||
#include "user/user_lib.h"
|
||||
#include "util/types.h"
|
||||
|
||||
int main(void) {
|
||||
uint64 pid = fork();
|
||||
if (pid == 0) {
|
||||
printu("Child: Hello world!\n");
|
||||
} else {
|
||||
printu("Parent: Hello world! child id %ld\n", pid);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* The application of lab3_2.
|
||||
* parent and child processes intermittently give up their processors.
|
||||
*/
|
||||
|
||||
#include "user/user_lib.h"
|
||||
#include "util/types.h"
|
||||
|
||||
int main(void) {
|
||||
uint64 pid = fork();
|
||||
uint64 rounds = 0xffff;
|
||||
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();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printu("Parent: Hello world! \n");
|
||||
for (uint64 i = 0; i < rounds; ++i) {
|
||||
if (i % 10000 == 0) {
|
||||
printu("Parent running %ld \n", i);
|
||||
yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
|
@ -69,3 +69,10 @@ void naive_free(void* va) {
|
|||
int fork() {
|
||||
return do_user_call(SYS_user_fork, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
//
|
||||
// lib call to yield
|
||||
//
|
||||
void yield() {
|
||||
do_user_call(SYS_user_yield, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
|
|
@ -7,3 +7,4 @@ int exit(int code);
|
|||
void* naive_malloc();
|
||||
void naive_free(void* va);
|
||||
int fork();
|
||||
void yield();
|
||||
|
|
Loading…
Reference in New Issue