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
  • 37,241
  • 25
  • 195
  • 267
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
  • 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
  • 39,472
  • 36
  • 165
  • 245
-3

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

Schnouki
  • 7,527
  • 3
  • 33
  • 38
umang2203
  • 78
  • 5