Upload
sheila-harris
View
26
Download
1
Embed Size (px)
DESCRIPTION
CSC 660: Advanced OS. Kernel Modules. What are Kernel Modules?. Parcels of code that can be dynamically inserted or removed from kernel at run time. Why use Kernel Modules?. Ease of maintenance Compile kernel once. Build, add, and remove modules afterwards. Ease of distribution - PowerPoint PPT Presentation
Citation preview
CSC 660: Advanced Operating Systems Slide #1
CSC 660: Advanced OS
Kernel Modules
CSC 660: Advanced Operating Systems Slide #2
What are Kernel Modules?
Parcels of code that can be dynamically inserted or removed from kernel at run time.
CSC 660: Advanced Operating Systems Slide #3
Why use Kernel Modules?
Ease of maintenanceCompile kernel once.
Build, add, and remove modules afterwards.
Ease of distributionCompile single kernel for all machines.
Include drivers / options as modules.
Vendors can distribute drivers as modules.
CSC 660: Advanced Operating Systems Slide #4
What modules are loaded?> lsmod | headModule Size Used byvmnet 31900 12vmmon 103584 0proc_intf 4100 0freq_table 4100 0cpufreq_userspace 4572 0cpufreq_ondemand 6172 0cpufreq_powersave 1920 0video 16260 0sony_acpi 6280 0> head -3 /proc/modulesvmnet 31900 12 - Live 0xf8c3a000vmmon 103584 0 - Live 0xf8c85000proc_intf 4100 0 - Live 0xf8c2c000
CSC 660: Advanced Operating Systems Slide #5
Loading Kernel Modules
1. modprobe name
2. Lookup nameResolve aliases using /etc/modprobe.d/*
3. Check dependencies/lib/modules/version/modules.dep
Created by depmod –a
4. Load prerequisite modules with insmod
5. Load named module.
CSC 660: Advanced Operating Systems Slide #6
Module Licensing
Specified with MOD_LICENSE() macro.
If an unlicensed module loaded, kernel tainted:hellomod: module license ‘unspecified’ taints kernel
Options found in linux/module.hGPL
Dual BSD/GPL
Proprietary
CSC 660: Advanced Operating Systems Slide #7
Why Module Licensing?
From linux/module.h:1. So modinfo can tell users if kernel is free.
2. So community can ignore bug reports including proprietary modules.
3. So vendors can do likewise based on their own policies.
CSC 660: Advanced Operating Systems Slide #8
Init and Cleanup
Kernel modules must have two functions.
init_moduleAlternatively declare with __init attribute.
Ex: register interrupt handler, add system call
cleanup_moduleAlternatively declare with __exit attribute
Undoes whatever init_module did so module can be unloaded safely.
CSC 660: Advanced Operating Systems Slide #9
Includes
All modules need<linux/module.h>
For printk need<linux/kernel.h>
Others depending on function.
CSC 660: Advanced Operating Systems Slide #10
References1. Daniel P. Bovet and Marco Cesati, Understanding the
Linux Kernel, 3rd edition, O’Reilly, 2005.2. Robert Love, Linux Kernel Development, 2nd edition,
Prentice-Hall, 2005.3. Kwan Lowe, Kernel Rebuild Guide,
http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html, 2004.
4. Claudia Rodriguez et al, The Linux Kernel Primer, Prentice-Hall, 2005.
5. Peter Salzman et. al., Linux Kernel Module Programming Guide, version 2.6.1, 2005.
6. Andrew S. Tanenbaum, Modern Operating Systems, 2nd edition, Prentice-Hall, 2001.