02_fundamentals.pdf
Document Details
Uploaded by Deleted User
Full Transcript
OPERATING SYSTEMS AND NETWORKS Prof. Dr. Andreas Wölfl Department of Applied Computer Science, Deggendorf Institute of Technology [email protected] OPERATING SYSTEM FUNDAMENTALS OPERATING SYSTEM FUNDAMENTALS 1. HISTORY HISTORY 1st generation (1945 - 1955): Hardwar...
OPERATING SYSTEMS AND NETWORKS Prof. Dr. Andreas Wölfl Department of Applied Computer Science, Deggendorf Institute of Technology [email protected] OPERATING SYSTEM FUNDAMENTALS OPERATING SYSTEM FUNDAMENTALS 1. HISTORY HISTORY 1st generation (1945 - 1955): Hardware: Relays / vacuum tubes Input: Plugboard Output: Printer Operating System: None Figure 1: COLOSSUS computer Prof. Dr. Andreas Wölfl Operating Systems and Networks 1 HISTORY 2nd generation (1955 - 1965): Hardware: Transistors Input: Punch cards Output: Printer Operating System: None Figure 2: IBM 1401 mainframe Prof. Dr. Andreas Wölfl Operating Systems and Networks 2 HISTORY A punch card for the FORTRAN statement Z(1) = Y + W(1): Prof. Dr. Andreas Wölfl Operating Systems and Networks 3 HISTORY 3rd generation (1965 - 1980): Hardware: ICs (Integrated Circuits) Input: Punch cards, tape drive Output: Printer Operating System: OS/360 Figure 3: IBM 360 mainframe Prof. Dr. Andreas Wölfl Operating Systems and Networks 4 HISTORY 4th1 generation (1980 - Present): Personal Computers Hardware: LSI (Large Scale Integration) Input: Floppy, CD-ROM, USB, network Output: Printer, monitor, display Operating System: Windows, Linux, iOS, Android Figure 4: Macintosh 1 Tanenbaum also mentions a 5th generation for mobile computers. Prof. Dr. Andreas Wölfl Operating Systems and Networks 5 OPERATING SYSTEM FUNDAMENTALS 2. COMPUTER ARCHITECTURE COMPUTER ARCHITECTURE Computer A digital electronic machine that can be programmed to automatically carry out sequences of arithmetic or logical operations. Running programs: An order given to the computer to execute an operation is called instruction. Computers can only execute instructions in their native machine language. A sequence of instructions is called a (computer) program. Prof. Dr. Andreas Wölfl Operating Systems and Networks 6 COMPUTER ARCHITECTURE Cooler CPU Mainboard RAM M.2 SSD Disk Graphics Card Hard Disk Power Supply Prof. Dr. Andreas Wölfl Operating Systems and Networks 7 COMPUTER ARCHITECTURE The Von Neuman architecture: Keyboard Main Memory Mouse Registers Control Unit (RAM) PC RAX Input Devices Memory Unit AC RBX Arithmetic / Display Logic Unit RCX Secondary Memory (Disk) Printer Central Processing Unit (CPU) I/O Devices Bus Output Devices Prof. Dr. Andreas Wölfl Operating Systems and Networks 8 COMPUTER ARCHITECTURE The Arithmetic and Logic Unit (ALU): Allows arithmetic (add, subtract, etc.) and logic2 (AND, OR, NOT, etc.) operations to be carried out. The Control Unit (CU): Controls the operation of the computer’s ALU, memory, and I/O3 devices. Provides timing and control signals required by other computer components. 2 Details in the course Foundations of Computer Science 3 I/O = Input / Output Prof. Dr. Andreas Wölfl Operating Systems and Networks 9 COMPUTER ARCHITECTURE The Central Processing Unit (CPU): Electronic circuit responsible for executing instructions. Contains the ALU, the CU and a variety of registers. Registers are high speed storage areas in the CPU, examples4 : PC Program Counter Holds the memory location of the next instr. AC Accumulator Stores intermediate results of the ALU RAX General-purpose Used for temporary data storage RBX General-purpose Used for temporary data storage RCX General-purpose Used for temporary data storage 4 Not exam relevant Prof. Dr. Andreas Wölfl Operating Systems and Networks 10 COMPUTER ARCHITECTURE The Memory Unit: 65535 Known as primary or main memory. 65534 Implemented using Random Access Memory (RAM). 65533 Faster than secondary memory but slower than registers. Comprised of memory locations, each of size 1 Byte. 2 Memory locations are accessed using integer addresses. 1 0 Prof. Dr. Andreas Wölfl Operating Systems and Networks 11 EXCURSUS Bits, bytes, and words: A bit is the smallest unit in a digital computer. It can take two values: 0, 1. A group of 8 bits form a byte, e.g. 01011010. The amount of bits a register can hold is referred to as word.5 Binary prefixes denote the quantity of bytes: 1 kB (kiloByte) = 210 Bytes = 1024 Bytes 1 MB (MegaByte) = 220 Bytes = 1024 kB 1 GB (GigaByte) = 230 Bytes = 1024 MB 1 TB (TeraByte) = 240 Bytes = 1024 GB 5 Hence the name XY-bit architecture. Current state of the art is 64 bit. Prof. Dr. Andreas Wölfl Operating Systems and Networks 12 EXCURSUS Number system: A writing system for expressing numbers. Name Base Digits Example Binary 2 0, 1 10011100010000002 Octal 8 0, 1, 2, 3, 4, 5, 6, 7 1161008 Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 4000010 Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 9C4016 Why? Computers perform any operation based on binary numbers (it is simple). Programmers prefer hexadecimal numbers (it is compact) Prof. Dr. Andreas Wölfl Operating Systems and Networks 13 COMPUTER ARCHITECTURE Machine Instruction Cycle The process by which a computer executes instructions. Basic stages: 1. Fetch: The next instruction is fetched from the memory unit. 2. Decode: The control unit interprets the instruction and passes it to the ALU. 3. Execute: The ALU that executes the operation according to the instruction. 4. Store: The result is stored to memory (or sent to an output device). Prof. Dr. Andreas Wölfl Operating Systems and Networks 14 COMPUTER ARCHITECTURE Machine Instruction Cycle: decode ALU CU execute fetch store RAM Note: The actual number of stages can vary across different CPUs. Typically, a modern CPU has around 15-20 stages. Prof. Dr. Andreas Wölfl Operating Systems and Networks 15 COMPUTER ARCHITECTURE Example instructions6 (Intel x86 64-bit architecture): 1 0x4000: mov 0x6fec, %rax # Load the word starting at address 0x6fec into the rax register 2 0x4003: mov 0x80ff, %rbx # Load the word starting at address 0x80ff into the rbx register 3 0x4006: add %rax, $2 # Add the value 2 to the word in the rax register 4 0x4009: cmp %rax, %rbx # Compare the contents of the rax and rbx registers 5 0x400c: jl 0x4006 # If eax < ebx, jump to the instruction at 0x4006 6 0x400f: mov %rax, 0x5041 # Store the value in rax at address 0x5041 7... 8 0x6fec: 3 # The word starting at address 0xffec stores a value of 3 9... 10 0x80ff: 8 # The word starting at location 0x80ff stores a value of 8 Note: For the sake of simplicity, we assume each instruction is represented by 3 bytes (real x86 64 bit instructions vary in length). 6 Not exam relevant Prof. Dr. Andreas Wölfl Operating Systems and Networks 16 COMPUTER ARCHITECTURE Conclusion: Computers are very (!) complex systems and hard to program. → It is nearly impossible for humans to understand every detail of every hardware component built into a computer. Prof. Dr. Andreas Wölfl Operating Systems and Networks 17 OPERATING SYSTEM FUNDAMENTALS 3. DEFINITION DEFINITION → A layer of software is required to turn ugly hardware into beautiful abstractions. Program Beautiful Interface Operating System Ugly Interface Hardware Prof. Dr. Andreas Wölfl Operating Systems and Networks 18 DEFINITION Definition ISO/IEC 2382/2015 An operating system is a software that controls the execution of programs and that may provide services such as resource allocation, scheduling, input-output control, and data management. → The operating system’s job is to provide user programs with a better, simpler, and cleaner interface to the computers hardware. Prof. Dr. Andreas Wölfl Operating Systems and Networks 19 DEFINITION Simplified structure of the Linux kernel: System Call Interface Process Process Mgmt. Subsystem Memory Mgmt. Subsystem Terminals Sockets File Systems Virtual Memory Creation & Termination I/O Subsystem Network Generic Block Page Line Discipline Signal Handling Protocols Layer Replacement Character Network Device Block Device Process Page Cache Device Drivers Drivers Drivers Scheduling Interrupt Request (IRQ) / Dispatcher Prof. Dr. Andreas Wölfl Operating Systems and Networks 20 OPERATING SYSTEM FUNDAMENTALS 4. SYSTEM CALLS SYSTEM CALLS System Call The programmatic way in which a program requests a service from the operating system’s API (application programming interface). Examples: App 1 App 2 Start a process. Create a file. Get the current system time. System API Read from USB (e.g., inputs from a game controller). OS Kernel Transfer data over a network connection. Hardware Prof. Dr. Andreas Wölfl Operating Systems and Networks 21 SYSTEM CALLS User Programs Protection Rings: Device Drivers Hierarchical layers in CPU architecture. Device Drivers Kernel Each ring further restricts the set of instructions that are allowed to execute. HW Ensure safe execution by isolating core system functions from user-level processes. Ring 0 X86 CPUs (Intel, AMD) support 4 rings, but Ring 1 most operating systems implement just two Ring 2 Ring 3 (Ring 0 and Ring 3). Prof. Dr. Andreas Wölfl Operating Systems and Networks 22 SYSTEM CALLS Kernel Mode The most privileged operating mode, allowing direct access to all system resources, encompassing memory and hardware components. When operating in kernel mode, programs can: Execute any CPU instruction. Access any memory address. Potentially crash the system, leading to an irrecoverable halt. Prof. Dr. Andreas Wölfl Operating Systems and Networks 23 SYSTEM CALLS User Mode A less privileged mode where code execution is limited in its access to system resources, encompassing hardware and primary memory areas. In user mode, programs: Represent the majority of executed code on the computer. Utilize a subset of available CPU instructions. Lack direct access to physical memory. Depend on system calls to interact with hardware components. Prof. Dr. Andreas Wölfl Operating Systems and Networks 24 SYSTEM CALLS Classification of memory regions: Kernel Space: The memory region where the operating system operates. User Space: The memory region dedicated for user programs. → Don’t confuse Kernel Mode, Kernel Space, User Mode, and User Space. Prof. Dr. Andreas Wölfl Operating Systems and Networks 25 EXCURSUS Example: The 2024 CrowdStrike incident was caused by an faulty automatic update of a sensor software running as a driver in Kernel Mode. Damage: 10B USD. Prof. Dr. Andreas Wölfl Operating Systems and Networks 26 SYSTEM CALLS Puts the system call code into the register and Control is returned to the user executes the TRAP instruction. process User Process 1 Return from 5 User Process Kernel Trap Executing System Call Executing 2 4 User Mode System API 2 4 System Call 3 4 Implementation Store results Handler Kernel Mode Decodes the code in the register and invokes After the implementation finishes, the the corresponding implementation result values are stored in memory Prof. Dr. Andreas Wölfl Operating Systems and Networks 27 SYSTEM CALLS Example: Get the current time (C language): 1 #include 2 #include 3 4 int main(int argc, char **argv) 5 { 6 time_t current_time = time(NULL); // system call 7 printf("Current time since the Unix epoch: %ld seconds\n", current_time); 8 return 0; 9 } Prof. Dr. Andreas Wölfl Operating Systems and Networks 28 SYSTEM CALLS Example: Get the current time (JAVA language): 1 public class CurrentTimeMillis { 2 public static void main(String[] args) { 3 long currentTimeMillis = System.currentTimeMillis(); 4 System.out.println("Current time in milliseconds: " + currentTimeMillis); 5 } 6 } Note: The system call is performed by the JVM. Prof. Dr. Andreas Wölfl Operating Systems and Networks 29 OPERATING SYSTEM FUNDAMENTALS 5. VIRTUALIZATION VIRTUALIZATION Virtualization The process of creating a software-based simulation of something, such as a virtual version of computer hardware, network, or an operating system. Technical terms: A software-representation of a computer is called virtual machine (VM). The program managing and executing virtual machines is called hypervisor. The computer running the hypervisor is called host machine, short host. The computer that is virtualized is called guest, short guest. Prof. Dr. Andreas Wölfl Operating Systems and Networks 30 VIRTUALIZATION Processes Processes Processes Processes Processes Processes Processes Kernel Kernel Kernel Kernel Kernel VM 1 VM 2 VM 1 VM 2 VM 3 Hypervisor Kernel Hypervisor Kernel Hardware Hardware Hardware Single OS Type-1 Hypervisor Type-2 Hypervisor Prof. Dr. Andreas Wölfl Operating Systems and Networks 31 VIRTUALIZATION Type-1 hypervisors: Sits on top of the bare-metal machine and has direct access to the hardware. Examples: KVM, Hyper-V Type-2 hypervisors: Leverages the host operating system, issuing system calls to manage processes, save files, and more. Examples: VirtualBox, VMWare Workstation, UTM Note: Both hypervisors require specific CPU capabilities7 to prevent emulation. 7 Such as Intel VT-x or AMD-v, which can be activated through BIOS settings. Prof. Dr. Andreas Wölfl Operating Systems and Networks 32 OPERATING SYSTEM FUNDAMENTALS 6. SUMMARY SUMMARY Speed comparison: 10-7 s 1ns Referencing registers 10-8 s 10 ns Referencing main memory 10-6 s 1 μs System Call 10-5 s 10 μs Context Switches 10-4 s 100 μs Reading 1bit from SSD 10-2 s 10 ms Reading 1bit from HDD 100 s 1s Transferring 1MB over the network Prof. Dr. Andreas Wölfl Operating Systems and Networks 33 SUMMARY Summary You should have acquired the following competencies (1): Define and explain the newly introduced technical terms. Sketch the Von Neuman architecture and discuss its components. Assess different types of memory based on capacity, access speed, and cost. Recite the Machine Instruction Cycle. Prof. Dr. Andreas Wölfl Operating Systems and Networks 34 SUMMARY Summary You should have acquired the following competencies (2): Distinguish between Kernel Mode, Kernel Space, User Mode, and User Space. Explain the purpose of a system call with the help of examples. State and describe the single steps to execute a system call. Clarify the difference between type-1 and type-2 hypervisors. Create a virtual machine and set up a Linux OS. Prof. Dr. Andreas Wölfl Operating Systems and Networks 35