TDDD63 Why should I be interested in Operating Systems? Mainframe Introduction to Operating Systems Part I OS/360 IBM 360 TOPS-10 Midframe Unix MiniComputers Christoph Kessler MS-DOS Workstations DEC-20 Windows Linux IDA, Linköping University MacOSX Copyright Notice: The slides partly use material from Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, course book in TDDB68). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. IBM PC ? Sun Workstations Christoph Kessler, IDA, Linköpings universitet. A Whole New World! Smart Phones Wearable Devices 2 C. Kessler, IDA, Linköpings universitet. A Whole New Future World! Portability Connectivity Networks Sensors Smart Vehicles Smart Highways Smart Cities Smart Homes / Smart El-Grids The current 7Series BMW and S-class Mercedes boast about 100 processors apiece. A relatively lowprofile Volvo still has 50 to 60 baby processors on board. 3 C. Kessler, IDA, Linköpings universitet. Increase in Hardware Complexity “Moore’s Law” (prediction 1965): #Transistors / mm2 doubles every ~2 years. Still holds today! Source: Intel NSC’s cluster supercomputer “Triolith” (TDDC78) C. Kessler, IDA, Linköpings universitet. 4 Increase in Software Complexity Need for new types of interfacing to hardware • Multiprocessor servers • Hardware multithreading • Multicore CPUs • Many-Core CPUs • Accelerators e.g. GPGPU • Hybrid computing • Clusters • Cloud servers •… C. Kessler, IDA, Linköpings universitet. Need for new types of OS Architectures Nvidia Tesla GPU 5 C. Kessler, IDA, Linköpings universitet. 6 1 Agenda Lecture I: Computer Systems Overview Building and Executing Programs Operating System Basics Computer Systems Lecture II: Interrupts and I/O System Calls Overview CPU Management Memory Management Copyright Notice: The slides partly use material from Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, course book in TDDB68). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. File System Protection and Security Christoph Kessler, IDA, Linköpings universitet. 7 C. Kessler, IDA, Linköpings universitet. Computer Systems and Environments Stand-alone desktop computer Stand-alone desktop computer PC, workstation: Computer system dedicated mainly to a single user. Client-server systems Parallel systems I/O devices: keyboards, mice, screens, small printers. Clustered systems Requirement: User convenience and responsiveness. Distributed systems Can adopt technology developed for larger operating system Real-time systems May run several different types of operating systems Handheld systems (Windows, MacOS, UNIX, Linux) 9 C. Kessler, IDA, Linköpings universitet. 10 C. Kessler, IDA, Linköpings universitet. Client-Server Computing Parallel Systems (1) Servers respond to requests by clients Multiprocessor systems with more than one CPU in close communication. Remote procedure call – also across machine boundaries via network but machines can be dedicated to one or few such roles, e.g. Compute server: compute an action requested by the client 11 processors share memory and a clock; communication usually takes place through the shared memory. Advantages of parallel systems: File server: Interface to file system (read, create, update, delete) C. Kessler, IDA, Linköpings universitet. (multi-core) Tightly coupled system (aka. shared-memory system, multiprocessor) Client/Server are mainly software roles, Today the default, even for desktop machines Increased throughput Economical Scalability of performance Multiprocessor system vs multiple single-processor system (reduction of hardware such as disks, controllers etc) Increased reliability graceful degradation (fault tolerance, …) fail-soft systems (replication, …) C. Kessler, IDA, Linköpings universitet. 12 2 Hardware Multithreading, Multi-Core Parallel Systems (2) Symmetric multiprocessing (SMP) SMP architecture Each processor runs an identical copy of the operating system. Many processes can run at once without performance deterioration. Most modern operating systems support SMP 2 hardware threads per core P0 P1 L1$ D1$ L1$ D1$ 2 cores per CPU chip L2$ Asymmetric multiprocessing Each processor is assigned a specific task; a master processor schedules and allocates work to slave processors. More common in special-purpose systems (e.g., embedded MP-SoC) Memory Ctrl Appears to the OS like 4 standard processors Main memory Intel Xeon Dualcore(2005) Remark: the notion of “processor” is relative: A traditional PC is normally considered to only have one CPU, but it usually has a graphics processor, a communication processor etc, and this is not considered a multi-processing system. 13 C. Kessler, IDA, Linköpings universitet. Parallel Systems (3) C. Kessler, IDA, Linköpings universitet. 14 Parallel Computing Systems Speed-up of a single application by parallel processing? Requires parallelisation / restructuring of the program Or explicitly parallel algorithms Used in High-Performance Computing for numerically intensive applications (weather forecast, simulations, ...) Now ubiquitous problem due to switch to multicore/manycore CPUs Multicomputer (”distributed memory parallel computer”) loosely coupled can be a more economic and scalable alternative to SMP’s but more cumbersome to program (message passing) Example: ”Beowulf ” Clusters More in TDDC78 – Programming parallel computers NSC Triolith C. Kessler, IDA, Linköpings universitet. 15 Clustered Systems Loosely coupled system but multiple systems (servers) working together Often using a high-speed interconnect between servers (e.g. Infiniband) Usually sharing external mass storage via a storage-area network (SAN) Provides a high-availability/reliability service which survives failures each processor has its own local memory processors communicate with one another through various communications lines, such as high-speed buses or telephone lines (LAN, WAN, MAN, Bluetooth, …). Distribute the computation among several physical processors. Asymmetric clustering - one server runs the application while other servers are in hot-standby mode Symmetric clustering - has multiple nodes running the same application, monitoring each other Resource sharing Some clusters are used for high-performance computing (HPC) Computation speed up Adaptivity: load sharing (migration of jobs) Fault tolerance Advantages of distributed systems: Applications must be written to use parallelization HPC clusters: MPI (Message-Passing Interface) TDDC78 Data centers: Mapreduce / Hadoop C. Kessler, IDA, Linköpings universitet. 16 Distributed Systems (1) Like multiprocessor systems, C. Kessler, IDA, Linköpings universitet. 17 May be either client-server or peer-to-peer systems C. Kessler, IDA, Linköpings universitet. 18 3 Distributed Systems (2) Distributed Computing Systems Network Operating System provides file sharing, e.g., NFS - Network File System provides communication scheme runs independently from other computers on the network Distributed Operating System less autonomy between computers gives the impression that there is a single operating system controlling the network. More about this in TDDD25 Distributed Systems 19 C. Kessler, IDA, Linköpings universitet. 20 C. Kessler, IDA, Linköpings universitet. Real-Time Systems Handheld Systems Often used as a control device in a dedicated application such as Personal Digital Assistants (PDAs), iPADs etc. controlling scientific experiments, medical imaging systems, industrial control systems, and some display systems. Cellular telephones Well-defined tasks with fixed time constraints. Issues: Limited Hard real-time systems. Conflicts with time-sharing systems, not supported by general-purpose OSs. TDD B63 – O perating Syste m Concepts – Slow A. Be d n a rs ki 1.5-1.9GHz display screens Limited Limited utility in industrial control or robotics Useful in applications (multimedia, virtual reality) requiring advanced OS features. Iphone 5S Shipping with 2GB-4GB RAM? processors Small Soft real-time systems memory battery lifetime More in TDDD07 Real-time Systems 21 C. Kessler, IDA, Linköpings universitet. C. Kessler, IDA, Linköpings universitet. 22 Before talking about OS, … … a short note on programming languages suitable for system programming Before talking about Operating Systems… Early operating systems were implemented in assembly language (and some low-level parts of modern OS still are). Necessary for direct access to hardware devices Since the 1970s the dominating language for system programming is C. Copyright Notice: The slides partly use material from Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, course book in TDDB68). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Christoph Kessler, IDA, Linköpings universitet. Also used a lot in high-performance and embedded computing Today, no new microprocessor ships without a C compiler. Many “high-level” programming languages are compiled to C. You will need C for programming labs in later courses Operating systems, Compiler construction, Parallel programming, Multicore/GPU programming, Realtime systems, Embedded systems, … C. Kessler, IDA, Linköpings universitet. 24 4 Java vs. C Java A Short History of C C C was developed in the early 1970’s by Dennis Ritchie at Bell Labs For application programming only For system programming mainly Design goals: Design goals: Programmer productivity Safety Hardware completely hidden Comfortable E.g. automatic memory management Protection (to some degree) Objective: structured but flexible programming language e.g. for writing device drivers or operating systems Used for implementing the Unix OS Book 1978 by Brian Kernighan and Dennis Ritchie (”K&R-C”) ”ANSI-C” 1989 standard by ANSI (”C89”) Direct control of hardware High performance / real-time Minimalistic design Less comfortable Little protection ”low-level” The C standard for many programmers (and compilers...) Became the basis for standard C++ Java borrowed much of its syntax The GNU C compiler implemented a superset (”GNU-C”) ”C99” standard by ISO, only minor changes E.g., array bound checking ”C11” (ISO) – multithreading support added Slow Time-unpredictable 25 C. Kessler, IDA, Linköpings universitet. … 26 C. Kessler, IDA, Linköpings universitet. The Compilation Workflow How to build and execute programs on a real computer /* file hello.c */ #include <stdio.h> int main() { printf("hello, world\n"); } Copyright Notice: The slides partly use material from Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, course book in TDDB68). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Christoph Kessler, IDA, Linköpings universitet. C. Kessler, IDA, Linköpings universitet. Preprocessing Phase 28 Compilation Phase C Preprocessor (cpp): modifies the original C source program according to directives that begin with the # character. Compilation Phase (cc1): Translate the text file hello.i into the text file hello.s. hello.s contains an assembly-language program Each statement in an assembly language program exactly describes one low-level machine language instruction in a standard text form. #include <stdio.h> tells the processor to read the contents of the system header file stdio.h and insert it directly into the program text. Fortran compiler C compiler Output is another C source program, typically with the .i suffix. C. Kessler, IDA, Linköpings universitet. .file "hello.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "hello, world" .text .p2align 4,,15 .globl main .type main, @function main: pushl%ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts leave xorl %eax, %eax ret .size main, .-main Assembly language 29 C. Kessler, IDA, Linköpings universitet. Assembly language provides a common output language for different compilers main: pushl movl subl andl subl movl call leave xorl ret %ebp %esp, %ebp $8, %esp $-16, %esp $16, %esp $.LC0, (%esp) puts %eax, %eax 30 5 hello.s Assembly Phase (in x86 assembler language) .file "hello.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "hello, world" .text .p2align 4,,15 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts leave xorl%eax, %eax ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)" Assembler (as): translates the text-based assembly program into machine language instructions, packages them in a form known as a relocatable object program, and stores the result in the object file hello.o a4 f0 dd 07 7c 65 a6 b2 06 0f c3 dd a2 ff bd 87 … hello.o is a binary file (object file) whose bytes encode machine instructions and -data rather than characters. Binary files use a system-specific binary file format, e.g. ELF, COFF. 31 C. Kessler, IDA, Linköpings universitet. 32 C. Kessler, IDA, Linköpings universitet. Linking Phase Calling the entire toolchain Linker (ld): merges pre-compiled object files to a single one. The result is an executable object file that is ready to be loaded into memory (using the OS loader) and executed by the system. E.g., gcc hello.c –o hello (here, for the GNU C compiler gcc) calls cpp, cc1, as, ld for single-module program hello.c The hello program uses the printf function, which is part of the standard C library. This function resides in a separate precompiled object file (e.g. printf.o or in libc.a) that has to be merged with hello.o. Also some additional code and data (program startup code, C runtime system, etc., in libc.a) is added by the linker. For automatizing the build process of multi-module programs, building-tools like make or IDEs like ECLIPSE are convenient. 33 C. Kessler, IDA, Linköpings universitet. Compiling and Linking Running an Executable Program for Multi-Module C Programs stdio.h glob.h xy.h #include abc.c #include mymain.c mymain.o #include int main() { printf("hello, world\n"); } def.c Preprocess Compile Assemble Link def.o hello libc.a link a.out (executable) C. Kessler, IDA, Linköpings universitet. In a Unix system, a shell is an application program which is a command line interpreter /* hello.c */ #include <stdio.h> preprocess compile + asm abc.o 34 C. Kessler, IDA, Linköpings universitet. Executable Object File (binary) C run-time library is linked with the user code 35 C. Kessler, IDA, Linköpings universitet. The shell prints a prompt, waits for the user to type in a command and then performs the command. unix> ./hello Input hello, world Output unix> If it is not a built-in shell command, then the shell assumes it is an executable file and that it should load and run it. 36 6 Running the hello Program Running the hello program When the enter key is hit on the keyboard, the shell knows that we have finished typing the command. As the characters ./hello are typed at the keyboard, the shell program reads each one into a register and then it is stored in memory The shell then calls the OS to allocate memory and load the executable file. The loader copies the code and data in the hello object file from disk to main memory. Loading the executable from disk into main memory Reading the hello command from the keyboard 37 C. Kessler, IDA, Linköpings universitet. Using a technique called Direct Memory Access (DMA) the data travels directly from the disk to the main memory without passing through the processor. 38 C. Kessler, IDA, Linköpings universitet. Running the hello program Once the code and data in the hello object file are loaded into memory the processor begins executing the machine instructions in the hello program’s main routine main: pushl movl subl andl subl movl call leave xorl ret Writing the output string from memory to the display C. Kessler, IDA, Linköpings universitet. OS Basics %ebp %esp, %ebp $8, %esp $-16, %esp $16, %esp $.LC0, (%esp) puts %eax, %eax These instructions copy the bytes in the “hello, world” string from memory to the register file and from there to the display device where they are displayed on the screen 39 Copyright Notice: The slides partly use material from Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, course book in TDDB68). No part of the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University. Christoph Kessler, IDA, Linköpings universitet. What is an Operating System (OS)? What is an Operating System (OS)? A program that acts as an intermediary An operating system provides an environment between a user of a computer and the computer hardware. within which other programs can do useful work; the OS does not perform any “useful” function itself. Operating system goals: Execute user programs in a well-defined environment. Make application software portable and not tied to a specific machine Make the computer system convenient to use. Administrate system resources. Improves overall system reliability Enable efficient use of the computer hardware Provides protection mechanisms for user programs and files and security against possible threats from within and outside the system hiding low-level and implementational detail error confinement, fault tolerance, reconfiguration... support parallel activity, avoid wasted CPU cycles... C. Kessler, IDA, Linköpings universitet. 41 C. Kessler, IDA, Linköpings universitet. 42 7 Operating Systems Where are OSs found? General purpose systems Microprocessor market shares in 1999 Embedded systems 99% 1% C. Kessler, IDA, Linköpings universitet. 43 Operating System Definition Manages all resources of a computer system Decides between conflicting requests for efficient and fair resource use 44 Hardware provides basic computing resources CPU, memory, I/O devices Operating system controls and coordinates use of hardware among various applications and users Controls execution of programs to prevent errors and improper use of the computer Application programs No universally accepted definition define the ways in which the system resources are used to solve the computing problems of the users “The one program running at all times on the computer” is called the kernel. Everything else is either a system program (ships with the operating system) or an application program. C. Kessler, IDA, Linköpings universitet. Application specific operating systems, e.g. mobile OS, real-time OS Android iOS Symbian Windows CE, Mobile, Phone Embedded Linux RT-Linux VxWorks OSE QNX ...IDA, Linköpings universitet. C. Kessler, Computer system can be divided into 4 components: OS is a control program General purpose operating systems Unix incl. variants, such as Sun/Oracle Solaris, HP-UX Linux Windows 95/98/2000, NT/XP/Vista/7/8/10/… Mac OS X … Computer System Structure OS is a resource allocator (A Selection) Word processors, compilers, web browsers, database systems, games Users 45 People, machines, other computers C. Kessler, IDA, Linköpings universitet. 46 Agenda Lecture I: Computer Systems Overview Building and Executing Programs Operating System Basics Lecture II: Interrupts and I/O System Calls CPU Management Memory Management File System Protection and Security C. Kessler, IDA, Linköpings universitet. 47 8