Introduction to the Linux kernel: challenges and case studies Juan Carlos Sáez Alcaide Department of Computer Architecture and Automation ArTeCS Group Complutense University of Madrid IV Semana de la Informática 2018 Feb 8, 2018 About Me Juan Carlos Sáez Alcaide ([email protected]) Interim Associate Professor, UCM Department of Computer Architecture and Automation Teaching: Operating Systems, Linux and Android Internals,… Member of the ArTeCS Research Group High Performance Computing Computer Architecture Interaction between system software and architecture … UCM Campus Representative of the USENIX Int’l Association Login (USENIX Magazine) IV Semana de la Informática 2018 - 2 Outline 1 Introduction 2 Main Features 3 Kernel Control Paths and Concurrency 4 Common Kernel abstractions 5 A case study: PMCTrack tool IV Semana de la Informática 2018 - 3 Outline 1 Introduction 2 Main Features 3 Kernel Control Paths and Concurrency 4 Common Kernel abstractions 5 A case study: PMCTrack tool IV Semana de la Informática 2018 - 4 Unix (I) Unics – Unix (1969) Created by Ken Thompson and rewrit- ten in “C” by Dennis Ritchie (1973) V6 (1975): Public source code (AT&T license) BSD distributions (Billy Joy) John Lion’s book on UNIX V6 Keys to success 1 Inexpensive license 2 Source code available 3 Code was simple and easy to modify 4 Ran on modest HW IV Semana de la Informática 2018 - 5 Unix (II) Unix (Cont.) V7 (1979): code can be no longer used for academic purposes Xenix (1980) Microsoft SCO Unix System III (1982) Unix System V (1983) HP-UX, IBM’s AIX, Sun’s Solaris IV Semana de la Informática 2018 - 6 Unix (III) Proyecto GNU (1983) - Richard Stallman SO GNU: Emacs, GNU compiler collection (GCC), GNU Hurd (kernel) Minix v1 (1987) - Andrew Tanenbaum Richard Stallman Minimal Unix-like OS (Unix clone) Teaching purposes. Modular structure Compatible with Unix V7 (user level) evolved towards the POSIX standard 1987 (Minix1 - i8088), 1997 (Minix2 - i386) Andrew Tanembaum IV Semana de la Informática 2018 - 7 Conflicts in the Unix world Unix Wars (1987-1996) Unix International (USL - AT&T) vs. Open Software Founda- tion Unix System V Release 4 (SVR4) War of specifications War ends in 1996 ! Open Group (Unix Trademark) Lawsuit brought by USL-AT&T against BSDI (1991-1994) Issue: attempt to make BSD free of any UNIX code Agreement is reached in 1994: Novell acquires USL IV Semana de la Informática 2018 - 8 And Linux comes out… (1991) A few months after Minix 1 was released the following mes- sage was posted at comp.os.minix: From: [email protected] (Linus Benedict Torvalds) Date: 25 Aug 91 20:57:08 GMT Local: Sun, Aug 25 1991 9:57 pm Subject: What would you like to see most in minix? Hello everybody out there using minix ­ I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I'd like any feedback on things people like/dislike in minix, as my OS resembles it somewhat (same physical layout of the file­system (due to practical reasons) among other things). I've currently ported bash(1.08) and gcc(1.40), and things seem to work. This implies that I'll get something practical within a few months, and I'd like to know what features most people would want. Any suggestions are welcome, but I won't promise I'll implement them :) Linus ([email protected]) PS. Yes it's free of any minix code and it has a multi-threaded fs. It is NOT portable (uses 386 task switching, etc), and it probably never support anything other than AT-harddisks, as that's all I have :(. IV Semana de la Informática 2018 - 9 And Linux comes out… (1991) Keys to success Unix Wars BSD Lawsuit Competition with Windows NT (common enemy) GPL License Internet ??? IV Semana de la Informática 2018 - 10 And Linux comes out… (1991) But Linux is just a kernel… GNU/Linux…, IBM/RedHat/HP/….Linux.. Distros (kernel + selection of pre-compiled tools) MCC Interim Linux 1992, Slackware (Patrick Volkerding) , Debian (Ian Murdock) 1993 S.U.S.E, Red Hat (Marc Erwing, Bob Young) 1994 Desktop Environments Xfree86 – Thomas Roel 1991 KDE – Matthias Ettrich 1996 Gnome – Miguel de Icaza 1997 … IV Semana de la Informática 2018 - 11 Linux Is Not UniX Open Group Current owner of the UNIX trademark SUS (Single Unix Specification) certification Unificación SUS / IEEE Posix en 2001 (SUS Version 3) A Unix system must comply with SUS Mac OS X Leopard (based on BSD) Z/OS IBM GNU/Linux is just a UNIX-like OS IV Semana de la Informática 2018 - 12 Funny Statistics for the Linux Kernel - Lines of Code, Bad words,... https://www.linuxcounter.net/statistics/kernel Lines of code per Kernel version Click and drag in the plot area to zoom in 25M 20M 15M Linux kernel: evolution since 1991 10M Lines of code 5M 0 1.0 1.2.2 2.0.2 3.7.8 4.4.44.8.9 4.11 1.3.271.3.65 2.0.402.1.372.1.75 2.2.182.3.292.4.162.5.162.5.542.6.163.0.143.0.523.0.903.2.153.2.533.4.283.4.66 3.10.9 3.13.5 4.14.5 2.1.113 3.12.11 3.18.17 Version Lines of code per kernel version Lines of Code Highcharts.com Source: https://www.linuxcounter.net IV Semana de la Informática 2018 1 de 1 - 6/2/18 13:42 13 Android: a Linux-based OS APPLICATIONS Home Contacts Phone Browser … APPLICATION FRAMEWORK Activity Window Content View Manager Manager Providers System Package Telephony Resource Location Notification Manager Manager Manager Manager Manager LIBRARIES ANDROID RUNTIME Media Surface Manager SQLite Core Libraries Framework Dalvik Virtual OpenGL | ES FreeType WebKit Machine / ART SGL SSL Bionic (libc) LINUX KERNEL Display Flash Memory Binder (IPC) Camera Driver Driver Driver Driver Audio Power Keypad Driver WifiFreeType Driver Drivers Management IV Semana de la Informática 2018 - 14 Linux kernel in Android Android relies on extensions made on top of the vanilla kernel: Binder Wakelocks klogger Ashmem Low Memory Killer Paranoid Network Alarm Timers … Today, the “Androidized” kernel constitutes a significant fork of Linux Linaro maintains an “androidized” kernel close to Linux main- line IV Semana de la Informática 2018 - 15 Outline 1 Introduction 2 Main Features 3 Kernel Control Paths and Concurrency 4 Common Kernel abstractions 5 A case study: PMCTrack tool IV Semana de la Informática 2018 - 16 Monolithic design Features Application Application All kernel components share the same address space user mode libc (API) Everything runs in kernel (privi- System call interface leged) mode Filesystem Good performance VFS support No isolation between compo- Network Device nents stack Drivers kernel mode Memory Process Kernel Components Management Management Architecture specific code (arch) Hardware IV Semana de la Informática 2018 - 17 User mode vs. kernel mode User mode Kernel mode D0 D0 D1 D1 D2 D2 D3 D3 State register D4 D4 D5 D5 T 15 D6 D6 14 D7 State register D7 S 13 12 A0 7 A0 11 byte 6 12 10 System A1 5 A1 11 9 A2 X 4 A2 10 8 3 User A3 N flags A3 7 Z 2 6 A4 V 1 A4 5 A5 C 0 A5 X 4 3 User A6 A6 N flags A7 A7 Z 2 V 1 C 0 0 0 0 216 − 1 TASK_SIZE I/O address TASK_SIZE space 232 − 1 Instruction set Instruction set Virtual address Virtual address space space IV Semana de la Informática 2018 - 18 Interactive map of the Linux kernel http://www.makelinux.net/kernel_map/ IV Semana de la Informática 2018 - 19 Main challenges A beast of a different nature Development process is labor-intensive Testing new features or bugfixes requires 1 (Re)Build the kernel (it may take a while!) 2 Install the new kernel 3 Reboot the machine No memory protection (no SIGSEGV) User-space like debugging tools are not available Documentation becomes outdated quickly Developers must really understand the kernel code No standard C library∗ Limited size of the kernel stack IV Semana de la Informática 2018 - 20 Obtaining kernel sources Vanilla: (The Linux Kernel Archives) www.kernel.org (tarball or git repository) git://git.kernel.org/pub/scm/linux/kernel/git/stable/ linux-stable.git https://git.kernel.org GNU/Linux distributions typically use Linux with patches Example Debian: Package installation with apt-get o apt source Source package of linux-image­* linux-source .deb package (install tarball at /usr/src/) More information at Debian Linux Kernel Handbook IV Semana de la Informática 2018 - 21 Working with the Linux kernel Obtain the sources (extract tarball if necessary) No Does it boot? Yes Apply patches (if necessary) Does it work? Configure the kernel Reboot into We are stable kernel done :-) Make changes to the source code Build the kernel (make,make-kpkg) No Compilation Yes errors? Install kernel and reboot machine IV Semana de la Informática 2018 - 22 Linux kernel modules What is a kernel module? A “code fragment” that can be loaded/unloaded into/from the OS kernel’s address space on demand Written in “C” Bundled as a .ko file (object file) Compilation driven by a Makefile insmod, rmmod Its functions are executed in kernel mode Limitation Not everything can be implemented as a kernel module System calls Scheduling algorithms … IV Semana de la Informática 2018 - 23 KGDB Requires 2 machines connected via serial port Development host: To build the kernel and invoke gdb Target system: Runs the kernel with KGDB support Source: https://blog.trendmicro.com IV Semana de la Informática 2018 - 24 KDB KDB: in-kernel debug shell (serial port/text console) No need to use an external debugging host KDB is not a source-level debugger Programmer needs to deal with assembly code You can use it in conjunction with gdb and external
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages51 Page
-
File Size-