kernel time
来源:互联网 发布:七月算法 百度云 编辑:程序博客网 时间:2024/04/25 09:50
linux内核是通过定时器中断来跟踪时间流;使用"HZ"宏表示1秒的时钟中断次数;
并使用"jiffies"及"jiffies_64"变量来记录时钟中断次数,在系统引导时计数器初始化为0。
示例4_1
1 比较jiffies计数器
内核提供的辅助函数
实际上这些函数都是宏,这里写成函数形式看起来比较直观。
因此示例4_1的"while"语句可改成
建议使用内核提供的函数或宏来操作jiffies,而不建议直接操作jiffies。
2 内核表述方法(jiffies)与时间表述方法的转换
时间表述方法可用的数据结构有"struct timeval"和"struct timespec"。其中"struct timeval"为老式的数但较为流行,它使用秒和毫秒值;而"struct timespec"为新式的,它使用的是秒与纳秒值。
内核提供四个辅助函数用于jiffies的此类转换
这些函数看起来是那么明了,以至于无需示例加以说明。
3 获取jiffies_64值
内核提供辅助函数
4 获取CPU时钟周期数值
使用jiffies值测量时间差间隔在大部分情况下已经足够,但如果测量更短的时间差,则可以使用处理器特定寄存器。内核为访问该寄存器提供以下接口:
rdtsc宏是与体系结构相关,而get_cycles则与体系结构无关。
5 获取当前时间
内核辅助函数
注:转载时请注明出自:add358.blog.chinaunix.net
并使用"jiffies"及"jiffies_64"变量来记录时钟中断次数,在系统引导时计数器初始化为0。
示例4_1
- #include <linux/jiffies.h>
- unsigned long stamp;
- stamp = jiffies + HZ; /* 之后1秒 */
- while( jiffies < stamp) /* 在这里忙等待1秒 */
- { cpu_relax();}
内核提供的辅助函数
- #include <linux/jiffies.h>
- int time_after(unsigned long a, unsigned b); /* a时间比b靠后时,返回真 */
- int time_before(unsigned long a, unsigned b); /* a比b靠前时,返回真 */
- int time_after_eq(unsigned long a, unsigned b); /* a比b靠后或相等,返回真 */
- int time_before_eq(unsigned long a, unsigned b); /* a比b靠前或相等,返回真 */
因此示例4_1的"while"语句可改成
- while(time_before(jiffies, stamp))
2 内核表述方法(jiffies)与时间表述方法的转换
时间表述方法可用的数据结构有"struct timeval"和"struct timespec"。其中"struct timeval"为老式的数但较为流行,它使用秒和毫秒值;而"struct timespec"为新式的,它使用的是秒与纳秒值。
内核提供四个辅助函数用于jiffies的此类转换
- #include <linux/time.h>
- unsigned long timespec_to_jiffies(struct timespec *value);
- void jiffies_to_timespec(unsigned jiffies, struct timespec *value);
- unsigned long timeval_to_jiffies(struct timeval *val);
- void jiffies_to_timeval(unsigned long jiffies, struct timeval *value);
3 获取jiffies_64值
内核提供辅助函数
- #include <linux/jiffies.h>
- u64 get_jiffies_64(void);
使用jiffies值测量时间差间隔在大部分情况下已经足够,但如果测量更短的时间差,则可以使用处理器特定寄存器。内核为访问该寄存器提供以下接口:
- #include <asm/msr.h>
- rdtsc(low32, high32);
- rdtscl(low32);
- rdtscsll(var64);
- #include <linux/timex.h>
- cycles_t get_cycles(void); /* cycles_t是能装入读取值的合适的无符号类型 */
5 获取当前时间
内核辅助函数
- #include <linux/time.h>
- unsigned long mktime(unsigned int year, unsigned int mon,
- unsigned int day, unsigned int hour,
- unsigned int min, unsigned int sec); /* 将墙钟时间转换为jiffies值 */
- void do_gettimeofday(struct timeval *tv);
- struct timespec current_kernel_time(void)
注:转载时请注明出自:add358.blog.chinaunix.net
- kernel time
- Boot time kernel options
- < Linux Kernel > Measuring Time
- OSE Real-Time Kernel
- linux kernel time management
- Symbian OS Internals: Real-time Kernel Programming
- kernel: TCP: time wait bucket table
- kernel: TCP: time wait bucket table overflow错误的解决办法
- Under Linux kernel 2.6.35, getting current time(accuracy macrosenconds).
- 服务器出现kernel: TCP: time wait bucket table overflow解决
- Linux Kernel open-time Capability file_ns_capable() Privilege Escalation
- < Linux Kernel > Compile-Time Optimization for Condition Checks
- The file access tests that the kernel performs each time
- kernel: TCP: time wait bucket table overflow错误的解决办法
- Measuring kernel latencies to ensure real-time constraints
- kernel: TCP: time wait bucket table overflow的问题
- kernel 调用uefi的run time service 关机
- Kernel
- 简单用法WebView
- Qt QLabel::setBuddy函数
- 在Sqlite中通过Replace来实现插入和更新
- hdu 4712 Hamming Distance ( 随机算法混过了 )
- VC++ 6.0 中如何使用 CRT 调试功能来检测内存泄漏 调试方法
- kernel time
- Qt 安装事件过滤器installEventFilter
- Hadoop的调度器总结
- 今个真高兴!
- linq.js JQuery.linq.js的试验例子
- jQuery选择器大全
- hadoop的使用命令
- c++ 不建议使用字符串常量到 char*的转换
- 在Unity3D的网络游戏中实现资源动态加载