More about Interrupt

노정훈·2023년 5월 30일
0

detailed_CE

목록 보기
3/4

More about Interrupt

  • 오늘날 OS는 interrupt를 기반으로 동작함.
  • interrupt가 발생하면 CPU는 현재 하는 일을 멈추고 해당 interrupt를 해결하기 위해 동작함.
  • processor가 특정 동작을 하고 있는 중에 다른 device들에게서 interrupt가 오는 경우, 현재 실행되고 있는 일을 멈추고 해당 interrupt에 대응하는 Interrupt Service Routine(ISR)이 수행하는 것을 가리킴.
  • 여기서 routine은 어떤 동작을 수행하는 프로그램 코드를 의미

Interrupt 작동단계 : ex) Keyboard

  1. Keyboard의 controller에서 key up, key down 등의 interrupt를 일으키는 event 감지
  2. Keyboard에서 전기적 신호가 processor로 전달됨. (interrupt 발생)
    • 바로 연결된 것은 아님
    • interrupt signal이 들어오는 processor의 pin에 전기신호가 들 어오게 됨.
  3. processor는 매번 execute 명령이 끝날 때마다 interrupt를 확인하고 interrupt 요청이 있을 경우 현재 하던 일을 중지. (현재 실행 중인 process 중지)
  4. 현재 하던 일을 stack에 저장하는 context switching이 발생. (실행 중이던 process 상태 저장)
  5. 이후 해당 ISR에 제어권이 넘어가며 수행됨. (ISR or handler 실행)
    • keyboard interrupt의 경우 scan code의 값을 ASCII code로 변 환하여 buffer에 저장
  6. ISR 수행 이후, 원래 수행하던 process 수행(context switching). (저장된 상태로 복구 후 다시 process 실행 재개)
    • keyboard 값이 필요한 process라면 buffer에서 읽어들이게 됨.

Interrupt 종류

Hardware Interrupt

  • processor에 연결된 hardware에서 발생시키는 interrupt
  • 키보드, 마우스를 조작할 때 발생되는 가장 흔한 예
  • Timer interrupt, 전원공급 이상 interrupt 등이 있음.

Software Interrupt

  • User application의 process가 system call을 할 때 발생되는 interrupt.
  • User application은 User mode에서 수행되기 때문에 직접 접근할 수 없는 resource들이 존재함.
  • 이에 접근이 필요한 코드가 User application에 있다면 해당 코드를 수행할 때 SVC(SuperVisor Call)를 통해 Kernel mode로 변경이 되고 해당 코드의 수행이 종료된 이후 다시 User mode로 변경됨.
  • system call은 OS가 제공하는 서비스들에 User application이 접근하게 해주는 interface이고, 이들 System call을 수행하게 해주는 instruction이 SVC.
  • Trap : Register와 stack pointer가 저장되고 Context switching이 일어나며 실행이 재개될 수 있게 해주는 명령어. CPU 내부 interrupt라고 불리며 system call도 Trap을 통해 구현됨.

Internal Interrupt

  • processor 내부에서 발생되는 interrupt로 processor가 프로그램의 코드를 실행하는 도중 발생한 interrupt를 말함.
  • 잘못된 instruction이나 data를 사용한 경우 발생
  • Overflow, Divided by zero, 기타 Exception 등이 나타난 경우 발생
  • Trap은 특정 조건을 걸어둔 경우 적절할 ISR이 수행되는 경우라면 Exception은 예기치 못한 예외상황에 해당함. SW 내부에서 exception 처리를 통해 프로그래밍에서 특정 exception들이 발생 시 처리할 수도 있음.

References:
1) https://dsaint31.tistory.com/entry/CE-Interrupt

profile
노정훈

0개의 댓글