├── slideware ├── power │ ├── media │ │ ├── catnap.jpg │ │ ├── tuxsleep.png │ │ ├── pchandheld.jpg │ │ ├── powerswitches.jpg │ │ └── tuxpolitician.png │ └── power.tex ├── overview │ ├── media │ │ ├── menuconfig.png │ │ └── kernel.svg │ └── overview.tex ├── debug │ ├── media │ │ └── tracingmenuconfig.png │ └── debug.tex ├── Makefile ├── intro │ └── intro.tex ├── interrupts │ ├── memory_interrupts_scheduling.tex │ └── media │ │ ├── memorymap.svg │ │ └── interrupts.svg ├── sample │ └── presentation_1.tex └── boot │ ├── machinedescriptions_n_boot.tex │ └── media │ ├── driverstack.svg │ ├── driver.svg │ └── memorymap.svg ├── exercises ├── led-gpio-key-module │ ├── Makefile │ ├── led-gpio-key-overlay.dts │ └── led-gpio-key.c ├── setup_pi.txt ├── regulatorframework.txt ├── upstream.txt ├── devicedriver.txt └── configure_build_install.txt ├── .gitignore ├── README.md └── LICENSE /slideware/power/media/catnap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/power/media/catnap.jpg -------------------------------------------------------------------------------- /slideware/power/media/tuxsleep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/power/media/tuxsleep.png -------------------------------------------------------------------------------- /slideware/power/media/pchandheld.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/power/media/pchandheld.jpg -------------------------------------------------------------------------------- /slideware/overview/media/menuconfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/overview/media/menuconfig.png -------------------------------------------------------------------------------- /slideware/power/media/powerswitches.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/power/media/powerswitches.jpg -------------------------------------------------------------------------------- /slideware/power/media/tuxpolitician.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/power/media/tuxpolitician.png -------------------------------------------------------------------------------- /slideware/debug/media/tracingmenuconfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yhr/kernelteaching/HEAD/slideware/debug/media/tracingmenuconfig.png -------------------------------------------------------------------------------- /exercises/led-gpio-key-module/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += led-gpio-key.o 2 | 3 | all: 4 | make -C $(KERNEL) M=$(PWD) modules 5 | 6 | clean: 7 | make -C $(KERNEL) M=$(PWD) clean 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | 35 | # pdf files 36 | *.pdf 37 | *.pdf_tex 38 | -------------------------------------------------------------------------------- /exercises/led-gpio-key-module/led-gpio-key-overlay.dts: -------------------------------------------------------------------------------- 1 | /dts-v1/; 2 | /plugin/; 3 | / { 4 | compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"; 5 | fragment@0 { 6 | target-path = "/soc"; 7 | __overlay__ { 8 | ledkey: ledkey { 9 | compatible = "gpio-led-key"; 10 | 11 | pinctrl-names = "default"; 12 | pinctrl-0 = <&my_pins>; 13 | 14 | gpios = <&gpio 18 1>; 15 | linux,code = <30>; // "A" 16 | 17 | led-supply = <&gpio_regulator>; 18 | }; 19 | }; 20 | }; 21 | 22 | fragment@1 { 23 | target = <&gpio>; 24 | __overlay__ { 25 | my_pins: my_pins { 26 | brcm,pins = <18>; 27 | brcm,function = <0>; // in (initially) 28 | brcm,pull = <2>; // pullup 29 | }; 30 | }; 31 | }; 32 | 33 | fragment@2 { 34 | target-path = "/soc"; 35 | __overlay__ { 36 | gpio_regulator: gpio_regulator { 37 | compatible = "regulator-gpio"; 38 | 39 | regulator-name = "fake_regulator_gpio_23"; 40 | 41 | enable-gpio = <&gpio 23 0>; 42 | states = <0000000 0 43 | 3300000 1>; 44 | 45 | enable-active-high; 46 | }; 47 | }; 48 | 49 | }; 50 | }; 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Teaching Linux Kernel Development 2 | The Open Kernel Teaching Project 3 | 4 | This project contains slideware and exercises for teaching kernel development. 5 | As a first step, the project will focus on providing material for a crash- 6 | course, with the goal of giving a wide understanding of what the Linux kernel 7 | is, how the big cogs in its machinery are set up, how it is built, how to debug, where to find documentation and how it is developed in the community. 8 | 9 | The intention is to turn students into kernel hackers, capable of contributing upstream and independently continue their studies. 10 | 11 | This presentation (from Lund Linux Conference 2017) describes the course with some nice pictures: https://goo.gl/KeiCgD 12 | 13 | To build the slideware you need to install the following packages: 14 | latex-beamer rubber inkscape (assuming you are running ubuntu 16) 15 | 16 | Please see our wiki page for more information on the project and how to join the mailing list and contribute. 17 | 18 | https://github.com/yhr/kernelteaching/wiki 19 | 20 | In addition to the contributors, thanks goes out to the following who has 21 | helped in one way or another (in random order): 22 | 23 | Joakim Nordell, Mian Yousaf Kaukab, Patrik Jakobsson, Hans Odeberg, Javier Gonzales, Linus Walleij, Philippe Bonnet 24 | -------------------------------------------------------------------------------- /exercises/setup_pi.txt: -------------------------------------------------------------------------------- 1 | Preparing your Raspberry PI for the labs 2 | ======================================== 3 | 4 | Boot up the pi with a serial cable attached. 5 | Start minicom on your PC and login to the raspberry pi (you might need to 6 | press enter to get to the login prompt) 7 | 8 | TIP: exit minicom by pressing CTRL-A Q 9 | 10 | User: pi 11 | Password: raspberry 12 | 13 | Change the default password: 14 | sudo passwd 15 | 16 | Set root password: 17 | sudo passwd root 18 | 19 | Change the hostname of your PI so you won't confuse it with any other 20 | on the network: 21 | su 22 | echo > /etc/hostname 23 | 24 | Enable root ssh login: 25 | sudo raspi-config 26 | Enable ssh under "Interfacing options", then quit 27 | sudo nano /etc/ssh/sshd_config 28 | ..and change the line "PermitRootLogin without-password" to: 29 | PermitRootLogin yes 30 | Exit nano with CTRL-X (remember to save when asked) 31 | 32 | Reboot: 33 | sudo reboot now 34 | 35 | Check IP adress: 36 | ifconfig 37 | eth0 ... 38 | inet addr: .. 39 | .. 40 | 41 | On your PC, log in over ssh to your pi to test: 42 | ssh pi@ 43 | 44 | On your PC, mount the pi root file system over ssh: 45 | mkdir piroot 46 | sshfs root@:/ piroot 47 | 48 | You can now access the PI's entire file system in the piroot directory. 49 | Neat, huh? This will allow you to replace the kernel, install modules 50 | and edit files without having to plug in the PI's sd card into your PC. 51 | 52 | Done! 53 | -------------------------------------------------------------------------------- /exercises/regulatorframework.txt: -------------------------------------------------------------------------------- 1 | Learning a framework: Using regulators 2 | ====================================== 3 | 4 | In this exercise, you will learn how to use a new framework by implementing 5 | support for turning on and off the LED in the led-button driver by using the 6 | regulator framework. 7 | 8 | 0. Preparations 9 | --------------- 10 | 11 | Make sure that you've completed the device driver exercise, and that you have 12 | built the kernel with gpio-regulator support(as specified in the build 13 | exercise) 14 | 15 | Read the kernel documentation on regulators. Search for it in Documentation/ 16 | The regulator to be used is specified in the led-keys device tree overlay, 17 | so have a look at how to obtain the right regulator for the device. 18 | 19 | Have a look at code using the regulator consumer API. Google for presentations. 20 | 21 | 1. Aquire the regulator and link it to the device 22 | -------------------------------------------------- 23 | 24 | Q: There is a 1-1 mapping between a led-button device and a regulator controlling the led, what data structure should contain the link? 25 | 26 | What part of the code should get hold of regulator from the device tree? 27 | 28 | Don't forget to handle errors. 29 | 30 | Q: Thee boiler plate driver code uses devm_ variants 31 | of a lot of API resource-handling functions, why is this so good? How are resourced freed if there is an error during probe? 32 | 33 | 2. Control the LED with the button 34 | ---------------------------------- 35 | 36 | The LED should be off when the button is pressed(and on otherwise on). 37 | Make sure that the module can be unloaded and loaded again. 38 | 39 | Done! 40 | 41 | -------------------------------------------------------------------------------- /slideware/Makefile: -------------------------------------------------------------------------------- 1 | OUT_DIR = out 2 | 3 | VIEWER ?= evince $(VIEWER_OPTS) 4 | 5 | LATEX_OPTS = --shell-escape 6 | LATEX_OPTS += --interaction=batchmode 7 | 8 | SVGTOLATEX ?= inkscape 9 | SVGTOLATEX_OPTS ?= -z -T --export-area-drawing 10 | SVGTOLATEX_IN ?= --file= 11 | SVGTOLATEX_OUT ?= --export-pdf= 12 | 13 | VPATH = .:./$(OUT_DIR) 14 | 15 | all: pdf 16 | 17 | # Specific view targets goes here 18 | 19 | view-overview: pdf 20 | $(VIEWER) $(OUT_DIR)/overview/overview.pdf 21 | 22 | view-intro: pdf 23 | $(VIEWER) $(OUT_DIR)/intro/intro.pdf 24 | 25 | view-boot: pdf 26 | $(VIEWER) $(OUT_DIR)/boot/machinedescriptions_n_boot.pdf 27 | 28 | view-sample: pdf 29 | $(VIEWER) $(OUT_DIR)/sample/presentation_1.pdf 30 | 31 | view-interrupts: pdf 32 | $(VIEWER) $(OUT_DIR)/interrupts/memory_interrupts_scheduling.pdf 33 | 34 | view-debug: pdf 35 | $(VIEWER) $(OUT_DIR)/debug/debug.pdf 36 | 37 | view-power: pdf 38 | $(VIEWER) $(OUT_DIR)/power/power.pdf 39 | 40 | # --- 41 | 42 | view: pdf 43 | $(VIEWER) $(wildcard $(OUT_DIR)/*/*.pdf) 44 | 45 | svg: $(addsuffix .pdf, $(basename $(shell find ./ -type f -name *.svg))) 46 | pdf: svg $(addsuffix .pdf, $(basename $(shell find ./ -type f -name *.tex))) 47 | 48 | 49 | %.pdf: %.svg 50 | $(eval DIR=$(dir $?)) 51 | $(eval TARGET=$(addsuffix .pdf, $(basename $@))) 52 | @echo "* Processing $?" 53 | @mkdir -p $(OUT_DIR)/$(DIR) 54 | @$(SVGTOLATEX) $(SVGTOLATEX_OPTS) $(SVGTOLATEX_IN)$< $(SVGTOLATEX_OUT)$(OUT_DIR)/$(TARGET) >/dev/null 2>&1 55 | 56 | %.pdf: %.tex 57 | $(eval DIR=$(dir $?)) 58 | $(eval FILE=$(patsubst $(DIR)%,%, $?)) 59 | @echo "* Processing $?" 60 | @mkdir -p $(OUT_DIR)/$(DIR) 61 | @rubber --pdf --into $(OUT_DIR)/$(DIR) $? 62 | 63 | clean: 64 | @test -d $(OUT_DIR) && rm -r $(OUT_DIR) || echo "Nothing to do" 65 | -------------------------------------------------------------------------------- /exercises/upstream.txt: -------------------------------------------------------------------------------- 1 | Upstreaming a driver 2 | ==================== 3 | 4 | In this exercise, you will learn how to move an out-of-tree device driver 5 | into the kernel tree, add the driver to the kernel configuration mechanism 6 | and make files, create a patch with the diff, check that it is upstream 7 | ready and send it to the teacher for review. 8 | 9 | 0. Preparations 10 | --------------- 11 | 12 | Make sure that you've completed the device driver and regulator exercises and 13 | have a working driver. 14 | 15 | Read through https://kernelnewbies.org/FirstKernelPatch 16 | 17 | 1. Move the gpio-led-key driver to the kernel tree 18 | --------------------------------------------------- 19 | 20 | Move the out-of tree driver you have worked on into the kernel tree. 21 | 22 | TIP: Commit any changes you have made before to the rpi-kernel tree, 23 | so you don't lose the overlay, and start a new branch on top of that before 24 | you start moving the driver. 25 | 26 | Move the driver to a good location under drivers/ and edit the 27 | subdirectory's Makefile and KConfig files to include the driver in the build 28 | and the configuration system. 29 | 30 | Make the driver buildable as a module(tristate config flag). 31 | 32 | TIP: inspect the Makefile and KConfig files and look at similar drivers 33 | for inspiration. 34 | 35 | 2. Build the driver as an in-kernel driver 36 | ----------------------------------------- 37 | 38 | Build the driver with your new config flag=Y (making it a part of zImage). 39 | 40 | Q: The driver will not suceed at the first probe. What error is printed? Check using dmesg. 41 | 42 | Q: The kernel probes the driver again, and second attempt succeeds. Why? 43 | 44 | 3. Build the driver as a kernelmodule 45 | ------------------------------------- 46 | 47 | Build the driver with your new config flag=M and test that it works as 48 | expected. 49 | 50 | Q: Do you need to load the module manually still? Why? 51 | 52 | Make sure the module can be unloaded and loaded again. 53 | 54 | TIP: you need to use modprobe to load the kernel module (or locate the module in /lib where you installed it using make modules_install ) 55 | 56 | 57 | 4. Generate a patch 58 | ------------------- 59 | 60 | Commit the result on your new branch, generate a patch 61 | git format-patch -1, and make sure it passes through the checkpatch tool (see the kernel newbies page for details). 62 | 63 | Write a good commit message(look at other commits in the same subdirectory), 64 | 65 | You'll probably need to do several iterations before you pass checkpatch. 66 | so "git commit --amend" is your friend. 67 | 68 | Signoff the patch before mailing it to the teacher, preferably using git send-email. 69 | 70 | NOTE: to send patches using git send-email, you have to install the package git-email and configure a smtp server. See the kernelnewbies article for details. 71 | 72 | Q: If you would have tried to upstream the patch for real, what maintainer would you have sent it to? Check using ./scripts/get_maintainer.pl 73 | 74 | The teacher will review your patch, and pass you when he's happy :) 75 | 76 | Done! 77 | -------------------------------------------------------------------------------- /exercises/led-gpio-key-module/led-gpio-key.c: -------------------------------------------------------------------------------- 1 | /* 2 | * led-gpio-key.c -- Driver for gpio buttons with a led 3 | * 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License version 2 as 7 | * published by the Free Software Foundation. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define DRV_NAME "led-gpio-key" 25 | 26 | struct led_gpio_key_drvdata { 27 | struct input_dev *input; 28 | struct gpio_desc *gpio; 29 | unsigned int buttoncode; 30 | int irq; 31 | }; 32 | 33 | /* call me when an interrupt happens, but not in interrupt context! 34 | static void led_gpio_key_report_state(struct led_gpio_key_drvdata *ddata) 35 | { 36 | struct input_dev *input = ddata->input; 37 | 38 | input_report_key(input, ddata->buttoncode, 39 | gpiod_get_value_cansleep(ddata->gpio)); 40 | 41 | input_sync(input); 42 | 43 | } 44 | */ 45 | 46 | static int led_gpio_key_probe(struct platform_device *pdev) 47 | { 48 | struct device *dev = &pdev->dev; 49 | struct input_dev *input; 50 | struct led_gpio_key_drvdata *ddata; 51 | int err = -ENOMEM; 52 | 53 | ddata = devm_kzalloc(dev, sizeof(struct led_gpio_key_drvdata), GFP_KERNEL); 54 | if (!ddata) 55 | return -ENOMEM; 56 | 57 | input = devm_input_allocate_device(dev); 58 | if (!input) 59 | return -ENOMEM; 60 | 61 | ddata->input = input; 62 | platform_set_drvdata(pdev, ddata); 63 | input_set_drvdata(input, ddata); 64 | 65 | input->name = pdev->name; 66 | input->phys = DRV_NAME"/input0"; 67 | input->dev.parent = &pdev->dev; 68 | 69 | input->id.bustype = BUS_HOST; 70 | input->id.vendor = 0x0001; 71 | input->id.product = 0x0001; 72 | input->id.version = 0x0100; 73 | 74 | set_bit(EV_KEY, input->evbit); 75 | 76 | err = device_property_read_u32(dev, "linux,code", &ddata->buttoncode); 77 | if (err) { 78 | dev_err(dev, "Button without keycode!\n"); 79 | goto fail; 80 | } 81 | 82 | set_bit(ddata->buttoncode, input->keybit); 83 | 84 | ddata->gpio = devm_gpiod_get(&pdev->dev, NULL, 0); 85 | if (IS_ERR(ddata->gpio)) { 86 | dev_err(dev, "unable to allocate gpio\n"); 87 | err = PTR_ERR(ddata->gpio); 88 | goto fail; 89 | } 90 | 91 | ddata->irq = gpiod_to_irq(ddata->gpio); 92 | if (ddata->irq < 0) { 93 | dev_err(dev, "unable to get irq for gpio\n"); 94 | err = ddata->irq; 95 | goto fail; 96 | } 97 | 98 | // This is a good spot to install the irq handler 99 | 100 | err = input_register_device(input); 101 | if (err) { 102 | dev_err(dev, "unable to register input device\n"); 103 | goto fail; 104 | } 105 | 106 | return 0; 107 | fail: 108 | return err; 109 | } 110 | 111 | 112 | static const struct of_device_id led_gpio_key_of_match[] = { 113 | { .compatible = "not-correct", }, 114 | { }, 115 | }; 116 | 117 | 118 | static struct platform_driver led_gpio_key_device_driver = { 119 | .probe = led_gpio_key_probe, 120 | .driver = { 121 | .name = DRV_NAME, 122 | .of_match_table = of_match_ptr(led_gpio_key_of_match), 123 | } 124 | }; 125 | 126 | module_platform_driver(led_gpio_key_device_driver); 127 | 128 | MODULE_DEVICE_TABLE(of, led_gpio_key_of_match); 129 | MODULE_AUTHOR("Your Name .com>"); 130 | MODULE_DESCRIPTION("Driver for gpio buttons with a led"); 131 | MODULE_LICENSE("GPL v2"); 132 | -------------------------------------------------------------------------------- /exercises/devicedriver.txt: -------------------------------------------------------------------------------- 1 | Device driver fundamentals: probing and interrupts 2 | ================================================== 3 | 4 | The code and the device tree overlay is located in exercises/led-gpio-key-module/ 5 | 6 | 0. Preparations 7 | --------------- 8 | 9 | Connecting the LED-button device. 10 | Connect the cables(there are two different variants) like this: 11 | (just below the serial cable) 12 | 13 | PI GPIO Cable variant 1 Cable variant2 14 | ------- --------------- -------------- 15 | GPIO 18 Orange Yellow 16 | GND Brown Blue 17 | GPIO 23 Red Green 18 | 19 | See http://www.hobbytronics.co.uk/image/data/tutorial/raspberry-pi/gpio-pinout-rev2.jpg 20 | 21 | 22 | To enable enumeration of the gpio-led device, we have to add it to 23 | the RPI device tree. This is easy to do using something called device tree 24 | overlays. During boot, a base device tree blob can be amened by the bootloader 25 | to include extra devices. 26 | 27 | * Copy the .dts file from gpio-led-module/ to arch/arm/boot/dts/overlays 28 | 29 | * Add the .dts file to the makefile in arch/arm/boot/dts 30 | (you do this by adding the line "led-gpio-key.dtbo" , see the other overlays in the makefile 31 | for how the make file works) 32 | 33 | * Build the dtb target(like the previous lab) 34 | 35 | * Copy the resulting led-gpio-key.dtbo file (in arch/arm/boot/dts/overlays) to 36 | /boot/overlays 37 | 38 | * Enable the overlay by adding the following line 39 | dtoverlay=led-gpio-key 40 | to /boot/config.txt 41 | 42 | * Reboot the pi and check that a led-gpio-key node exist in 43 | /proc/device-tree/soc/ledkey 44 | 45 | * Look at the attributes that the node exports in the sysfs, and 46 | compare to what's in the .dts file. 47 | 48 | 1. Build the out of tree driver, copy it to the pi insert it 49 | ------------------------------------------------------------ 50 | 51 | A good first step is to copy the led-gpio-key module directory to i.e. 52 | ~/src and create a git project so you can go back if you mess anything up. 53 | 54 | i.e. 55 | 56 | cp -r ../kernelteaching/exercises/led-gpio-key-module ~/src 57 | cd ~/src/led-gpio-key-module 58 | git init . 59 | git add * 60 | git commit -m "Initial commit" 61 | 62 | 63 | * Perform make in the driver's directory, transfer the resulting .ko-file 64 | to the pi(anywhere is good) and insert it. 65 | 66 | Make sure you pass parameters when building: 67 | 68 | make ARCH=arm CROSS_COMPILE=$RPI_CC KERNEL=/home/student/src/rpi-linux 69 | 70 | Then: 71 | 72 | * Inspect the module info with modinfo 73 | * Check that is it is loaded with lsmod 74 | 75 | 76 | 2. Make the driver enumerate by adding the correct compatible-string 77 | -------------------------------------------------------------------- 78 | 79 | * The device table is not correct. Fix this. Have a look at the device tree 80 | overlay to figure out the right string. 81 | 82 | To load a new version of the module you have to unload it first: 83 | sudo rmmod led-gpio-key 84 | 85 | * Check that a new input device is created in /dev/input 86 | 87 | 3. Implement an interrupt handler 88 | --------------------------------- 89 | 90 | The gpio interrupt should result in a report to the input framework. Enable the interrupt in the probe function. 91 | 92 | * Start by reading the code and try to undestand what every bit does. 93 | 94 | * Use a threaded irq(devm_request_threaded_irq) to implement the top/bottom half pattern. 95 | Note: you don't need to do anything in the top half for this driver 96 | Documentation: https://www.kernel.org/doc/htmldocs/kernel-api/API-request-threaded-irq.html 97 | 98 | TIP: Search for other drivers doing the same thing, i.e: 99 | git grep devm_request_threaded_irq drivers/input 100 | 101 | Test that events are emitted using evtest. 102 | Install evtest (on the pi) if needed: sudo apt-get install evtest 103 | 104 | 105 | -------------------------------------------------------------------------------- /slideware/intro/intro.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | 11 | %------------------------------------------------------------------------- 12 | 13 | \title[TLKDCC Intro]{The Linux Kernel Development Crash Course} 14 | \author{Hans Holmberg} 15 | \institute[LKTP] 16 | { 17 | Linux Kernel Teaching Project \\ 18 | \medskip 19 | \textit{hans.holmberg@gmail.com} 20 | } 21 | \date{\today} 22 | %------------------------------------------------------------------------ 23 | \begin{document} 24 | 25 | \begin{frame} 26 | \titlepage 27 | \includegraphics{../common/tux} 28 | \end{frame} 29 | 30 | \begin{frame} 31 | \frametitle{Overview} 32 | \tableofcontents 33 | \end{frame} 34 | 35 | \section{Background} 36 | \begin{frame} 37 | \frametitle{Background} 38 | Why teaching kernel development? 39 | \begin{itemize} 40 | \item Kernel development has a steep learning curve 41 | \item A crash course get students past the first bump 42 | \end{itemize} 43 | 44 | Why do it open-source? 45 | \begin{itemize} 46 | \item Share the effort! 47 | \item More teachers, reach more students 48 | \end{itemize} 49 | \end{frame} 50 | 51 | %----------------------------------------------------------------------- 52 | \section{Course goals} 53 | \begin{frame} 54 | \frametitle{Course goals - what is achievable?} 55 | Provide a wide overview of the Linux kernel machinery and how to develop kernel code \\ 56 | .. and in the end turn students into kernel hackers, capable of contributing upstream and independently continue exploring. 57 | \end{frame} 58 | 59 | %----------------------------------------------------------------------- 60 | \section{Prerequisites} 61 | 62 | \begin{frame} 63 | \frametitle{Prerequisites} 64 | \begin{itemize} 65 | \item Mandatory 66 | \begin{itemize} 67 | \item C 68 | \item Operating system concepts 69 | \end{itemize} 70 | 71 | \item Optional (will help those who need it) 72 | \begin{itemize} 73 | \item GIT 74 | \item Build toolchain 75 | \item Linux tools(grep, diff, ..) 76 | \end{itemize} 77 | \end{itemize} 78 | \end{frame} 79 | 80 | %----------------------------------------------------------------------- 81 | \section{Lectures} 82 | \begin{frame} 83 | \frametitle{Lectures} 84 | Theory 85 | \begin{itemize} 86 | \item Linux Kernel overview 87 | \item Kernel boot and machine descriptions (ACPI/DT) 88 | \item Interrupts, threads and processes 89 | \item Power management 90 | \end{itemize} 91 | Craft 92 | \begin{itemize} 93 | \item Navigating the source tree 94 | \item Configuring and building the kernel 95 | \item Debugging and tracing 96 | \end{itemize} 97 | Community 98 | \begin{itemize} 99 | \item Development best practices 100 | \item Community interaction and upstreaming 101 | \end{itemize} 102 | \end{frame} 103 | 104 | %----------------------------------------------------------------------- 105 | \section{Labs} 106 | \begin{frame} 107 | \frametitle{Labs} 108 | \begin{itemize} 109 | \item Configuring and building your own kernel 110 | \item Finding documentation in the source tree and history 111 | \item Debugging 112 | \item Driver development 113 | \item Learning a framework 114 | \item Upstreaming 115 | \end{itemize} 116 | \end{frame} 117 | 118 | %----------------------------------------------------------------------- 119 | \section{What's next?} 120 | \begin{frame} 121 | \frametitle{What's next?} 122 | \begin{itemize} 123 | \item Great feedback so far, so we're going to continue this. 124 | \item Contributions very welcome 125 | \item Reviewers of the material and teachers wanted 126 | \item Want to attend the course? Let us know! 127 | \end{itemize} 128 | \end{frame} 129 | 130 | \begin{frame} 131 | \frametitle{Contacts} 132 | \begin{itemize} 133 | \item github.com/yhr/kernelteaching 134 | \item kernel-teaching@googlegroups.com 135 | \end{itemize} 136 | \end{frame} 137 | 138 | 139 | %----------------------------------------------------------------------- 140 | \begin{frame} 141 | \Huge{\centerline{Thanks!}} 142 | \end{frame} 143 | 144 | \end{document} 145 | -------------------------------------------------------------------------------- /exercises/configure_build_install.txt: -------------------------------------------------------------------------------- 1 | 2 | Exercise: Configuring, building and installing the kernel on a RPI 3 | ================================================================== 4 | 5 | USB-stick users: the raspberry pi kernel tree is cloned in ~/src/rpi-linux 6 | If you're labbing in your own environment, clone the rpi-kernel from 7 | https://github.com/raspberrypi/linux 8 | 9 | You can try to run the exercises on an upstream kernel too, but then you are 10 | on your own :) 11 | 12 | If you're doing the exercises in your own linux installation, you must install 13 | the toolchain for cross compiling. Follow the instructions under 14 | "INSTALL TOOLCHAIN" @ 15 | https://www.raspberrypi.org/documentation/linux/kernel/building.md 16 | 17 | Make sure you point out the right path in CROSS_COMPILE when doing kernel 18 | builds! 19 | 20 | 21 | 0. Prepare the sd-card with a raspbian-stretch-lite image 22 | -------------------------------------------------------- 23 | 24 | Download raspian stretch lite from: 25 | https://www.raspberrypi.org/downloads/raspbian/ 26 | 27 | Write the image to the sd card, use etcher or dd (or something else), see: 28 | https://www.raspberrypi.org/documentation/installation/installing-images/linux.md 29 | 30 | Then follow the instructions in setup_pi.txt. 31 | 32 | 1. Check out the latest branch and look at the history 33 | ------------------------------------------------------ 34 | 35 | The kernel shipping with the raspbian distribution is 4.9, which is a tad old. 36 | We want to use the latest available kernel from the rpi kernel repository, 37 | so we are going to build the rpi-4.14.y branch, after checking kernel 4.9 was released. 38 | Tip: check the history for the Makefile (git log --oneline Makefile) 39 | 40 | Q: What date was kernel 4.9 released? 41 | 42 | ..then check how many patches that has been merged between 4.9 and 4.14.32 43 | 44 | Tip: git log [first revison]..[second revision] --pretty=oneline | wc -l 45 | 46 | Revisions can be specified as a hash of a particular commit, or as a tag. 47 | Upstream kernel version tags have not been cloned into the rpi repository, 48 | so you have to use commit hashes as revisons. 49 | 50 | 51 | Q: If the maintainers spent fifteen minutes reviewing each patch, how many man months, roughly, was spent on quality control? 52 | 53 | 54 | 2. Configure the kernel 55 | ----------------------- 56 | 57 | NB: don't forget to specify the right architecure(arm) via the ARCH make 58 | parameter in every make-step - if not, the make system will assume X86 and 59 | the config will be all messed up. 60 | 61 | 2.1 Use the kernel make system to generate the built-in default kernel 62 | configuration. 63 | 64 | If you have a RPI v2 or RPI v3 the default make config target is 65 | bcm2709_defconfig, if it is RPI v1 it is bcmrpi_defconfig. 66 | 67 | Make sure to set up environment variable KERNEL to kernel7 68 | KERNEL=kernel7 69 | 70 | This is some recently introduced magic specified in: 71 | https://www.raspberrypi.org/documentation/linux/kernel/building.md 72 | 73 | Make a copy of the generated .config named .origconfig 74 | 75 | 2.2 Configure the kernel to include the gpio-regulator driver as built-in. 76 | -------------------------------------------------------------------------- 77 | 78 | Tip: This will tell you where the driver is located 79 | git grep gpio-regulator -- drivers/ 80 | 81 | Tip: Figure out which config flag to enable by inspecting the Makefile in the 82 | driver's directory, then search for it in menuconfig (/ will get you into search mode in menuconfig) 83 | 84 | Check the difference between the new config (.config) and the default one. 85 | 86 | 3. Build the kernel 87 | ------------------- 88 | 89 | NB: in addition to specifying architecture, you now neeed to specify a cross 90 | compiler via the CROSS_COMPILE parameter in the kernel build. for those using 91 | the prepared usb sticks, the path to the cross compile toolchain is stored in 92 | the environment variable $RPI_CC. 93 | 94 | Build the targets zImage, dtbs and modules 95 | TIP: Use the -j to parallelize the build and speed things up. 96 | 97 | 4 Install the kernel 98 | -------------------- 99 | 100 | NB: make sure you have sshfs-mounted (see setup_pi.txt) the pi's root filesystem. 101 | The instructions will probably work if you insert the PI sd card on your computer and use 102 | the path to the mount point of the root fs as . 103 | 104 | Install kernelimage, device tree blobs and modules: 105 | 106 | cp arch/arm/boot/zImage /boot 107 | cp arch/arm/boot/dts/*.dtb /boot 108 | make ARCH=arm INSTALL_MOD_PATH= modules_install 109 | 110 | Add the following line to /boot/config on the pi to tell it to boot your kernel: 111 | kernel=zImage 112 | 113 | Reboot the pi & check that you are running the new kernel. 114 | Have a look at the installed module sets: 115 | ls /lib/modules 116 | 117 | Q: Why did we have to install a new set of kernel modules? 118 | 119 | Done! 120 | -------------------------------------------------------------------------------- /slideware/interrupts/memory_interrupts_scheduling.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | \usepackage{hyperref} 11 | 12 | \AtBeginSection[]{ 13 | \begin{frame} 14 | \vfill 15 | \centering 16 | \usebeamerfont{title}\Huge{\insertsectionhead\par} 17 | \vfill 18 | \end{frame} 19 | } 20 | 21 | %------------------------------------------------------------------------- 22 | 23 | \title[TLKDCC Memory, Interrupts, Scheduling]{Memory management, Interrupts and Scheduling} 24 | \author{Hans Holmberg} 25 | \institute[LKTP] 26 | { 27 | Linux Kernel Teaching Project \\ 28 | \medskip 29 | \textit{hans.holmberg@gmail.com} 30 | } 31 | \date{\today} 32 | %------------------------------------------------------------------------ 33 | \begin{document} 34 | 35 | \begin{frame} 36 | \titlepage 37 | \includegraphics{../common/tux} 38 | \end{frame} 39 | 40 | \begin{frame} 41 | \frametitle{Overview} 42 | \tableofcontents 43 | \end{frame} 44 | 45 | %----------------------------------------------------------------------- 46 | \section{Memory management} 47 | 48 | \begin{frame} 49 | \frametitle{Adress types} 50 | \begin{itemize} 51 | \item \textbf{Virtual addresses:} Regular addresses for userspace programs. May or may not be backed by physical addresses. 52 | \item \textbf{Physical addresses:} Used between the processor and the systems memory. Not necessarily the same as bus addresses. 53 | \item \textbf{Bus adresses:} Used between peripheral buses and memory. Can sometimes be remapped with an IOMMU to provide features like making system memory appear as physically contiguous. 54 | \item \textbf{Kernel logical adresses:} The regular addresses used in the kernel. Often treated as if they were physical addresses and are mapped to a portion or all of the physical memory. Physical and logical addresses usually only differ by a fixed offset and are linear. 55 | \end{itemize} 56 | \end{frame} 57 | 58 | \begin{frame} 59 | \frametitle{Pages frames} 60 | \textbf{Physical memory is grouped into fixed size chunks:} 61 | \begin{itemize} 62 | \item Each chunk is called a page frame and are numbered sequentially. 63 | \item The size of page frames can vary but are usually 4096 bytes long. 64 | \item PAGE\_SIZE is defined to the size of the target you’re building for. 65 | \end{itemize} 66 | \end{frame} 67 | 68 | \begin{frame} 69 | \frametitle{Allocating memory in the kernel} 70 | void *kmalloc(size\_t size, gfp\_t flags) \\ 71 | The normal method of allocating memory in the kernel. 72 | \textbf{Commonly used flags:} 73 | \begin{itemize} 74 | \item GFP\_KERNEL: Normal kernel memory. May sleep. 75 | \item GFP\_ATOMIC: Allocation will not sleep. May use emergency pools. Can be used in interrupt handlers where sleeping is not allowed. 76 | \item GFP\_DMA: Allocate memory suitable for DMA. Ie. in the lower 32-bit address range 77 | \end{itemize} 78 | \end{frame} 79 | 80 | \begin{frame} 81 | \frametitle{Userspace: threads share process memory} 82 | \begin{center} 83 | \includegraphics[width=3cm]{media/memorymap.pdf} 84 | \end{center} 85 | \end{frame} 86 | 87 | 88 | %----------------------------------------------------------------------- 89 | \section{Interrupts and scheduling} 90 | 91 | \begin{frame} 92 | \frametitle{Concurrency} 93 | Sharing time across multiple processors. 94 | \begin{itemize} 95 | \item Your code can be interrupted at any time (with a few exceptions). 96 | \item Your code can be running at the same time on multiple CPUs. 97 | \item Your code can be re-entered by the same CPU. 98 | \item Always control access to shared data. 99 | \end{itemize} 100 | \end{frame} 101 | 102 | \begin{frame} 103 | \frametitle{Code execution modes} 104 | \begin{itemize} 105 | \item \textbf{Interrupts:} handle something that needs immediate attention, usually from a piece of hardware. The alternative is polling, which is less efficient. 106 | \item \textbf{SoftIRQs, Tasklets:} handle something directly, but allow interrupts 107 | \item \textbf{Kernel threads, user space threads:} 108 | \begin{itemize} 109 | \item Kernel threads and users space threads are tasks 110 | \item System calls are executed in the context of user space task 111 | \item Kernel threads are used to defer work or handle background task 112 | \end{itemize} 113 | \end{itemize} 114 | \end{frame} 115 | 116 | \begin{frame} 117 | \frametitle{Interrupts} 118 | \begin{itemize} 119 | \item Is not associated with a kernel process - no current task available. 120 | Cannot sleep. 121 | \item Is time critical since it interrupts other code. 122 | \item Try to defer any work to outside of interrupt context). 123 | \item No access to userspace (copy\_from\_user(), copy\_to\_user(), get\_user(), put\_user()) 124 | \end{itemize} 125 | \end{frame} 126 | 127 | \begin{frame} 128 | \frametitle{Top and bottom half interrupt handling} 129 | \begin{itemize} 130 | \item \textbf{Top half:} Do what is absolutely needed in interrupt context (i.e. let the device know that you have received the interrupt) 131 | \item \textbf{Bottom half:} Process the interrupt and the data that has been delivered 132 | \end{itemize} 133 | 134 | Easy to implement with the kernel’s threaded irqs API \footnote{\url{https://www.kernel.org/doc/htmldocs/kernel-api/API-request-threaded-irq.html}\\} \\ 135 | Note: you need to use the flag IRQF\_ONESHOT for the pi.. 136 | 137 | \end{frame} 138 | 139 | 140 | \begin{frame} 141 | \frametitle{Soft IRQs} 142 | \begin{itemize} 143 | \item Pending Soft IRQs are executed when when the kernel is about to return to user space. 144 | \item The Soft IRQs are statically allocated at compile time 145 | \item Handlers must be reentrant 146 | \item Only six types in use 147 | \item Examples: NET\_TX\_SOFTIRQ, NET\_RX\_SOFTIRQ 148 | \item Efficiently distributes deferred work across CPUs 149 | \item Good for highly threaded, high frequency tasks 150 | \item May not sleep 151 | \end{itemize} 152 | \end{frame} 153 | 154 | \begin{frame} 155 | \frametitle{Tasklets} 156 | \begin{itemize} 157 | \item Similar to Soft IRQs, and implemented on top 158 | \item All tasklets of the same type is handled sequencially and on the scheduling CPU 159 | \item Handlers do not need to be reentrant 160 | \item May not sleep 161 | \end{itemize} 162 | \end{frame} 163 | 164 | \begin{frame} 165 | \frametitle{Work queues} 166 | \begin{itemize} 167 | \item Queue work in kernel space 168 | \item Executed by worker thread (kernel task) 169 | \item Priority can be set. 170 | \end{itemize} 171 | \end{frame} 172 | 173 | \begin{frame} 174 | \frametitle{Summary} 175 | \includegraphics[width=0.8\textwidth]{media/interrupts.pdf} 176 | \end{frame} 177 | 178 | \begin{frame} 179 | \frametitle{Scheduling} 180 | \textbf{Realtime Scheduling Policy: Each task has a priority} 181 | \begin{itemize} 182 | \item SCHED\_FIFO: First-in, first-out scheduling algorithm Task continues to run until it blocks or explicitly yields 183 | \item SCHED\_RR: Each process can run only until it exhausts a predetermined timeslice 184 | \item SCHED\_DEADLINE: Earliest Deadline First (EDF) scheduling 185 | \end{itemize} 186 | \textbf{Normal Scheduling Policy:} 187 | \begin{itemize} 188 | \item SCHED\_NORMAL: Completely Fair Scheduler, used for cycles not spent on realtime tasks. 189 | \end{itemize} 190 | \end{frame} 191 | 192 | \begin{frame} 193 | \frametitle{SCHED\_NORMAL: completely fair scheduler} 194 | \begin{itemize} 195 | \item Tries to emulate a processor that is capable of running several tasks simultaneously. 196 | \item Aims to compensate a task for the time it has not been running, by calculating the wait time. 197 | \item When a task is running, it the wait time decreases and eventually a task with a longer wait time is scheduled. 198 | \end{itemize} 199 | See the kernel documentation for more information.\footnote{Kernel documentation, CFS scheduler \url{http://lxr.free-electrons.com/source/Documentation/scheduler/sched-design-CFS.txt} \\} 200 | 201 | \end{frame} 202 | %----------------------------------------------------------------------- 203 | 204 | \begin{frame} 205 | \Huge{\centerline{Thanks!}} 206 | \end{frame} 207 | 208 | \end{document} 209 | -------------------------------------------------------------------------------- /slideware/overview/overview.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | \usepackage{hyperref} 11 | 12 | \AtBeginSection[]{ 13 | \begin{frame} 14 | \vfill 15 | \centering 16 | \usebeamerfont{title}\Huge{\insertsectionhead\par} 17 | \vfill 18 | \end{frame} 19 | } 20 | 21 | %------------------------------------------------------------------------- 22 | 23 | \title[TLKDCC Overview]{Linux Kernel Overview} 24 | \author{Hans Holmberg} 25 | \institute[LKTP] 26 | { 27 | Linux Kernel Teaching Project \\ 28 | \medskip 29 | \textit{hans.holmberg@gmail.com} 30 | } 31 | \date{\today} 32 | %------------------------------------------------------------------------ 33 | \begin{document} 34 | 35 | \begin{frame} 36 | \titlepage 37 | \includegraphics{../common/tux} 38 | \end{frame} 39 | 40 | \begin{frame} 41 | \frametitle{Overview} 42 | \tableofcontents 43 | \end{frame} 44 | 45 | %----------------------------------------------------------------------- 46 | \section{What is Linux?} 47 | 48 | \begin{frame} 49 | \frametitle{What is Linux?} 50 | \begin{itemize} 51 | \item Linux is a Unix-like and mostly POSIX-compliant computer operating system (OS) assembled under the model of free and open-source software development and distribution. \footnote{Wikipedia on Linux \url{https://en.wikipedia.org/wiki/Linux}\\} 52 | \item The defining component of Linux is the Linux kernel, first released on September 17, 1991 by Linus Torvalds. 53 | \item Linux is sometimes referred to as GNU/Linux by the Free Software Foundation, as it relies of GNU code(such as the tool chain). 54 | \end{itemize} 55 | \end{frame} 56 | 57 | \begin{frame} 58 | \frametitle{Linux is everywhere} 59 | 25 years since it's creation, Linux now rules most of the planet's computer systems. \\ 60 | \begin{itemize} 61 | \item Servers 62 | \begin{itemize} 63 | \item First wide adoption of Linux 64 | \item Completely dominant 65 | \item Even Microsoft is using Linux to run their cloud 66 | \end{itemize} 67 | \item Embedded 68 | \begin{itemize} 69 | \item Phones: 1.3 Billion phones shipped with Android/Linux in 2015 70 | \item Runs lots and lots of other types of small devices(IOT/..) 71 | \end{itemize} 72 | \item Desktops - The exception, but any year now. 73 | \end{itemize} 74 | 75 | \end{frame} 76 | 77 | %----------------------------------------------------------------------- 78 | \section{The kernel as part of the system} 79 | 80 | \begin{frame} 81 | \frametitle{The kernel piece in the puzzle} 82 | The kernel's role in the system: \\ 83 | \begin{itemize} 84 | \item Hardware abstraction 85 | \item Provide services(IPC, networking, ..) 86 | \item Resource management(Memory, cpu time) 87 | \item Security 88 | \end{itemize} 89 | \end{frame} 90 | 91 | \begin{frame} 92 | \frametitle{The Kernel ABI} 93 | \begin{itemize} 94 | \item The Linux ABI is the kernel-–user space API, which allows programs in user space to access system resources and services of the Linux kernel. 95 | \item It is composed out of the System Call Interface of the Linux kernel and the subroutines in the GNU C Library (glibc), which are resonably compatible with POSIX. 96 | \item The ABI can also be considered to include the interfaces provided in the virtual file system. 97 | 98 | \item The Linux ABI must be backward compatible and must not break; this stability guarantees the portability of not only source code, but also pre-compiled programs. 99 | \end{itemize} 100 | \end{frame} 101 | 102 | \begin{frame} 103 | \frametitle{The kernel ABI} 104 | \begin{center} 105 | \includegraphics[width=0.8\textwidth]{media/kernel} 106 | \end{center} 107 | \end{frame} 108 | 109 | \begin{frame} 110 | \frametitle{Pitfalls} 111 | \begin{itemize} 112 | \item Kernel headers (kernel *.h-files needed by user space) consistency - User space and the kernel must have the same definition of structures passed over to the other side. 113 | \item 32 vs 64 bit - The kernel might be running in 64 bit while user space is 32 bit 114 | Pointer problems and different definitions of long, be careful! 115 | \end{itemize} 116 | \end{frame} 117 | 118 | %----------------------------------------------------------------------- 119 | \section{Everything is a file} 120 | 121 | \begin{frame} 122 | \frametitle{"Everything" is a file in Linux} 123 | \begin{itemize} 124 | \item "Everything is a file" describes one of the defining features of Unix, and its derivatives. 125 | 126 | \item Linux uses the file system abstraction to provide access to hardware, configuration and debug information by exposing files that can be read and written. 127 | \item Note that these special files are only exposed in file system name space - the files can be accessed like normal files but are not actually stored on any media. 128 | \end{itemize} 129 | \end{frame} 130 | 131 | \begin{frame} 132 | \frametitle{The Linux filesystem} 133 | \textbf{sys} : a means to export kernel data structures, their attributes, and the 134 | linkages between them to userspace \\ 135 | \textbf{configfs} : configuration of kernel objects from user space \\ 136 | \textbf{dev} : contains the special device files for all the devices \\ 137 | \textbf{proc} : more information to userspace (cmdline, version, devicetree) \\ 138 | \textbf{debugfs} : kernel to userspace debug information \\ 139 | \end{frame} 140 | 141 | \begin{frame} 142 | \frametitle{Examples} 143 | \begin{itemize} 144 | \item /proc/version 145 | \item /proc/cmdline 146 | \item /sys/bus/mmc/devices/ 147 | \end{itemize} 148 | \end{frame} 149 | 150 | %----------------------------------------------------------------------- 151 | \section{The kernel source code} 152 | 153 | \begin{frame} 154 | \frametitle{Upstream} 155 | 156 | There are several different kernels being maintained and released from the upstream community at kernel.org\footnote{The Linux Kernel Archives \url{https://www.kernel.org}\\}. 157 | 158 | \begin{itemize} 159 | \item Mainline (i.e 4.9-rc2) 160 | \begin{itemize} 161 | \item Maintained by Linus Torvalds, benevolent dictator 162 | \item Master tree, all new code is merged here 163 | \end{itemize} 164 | \item Stable and longterm: (i.e 4.4.30, 3.10.105) 165 | \begin{itemize} 166 | \item Maintained by Greg K-H and others 167 | \item Bugfixes(i.e. security flaws) and trivial support for new devices 168 | \end{itemize} 169 | \item Next 170 | \begin{itemize} 171 | \item Maintained by Stephen Rothwell 172 | \item Staging ground for new code from the maintainers 173 | \end{itemize} 174 | \end{itemize} 175 | \end{frame} 176 | 177 | \begin{frame} 178 | \frametitle{Source code anatomy overview} 179 | \begin{itemize} 180 | \item \textbf{kernel} : core kernel code (i.e kernel initialization) \\ 181 | \item \textbf{arch} : architecture specific code(i.e x86, arm, arm64, cris) \\ 182 | \item \textbf{drivers} : device trivers (i.e, keyboards, mmc, ..) \\ 183 | \item \textbf{documentation} : kernel documentation \\ 184 | \item \textbf{scripts} : kernel utilities i.e (checkpatch, cleanpatch) \\ 185 | \end{itemize} 186 | 187 | A really nice, cross-referenced web interface for accessing different version of the source code is prprovided by Free Electrons\footnote{LXR: \url{http://lxr.free-electrons.com/source/kernel/}\\}. 188 | \end{frame} 189 | 190 | \begin{frame} 191 | \frametitle{Finding documentation} 192 | \begin{itemize} 193 | \item Look in documentation/ 194 | \item Read the code! 195 | \item Use the git history 196 | \item Google! 197 | \end{itemize} 198 | \end{frame} 199 | 200 | \begin{frame} 201 | \frametitle{Essential tools} 202 | \textbf{git} 203 | \begin{itemize} 204 | \item \textbf{clone} : clone(duplicate) a repository \\ 205 | \item \textbf{checkout} : checkout a specific version\\ 206 | \item \textbf{diff} : compare two revisions\\ 207 | \item \textbf{log} : show commit history\\ 208 | \item \textbf{blame} : figure out which commit changed a particular line\\ 209 | \item \textbf{grep} : like normal grep, but faster in a git repo \\ 210 | \end{itemize} 211 | \textbf{gitk} : graphical tool for browsing the history 212 | \end{frame} 213 | 214 | %----------------------------------------------------------------------- 215 | \section{Building the kernel} 216 | 217 | \begin{frame} 218 | \frametitle{Kernel configuration} 219 | Before building the kernel you need to configure it for your target system. 220 | The .config file contains: 221 | \begin{itemize} 222 | \item Configuration options 223 | \item Debug enablement 224 | \item Which drivers to build 225 | \end{itemize} 226 | \end{frame} 227 | 228 | \begin{frame}[fragile] 229 | \frametitle{.config example - Raspberry pi} 230 | \begin{semiverbatim} 231 | # 232 | # Automatically generated file; DO NOT EDIT. 233 | # Linux/arm 4.9.0-rc3 Kernel Configuration 234 | # 235 | CONFIG_ARM=y 236 | CONFIG_ARM_HAS_SG_CHAIN=y 237 | CONFIG_MIGHT_HAVE_PCI=y 238 | CONFIG_SYS_SUPPORTS_APM_EMULATION=y 239 | CONFIG_HAVE_PROC_CPU=y 240 | CONFIG_STACKTRACE_SUPPORT=y 241 | CONFIG_LOCKDEP_SUPPORT=y 242 | CONFIG_TRACE_IRQFLAGS_SUPPORT=y 243 | ... and another 5732 lines 244 | \end{semiverbatim} 245 | \end{frame} 246 | 247 | \begin{frame} 248 | \frametitle{menuconfig} 249 | \includegraphics[width=\textwidth]{media/menuconfig.png} 250 | \end{frame} 251 | 252 | \begin{frame}[fragile] 253 | \frametitle{Sample build flow, Raspberry pi} 254 | \begin{semiverbatim} 255 | \item make ARCH=arm bcm2835_defconfig 256 | \item make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage 257 | \item make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules 258 | \item make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs 259 | \item make modules_install INSTALL_MOD_PATH=/mnt/rpi-root 260 | \item cp arch/arm/boot/zImage /mnt/rpi-root/boot 261 | \item cp arch/arm/boot/dts/*.dtb /mnt/rpi-root/boot 262 | \end{semiverbatim} 263 | \end{frame} 264 | 265 | %----------------------------------------------------------------------- 266 | \begin{frame} 267 | \Huge{\centerline{Thanks!}} 268 | \end{frame} 269 | 270 | \end{document} 271 | -------------------------------------------------------------------------------- /slideware/power/power.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | \usepackage{hyperref} 11 | \usepackage{listings} 12 | 13 | \AtBeginSection[]{ 14 | \begin{frame} 15 | \vfill 16 | \centering 17 | \usebeamerfont{title}\Huge{\insertsectionhead\par} 18 | \vfill 19 | \end{frame} 20 | } 21 | 22 | %------------------------------------------------------------------------- 23 | 24 | \title[TLKDCC Power management]{Power management} 25 | \author{Hans Holmberg} 26 | \institute[LKTP] 27 | { 28 | Linux Kernel Teaching Project \\ 29 | \medskip 30 | \textit{hans.holmberg@gmail.com} 31 | } 32 | \date{\today} 33 | %------------------------------------------------------------------------ 34 | \begin{document} 35 | 36 | \begin{frame} 37 | \titlepage 38 | \includegraphics{../common/tux} 39 | \end{frame} 40 | 41 | \begin{frame} 42 | \frametitle{Overview} 43 | \tableofcontents 44 | \end{frame} 45 | 46 | %----------------------------------------------------------------------- 47 | \section{Overview} 48 | 49 | \begin{frame} 50 | \frametitle{Why bother with power management?} 51 | \begin{itemize} 52 | \item Cost of energy 53 | \item Cost of cooling 54 | \item Battery time 55 | \item Skin temperature, CPU temperature restrictions 56 | \end{itemize} 57 | \end{frame} 58 | 59 | \begin{frame} 60 | \frametitle{Dynamic power dissapation} 61 | 62 | Dynamic power dissaption (P), depends on capacitance(C), voltage(V) and and clock frequency (f): 63 | \[P = CV^2f\] 64 | \begin{itemize} 65 | \item Capacitance is a constant in a given system and depends on the number of gates 66 | \item Minimal voltage depends on clock frequency, higher voltage is needed to charge capacitors as the frequency increases 67 | \item Performance scales with frequency 68 | \end{itemize} 69 | \end{frame} 70 | 71 | \begin{frame} 72 | \frametitle{Leakage} 73 | \begin{itemize} 74 | \item Even when the clock frequency is reduced to zero, the IP block will consume power due to leakage. 75 | \item To remove the leakage power consumtion, the voltage needs to be gated(turned off). 76 | \item Gating power comes at a cost: the internal state needs to be reinitialized when the block is power up again. 77 | \end{itemize} 78 | \end{frame} 79 | 80 | \begin{frame} 81 | \frametitle{So what can we do?} 82 | \begin{itemize} 83 | \item Scale down clock frequencies (while maintaining reasonable performance) 84 | \item Utilize any ip-block specific powersave functions 85 | \item Power down unused parts of the system 86 | \item Put the whole system to sleep when acceptable 87 | \end{itemize} 88 | \end{frame} 89 | %----------------------------------------------------------------------- 90 | \section{System / static power management} 91 | \begin{frame} 92 | \frametitle{Suspend} 93 | \begin{itemize} 94 | \item Initiated by userspace (i.e. after inactivity) 95 | \begin{itemize} 96 | \item \textbf{echo mem \textgreater /sys/power/state} 97 | \end{itemize} 98 | \item Puts the whole system to sleep 99 | \item Userspace is frozen 100 | \item Big latency cost 101 | \end{itemize} 102 | \begin{center} 103 | \includegraphics[width=6cm]{media/tuxsleep.png} 104 | \end{center} 105 | \end{frame} 106 | 107 | \begin{frame} 108 | \frametitle{Suspend-resume cycle} 109 | \begin{enumerate} 110 | \item Freeze tasks 111 | \item Suspend devices 112 | \item Disable nonboot cpus 113 | \item Enter suspend 114 | \item - wakeup event - 115 | \item Enable nonboot cpus 116 | \item Resume devices 117 | \item Thaw tasks 118 | \end{enumerate} 119 | \end{frame} 120 | 121 | \begin{frame} 122 | \frametitle{Driver hooks} 123 | \begin{enumerate} 124 | \item \textbf{prepare}: stop registring new devices 125 | \item \textbf{suspend}: stop IO, put device in low power state 126 | \item \textbf{suspend\_late}: save device state (if not done yet) 127 | \item \textbf{suspend\_noirq}: save device state if irqs need to be off 128 | \noindent\rule{4cm}{0.4pt} 129 | \item \textbf{resume\_noirq}: undo suspend\_noirq 130 | \item \textbf{resume\_early}: undo suspend\_late 131 | \item \textbf{resume}: undo suspend 132 | \item \textbf{complete}: undo prepare 133 | \end{enumerate} 134 | See the kernel docs for details \footnote{\url{https://www.kernel.org/doc/Documentation/power/devices.txt}} 135 | \end{frame} 136 | 137 | \begin{frame} 138 | \frametitle{Example - lpc32xx touchscreen driver} 139 | \begin{itemize} 140 | \item The lpc32xx driver implements suspend and resume 141 | \item drivers/input/touchscreen/lpc32xx\_ts.c:377 142 | \end{itemize} 143 | \end{frame} 144 | 145 | 146 | \begin{frame} 147 | \frametitle{Power Management Domains} 148 | \begin{itemize} 149 | \item Normally, the driver's bus framework calls the suspend hooks 150 | \item device.dev\_pm\_domain can be used to override the normal callbacks 151 | \item Used if power states needs to be coordinated across devices sharing a power resource (clocks, power planes, ..) 152 | \end{itemize} 153 | \end{frame} 154 | 155 | \begin{frame} 156 | \frametitle{Different policies} 157 | \begin{itemize} 158 | \item PCs: suspend on inactivity 159 | \item Handheld devices: suspend as soon as possible (opportunistic) 160 | \item Opportunistic suspend configured via /sys/power/autosleep 161 | \end{itemize} 162 | \includegraphics[width=6cm]{media/pchandheld.jpg} 163 | \end{frame} 164 | 165 | \begin{frame} 166 | \frametitle{Wake locks and wakeup sources} 167 | \begin{itemize} 168 | \item For opportunistic suspend, userspace and drivers needs to be able to keep the system awake if needed be 169 | \item Drivers can grab a wake lock to block suspend 170 | \item Userspace can create and unlock locks via 171 | \begin{itemize} 172 | \item /sys/power/wake\_lock 173 | \item /sys/power/wake\_unlock 174 | \end{itemize} 175 | \item Statistics on wakelocks are available in /sys/kernel/debug/wakeup\_sources 176 | \end{itemize} 177 | \end{frame} 178 | 179 | %----------------------------------------------------------------------- 180 | \section{Runtime power management} 181 | 182 | \begin{frame} 183 | \frametitle{Runtime/dynamic power management} 184 | 185 | \begin{itemize} 186 | \item Put devices in low-power mode when possible 187 | \item Userspace should not be affected 188 | \end{itemize} 189 | \begin{center} 190 | \includegraphics[width=6cm]{media/powerswitches.jpg} 191 | \end{center} 192 | \end{frame} 193 | 194 | 195 | \begin{frame} 196 | \frametitle{The runtime PM core} 197 | \begin{itemize} 198 | \item Drivers inform the PM core when a device is in use via: 199 | \begin{itemize} 200 | \item pm\_runtime\_get (I'm about to use it) 201 | \item pm\_runtime\_put (Done for now) 202 | \end{itemize} 203 | \item The PM core counts uses and triggers driver callbacks: 204 | \begin{itemize} 205 | \item runtime\_suspend (use count 1 -\textgreater 0) 206 | \item runtime\_resume (use count 0 -\textgreater 1) 207 | \end{itemize} 208 | \item It is also possible to suspend automatically after a specified inactivity time (autosuspend) 209 | \item API details in the kernel docs \footnote{\url{https://www.kernel.org/doc/Documentation/power/runtime\_pm.txt}} 210 | \end{itemize} 211 | \end{frame} 212 | 213 | \begin{frame} 214 | \frametitle{Combining system and runtime PM} 215 | Differences: 216 | \begin{itemize} 217 | \item System PM: suspend when requested, resume with system 218 | \item Runtime PM: suspend on inactivity, resume when needed 219 | \end{itemize} 220 | Solution: 221 | \begin{itemize} 222 | \item Implement runtime PM first 223 | \item If needed, implement system pm as well, and try to reuse runtime pm callbacks when possible 224 | \end{itemize} 225 | See Kevin Hilman's presentation for more details \footnote{\url{http://www.slideshare.net/linaroorg/runtime-pm}} 226 | \end{frame} 227 | 228 | \begin{frame} 229 | \frametitle{CPU Power save in idle} 230 | \begin{center} 231 | \includegraphics[width=3cm]{media/catnap.jpg} 232 | \end{center} 233 | \begin{itemize} 234 | \item When the CPU is not executing a task, Linux will try to put the processor in a low-power idle mode 235 | \item The idle mode is selected by a cpuidle governor that tries to balance power with wake-up latency depending on cpu-utilization 236 | \item Idle modes are architecture specific 237 | \end{itemize} 238 | \end{frame} 239 | 240 | %----------------------------------------------------------------------- 241 | \section{Frequency and voltage scaling} 242 | 243 | \begin{frame} 244 | \frametitle{Frequency and voltage scaling} 245 | \begin{itemize} 246 | \item Governors together with cpufreq drivers can control the performance and power consumtion according to different policies 247 | \item Cpufreq drivers provides architecture-specific implementation 248 | \item Governors provide generic policies 249 | \item Choosing governor is up to the user 250 | \end{itemize} 251 | \includegraphics[width=3cm]{media/tuxpolitician.png} 252 | \end{frame} 253 | 254 | \begin{frame} 255 | \frametitle{Governors 1/2} 256 | \begin{itemize} 257 | \item \textbf{Performance}: sets the CPU statically to the 258 | highest frequency within the borders of scaling\_min\_freq and 259 | scaling\_max\_freq. 260 | 261 | \item \textbf{Powersave}: sets the CPU statically to the 262 | lowest frequency within the borders of scaling\_min\_freq and 263 | scaling\_max\_freq. 264 | 265 | \item \textbf{Userspace}: allows the user, or any userspace 266 | program running with UID "root", to set the CPU to a specific frequency 267 | by making a sysfs file "scaling\_setspeed" available in the CPU-device 268 | directory. 269 | 270 | \end{itemize} 271 | \end{frame} 272 | 273 | \begin{frame} 274 | \frametitle{Governors 2/2} 275 | \begin{itemize} 276 | 277 | \item \textbf{Ondemand}: sets the CPU depending on the 278 | current usage. To do this the CPU must have the capability to 279 | switch the frequency very quickly. 280 | 281 | \item \textbf{Conservative}: much like the "ondemand" governor, sets the CPU depending on the current usage. Gracefully increases and decreases the CPU speed 282 | rather than jumping to max speed the moment there is any load on the 283 | CPU. 284 | \end{itemize} 285 | \end{frame} 286 | 287 | 288 | %----------------------------------------------------------------------- 289 | \begin{frame} 290 | \Huge{\centerline{Thanks!}} 291 | \end{frame} 292 | 293 | \end{document} 294 | -------------------------------------------------------------------------------- /slideware/sample/presentation_1.tex: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Beamer Presentation 3 | % LaTeX Template 4 | % Version 1.0 (10/11/12) 5 | % 6 | % This template has been downloaded from: 7 | % http://www.LaTeXTemplates.com 8 | % 9 | % License: 10 | % CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/) 11 | % 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | 14 | %---------------------------------------------------------------------------------------- 15 | % PACKAGES AND THEMES 16 | %---------------------------------------------------------------------------------------- 17 | 18 | \documentclass{beamer} 19 | 20 | \mode { 21 | 22 | % The Beamer class comes with a number of default slide themes 23 | % which change the colors and layouts of slides. Below this is a list 24 | % of all the themes, uncomment each in turn to see what they look like. 25 | 26 | %\usetheme{default} 27 | %\usetheme{AnnArbor} 28 | %\usetheme{Antibes} 29 | %\usetheme{Bergen} 30 | %\usetheme{Berkeley} 31 | %\usetheme{Berlin} 32 | %\usetheme{Boadilla} 33 | %\usetheme{CambridgeUS} 34 | %\usetheme{Copenhagen} 35 | %\usetheme{Darmstadt} 36 | %\usetheme{Dresden} 37 | %\usetheme{Frankfurt} 38 | %\usetheme{Goettingen} 39 | %\usetheme{Hannover} 40 | %\usetheme{Ilmenau} 41 | %\usetheme{JuanLesPins} 42 | %\usetheme{Luebeck} 43 | %\usetheme{Madrid} 44 | %\usetheme{Malmoe} 45 | %\usetheme{Marburg} 46 | %\usetheme{Montpellier} 47 | %\usetheme{PaloAlto} 48 | %\usetheme{Pittsburgh} 49 | %\usetheme{Rochester} 50 | %\usetheme{Singapore} 51 | %\usetheme{Szeged} 52 | %\usetheme{Warsaw} 53 | 54 | % As well as themes, the Beamer class has a number of color themes 55 | % for any slide theme. Uncomment each of these in turn to see how it 56 | % changes the colors of your current slide theme. 57 | 58 | %\usecolortheme{albatross} 59 | %\usecolortheme{beaver} 60 | %\usecolortheme{beetle} 61 | %\usecolortheme{crane} 62 | %\usecolortheme{dolphin} 63 | %\usecolortheme{dove} 64 | %\usecolortheme{fly} 65 | %\usecolortheme{lily} 66 | %\usecolortheme{orchid} 67 | %\usecolortheme{rose} 68 | \usecolortheme{seagull} 69 | %\usecolortheme{seahorse} 70 | %\usecolortheme{whale} 71 | %\usecolortheme{wolverine} 72 | 73 | %\setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line 74 | %\setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line 75 | 76 | %\setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line 77 | } 78 | 79 | \usepackage{graphicx} % Allows including images 80 | \usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables 81 | 82 | 83 | %---------------------------------------------------------------------------------------- 84 | % TITLE PAGE 85 | %---------------------------------------------------------------------------------------- 86 | 87 | \title[Short title]{Full Title of the Talk} % The short title appears at the bottom of every slide, the full title is only on the title page 88 | 89 | \author{John Smith} % Your name 90 | \institute[UCLA] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space 91 | { 92 | University of California \\ % Your institution for the title page 93 | \medskip 94 | \textit{john@smith.com} % Your email address 95 | } 96 | \date{\today} % Date, can be changed to a custom date 97 | 98 | \begin{document} 99 | 100 | \begin{frame} 101 | \titlepage % Print the title page as the first slide 102 | \includegraphics{../common/tux} 103 | \end{frame} 104 | 105 | \begin{frame} 106 | \frametitle{Overview} % Table of contents slide, comment this block out to remove it 107 | \tableofcontents % Throughout your presentation, if you choose to use \section{} and \subsection{} commands, these will automatically be printed on this slide as an overview of your presentation 108 | \end{frame} 109 | 110 | %---------------------------------------------------------------------------------------- 111 | % PRESENTATION SLIDES 112 | %---------------------------------------------------------------------------------------- 113 | 114 | %------------------------------------------------ 115 | \section{First Section} % Sections can be created in order to organize your presentation into discrete blocks, all sections and subsections are automatically printed in the table of contents as an overview of the talk 116 | %------------------------------------------------ 117 | 118 | \subsection{Subsection Example} % A subsection can be created just before a set of slides with a common theme to further break down your presentation into chunks 119 | 120 | \begin{frame} 121 | \frametitle{Paragraphs of Text} 122 | Sed iaculis dapibus gravida. Morbi sed tortor erat, nec interdum arcu. Sed id lorem lectus. Quisque viverra augue id sem ornare non aliquam nibh tristique. Aenean in ligula nisl. Nulla sed tellus ipsum. Donec vestibulum ligula non lorem vulputate fermentum accumsan neque mollis.\\~\\ 123 | 124 | Sed diam enim, sagittis nec condimentum sit amet, ullamcorper sit amet libero. Aliquam vel dui orci, a porta odio. Nullam id suscipit ipsum. Aenean lobortis commodo sem, ut commodo leo gravida vitae. Pellentesque vehicula ante iaculis arcu pretium rutrum eget sit amet purus. Integer ornare nulla quis neque ultrices lobortis. Vestibulum ultrices tincidunt libero, quis commodo erat ullamcorper id. 125 | \end{frame} 126 | 127 | %------------------------------------------------ 128 | 129 | \begin{frame} 130 | \frametitle{Bullet Points} 131 | \begin{itemize} 132 | \item Lorem ipsum dolor sit amet, consectetur adipiscing elit 133 | \item Aliquam blandit faucibus nisi, sit amet dapibus enim tempus eu 134 | \item Nulla commodo, erat quis gravida posuere, elit lacus lobortis est, quis porttitor odio mauris at libero 135 | \item Nam cursus est eget velit posuere pellentesque 136 | \item Vestibulum faucibus velit a augue condimentum quis convallis nulla gravida 137 | \end{itemize} 138 | \end{frame} 139 | 140 | %------------------------------------------------ 141 | 142 | \begin{frame} 143 | \frametitle{Blocks of Highlighted Text} 144 | \begin{block}{Block 1} 145 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lectus nisl, ultricies in feugiat rutrum, porttitor sit amet augue. Aliquam ut tortor mauris. Sed volutpat ante purus, quis accumsan dolor. 146 | \end{block} 147 | 148 | \begin{block}{Block 2} 149 | Pellentesque sed tellus purus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum quis magna at risus dictum tempor eu vitae velit. 150 | \end{block} 151 | 152 | \begin{block}{Block 3} 153 | Suspendisse tincidunt sagittis gravida. Curabitur condimentum, enim sed venenatis rutrum, ipsum neque consectetur orci, sed blandit justo nisi ac lacus. 154 | \end{block} 155 | \end{frame} 156 | 157 | %------------------------------------------------ 158 | 159 | \begin{frame} 160 | \frametitle{Multiple Columns} 161 | \begin{columns}[c] % The "c" option specifies centered vertical alignment while the "t" option is used for top vertical alignment 162 | 163 | \column{.45\textwidth} % Left column and width 164 | \textbf{Heading} 165 | \begin{enumerate} 166 | \item Statement 167 | \item Explanation 168 | \item Example 169 | \end{enumerate} 170 | 171 | \column{.5\textwidth} % Right column and width 172 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lectus nisl, ultricies in feugiat rutrum, porttitor sit amet augue. Aliquam ut tortor mauris. Sed volutpat ante purus, quis accumsan dolor. 173 | 174 | \end{columns} 175 | \end{frame} 176 | 177 | %------------------------------------------------ 178 | \section{Second Section} 179 | %------------------------------------------------ 180 | 181 | \begin{frame} 182 | \frametitle{Table} 183 | \begin{table} 184 | \begin{tabular}{l l l} 185 | \toprule 186 | \textbf{Treatments} & \textbf{Response 1} & \textbf{Response 2}\\ 187 | \midrule 188 | Treatment 1 & 0.0003262 & 0.562 \\ 189 | Treatment 2 & 0.0015681 & 0.910 \\ 190 | Treatment 3 & 0.0009271 & 0.296 \\ 191 | \bottomrule 192 | \end{tabular} 193 | \caption{Table caption} 194 | \end{table} 195 | \end{frame} 196 | 197 | %------------------------------------------------ 198 | 199 | \begin{frame} 200 | \frametitle{Theorem} 201 | \begin{theorem}[Mass--energy equivalence] 202 | $E = mc^2$ 203 | \end{theorem} 204 | \end{frame} 205 | 206 | %------------------------------------------------ 207 | 208 | \begin{frame} 209 | \frametitle{Image} 210 | \includegraphics{../common/tux} 211 | \end{frame} 212 | 213 | %------------------------------------------------ 214 | 215 | \begin{frame}[fragile] % Need to use the fragile option when verbatim is used in the slide 216 | \frametitle{Verbatim} 217 | \begin{example}[Theorem Slide Code] 218 | \begin{verbatim} 219 | \begin{frame} 220 | \frametitle{Theorem} 221 | \begin{theorem}[Mass--energy equivalence] 222 | $E = mc^2$ 223 | \end{theorem} 224 | \end{frame}\end{verbatim} 225 | \end{example} 226 | \end{frame} 227 | 228 | %------------------------------------------------ 229 | 230 | \begin{frame} 231 | \frametitle{Figure} 232 | Uncomment the code on this slide to include your own image from the same directory as the template .TeX file. 233 | %\begin{figure} 234 | %\includegraphics[width=0.8\linewidth]{test} 235 | %\end{figure} 236 | \end{frame} 237 | 238 | %------------------------------------------------ 239 | 240 | \begin{frame}[fragile] % Need to use the fragile option when verbatim is used in the slide 241 | \frametitle{Citation} 242 | An example of the \verb|\cite| command to cite within the presentation:\\~ 243 | 244 | This statement requires citation \cite{p1}. 245 | \end{frame} 246 | 247 | %------------------------------------------------ 248 | 249 | \begin{frame} 250 | \frametitle{References} 251 | \footnotesize{ 252 | \begin{thebibliography}{99} % Beamer does not support BibTeX so references must be inserted manually as below 253 | \bibitem[Smith, 2012]{p1} John Smith (2012) 254 | \newblock Title of the publication 255 | \newblock \emph{Journal Name} 12(3), 45 -- 678. 256 | \end{thebibliography} 257 | } 258 | \end{frame} 259 | 260 | %------------------------------------------------ 261 | 262 | \begin{frame} 263 | \Huge{\centerline{The End}} 264 | \end{frame} 265 | 266 | %---------------------------------------------------------------------------------------- 267 | 268 | \end{document} 269 | -------------------------------------------------------------------------------- /slideware/boot/machinedescriptions_n_boot.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | \usepackage{hyperref} 11 | 12 | \AtBeginSection[]{ 13 | \begin{frame} 14 | \vfill 15 | \centering 16 | \usebeamerfont{title}\Huge{\insertsectionhead\par} 17 | \vfill 18 | \end{frame} 19 | } 20 | 21 | %------------------------------------------------------------------------- 22 | 23 | \title[TLKDCC Machine descriptions and boot]{Machine descriptions and boot} 24 | \author{Hans Holmberg} 25 | \institute[LKTP] 26 | { 27 | Linux Kernel Teaching Project \\ 28 | \medskip 29 | \textit{hans.holmberg@gmail.com} 30 | } 31 | \date{\today} 32 | %------------------------------------------------------------------------ 33 | \begin{document} 34 | 35 | \begin{frame} 36 | \titlepage 37 | \includegraphics{../common/tux} 38 | \end{frame} 39 | 40 | \begin{frame} 41 | \frametitle{Overview} 42 | \tableofcontents 43 | \end{frame} 44 | 45 | %----------------------------------------------------------------------- 46 | \section{Kernel boot process} 47 | 48 | \begin{frame} 49 | \frametitle{Bootstrapping} 50 | \begin{itemize} 51 | \item The kernel cannot start itself on a system - a bootloader is needed to load the kernel from disk(or over the network, a serial cable or usb, ..). 52 | \item The boot loader (that is usally bootstrapped as well) must initialize the system memory and load the kernel and provide the kernel with sufficent information to initialize the machine it is running on. 53 | \end{itemize} 54 | \end{frame} 55 | 56 | \begin{frame} 57 | \frametitle{Kernel boot process overview} 58 | \includegraphics[width=\textwidth]{media/boot.pdf} 59 | \end{frame} 60 | 61 | \begin{frame} 62 | \frametitle{Secure boot} 63 | \begin{itemize} 64 | \item In order to keep malicious code from running in kernel space, the code and data must be verified to be from a trusted source. 65 | \item Verification is done using a chain of trust from the boot stages up to the kernel. Each component must cryptographically verify the next piece of code before executing it. 66 | \item Once the kernel is running, the kernel can verify all kernel modules it is loading, if you turn on the CONFIG\_MODULE\_SIG option \footnote{See module signing kernel documentation \url{https://www.kernel.org/doc/Documentation/module-signing.txt}\\} 67 | \end{itemize} 68 | \end{frame} 69 | 70 | \begin{frame} 71 | \frametitle{Kernel initialization} 72 | \begin{enumerate} 73 | \item Early init - handle parameters passed on from the bootloader 74 | \item Transition to protected mode (if x86) 75 | \item Decompression of kernel 76 | \item Page table and early interrupt and exception handling setup 77 | \item start\_kernel() \footnote{main.c \url{http://lxr.free-electrons.com/source/init/main.c} \\} 78 | \begin{enumerate} 79 | \item Perform arch−specific setup (memory layout analysis, copying boot command line again, etc.). 80 | \item Print Linux kernel "banner" containing the version (early prints available now) 81 | \item Initialise traps, irqs, data required for scheduler. 82 | \item Parse boot command line options and initialise console. - (normal console prints available) 83 | \item Enable interrupts. 84 | \item Initialize memory allocation and print out the "Memory: ..." line. 85 | \item Perform arch−specific "check for bugs" and, whenever possible, activate workaround for processor/bus/etc bugs. 86 | \item Initialize scheduler, trigger start of init process 87 | \item Go to idle loop 88 | \end{enumerate} 89 | \end{enumerate} 90 | \end{frame} 91 | 92 | \begin{frame} 93 | \frametitle{Memory map (post-boot) example, 32bit, Virtual} 94 | \begin{center} 95 | \includegraphics[width=0.4\textwidth]{media/memorymap.pdf} 96 | \end{center} 97 | \end{frame} 98 | %----------------------------------------------------------------------- 99 | \section{Machine descriptions} 100 | 101 | \begin{frame} 102 | \frametitle{Machine descriptions definition} 103 | Describing system hardware in a platform-independent manner 104 | \begin{itemize} 105 | \item One kernel binary, many boards/platforms 106 | \item Non-auto-detectable stuff needs to be specified somehow 107 | \item Devices on non-enumerable buses 108 | \item Device properties 109 | \item Memory mapped registers 110 | \item GPIOs 111 | \item Regulators 112 | \item ..other board/soc/.. specifics 113 | \end{itemize} 114 | \end{frame} 115 | 116 | \begin{frame} 117 | \frametitle{Illustration} 118 | \begin{center} 119 | \includegraphics[width=0.8\textwidth]{media/descriptiontree.pdf} 120 | \end{center} 121 | \end{frame} 122 | 123 | \begin{frame} 124 | \frametitle{Devicetree vs ACPI} 125 | \begin{itemize} 126 | \item Device tree 127 | \begin{itemize} 128 | \tiny 129 | \item Keep it simple 130 | \item Mandatory for all new ARM SOCs 131 | \item Machine description only (Flattened Device Tree) 132 | \item Tree structure written in DTS (Device Tree Source) format 133 | \item Compiler available in kernel tree 134 | \item Mainly embedded 135 | \item DTB Normally stored on main storage (eMMC / ..) 136 | \end{itemize} 137 | \item ACPI - Advanced Configuration and Power Interface 138 | \begin{itemize} 139 | \tiny 140 | \item Mainly x86/desktops/servers (but recently also in embedded stuff) 141 | \item Feature rich 142 | \item Aims to abstract the hardware from the OS 143 | \item Predominately x86 ...but support for ARM V8 added in the ACPI 5.1 spec 144 | \item Machine description (DSDT) + runtime services 145 | \item Tree structure written in ASL (ACPI Source Language) format 146 | \item Separate(open source) compiler available 147 | \item Normally stored in firmware SPI NOR 148 | \end{itemize} 149 | \end{itemize} 150 | \end{frame} 151 | 152 | \begin{frame} 153 | \frametitle{Development flow} 154 | \begin{itemize} 155 | \item Devicetree 156 | \begin{itemize} 157 | \item Update board .dts 158 | \item Build kernel, or just the dts 159 | \item Provision and reboot 160 | \item Commit result 161 | \end{itemize} 162 | \item ACPI 163 | \begin{itemize} 164 | \item Grab the DSDT table cat /sys/firmware/acpi/tables/DSDT > dsdt.dat 165 | \item Decompile iasl -d dsdt.dat 166 | \item Enable DSDT override (DSDT .hex included in kernel) 167 | \item Menuconfig: Device Drivers > Generic Driver Options > Include Custom DSDT 168 | \item Update dsdt.dsl (+kernel) 169 | \item Compile DSDT 170 | \item iasl -ic dsdt.dsl 171 | \item Build kernel, provision and reboot 172 | \item Update firmware 173 | \end{itemize} 174 | \end{itemize} 175 | \end{frame} 176 | 177 | \begin{frame} 178 | \frametitle{Machine description examples} 179 | \begin{itemize} 180 | \item Raspberry Pi 2B - arch/arm/boot/dts/bcm2709-rpi-2-b.dts 181 | \item Laptop - laptop\_dsdt.dsl 182 | \end{itemize} 183 | \end{frame} 184 | 185 | %----------------------------------------------------------------------- 186 | \section{Drivers} 187 | 188 | \begin{frame} 189 | \frametitle{What is a driver?} 190 | A device driver: 191 | \begin{itemize} 192 | \item Enables the operating system to interact with a piece of hardware. 193 | \item Aims to abstract the hardware specific properties away 194 | \item Provide access to it via an interface shared with other devices to a common kernel framework(i.e. input, iio, ..) 195 | \end{itemize} 196 | \end{frame} 197 | 198 | 199 | \begin{frame} 200 | \frametitle{What is a driver?} 201 | \begin{center} 202 | \includegraphics[width=0.65\textwidth]{media/driverstack.pdf} 203 | \end{center} 204 | \end{frame} 205 | 206 | \begin{frame} 207 | \frametitle{Driver vs Device} 208 | It is important to distinguish between drivers and devices: 209 | \begin{itemize} 210 | \item Object oriented view: A driver is the class, a device is an object. 211 | \item Drivers provide code handling a class of hardware, device objects contain the specific state for a single piece of hardware. 212 | \item Drivers work as adapters between the hardware and the kernel framework the devices are attached to. 213 | \end{itemize} 214 | \end{frame} 215 | 216 | \begin{frame} 217 | \frametitle{Driver vs Device} 218 | \begin{center} 219 | \includegraphics[width=0.65\textwidth]{media/driver.pdf} 220 | \end{center} 221 | \end{frame} 222 | 223 | \begin{frame} 224 | \frametitle{Device types} 225 | \begin{itemize} 226 | \item Block devices - access to raw storage 227 | \item Network devices - network interfaces 228 | \item Character devices - all others 229 | \end{itemize} 230 | 231 | %Major and minor number, used when creating files. 232 | %Documentation/devices.txt 233 | %All devices stored in /dev 234 | 235 | \end{frame} 236 | 237 | \begin{frame} 238 | \frametitle{Drivers, devices and buses} 239 | Drivers and devices are attached to a bus to communicate with the hardware. 240 | \begin{itemize} 241 | \item Completely enumarable buses: PCI, USB, .. 242 | \item Semi-enumerable buses: I2C, SPI, .. 243 | \item Non-enumerable bus: platform devices 244 | \end{itemize} 245 | \end{frame} 246 | 247 | 248 | \begin{frame} 249 | \frametitle{Driver life cycle} 250 | \begin{itemize} 251 | \item Init - global initialization 252 | \item Probe - create device 253 | \item Open / Close cycles 254 | \item Power management cycles 255 | \item Remove - global deinitalization 256 | \end{itemize} 257 | \end{frame} 258 | 259 | \begin{frame} 260 | \frametitle{Built in vs loadable modules} 261 | \begin{itemize} 262 | \item Code that does not need to be executed before a filesystem is available to the kernel can be compiled as a kernel module. \\ 263 | \item Kernel modules saves a lot of memory! 264 | \item Modules can be loaded automatically, if the module provides a device table that can be matched with i.e usb device ids. \\ 265 | \end{itemize} 266 | \end{frame} 267 | 268 | \begin{frame} 269 | \frametitle{Useful tools} 270 | \begin{itemize} 271 | \item List loaded modules: lsmod 272 | \item Load module: insmod(single module), modprobe(resolves dependencies) 273 | \item Display module information: modinfo 274 | \item Generate module dependencies: depmod 275 | \item Driver module example: pl2303 serial converter\\ 276 | \end{itemize} 277 | See the kernel documentation project for more (great) documentation on kernel modules \footnote{Linux Loadable Kernel Module HOWTO \url{http://www.tldp.org/HOWTO/html\_single/Module-HOWTO/}\\}. 278 | \end{frame} 279 | 280 | \begin{frame} 281 | \frametitle{ACPI Driver example} 282 | ACPI Battery driver 283 | \begin{itemize} 284 | \item ID: PNP0C0D 285 | \item Source: drivers/acpi/button.c 286 | \end{itemize} 287 | \end{frame} 288 | 289 | \begin{frame} 290 | \frametitle{Devicetree example} 291 | GPIO Regulator driver 292 | \begin{itemize} 293 | \item ID: gpio-regulator 294 | \item Source: drivers/regulator/gpio-regulator.c 295 | \end{itemize} 296 | \end{frame} 297 | 298 | %----------------------------------------------------------------------- 299 | 300 | \begin{frame} 301 | \Huge{\centerline{Thanks!}} 302 | \end{frame} 303 | 304 | \end{document} 305 | -------------------------------------------------------------------------------- /slideware/boot/media/driverstack.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 27 | 32 | 33 | 40 | 45 | 46 | 53 | 59 | 60 | 67 | 73 | 74 | 75 | 93 | 95 | 96 | 98 | image/svg+xml 99 | 101 | 102 | 103 | 104 | 105 | 109 | 156 | 163 | Process 176 | User space 188 | 193 | Kernel space 205 | 212 | Kernelframework 230 | Driver 243 | 250 | Hardware 263 | 264 | 265 | -------------------------------------------------------------------------------- /slideware/boot/media/driver.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 27 | 32 | 33 | 40 | 45 | 46 | 53 | 58 | 59 | 66 | 71 | 72 | 79 | 84 | 85 | 92 | 98 | 99 | 106 | 112 | 113 | 114 | 132 | 134 | 135 | 137 | image/svg+xml 138 | 140 | 141 | 142 | 143 | 144 | 148 | 155 | 162 | 209 | 216 | Kernelframework 234 | Driver 247 | 254 | Hardware 267 | 276 | 285 | 294 | Device 307 | 312 | 313 | 314 | -------------------------------------------------------------------------------- /slideware/debug/debug.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | 3 | \mode { 4 | \usecolortheme{seagull} 5 | 6 | \setbeamertemplate{footline}[page number]} 7 | \usepackage{graphicx} 8 | \usepackage{booktabs} 9 | \usepackage{url} 10 | \usepackage{hyperref} 11 | \usepackage{listings} 12 | 13 | \AtBeginSection[]{ 14 | \begin{frame} 15 | \vfill 16 | \centering 17 | \usebeamerfont{title}\Huge{\insertsectionhead\par} 18 | \vfill 19 | \end{frame} 20 | } 21 | 22 | %------------------------------------------------------------------------- 23 | 24 | \title[TLKDCC Debugging]{Debugging} 25 | \author{Hans Holmberg} 26 | \institute[LKTP] 27 | { 28 | Linux Kernel Teaching Project \\ 29 | \medskip 30 | \textit{hans.holmberg@gmail.com} 31 | } 32 | \date{\today} 33 | %------------------------------------------------------------------------ 34 | \begin{document} 35 | 36 | \begin{frame} 37 | \titlepage 38 | \includegraphics{../common/tux} 39 | \end{frame} 40 | 41 | \begin{frame} 42 | \frametitle{Overview} 43 | \tableofcontents 44 | \end{frame} 45 | 46 | %----------------------------------------------------------------------- 47 | \section{Debug prints} 48 | 49 | \begin{frame} 50 | \frametitle{Debug prints in the kernel} 51 | \begin{itemize} 52 | \item Prints are easy to implement, but comes at a cost 53 | \item Code size and execution time is affected 54 | \item Consider what is *really* needed to leave in your code 55 | \item Don't use printk, use standardized formatting instead: 56 | \begin{itemize} 57 | \item \textbf{dev\_warn, dev\_err, .. :} with device pointer 58 | \item \textbf{pr\_warn, pr\_err, .. :} no device pointer 59 | \end{itemize} 60 | \end{itemize} 61 | \end{frame} 62 | 63 | \begin{frame}[fragile] 64 | \frametitle{Example 1} 65 | \begin{verbatim} 66 | static int __init my_init(void) 67 | { 68 | if (bus_register(&some_bus)) { 69 | pr_err("my_module: Failed to register\n"); 70 | goto fail_bus_register; 71 | } 72 | pr_info("my_module: init done\n"); 73 | return 0; 74 | 75 | fail_bus_register: 76 | return -1; 77 | } 78 | module_init(my_init); 79 | \end{verbatim} 80 | \end{frame} 81 | 82 | \begin{frame}[fragile] 83 | \frametitle{Example 2} 84 | \begin{verbatim} 85 | ssize_t show_attr(struct device *dev, 86 | struct device_attribute *attr, 87 | char *buf) 88 | { 89 | struct my_dev *mdev = to_mdev(dev); 90 | 91 | dev_info(dev, "Showing attribute %s\n", 92 | attr->attr.name); 93 | 94 | if (!mdev->handle) { 95 | dev_err(dev, "Invalid handle\n"); 96 | return 0; 97 | } 98 | ... 99 | } 100 | \end{verbatim} 101 | \end{frame} 102 | 103 | \begin{frame} 104 | \frametitle{Warning levels} 105 | 106 | \begin{table}[h!] 107 | \begin{tabular}{l l l} 108 | \toprule 109 | Level & Meaning & Macros \\ 110 | \midrule 111 | 0 & emergency message & *\_emerg \\ 112 | 1 & alert & *\_alert \\ 113 | 2 & critical condition & *\_crit \\ 114 | 3 & error & *\_err \\ 115 | 4 & warning & *\_warn \\ 116 | 5 & notice & *\_notice \\ 117 | 6 & information & *\_info \\ 118 | 7 & debug & *\_debug \\ 119 | \bottomrule 120 | \end{tabular} 121 | \end{table} 122 | 123 | \end{frame} 124 | 125 | \begin{frame} 126 | \frametitle{Looking at the logs} 127 | \begin{itemize} 128 | \item A subset of logs are printed on the serial debug port. To determine the subset, set the kernel commandline parameter loglevel=N, where: 129 | \begin{itemize} 130 | \item \textbf{N = 0 :} nothing is printed 131 | \item \textbf{N = 8 :} everything is printed 132 | \end{itemize} 133 | \item To change log level at runtime: 134 | \begin{itemize} 135 | \item echo \textless level\textgreater \space \textgreater \space /proc/sys/kernel/printk 136 | \end{itemize} 137 | \item To view the logs after boot, use dmesg. 138 | \begin{itemize} 139 | \item dmesg -l \textless level\textgreater \space filters messages 140 | \end{itemize} 141 | \end{itemize} 142 | 143 | \end{frame} 144 | 145 | \begin{frame}[fragile] 146 | \frametitle{Enabling debug prints compile time} 147 | \begin{itemize} 148 | \item pr\_debug and dev\_debug are normally empty macros 149 | \item To enable debugging output, build the appropriate file with -DDEBUG by adding the following line to the Makefile: 150 | \begin{verbatim} 151 | FLAGS_[filename].o := -DDEBUG 152 | \end{verbatim} 153 | \end{itemize} 154 | \end{frame} 155 | 156 | \begin{frame} 157 | \frametitle{Dynamic debug} 158 | \begin{itemize} 159 | \item Dynamic debug is designed to allow you to dynamically enable/disable kernel code to obtain additional kernel information. 160 | \item If the config option CONFIG\_DYNAMIC\_DEBUG is set, *\_debug calls can be dynamically enabled via debugfs/dynamic\_debug/control 161 | \item Debug messages can be enabled per: 162 | \begin{itemize} 163 | \item source filename 164 | \item function name 165 | \item line number .. 166 | \end{itemize} 167 | \item See the kernel documentation\footnote{Dynamic debug howto \url{https://www.kernel.org/doc/Documentation/dynamic-debug-howto.txt} \\} for more info. 168 | \end{itemize} 169 | \end{frame} 170 | 171 | %----------------------------------------------------------------------- 172 | \section{Tracing} 173 | 174 | \begin{frame} 175 | \frametitle{Strace} 176 | \begin{itemize} 177 | \item A command line tool that intercepts and records the system calls which are called by a process and the signals which are received by a process. 178 | \item Useful for bug isolation, sanity checking of the kernel ABI and 179 | a great way of learning about kernel/userspace interaction. 180 | \item Enables debugging of a program without a recompile (or even access to the source code) 181 | \end{itemize} 182 | \end{frame} 183 | 184 | \begin{frame} 185 | \frametitle{Ftrace} 186 | \begin{itemize} 187 | \item A tracer designed to help out developers and 188 | designers of systems to find what is going on inside the kernel. 189 | \item Very often enabled on production kernels - you can debug your customer's running kernel image. 190 | \item Minimal overhead 191 | \item Uses a ring buffer for storing trace data 192 | \item Versatile - function tracing, event tracing, fast prints... 193 | \item Great for studing kernel internals 194 | \end{itemize} 195 | \end{frame} 196 | 197 | \begin{frame} 198 | \frametitle{Menuconfig - Kernelhacking - Tracers} 199 | \includegraphics[width=0.7\textwidth]{media/tracingmenuconfig.png} 200 | \end{frame} 201 | 202 | \begin{frame}[fragile] 203 | \frametitle{Check available tracers} 204 | \begin{verbatim} 205 | cd /sys/kernel/debug/tracing 206 | cat available_tracers 207 | \end{verbatim} 208 | \end{frame} 209 | 210 | \begin{frame} 211 | \frametitle{Function trace} 212 | \begin{itemize} 213 | \item Uses the -pg option in gcc to insert a call to the special function mcount\(\) at the start of every function 214 | \item During compilation, all calls to mcount is recorded and stored in the kernel 215 | \item During boot, these are converted to NOP-instructions during to cut away overhead 216 | \item The NOP's are converted to trace calls when tracing is enabled 217 | \item The magic is well described in Steven Roestedt's presentation from Linux Plumbers 2014. \footnote{Ftrace Kernel Hooks: More than just tracing \url{https://linuxplumbersconf.org/2014/ocw/system/presentations/1773/original/ftrace-kernel-hooks-2014.pdf} \\} 218 | \end{itemize} 219 | \end{frame} 220 | 221 | \begin{frame}[fragile] 222 | \frametitle{Function trace - Example 1} 223 | \begin{verbatim} 224 | cd /sys/kernel/debug/tracing 225 | echo function > current_tracer 226 | echo 1 > tracing_on && sleep 1 && echo 0 > tracing_on 227 | cat trace 228 | \end{verbatim} 229 | \end{frame} 230 | 231 | \begin{frame}[fragile] 232 | \frametitle{Function trace - Example 2} 233 | \begin{verbatim} 234 | cd /sys/kernel/debug/tracing 235 | echo pl011* > set_ftrace_filter 236 | echo function > current_tracer 237 | cat trace 238 | echo 1 > tracing_on && sleep 1 && echo 0 > tracing_on 239 | cat trace 240 | echo function_graph > current_tracer 241 | echo 1 > tracing_on && sleep 1 && echo 0 > tracing_on 242 | cat trace 243 | \end{verbatim} 244 | \end{frame} 245 | 246 | \begin{frame} 247 | \frametitle{Trace points} 248 | \begin{itemize} 249 | \item One of the most common uses of ftrace is the event tracing. 250 | Through out the kernel is hundreds of static event points that 251 | can be enabled via the debugfs file system to see what is 252 | going on in certain parts of the kernel. 253 | \item Available events: cat /sys/kernel/debug/tracing/available\_events 254 | \end{itemize} 255 | \end{frame} 256 | 257 | \begin{frame}[fragile] 258 | \frametitle{Trace points example} 259 | What is the irq number for the pl011 interrupt? 260 | \begin{verbatim} 261 | echo irq_handler_entry >> set_event 262 | echo irq_handler_exit >> set_event 263 | echo nop > current_tracer 264 | echo 1 > tracing_on && sleep 1 && echo 0 > tracing_on 265 | cat trace |grep pl011 266 | \end{verbatim} 267 | \end{frame} 268 | 269 | \begin{frame} 270 | \frametitle{Trace\_printk} 271 | \begin{itemize} 272 | \item Printk is great, but has significant overhead and can bog down the system and change timing. 273 | \item trace\_printk has minimal overhead and writes to the trace buffer instead of of the console. It can be used in any context. 274 | \item printk has an overhead in the order of milliseconds, trace\_printk in microseconds 275 | \item trace prints will be displayed in all tracer outputs 276 | \end{itemize} 277 | \end{frame} 278 | 279 | \begin{frame}[fragile] 280 | \frametitle{Example - Traceprintk} 281 | \tiny 282 | \begin{verbatim} 283 | static irqreturn_t pl011_int (int irq , void * dev_id ) 284 | { 285 | ... 286 | status = readl ( uap - > port . membase + UART011_MIS ); 287 | trace_printk (" status %#x\n", status ); 288 | ... 289 | \end{verbatim} 290 | \noindent\rule[0.5ex]{\linewidth}{1pt} 291 | \begin{verbatim} 292 | cat/sys/kernel/debug/tracing/trace 293 | # _ -----= > irqs-off 294 | # / _----= > need-resched 295 | # | /_---= > hardirq / softirq 296 | # ||/_--= > preempt - depth 297 | # |||/ delay 298 | # TASK-PID CPU# |||| TIMESTAMP FUNCTION 299 | # | | | | || | | | 300 | kworker /0:1-549 [000] d.h2 47.102049: pl011_int : status 0 x20 301 | sh -666 [000] d.h2 47.102438: pl011_int : status 0 x20 302 | \end{verbatim} 303 | \end{frame} 304 | 305 | \begin{frame} 306 | \frametitle{Other functions} 307 | Ftrace is really powerful and has lots of other uses.\\ 308 | Additional tracers: \\ 309 | \begin{itemize} 310 | \item irqsoff : measure max interrupt latency 311 | \item wakeup : measure max task wakeup latency 312 | \end{itemize} 313 | You can also dynamically trigger tracing, monitor stack usage, and many other things. See the kernel documentation \footnote{Ftrace \url{https://www.kernel.org/doc/Documentation/trace/ftrace.txt}}. \\ 314 | Rabin Vincent's presentation from LLC 2013 is also a good source of ftrace tricks and hacks \footnote{Introduction to ftrace \url{http://goo.gl/NttCcp} \\}. 315 | \end{frame} 316 | %----------------------------------------------------------------------- 317 | \section{Crash log analysis} 318 | \begin{frame} 319 | \frametitle{Oops and kernel panics} 320 | \begin{itemize} 321 | \item \textbf{Panic} : Unrecoverable errors 322 | \item \textbf{Oops} : Non-fatal error, kernel continues (but might not work correctly) 323 | \end{itemize} 324 | \end{frame} 325 | 326 | \begin{frame}[fragile] 327 | \frametitle{Oops example} 328 | \tiny 329 | \begin{verbatim} 330 | [ 41.596330] ------------[ cut here ]------------ 331 | [ 41.603095] kernel BUG at drivers/input/keyboard/gpio_led_key.c:52! 332 | [ 41.611584] Internal error: Oops - BUG: 0 [#1] SMP ARM 333 | [ 41.618969] Modules linked in: 334 | [ 41.624291] CPU: 2 PID: 91 Comm: irq/184-soc:led Not tainted 4.9.0-rc3-v7+ #4 335 | [ 41.633877] Hardware name: BCM2709 336 | [ 41.639723] task: b9100000 task.stack: b9108000 337 | [ 41.646723] PC is at led_gpio_key_isr+0xc4/0xe0 338 | [ 41.653702] LR is at regulator_enable+0xa8/0x14c 339 | [ 41.660736] pc : [<80583cb8>] lr : [<804a3f24>] psr: 60000013 340 | [ 41.660736] sp : b9109ee0 ip : b9109ec0 fp : b9109f04 341 | [ 41.677151] r10: 8016f100 r9 : b9bf8e80 r8 : b9bf8d80 342 | [ 41.684878] r7 : 00000000 r6 : b9194c00 r5 : 00000000 r4 : b9bf7e10 343 | [ 41.693959] r3 : 80a5f9d0 r2 : 00000000 r1 : 00000000 r0 : 00000000 344 | [ 41.703034] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user 345 | [ 41.712788] Control: 10c5387d Table: 391f406a DAC: 00000055 346 | [ 41.721158] Process irq/184-soc:led (pid: 91, stack limit = 0xb9108210) 347 | [ 41.730480] Stack: (0xb9109ee0 to 0xb910a000) 348 | [ 41.737543] 9ee0: 80583bf4 b9bf8e80 00000000 b9b66b40 00000001 b9b66b40 b9109f24 b9109f08 349 | [ 41.751388] 9f00: 8016f12c 80583c00 00000004 b9108000 00000000 b9bf8ea4 b9109f5c b9109f28 350 | [ 41.765431] 9f20: 8016f460 8016f10c 00000000 8016f278 00000000 b9bf8ec0 00000000 b9bf8e80 351 | [ 41.779664] 9f40: 8016f338 00000000 00000000 00000000 b9109fac b9109f60 8013c710 8016f344 352 | [ 41.794046] 9f60: 00000000 00000000 00000000 b9bf8e80 00000000 00000000 b9109f78 b9109f78 353 | [ 41.808738] 9f80: 00000000 00000000 b9109f88 b9109f88 b9bf8ec0 8013c628 00000000 00000000 354 | [ 41.823806] 9fa0: 00000000 b9109fb0 80107e88 8013c634 00000000 00000000 00000000 00000000 355 | [ 41.839158] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 356 | [ 41.854878] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000 357 | [ 41.870790] [<80583cb8>] (led_gpio_key_isr) from [<8016f12c>] (irq_thread_fn+0x2c/0x44) 358 | [ 41.886655] [<8016f12c>] (irq_thread_fn) from [<8016f460>] (irq_thread+0x128/0x1f8) 359 | [ 41.902258] [<8016f460>] (irq_thread) from [<8013c710>] (kthread+0xe8/0x104) 360 | [ 41.913375] [<8013c710>] (kthread) from [<80107e88>] (ret_from_fork+0x14/0x2c) 361 | [ 41.924627] Code: e2422001 e3520000 e583205c 1affffef (e7f001f2) 362 | [ 41.934698] ---[ end trace c6b22157650fc26a ]--- 363 | \end{verbatim} 364 | \end{frame} 365 | 366 | \begin{frame}[fragile] 367 | \frametitle{Post mortem analysis} 368 | \begin{itemize} 369 | \item If the kernel panics, a common way of debugging is to save the contents of the system memory and analyze it. 370 | \item The kernel can be configured (CONFIG\_CRASH\_DUMP) to boot into a second kernel at separate location in memory, capable of saving the system memory to disk or send it over the network. 371 | \item See the kdump kernel documentation for how to set this up \footnote{kdump \url{https://www.kernel.org/doc/Documentation/kdump/kdump.txt}} 372 | \item When the capture kernel has booted, the dump is available in /proc/vmcore 373 | \item Wikipedia also has a good page on this \footnote{Wikipedia kdump \url{https://en.wikipedia.org/wiki/Kdump_(Linux)} \\} 374 | \end{itemize} 375 | \end{frame} 376 | 377 | \begin{frame} 378 | \frametitle{Analyzing dumps: crashtool} 379 | \begin{itemize} 380 | \item Developed by Red Hat 381 | \item Requires a dump file and a kernel image built with symbols included 382 | \item Provides an interactive environment similar to gdb 383 | \item Can display information about tasks, display back traces, display log and trace buffers, inspect memory, and much more 384 | \item See the excellent documentation for more information \footnote{Crash \url{https://people.redhat.com/anderson/crash_whitepaper} \\} 385 | \end{itemize} 386 | \end{frame} 387 | 388 | %----------------------------------------------------------------------- 389 | \section{Interactive debug} 390 | \begin{frame} 391 | \frametitle{Kgdb} 392 | \begin{itemize} 393 | \item Enables in-kernel debugging directly using a non-usb keyboard and vga text console or remotely using a serial port 394 | \item Possible to stop the kernel, do single stepping, inspect memory 395 | \item See the documentation \footnote{Kgdb \url{http://free-electrons.com/kerneldoc/latest/DocBook/kgdb/} \\} for how to set it up. 396 | \item Can be used with QEMU 397 | \end{itemize} 398 | \end{frame} 399 | 400 | \begin{frame} 401 | \frametitle{JTAG debugging} 402 | \begin{itemize} 403 | \item Enables full debugging of the hardware from another machine via a dongle witout affecting the kernel. 404 | \item Dongles range from relatively inexpensive to extremely expensive and feature-rich. 405 | \item GDB can be used as a front-end. 406 | \end{itemize} 407 | \end{frame} 408 | 409 | %----------------------------------------------------------------------- 410 | \begin{frame} 411 | \Huge{\centerline{Thanks!}} 412 | \end{frame} 413 | 414 | \end{document} 415 | -------------------------------------------------------------------------------- /slideware/boot/media/memorymap.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 27 | 32 | 33 | 40 | 45 | 46 | 53 | 59 | 60 | 67 | 73 | 74 | 75 | 93 | 95 | 96 | 98 | image/svg+xml 99 | 101 | 102 | 103 | 104 | 105 | 109 | 116 | 123 | 130 | - 0x40000000 184 | 191 | 198 | 204 | - 0xC0000000 218 | Kernel 231 | 237 | 243 | 250 | Process stack 263 | 270 | Shared libraries 283 | Process dataand code 301 | reserved 314 | 321 | Heap 334 | - 0x00000000 348 | - 0x08048000 362 | - 0xFFFFFFF 376 | 377 | 378 | -------------------------------------------------------------------------------- /slideware/interrupts/media/memorymap.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 27 | 32 | 33 | 40 | 45 | 46 | 53 | 59 | 60 | 67 | 73 | 74 | 75 | 93 | 95 | 96 | 98 | image/svg+xml 99 | 101 | 102 | 103 | 104 | 105 | 109 | 116 | 123 | 130 | 177 | 184 | 190 | Kernel 203 | 209 | 215 | 222 | Stack 235 | 242 | Shared libraries 255 | Process 268 | reserved 281 | 288 | Heap 301 | 318 | 325 | ThreadA 343 | ThreadB 361 | 362 | 363 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The following license applies to all source files in this project, 2 | unless explicitly stated otherwise in the source file itself. 3 | 4 | 5 | GNU GENERAL PUBLIC LICENSE 6 | Version 2, June 1991 7 | 8 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 9 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 10 | Everyone is permitted to copy and distribute verbatim copies 11 | of this license document, but changing it is not allowed. 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change free 18 | software--to make sure the software is free for all its users. This 19 | General Public License applies to most of the Free Software 20 | Foundation's software and to any other program whose authors commit to 21 | using it. (Some other Free Software Foundation software is covered by 22 | the GNU Lesser General Public License instead.) You can apply it to 23 | your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | this service if you wish), that you receive source code or can get it 29 | if you want it, that you can change the software or use pieces of it 30 | in new free programs; and that you know you can do these things. 31 | 32 | To protect your rights, we need to make restrictions that forbid 33 | anyone to deny you these rights or to ask you to surrender the rights. 34 | These restrictions translate to certain responsibilities for you if you 35 | distribute copies of the software, or if you modify it. 36 | 37 | For example, if you distribute copies of such a program, whether 38 | gratis or for a fee, you must give the recipients all the rights that 39 | you have. You must make sure that they, too, receive or can get the 40 | source code. And you must show them these terms so they know their 41 | rights. 42 | 43 | We protect your rights with two steps: (1) copyright the software, and 44 | (2) offer you this license which gives you legal permission to copy, 45 | distribute and/or modify the software. 46 | 47 | Also, for each author's protection and ours, we want to make certain 48 | that everyone understands that there is no warranty for this free 49 | software. If the software is modified by someone else and passed on, we 50 | want its recipients to know that what they have is not the original, so 51 | that any problems introduced by others will not reflect on the original 52 | authors' reputations. 53 | 54 | Finally, any free program is threatened constantly by software 55 | patents. We wish to avoid the danger that redistributors of a free 56 | program will individually obtain patent licenses, in effect making the 57 | program proprietary. To prevent this, we have made it clear that any 58 | patent must be licensed for everyone's free use or not licensed at all. 59 | 60 | The precise terms and conditions for copying, distribution and 61 | modification follow. 62 | 63 | GNU GENERAL PUBLIC LICENSE 64 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 65 | 66 | 0. This License applies to any program or other work which contains 67 | a notice placed by the copyright holder saying it may be distributed 68 | under the terms of this General Public License. The "Program", below, 69 | refers to any such program or work, and a "work based on the Program" 70 | means either the Program or any derivative work under copyright law: 71 | that is to say, a work containing the Program or a portion of it, 72 | either verbatim or with modifications and/or translated into another 73 | language. (Hereinafter, translation is included without limitation in 74 | the term "modification".) Each licensee is addressed as "you". 75 | 76 | Activities other than copying, distribution and modification are not 77 | covered by this License; they are outside its scope. The act of 78 | running the Program is not restricted, and the output from the Program 79 | is covered only if its contents constitute a work based on the 80 | Program (independent of having been made by running the Program). 81 | Whether that is true depends on what the Program does. 82 | 83 | 1. You may copy and distribute verbatim copies of the Program's 84 | source code as you receive it, in any medium, provided that you 85 | conspicuously and appropriately publish on each copy an appropriate 86 | copyright notice and disclaimer of warranty; keep intact all the 87 | notices that refer to this License and to the absence of any warranty; 88 | and give any other recipients of the Program a copy of this License 89 | along with the Program. 90 | 91 | You may charge a fee for the physical act of transferring a copy, and 92 | you may at your option offer warranty protection in exchange for a fee. 93 | 94 | 2. You may modify your copy or copies of the Program or any portion 95 | of it, thus forming a work based on the Program, and copy and 96 | distribute such modifications or work under the terms of Section 1 97 | above, provided that you also meet all of these conditions: 98 | 99 | a) You must cause the modified files to carry prominent notices 100 | stating that you changed the files and the date of any change. 101 | 102 | b) You must cause any work that you distribute or publish, that in 103 | whole or in part contains or is derived from the Program or any 104 | part thereof, to be licensed as a whole at no charge to all third 105 | parties under the terms of this License. 106 | 107 | c) If the modified program normally reads commands interactively 108 | when run, you must cause it, when started running for such 109 | interactive use in the most ordinary way, to print or display an 110 | announcement including an appropriate copyright notice and a 111 | notice that there is no warranty (or else, saying that you provide 112 | a warranty) and that users may redistribute the program under 113 | these conditions, and telling the user how to view a copy of this 114 | License. (Exception: if the Program itself is interactive but 115 | does not normally print such an announcement, your work based on 116 | the Program is not required to print an announcement.) 117 | 118 | These requirements apply to the modified work as a whole. If 119 | identifiable sections of that work are not derived from the Program, 120 | and can be reasonably considered independent and separate works in 121 | themselves, then this License, and its terms, do not apply to those 122 | sections when you distribute them as separate works. But when you 123 | distribute the same sections as part of a whole which is a work based 124 | on the Program, the distribution of the whole must be on the terms of 125 | this License, whose permissions for other licensees extend to the 126 | entire whole, and thus to each and every part regardless of who wrote it. 127 | 128 | Thus, it is not the intent of this section to claim rights or contest 129 | your rights to work written entirely by you; rather, the intent is to 130 | exercise the right to control the distribution of derivative or 131 | collective works based on the Program. 132 | 133 | In addition, mere aggregation of another work not based on the Program 134 | with the Program (or with a work based on the Program) on a volume of 135 | a storage or distribution medium does not bring the other work under 136 | the scope of this License. 137 | 138 | 3. You may copy and distribute the Program (or a work based on it, 139 | under Section 2) in object code or executable form under the terms of 140 | Sections 1 and 2 above provided that you also do one of the following: 141 | 142 | a) Accompany it with the complete corresponding machine-readable 143 | source code, which must be distributed under the terms of Sections 144 | 1 and 2 above on a medium customarily used for software interchange; or, 145 | 146 | b) Accompany it with a written offer, valid for at least three 147 | years, to give any third party, for a charge no more than your 148 | cost of physically performing source distribution, a complete 149 | machine-readable copy of the corresponding source code, to be 150 | distributed under the terms of Sections 1 and 2 above on a medium 151 | customarily used for software interchange; or, 152 | 153 | c) Accompany it with the information you received as to the offer 154 | to distribute corresponding source code. (This alternative is 155 | allowed only for noncommercial distribution and only if you 156 | received the program in object code or executable form with such 157 | an offer, in accord with Subsection b above.) 158 | 159 | The source code for a work means the preferred form of the work for 160 | making modifications to it. For an executable work, complete source 161 | code means all the source code for all modules it contains, plus any 162 | associated interface definition files, plus the scripts used to 163 | control compilation and installation of the executable. However, as a 164 | special exception, the source code distributed need not include 165 | anything that is normally distributed (in either source or binary 166 | form) with the major components (compiler, kernel, and so on) of the 167 | operating system on which the executable runs, unless that component 168 | itself accompanies the executable. 169 | 170 | If distribution of executable or object code is made by offering 171 | access to copy from a designated place, then offering equivalent 172 | access to copy the source code from the same place counts as 173 | distribution of the source code, even though third parties are not 174 | compelled to copy the source along with the object code. 175 | 176 | 4. You may not copy, modify, sublicense, or distribute the Program 177 | except as expressly provided under this License. Any attempt 178 | otherwise to copy, modify, sublicense or distribute the Program is 179 | void, and will automatically terminate your rights under this License. 180 | However, parties who have received copies, or rights, from you under 181 | this License will not have their licenses terminated so long as such 182 | parties remain in full compliance. 183 | 184 | 5. You are not required to accept this License, since you have not 185 | signed it. However, nothing else grants you permission to modify or 186 | distribute the Program or its derivative works. These actions are 187 | prohibited by law if you do not accept this License. Therefore, by 188 | modifying or distributing the Program (or any work based on the 189 | Program), you indicate your acceptance of this License to do so, and 190 | all its terms and conditions for copying, distributing or modifying 191 | the Program or works based on it. 192 | 193 | 6. Each time you redistribute the Program (or any work based on the 194 | Program), the recipient automatically receives a license from the 195 | original licensor to copy, distribute or modify the Program subject to 196 | these terms and conditions. You may not impose any further 197 | restrictions on the recipients' exercise of the rights granted herein. 198 | You are not responsible for enforcing compliance by third parties to 199 | this License. 200 | 201 | 7. If, as a consequence of a court judgment or allegation of patent 202 | infringement or for any other reason (not limited to patent issues), 203 | conditions are imposed on you (whether by court order, agreement or 204 | otherwise) that contradict the conditions of this License, they do not 205 | excuse you from the conditions of this License. If you cannot 206 | distribute so as to satisfy simultaneously your obligations under this 207 | License and any other pertinent obligations, then as a consequence you 208 | may not distribute the Program at all. For example, if a patent 209 | license would not permit royalty-free redistribution of the Program by 210 | all those who receive copies directly or indirectly through you, then 211 | the only way you could satisfy both it and this License would be to 212 | refrain entirely from distribution of the Program. 213 | 214 | If any portion of this section is held invalid or unenforceable under 215 | any particular circumstance, the balance of the section is intended to 216 | apply and the section as a whole is intended to apply in other 217 | circumstances. 218 | 219 | It is not the purpose of this section to induce you to infringe any 220 | patents or other property right claims or to contest validity of any 221 | such claims; this section has the sole purpose of protecting the 222 | integrity of the free software distribution system, which is 223 | implemented by public license practices. Many people have made 224 | generous contributions to the wide range of software distributed 225 | through that system in reliance on consistent application of that 226 | system; it is up to the author/donor to decide if he or she is willing 227 | to distribute software through any other system and a licensee cannot 228 | impose that choice. 229 | 230 | This section is intended to make thoroughly clear what is believed to 231 | be a consequence of the rest of this License. 232 | 233 | 8. If the distribution and/or use of the Program is restricted in 234 | certain countries either by patents or by copyrighted interfaces, the 235 | original copyright holder who places the Program under this License 236 | may add an explicit geographical distribution limitation excluding 237 | those countries, so that distribution is permitted only in or among 238 | countries not thus excluded. In such case, this License incorporates 239 | the limitation as if written in the body of this License. 240 | 241 | 9. The Free Software Foundation may publish revised and/or new versions 242 | of the General Public License from time to time. Such new versions will 243 | be similar in spirit to the present version, but may differ in detail to 244 | address new problems or concerns. 245 | 246 | Each version is given a distinguishing version number. If the Program 247 | specifies a version number of this License which applies to it and "any 248 | later version", you have the option of following the terms and conditions 249 | either of that version or of any later version published by the Free 250 | Software Foundation. If the Program does not specify a version number of 251 | this License, you may choose any version ever published by the Free Software 252 | Foundation. 253 | 254 | 10. If you wish to incorporate parts of the Program into other free 255 | programs whose distribution conditions are different, write to the author 256 | to ask for permission. For software which is copyrighted by the Free 257 | Software Foundation, write to the Free Software Foundation; we sometimes 258 | make exceptions for this. Our decision will be guided by the two goals 259 | of preserving the free status of all derivatives of our free software and 260 | of promoting the sharing and reuse of software generally. 261 | 262 | NO WARRANTY 263 | 264 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 265 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 266 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 267 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 268 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 269 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 270 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 271 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 272 | REPAIR OR CORRECTION. 273 | 274 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 275 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 276 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 277 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 278 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 279 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 280 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 281 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 282 | POSSIBILITY OF SUCH DAMAGES. 283 | 284 | END OF TERMS AND CONDITIONS 285 | 286 | How to Apply These Terms to Your New Programs 287 | 288 | If you develop a new program, and you want it to be of the greatest 289 | possible use to the public, the best way to achieve this is to make it 290 | free software which everyone can redistribute and change under these terms. 291 | 292 | To do so, attach the following notices to the program. It is safest 293 | to attach them to the start of each source file to most effectively 294 | convey the exclusion of warranty; and each file should have at least 295 | the "copyright" line and a pointer to where the full notice is found. 296 | 297 | {description} 298 | Copyright (C) {year} {fullname} 299 | 300 | This program is free software; you can redistribute it and/or modify 301 | it under the terms of the GNU General Public License as published by 302 | the Free Software Foundation; either version 2 of the License, or 303 | (at your option) any later version. 304 | 305 | This program is distributed in the hope that it will be useful, 306 | but WITHOUT ANY WARRANTY; without even the implied warranty of 307 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 308 | GNU General Public License for more details. 309 | 310 | You should have received a copy of the GNU General Public License along 311 | with this program; if not, write to the Free Software Foundation, Inc., 312 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 313 | 314 | Also add information on how to contact you by electronic and paper mail. 315 | 316 | If the program is interactive, make it output a short notice like this 317 | when it starts in an interactive mode: 318 | 319 | Gnomovision version 69, Copyright (C) year name of author 320 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 321 | This is free software, and you are welcome to redistribute it 322 | under certain conditions; type `show c' for details. 323 | 324 | The hypothetical commands `show w' and `show c' should show the appropriate 325 | parts of the General Public License. Of course, the commands you use may 326 | be called something other than `show w' and `show c'; they could even be 327 | mouse-clicks or menu items--whatever suits your program. 328 | 329 | You should also get your employer (if you work as a programmer) or your 330 | school, if any, to sign a "copyright disclaimer" for the program, if 331 | necessary. Here is a sample; alter the names: 332 | 333 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 334 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 335 | 336 | {signature of Ty Coon}, 1 April 1989 337 | Ty Coon, President of Vice 338 | 339 | This General Public License does not permit incorporating your program into 340 | proprietary programs. If your program is a subroutine library, you may 341 | consider it more useful to permit linking proprietary applications with the 342 | library. If this is what you want to do, use the GNU Lesser General 343 | Public License instead of this License. 344 | -------------------------------------------------------------------------------- /slideware/overview/media/kernel.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 33 | 34 | 41 | 46 | 47 | 54 | 59 | 60 | 67 | 72 | 73 | 80 | 86 | 87 | 94 | 100 | 101 | 108 | 114 | 115 | 122 | 128 | 129 | 136 | 142 | 143 | 150 | 156 | 157 | 164 | 170 | 171 | 178 | 184 | 185 | 192 | 198 | 199 | 200 | 219 | 221 | 222 | 224 | image/svg+xml 225 | 227 | 228 | 229 | 230 | 231 | 235 | 265 | 273 | 281 | 289 | 297 | 305 | 310 | 315 | 320 | 325 | 330 | 351 | test 377 | 398 | user space process hardware kernel glibc/bionic/.. alsalib/mesa/.. firmware 472 | 477 | 482 | 487 | 488 | 489 | -------------------------------------------------------------------------------- /slideware/interrupts/media/interrupts.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 27 | 32 | 33 | 40 | 45 | 46 | 53 | 59 | 60 | 67 | 73 | 74 | 81 | 87 | 88 | 95 | 101 | 102 | 109 | 115 | 116 | 117 | 137 | 139 | 140 | 142 | image/svg+xml 143 | 145 | 146 | 147 | 148 | 149 | 153 | 160 | 167 | 174 | 179 | 186 | InterrupthandlerX 208 | 215 | ThreadA 232 | 237 | 243 | 250 | 255 | 260 | InterrupthandlerY 282 | 289 | Soft IRQ[From X] 306 | 311 | 318 | ThreadQueued work[From Y] 340 | 347 | ThreadA 364 | 369 | 374 | 379 | 386 | Interrupts off 401 | Kernel space 414 | User space 428 | Time -----> 449 | [Int X] 461 | [Int Y] 473 | 474 | 475 | --------------------------------------------------------------------------------