澄清在linux中的纳秒()睡眠 [英] Clarification on nanosecond() sleep in linux

查看:263
本文介绍了澄清在linux中的纳秒()睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用纳秒睡眠,我能睡1纳秒吗?

linux上是否支持更精细的计时器粒度?

大多数计时器粒度将是10毫秒(调度程序滴答),所以我的理解是不可能实现小于10毫秒的计时器粒度。

有人可以澄清吗?



如果假设支持更精细的分辨率,我的任务将进入休眠状态,或者内核将代表我的任务执行繁忙的循环以传递时间(例如100微秒或500纳秒)?



有人可以澄清一下吗?



我尝试了什么:



如果假设支持更精细的分辨率,我的任务将被置于休眠状态,或者内核将代表我的任务进行繁忙循环以传递时间(例如100微秒)或500纳秒)?



有人可以澄清一下吗?

Using nanosecond sleep , will i able to sleep for 1 nanosecond?.
Is that much finer timer granularity is supported on linux?
Mostly timer granularity will be 10mSec(scheduler tick), so my understanding is that it is not possible to achieve timer granularity less than 10mSec.
can someone clarify please?

If suppose finer resolution is supported , my task will be put into sleep or kernel will do busy loop on behalf of my task to pass time(say 100 microsecond or 500 nanosecond)?

Can someone please clarify?

What I have tried:

If suppose finer resolution is supported , my task will be put into sleep or kernel will do busy loop on behalf of my task to pass time(say 100 microsecond or 500 nanosecond)?

Can someone please clarify?

推荐答案

你不能使用计时器进行绝对计时在多活动操作系统中。当计时器到期时,这意味着操作系统将您的活动(进程)放回执行队列,因此它将在下次到达队列顶部时恢复。这将是在1 b或更多纳秒之后。



参见 nanosleep(2):高分辨率睡眠 - Linux手册页 [ ^ ]。
You cannot use timers for absolute timing in a multi-activity operating system. When a timer expires that merely means that the operating system places your activity (process) back on the execution queue, so it will resume the next time it reaches the top of the queue. This will be after 1 or more nanoseconds.

See nanosleep(2): high-resolution sleep - Linux man page[^].


您可能无法在单纳秒内睡眠,因为可用的分辨率取决于基础时钟的粒度是系统依赖的。如果基础时钟的分辨率不是纳秒或更小,则传递的值将被四舍五入。



另请参阅OpenGroup规范nanosleep [ ^ ]和 nanosleep(2):high -resolution sleep - Linux手册页 [ ^ ]。



要获得硬件时钟的分辨率,请参阅 clock_getres (2):时钟/时间函数 - Linux手册页 [ ^ 。请注意,还有 clock_nanosleep(2) - Linux手册页 [ ^ ]函数允许使用时钟的指定。



当使用sleep函数时,只有当前线程(或单线程时的当前进程)将等待。包括内核在内的其他线程将继续运行。
You will probably not be able to sleep for a single nano second because the available resolution depends on the granularity of the underlying clock which is system dependant. If the underlying clock has not a resolution of a nano second or less, the passed value will be by rounded up.

See also the OpenGroup specification nanosleep[^] and the nanosleep(2): high-resolution sleep - Linux man page[^].

To get the resolution of the hardware clock see clock_getres(2): clock/time functions - Linux man page[^]. Note that there is also the clock_nanosleep(2) - Linux man page[^] function which allows specification of the clock to be used.

When using sleep functions only the current thread (or the current process when it is single threaded) will be waiting. Other threads including the kernel will continue operation.


这篇关于澄清在linux中的纳秒()睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆