LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-26-2010, 05:36 AM   #1
bizoo
LQ Newbie
 
Registered: Jul 2009
Posts: 17

Rep: Reputation: 0
behaviour of dynamic (kernel) timer


HI
My system: Ubuntu 2.6.31. Language C, compiler: gcc

I am running dynamic timer as a kernel module and my issue is that the once the timer overflows , the program finishes. On the other hand i have forced to arm the timer again because of a while loop but the timer never is started again.
i am targetting a periodic timer but it runs once and thats it.

any ideas?
thx

Code:
#include <asm/param.h>
#include <linux/sched.h>
#include "ktimer.h"
struct timer_list mtimer;
int actual_module(void);
void handler(unsigned long z);

int actual_module()
{
int k=0,x=0;
init_timer(&mtimer);	
mtimer.function=handler;
while(k<2){
x=mod_timer(&mtimer, jiffies +2*HZ ) ;
schedule();
k++;
}

//timeout=expire-jiffies;

return 0;
}


void handler(unsigned long z)
{
printk("the timer overflows  \n");
return;
}




static int __init ktimer_init(void)
{
 int err = 0;
 printk(KERN_INFO  "dynamic timer module init\n");
 err= actual_module();
 if(err != 0) 
 {
 return err;
 }
 return 0;	
}

static void __exit ktimer_exit(void)
{
del_singleshot_timer_sync(&mtimer);
return;
}


module_init(ktimer_init);
module_exit(ktimer_exit);
 
Old 01-28-2010, 12:10 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
you might want to move this statement inside the timer callback. After all, when you say periodic, you don't want the same timer to be initialized twice, as your code does or tries to do(kernel actually initializes it only once), but to be called every 2 secs. For it to be called every 2 secs, you would need the timer callback to invoke mod_timer every time it runs.
Code:
#include <asm/param.h>
#include <linux/sched.h>
#include "ktimer.h"
struct timer_list mtimer;
int actual_module(void);
void handler(unsigned long z);

int actual_module()
{
int k=0,x=0;
init_timer(&mtimer);	
mtimer.function=handler;

x=mod_timer(&mtimer, jiffies +2*HZ ) ;
schedule();
k++;


//timeout=expire-jiffies;

return 0;
}


void handler(unsigned long z)
{
printk("the timer overflows  \n");
mod_timer(&mtimer, jiffies +2*HZ ) ;
return;
}




static int __init ktimer_init(void)
{
 int err = 0;
 printk(KERN_INFO  "dynamic timer module init\n");
 err= actual_module();
 if(err != 0) 
 {
 return err;
 }
 return 0;	
}

static void __exit ktimer_exit(void)
{
del_singleshot_timer_sync(&mtimer);
return;
}


module_init(ktimer_init);
module_exit(ktimer_exit);

Last edited by shishir; 01-28-2010 at 10:54 PM.
 
  


Reply

Tags
dynamic, kernel, linux, module, timer



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
Firewall/Gateway distribution with dynamic/automatic QoS based on network behaviour redvivi Linux - Distributions 3 01-22-2010 08:23 PM
How can I get LAPIC timer to run instead of the PIT timer? sixerjman Linux - Kernel 1 10-16-2007 09:59 PM
Multimedia timer (SMP friendly timer) bigqueso Linux - Kernel 0 03-15-2007 03:49 PM
Increasing Kernel timer (2.4) john_d13 Slackware 3 06-16-2006 01:00 AM
Kernel Timer koby *BSD 1 07-19-2005 05:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:31 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration