EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  2025  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  2025 
<== Date ==> <== Thread ==>

Subject: Re: epicsThreadSleep and epicsThreadSleepQuantum
From: Mark Rivers via Core-talk <[email protected]>
To: "Konrad, Martin" <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Tue, 11 Jun 2019 11:35:01 +0000
Hi Martin,


I started a tech-talk thread on this topic 11 years ago:


https://epics.anl.gov/tech-talk/2008/msg00987.php


Mark



________________________________
From: [email protected] <[email protected]> on behalf of Konrad, Martin via Core-talk <[email protected]>
Sent: Monday, June 10, 2019 10:31 PM
To: EPICS Core Talk
Subject: epicsThreadSleep and epicsThreadSleepQuantum

Hi,
I noticed that on most modern Linux machines epicsThreadSleepQuantum()
returns 0.01. The Application Developer's Guide says:

"This function returns the minimum slumber interval obtainable with
epicsThreadSleep() in seconds. [...]"

Looking at the implementation of epicsThreadSleep() which for POSIX uses
nanosleep() I don't think this statement is true. On Linux systems
running kernels >=2.5.47 (?) nanosleep() leverages high resolution
timers and thus is generally able to provide a few orders of magnitude
finer granularity [1,2]. According to my understanding the jiffy
returned by epicsThreadSleepQuantum() is completely unrelated to the
high resolution timers used by nanosleep().

In Base as well as in support modules I found code that calls

epicsThreadSleep(epicsThreadSleepQuantum())

- apparently with the intention of sleeping for a minimum amount of
time. This might result in a much longer sleep than necessary
potentially adding unnecessary latency on modern systems.

It seems like I'm not the first one who's surprised by the way this
function behaves and it seems like it might be misbehaving on other
platforms as well [3,4].

I'm wondering if it would be better to return 0. Maybe only on systems
that support high res timers (not sure if there is a way to detect
this)? Any thoughts?

-Martin

[1] https://rt.wiki.kernel.org/index.php/High_resolution_timers
[2] https://elinux.org/High_Resolution_Timers
[3]
https://github.com/epics-modules/asyn/blob/master/documentation/RELEASE_NOTES.html#L686-L694
[4]
https://github.com/epics-modules/asyn/blob/e40a5185ba55ec7d8e848197c7e371ce1684f2e7/asyn/miscellaneous/asynShellCommands.c#L1189-L1229

--
Martin Konrad
Facility for Rare Isotope Beams
Michigan State University
640 South Shaw Lane
East Lansing, MI 48824-1321, USA
Tel. 517-908-7253
Email: [email protected]

References:
epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk

Navigate by Date:
Prev: epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
Next: Re: epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  2025 
Navigate by Thread:
Prev: epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
Next: Re: epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  2025 
ANJ, 11 Jun 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions ·
· Download · Search · IRMIS · Talk · Documents · Links · Licensing ·