Linux kernel timers - PowerPoint PPT Presentation

About This Presentation
Title:

Linux kernel timers

Description:

Linux kernel timers. How can a module cause a function to be invoked at some ... (optional) 8254 Watchdog Timer (NMI) (optional) Network Interface Card (IRQ varies) ... – PowerPoint PPT presentation

Number of Views:503
Avg rating:3.0/5.0
Slides: 11
Provided by: ProfessorA2
Learn more at: https://www.cs.usfca.edu
Category:

less

Transcript and Presenter's Notes

Title: Linux kernel timers


1
Linux kernel timers
  • How can a module cause a function to be invoked
    at some future moment in time?

2
Hardware timer-counters
  • IA32 systems several hardware timers
  • External devices, or internal to processor
  • Examples
  • 8254 Programmable Interval Timer (IRQ0)
  • MC146818 Real Time Clock w/CMOS (IRQ8)
  • Pentiums 64-bit Time Stamp Counter register
  • Local APICs programmable Counter register
  • (optional) 8254 Watchdog Timer (NMI)
  • (optional) Network Interface Card (IRQ varies)

3
Linux Software Timers
  • Easy for device-driver programmers to use
  • Used mainly for detecting device lockups
  • But could also be used for other purposes
  • The driver-writer merely needs to
  • 1) define a customized timeout-function
  • 2) allocate and initialize a kernel-structure
  • 3) call standard routines for timer-control

4
Software Timers Data-Structure
struct timer_list
struct list_head list
unsigned long expires
unsigned long data
void (function)( unsigned long )
Use the init_timer() routine to initialize the
list field
5
Defining your timeout action
  • void my_action( unsigned long dataptr )
  • / perform your desired actions / / then
    reschedule timer expiration /
  • next_timeout jiffies 5HZ
  • mod_timer( my_timer, next_timeout )

6
Assigning structures attributes
  • struct timer_list my_timer // declared
    global
  • int init_module( void )
  • init_timer( my_timer ) // for list setup
  • my_timer.data (unsigned long)my_data
  • my_timer.function my_action
  • my_timer.expires jiffies 5 HZ
  • add_timer( my_timer )
  • return SUCCESS

7
Removing your timer safely
  • void cleanup_module( void )
  • int
  • status del_timer_sync( my_timer )
  • // 1 means my_timer was queued
  • // 0 means my_timer wasnt queued

8
Kernels dynamic-timer handling
  • Need to deal efficiently with many timers
  • One big linked list would NOT be efficient
  • Linux adopts a clever partitioning structure
  • Uses special structures (called tvecs)
  • Timers partitioned by their expiration-times
  • Result reduces amount of list-processing

9
Groups of timer lists
Array of tvec structures
(lt 0xFF ) ( lt 0x3FFF ) ( lt 0xFFFFF ) (
lt 0x3FFFFFF ) ( lt 0xFFFFFFFF )
10
In-Class Exercise
  • Modify the mytimer.c demo (on website)
  • Change expiration-frequency (to 5 secs)
  • Print timers messages on users console
  • (See our announce.c demo for how-to)
Write a Comment
User Comments (0)
About PowerShow.com