Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kernel Event-Timers Our first look at the Linux kernel’s mechanism for managing its dynamic timers.

Similar presentations


Presentation on theme: "Kernel Event-Timers Our first look at the Linux kernel’s mechanism for managing its dynamic timers."— Presentation transcript:

1 Kernel Event-Timers Our first look at the Linux kernel’s mechanism for managing its dynamic timers

2 The timer interrupt “There is a sense in which the timer interrupt drives the entire Operating System” -- John O’Gorman

3 The ‘task_struct’ structure The OS kernel creates a Task Control Block for each task which currently exists In Linux this TCB has type ‘task_struct’ There are numerous fields in a task_struct We wrote a module which creates a ‘/proc’ file (named ‘tcbinfo’) to let us see a TCB We wrote a demo-program (dumptcb,cpp) which displays a task’s ‘task_struct’ in hex format, by reading the ‘/proc/tcbinfo’ file

4 Timer-related fields There are several fields in the ‘task_struct’ which pertain to time-keeping mechanisms –‘it_real_value’ and ‘it_real_incr’ –‘it_prof_value’ and ‘it_prof_incr’ –‘it_virt_value’ and ‘it_virt_incr’ –‘real_timer’ The ‘real_timer’ field is actually a structure of type ‘struct timer_list’ (an ‘event timer’)

5 ‘struct timer_list’ The ‘real_timer’ field in the ‘task_struct’ is an element of type ‘struct timer_list’. expires data function next prev

6 Demo: ‘realtimers.c’ We wrote a kernel module which creates a pseudo-file (named ‘/proc/realtimers’) that shows a list of all current tasks that have an active real-time event-timer You can compile this module (using our ‘Makefile’ script) with: $ make realtimers.o Install it with: $ /sbin/insmod realtimers.o Then use it with: $ cat /proc/realtimers

7 The ‘setitimer()’ function In our lab-exercise on Friday we studied the ‘setitimer()’ library-function, used by applications to implement ‘interval timers’ Now we can see how ‘setitimer()’ affects timer-related fields in a task’s ‘task_struct’ Our ‘timerinfo.c’ module creates a ‘/proc’ file that displays those timer-related fields Our ‘trytimer.cpp’ demo illustrates this

8 The kernel’s ‘TO DO’ list A multitasking operating system has many timer-related events to keep track of, so it could have lots of work to do each time a timer-interrupt occurs So there needs to be a very efficient way to manage all of the kernel’s event-timers Linux employs a clever mechanism for organizing all of its active event-timers

9 Doubly-Linked Lists next prev next prev next prev next prev next prev A single-element list A multi-element list

10 timer-list vectors vecindex

11 The ‘tvecs[ ]’ array tvec1 tvec2 tvec3 tvec4 tvec5 tvecs vec[ 256 ]index vec[ 64 ]index vec[ 64 ]index vec[ 64 ]index vec[ 64 ]index

12 Where is an event-timer put? Each event-timer has an ‘expires’ field ‘expires’ holds a future value for ‘jiffies’ It’s a 32-bit unsigned long integer These bits are subdivided: 32=6+6+6+6+8 The event-timer is assigned to one of the five timer-list vectors, based on which one of five numeric intervals ‘expires’ falls into This organizes the kernel’s ‘TO DO’ list

13 The five ‘expires’ intervals Compute: when = expires – jiffies; Use tvec1[ when>>0 ]: 0  when < 2 8 Use tvec2[ when>>8 ]: 2 8  when < 2 14 Use tvec3[ when>>14]: 2 14  when < 2 20 Use tvec4[ when>>20]: 2 20  when < 2 26 Use tvec5[ when>>26]: 2 26  when < 2 32

14 The work to be done When a timer-interrupt occurs, the value of ‘jiffies’ gets incremented, so it is possible that some ‘event-timers’ may have expired The kernel checks the ‘index’ field of the ‘root’ timer-list vector to quickly find the list of event- timers which might have expired It processes the event-timers in that list. then increments the root vector’s ‘index’ (modulo 256) If ( index == 0 ) the tvecs array is ‘cascaded’

15 In-class exercises Try modifying the ‘trytimer.cpp’ program so that it calls ‘setitimer()’ with ITIMER_PROF instead of ITIMER_REAL. What do you observe about the ‘task_struct’ fields? Try modifying the ‘trytimer.cpp’ program so it calls ‘setitimer()’ with ITIMER_VIRTUAL instead of ITIMER_REAL. What do you observe about the ‘task_struct’ fields?

16 Exercises (continued) Try installing your own signal-handlers for the SIGALRM, the SIGVTALRM, and the SIGPROF signals, to see the effects of using ‘setitimer()’ with the three different types of interval timers. Use our ‘realtimers.c’ module to look at the list of all current tasks that have an active ‘event-timer’


Download ppt "Kernel Event-Timers Our first look at the Linux kernel’s mechanism for managing its dynamic timers."

Similar presentations


Ads by Google