CS 6560 Operating System Design Kernel Loadable Modules

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Linux Device Drivers & Project3 preview CSC345. Project 3 Preview Write a device driver for a pseudo stack device Idea from
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Drivers and the kernel1-1 Drivers and the kernel UNIX system has three layers: m The hardware m The operating system kernel m The user-level programs Kernel.
Computer System Laboratory
Click Router: Hands on Arvind Venkatesan. Acknowledgements Thanks Hema for beautifying the slides!
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
CIS238/DL1 Chapter 15 Rebuilding the Linux Kernel Preparing the Source Code Locating the Source Code Installing the Source Code Read the Documentation.
Building and Running Modules Ted Baker  Andy Wang CIS 4930 / COP 5641.
Homework 6 Sarah Diesburg Operating Systems CS 3430.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
Embedded System Programming Introduction to Device Drivers.
CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.
CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco.
Add a New System Call to Linux. Hw1 Add a New System Call to Linux and Compile Kernel Add a New System Call to Linux by Kernel Module.
Kernel module programming and debugging Advanced Operating Systems.
Tutorial and Demos on Linux Virtual Machine
1 Netfilter in Linux Bing Qi Department of Computer Science and Engineering Auburn university.
Computer Science 210 Computer Organization Modular Decomposition Making a Library Separate Compilation.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
1 Week 6 Intro to Kernel Modules, Project 2 Sarah Diesburg Florida State University.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
Operating System Program 5 I/O System DMA Device Driver.
For OS Experiments. What Do We Need? A Computer &
Kernel Modules Giving your Linux more pop since 1995.
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
1 What is a Kernel The kernel of any operating system is the core of all the system’s software. The only thing more fundamental than the kernel is the.
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Linux Kernel Management. Module 9 – Kernel Administration ♦ Overview The innermost layer of Linux operating system is the kernel, which is a thin layer.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Linux Kernel Programming (LKP). LKP New sub-course New sub-course We will learn together We will learn together Evaluation of this part of course will.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
Kernel Structure and Infrastructure David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Virtual Memory Mohammad H. Mofrad February 23, 2016
Add a New System Call to Linux
OS – Ex 1 Nezer J. Zaidenberg.
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Linux Kernel Module Programming
Computer System Laboratory
Drivers and the kernel UNIX system has three layers: Kernel
Linux Kernel Module Programming
CS-3013 Operating Systems C-term 2008
Chapter 2: The Linux System Part 2
Intro to Kernel Modules and /proc
IS3440 Linux Security Unit 7 Securing the Linux Kernel
chapter 2 - Hello World Model
Kernel Structure and Infrastructure
CS 6560 Operating System Design
Operation System Program 1
Kernel – Device Drivers (part 2)
Lab 4 Kernel Module Operating System Lab.
Linking & Loading CS-502 Operating Systems
Kernel Structure and Infrastructure
Implementation of Embedded OS
Computer System Laboratory
Loadable Kernel Modules
Linking & Loading CS-502 Operating Systems
Presentation transcript:

CS 6560 Operating System Design Kernel Loadable Modules References Textbook, chapter 16 http://tldp.org/LDP/lkmpg/2.6/html/index.html http://www.linux.org/docs/ldp/howto/Module-HOWTO/index.html https://linuxlink.timesys.com/docs/printk

Kernel Modules: Why? System call like functionality. Don’t have to recompile the kernel. Separate modules are separate. Modifying one module doesn’t require another module to recompile. Modules can be inserted and removed dynamically. When added they become part of the kernel with access to the rest of the kernel. When removed, there is no mark left on the kernel (unlike new system calls).

Kernel Module Structure Kernel modules consist of An initialization routine that is called when the module is loaded An exit routine that is called when the module is removed. Functions and variables that can be exported for use by other parts of the kernel, including other modules. Meta data that can be accessed by tools and the kernel.

Starting Example Here is an example of kernel module that has the basic structure. //*----------------------------------------------------------------------*/ /* File: CS6560_LKM.c Example of a loadable kernel module that initializes, exports functions, and exits. */ /* Standard headers for LKMs */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/moduleparam.h> #include "CS6560_LKM.h" int init_CS6560_module(void); void exit_CS6560_module(void); /* Initialize the LKM */ int init_CS6560_module() { printk(KERN_ALERT "CS6560_LKM_one: init_CS6560_module\n"); return 0; }

Starting Example (cont.) /* Exit the LKM */ void exit_CS6560_module() { printk("CS6560_LKM_one: exit_CS6560_module\n"); } /* Example exported function */ int CS6560_LKM_function1(int arg1) printk("CS6560_LKM_one: CS6560_LKM_function1\n"); return 0; EXPORT_SYMBOL(CS6560_LKM_function1); module_init(init_CS6560_module); module_exit(exit_CS6560_module); MODULE_LICENSE("GPL"); MODULE_AUTHOR("CS6560 at CSUEB"); /*----------------------------------------------------------------------*/

Points printw and Kernel loglevels - see man pages for syslogd and klogctl. Also see kernel code for printw.c. Naming and registration of module init and exit functions. Exporting symbols Meta data macros

Development Modes Standalone Integrated Work in separate directory (see pages 282-283) (next slide) Integrated Put module code in source code tree (see textbook, pages 281-282) Pick appropriate directory and place module code there Add line (obj-m += …) to Makefile in that directory (see info make for how to set variables, and the kbuild documentation on configuration.)

Standalone Makefile # Makefile for kernel module development # # CS6560 Fall 2007 ########################## obj-m := CS6560_LKM_one.o obj-m += CS6560_LKM_two.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Loading and Unloading Modules Commands insmod Insert an LKM into the kernel. rmmod Remove an LKM from the kernel. depmod Determine interdependencies between LKMs. kerneld Kerneld daemon program ksyms Display symbols that are exported by the kernel for use by new LKMs. lsmod List currently loaded LKMs. modinfo Display contents of .modinfo section in an LKM object file. modprobe Insert or remove an LKM or set of LKMs intelligently. For example, if you must load A before loading B, modprobe will automatically load A when you tell it to load B.

Examples in Class Modules_two Compile Look at Bring up dmesg # make Look at modinfo CS6560_LKM_one.ko modinfo CS6560_LKM_two.ko Bring up dmesg Use: dmesg | tail or use: cat /proc/kmsg Load CS6560_LKM_one lsmod CS6560_LKM_one.ko /proc/modules /sys/module

Try the second one Load and unload CS6560_LKM_two.ko Look at what happens each time to Messages /proc/modules /sys/module

Now with parameters Initialization on command line Changing variables with /sys/ using cat

Applications of Modules Proc files Device drivers Interrupt Handlers File systems System calls Monitoring and replacing core functionality such as scheduling

Proc Files Example From http://tldp.org/LDP/lkmpg/2.6/html/x710.html