Re: Periodic event in Kernel Module

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

 



On 2/10/07, Curran, Dominic <dcurran@xxxxxx> wrote:
>
> > 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 );

Use time_after/time_before, as this direct comparison will miss wraps.

Thanks,
Nish

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