LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 02-22-2009, 01:49 AM   #1
iamjayanth
Member
 
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, 11:42 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You want to use setitimer(). See http://www.informit.com/articles/art...3618&seqNum=14 for details.
--- rod.
 
Old 02-22-2009, 10:44 PM   #3
iamjayanth
Member
 
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, 03:08 AM   #4
bhaskarreddy
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);
writeb(reg_val,led_addr);
/* SET LED OFF */
reg_val = readb(led_addr);
reg_val &= ~(1<<0);
writeb(reg_val,led_addr);


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


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 */
//my_timer.data = func_parameter; /* Parameter to be passed to timer_func */
add_timer(&my_timer); /* Start the timer */
return 0;

}
void exit_led(void)
{
printk("exit\n");
del_timer(&my_timer);
}

module_init(init_led);
module_exit(exit_led);
 
1 members found this post helpful.
Old 03-03-2009, 08:43 AM   #5
iamjayanth
Member
 
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, 06:53 PM   #6
cafun4o
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
 
  


Reply


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 04:15 AM
LXer: Doubts dog anonymous Thinkpad code for Linux kernel LXer Syndicated Linux News 0 08-14-2006 06:54 PM
LXer: Linux: High-Res Timers and Tickless Kernel LXer Syndicated Linux News 0 06-24-2006 07:21 AM
How to build kernel timers? santhosh.linux Programming 1 12-14-2005 09:10 PM
kernel-level timers? for benchmarking... microtim Programming 1 03-10-2003 03:00 PM


All times are GMT -5. The time now is 02:52 PM.

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