OS Structures & Linux Overview
Modules (2/12 again)
•Many modern operating systems implement loadable kernel modules (run time에 어떤 코드 블록을 올릴 수 있는 것= kernel module)
–Uses object-oriented approach
–Each core component is separate
–Each talks to the others over known interfaces
–Each is loadable as needed within the kernel
–Linux, Solaris, etc
• Overall, similar to layers but with more flexible
• Similar to microkernel but no messaging communication
Hybrid Systems
• Most modern operating systems are actually not one pure model
–Hybrid combines multiple approaches from different systems to address performance, security, usability needs
–Linux and Solaris kernels are monolithic by having the OS in a single kernel address space
Plus modular for dynamic loading of functionality
–Windows mostly monolithic, plus microkernel for different subsystem personalities
–Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment
Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions)
iOS
•Apple mobile OS for iPhone, iPad
–Structured on Mac OS X, added functionality
–Cocoa Touch
Framework for developing mobile apps
–Media services
Layer for graphics, audio, video
–Core services
Provides cloud computing, databases
–Core operating system, based on Mac OS X kernel
Android
Android Architecture
Linux Overview
Why Linux?
•Learning Linux means improving the ability to develop/test applications using various commands and tools provided by Linux
–vim, emacs, make, gcc, gdb, etc.
: 리눅스를 배우는 것은 리눅스에서 제공하는 다양한 명령과 도구(ex. vim, emacs, make, gcc, ...)를 사용하여 응용 프로그램 개발/테스트 능력을 향상시키는 것을 의미.
•Why should we learn Linux?
–Most devices used in the IT industry are based on the Linux OS
E.g., Android for mobile, cloud server, network equipment, GENIVI for vehicle control and infotainment, Yoctoproject for IoTdevices, etc.
–Many open source programs run in the Linux-based environments.
: 리눅스를 배워야 하는 이유는 다양한 IT 업계에서 사용하는 디바이스 대부분은 리눅스 OS 기반이기 때문.
Why Linux Kernel?
•Learning Linux Kernel means understanding the detailed operation of the kernel and improving the ability to modify several parts of the kernel
•Why should we learn Linux kernel?
–You need to know detailed knowledge of the kernel to be an advanced programmer
Code optimization, debugging skills, etc.
–It is essential if you want to be an embedded system developer dealing with low-level hardware interfaces (device drivers)
–Linux kernel is an open-source based OS
The Birth of Linux
•Linux is a modern, free operating system based on UNIX standards
–First developed as a small but self-contained kernel (version 0.01) in 1991 by Linus Torvalds, with the major design goal of UNIX compatibility, released as open source
–Linux Kernel 1.0 (March 1994) ~ 5.0 (March 2019)
LoC per Linux Kernel Version
The Linux System
•Linux uses many tools developed as part of Berkeley’s BSD OS, MIT’s X Window System, and the Free Software Foundation's GNU project
–The Linux system is maintained by a loose network of developers collaborating over the Internet (the Linux community)
–The main system libraries were started by the GNU project, with improvements provided by the Linux community
• File System Hierarchy Standard document maintained
by the Linux community to ensure compatibility across
various system components
- Specifies overall layout of a standard Linux file system, determines under which directory names configuration files, libraries, system binaries, and run-time data files should be stored
: 리눅스 커뮤니티에서는 다양한 시스템 구성 요소 간의 호환성을 보장하기 위해 파일 시스템 계층 표준 문서를 유지/관리하고 있다. \(root directory)내부에 \bin, \dev, \home, ...등 표준 리눅스 파일 시스템의 전체 레이아웃을 지정하고 구성 파일, 라이브러리 시스템 바이너리 및 런타임 데이터 파일이 저장되어야 하는 디렉토리 이름을 결정.
Design Principles of Linux
: 리눅스는 UNIX 기반이라, UNIX 호환기능 툴들을 이용하여 멀티유저, 멀티태스킹을 지원한다. 파일 시스템도 기존 UNIX 의미 체계를 준수하며 표준 UNIX 네트워킹 모델을 구현한다. 설계 목표는 속도, 효율성, 표준화이다.
속도와 효율성은 모놀리식 구조를 사용함으로써 만족시킴
•A multiuser, multitasking system with a full set of UNIX-compatible tools
•Its file system adheres to traditional UNIX semantics, and it fully implements the standard UNIX networking model
•Main design goals are speed, efficiency, and standardization
•Linux is designed to be compliant with the relevant POSIX documents
- The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems
Linux OS Structure
리눅스를 UNIX를 기반으로 하며 모놀리식과 유사한 구조로 되어있다. 즉 커널의 모든 기능을 단일 주소 공간에서 실행되는 단일 정적 바이너리 파일에 배치하여 속도와 효율성 측면에서 이점을 보인다.
또한 리눅스에는 런타임 중에 커널을 수정할 수 있는 모듈식 설계도 있다.
주로 장치 드라이버 및 파일 시스템 지원을 위해 로드 가능한 커널 모듈 (LKMs)을 사용한다.
LKM은 시스템이 시작될 때 또는 USB 장치가 실행 중인 시스템에 연결/해제되는 경우와 같이 런타임 중에 커널에 "삽입 또는 제거"될 수 있다.
•It is based on UNIX and is structured similarly, i.e., Monolithicrather than Microkernel
–Placing all of the functionality of the kernel into a single, static binary file that runs in a single address space
–Distinct performance advantages in terms of speed and efficiency
•Linux also has a modular design that allows the kernel to be modified during run time
–Using loadable kernel modules (LKMs), primarily for supporting device drivers and file systems
- LKMs can be “inserted OR removed” into/from the kernel as the system is started or during run time, such as when a USB device is plugged into/out a running machine
Linux OS Structure
•Like most UNIX implementations, Linux is composed of three main bodies of code; Kernel, System libraries and System utilities
대부분의 UNIX 구현과 마찬가지로, Linux는 커널, 시스템 라이브러리, 시스템 유틸리티의 세 가지 주요 코드 본문으로 구성된다.
Components of the Linux System
•Kernel
: OS에서 중요하게 취급되는 abstraction 유지/관리
모든 커널 코드는 커널 모드에서 실행된다.
–Responsible for maintaining all the important abstractions of the OS
_All the kernel code executes in the processor’s privileged mode(= kernel mode) with full access to all the physical resources of the computer
–All kernel code and data structures are kept in the same single address space
•System Libraries
_Define a standard set of functions through which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code
–The most important system library is the C library, known as libc
Components of the Linux System
•System Utilities (= System Services)
: 개별적이고 전문적인 관리 업무를 수행하는 프로그램.
–Programs that perform individual, specialized management tasks
–Some are invoked just once to initialize and configure some aspect of the system.
_Others (known as daemons in UNIX terminology) run permanently, handling such tasks as responding to incoming network connections, accepting logon requests from terminals, and updating log files
Kernel Modules
: 커널 모듈은 커널의 나머지 부분과 독립적으로 컴파일, 로드/언로드 할 수 있는 커널 코드 섹션이다.
일반적으로 장치 드라이버, 파일 시스템 또는 네트워킹 프로토콜을 구현할 수 있다.
•Sections of kernel code that can be compiled, loaded, and unloaded independent of the rest of the kernel
•A kernel module may typically implement a device driver, a file system, or a networking protocol
•The module interface allows third parties to write and distribute, on their own terms, device drivers or file systems that could not be distributed under the GPL
•Kernel modules allow a Linux system to be set up with a standard, minimal kernel, without any extra device drivers built in
Kernel Modules
• Kernel modules allow a Linux system to be set up with a standard, minimal kernel, without any extra device drivers built in
• Four components to Linux module support:
– module-management system
– module loader and unloader
– driver-registration system
– conflict-resolution mechanism
Module Management
• Supports loading modules into memory and letting them talk to the rest of the kernel
• Module loading is performed in two stages
1) The module loader asks the kernel to reserve a continuous area of virtual kernel memory for the module
2) The module loader passes the module, plus any symbol table that the new module wants to export, to the kernel
• Module requestor (unloader)
– Manages loading requested, but currently unloaded, modules
– Regularly queries the kernel to see whether a dynamically loaded module is still in use, and will unload it when it is no longer actively needed
Driver Registration
• Allows modules to tell the rest of the kernel that a new driver has become available
• The kernel maintains dynamic tables of all known drivers, and provides a set of routines to allow drivers to be added to or removed from these tables at any time
• Registration tables include the following items:
– Device drivers
– File systems
– Network protocols
– Binary format
Conflict Resolution
: 모듈들이 HW resource에 접근할 때 crash 방지 및 autoprob(새로운 디바이스를 자동으로 detect하는 프로그램)이 device driver를 방해하지 않도록 방지
• A mechanism that allows different device drivers to reserve hardware resources and to protect those resources from accidental use by another driver
• The conflict resolution module aims to:
– Prevent modules from clashing over access to hardware resources
– Prevent autoprobes from interfering with existing device drivers
– Resolve conflicts with multiple drivers trying to access the same hardware:
1) Kernel maintains list of allocated HW resources
2) Driver reserves resources with kernel database first
3) Reservation request rejected if resource not available