CPU virtualizing을 위한 대표적인 방법 : time sharing
- 몇 가지 문제점 : 오버헤드, control(running process efficiently with CPU controlling)
6.1 Basic Technique : Limited Direct Execution
- "direct execution" : run the program directly on the CPU
- 몇 가지 문제점 : 프로그램이 실행 중일 때 OS 단에서 발생하는 문제 --> ex) how to switch process one to another
- 따라서, 실행 중인 프로그램에 대한 limit가 필요함
6.2 Problem #1 : Restricted Operations
- Direct execution 의 장단점
: 장점) 빠른 실행
: 단점) I/O request나 시스템 자원(CPU, 메모리 등)에 대한 접근 요청이 있을 경우에 대한 control 문제
- 만약 실행 중인 프로그램이 요청하는 모든 자원에 접근 가능하게 할 경우, protection문제 발생
- 따라서 유저모드와 커널모드로 구분
- 유저 모드 : i/o request나 디스크에 대한 접근에 제한적. 제한된 수행을 하려고 할 시에는 exception 발생시킴
- 커널 모드(OS) : 유저모드에서는 건드리지 못하는 작업(privileged operation)
- 문제점 : 유저모드에서 privileged operation이 필요한 경우 어떻게 해결?
- system call로 해결. System call을 하기 위해 필요한 것이 trap 개념
- user mode --> system call by trap --> simultaneously jump into kernel mode --> perform privileged operation --> when finished, return-from-trap --> user mode (simultaneously reducing the privilege level back to user mode)
- 이런 작업이 수행되기 위해서는 caller의 레지스터 상태가 저장되어야 한다.(trap을 통해 커널모드 실행 후 올바른 유저 모드로 돌아오기 위해서 이전 상태 저장 필요)
- flag, PC, register 등을 이용
- 그렇다면, 커널모드로 전환되었을 때, 어떤 코드를 실행해야 하는지에 대해서는 어떻게 알까?
- trap table 개념
- OS는 부팅 시에 HW에 특정 이벤트 발생 시 어떤 코드를 실행할 것인지 미리 세팅을 해놓는다.
- There are two phases in the LDE protocol
: 1. the kernel initializes the trap table, and the CPU remembers its location for subsequent use.
: 2. the kernel sets up a few things before using a return-from-trap instruction to start the execution of the process; this switches the CPU to user mode and begins running the process.
6.3 Problem #2 : Switching Between Processes
A Cooperative Approach : Wait For System Calls
- 현재 실행 중인 프로그램이 자발적으로 CPU를 놓아 줌으로써 다른 작업에 CPU가 할당되도록 함
- 자발적으로 CPU를 놓아준다? --> system call(ex. 파일 오픈, 열람, 혹은 프로세스 생성 등)
- 그렇다면 이러한 시스템 콜이 없는 프로세스가 무한루프에 빠져 있는 상황이라면?
- process switching이 불가능해짐. 유일한 스위칭 방법 : reboot..
A Non-Cooperative Approach : The OS Takes Control
- timer & interrupt handler
- 특정 시간이 다 되면 현재 실행 중인 프로그램 멈추고 다른 것을 실행시키는 방법
Saving and Restoring Context
- Scheduler & context switch
- OS가 해야할 일은 저장과 복구를 잘 하는 것(context switch 일어날 때)
-출처-
<OPERATING SYSTEMS three easy pieces>
REMZI H. ARPACI-DUSSEAU
ANDREA C. ARPACI-DUSSEAU
UNIVERSITY OF WISCONSIN-MADISON
'CS > 운영체제' 카테고리의 다른 글
8. Scheduling : The Multi-Level Feedback Queue (0) | 2019.11.04 |
---|---|
7. Scheduling : Introduction (0) | 2019.11.04 |
5. Interlude : Process API (0) | 2019.10.31 |
(Part I : Virtualization) 4. The Abstraction : The Process (0) | 2019.10.31 |
2. Introduction to Operating Systems (0) | 2019.10.31 |
댓글