Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 02-22-2009, 02:49 AM   #1
Registered: Oct 2008
Posts: 51

Rep: Reputation: 15
Doubts about timers in linux kernel

Hi ,

I am trying to learn timers in linux kernel. I am trying to write a program where I can configure a timer to tick in every 5 seconds and a function should thus exicute in every five seconds. I tried one program with the help of linux/timer.h headerfile but I couldnt get the delay right and my function exicutes only once.That is my timer acts like a single shot timer. How can I make the timer multi slot (not single slot , that is what I am trying to say), Plus How can I calculate the time delay in linux kernel. What is jiffies infact. What is the value of 1 jiffy in seconds . Hoping for help

Jayanth. S
Old 02-22-2009, 12:42 PM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
You want to use setitimer(). See for details.
--- rod.
Old 02-22-2009, 11:44 PM   #3
Registered: Oct 2008
Posts: 51

Original Poster
Rep: Reputation: 15
Thanks for the link...But this timer will only work on user space ....I want implement a timer on the kernel module...Can anyone help me out...Also what is jiffies.
Old 03-02-2009, 04:08 AM   #4
LQ Newbie
Registered: Dec 2008
Posts: 5

Rep: Reputation: 1
kernel timers

Hi.if you have time then go through it...

it'a small module which can toggle the led every 5 seconds..

jiffie --> it'a variable which holds the count of ticks since system boot up...

and go through the linux/timer.h...

int *led_addr ;
struct timer_list my_timer;

static void timer_func(unsigned long func_parameter)

u8 reg_val;
/* SET LED ON */

reg_val = readb(led_addr);
reg_val |= (1<<0);
reg_val = readb(led_addr);
reg_val &= ~(1<<0);

/*making to run timer_func() periodically*/
my_timer.expires = jiffies + 1*HZ;
// = func_parameter;
my_timer.function = timer_func;

int init_led(void)

led_addr = ioremap((CPLD_PHY_BASE+LED_BASE),1);
init_timer(&my_timer); /* Also see setup_timer() */
my_timer.expires = jiffies + 5*HZ; /* n is the timeout in number of seconds */
my_timer.function = timer_func; /* Function to execute after n seconds */
// = func_parameter; /* Parameter to be passed to timer_func */
add_timer(&my_timer); /* Start the timer */
return 0;

void exit_led(void)

1 members found this post helpful.
Old 03-03-2009, 09:43 AM   #5
Registered: Oct 2008
Posts: 51

Original Poster
Rep: Reputation: 15
Thanks sir..u r a master..that cleared up everything nicely...u r a genius....Nice and simple program to understand the functioning of timers...excellent....Thanks again...
Old 01-31-2012, 07:53 PM   #6
LQ Newbie
Registered: Jan 2007
Posts: 10

Rep: Reputation: 0
Thanks bhaskarreddy, you saved me too This is the only example I managed to find about linux/timers.h


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timers of ARM in Kernel? raedbenz Linux - Embedded & Single-board computer 2 06-30-2008 05:15 AM
LXer: Doubts dog anonymous Thinkpad code for Linux kernel LXer Syndicated Linux News 0 08-14-2006 07:54 PM
LXer: Linux: High-Res Timers and Tickless Kernel LXer Syndicated Linux News 0 06-24-2006 08:21 AM
How to build kernel timers? santhosh.linux Programming 1 12-14-2005 10:10 PM
kernel-level timers? for benchmarking... microtim Programming 1 03-10-2003 04:00 PM

All times are GMT -5. The time now is 03:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration