嵌入式设备上的微秒(或一毫秒)时间分辨率(Linux 内核)
我构建了一个内核模块,需要至少 1 毫秒的时间分辨率。我目前使用 do_gettimeofday() 但我担心一旦我将模块移动到嵌入式设备,这将不起作用。该设备具有 180 Mz 处理器 (MIPS),内核中的默认 HZ 值为 100。因此,使用 jiffies 最多只能提供 10 毫秒的分辨率。那不会削减它。
我想知道的是 do_gettimeofday() 是否基于计时器中断(HZ)。能否保证提供至少1ms的分辨率?
谢谢!
I have a kernel module I've built that requires at least 1 ms time resolution. I currently use do_gettimeofday() but I'm concerned that this won't work once I move my module to an embedded device. The device has a 180 Mz processor (MIPS) and the default HZ value in the kernel is 100. Thus using jiffies will only give me at best 10 ms resolution. That won't cut it.
What I'd like to know is if do_gettimeofday() is based on the timer interrupt (HZ). Can it be guaranteed to provide at least 1 ms of resolution?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ms 不是微秒,而是毫秒。如果不了解有关您选择的设备的更多信息,没有人可以回答这样一个与实现相关的问题,例如 gettimeofday 是否基于计时器中断。如果您选择了一种设备,并且知道其指令集和时钟速度,那么为什么不查看该特定内核的实现来找出答案呢?
ms is not microsecond, it's millisecond. Without knowing more about your choice of device, no one can possibly answer such an implementation-dependent question as whether gettimeofday is based on the timer interrupt. If you have chosen a device, which knowing the instruction set and clock speed suggests, then why don't you look at the implementation of that particular kernel to find out?
在嵌入式设备上,无法保证。由于它是基于 MIPS 的,所以可能没问题,大多数 MIPS 机器都有周期计数器。但是,您将必须阅读内核该部分的源代码,以了解它在您的平台上执行的操作。
On an embedded device, it can't be guaranteed. Seeing as it's MIPS based, it's probably OK, most MIPS machines have cycle counters. But, you're going to have to go read the source to that part of the kernel to see what it is doing on your platform.
是的,您需要在内核中启用
CONFIG_HIGH_RES_TIMERS
,并确保您的平台注册clock_event_device
。这是允许向用户空间公开高分辨率计时器的机制。您可以通过在用户空间中调用clock_getres()
来检查计时器的分辨率。Yes, you need to enable
CONFIG_HIGH_RES_TIMERS
in your kernel, and make sure that your platform registers aclock_event_device
. This is the mechanism that allows to expose high-resolution timers to userspace. You can check the resolution of your timers by callingclock_getres()
in userspace.