本文介绍了将吉菲斯转换为毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux中手动将抖动转换为毫秒,反之亦然?我知道内核2.6具有此功能,但是我正在研究2.4(家庭作业),尽管我查看了代码,但它使用了许多宏常量,我不知道它们是否在2.4中定义.

How do I manually convert jiffies to milliseconds and vice versa in Linux? I know kernel 2.6 has a function for this, but I'm working on 2.4 (homework) and though I looked at the code it uses lots of macro constants which I have no idea if they're defined in 2.4.

推荐答案

如先前的回答所述,jiffies递增的速率是固定的.

As a previous answer said, the rate at which jiffies increments is fixed.

为接受jiffies的函数指定时间的标准方法是使用常量HZ.

The standard way of specifying time for a function that accepts jiffies is using the constant HZ.

这是赫兹(Hertz)的缩写,或每秒的刻度数.在计时器刻度设置为1ms的系统上,HZ = 1000.某些发行版或体系结构可能使用另一个数字(以前是100).

That's the abbreviation for Hertz, or the number of ticks per second. On a system with a timer tick set to 1ms, HZ=1000. Some distributions or architectures may use another number (100 used to be common).

为函数指定jiffies计数的标准方法是使用HZ,如下所示:

The standard way of specifying a jiffies count for a function is using HZ, like this:

schedule_timeout(HZ / 10);  /* Timeout after 1/10 second */

在大多数简单情况下,这都可以正常工作.

In most simple cases, this works fine.

2*HZ     /* 2 seconds in jiffies */
HZ       /* 1 second in jiffies */
foo * HZ /* foo seconds in jiffies */
HZ/10    /* 100 milliseconds in jiffies */
HZ/100   /* 10 milliseconds in jiffies */
bar*HZ/1000 /* bar milliseconds in jiffies */

后两个问题有点问题,例如,在具有10 ms计时器滴答的系统上,HZ/100为1,精度开始受到影响.您可能会在0.0001到1.999之间的任何时间间隔内获得延迟(本质上是0-2毫秒).如果您尝试在10ms的滴答系统上使用HZ/200,则整数除法会给您0个jiffies!

Those last two have a bit of a problem, however, as on a system with a 10 ms timer tick, HZ/100 is 1, and the precision starts to suffer. You may get a delay anywhere between 0.0001 and 1.999 timer ticks (0-2 ms, essentially). If you tried to use HZ/200 on a 10ms tick system, the integer division gives you 0 jiffies!

因此,经验法则是,请小心使用HZ来获取微小值(接近1吉菲).

So the rule of thumb is, be very careful using HZ for tiny values (those approaching 1 jiffie).

要进行另一种转换,您可以使用:

To convert the other way, you would use:

jiffies / HZ          /* jiffies to seconds */
jiffies * 1000 / HZ   /* jiffies to milliseconds */

您不应期望比毫秒精度更好的东西.

You shouldn't expect anything better than millisecond precision.

这篇关于将吉菲斯转换为毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:15