Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... ·...
Transcript of Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... ·...
![Page 1: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/1.jpg)
Week 6
Intro to Kernel Modules,
Project 2
1
Sarah Diesburg
Florida State University
![Page 2: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/2.jpg)
Kernel Logistics
� Where should I put the kernel source?
� /usr/src/
� Creates /usr/src/linux-2.6.32/
� Where do I issue kernel building commands
(e.g. ‘make oldconfig’, ‘make menuconfig’,
‘make’, …)?
� Inside /usr/src/linux-2.6.32/
2
![Page 3: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/3.jpg)
Kernel Logistics
� Where is the kernel image installed?
� Inside /boot/
� Starts with vmlinuz…
� Where does the initramfs image go?
� Inside /boot/
� Where is the grub file?
� /boot/grub/menu.lst
3
![Page 4: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/4.jpg)
Kernel Logistics
� Where should I develop my new kernel
modules?
� Inside /usr/src/linux-2.6.32/<module_name>/
4
![Page 5: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/5.jpg)
Kernel Modules
Or “drivers”, if you prefer…
5
![Page 6: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/6.jpg)
Kernel Module
� A kernel module is a portion of kernel
functionality that can be dynamically loaded
into the operating system at run-time
� Example� Example
� USB drivers
� File system drivers
� Disk drivers
� Cryptographic libraries
6
![Page 7: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/7.jpg)
Why not just compile everything
into the kernel?� Each machine only needs a certain number
of drivers
� For example, should not have to load every single motherboard driver
� Load only the modules you need
� Smaller system footprint
� Dynamically load modules for new devices
� Camera, new printer, etc.
7
![Page 8: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/8.jpg)
Creating a Kernel Module
� Hello world example
8
![Page 9: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/9.jpg)
Sample Kernel Module: hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void)
{
printk(KERN_ALERT “Hello, world!\n”);
return 0;return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT “Goodbye, sleepy world.\n”);
}
module_init(hello_init);
module_exit(hello_exit);
9
![Page 10: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/10.jpg)
Sample Kernel Module: hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void)
{
printk(KERN_ALERT “Hello, world!\n”);
return 0;
Module headers
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT “Goodbye, sleepy world.\n”);
}
module_init(hello_init);
module_exit(hello_exit);
10
![Page 11: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/11.jpg)
Sample Kernel Module: hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void)
{
printk(KERN_ALERT “Hello, world!\n”);
return 0;
License
declaration
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT “Goodbye, sleepy world.\n”);
}
module_init(hello_init);
module_exit(hello_exit);
11
![Page 12: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/12.jpg)
Sample Kernel Module: hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void)
{
printk(KERN_ALERT “Hello, world!\n”);
return 0;
Initialization
function, runs
when module
loaded
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT “Goodbye, sleepy world.\n”);
}
module_init(hello_init);
module_exit(hello_exit);
12
Tells kernel which
function to run on
load
![Page 13: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/13.jpg)
Sample Kernel Module: hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE(“Dual BSD/GPL”);
static int hello_init(void)
{
printk(KERN_ALERT “Hello, world!\n”);
return 0;return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT “Goodbye, sleepy world.\n”);
}
module_init(hello_init);
module_exit(hello_exit);
13
Exit function, runs
when module exits
Tells kernel which
function to run on
exit
![Page 14: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/14.jpg)
Sample Kernel Module: Makefile
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= \
/lib/modules/`uname -r`/build//lib/modules/`uname -r`/build/
PWD := `pwd`
default:
$(MAKE) -C $(KERNELDIR) \
M=$(PWD) modules
endif
clean:
rm -f *.ko *.o Module* *mod*
14
![Page 15: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/15.jpg)
/usr/src/hello$> make
� Creates hello.ko – This is the finished kernel
module!
Compile the Kernel Module
module!
15
![Page 16: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/16.jpg)
Inserting and Removing the Module
� insmod – insert a module
/usr/src/hello$> sudo insmod hello.ko
� rmmod – remove a module
/usr/src/hello$> sudo rmmod hello.ko
16
![Page 17: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/17.jpg)
Listing Modules
� lsmod – lists all running modules
/usr/src/hello$>lsmod
17
![Page 18: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/18.jpg)
Where is it printing?
� Look inside /var/log/syslog
� Hint – to watch syslog in realtime, issue the
following command in a second terminal:
$> sudo tail –f /var/log/syslog
� Demo…
18
![Page 19: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/19.jpg)
Kernel Module vs User Application
� All kernel modules are event-driven� Register functions
� Wait for requests and service them
� Server/client model
� No standard C library� No standard C library� Why not?
� No floating point support
� Segmentation fault could freeze/crash your system� Kernel ‘oops’!
19
![Page 20: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/20.jpg)
Kernel Functions
� printk() instead of printf()
� kmalloc() instead of malloc()
� kfree() instead of free()
� Where can I find definitions of these kernel
functions?
20
![Page 21: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/21.jpg)
Kernel manpages
� Section 9 of manpages
� Must install manually for our development
kernel
$> wget http://ftp.us.debian.org/debian/pool/main/l/linux-
2.6/linux-manual-2.6.32_2.6.32-22_all.deb
$> sudo dpkg –i linux-manual-2.6.32_2.6.32-22_all.deb
21
![Page 22: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/22.jpg)
Kernel Headers
� #include <linux/init.h> /* module stuff */
� #include <linux/module.h> /* module stuff */
� #include <asm/semaphore.h> /* locks */
#include <linux/list.h> /* linked lists */� #include <linux/list.h> /* linked lists */
� #include <linux/string.h> /* string functions! */
� Look inside linux-2.6.32/include/ for more…
� Google is also your friend
22
![Page 23: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/23.jpg)
How can I explore the kernel?
� Use lxr (“Linux Cross Referencer”):
� http://lxr.linux.no/
� Select your kernel version and enter search terms
� Use grep on your kernel source
$> grep –Rn xtime /usr/src/linux-
2.6.32
� R = recursive, n = display line number
23
![Page 24: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/24.jpg)
Project 2: /Proc Kernel
Module and Elevator
24
![Page 25: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/25.jpg)
procfs Kernel Module
� procfs “hello world” example
� Creates a read-only procfs entry
� Steps
� Create entry in module_init function� Create entry in module_init function
� Register reading function with procfs_read
� Delete entry in module_cleanup function
� Reference
� Linux Kernel Module Programming Guide: Proc FS
25
![Page 26: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/26.jpg)
Procfs: Headers and Global Data
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
MODULE_LICENSE(“GPL”);
#define ENTRY_NAME “helloworld”#define ENTRY_NAME “helloworld”
#define PERMS 0644
#define PARENT NULL
struct proc_dir_entry *proc_entry;
int procfile_read(char *buf, char **buf_location, off_t
offset, int buffer_length, int *eof, void *data);
26
![Page 27: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/27.jpg)
Procfs: Creation
int hello_proc_init(void)
{
proc_entry =
create_proc_entry(ENTRY_NAME,
PERMS,PARENT);
/* check proc_entry != NULL */
proc_entry->read_proc = procfile_read;proc_entry->read_proc = procfile_read;
proc_entry->mode = S_IFREG | S_IRUGO;
proc_entry->uid = 0;
proc_entry->gid = 0;
proc_entry->size = 11;
printk(“/proc/%s created\n”, ENTRY_NAME);
return 0;
}
27
![Page 28: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/28.jpg)
Procfs: Reading
int procfile_read(char *buf, char **buf_location, off_t offset, int buffer_length, int *eof, void *data)
{
int ret;
printk(“/proc/%s read called.\n”, ENTRY_NAME);
/* Setting eof. We exhaust all data in one shot */
*eof = 1;
ret = sprintf(buf, “Hello World!\n”);
return ret;
}
28
![Page 29: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/29.jpg)
Procfs: Deletion
void hello_proc_exit(void)
{
remove_proc_entry(ENTRY_NAME, NULL);
printk(“Removing /proc/%s.\n”, ENTRY_NAME);
}
29
![Page 30: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/30.jpg)
Procfs: Registration
module_init(hello_proc_init);
module_exit(hello_proc_exit);
30
![Page 31: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/31.jpg)
Testing Procfs
$> sudo insmod hello_proc.ko
$> sudo tail /var/log/syslog
$> cat /proc/helloworld
$> sudo rmmod hello_proc$> sudo rmmod hello_proc
31
![Page 32: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/32.jpg)
Part 2: Kernel Time
� Implement a procfs entry to display the value
of xtime
� Hint: You may not be able to directly read xtime from your module, but maybe something else can…
32
![Page 33: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/33.jpg)
Part 3: Elevator Scheduling
33
![Page 34: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/34.jpg)
Part 3: Elevator Scheduling
� Implement a kernel module that simulates an
elevator system
� Implement system calls to interact with your
elevatorelevator
� Implement a procfs entry to display
debugging information
� Test using a set of user-space programs to
exercise your system
34
![Page 35: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/35.jpg)
Why Elevator Scheduling?
� Classic producer/consumer analogy
� Similar to disk elevators
� File system produces read/write requests
� Disk consumes requests, optimized for disk head � Disk consumes requests, optimized for disk head position, rotational delays, etc.
35
![Page 36: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/36.jpg)
Your Elevator
� One elevator
� Five floors
� Four types of people
� Adults� Adults
� Children
� Delivery people
� Maintenance people
� The elevator cannot exceed its maximum
weight load
36
![Page 37: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/37.jpg)
Your Elevator
� People will line up at each floor in a first-in,
first-out (FIFO) order
� Each person has a starting floor and a
destination floordestination floor
� The elevator must pause for a period of time
to collect people and move between floors
� Once the elevator reaches a passenger’s
destination floor, that passenger gets out and
ceases to exist
37
![Page 38: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/38.jpg)
Passengers will line up (FIFO)
38
![Page 39: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/39.jpg)
Each passenger has a destination floor
in mind…
39
I want
to go to
floor 3
![Page 40: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/40.jpg)
The elevator must be started to service
passengers…
40
Start!
![Page 41: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/41.jpg)
The elevator must be started to service
passengers…
41
Elevator
starts on the
first floor
![Page 42: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/42.jpg)
Passengers enter in FIFO order
42
Make sure
passengers don’t
exceed weight
limit!
![Page 43: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/43.jpg)
Passengers enter in FIFO order
43
More passengers
can be queuing
up!
![Page 44: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/44.jpg)
Elevator can move to any floor
44
Going to floor 3!
Red and black
has destination
floor 3, blue has
destination floor 2
![Page 45: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/45.jpg)
Elevator can move to any floor
45
Must take certain
amount of time
between floors…
![Page 46: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/46.jpg)
Elevator can move to any floor
46
Must take certain
amount of time
between floors…
![Page 47: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/47.jpg)
Elevator can move to any floor
47
Must take certain
amount of time
between floors…
![Page 48: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/48.jpg)
Elevator can move to any floor
48
Must take certain
amount of time
between floors…
![Page 49: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/49.jpg)
Elevator can move to any floor
49
Must take certain
amount of time
between floors…
![Page 50: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/50.jpg)
Passengers disappear when they exit…
50
![Page 51: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/51.jpg)
Elevator stop in progress…
51
Must finish
delivering
passengers
before stopping…
Stop in
Progress
![Page 52: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/52.jpg)
Elevator stop in progress…
52
Must finish
delivering
passengers
before stopping…
Stop in
Progress
![Page 53: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/53.jpg)
Elevator stop in progress…
53
Must finish
delivering
passengers
before stopping…
Stop in
Progress
![Page 54: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/54.jpg)
Elevator stop
54
Full stop
![Page 55: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/55.jpg)
Controlling the Elevator
Implement the following system calls
� int start_elevator(void)
� int issue_request(int passenger_type, int
start_floor, int destination_floor)
� int stop_elevator(void)
55
![Page 56: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/56.jpg)
Elevator Scheduling Algorithms
� A scheduling algorithm considers the state of
the consumers and all requests and tries to
optimize some metric
� Throughput: Maximize total requests, minimize � Throughput: Maximize total requests, minimize processing total time.
� Priorities: Requests now have deadlines. Maximize number of requests meeting deadlines.
� Burst throughput: Maximize peak requests that can be handled.
� Energy: Minimize consumer action
56
![Page 57: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/57.jpg)
Elevator Test Applications
� consumer.c
� Runs in infinite loop
� Issues K passenger requests once per second
� producer.c� producer.c
� Takes an argument telling the elevator to start or stop
57
![Page 58: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/58.jpg)
Kernel Time Constraints
#include <linux/delay.h>
void ssleep(unsigned int seconds);
� A call to ssleep will have the program cease
to the task scheduler for seconds number of
seconds
58
![Page 59: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/59.jpg)
Additional Design Considerations
� How to move elevator?
� How to protect the floor FIFO queues?
� What scheduling algorithm to use?
59
![Page 60: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/60.jpg)
Next Time
� Kernel debugging techniques
� How to insert system calls
� Some elevator scheduling algorithms
60
![Page 61: Week 6 Intro to Kernel Modules, Project 2diesburg/courses/cop4610_fall10/week06/... · 2012-08-04 · Intro to Kernel Modules, Project 2 1 Sarah Diesburg Florida State University.](https://reader034.fdocuments.us/reader034/viewer/2022042812/5fb13966736d7c0c5f02375c/html5/thumbnails/61.jpg)
What you should do?
� Finish part 1 (5 system calls)
� Finish part 2 (/proc module)
� Try sample kernel module and proc module
Make skeleton part 3 module� Make skeleton part 3 module
� Make elevator and floor queue data
structures
61