[ OS ] 01. Introduction

38A·2023년 4월 7일
1

Operating System

목록 보기
1/14
post-thumbnail

🖥️ Definitions of operating system

What is an Operationg System?

  • There is no completely adequate(적절한) definition for OS
  • Roughly, an OS is :
    - Intermediary(중개자) between the user and H/W
    - Kernel + additional programs
    • Kernel : core of OS that runs at all times
      • System / application programs are not included
  • Operating system goal
    - Execute user programs and make solving user problems easier.
    - Make the computer system convenient to use.
    - Use the computer hardware in an efficient manner(방법)

Components of Computer System

  • Computer system can be divided into four components
    - Hardware : provides basic computing resources
    ➡️ CPU, memory, I/O devices
    - Operating system
    ➡️ Controls and coordinates(조정) use of hardware among various applications and users
    - Application programs – define the ways in which the system resources are used to solve the computing problems of the users
    ➡️ Word processors, compilers, web browsers, database systems, video games
    - Users
    ➡️ People, machines, other computers

What Operating Systems Do?

  • provides environment
    - Performs(수행하다) no useful function by itself.
    - However, the user can do something easily in the environment provided by OS.
  • manages the system resources
    - Let the users and the programs share the system resources in time and space.
    - Let the user use the computer hardware in an efficient manner.

System View

  • An OS is a resource allocator
    - Manages all resources ➡️ CPU, memory, file-storage, I/O device, ...
    • Decides between conflicting requests for efficient and fair(공정하게) resource use
  • An OS is a control program
    - Controls execution of programs to prevent(방지하다) errors and improper(부적절한) use of the computer

🖥️ Computer system organization and operation

Computer System Operation

  • What happens when a computer starts running?
    1. Bootstrap program (firmware) is executed
    - Diagnose(진단) and initialize system
    - Load and execute OS kernel ➡️ Bootstrap loader
    2. OS kernel
    - Boots (init)
    - Waits for some event
    - Handles event

→ Modern operating systems are interrupt driven(기반) programs

Modern Computer System

  • Common bus: a subsystem that transfers data between computer components
    • CPU, memory and device controllers are connected to a common bus
    • I/O devices and the CPU can execute concurrently(동시에)
  • Each device controller has a local buffer
    - buffer : 빠른 bus와 상대적으로 느린 I/O 사이 속도조절
  • CPU moves data from/to main memory to/from local buffers
  • I/O is from the device to local buffer of controller
  • Device controller informs(알리다) CPU that it has finished its operation by causing(발생) an interrupt
    ➡️ 끝나면 interrupt를 주기 때문에 CPU는 다른 task 수행 가능

Interrupt

  • Interrupt: an asynchronous signal from hardware or software indicating the need for attention
    • Supported by H/W
    • Each type of interrupt is associated(연결) with a number (IRQ number)
  • Separate segments of code determine what action should be taken for each type of interrupt
    • Table of interrupt handler: interrupt vector → handler들의 address가 저장
    • A mechanism to process event
      - H/W interrupt
      - S/W interrupt
      • System call (= monitor call): request from program to OS
      • Exception

Execution cycle of CPU

  • PC : Program Counter
  • IRQ : Interrupt Request → Interrupt #
  • ISR : Interrupt Service Routine → Interrupt handler
InterruptRequest = FALSE;while(haltFlag not set during execution) {
	IR = memory[PC];
	PC++;
	execute(IR);
	if(InterruptRequest) { // Interrupt the current process
		save_PC(); // Save the PC
 		restore_PC(IRQ); // Branch to the ISR for this IRQ
	}
}

→ handler로 점프하기 위해서 PC에 handler의 위치를 넣는데, 이 위치는 interrupt vector에 있다.

⭐️ Interrupt Mechanism

  • Interrupt handling
    1. CPU stops current work and transfers execution to interrupt handler
    2. Interrupt is handled by corresponding handler
    3. Return to the interrupted program
    - Before interrupt handler is invoked(호출), necessary information should be saved ( return address, state )

Interrupt-based I/O

  1. CPU sends request and / continue current process or do another job.
  2. When data transfer is done, I/O device interrupts

Main memory

  • Register
    • Small, fast, memory in CPU
  • Main memory
    • array of cells to store data or instruction
    • Each cell is dentified by its address
    • Fast, volatile(휘발성)
  • All forms of memory provide an array of bytes.
    Each byte has its own address
    • load, store → 대상과 주소가 중요

Storage Structure

Performance of Various Levels of Storage

I/O Device Access


  • Old systems
    - Busy waiting : CPU checks devices status periodically(주기적으로)

    → Problem: CPU does nothing but waits for I/O device
    (중요하고 비싼 자원인 CPU를 낭비하는 방식)

  • Modern systems
    - Interrupt-driven I/O (Interrupt-based I/O)
    • CPU sends request to controller
    • When requested I/O operation is completed, CPU is noticed by interrupt.
    • If necessary, CPU can request for information about I/O operation

      → Problem: CPU should transfer large bulk of data (메모리로 이동하는 transfer에는 CPU가 관여를 해야함)

  • DMA (Direct memory Access) : For large bulk of data
    • Device controller directly transfers large bulk of data into main memory
    • CPU doesn’t have to be involved(관여 x) in data transfer

🖥️ Computer system architecture

Single-Processor systems

  • Single general-purpose(범용) main CPU
  • Some special-purpose processors for devices
    - Not for user process
    • Ex) processor of device controller
  • Advantage of single processor system
    - Simple
    - Cheap

Multi-Processor Systems

  • Two or more processors in close communication
    - Tightly-coupled system
    • Shared bus, clock, memory, peripheral
  • Usually, includes multi-core systems : 칩은 하나인데 코어가 여러개
    → Cores can share cache memory
  • Categories
    - Symmetric multiprocessing (SMP)
    • All processors are peers(동등)
    • Asymmetric multiprocessing : CPU의 종류가 다르면 Asymmetruc
      • Master-slave relation : The master schedules and allocates the slaves.
  • Advantages of multiprocessor system
    - Increased throughput(단순속도 x) (compared with single-processor systems)
    → N processors : speed up by N times (in ideal case) | But, usually some overhead
    - Improved reliability(신뢰성, 확실성)
    - Economy(절약) of scale (compared to clustered systems)
    • Memory, peripherals(주변기기) can be shared

Clustered Systems

- Loosely coupled system (network로 연결) ↔️ titly coupled system (multi processor systems)

- Multiple systems working together (bus, memory, clock이 공유되어야 컴퓨터 한 대)

  • Usually sharing storage via a storage-area network (SAN : storage를 공유하는 네트워크)
    → SAN : a dedicated(전용) network that provides access to consolidated(통합) block level data storage.
    • Primarily used to enhance storage devices, accessible to servers so that the devices / appear like(처럼 보인다) locally(로컬로) attached(연결된) devices to the operating system → Composed(구성) of hosts, switches storage elements
    • Provides a high-availability(안전성) service which survives failures → Increased reliability(신뢰성)
      - Asymmetric clustering has one machine in hot-standby(상시대기) mode
      - Symmetric clustering has multiple nodes running applications, monitoring each other (한쪽에 fault가 나도 나머지는 working)
      - Grace degradation : 한쪽에 fault가 나도 나머지는 working
      - Fault tolerant(내성) : 기능적인 손해가 있을 수도 있지만, 전체 시스템에 문제가 있어도 적어도 일부는 working
    • Some clusters are for high-performance computing (HPC)
      → Applications must be written to use parallelization
  • Some have distributed lock manager (DLM) to avoid conflicting operations
    - 여러개의 컴퓨터가 동시에 접근하지 못하도록, 한 컴퓨터가 write할 때 다른 컴퓨터의 접근 Lock

🖥️ Operating system structure and operation

  • Motivation: single user cannot keep CPU and I/O devices busy at all times

Multiprogramming

  • 프로세서가 입출력 작업의 종료를 대기할 동안 하나의 프로세서에서 다른 프로그램을 수행할 수 있도록 하는 것
  • Multiprogramming organizes jobs (code and data) so CPU always has one to execute.
  • A subset of total jobs in system is kept in memory
  • One job selected and run via(~을 통해) job scheduling
  • OS switches jobs if a job should wait

Timesharing (multitasking)

: logical extension of multiprogramming in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive(대화식) computing. - switching overhead로 인해 스위칭 할 때 마다 딜레이가 생김

  • 스위칭을 빠르게 한다. 필요하지 않은 상황에서도 스위칭을 한다
  • Response(응답) time should be < 1 second
  • Each user has at least one program executing(process) in memory
  • CPU scheduler selects a job that is ready to run

Multiprogramming vs. Multitasking

앞에서 말한 멀티 프로그래밍은 프로세서의 자원낭비를 막기 위함이고, 멀티태스킹은 정해진 시간동안 각각의 task를 번갈아가며 수행하는 것을 의미한다.

Virtual Memory

  • Main memory is not enough to accommodate(수용) all processes on multiprogramming / multitasking system.
    ➔ Remedies
    • Swapping moves memory contents in(Disk→Mem) and out(Mem→Disk) to run.
    • Virtual memory allows execution of processes not completely in memory
  • Virtual memory is a computer system technique which gives an application program the impression that it has contiguous(연속적) working memory, while in fact it is physically fragmented(조각나있다) and may even overflow on to disk storage.
    - “Using disk space to extend physical memory size” + alpha

Operating System Operations

  • Modern OS’s are interrupt-driven programs
    - Events are signaled by interrupts, which are handled by interrupt handlers
    - H/W and S/W resources are shared
    Problem: An error from a process can corrupt(손상되다) whole(전체) system

  • Essential(필수) requirement for multi-user OS: Error of a program should not affect(영향을 미치다) to other program
    - Dangerous instructions ➔ dual mode operation
    → See 80x86 instruction set
    - Long execution ➔ timer interrupt

⭐️ Dual-mode operation (requires H/W support)

  • User mode (super-user(sudo)도 user mode!)
    - User defined code (application)
    - Privileged(특권) instructions, which can cause harm to other system, are prohibited(금지) : 잘못 사용할 경우 피해를 끼칠 수 있는 inst.
    • I/O instruction, timer instruction, ...
    • Privileged instruction can be invoked only through OS system call.
    • 만약 사용한다면? interrupt! → jump to interrupt handler → kernel이 terminate
  • Kernel mode (supervisor mode, system mode, privileged mode)
    - OS code
    - Privileged instructions are permitted(통과)
  • Advantage of dual-mode operation
    - Errors violating(위반) mode can be detected by H/W and handled by OS
    • Abnormal(비정상) termination without system halt
    • Error message
    • Memory is dumped(버려진)

Timer interrupt

  • Protecting from very long execution of a program
    - Before OS gives control to user process, timer is set to interrupt after pre-defined(미리 정의한) duration(기간)
    - If timer interrupt occurs, OS can take control to handle each case appropriately(적절하게)
    * Note: Time counter can be modified by only privileged instruction

Multi-mode Operation

  • Ring 0 : Kernel mode
  • Ring 1 and 2 : for vitual machine
  • Ring 3 : user mode

🖥️ Core components of OS

Process Management (1st 가장 중요한 resouce)

  • Process: program in execution (active entity) : 실행x → in Disk (문서 하나하나, ppt)
    - Job, time-shared program
    - Active program with required resources
    → Ex) word-processor running on PC, ...
    - Single threaded process has a program counter
    → Multiple instances of a program: separate processes
    - Unit(단위) of work
    → Operating system processes, user processes

Terminologies(용어) similar to process

  1. Thread: a way for a program to split itself into two or more simultaneously running task
    (하나의 process안에 여러개의 flow, Ex_ ppt를 print, edit)
  • Basic unit of CPU utilization(활용도)
  • Smaller unit than process
  • Each thread has its own ID, program counter, register set, stack,...
  • Major resources are shared (Same processor, multi thread)
  1. Task: an execution path through address space (process, thread 구분 x)
    • A set of program instructions that is loaded in memory
    • In some context, such as Linux, task means process or both process and thread
      : Major resuouces shared의 차이점이 x
  • Process management by OS(resource 할당)
    - Creating(allocation) / deleting(release) processes
    - Suspending(pause) / resuming process
    - Process synchronization → 궁극적인 목적 : 문제가 발생하지 않게 하는 것 예방
    - Process communication
    → 두개 이상의 Process가 협력할 때 resource 가 공유되지 않기 때문에 OS의 특별한장치 필요
    - Deadlock handling

Memory Management (2nd 가장 중요한 resouce)

  • Main memory is central(중심) to operation of modern system
    - The only large storage that CPU can address/access directly.
    - Repository(저장소) of data shared by CPU and I/O devices.
  • Memory management by OS
    - Keeping track(추적) of which part of memory is occupied(점유하다) by whom → 2중할당 방지
    - Allocating / deallocating memory space
    - Deciding which process and data to move in/out of memory (swapping)

Storage Management

  • Abstraction of physical storage into logical file
    - Physical storage: magnetic disk, optical disk, magnetic tape, ...
    → Various in speed, capacity(용량), transfer rate, access method
    - File: logical storage unit abstracted by OS

    Device Driver(S/W) → cf. Device Controller(H/W)
    : Device drivers provides uniform interfaces

  • File-system management
    - Creating / deleting files and directories
    - Supporting primitives(기본요소) for manipulating files / directories
    - Mapping files into secondary storage
    - Backup files on stable storage media

Cashing

  • Temporal copy of used information into small and faster storage for next access
    - Based on locality of references
  • When a particular piece of information(특정 정보) is needed,
    - First, check if it is in cache → faster than original source
    - If so, use it, otherwise, use information from original source
    cf. Main memory can be viewed as a cache for secondary memory

Cache Coherence(일치, 일관)

  • Multiprocessor environment must provide Cache coherence in hardware such that all CPUs have the most recent value in their cache
  • Cache coherence: integrity of data stored in local caches of a shared resource

Protection and Security

  • Major issue in multi-user, multi-processing system
    - Authorization(권한부여) mechanism for file, memory segment, CPU, and other resources
  • Protection: any mechanism for controlling access of process or users to resources
    - Unique User ID, group ID are assigned to all processes and resources → ID가 다르면 차단하는 방식
  • However, protection is not sufficient(충분하지 x)
    - Authentication(인증) can be stolen(도용)
  • Security: defense against(~에 반대하여) external and internal attack to acquire(얻은) authentication(인증) illegally(불법적으로)
    - Security issue is very important in recent environment

HGU 전산전자공학부 김인중 교수님의 23-1 운영체제 수업을 듣고 작성한 포스트이며, 첨부한 모든 사진은 교수님 수업 PPT의 사진 원본에 필기를 한 수정본입니다.

profile
HGU - 개인 공부 기록용 블로그

0개의 댓글