Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco.

Similar presentations


Presentation on theme: "CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco."— Presentation transcript:

1 CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco

2 Instructor Contact Information Office: Harney Science Center – 212 Hours: Mon-Wed 2:30pm-4:00pm Phone: (415) 422-6562 Email: cruse@usfca.educruse@usfca.edu Webpage: nexus.cs.usfca.edu/~cruse/

3 Course Textbooks Alessandro Rubini and Jonathan Corbet, Linux Device Drivers (Second Edition), O’Reilly & Associates, Incorporated (2001) M. Beck et al, Linux Kernel Programming (Third Edition), Addison-Wesley (2002)

4 Linux kernel modules Great mechanism for kernel ‘extensibility’ Neat tool for studying how kernel works Kernel can be modified while it’s running Unnecessary to recompile and then reboot But inherently unsafe: bugs cause system crashes!

5 ‘Extensibility’ Modern OS needs ability to evolve Will need to support new devices Will need to allow ‘bugs’ to be fixed Will need to permit performance gains Otherwise: suffer early obsolescence!

6 Two Extensibility Mechanisms ‘Open Source’ programming ‘Installable’ kernel modules

7 ‘Superuser’ privileges Modifying a running kernel is ‘risky’ Only authorized ‘system administrators’ are allowed to install kernel modules

8 A few ‘/proc’ examples $ cat /proc/version $ cat /proc/cpuinfo $ cat /proc/modules $ cat /proc/iomem $ cat /proc/self/maps

9 Module structure Two ‘module administration’ functions plus Appropriate ‘module service’ functions

10 Required module functions int init_module( void ); // gets called during module installation void cleanup_module( void ); // gets called during module removal

11 How to compile a module gcc –c –O mod.c

12 Using ‘insmod’ and ‘rmmod’ root# /sbin/insmod jiffies.o root# /sbin/rmmod jiffies

13 Using the ‘sudo’ command user$ sudo /sbin/insmod jiffies.o user$ sudo /sbin/rmmod jiffies

14 jiffies unsigned long volatile jiffies; global kernel variable (used by scheduler) Initialized to zero when system reboots Gets incremented when timer interrupts So it counts ‘clock-ticks’ since cpu restart ‘tick-frequency’ is architecture dependent

15 jiffies overflow Won’t overflow for at least 16 months Linux recently modified to ‘fix’ overflow New declaration in ‘linux/sched.h’: unsigned long longjiffies_64; and a new instruction in ‘do_timer()’ (*(u64*)&jiffies_64)++; which compiles to assembly language as add$1, jiffies+0 adc$0, jiffies+4


Download ppt "CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco."

Similar presentations


Ads by Google