340 likes | 536 Views
Operating System. 07. Summer Vacation 허승현. Operating system. OS ?. 어플리케이션 프로그램의 실행을 제어 하고 사용자와 컴퓨터 하드웨어 사이의 인터페이스 역할을 하는 프로그램. CPU 를 효과적으로 사용하기 위해 유저 프로그램의 제어권을 줬다가 빼었다가 한다. CPU 효율을 얼마나 높일 수 있는가 ? CPU > REGISTER > CACHE MEMORY > I/O DEVICES. Operating system.
E N D
Operating System 07. Summer Vacation 허승현
Operating system • OS ? • 어플리케이션 프로그램의 실행을 제어 하고 사용자와 컴퓨터 하드웨어 • 사이의 인터페이스 역할을 하는 프로그램 • CPU를효과적으로 사용하기 위해 유저 프로그램의 제어권을 줬다가 • 빼었다가 한다. • CPU 효율을 얼마나 높일 수 있는가? • CPU > REGISTER > CACHE MEMORY > I/O DEVICES
Operating system • servicesProvided by the O.S • Facilities for Program creation : 프로그램 생성 • : 유틸리티의 일종인 에디터, 컴파일러,디버거 지원. • Program execution : 프로그램 실행 • : 명령어, 데이터를 메모리에 적재시키고, I/O and 파일초기화. • Access to I/O and files • : 쉽게사용 할 수 있게 • System access : 시스템접근. • : resource, data보호, 자원간의 충돌방지(deadlock….) • Error detection and response : 에러감지, 반응 • : 하드웨어 에러 : 메모리 에러, 장치에러, 오작동 • 소프트웨어 에러 : overflow, 접근이 금지된 메모리 접근 시도. • Accounting • : 사용자 통계자료 수집, 다중 사용자 고지서 발부에도,,,,,
Operating system • Layers and View of Computer System
Operating system • Computer Components : Top – Level approach • Processor : Central Processing Unit. • Main Memory : real memory, primary memory -휘발성 stores Data and Programs. • I/O Module : Move data between the computer and its external enviroment. • The external enviroment consist of a variety of devices. • System bus : provide for communication among processors, main • Memory,and I/O module
Operating system • Computer Components : Top – Level approach • PC : Program Counter • IR : Instruction register • Data 교환 MAR : Memory address register MAR : Memory buffer register I/O AR : Input/Output address register I/O BR : Input/Output buffer register
Operating system • Processor Registers • User visible register • - general purpose register program control • - Handled by machine language • Data Register • 데이터 상에 존재하는 연산을 수행하기 위해 사용자에게 할당하는 공간 40 bit • Address Register • 데이터와 명령어의 메모리 어드레스를 포함. 40 bit 32 bit • index/offset >> relocation • segment pointer • stack pointer :
Operating system Operating system • Control and Status Register • PC : Program counter - Contains the address of the next instruction to be fetched. • IR : Instruction register - Contains the instruction most recently fetched. • Program Status Word (PSW) • A register or group of registers containing: • - condition codes and status info bits. • - Interrupt enable/disable bit. • - Supervisor(OS)/user mode bit.
Operating system • Instruction cycle • The CPU fetches the next instruction (with operands) from • memory. • Then the CPU executes the instruction. • Program counter (PC) holds address of the instruction to be • fetched next. • Program counter is automatically incremented after each • fetch.
Operating system • Example of instruction execution
Operating system • Example of instruction execution
Operating system • Interrupt : CPU >> I / O 인터럽트가 없다면 CPU는 I/O가명령을 완전히 수행 할 때 까지 기다려야 한다. • Computers now permit I/O modules to INTERRUPT the CPU. • For this the I/O module just assert an interrupt request line • on the control bus • Then CPU transfer control to an Interrupt Handler Routine • (normally part of the OS)
Operating system • Necessity Interrupt • WRITE transfer control to the printer driver (I/O pgm) • I/O pgm prepare I/O module for printing (4) • CPU has to WAIT for I/O command to complete • Long wait for a printer • I/O pgm finishes in (5) and report status of operation
Operating system • Instruction Cycle with Interrupts • CPU checks for interrupts after each instruction • If no interrupts, then fetch the next instruction for the current program • If an interrupt is pending, then suspend execution of the current program, and execute the interrupt handler
Operating system • Interrupts improve CPU usage • I/O pgm prepares the I/O module and issues the I/O command (eg: to printer) • I/O pgm branches to user pgm • User code gets executed during I/O operation (eg: printing): no waiting • User pgm gets interrupted (x) when I/O operation is done and branches to interrupt handler to examine status of I/O module • Execution of user code resumes
Operating system • Interrupt 구분 • I/O • signals normal completion of operation or error • Program Exception • overflows • try to execute illegal instruction • reference outside user’s memory space • Timer • preempts a pgm to perform another task • Hardware failure (eg: memory parity error, power failure)
Operating system • Multiple Interrupts sequential order • Disable interrupts during an interrupt • Interrupts remain pending until the processor enables interrupts • After interrupt handler routine completes, the processor checks for additional interrupts
Operating system • Multiple Interrupts : Priority • DX(x) • if DI(O) • 우선순위 높은 Interrupt는 • 실행 X • Higher priority interrupts cause lower-priority interrupts to wait • Causes a lower-priority interrupt handler to be interrupted • Example: when input arrives from communication line, it needs to be absorbed quickly to make room for more input
Operating system • Locality of reference : 참조의 국부성 • 메모리에 Data에 블록 단위로 올라갈때 현재 수행중인 프로그램의 다음 번째 수행 프로그램은 그 블록 속에 같이 포함되어 있을 확률이 높다는 것 (Denn68)
Operating system • Multiprogramming =>MultiTasking • When a program reads a value on a I/O device it will need to wait for the I/O operation to complete • Interrupts are mostly effective when a single CPU is shared among several concurrently active processes. • The CPU can then switch to execute another program when a program waits for the result of the read operation. (more later)
Operating system • Multiprogramming • When a program reads a value on a I/O device it will need to wait for the I/O operation to complete • Interrupts are mostly effective when a single CPU is shared among several concurrently active processes. • The CPU can then switch to execute another program when a program waits for the result of the read operation. (more later)
Operating system • Multiprogramming Uniprogramming Multiprogramming Processor use 22% 43% Memory use(256) 30% 67% Disk use 33% 67% Printer use 33% 67% Elapsed time 30 min. 15 min. Throughput rate 6 jobs/hr 12 jobs/hr Mean response time 18 min. 10 min.
Operating system Cheaper Larger capacity Slower • Memory Hierarchy Registers Cache Main Memory Magnetic Disc Smaller frequency of access Removable Media
Operating system • Cache Memory • Small cache of expensive but very fast memory interacting with slower but much larger memory • Invisible to OS and user programs but interact with other memory management hardware • Processor first checks if word referenced to is in cache • If not found in cache, a block of memory containing the word is moved to the cache
Operating system • Direct Memory Access • CPU issues request to a DMA module (separate module or incorporated into I/O module) • DMA module transfers a block of data directly to or from memory (without going through CPU) • An interrupt is sent when the task is complete • The CPU is only involved at the beginning and end of the transfer • The CPU is free to perform other tasks during data transfer
Chater 2. Process and threads Operating system
Operating system • Process • ‘이미지’를 만들어 놓고 수행 - 메모리가 커지면서 가능. • CPU 가 관리 할 수 있는 JOB의 단위. - 실행중인 프로그램이나 활성화 된 상태. 실행 될 수 있는 개체 모두를 뜻한다. • 프로그램의 정보를 가지고 있다. • ( run/ready.., PSW, register, PC 등…) • Context switching(KERNEL 모드 동작) • : Process 간의교환 작업이 넘어가면서 저장해야 할 것들이 많다.
Operating system • Thread • 작은 프로세스. • Thread Switching • : 스레드 간의 교환 작업 같은 프로그램 내에서의 이동이기 때문에 저장할 것이 • 적다.
Operating system • Desirable Hardware Feature • Memory protection - 유저 프로그램이 모니터를 포함하는 메모리 지역을 변경 시도 할 경우 프로세서 하드웨어가 오류 출력. - 모니터 프로그램이 손상 되지 않도록 보호한다. • Timer • 어떤 프로그램이 시스템을 독점하는 것을 방지. • RTC(Real Time Clock)에 일정 시간을 주고 한 JOB 수행 중 시간이 다 되면 • interrupt 띄우고 다음 Job 수행. • Privilege Instruction - 모니터 프로그램만 수행 할 수 있는 명령어. • Interrupt
Operating system • SMP(symetric Multi Processing) • 여러 개의 CPU를 가진 것. • 구현하기 어려움. • 수행해야 할 작업이 병렬로 처리 될 때 유리하다. • CPU가 여러 개라 하나가 뻗어도 성능만 떨어질 뿐. 시스템은 계속작동. • 멀티 프로세서라는 것은 유저가 모르게..
Operating system • KLT vs ULT • ULT - 장점 1. 스레드 스위치는 커넬을 필요하지 않는다. 2. 스케쥴링은 어떠한 특별한 어플리게이션에 의해 실행. 3. 어떤 운영체제에서나 운영가능. Thread Library 만 필요. - 단점 1. 커넬은 한번에 하나의 프로세스를 할당한다. 두개의스레드는 두 개의 프로세스에서 동시 수행될 수 없다. -> MultiProcessing불가. • KLT - 장점 1. 커넬은 동시에 여러 프로세서에게 같은 프로세스의 많은 스레드를스케쥴 할 수 있다. 2. Multithread 가능하다. - 단점 1. 커넬모드 전환. 속도 느리다.
Operating system • Thread Library • Contains code for: • creating and destroying threads • passing messages and data between threads • scheduling thread execution • saving and restoring thread contexts
Operating system • Micro Kernel • Small operating system core That provides the foundation for Modular extension • Contains only essential operating systems functions • Many services traditionally included in the operating system are now external subsystems • device drivers • file systems • virtual memory manager • windowing system and security services