problem in writing a dynamic timer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All

I want to write a small kernel module.
The module will create a dynamic timer and
invoke a specified function after a fixed time interval(5 sec in my case).
The code for the sample module is as follows:
===========================sample code=======================================
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/timer.h>

//invoke this function after 5 seconds

void call_func(unsigned long x)
{
	printk("called from a dynamic timer\n");
	//do some processing here
	.......
	.......
}

//add a timer
int init_module(void)
{
	struct timer_list timer;
	init_timer(&timer);
	timer.expires=jiffies + 5*HZ;
	timer.function= & call_func;
	add_timer(&timer);
	printk("this is timer_module\n");
	return 0;
}

void cleanup_module(void)
{
	printk("goodbye\n");
}

MODULE_LICENSE("GPL");
MODULE_AUTHOR("sanjay");
MODULE_DESCRIPTION("A TEST MODULE TO CREATE A DYNAMIC TIMER")

=============================end code============================================
the makefile for module reads:
obj-m += timer_module.o
default:
	make -C /lib/modules/`uname -r`/build/ SUBDIRS=$(PWD) module
=================================================================================

The module compiles fine.
But whenever i try to insert the module, the kernel crashes giving a stack 
trace and following warning:
	<0>Kernel panic: fatal exception in interrupt handler -not syncing.

kindly indicate the mistake I am making.
I think the timer is deactivated after one invocation, so there is no need to del_timer_sync
in this case

Thanks and Regards
Sanjay Kumar

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux