分类: LINUX
2008-12-05 11:22:42
1.linux/jiffies.h
2.时间表示
j = jiffies; /* read the current value */
stamp_1 = j + HZ; /* 1 second in the future */
stamp_half = j + HZ/2; /* half a second */
stamp_n = j + n * HZ / 1000; /* n milliseconds */
在64位机器上得到值:
#include
u64 get_jiffies_64(void);
3.时间比较
#include
int time_after(unsigned long a, unsigned long b);
int time_before(unsigned long a, unsigned long b);
int time_after_eq(unsigned long a, unsigned long b);
int time_before_eq(unsigned long a, unsigned long b);
diff = (long)t2 - (long)t1;.
以上转换为 signed long, 相减, 得出结果
4.与用户空间时间转换
linux/time.h
结构体
旧的struct timeval{ seconds xx;microseconds yy;}
新的struct timespec {seconds xx; nanoseconds yy;}
函数
|
|
7.1.2. 处理器特定的寄存器
1.若对时间要求严格,可依赖硬件,大部分现代处理器包含一个计数器寄存器,它在每个时钟周期固定地递增一次