Kernel Event-Timers - PowerPoint PPT Presentation

About This Presentation
Title:

Kernel Event-Timers

Description:

vec. index. The tvecs[ ]' array. tvec1. tvec2. tvec3. tvec4. tvec5 ... vec[ 64 ] index. Where is an event-timer put? Each event-timer has an expires' field ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 17
Provided by: professora5
Learn more at: https://www.cs.usfca.edu
Category:
Tags: event | kernel | timers | vec

less

Transcript and Presenter's Notes

Title: Kernel Event-Timers


1
Kernel Event-Timers
  • Our first look at the Linux kernels 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
OGorman
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 tasks 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.

next
prev
expires
data
function
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 tasks task_struct
  • Our timerinfo.c module creates a /proc file
    that displays those timer-related fields
  • Our trytimer.cpp demo illustrates this

8
The kernels 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 kernels event-timers
  • Linux employs a clever mechanism for organizing
    all of its active event-timers

9
Doubly-Linked Lists
next
prev
A single-element list
next
next
next
next
prev
prev
prev
prev
A multi-element list
10
timer-list vectors
vec
index
11
The tvecs array
tvecs
tvec1
vec 256
index
tvec2
vec 64
index
tvec3
vec 64
index
tvec4
vec 64
index
tvec5
vec 64
index
12
Where is an event-timer put?
  • Each event-timer has an expires field
  • expires holds a future value for jiffies
  • Its a 32-bit unsigned long integer
  • These bits are subdivided 3266668
  • 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 kernels TO DO list

13
The five expires intervals
  • Compute when expires jiffies
  • Use tvec1 whengtgt0 0 ? when lt 28
  • Use tvec2 whengtgt8 28 ? when lt 214
  • Use tvec3 whengtgt14 214 ? when lt 220
  • Use tvec4 whengtgt20 220 ? when lt 226
  • Use tvec5 whengtgt26 226 ? when lt 232

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 vectors 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
Write a Comment
User Comments (0)
About PowerShow.com