Skip to content

Commit

Permalink
Project3 out
Browse files Browse the repository at this point in the history
  • Loading branch information
hestati63 committed May 7, 2020
1 parent 8906e08 commit b74dcd6
Show file tree
Hide file tree
Showing 139 changed files with 3,695 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BUILD_SUBDIRS = threads userprog filesys
BUILD_SUBDIRS = threads userprog vm filesys
TAR_PATH := team${TEAM}.tar.gz

all::
Expand Down Expand Up @@ -36,5 +36,5 @@ ifeq ($(shell echo ${TEAM} | egrep "^[1-9]{1}[0-9]{0,2}$$"),)
else
@tar -zcf /tmp/${TAR_PATH} . && \
mv /tmp/${TAR_PATH} . && \
echo "Successfully arhived. Submit '${TAR_PATH}'."
echo "Successfully archived. Submit '${TAR_PATH}'."
endif
2 changes: 1 addition & 1 deletion Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include ../../threads/targets.mk
# User process code.
include ../../userprog/targets.mk
# Virtual memory code.
# include ../../vm/targets.mk
include ../../vm/targets.mk
# Filesystem code.
include ../../filesys/targets.mk
# Library code shared between kernel and user programs.
Expand Down
3 changes: 2 additions & 1 deletion filesys/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ../Makefile.kernel
all grade check:
@echo "project 4 is not ready. Wait for the announcement."
10 changes: 9 additions & 1 deletion include/lib/user/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef int pid_t;

/* Map region identifier. */
typedef int off_t;
#define MAP_FAILED ((mapid_t) -1)
#define MAP_FAILED ((void *) NULL)

/* Maximum characters in a filename written by readdir(). */
#define READDIR_MAX_LEN 14
Expand Down Expand Up @@ -49,4 +49,12 @@ bool readdir (int fd, char name[READDIR_MAX_LEN + 1]);
bool isdir (int fd);
int inumber (int fd);

static inline void* get_phys_addr (void *user_addr) {
void* pa;
asm volatile ("movq %0, %%rax" ::"r"(user_addr));
asm volatile ("int $0x42");
asm volatile ("\t movq %%rax, %0": "=r" (pa));
return pa;
}

#endif /* lib/user/syscall.h */
13 changes: 13 additions & 0 deletions include/vm/anon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef VM_ANON_H
#define VM_ANON_H
#include "vm/vm.h"
struct page;
enum vm_type;

struct anon_page {
};

void vm_anon_init (void);
bool anon_initializer (struct page *page, enum vm_type type, void *kva);

#endif
17 changes: 17 additions & 0 deletions include/vm/file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef VM_FILE_H
#define VM_FILE_H
#include "filesys/file.h"
#include "vm/vm.h"

struct page;
enum vm_type;

struct file_page {
};

void vm_file_init (void);
bool file_map_initializer (struct page *page, enum vm_type type, void *kva);
void *do_mmap(void *addr, size_t length, int writable,
struct file *file, off_t offset);
void do_munmap (void *va);
#endif
4 changes: 4 additions & 0 deletions include/vm/inspect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _VM_INSPECT_H_
#define _VM_INSPECT_H_
void register_inspect_intr (void);
#endif
24 changes: 24 additions & 0 deletions include/vm/uninit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef VM_UNINIT_H
#define VM_UNINIT_H
#include "vm/vm.h"

struct page;
enum vm_type;

typedef bool vm_initializer (struct page *, void *aux);

/* Uninitlialized page. The type for implementing the
* "Lazy loading". */
struct uninit_page {
/* Initiate the contets of the page */
vm_initializer *init;
enum vm_type type;
void *aux;
/* Initiate the struct page and maps the pa to the va */
bool (*page_initializer) (struct page *, enum vm_type, void *kva);
};

void uninit_new (struct page *page, void *va, vm_initializer *init,
enum vm_type type, void *aux,
bool (*initializer)(struct page *, enum vm_type, void *kva));
#endif
109 changes: 109 additions & 0 deletions include/vm/vm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#ifndef VM_VM_H
#define VM_VM_H
#include <stdbool.h>
#include "threads/palloc.h"

enum vm_type {
/* page not initialized */
VM_UNINIT = 0,
/* page not related to the file, aka anonymous page */
VM_ANON = 1,
/* page that realated to the file */
VM_FILE = 2,
/* page that hold the page cache, for project 4 */
VM_PAGE_CACHE = 3,

/* Bit flags to store state */

/* Auxillary bit flag marker for store information. You can add more
* markers, until the value is fit in the int. */
VM_MARKER_0 = (1 << 3),
VM_MARKER_1 = (1 << 4),

/* DO NOT EXCEED THIS VALUE. */
VM_MARKER_END = (1 << 31),
};

#include "vm/uninit.h"
#include "vm/anon.h"
#include "vm/file.h"

struct page_operations;
struct thread;

#define VM_TYPE(type) ((type) & 7)

/* The representation of "page".
* This is kind of "parent class", which has four "child class"es, which are
* uninit_page, file_page, anon_page, and page cache (project4).
* DO NOT REMOVE/MODIFY PREDEFINED MEMBER OF THIS STRUCTURE. */
struct page {
const struct page_operations *operations;
void *va; /* Address in terms of user space */
struct frame *frame; /* Back reference for frame */

/* Your implementation */

/* Per-type data are binded into the union.
* Each function automatically detects the current union */
union {
struct uninit_page uninit;
struct anon_page anon;
struct file_page file;
#ifdef EFILESYS
struct page_cache page_cache;
#endif
};
};

/* The representation of "frame" */
struct frame {
void *kva;
struct page *page;
};

/* The function table for page operations.
* This is one way of implementing "interface" in C.
* Put the table of "method" into the struct's member, and
* call it whenever you needed. */
struct page_operations {
bool (*swap_in) (struct page *, void *);
bool (*swap_out) (struct page *);
void (*destroy) (struct page *);
enum vm_type type;
};

#define swap_in(page, v) (page)->operations->swap_in ((page), v)
#define swap_out(page) (page)->operations->swap_out (page)
#define destroy(page) \
if ((page)->operations->destroy) (page)->operations->destroy (page)

/* Representation of current process's memory space.
* We don't want to force you to obey any specific design for this struct.
* All designs up to you for this. */
struct supplemental_page_table {
};

#include "threads/thread.h"
void supplemental_page_table_init (struct supplemental_page_table *spt);
bool supplemental_page_table_copy (struct supplemental_page_table *dst,
struct supplemental_page_table *src);
void supplemental_page_table_kill (struct supplemental_page_table *spt);
struct page *spt_find_page (struct supplemental_page_table *spt,
void *va);
bool spt_insert_page (struct supplemental_page_table *spt, struct page *page);
void spt_remove_page (struct supplemental_page_table *spt, struct page *page);

void vm_init (void);
bool vm_try_handle_fault (struct intr_frame *f, void *addr, bool user,
bool write, bool not_present);

#define vm_alloc_page(type, upage, writable) \
vm_alloc_page_with_initializer ((type), (upage), (writable), NULL, NULL)
bool vm_alloc_page_with_initializer (enum vm_type type, void *upage,
bool writable, vm_initializer *init, void *aux);
void vm_dealloc_page (struct page *page);
bool vm_claim_page (void *va);
enum vm_type page_get_type (struct page *page);

#endif /* VM_VM_H */
6 changes: 4 additions & 2 deletions tests/Make.tests
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ include ../../Makefile.userprog
endif

TIMEOUT = 60
MEMORY = 20
SWAP_DISK = 4

clean::
rm -f $(OUTPUTS) $(ERRORS) $(RESULTS)
Expand Down Expand Up @@ -51,15 +53,15 @@ $(foreach test,$(TESTS),$(eval $(test).output: TEST = $(test)))
# Prevent an environment variable VERBOSE from surprising us.
VERBOSE =

TESTCMD = pintos -v -k -T $(TIMEOUT)
TESTCMD = pintos -v -k -T $(TIMEOUT) -m $(MEMORY)
TESTCMD += $(SIMULATOR)
TESTCMD += $(PINTOSOPTS)
ifeq ($(filter userprog, $(KERNEL_SUBDIRS)), userprog)
TESTCMD += --fs-disk=$(FSDISK)
TESTCMD += $(foreach file,$(PUTFILES),-p $(file):$(notdir $(file)))
endif
ifeq ($(filter vm, $(KERNEL_SUBDIRS)), vm)
TESTCMD += --swap-disk=4
TESTCMD += --swap-disk=$(SWAP_DISK)
endif
TESTCMD += -- -q
TESTCMD += $(KERNELFLAGS)
Expand Down
1 change: 0 additions & 1 deletion tests/userprog/child-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "tests/lib.h"

const char *test_name = "child-simple";

int
main (void)
{
Expand Down
17 changes: 17 additions & 0 deletions tests/vm/Grading
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Percentage of the testing point total designated for each set of
# tests.

# This project is primarily about virtual memory, but all the previous
# functionality should work too

1% tests/threads/Rubric.alarm
1% tests/threads/Rubric.priority
8% tests/userprog/Rubric.functionality
5% tests/userprog/Rubric.robustness

55% tests/vm/Rubric.functionality
25% tests/vm/Rubric.robustness
5% tests/filesys/base/Rubric

# Extra project
25% tests/vm/cow/Rubric
17 changes: 17 additions & 0 deletions tests/vm/Grading.extra
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Percentage of the testing point total designated for each set of
# tests.

# This project is primarily about virtual memory, but all the previous
# functionality should work too

2% tests/threads/Rubric.alarm
3% tests/threads/Rubric.priority
2% tests/userprog/Rubric.functionality
3% tests/userprog/Rubric.robustness

50% tests/vm/Rubric.functionality
20% tests/vm/Rubric.robustness
20% tests/filesys/base/Rubric

# Extra project
10% tests/vm/cow/Rubric
Loading

0 comments on commit b74dcd6

Please sign in to comment.