Linux Overview Anand Sivasubramaniam Dept. of Computer Science & Eng. The Pennsylvania State University.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Genesis: from raw hardware to processes System booting sequence: how does a machine come into life.
Chapter 6 Limited Direct Execution
Features of Intel Processor Architectures that Lend to Operating System Design Jim Snyder.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Introduction to Kernel
Process management in Minix1 Processes Process is a program in execution. Program is a static entity while process is an active entity. Process Control.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Real-time Systems The Linux kernel. The Operating System Kernel Resident in memory, privileged mode System calls offer general purpose services.
OS Spring’03 Introduction Operating Systems Spring 2003.
Figure 1.1 Interaction between applications and the operating system.
Cs238 Lecture 3 Operating System Structures Dr. Alan R. Davis.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
OS Spring’04 Introduction Operating Systems Spring 2004.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
hardware and operating systems basics.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 1: Introduction.
System Calls 1.
Protection and the Kernel: Mode, Space, and Context.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
ICOM Noack Operating Systems - Administrivia Prontuario - Please time-share and ask questions Info is in my homepage amadeus/~noack/ Make bookmark.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3: Operating Systems Computer Science: An Overview Tenth Edition.
From UEFI Shell to Linux - UEFI Linux BootLoader Zhang Rui Software Engineer Sep 28 th 2011.
Introduction to Operating Systems Chapter 1. cs431 -cotter2 Lecture Objectives Understand the relationship between computing hardware, operating system,
2001 Networking Operating Systems (CO32010) 1. Operating Systems 2. Processes and scheduling 3.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview Part 2: History (continued)
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
LINUX System : Lecture 7 Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
System Calls. The Linux we use is: Linux-Mandrake 7.0. In this project, you are going to change some kernel files and recompile the kernel. After you.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
1.4 Hardware Review. CPU  Fetch-decode-execute cycle 1. Fetch 2. Bump PC 3. Decode 4. Determine operand addr (if necessary) 5. Fetch operand from memory.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
MINIX Presented by: Clinton Morse, Joseph Paetz, Theresa Sullivan, and Angela Volk.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
File System Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki CS 314.
CSNB334 Advanced Operating Systems 3. Kernel Structure and Organization Lecturer: Abdul Rahim Ahmad.
Lecture 7 Interrupt ,Trap and System Call
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems Concepts
Introduction to Kernel
Kernel Design & Implementation
Interrupts and signals
Protection of System Resources
Modeling Page Replacement Algorithms
Modeling Page Replacement Algorithms
Linux Architecture Overview.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Outline Operating System Organization Operating System Examples
System Calls System calls are the user API to the OS
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Linux Overview Anand Sivasubramaniam Dept. of Computer Science & Eng. The Pennsylvania State University

Why Linux? It’s free! Open Source (modifiability, extensibility, …) Works on several platforms Robustness (after several revisions, and several people working on it) Widespread Usage Compatibility with several other platforms.

Coverage from … M. Beck, H. Bohme, M. Dziadzka, U. Kunitz, R. Magnus, D. Verworner. Linux Kernel Internals, 2 nd edition, Addison-Wesley. R. Card, E. Dumas, F. Mevel. The Linux Kernel book. John-Wiley. Mainly Linux 2.0

Linux Features Monolithic kernel (but well-defined interfaces) Multi-tasking Multi-user capability Multi-processing Support (since 2.0) Architecture Independence (PCs, Alpha, Sparc,…) Demand loaded executables (on fork, shared address space, and copy-on- write) 4K Pages, demand-paging with memory protection Dynamic size for disk cache Shared Libraries (dll) Support for Posix standard Several Executables formats Several File Systems (Ext2) Several network protocols

/usr/src/linux hierarchy linux mmnet kernel initlibincludeipcarchdriversfs fat vfat nfs minix msdos ext ext2 proc... unix ipv4 ipv6 core... net char block pci scsi sound video cdrom sparc... sparc64 alpha i386 mips linux net scsi video asm-arch

arch/* contains architecture specific code arch/i386/boot contains init code (in assembly) to initialize h/w, load the kernel, install ISRs, switch to protected mode and then calls start_kernel(void) in init/ Kernel/ and arch/i386/kernel/ contain the core kernel code (fork,scheduler, timers, DMA and interrupt management, signal handling, switching protection modes) VM system, memory allocation, paging are in mm/ and arch/i386/mm. The virtual file system interface is in /fs, and the subdirectories contain respective file systems drivers/ contains different drivers. ipc/ has sources for IPC (semaphores, shared memory, message queues) net/ has different protocol codes lib/ contains standard C libraries Include/ and asm/include have the necessary include files with /usr/include having links to these.

Building Make config (reads arch/i386/config.in file, to find out which components to include, which inturn consults config.in in other directories. Config.in contains directives on what packages to include. Make depend Make boot (gives a bootable kernel arch/i386/boot/zImage). Make bzlilo (copies bootable kernel to /vmlinuz and the kernel can then be installed using LILO) Make drivers (to just compile drivers) Make modules (file systems and drivers not linked in can be created as modules) Make modules_install (the created modules are installed in the /lib/modules/kernel_version directory)

Booting On power up, CPU is reset and PC is set to a certain value in the BIOS ROM. BIOS does hardware tests and initializations. BIOS tries to read first sector (boot sector) of disk (first floppy then HD) This sector is read into memory and is of a pre-determined format –0x000 Jmp xxx –0x003 Disk Params –0x03E Code –0x1BE Partition 1 entry –0x1CE Partition 2 entry –0x1DE Partition 3 entry –0x1EE Partition 4 entry –0x1FE Magic Number PC is then set to the first location, which then goes to the code that checks which is he active partition. That entry has the sector number of the boot block of that partition which looks similar and has the code to boot that OS (part of LILO for Linux).

After loading the kernel, it jumps to arch/i386/boot/setup.S (start) This code initializes and establishes hardware, and then switches to Protected Mode by setting a bit in the machine Status Word. Executes “jmp 0x1000, KERNEL_CS” Goes to arch/i386/kernel/head.S (startup_32:) This does MMU, coprocessor and interrupt descriptor initializations, and sets the environment for the kernel C functions. Subsequently start_kernel() in init/main.c is called.

Start_kernel(void) { Memory_start = paging_init(memory_start,memory_end); Trap_init(); Init_IRQ(); Sched_init(); Time_init() Parse_options(command_line); Init_modules(); Memory_start = console_init(memory_start,memory_end); Memory_start= pci_init(memory_start,memory_end); Memory_start = kmalloc_init(memory_start,memory_end); Sti(); Memory_start=inode_init(memory_start,memory_end); Memory_start=file_table_init(memory_start,memory_end); Memory_start=name_cache_init(memory_start,memory_end); Mem_init(memory_start,memory_end); Buffer_init(); Sock_init(); Ipc_init(); …

Process 0 is now running. It generates a kernel thread which executes the init function Kernel_thread(init,NULL,0); Process 0 executes idle process: Cpu_idle(NULL); Init() { kernel_thread(bdflush,NULL,0); // buffer cache sync daemon kernel_thread(kswapd,NULL,0); // swap daemon setup(); // init file sys, and mount root … open console, file descriptors 0, 1 and 2 … execve(“…../init”,argv_init,envp_init); // getty runs on each tty }

Adding a System Call show_mult(x, y, *z) Each sys call has a name and a number Go to /asm/unistd.h: #define __NR_sched_r_get_interval 161 #define __NR_nanosleep 162 #define __NR_mremap 163 #define __NR_show_mult 164 Go to arch/i386/kernel/entry.S.long SYMBOL_NAME(sys_nanosleep).long SYMBOL_NAME(sys_mremap).long SYMBOL_NAME(sys_show+mult).space (NR_syscalls-164)*4 // padding

Now to add the code for the syscall, say in /sys.c (which has other syscalls) asmlinkage int sys_show_mult(int x, int y, int *res) { int error, compute; error = verify_area(VERIFY_WRITE, res, sizeof(*res)); if (error) return error; compute = x*y; put_user(compute,res); printk(“Value computed”); return 0; } Compile kernel and reboot the machine.

How do you use this? If it is already defined in a library, then fine. Else, you can use a macro definition _syscall3 (int, show_mult, int, x, int, y, int *, resul); Which expands as: int show_mult(int x, int y, int *resul) { long __res; __asm__ __volatile (“int $0x80” : “=a” (__res) “0” (164), “b” ((long) (x)), “c” ((long) (y)), “d” ((long) (resul))); if (__res>=0) return (int) __res; errno = -__res; return –1; } Which places sys call # in eax register, parameters in ebx, ecx and edx, and then invokes software interrupt 0x80.

Upon this trap, the function system_call in arch/i386/kernel/entry.S is invoked. This uses the syscall # (in eax) to index the table sys_call_table, to call the corresponding function. User program is as follows: #include _syscall3 (int, show_mult, int, x, int, y, int *, resul); main() { int ret=0; show_mult(2, 5, &ret); }

What happens on a syscall? On the software interrupt (0x80), the control is transferred to system_call() in arch/i386/kernel/entry.S Here is what goes on inside this routine … SAVE_ALL; // saves registers … *sys_call_table[sys_call_num](sys_call_args); … if (intr_count) goto exit_now // nested interrupts if (bh_mask & bh_active) { ++intr_count; Sti(); Do_bottom_half(); --intr_count; } sti();

if (need_resched) { schedule();// return much later! goto ret_from_sys_call; } … if (current->signal & ~current->blocked) do_signal(); … exit_now: RESTORE ALL; // return using iret

Basics of Interrupt Handling In arch/i386/kernel/irq.c and include/asm/irq.h Three types of interrupts: Fast, Slow, System Calls (software) Slow Interrupts (typical), turn off interrupts only for a little while. E.g. timer SLOW_IRQ(intr_num, intr_controller, intr_mask) { SAVE_ALL; // macro in include/asm/irq.h ENTER_KERNEL; // exclusive execn. In kernel – for SMP ACK(intr_controller,intr_mask); ++intr_count; // nesting depth Sti(); // enable interrupts Do_IRQ(intr_num, Register); // do actual ISR Cli(); UNBLK(intr_controller,intr_mask); --intr_count; Ret_from_sys_call(); }

FAST_IRQ(intr_num,intr_controller,intr_mask) { SAVE_MOST; // macro in include/asm/irq.h ENTER_KERNEL; ACK(intr_controller,intr_mask); ++int_count; Do_fast_IRQ(intr_num); UNBLK(intr_controller,intr_mask); --intr_count; LEAVE_KERNEL RESTORE_MOST; }

Timer Interrupt 1 tick = 10 ms, 100 interrupts every second