Skip to content

Commit

Permalink
✨ Add : SystemCall All Pass #15
Browse files Browse the repository at this point in the history
  • Loading branch information
chwangmin committed Jun 10, 2023
1 parent 4f49764 commit 366b1a9
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 27 deletions.
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Created by https://www.toptal.com/developers/gitignore/api/c
# Edit at https://www.toptal.com/developers/gitignore?templates=c

### C ###
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# git_ignore
*.bin

# End of https://www.toptal.com/developers/gitignore/api/c
2 changes: 1 addition & 1 deletion include/threads/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define LOADER_BASE 0x7c00 /* Physical address of loader's base. */
#define LOADER_END 0x7e00 /* Physical address of end of loader. */

/* Physical address of kernel base. */
/* Virtual address of kernel base. */
#define LOADER_KERN_BASE 0x8004000000

/* Kernel virtual address at which all physical memory is mapped. */
Expand Down
26 changes: 26 additions & 0 deletions include/threads/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <list.h>
#include <stdint.h>
#include "threads/interrupt.h"
#include "threads/synch.h" // 이것을 추가해야 포인터를 쓸 수 있습니다.
#ifdef VM
#include "vm/vm.h"
#endif
Expand All @@ -28,6 +29,9 @@ typedef int tid_t;
#define PRI_DEFAULT 31 /* Default priority. */
#define PRI_MAX 63 /* Highest priority. */

#define FDT_PAGES 2
#define FDT_COUNT_LIMIT 128

/* A kernel thread or user process.
*
* Each thread structure is stored in its own 4 kB page. The
Expand Down Expand Up @@ -94,12 +98,28 @@ struct thread {
int64_t wakeup_tick; /* 해당 쓰레드가 깨어나야 할 tick을 저장할 필드 */
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */

/*priority donation 관련 항목 추가*/
int init_priority; /* donation 이후 우선순위를 초기화하기 위해 초기값 저장 */
struct lock *wait_on_lock; /* 해당 스레드가 대기 하고 있는 lock자료구조의 주소를 저장 */
struct list donations; /* multiple donation 을 고려하기 위해 사용 */
struct list_elem donation_elem; /* multiple donation 을 고려하기 위해 사용 */

/*project 2 - SystemCall 항목 추가*/
int exit_status; /* exit 호출 시 종료 status */
struct file **fdt; /* 부모 프로세스의 디스크립터 */
int next_fd; /* 다음 디스크립트를 가리키는 테이블 번호 */

struct intr_frame parent_if; /* 프로세스 프로그램 메모리 적재 */
struct list child_list; /* 자식 리스트 */
struct list_elem child_elem; /* 자식 리스트 element */

struct semaphore load_sema; /* load 세마포어 */
struct semaphore exit_sema; /* exit 세마포어 */
struct semaphore wait_sema; /* wait 세마포어 */

struct file *running; // 현재 실행중인 파일

#ifdef USERPROG
/* Owned by userprog/process.c. */
uint64_t *pml4; /* Page map level 4 */
Expand Down Expand Up @@ -155,6 +175,10 @@ int64_t get_next_tick_to_awake(void);

void test_max_priority(void);
bool cmp_priority(const struct list_elem *a, const struct list_elem *b, void *aux UNUSED);
// project2
bool cmp_thread_priority(const struct list_elem *a, const struct list_elem *b, void *aux);
bool cmp_thread_ticks(const struct list_elem *a, const struct list_elem *b, void *aux);
// ---

void donate_priority(void);
void remove_with_lock(struct lock *lock);
Expand All @@ -163,4 +187,6 @@ void refresh_priority(void);
bool
thread_compare_donate_priority(const struct list_elem *x, const struct list_elem *y, void *aux UNUSED);

void preempt_priority(void);

#endif /* threads/thread.h */
8 changes: 7 additions & 1 deletion include/userprog/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ int process_exec (void *f_name);
int process_wait (tid_t);
void process_exit (void);
void process_activate (struct thread *next);

/* project 2 */
void argument_stack(char **argv, int argc, void **rsp);
struct thread *get_child_process(int pid);
int process_add_file(struct file *f);
struct file *process_get_file(int fd);
void process_close_file(int fd);
struct thread *get_child_process(int pid);
#endif /* userprog/process.h */
3 changes: 2 additions & 1 deletion include/userprog/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define USERPROG_SYSCALL_H

void syscall_init (void);
struct lock filesys_lock;

#endif /* userprog/syscall.h */
#endif /* userprog/syscall.h */
1 change: 1 addition & 0 deletions lib/user/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
int main (int, char *[]);
void _start (int argc, char *argv[]);

// user program의 진입점이다.
void
_start (int argc, char *argv[]) {
exit (main (argc, argv));
Expand Down
Binary file added output/test
Binary file not shown.
36 changes: 29 additions & 7 deletions threads/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,33 @@ tid_t thread_create(const char *name, int priority,
t->tf.cs = SEL_KCSEG;
t->tf.eflags = FLAG_IF;

/* 현재 스레드의 자식으로 추가 */
list_push_back(&thread_current()->child_list, &t->child_elem);

/* File Descriptor 테이블 메모리 할당 */
t->fdt = palloc_get_multiple(PAL_ZERO, FDT_PAGES);
if (t->fdt == NULL) // 메모리 할당 실패시 에러 리턴.
return TID_ERROR; // -1

/* Add to run queue. */
thread_unblock(t);
preempt_priority();

return tid;
}

/* 현재 실행중인 thread와 우선순위를 비교하여, 새로 생성된
thread의 우선순위가 높다면 thread_yield()를 통해 CPU를 양보 */
/* 현재 실행중인 thread와 우선순위를 비교하여, 새로 생성된
thread의 우선순위가 높다면 thread_yield()를 통해 CPU를 양보 */
void preempt_priority(void)
{
if (thread_current() == idle_thread)
return;
if (list_empty(&ready_list))
return;
struct thread *curr = thread_current();
if (t->priority > curr->priority)
{
struct thread *ready = list_entry(list_front(&ready_list), struct thread, elem);
if (curr->priority < ready->priority) // ready_list에 현재 실행중인 스레드보다 우선순위가 높은 스레드가 있으면
thread_yield();
}

return tid;
}

/* Puts the current thread to sleep. It will not be scheduled
Expand Down Expand Up @@ -441,6 +456,13 @@ init_thread(struct thread *t, const char *name, int priority)
t->init_priority = priority; // 초기 중요도 값 설정
t->wait_on_lock = NULL; // 기다리는 락은 NULL로 설정
list_init(&t->donations); // 스레드의 donations를 초기화

t->exit_status = 0; /* exit status 는 0으로 초기화 */
t->next_fd = 2; /* next_fd 는 2로 초기화 (0 - 표준 입력, 1 - 표춘출력) */
sema_init(&t->load_sema, 0); /* load의 세마 초기화 */
sema_init(&t->exit_sema, 0); /* exit의 세마 초기화 */
sema_init(&t->wait_sema, 0); /* wait의 세마 초기화 */
list_init(&(t->child_list)); /* child_list를 초기화(head,tail 지정) */
}

/* Chooses and returns the next thread to be scheduled. Should
Expand Down
2 changes: 1 addition & 1 deletion userprog/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ page_fault (struct intr_frame *f) {
be assured of reading CR2 before it changed). */
intr_enable ();


/* Determine cause. */
not_present = (f->error_code & PF_P) == 0;
write = (f->error_code & PF_W) != 0;
user = (f->error_code & PF_U) != 0;
exit(-1);

#ifdef VM
/* For project 3 and later. */
Expand Down
Loading

0 comments on commit 366b1a9

Please sign in to comment.