Re: Timer Issues

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 23 May 2003 17:19:39 +0200
Lukas Ruf <ruf@rawip.org> wrote:

>I would like  to have a function that gets  triggered every second to
>read  the actual  state  of  the counters,  this  function is  called
>timed_func() later.  The function should be triggered irrespective of
>the  status of  the  other functionality  /*  I know  about the  race
>conditions...    and  the  fact   that  the   linux  kernel   is  not
>interruptible per node */
>
>Ideas:
>
>In my mind  the following ideas on came up how  this problem could be
>solved in principle:
>
>a) implement timed_func()  as a "normal" function in  the same module
>   -- this would be the easiest.
>
>b) implement  timed_func() as  a separate module-function.   There, I
>   assume there is no difference executionwise.
>
>c) implement timed_func() as an own kernel_thread such that it gets a
>   schedulable entity.
>
>My Questions:
>
>- Is it possible to  have timed_func() being launched every second in
>  cases  a) &  b)  or is  the whole kernel module  blocked until  the
>  function gets executed?
>  
>  If it  would be possible to implement a) or b), how could I achieve
>  this?
> 
>- Is there another solution/idea that has not come to my mind so far?


The  solution to  your  problem is  really  simple. You  just need  to
schedule  a periodic kernel  timer. This  is the  most straightforward
solution for your needs since kernel timer functions are always called
at just the right time even if  the processor  is  executing  a system  
call. So what you need is simply a code like this one. 

In module initialization

 	init_timer(&timer);
        timer.expires = jiffies + HZ;
        timer.function = handler;
        add_timer(&timer);

Then, in handler() code put as last instructions,

	timer.expires = jiffies + HZ;
        add_timer(&timer);

When kernel  timer function  has been executed,  it reschedules  a new
kernel timer.  If you have  timer as global  you don't need  to define
again the  field function. Obvioulsy,  you can't assume that  the next
call to  handler() will be done  after *exactly* HZ ticks  but I think
that it's the easiest solution for your purposes.

PS If you  have a copy of  Linux Device Drivers please take  a look at
page 203.

Regards.


- --

Angelo Dell'Aera 'buffer' 
Antifork Research, Inc.	  	http://buffer.antifork.org

PGP information in e-mail header


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+0NcipONIzxnBXKIRAtyOAKCh2DtvMCDyBZpg9lTtp8ULIcSc+ACgra/6
2G0fqqlFCzbxcg3ZTVH6Lo8=
=Lq5W
-----END PGP SIGNATURE-----
--
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