为何jiffies在系统重启后为赋值?求高手解答

为什么jiffies在系统重启后为赋值?求高手解答
代码很简单
static int __init hello_init(void)
{
printk(KERN_EMERG"hello_init jiffies = %ld.\n", jiffies);
return 0;
}

static void __exit hello_exit(void)
{
printk(KERN_EMERG"hello_exit jiffies = %ld.\n", jiffies);
}

linux系统是Red Hat Enterprise Linux 5,内核是2.6.27.62。
1.命令行下[root@localhost hello]# reboot
2.插入模块[root@localhost hello]# insmod hello.ko 
[root@localhost hello]# 
Message from syslogd@ at Tue Aug 14 09:56:20 2012 …
localhost kernel: hello_init jiffies = -55129.
3.卸载模块[root@localhost hello]# rmmod hello.ko 
[root@localhost hello]# 
Message from syslogd@ at Tue Aug 14 09:56:43 2012 …
localhost kernel: hello_exit jiffies = -49387.

两次打印jiffies的值都为负数,jiffies不是应该从0开始的吗?而且内核里面是extern unsigned long volatile __jiffy_data jiffies;jiffies应该是无符号数啊,怎么会变成负数了呢?求解,@高手大大们

C/C++ code

由于某设备缺少一个模块,需要对原来代码中的jiffies(系统时钟节拍)进行移植,做成一个.ko,方法如下:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
module_param(jiffies,ulong,444)
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world/n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world/n");
}
module_init(hello_init);
module_exit(hello_exit);

makefile如下:
obj-m := hello.o
KERNELDR := /usr/src/linux-2.6.26
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDR) M=$(PWD) modules
moduels_install:
$(MAKE) -C $(KERNELDR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
使用make命令,编译成一个.ko文件,在LINUX下执行insmod hello.ko
然后在sys文件夹下可以找到hello这个模块,打开会找到programme,再 打开就会找到jiffies,用cat就可以查看,module_param就是钥匙,444表示
LINUX的root,group及usr的权限

为何jiffies在系统重启后为赋值?求高手解答

相关文章:

你感兴趣的文章:

标签云: