2

i need to do some polling in Linux kernel for continues some time so i need to design while loop that exits after some milliseconds interval. So how can i do that?

I have though to use gettimeofday() but that can be used at user space i want this in kernel space.

Cœur
  • 34,719
  • 24
  • 185
  • 251
Jeegar Patel
  • 24,980
  • 49
  • 151
  • 213
  • 1
    this is not duplicate question...that question talk for userspace and i am about kernel space...that was for getting accurate time here i am interested in running while loop for some time – Jeegar Patel Apr 16 '13 at 10:07

2 Answers2

2

use msecs_to_jiffies :

unsigned long j0,j1,delay;
delay = msecs_to_jiffies(20); /* 20 msec delay */
j0 = jiffies; 
j1 = j0 + delay; 

while (time_before(jiffies, j1)) 
        /* do something */

If you have high resolution timers on your system, you can use it for times in magnitude smaller than one jiffy. Generally consider using kernel timers or hrt.

Community
  • 1
  • 1
0x90
  • 37,093
  • 35
  • 149
  • 233
-3

You can use the sleep function, like sleep(1): it will stop the activity for 1 sec.

Schnouki
  • 7,129
  • 2
  • 34
  • 37
umang2203
  • 78
  • 5