The Linux Kernel: Introduction

1y ago
17 Views
2 Downloads
1.32 MB
25 Pages
Last View : 19d ago
Last Download : 3m ago
Upload by : Gannon Casey
Transcription

The Linux Kernel:IntroductionCS591 (Spring 2001)HistorynnnnnnnnnUNIX: 1969 Thompson & Ritchie AT&T Bell Labs.BSD: 1978 Berkeley Software Distribution.Commercial Vendors: Sun, HP, IBM, SGI, DEC.GNU: 1984 Richard Stallman, FSF.POSIX: 1986 IEEE Portable Operating System unIX.Minix: 1987 Andy Tannenbaum.SVR4: 1989 AT&T and Sun.Linux: 1991 Linus Torvalds Intel 386 (i386).Open Source: GPL.CS591 (Spring 2001)1

Linux FeaturesnnUNIX-like operating system.Features:n Preemptive multitasking.n Virtual memory (protected memory, paging).n Shared libraries.n Demand loading, dynamic kernel modules.n Shared copy-on-write executables.n TCP/IP networking.n SMP support.n Open source.CS591 (Spring 2001)What’s a Kernel?nnnnnnnAKA: executive, system monitor.Controls and mediates access to hardware.Implements and supports fundamental abstractions:n Processes, files, devices etc.Schedules / allocates system resources:n Memory, CPU, disk, descriptors, etc.Enforces security and protection.Responds to user requests for service (system calls).Etc etc CS591 (Spring 2001)2

Kernel Design GoalsnnnnnnPerformance: efficiency, speed.n Utilize resources to capacity with low overhead.Stability: robustness, resilience.n Uptime, graceful degradation.Capability: features, flexibility, compatibility.Security, protection.n Protect users from each other & system from badusers.Portability.Extensibility.CS591 (Spring 2001)Example “Core” KernelApplicationsSystem Libraries (libc)ModulesSystem Call InterfaceI/O RelatedFile SystemsProcess RelatedSchedulerNetworkingMemory ManagementDevice DriversIPCArchitecture-Dependent CodeHardwareCS591 (Spring 2001)3

Architectural o-kernel.Virtual machine.CS591 (Spring 2001)Linux Source Tree i2ci2oideieee1394isdnmacintoshmiscnet evptsefsext2fathfshpfs kasm-mipsasm-mips64linuxmath-emunetpcmciascsivideo t2fathfshpfs pv4ipv6ipxirdakhttpdlapb CS591 (Spring 2001)4

linux/archnnnnSubdirectories for each current port.Each contains kernel, lib, mm, boot and otherdirectories whose contents override code stubs inarchitecture independent code.lib contains highly-optimized common utility routinessuch as memcpy, checksums, etc.arch as of 2.4:n alpha, arm, i386, ia64, m68k, mips, mips64.n ppc, s390, sh, sparc, sparc64.CS591 (Spring 2001)linux/driversnnnnnnnnnLargest amount of code in the kernel tree ( 1.5M).device, bus, platform and general directories.drivers/char – n tty.c is the default line discipline.drivers/block – elevator.c, genhd.c, linear.c, ll rw blk.c, raidN.c.drivers/net –specific drivers and general routines Space.c andnet init.c.drivers/scsi – scsi *.c files are generic; sd.c (disk), sr.c (CDROM), st.c (tape), sg.c (generic).General:n cdrom, ide, isdn, parport, pcmcia, pnp, sound, telephony,video.Buses – fc4, i2c, nubus, pci, sbus, tc, usb.Platforms – acorn, macintosh, s390, sgi.CS591 (Spring 2001)5

linux/fsnnContains:n virtual filesystem (VFS) framework.n subdirectories for actual filesystems.vfs-related files:n exec.c, binfmt *.c - files for mapping new process images.n devices.c, blk dev.c – device registration, block devicesupport.n super.c, filesystems.c.n inode.c, dcache.c, namei.c, buffer.c, file table.c.n open.c, read write.c, select.c, pipe.c, fifo.c.n fcntl.c, ioctl.c, locks.c, dquot.c, stat.c.CS591 (Spring 2001)linux/includennninclude/asm-*:n Architecture-dependent include subdirectories.include/linux:n Header info needed both by the kernel and user apps.n Usually linked to /usr/include/linux.n Kernel-only portions guarded by #ifdefsn #ifdef KERNELn/* kernel stuff */n #endifOther directories:n math-emu, net, pcmcia, scsi, video.CS591 (Spring 2001)6

linux/initnnnnJust two files: version.c, main.c.version.c – contains the version banner that prints atboot.main.c – architecture-independent boot code.start kernel is the primary entry point.CS591 (Spring 2001)linux/ipcnnnSystem V IPC facilities.If disabled at compile-time, util.c exports stubs thatsimply return –ENOSYS.One file for each facility:n sem.c – semaphores.n shm.c – shared memory.n msg.c – message queues.CS591 (Spring 2001)7

linux/kernelnnnnnThe core kernel code.sched.c – “the main kernel file”:n scheduler, wait queues, timers, alarms, task queues.Process control:n fork.c, exec.c, signal.c, exit.c etc Kernel module support:n kmod.c, ksyms.c, module.c.Other operations:n time.c, resource.c, dma.c, softirq.c, itimer.c.n printk.c, info.c, panic.c, sysctl.c, sys.c.CS591 (Spring 2001)linux/libnnkernel code cannot call standard C library routines.Files:n brlock.c – “Big Reader” spinlocks.n cmdline.c – kernel command line parsing routines.n errno.c – global definition of errno.n inflate.c – “gunzip” part of gzip.c used during boot.n string.c – portable string code.n Usually replaced by optimized, architecturedependent routines.n vsprintf.c – libc replacement.CS591 (Spring 2001)8

linux/mmnnnPaging and swapping:n swap.c, swapfile.c (paging devices), swap state.c (cache).n vmscan.c – paging policies, kswapd.n page io.c – low-level page transfer.Allocation and deallocation:n slab.c – slab allocator.n page alloc.c – page-based allocator.n vmalloc.c – kernel virtual-memory allocator.Memory mapping:n memory.c – paging, fault-handling, page table code.n filemap.c – file mapping.n mmap.c, mremap.c, mlock.c, mprotect.c.CS591 (Spring 2001)linux/scriptsnScripts for:n Menu-based kernel configuration.n Kernel patching.n Generating kernel documentation.CS591 (Spring 2001)9

SummarynnnnLinux is a modular, UNIX-like monolithic kernel.Kernel is the heart of the OS that executes withspecial hardware permission (kernel mode).“Core kernel” provides framework, data structures,support for drivers, modules, subsystems.Architecture dependent source sub-trees live in /arch.CS591 (Spring 2001)Booting and KernelInitializationCS591 (Spring 2001)10

System Lifecycle: Ups & wnCS591 (Spring 2001)Boot TerminologynLoader:Program that moves bits from disk (usually)to memory and then transfers CPU control to the newly“loaded” bits (executable).nnBootloader / Bootstrap:nnBoot PROM / PROM Monitor / BIOS:nnProgram that loads the “first program” (the kernel).Persistent code that is “already loaded” on power-up.Boot Manager:nProgram that lets you choose the “first program” to load.CS591 (Spring 2001)11

LILO: LInux LOadernnnA versatile boot manager that supports:n Choice of Linux kernels.n Boot time kernel parameters.n Booting non-Linux kernels.n A variety of configurations.Characteristics:n Lives in MBR or partition boot sector.n Has no knowledge of filesystem structure so n Builds a sector “map file” (block map) to find kernel./sbin/lilo – “map installer”.n /etc/lilo.conf is lilo configuration file.CS591 (Spring 2001)Example lilo.conf Fileboot /dev/hdamap /boot/mapinstall /boot/boot.bprompttimeout 50default linuximage /boot/vmlinuz-2.2.12-20label linuxinitrd /boot/initrd-2.2.12-20.imgread-onlyroot /dev/hda1CS591 (Spring 2001)12

/sbin/initnnnAncestor of all processes (except idle/swapperprocess).Controls transitions between “runlevels”:n 0: shutdownn 1: single-usern 2: multi-user (no NFS)n 3: full multi-usern 5: X11n 6: rebootExecutes startup/shutdown scripts for each runlevel.CS591 (Spring 2001)ShutdownnnnnUse /bin/shutdown to avoid data loss and filesystemcorruption.Shutdown inhibits login, asks init to send SIGTERMto all processes, then SIGKILL.Low-level commands: halt, reboot, poweroff.n Use -h, -r or -p options to shutdown instead.Ctrl-Alt-Delete “Vulcan neck pinch”:n defined by a line in /etc/inittab.n ca::ctrlaltdel:/sbin/shutdown -t3 -r now.CS591 (Spring 2001)13

Advanced Boot ConceptsnInitial ramdisk (initrd) – two-stage boot for flexibility:n First mount “initial” ramdisk as root.n Execute linuxrc to perform additional setup, configuration.n Finally mount “real” root and continue.n See Documentation/initrd.txt for details.n Also see “man initrd”.nNet booting:n Remote root (Diskless-root-HOWTO).n Diskless boot (Diskless-HOWTO).CS591 (Spring 2001)SummarynnnnnBootstrapping a system is a complex, device-dependentprocess that involves transition from hardware, to firmware, tosoftware.Booting within the constraints of the Intel architecture isespecially complex and usually involves firmware support(BIOS) and a boot manager (LILO)./sbin/lilo is a “map installer” that reads configuration informationand writes a boot sector and block map files used during boot.start kernel is Linux “main” and sets up process context beforespawning process 0 (idle) and process 1 (init).The init() function performs high-level initialization beforeexec’ing the user-level init process.CS591 (Spring 2001)14

System CallsCS591 (Spring 2001)System CallsnnnnInterface between user-level processes andhardware devices.n CPU, memory, disks etc.Make programming easier:n Let kernel take care of hardware-specific issues.Increase system security:n Let kernel check requested service via syscall.Provide portability:n Maintain interface but change functionalimplementation.CS591 (Spring 2001)15

POSIX APIsnnnnAPI Application Programmer Interface.n Function defn specifying how to obtain service.n By contrast, a system call is an explicit request to kernelmade via a software interrupt.Standard C library (libc) contains wrapper routines that makesystem calls.n e.g., malloc, free are libc routines that use the brk systemcall.POSIX-compliant having a standard set of APIs.Non-UNIX systems can be POSIX-compliant if they offer therequired set of APIs.CS591 (Spring 2001)Linux System Calls (1)Invoked by executing int 0x80.n Programmed exception vector number 128.n CPU switches to kernel mode & executes a kernelfunction.n Calling process passes syscall number identifyingsystem call in eax register (on Intel processors).n Syscall handler responsible for:n Saving registers on kernel mode stack.n Invoking syscall service routine.n Exiting by calling ret from sys call().CS591 (Spring 2001)16

Linux System Calls (2)nSystem call dispatch table:n Associates syscall number with correspondingservice routine.n Stored in sys call table array having up toNR syscall entries (usually 256 maximum).nnth entry contains service routine address ofsyscall n.CS591 (Spring 2001)Initializing System Callsntrap init() called during kernel initialization setsup the IDT (interrupt descriptor table) entrycorresponding to vector 128:n set system gate(0x80, &system call);nA system gate descriptor is placed in the IDT,identifying address of system call routine.nnDoes not disable maskable interrupts.Sets the descriptor privilege level (DPL) to 3:n Allows User Mode processes to invokeexception handlers (i.e. syscall routines).CS591 (Spring 2001)17

The system call() FunctionnnnnSaves syscall number & CPU registers used byexception handler on the stack, except thoseautomatically saved by control unit.Checks for valid system call.Invokes specific service routine associated withsyscall number (contained in eax):n call *sys call table(0, %eax, 4)Return code of system call is stored in eax.CS591 (Spring 2001)Parameter PassingnOn the 32-bit Intel 80x86:n 6 registers are used to store syscall parameters.n eax (syscall number).n ebx, ecx, edx, esi, edi store parameters tosyscall service routine, identified by syscallnumber.CS591 (Spring 2001)18

Wrapper RoutinesnnnKernel code (e.g., kernel threads) cannot use libraryroutines.syscall0 syscall5 macros define wrapperroutines for system calls with up to 5 parameters.e.g., syscall3(int,write,int,fd,const char *,buf,unsigned int,count)CS591 (Spring 2001)Example: “Hello, world!”.data# section declarationmsg:.string "Hello, world!\n"len . - msg.text# our dear string# length of our dear string# section declaration.global start# we must export the entry point to the ELF linker or# loader. They conventionally recognize start as their# entry point. Use ld -e foo to override the default.start:# write our string to stdoutmovlmovlmovlmovlint len,%edx msg,%ecx 1,%ebx 4,%eax 0x80#####third argument: message lengthsecond argument: pointer to message to writefirst argument: file handle (stdout)system call number (sys write)call kernel 0,%ebx 1,%eax 0x80# first argument: exit code# system call number (sys exit)# call kernel# and exitmovlmovlintCS591 (Spring 2001)19

Linux Files Relating to SyscallsnMain files:n arch/i386/kernel/entry.Sn System call and low-level fault handlingroutines.n include/asm-i386/unistd.hn System call numbers and macros.n kernel/sys.cn System call service routines.CS591 (Spring 2001)arch/i386/kernel/entry.S.dataENTRY(sys call table).long SYMBOL NAME(sys ni syscall) /* 0 call*/.long SYMBOL NAME(sys exit).long SYMBOL NAME(sys fork).long SYMBOL NAME(sys read).long SYMBOL NAME(sys write)old "setup()" systemn Add system calls by appending entry tosys call table:.long SYMBOL NAME(sys my system call)CS591 (Spring 2001)20

include/asm-i386/unistd.hnEach system call needs a number in the system calltable:n e.g., #define NR write 4n #define NR my system call nnn, wherennn is next free entry in system call table.CS591 (Spring 2001)kernel/sys.cnnService routine bodies are defined here:e.g., asmlinkage retvalsys my system call (parameters) {body of service routine;return retval;}CS591 (Spring 2001)21

Kernel ModulesCS591 (Spring 2001)Kernel ModulesnnSee A. Rubini, “Device Drivers”, Chapter 2.Modules can be compiled and dynamically linked intokernel address space.n Useful for device drivers that need not always beresident until needed.n Keeps core kernel “footprint” small.n Can be used to “extend” functionality of kernel too!CS591 (Spring 2001)22

Example: “Hello, world!”#define MODULE#include linux/module.h int init module(void) {printk(“ 1 Hello, world!\n”);return 0;}void cleanup module(void) {printk(“ 1 Goodbye cruel world L \n”);}CS591 (Spring 2001)Using ModulesnModule object file is installed in running kernel usinginsmod module name.n Loads module into kernel address space and linksunresolved symbols in module to symbol table ofrunning kernel.CS591 (Spring 2001)23

The Kernel Symbol TablenSymbols accessible to kernel-loadable modulesappear in /proc/ksyms.n register symtab registers a symbol table inthe kernel’s main table.n Real hackers export symbols from the kernel bymodifying kernel/ksyms.c JCS591 (Spring 2001)Project Suggestions (1)nnnnnnnnnReal-Time thread library.Scheduler activations in Linux.A Linux “upcall” mechanism.Real-Time memory allocator / garbage collector.A distributed shared memory system.A QoS-based socket library.An event-based mechanism for implementingadaptive systems.DWCS packet scheduling.A heap-based priority scheduler for Linux.CS591 (Spring 2001)24

Project Suggestions (2)n µSnnnnnnnresolution timers for Linux.Porting the Bandwidth-Broker to Linux.A QoS Management framework like QuO or Dionisys.A Real-Time communications protocol.A feedback-control system forflow/error/rate/congestion control.“Active Messages” for Linux.A thread continuation mechanism.A thread migration / load-balancing system.CS591 (Spring 2001)25

n Linux is a modular, UNIX -like monolithic kernel. n Kernel is the heart of the OS that executes with special hardware permission (kernel mode). n "Core kernel" provides framework, data structures, support for drivers, modules, subsystems. n Architecture dependent source sub -trees live in /arch. CS591 (Spring 2001) Booting and Kernel .

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

Anatomy of a linux kernel development Questions : – How to work kernel code? – How to write C code on the kernel? – How to building and install the kernel on old version linux? – How to release the linux kernel? – How to fixes bugs (patch) on kernel trees? Goal : –

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

Other Linux resources from O’Reilly Related titles Building Embedded Linux Systems Linux Device Drivers Linux in a Nutshell Linux Pocket Guide Running Linux Understanding Linux Network Internals Understanding the Linux Kernel Linux Books Resource Center linu

Linux in a Nutshell Linux Network Administrator’s Guide Linux Pocket Guide Linux Security Cookbook Linux Server Hacks Linux Server Security Running Linux SELinux Understanding Linux Network Internals Linux Books Resource Center linux.oreilly.comis a complete catalog of O’Reilly’s books on Linux and Unix and related technologies .