RE: Periodic event in Kernel Module

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

 



> 
> > Hello. I have written a netfilter kernel module and I want some code
> > to run periodically, ie a function in the module should run every 5
> > seconds.
> >
> > I have researched and implemented a kernel work queue however this
> > does not have the capability of being periodic from my assessment.
> > Can anyone point me in the right direction?
> >
> 
> i've read all messages in this thread and seems the only way proposed
> is using timers...
> 
> i've implemented a very similar kernel module, using netfilter to
track
> connections, and i created a kernel tread that detect inactivity in a
> loop, and sleeping for a while in between.
> 
> this solutions will work for you? :)
> 
> or maybe i'm doing a very ugly thing? :(
> 

The original poster asked for code to run periodically.  From that I
assumed he meant every X number of jiffies.
Using timers will give him pretty good accuracy in that respect.

What mechanism are you using to sleep and wake yourself up within your
thread ? 

If you are using schedule() to sleep and then testing if > X jiffies has
passed then this will also work.  
e.g.
	while( !exit )
	{
		start = jiffies;
		do {
		schedule();
		} while( jiffies - start < X );

		do_work_here();
	}

However I would suggest that you may not get the same accuracy as using
timers.  When you call schedule() you have no control over how long it
will be before your thread gets scheduled back in.
If you don't care about accuracy then that probably not a problem.

Your method of using a thread benefits from being able to block (wait)
in that context.  You cannot block in a timer context.

dom


--
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