1、jiffies
HZ=100,jiffies=1 means 10ms。
2,延时
unsigned long timeout = jiffies + (3*HZ);
while (hwgroup->busy) {
if (time_after(jiffies, timeout)) {
return -EBUSY;
}
}
unsigned long timeout = HZ;
schedule_timeout(timeout); /* Allow other parts of the kernel to run */
短延时:mdelay, udelay, ndelay
3,时间
clock_settime, clock_gettime
do_gettimeofday
time()
localtime()
mktime()
gettimeofday()
3,定时器
#include <linux/timer.h>
struct timer_list my_timer;
init_timer(&my_timer); /* Also see setup_timer() */
my_timer.expire = jiffies + n*HZ; /* n is the timeout in number of seconds */
my_timer.function = timer_func; /* Function to execute after n seconds */
my_timer.data = func_parameter; /* Parameter to be passed to timer_func */
add_timer(&my_timer); /* Start the timer */
其他函数:mod_timer, del_timer
用户态:setitimer,getitimer
4、高精度定时器
void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode);
timer.function = hr_callback;
int hrtimer_start(struct hrtimer *timer, ktime_t tim,
const enum hrtimer_mode mode);
int hrtimer_cancel(struct hrtimer *timer);