[태그:] thread

  • Pintos Project 2 한국어 설명서 (design report) – User Program, System Call

    목차

    0. Analysis
    0.1. Process Execution Procedure
    0.1.1. analysis
    0.2. System Call Procedure
    0.2.1. what is system call
    0.2.2. analysis
    0.3. File System
    0.3.1. what is file descriptor
    0.3.2. analysis

    1. Process terminate messages
    1.1. goal
    1.2. how to solve problems

    2. Argument Passing
    2.1. goal
    2.2. how to solve problems

    3. System Call
    3.1. goal
    3.2. how to solve problems
    3.2.1. data structure
    3.2.2. detailed algorithm
    3.2.3. implement system calls

    4. Denying Writes to Executables
    4.1. goal
    4.2. how to solve problems

    본문내용

    0. Analysis
    project 1에선 kernel에서 실행되는 thread들 위주였다면 project 2에서는 user program을 실행시키는 것이 위주이다. 따라서 project 1에선 alarm clock, priority scheduling, advanced scheduling 등의 코드들이 모두 kernel의 일부였고 해당 코드들을 kernel에서 직접 compile했지만, project 2에선 user program을 이용하여 compile한다. user program을 실행시키기 위하여 구현해야 하는 것은 아래와 같다.
    1. Process terminate messages
    2. Argument passing
    3. System call
    4. Denying writes to executables
    user program은 file system에서 load되고 있고, 많은 system call 구현은 file system에서 다뤄진다.
    0.1. Process Execution Procedure
    0.1.1. analysis
    1. main()
    Process Execution Procedure을 분석하기 위해 먼저 threads/init.c의 main 함수를 보겠다.
    0. Analysis 0.1. Process Execution Procedure
    0.1.1. analysis 0.2. System Call Procedure
    0.2.1. what is system call 0.2.2. analysis 0.3. File System 0.3.1. what is file descriptor 0.3.2. analysis

    출처 : 해피캠퍼스

  • Pintos Project 1 한국어 설명서 (design report) – Alarm clock, Priority Scheduling, Advanced Scheduling

    목차

    0. analysis
    0.1. thread
    0.1.1. struct thread
    0.1.2. thread functions
    – [thread 시작 관련 function]
    – [thread 관리 function]
    – [thread 동작 관련 function]
    – [scheduling function]
    – [timer 관련 function]
    0.1.3. list
    – [list function]
    0.1.4. how to switch thread
    0.2. synchronization
    0.2.1. meaning of synchronization
    0.2.2. disabling interrupts
    0.2.2.1. meaning of disabling interrupts
    0.2.2.2. caution
    0.2.2.3. implement
    0.2.3. semaphore
    0.2.3.1. meaning of semaphore
    0.2.3.2. implementation
    0.2.4. lock
    0.2.4.1. meaning of lock
    0.2.4.2. implementation
    0.2.5. condition
    0.2.5.1. meaning of condition
    0.2.5.2. implementation
    0.2.6. interrupt handling
    0.2.6.1. external interrupt handling

    1. alarm clock
    1.1. current implementation
    1.1.1. timer.c functions
    1.1.2. busy-waiting
    1.2. new implementation

    2. priority scheduling
    2.1. current implementation
    2.2. new implementation
    2.2.1. priority scheduling modification
    2.2.2. synchronization modification
    2.2.3. priority donation modification

    3.advanced scheduling
    3.1. MLFQS
    3.2. Priority scheduling
    3.2.1. ready queue 관리
    3.2.2. priority 관리
    3.2.3. priority 계산
    3.3. fixed-point arithmetic
    3.4. implementation

    본문내용

    0.1. thread
    pintos에서는 thread creation과 thread completion, Round-Robin 방식의 thread switching(simple scheduler)을 이미 구현해 두었다.
    0.1.1. struct thread
    kernel thread의 struct는 “threads/thread.h”에 선언되어 있다.
    thread structure은 4kB page를 차지한다. struct thread는 page of memory의 시작부터 공간을 차지한다. page의 나머지 부분은 thread의 stack을 위해 이용되는데, 이는 end of the page로부터 아래쪽 방향으로 내려가며 진행된다.

    따라서 kernel stack을 위한 공간을 위해 struct thread는 너무 크기가 크면 안 된다. base struct thread는 1kB 미만이어야 한다. 그리고 kernel stack도 너무 크면 안 된다. stack에서 overflow가 발생하면 thread state를 침범할 것이므로 kernel function은 struct와 array에 non-static local variable 같이 너무 많은 공간을 할당하지 않고, malloc()이나 palloc_get_page() 같은 동적 할당 function을 써야 한다.
    [Member of struct thread]
    tid_t tid
    thread identifier를 뜻한다. 각 thread를 분간한다. 현재는 int 자료형에 1부터 numbering되게끔 짜여져 있다.

    출처 : 해피캠퍼스

  • Pintos Project 2 final report – User Program, System Call

    목차

    1. Process termination message
    1.1. algorithm
    1.2. function

    2. Argument passing

    3. System calls for user process
    3.1. algorithm
    3.2. data structure
    3.3. function

    4. System calls for file manipulation
    4.1. algorithm
    4.2. data structure
    4.3. function

    5. denying writes
    5.1. algorithm
    5.2. function

    6. discussion
    6.1. argument passing 오류
    6.2. bad test 오류
    6.3. multi-oom 오류
    6.4. 결과

    본문내용

    1. Process termination message
    process가 종료될 때마다 process 종료 메세지를 띄워야 한다.
    종료 메세지의 출력 예시와 형식은 아래와 같다.
    printf(“%s: exit(%d\n)”,variable_1, variable_2)
    ex) args-single: exit(0)
    variable_1 : process의 이름
    variable_2 : exit code
    1.1. algorithm
    exit system call을 담당하는 함수를 만들고
    함수 안에서 해당 thread를 종료시키고, 종료 메세지를 출력하도록 한다.
    process가 종료될 때마다 exit system call을 호출한다면
    해당 thread도 종료될 것이고, 종료 메세지도 출력될 것이다.
    1.2. function
    원래 기존의 pintos에서는
    해당 파일의 load에 실패한 경우 thread_exit()을 호출하였다.
    static void
    start_process (void *file_name_)

    <중 략>

    2. Argument passing
    user에 의해 입력된 command는
    프로그램 이름과 함께 부수적으로 붙는 option들이 다양하므로
    이를 모두 인식할 수 있어야 한다.
    그러나 현재 pintos는
    command line에 명령어를 입력하였을 때
    입력된 명령어 전체를 하나의 프로그램 이름으로 인식하도록 구현되어 있으며,
    프로그램 이름과 option들을 구분하여 인식하지 못하는 상태이다.
    따라서 입력된 command line을
    프로그램 이름과 option들로 parsing될 수 있게 수정한다.

    /* userprog/process.c */
    tid_t
    process_execute (const char *file_name)
    {
    char *command_line;
    char *name;
    char *remain;
    tid_t tid;
    // 메모리 할당, 메모리 할당 실패한 경우 함수종료, file_name을 comman
    command_line = palloc_get_page (0);
    if (command_line == NULL)
    return TID_ERROR;
    strlcpy (command_line, file_name, PGSIZE);

    출처 : 해피캠퍼스

  • Pintos Project 1 final report – Alarm clock, Priority Scheduling, Advanced Scheduling

    목차

    1. alarm clock
    1.1. implementation
    1.1.1.data structure
    1.1.2. algorithm
    1.2. discussion

    2. priority scheduling
    2.1. implementation
    2.1.1. data sturcture
    2.1.2. algorithm
    2.2. discussion

    3. advanced scheduling
    3.1. implement
    3.1.1. how to compute priority in advanced scheduling
    3.1.2. data structure
    3.1.3. algorithm
    3.2. discussion

    4. result

    본문내용

    1. alarm clock
    1.1. implementation
    기존의 busy-waiting 방식을 sleep/wake-up 방식으로 변경하는 것은 시스템 자원을 효율적으로 사용하는 데 매우 중요하다. busy-waiting 방식은 프로세서가 일정한 시간동안 아무 작업도 하지 않고 반복적으로 상태를 확인하는 방법으로, 타이머나 조건이 충족될 때까지 CPU가 루프를 반복하며 기다린다. (예를 들어, 알람시계의 경우 지정된 시간이 도달할 때까지 현재 시간을 계속 확인하는 방법이다.) 이로 인해 CPU 사이클을 낭비하게 됨으로써 CPU 자원이 불필요하게 낭비되고, 전력 소비를 증가시킬 수 있다. 반면, sleep/wake-up 방식은 프로세서가 작업을 기다리는 동안 유휴 상태로 전환되어 다른 작업을 수행할 수 있게 한다. 따라서 시스템 효율성을 증가시킬 수 있으며, 특히 임베디드 시스템이나 배터리로 구동되는 장치에서 매우 유용하다. 이를 통해 불필요한 자원 낭비를 줄이고, 시스템의 응답성을 높일 수 있다.

    1.1.1.data structure
    struct thread에 wakeup 변수 추가
    busy-waiting 방식과 sleep/wake-up 방식의 가장 큰 차이점은 thread가 깨어야 할 시간에만 깨는지, 아니면 깨지 않아도 될 시간에도 깨워서 시간을 확인하는 지다. 그러므로 sleep/wakeup 방식을 구현하기 위해 각 thread가 깨어야 할 시간을 저장하는 변수를 thread struct 안에 추가해 주는 것이 좋다. wakeup 변수는 현재 thread가 깨어나야 하는 ticks 값을 저장한다.

    출처 : 해피캠퍼스