250x250
Notice
Recent Posts
Recent Comments
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

SYDev

[운영체제] Exercise 1 본문

3학년 2학기 전공/운영체제

[운영체제] Exercise 1

시데브 2024. 9. 14. 01:09
728x90
경희대학교 허선영 교수님의 운영체제 수업을 기반으로 정리한 글입니다.

 

Part 1: Overview

Goals of this Exercise 

  • What operating systems do
  • How operating systems interact with user programs and computer hardware?

 

Going Deeper! 

- Software Interrupt and System Call

  • On Unix and Linux systems, software interrupt(trap) -> system calls를 요청하기 위해 사용됨 
  • int -> x86 processors에서 software interrupt를 호출하기 위해 사용하는 assebly language instruction
  • ex) int $0x80 -> 16진수 형태의 interrupt number를 호출
Warning 1: syscall instruction
x86 assembly language에서, system calls를 호출하는 다른 명령어인 syscall 존재 
-> syscall은 int 명령어가 사용하는 parameter register와 다른 register를 사용

 

  1. int $0x08 실행  
  2. interrupt vector를 참조 -> CPU는 system_call() function이 위치한 entry point로 점프
  3. syscall table 참조 -> system_call() function은 system_call handling을 위한 특정한 함수를 호출 (ex: sys_read)
  4. system call을 처리한 이후, user process는 작업을 계속 진행 -> system call은 synchronous하게 다뤄짐

What is the difference between Trap and Interrupt?

Trap
- user process 내부에서 발생한 exception에 의해 발생
synchronous interrupt
- invalid memory access, division by zero, breakpoint, ...

- Trap은 OS를 user mode에서 kernel mode로 변경 -> OS는 특정 actions를 진행하고 process에 대한 control을 return함
- trap handler는 synchronous하게 작동 -> os가 trap을 detect -> user process 중지 -> trap handling이 끝나면 작동

Defference Between Trap and Interrupt
Trap
- hardware device에서 발생
Synchronous process
- software device에 의해서만 발생
- user program instruction에 의해서만 발생
- interrupt에 포함되는 개념

Interrupt
- user program에서 발생
Asynchronous process
- hardware/software device 모두에서 발생 가능 -> application이 특정 os service를 발견했거나 종료됐을 때, software interrupts 발생
- OS/user program instruction 모두에서 발생 가능

그렇다면 trap과 software interrupt는 무슨 차이점을 가지는가?? -> 
Trap은 Software Interrupt의 일종

Software interrupt는 크게 Fault, Trap, Abort로 나눠짐

1. Falut
- software에 문제가 있는 경우 -> ex) invalid memory access
- segmentation Fault error가 대표적

2. Trap
"일부러"interrupt를 발생시키는 경우 -> ex) system call과 같이 interrupt를 발생시켜 os를 호출하는 경우
- interrupt의 결과를 기다리기 위해 Synchronous해야함

3.Abort
- 프로그램을 강제 종료하는 등의 interrupt -> fault보다 더 강제성 있음

source: https://en.wikipedia.org/wiki/Interrupt



Reference: https://www.baeldung.com/cs/os-trap-vs-interrupt

 

Task 1

Task 1.1: von Neumann Architecture

von Neumann Architecture 

  • CPU - arithmetic logic units & control unit으로 구성
  • Memory - data & instruction 영역으로 구성
  • CPU와 Memory를 분리하여 명령어를 따로 저장하는 '프로그램 내장 방식'이 핵심!!! -> CPU와 Memory를 분리하고, '연산 작업'을 program memory에 순서대로 저장한 후, 해당 연산 작업이 필요해질 때 저장해놓은 program을 찾아 data 영역으로 꺼내온 뒤 입력값과 함께 전달해 CPU에 전달해 연산 작업 진행

what is program counter?

  • a special register that point the address of the next instruction <-> 연산 결과를 임시로 저장하는 general register

 

Task 1.2: Stroage Hierarchy

Storage Hierarchy

  • Architecture
    • Registers
    • Cache
    • Main memory - DRAM
    • Nonvolatile memory - SSD
    • hard-disk drivers - HDD
    • magnetic tapes
  • storage capacity - access time
    • register에 가까울수록 stoage capacity가 작아지고, access time이 빨라짐
    • magnetic tapes에 가가울수록 storage capacity가 커지고, access time이 느려짐
  • on-chip memory -> registers & cache는 CPU 상에 존재하기 때문에 접근 속도가 매우 빠름

 

Task 1.3: Interrupts

  • (1) Interrupt Request Line(IRL) or Interrupt Request Pin(IRP)
    • CPU 하단에 위치한 pin(wire)
    • CPU에는 1~2개의 IRP가 존재 -> multiple I/O devices와 상호작용하기 위해 Programmable Interrupt Controller(PIC)와 연결
    • cpu senses after executing every instruction - > interrupt는 상시로 확인해야 함 
    • CPU가 interrupt request line에서 signal을 감지 -> interrupt number의 index에 해당하는 interrupt vector를 탐색(interrupt vector table은 memory에 위치) -> interrupt vector가 가리키는 interrupt service routine으로 jump
  • (2) Interrupt Handler(Service) Routine
    • interrupt service routine의 주소를 가리킴 
  • (3) Interrupt Vector
  • (4) Device Controller
    • Device Controller가 CPU에 interrupt 요청 -> pic -> IRP(interrupt request pin) -> CPU -> Interrupt Service Routine -> ISR이 interrupt를 해결

 

Task 2: True of False?

(1) Computer Architecture

  • In a von Neumann computer system, memory knows what data is for -> 
    • von Neumann architecture에서는 memory와 cpu가 분리되어 있음 -> memory에는 data가 저장만 돼있고, 이를 사용하는 것은 cpu
  • Cache can be shared by multiple in the CPU -> O
  • Multiple cores in the CPU can execute different instructions at the same time -> -> core는 각각 pc를 가짐
  • CPU with different ISAs(cpu가 처리할 수 있는 명령어의 집합) can execute the smae instructions -> -> ex) intel과 arm programs는 서로 명령어 호환 X
  • Both the kernel and user programs reside in main memory -> O

 

(2) Interrupt and System Call

  • Interrupts are used throughout modern operating systems to handle asynchronous events -> O
  • Device drivers are hardware components embedded in I/O devices -> -> device driver는 os 내부에 존재하는 software
  • The interrupt vector differs according to the architecture of the processor. -> O
  • Programs can run in different operating systems if CPUs use the same ISA. -> -> os가 다르면 system call api가 달라 호환이 어렵다.
  • When a system call is called, transition from user mode to kernel mode occurs. -> O
728x90