Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  02 Mar 2021, Konstantin Olchanski, Info, shortest possible sleep 
    Reply  02 Mar 2021, Stefan Ritt, Info, shortest possible sleep 
       Reply  03 Mar 2021, Konstantin Olchanski, Info, shortest possible sleep 
Message ID: 2117     Entry time: 03 Mar 2021     In reply to: 2116
Author: Konstantin Olchanski 
Topic: Info 
Subject: shortest possible sleep 
> Why do you need that?

UNIX/POSIX advertises functions for sleeping in microseconds and nanoseconds,
for sure it is interesting to know what they actually do and what happens
when you ask them to sleep for 1 microsecond or 1 nanosecond.

To sleep or not to sleep that is a question.

But if I do decide to sleep, and I call the sleep function, I want to know what actually happens.

Now I do and I share it with all.

On current Linux, shortest sleep is around 60 usec. select() with sleep
shorter than that will not sleep at all, nanosleep() will always sleep for
the shortest amount.

P.S. For fans of interrupts ("because they are fast"), sleep waiting for interrupt
probably has same latency/granularity as above (60 usec), so if I drive a DMA engine
and I except the DMA transfer to complete under 60 usec, I should use a busy loop
to poll the "DMA done" bit instead of going to sleep and wait for the DMA interrupt.

K.O.
ELOG V3.1.4-2e1708b5