Re: Periodic event in Kernel Module

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

 



hi,

El Sat, 10 Feb 2007 18:37:34 -0600
"Curran, Dominic" <dcurran@xxxxxx> ha escrit:

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

i'm using schedule_timeout, because i need to verify if some connections
are expired, but i don't care it it's a fixed time between verifications
> 
> 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();
> 	}

my code looks like:

for (;;) 
{
      set_current_state(TASK_INTERRUPTIBLE);
      schedule_timeout(X);

      set_current_state(TASK_RUNNING);
      if (signal_pending(current))
         break;

      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.

yes, i don't care about accuracy...

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

i know, i'm doing some data cleanups, that probably would sleep in some
situacions

topi

> 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