Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0915ead
alarm clock with inter_disable
Nov 13, 2022
64ec676
alarm clock with intru_disable
Nov 13, 2022
664730e
proj1.Alarm
Nov 13, 2022
7aae391
priority alarm
Nov 14, 2022
839013a
proj1_1 alarm_clock
Nov 14, 2022
e883fb9
priority change
Nov 14, 2022
eaab2b7
alarm-priority implemented
Nov 15, 2022
d8ddd3c
priority_change,fifo,preempt,sema
Nov 15, 2022
d05f273
priority_donate_one
Nov 15, 2022
9957aae
before priority_hy
Nov 15, 2022
d54aa29
priority_part1(fifo, preempt,change)
Nov 15, 2022
117ebf2
alarm_priority
Nov 15, 2022
33e2e89
priority_condvar
Nov 16, 2022
b225640
priority scheduling
Nov 16, 2022
7e901d5
refactoring priority scheduling
Nov 16, 2022
b5fc289
argument passing part3
Nov 20, 2022
f508192
argument parsing and passing
Nov 21, 2022
6760989
exit syscall
Nov 21, 2022
5584a29
exit syscall
Nov 21, 2022
71cb245
open syscall
Nov 21, 2022
3a055f8
syscall_create,open,close
Nov 22, 2022
c9a10f2
bad testcases
Nov 22, 2022
a933912
read syscall
Nov 22, 2022
02e6ea0
write syscall
Nov 23, 2022
fc379fe
rox simlpe
Nov 23, 2022
b28576a
fork ing
Nov 24, 2022
7a34530
fork once
Nov 25, 2022
9af1781
fork wo recursive
Nov 25, 2022
04fa0f7
fork w/recursive
Nov 25, 2022
e7d85b9
wait syscall
Nov 25, 2022
465f5df
rox syscall
Nov 26, 2022
0afab21
last busy waiting version(only multi-oom failed)
Nov 26, 2022
acf37d3
change into sleepNwake
Nov 26, 2022
be10193
narin maybe
Nov 28, 2022
c876b68
project2. finished
Nov 28, 2022
ebab9ab
project 02
Nov 29, 2022
9b0045f
Update process.c
jnl1128 Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": [
{
"type": "gdb",
"request": "attach",
"name": "Attach to gdbserver",
"executable": "${fileDirname}/build/kernel.o",
"target": "localhost:1234",
"remote": true,
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
}
30 changes: 30 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"files.associations": {
"list.h": "c",
"synch.h": "c",
"syscall.h": "c",
"thread.h": "c",
"*.inc": "c",
"interrupt.h": "c",
"debug.h": "c",
"process.h": "c",
"stdint.h": "c",
"file.h": "c",
"init.h": "c",
"filesys.h": "c",
"inode.h": "c",
"directory.h": "c",
"types.h": "c",
"stat.h": "c",
"off_t.h": "c",
"fcntl.h": "c",
"intr-stubs.h": "c",
"intrinsic.h": "c",
"stdio.h": "c",
"syscall-nr.h": "c",
"stdbool.h": "c",
"malloc.h": "c",
"vaddr.h": "c",
"vm.h": "c"
}
}
18 changes: 13 additions & 5 deletions devices/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ timer_elapsed (int64_t then) {
}

/* Suspends execution for approximately TICKS timer ticks. */
void
timer_sleep (int64_t ticks) {
void timer_sleep (int64_t ticks) {
int64_t start = timer_ticks ();

ASSERT (intr_get_level () == INTR_ON);
while (timer_elapsed (start) < ticks)
thread_yield ();

// ASSERT (intr_get_level () == INTR_ON);
// while (timer_elapsed (start) < ticks)
// thread_yield ();
if (ticks > 0)
thread_sleep(ticks + start);
else if (ticks == 0)
thread_yield();
else
return;
}

/* Suspends execution for approximately MS milliseconds. */
Expand Down Expand Up @@ -126,6 +132,8 @@ static void
timer_interrupt (struct intr_frame *args UNUSED) {
ticks++;
thread_tick ();
if (ticks >= get_next_tick_to_awake())
thread_awake(ticks);
}

/* Returns true if LOOPS iterations waits for more than one timer
Expand Down
12 changes: 6 additions & 6 deletions filesys/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include "filesys/inode.h"
#include "threads/malloc.h"

/* An open file. */
struct file {
struct inode *inode; /* File's inode. */
off_t pos; /* Current position. */
bool deny_write; /* Has file_deny_write() been called? */
};
// /* An open file. */
// struct file {
// struct inode *inode; /* File's inode. */
// off_t pos; /* Current position. */
// bool deny_write; /* Has file_deny_write() been called? */
// };

/* Opens a file for the given INODE, of which it takes ownership,
* and returns the new file. Returns a null pointer if an
Expand Down
28 changes: 14 additions & 14 deletions filesys/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

/* On-disk inode.
* Must be exactly DISK_SECTOR_SIZE bytes long. */
struct inode_disk {
disk_sector_t start; /* First data sector. */
off_t length; /* File size in bytes. */
unsigned magic; /* Magic number. */
uint32_t unused[125]; /* Not used. */
};
// struct inode_disk {
// disk_sector_t start; /* First data sector. */
// off_t length; /* File size in bytes. */
// unsigned magic; /* Magic number. */
// uint32_t unused[125]; /* Not used. */
// };

/* Returns the number of sectors to allocate for an inode SIZE
* bytes long. */
Expand All @@ -27,14 +27,14 @@ bytes_to_sectors (off_t size) {
}

/* In-memory inode. */
struct inode {
struct list_elem elem; /* Element in inode list. */
disk_sector_t sector; /* Sector number of disk location. */
int open_cnt; /* Number of openers. */
bool removed; /* True if deleted, false otherwise. */
int deny_write_cnt; /* 0: writes ok, >0: deny writes. */
struct inode_disk data; /* Inode content. */
};
// struct inode {
// struct list_elem elem; /* Element in inode list. */
// disk_sector_t sector; /* Sector number of disk location. */
// int open_cnt; /* Number of openers. */
// bool removed; /* True if deleted, false otherwise. */
// int deny_write_cnt; /* 0: writes ok, >0: deny writes. */
// struct inode_disk data; /* Inode content. */
// };

/* Returns the disk sector that contains byte offset POS within
* INODE.
Expand Down
8 changes: 8 additions & 0 deletions include/filesys/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
#define FILESYS_FILE_H

#include "filesys/off_t.h"
#include "filesys/inode.h"

struct inode;

/* An open file. */
struct file {
struct inode *inode; /* File's inode. */
off_t pos; /* Current position. */
bool deny_write; /* Has file_deny_write() been called? */
};

/* Opening and closing files. */
struct file *file_open (struct inode *);
struct file *file_reopen (struct file *);
Expand Down
21 changes: 21 additions & 0 deletions include/filesys/inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
#include <stdbool.h>
#include "filesys/off_t.h"
#include "devices/disk.h"
#include "kernel/list.h"

struct bitmap;

/* On-disk inode.
* Must be exactly DISK_SECTOR_SIZE bytes long. */
struct inode_disk {
disk_sector_t start; /* First data sector. */
off_t length; /* File size in bytes. */
unsigned magic; /* Magic number. */
uint32_t unused[125]; /* Not used. */
};

/* In-memory inode. */
struct inode {
struct list_elem elem; /* Element in inode list. */
disk_sector_t sector; /* Sector number of disk location. */
int open_cnt; /* Number of openers. */
bool removed; /* True if deleted, false otherwise. */
int deny_write_cnt; /* 0: writes ok, >0: deny writes. */
struct inode_disk data; /* Inode content. */
};


void inode_init (void);
bool inode_create (disk_sector_t, off_t);
struct inode *inode_open (disk_sector_t);
Expand Down
4 changes: 3 additions & 1 deletion include/threads/synch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct semaphore {
struct list waiters; /* List of waiting threads. */
};

void sema_init (struct semaphore *, unsigned value);
void sema_init(struct semaphore *, unsigned value);
void sema_down (struct semaphore *);
bool sema_try_down (struct semaphore *);
void sema_up (struct semaphore *);
Expand Down Expand Up @@ -38,6 +38,8 @@ void cond_wait (struct condition *, struct lock *);
void cond_signal (struct condition *, struct lock *);
void cond_broadcast (struct condition *, struct lock *);

bool cmp_sem_priority(const struct list_elem *a, const struct list_elem *b, void *aux);

/* Optimization barrier.
*
* The compiler will not reorder operations across an
Expand Down
52 changes: 48 additions & 4 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,10 @@ typedef int tid_t;
#define PRI_DEFAULT 31 /* Default priority. */
#define PRI_MAX 63 /* Highest priority. */

#define ERROR_EXIT2 -2
#define FDBASE 2
#define FDLIMIT 32

/* A kernel thread or user process.
*
* Each thread structure is stored in its own 4 kB page. The
Expand Down Expand Up @@ -85,15 +90,36 @@ typedef int tid_t;
* only because they are mutually exclusive: only a thread in the
* ready state is on the run queue, whereas only a thread in the
* blocked state is on a semaphore wait list. */
struct thread {

struct child_info{
bool finished;
tid_t c_tid;
int c_exit_code;
struct list_elem c_elem;
struct semaphore c_sema;
};

struct thread
{
/* Owned by thread.c. */
tid_t tid; /* Thread identifier. */
enum thread_status status; /* Thread state. */
enum thread_status status; /* Thread state. 4가지 : ready, blocked, running, dying*/
char name[16]; /* Name (for debugging purposes). */
int my_exit_code;
int priority; /* Priority. */

/* Shared between thread.c and synch.c. */
int init_priority;

bool do_fork_error;
int64_t wakeup_tick; /* Shared between thread.c and synch.c. */
struct lock* wait_on_lock;
struct thread *my_parent;
struct file *my_file;
struct child_info *my_info;
struct file* fd_table[FDLIMIT]; /* file descriptor(fd) table */
struct list_elem donation_elem;
struct list_elem elem; /* List element. */
struct list child_list;
struct list donations;

#ifdef USERPROG
/* Owned by userprog/process.c. */
Expand Down Expand Up @@ -143,4 +169,22 @@ int thread_get_load_avg (void);

void do_iret (struct intr_frame *tf);

void thread_sleep(int64_t ticks);
void thread_awake(int64_t ticks);
void update_next_tick_to_awake(int64_t ticks);
int64_t get_next_tick_to_awake(void);

char is_readylist_empty(void);
int get_ready_list_max_priority(void);
int destruction_req_contains(tid_t child_tid);

void test_max_priority(void);
bool cmp_priority(const struct list_elem *a_, const struct list_elem *b_,
void *aux UNUSED);
bool donate_cmp_priority(const struct list_elem *a_, const struct list_elem *b_,
void *aux UNUSED);

void donate_priority(void);
void remove_with_lock(struct lock *lock);
void refresh_priority(void);
#endif /* threads/thread.h */
2 changes: 2 additions & 0 deletions include/userprog/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "threads/thread.h"

/* ELF types. See [ELF1] 1-2. */

tid_t process_create_initd (const char *file_name);
tid_t process_fork (const char *name, struct intr_frame *if_);
int process_exec (void *f_name);
Expand Down
1 change: 1 addition & 0 deletions 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 */
2 changes: 2 additions & 0 deletions lib/user/syscall.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <syscall.h>
#include <stdint.h>
#include "../syscall-nr.h"
#include "include/lib/stdbool.h"
#include "include/lib/user/syscall.h"

__attribute__((always_inline))
static __inline int64_t syscall (uint64_t num_, uint64_t a1_, uint64_t a2_,
Expand Down
2 changes: 1 addition & 1 deletion tests/userprog/fork-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fork_and_wait (void){

if (magic >= 10){
exit(magic);
}
}

if ((pid = fork("child"))){
magic++;
Expand Down
14 changes: 7 additions & 7 deletions tests/userprog/no-vm/multi-oom.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ consume_some_resources (void)
break;
}
#else
if (open (test_name) == -1)
break;
if (open(test_name) == -1)
break;
#endif
}
}
Expand Down Expand Up @@ -107,8 +107,9 @@ make_children (void) {
int pid;
char child_name[128];
for (; ; random_init (i), i++) {
if (i > EXPECTED_DEPTH_TO_PASS/2) {
snprintf (child_name, sizeof child_name, "%s_%d_%s", "child", i, "X");
if (i > EXPECTED_DEPTH_TO_PASS / 2)
{
snprintf(child_name, sizeof child_name, "%s_%d_%s", "child", i, "X");
pid = fork(child_name);
if (pid > 0 && wait (pid) != -1) {
fail ("crashed child should return -1.");
Expand All @@ -121,7 +122,7 @@ make_children (void) {
snprintf (child_name, sizeof child_name, "%s_%d_%s", "child", i, "O");
pid = fork(child_name);
if (pid < 0) {
exit (i);
exit(i);
} else if (pid == 0) {
consume_some_resources();
} else {
Expand All @@ -142,8 +143,7 @@ make_children (void) {
int
main (int argc UNUSED, char *argv[] UNUSED) {
msg ("begin");

int first_run_depth = make_children ();
int first_run_depth = make_children();
CHECK (first_run_depth >= EXPECTED_DEPTH_TO_PASS, "Spawned at least %d children.", EXPECTED_DEPTH_TO_PASS);

for (int i = 0; i < EXPECTED_REPETITIONS; i++) {
Expand Down
3 changes: 1 addition & 2 deletions threads/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ main (void) {
}

/* Clear BSS */
static void
bss_init (void) {
static void bss_init (void) {
/* The "BSS" is a segment that should be initialized to zeros.
It isn't actually stored on disk or zeroed by the kernel
loader, so we have to zero it ourselves.
Expand Down
Loading