pintOS project2: User Programs (KAIST.ver)

Ethereal·2021년 10월 4일
0

pintOS

목록 보기
7/9

https://casys-kaist.github.io/pintos-kaist/project2/introduction.html
https://web.stanford.edu/class/cs140/projects/pintos/pintos_3.html#SEC32

📖개요

이제는 OS에서 user의 program 이 실행될 수 있게 해주는 시스템을 작성합니다. 한 개 이상의 프로세스가 실행되는 환경에서 메모리, scheduling, 등등을 올바르게 작동시켜 여러 프로세스가 한번에 실행되는 illusion을 유지시켜야합니다. 프로세스는 단 하나의 thread만을 가집니다. (multi-thread process는 지원하지 않습니다.)

project1의 테스트 코드는 kernel 자체를 조작하였지만, 이번에는 user program이 실행되는 식으로 작동합니다. user program interface들을 요구된 대로 구현해야합니다. (You must make sure that the user program interface meets the specifications described here)

예상되는 코드 수정:

src/include/threads/thread.h   |  23 ++
src/include/userprog/syscall.h |   3 +
src/threads/thread.c           |   5 +
src/userprog/exception.c       |   4 +
src/userprog/process.c         | 355 +++++++++++++++++++++++++++++++++++++++++-
src/userprog/syscall.c         | 429 ++++++++++++++++++++++++++++++++++++++++++-
6 files changed, 782 insertions(+), 37 deletions(-)

💮process.c, process.h

Loads ELF binaries and starts processes.

ELF (Executable and linkable format)
is a common standard file format for executable files, object code, shared libraries, and core dumps.

💮syscall.c, syscall.h

언제든 user process가 kernel의 기능을 사용 할때 system call을 호출합니다. 현재는 메세지만을 출력하고 user process를 종료시킵니다. project 2에서는 각 system call이 해야하는 일들을 구현하면 됩니다.


Using the File System

이번 프로젝트에서는 file system 코드들과 상호작용을 해야합니다. 왜냐하면 user program들은 file system을 통해 불러와지고, 많은 system call들은 file system을 다뤄야하기 때문입니다. 하지만 이는 이 번 프로젝트의 목표가 아니기에, filesys directory에 간단하지만 완성된 filesytem을 제공합니다. filesys.h 와 file.h를 참고할 필요가 있습니다. 하지만,

  • file system 관련 코드를 이번 프로젝트에서는 변경할 필요가 없습니다.

  • file system routine을 올바르게 사용하는 것이 project 4을 위해 아주 유익할 것 입니다.

위의 두 가지 사항 때문에 현재로서는 아래의 한계사항들이 존재하고 감내야합니다.

  1. file system 내부적인 synchronization은 없습니다. 프로세스들이 파일에 접근할 때 동기화가 보장되어야합니다.

  2. File size is fixed at creation time. The root directory is represented as a file, so the number of files that may be created is also limited.

  3. File data is allocated as a single extent, that is, data in a single file must occupy a contiguous range of sectors on disk. External fragmentation can therefore become a serious problem as a file system is used over time.

  4. No subdirectories

  5. File names are limited to 14 characters.

  6. A system crash mid-operation may corrupt the disk in a way that cannot be repaired automatically. There is no file system repair tool anyway.

filesys_remove() 는 구현되어 있습니다. 이는 file이 열려있는 상태에서 삭제가 되었을때 해당 파일을 사용하고 있는 thread가 있다면 바로 deallocated되는 것이 아니라, 사용 중 삭제된 file을 사용하는 thread가 모두 닫히면 삭제가 됩니다.


How User Programs Work

PintOS는 평범한 c program들을 실행할 수 있습니다. (memory가 충분하고, 내가 구현한 syscall만 사용한다면). malloc()은 구현 할 수 없습니다. 이번 프로젝트에서는 어떤 syscall도 memory allocation을 할 수 없기 때문입니다.

Pintos can load ELF executables with the loader provided for you in userprog/process.c. ELF is a file format used by Linux, Solaris, and many other operating systems for object files, shared libraries, and executables.

💻init.c (어디서부터 시작되는거지?)

threads/init.c

int
main (void) {
...
	/* Break command line into arguments and parse options. */
	argv = read_command_line ();
	argv = parse_options (argv);
...
	/* Run actions specified on kernel command line. */
	run_actions (argv);
...
}

/* Executes all of the actions specified in ARGV[]
   up to the null pointer sentinel. */
static void
run_actions (char **argv) {
	/* An action. */
	struct action {
		char *name;                       /* Action name. */
		int argc;                         /* # of args, including action name. */
		void (*function) (char **argv);   /* Function to execute action. */
	};

	/* Table of supported actions. */
	static const struct action actions[] = {
    /* ==================== 여기! ==================== */
		{"run", 2, run_task},
	...
}

/* Runs the task specified in ARGV[1]. */
static void
run_task (char **argv) {
	const char *task = argv[1];

	printf ("Executing '%s':\n", task);
#ifdef USERPROG
	if (thread_tests){
		run_test (task);
	} else {
    	/* ==================== 여기! ==================== */
		process_wait (process_create_initd (task));
	}
#else
	run_test (task);
#endif
	printf ("Execution of '%s' complete.\n", task);
}

보다 싶이 init.c 의 main에서 호출되는 process 관련 함수는 process_create_init() 및 process_wait() 이다. 아마도,

test 실행 커멘드

pintos -v -k -T 60 -m 20   --fs-disk=10 -p tests/userprog/args-none:args-none -- -q   -f run args-none
pintos -v -k -T 60 -m 20   --fs-disk=10 -p tests/userprog/args-single:args-single -- -q   -f run 'args-single onearg'
pintos -v -k -T 60 -m 20   --fs-disk=10 -p tests/userprog/args-multiple:args-multiple -- -q   -f run 'args-multiple some arguments for you!'
pintos -v -k -T 60 -m 20   --fs-disk=10 -p tests/userprog/args-many:args-many -- -q   -f run 'args-many a b c d e f g h i j k l m n o p q r s t u v'
pintos -v -k -T 60 -m 20   --fs-disk=10 -p tests/userprog/args-dbl-space:args-dbl-space -- -q   -f run 'args-dbl-space two  spaces!'

pintos --fs-disk=10 -p tests/userprog/args-single:args-single -- -q -f run 'args-single onearg'
pintos --fs-disk=10 -p tests/userprog/args-single:args-single -- -q   -f run 'args-single onearg'
pintos --fs-disk=10 -p tests/userprog/args-multiple:args-multiple -- -q   -f run 'args-multiple some arguments for you!'
pintos --fs-disk=10 -p tests/userprog/args-many:args-many -- -q   -f run 'args-many a b c d e f g h i j k l m n o p q r s t u v'
pintos --fs-disk=10 -p tests/userprog/args-dbl-space:args-dbl-space -- -q   -f run 'args-dbl-space two  spaces!'
profile
꿈에다가 우리들의 돛을 달고 앞으로 다가올 그 날을 위해 밤을 지나자

0개의 댓글