本文介绍了jiffies的 - 如何计算秒过去了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块code,我想要计算秒的时候..虽然我得到一次一会儿的,我怎么能转换它在几秒钟?

I have a piece of code, i want to calculate the time in seconds.. though i am getting time in jiffies, how can i convert it in seconds?

这是我的内核code:

here is my kernel code:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/timer.h>
unsigned long js, je, tet;
int netblock_init_module(void){
    js = jiffies;
    printk("\n[Jiffies start Time : %lu]\nModule Started.\n", js);
    return 0;
}

void netblock_cleanup_module(void) {
    je = jiffies;
    printk("\n[Jiffies End Time : %lu]\nModule Removed.\n", je);
    tet = je - js;
    printk("\nEnd Time [%lu] - Start Time [%lu]: \nTotlal elapsed Time [%lu]\n",js,je, tet);

}

module_init(netblock_init_module);
module_exit(netblock_cleanup_module);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("JIFFIES EXAMPLE");
MODULE_AUTHOR("RAHEEL");

输出我收到像这样:

Output I am getting is like to this:

$ insmod的jiffexample.ko

[开始的jiffies时间:13363583]

[Jiffies start Time : 13363583]

模块入门

$ rmmod的jiffexample.ko

[jiffies的结束时间:13361588]

[Jiffies End Time : 13361588]

模块已删除。

结束时间13361588 - 启动时间1336358

End Time 13361588 - Start Time 1336358

总耗时[1605]

现在我想转换的时间,以秒..如何其可能在几秒钟内这种经过时间1605转换?
或者也可以请你告诉我有多少个jiffies处于第二?

Now i want to get converted time in seconds.. how its possible to convert this elapsed time 1605 in seconds?or alternatively can you please tell me how many jiffies are in a second?

推荐答案

从http://www.kernel.org/doc/man-pages/online/pages/man7/time.7.html:

一个瞬间的大小是由内核常数HZ的值确定。

HZ的值跨内核版本和硬件平台的不同而不同。在i386的情况如下:内核上直至并包括2.4.x的,HZ为100,给人以0.01秒一个瞬间值;首先是2.6.0,HZ提高到1000,给人0.001秒的瞬间。由于内核2.6.13的HZ值是一个内核配置参数,可以是100,250(默认值)或1000,高产,分别为0.01,0.004,或0.001秒的jiffies值。由于内核2.6.20,进一步频率为可供选择:300,这个数字整除为常见的视频帧速率(PAL,25 HZ; NTSC,30 HZ)

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

仅仅通过HZ分裂。

这篇关于jiffies的 - 如何计算秒过去了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:15