我在'Linux设备驱动程序‘中读到了第7章:时间可以用“jiffies”来衡量。股票jiffies变量的问题在于它非常频繁地被包装(特别是当您将CONFIG_HZ设置为1000时)。
在我的内核模块中,我保存了一个jiffies值,该值在将来被设置为某个时间,并在以后将其与当前的“jiffies”值进行比较。我已经了解到,有些函数考虑到了32位跳转包装,因此,为了比较我使用的两个值:
if (time_after(jiffies, some_future_jiffies_value))
{
// we've already passed the saved value
据我所知,Linux内核中的"jiffies“是自引导以来的滴答数,一秒钟内的滴答数由"HZ”定义,因此在理论上:
(uptime in seconds) = jiffies / HZ
但根据我的测试,上面的说法是不正确的。例如:
$ uname -r
2.6.32-504.el6.x86_64
$ grep CONFIG_HZ /boot/config-2.6.32-504.el6.x86_64
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_
据我所知,USER_HZ常数是在Linux2.6中添加的,以解决用户空间中HZ值的期望值产生的问题:在以前的Linux版本中,更改HZ值可能会导致用户空间应用程序中的值被无意地缩放。
我对USER_HZ常数如何解决这个缩放问题感到困惑。例如,假设用户空间应用程序将jiffies转换为秒:
long MY_HZ = sysconf(_SC_CLK_TCK);
/* num_jiffies acquired from /proc but
* simplified to 1000 here for clarity */
long num_jiffies = 1000;
long num_sec
我试着在linux内核源代码(2.6.18.8版本)中使用llvm- of (llvm 1.7版)编译一个驱动程序(linux/drivers/net/zorro8390.c)用于研究,但我从jiffies.h中得到了很多错误:
bash-3.2$ llvm-gcc -D__GNUCC -E -I../../include zorro8390.c -o test.o
In file included from ../../include/linux/lockdep.h:12,
from ../../include/linux/spinlock_types.h:
如何用c语言在ubuntu linux机器上查找进程启动时间。在linux中,有/proc/pid/stat文件,它提供信息
starttime %lu /*The time in jiffies the process started after system boot*/
和文件/proc/stat,它提供了
btime %lu /*measurement of system boot time since Epoch in seconds*/
为了将这两个值相加,我如何将以前的值转换为秒,因为它是以jiffies为单位的。
我在内核中看到了以下代码:
/*
* Have the 32 bit jiffies value wrap 5 minutes after boot
* so jiffies wrap bugs show up earlier.
*/
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
static inline u32 cstamp_delta(unsigned long cstamp)
{
return (cstamp - INITIAL_JIFFIES) *
我读过,在引导时,jiffies不是初始化为零,而是初始化为INITIAL_JIFFIES常量。
从头文件
/*
* Have the 32 bit jiffies value wrap 5 minutes after boot
* so jiffies wrap bugs show up earlier.
*/
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
如何-300*HZ包装5分钟后启动。有人能解释一下吗?