Table of Contents
Praktikum „Kernel Programming“
Description
Since the early age of computers operating systems (OS) have been playing a vital role in the software stack. The operating system is a software layer at the bottom of the software stack that extracts a high level abstraction of the underlying hardware, implements resource management and offers a variety of services into the layers that sit on top of it. Although programs can run directly on top of the hardware this is a rare case that usually can been seen only in embedded systems. Programming exactly above the “bare metal” machine adds more complexity to the programmers and requires a better understanding of the hardware.
The modern operating systems consist of a program so called kernel. The main functionality of the kernel is to handle the Central Processing Unit (CPU), the memory accesses and the input/output (I/O) requests. The software that is implemented as part of the kernel run in the context so called kernel space whereas the software on top of it in the so called user space. This comes from the memory abstraction that the kernel provides to applications (in this context applications can be considered the software implemented on top of the kernel). Running in the kernel space gives programmers privileged access to the hardware that in many cases is restricted from the user space, thus several functionalities can be implemented only inside the kernel space. Moreover, since the kernel is at the bottom of the software stack, it can dramatically affect the performance of the applications in many cases.
Currently, one of the most widely used operating systems (especially in the server environments) is the Linux OS, that consist of the Linux kernel. The Linux kernel, initially written from Linus Torvalds, follows the principles found in the Unix-kernel and it is published under the GNU General Public License version 2 (GPLv2). In this software lab you will learn the basics for Linux kernel development. At the end of this course you should be able to write your own kernel module.
This software lab will be given in English.
Target audience
This software lab is suitable for advance undergraduate and graduate students of the Computer Science department. It requires advanced knowledge C programming language. Moreover, familiarity with basic Linux (Unix) utilities such as ls, rm, grep, tar. Use of available text editors (e.g, Vim, emacs.). Experience with any major Linux distribution. Students of other departments are also welcome.
Date and Time
Lecturers
- Konstantinos Chasapis (contact person)
Overview
In the first weeks of the lectures we will recap all the required knowledge for this software lab. Then we will introduce the basic concepts and principles of Linux Kernel programming. Later, the participants will have to present specific aspects of Linux Kernel programming. Short assignments will be given to students during the semester. At the end of the semester the students will also have to work on a short project.
Syllabus
Presentations given by the lecturers:
- 15.10.14 – General information of the course. (room change DKRZ #034)
- 22.10.14 – Basic Linux tools and advanced features of C (pointers, structures, unions, memory allocation, function pointers, inline assembly).
- 29.10.14 – Introduction to the Linux Kernel (role, parts, modules, system calls) slides.pdf.
- 05.11.14 – Building, running and monitoring the Linux kernel (source tree, configure, install, boot/init process, monitor tools)slides.pdf.
- 12.11.14 – Writing your first linux kernel module (build, load, unload, parameters, user VS. Kernel space programming)slides.pdf.
– Above presentations are licensed under the Creative Commons Attribution 4.0 International License.
- 19.11.14 – No lecture.
- 26.11.14 – No lecture.
- 03.12.14 – No lecture.
Presentations given by the students*:
- 10.12.14 – no lecture
- 17.12.14 – Character device drivers (major-minnor number, file operations, ioctl, blocking I/O, access control) - Oster, König 1)slides.pdf src.tar.
- 07.01.15 – Debugging (printing, querying, watching, kgdb, syslogd, debugfs, kprobes), proc fs, etc. - Heinrich, Jensen 2).
- 14.01.15 – Kernel Synchronization (Race conditions, Threads, Semaphores, Mutexes, Spinlocks, Atomics, Alternatives) Kernel Timers (Tick Rate, Jiffies, Hardware clocks) and Interupt handling (installing, Implementing, Top and Bottomn Halves) Reentrant modules. - Esdonk, Sengpiel 3)slides.pdf.
- 21.01.15 – Memory Subsystem (kmalloc, vmalloc, lookaside caches, large buffers) and Data types in the Linux kernel (linked lists, Queues, Maps, Binary Trees). - Brömstrup, Koglin 4)slides.pdf src.tgz.
* two hours per presentation.
- 18.03.15 – Project presentations, face-to-face examination of the assignments.
Rules for the presentations
- At least three weeks prior the date of the presentation, you should send your supervisor a list of bullet points (related to your topic) that you will include in your presentation.
- Two weeks before the date of the presentation, you should send a draft of the slides of the presentation.
- One week before the date of the presentation, you should send an advanced/final version of the slides of the presentation.
- If we do not receive your slides 1 week prior the date of the presentation or in case of no show, your time slot will be cancelled and, therefore, you will fail.
You are advised to have face to face meetings with your supervisor in the beginning/meantime if you need help or solve questions. To do so, arrange in advance an appointment with your corresponding supervisor.
Code examples
Assignments
- Assignment 0 - due to 29.11.2014
- Assignment 1 - due to 13.01.2015
- Assignment 2 - due to 05.02.2015
It is recommended to use a virtual machine to solve your assignments since you can easily crash your system. However, compiling the kernel will take considerably longer. You are free to choose whichever virtualization solution you prefer (https://www.linux-kvm.org, https://www.virtualbox.org, https://www.vmware.com). Use CentOS 7.0 http://www.centos.org.
Policies
- Students can work in teams of two maximum three persons. The team members should be announced in advance.
- For each presentation you have to deliver the slides along with the source code examples. Slides and source code will be published here.
- Each team should provide its own unique solution.
- Do not copy other teams solutions.
- You can submit your assignment after the deadline. However, you will have to pay a penalty of 10% assigments mark per day of delay.
- You can ask questions in the mailing list of the course or to the lecturers directly.
References
Links
http://lxr.free-electrons.com/
http://lse.sourceforge.net/kdump/
http://lttng.org/docs/#doc-instrumenting-linux-kernel
https://www.kernel.org/pub/linux/kernel/people/rusty/kernel-locking/x490.html
http://www.tldp.org/LDP/lkmpg/2.6/lkmpg.pdf
Memory layout: http://mylinuxbook.com/linux-processes-part2/
Virtual memory in Linux (kernel): http://www.makelinux.net/ldd3/chp-15-sect-1
Programming in General
C-Workshop / Tutorial: http://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2011_2012/c-workshop.zip
Git-Workshop: http://wr.informatik.uni-hamburg.de/teaching/wintersemester_2011_2012/git-workshop
Git-Cheat-Sheet: https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
Shell-Programming Bash-Intorduction: https://help.ubuntu.com/community/Beginners/BashScripting http://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger
Linux Cheat-Sheet: http://www.computerworld.com/article/2598082/linux/linux-command-line-cheat-sheet.html
Makefile tutorial: http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ GNU Make Manual: http://www.gnu.org/software/make/manual/make.html
Debugging
Books
- Linux Device Drivers, 3d edition, Sprache: Englisch, ISBN-10: 0596005903, ISBN-13: 978-0596005900, price: EUR 29,00
- Linux Kernel Development (3rd Edition), Sprache: Englisch, ASIN: B003V4ATI0, price: EUR 30,95
- Advanced Programming in the UNIX Environment, Second Edition, Sprache: Englisch, ISBN-10: 0321637739, ISBN-13: 978-0321637734, price: EUR 44,95
- Understanding the Linux Kernel, 3rd edition, Sprache: Englisch, ASIN: B00E28C248, price: EUR 73,00
- Essential Linux Device Drivers (Prentice Hall Open Source Software Development), Sprache: Englisch, ISBN-10: 132396556, ISBN-13: 978-0132396554, price: 36,95
- Modern Operating Systems (3rd Edition), Publisher: Prentice Hall; 3 edition (December 21, 2007), Language: English, ISBN-10: 0136006639, ISBN-13: 978-0136006633
- Linux Performance and Tuning Guidelines, An IBM Redpaper publication http://www.redbooks.ibm.com/abstracts/redp4285.html
- The C Programming Language, 2nd Edition, Publisher: Prentice Hall; 2 edition (April 1, 1988), Language: English, ISBN-10: 0131103628, ISBN-13: 978-0131103627
- Modern Operating Systems, 3rd Edition, Author: Andrew S. Tanenbaum, Sprache: Englisch, ISBN-10: 1292025778, ISBN-13: 978-1292025773
- Just for Fun: The Story of an Accidental Revolutionary, Publisher: HarperBusiness; Reprint edition (June 4, 2002), Language: English, ISBN-10: 0066620732, ISBN-13: 978-0066620732