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

Subject: Re: epicsThreadSleep and epicsThreadSleepQuantum
From: Mark Rivers via Core-talk <[email protected]>
To: Michael Davidsaver <[email protected]>, "'Konrad, Martin'" <[email protected]>, "[email protected]" <[email protected]>
Date: Wed, 12 Jun 2019 20:57:02 +0000
> b) Consider marking epicsThreadSleepQuantum(), timerQueueActive::quantum(), and fdManager::quantum() as deprecated.


These are the places where epicsThreadSleepQuantum is used in synApps, including asyn and areaDetector:


corvette:~/devel>find . -name '*.c*' -type f -exec grep -H epicsThreadSleepQuantum {} \;
./asyn-4-35/asyn/linuxGpib/drvLinuxGpib.c:      epicsThreadSleep(epicsThreadSleepQuantum());
./asyn-4-35/asyn/miscellaneous/asynShellCommands.c:      timeCaps.wPeriodMin, timeCaps.wPeriodMax, epicsThreadSleepQuantum()); */
./asyn-4-35/asyn/miscellaneous/asynShellCommands.c:      minPeriodMs, status, epicsThreadSleepQuantum()); */
./vme-2-8-2/vmeApp/src/drvIK320.c:    quantum = epicsThreadSleepQuantum();
./tpmac-3-11dls5/pmacApp/src/pmacDriver.c:        const double delay = epicsThreadSleepQuantum();
./stream-2-7-7/StreamDevice/src/AsynDriverInterface.cc:            +epicsThreadSleepQuantum()*0.5
./motor-6-9/motorApp/DeltaTauSrc/drvPmac.cc:    quantum = epicsThreadSleepQuantum();
./motor-6-9/motorApp/DeltaTauSrc/drvPmac.cc:    Debug(5, "motor_init: epicsThreadSleepQuantum = %f\n", quantum);
./motor-6-9/motorApp/OmsSrc/drvMAXv.cc: * 06  05-17-06 rls - Allow polling rate up to 1/epicsThreadSleepQuantum().
./motor-6-9/motorApp/OmsSrc/drvMAXv.cc:        epicsThreadSleep(epicsThreadSleepQuantum());
./motor-6-9/motorApp/OmsSrc/drvMAXv.cc:          int scan_rate)        /* 1 <= polling rate <= (1/epicsThreadSleepQuantum) */
./motor-6-9/motorApp/OmsSrc/drvMAXv.cc:    quantum = epicsThreadSleepQuantum();
./motor-6-9/motorApp/OmsSrc/drvOms.cc:    quantum = epicsThreadSleepQuantum();
./motor-6-9/motorApp/OmsSrc/drvOms58.cc:    quantum = epicsThreadSleepQuantum();
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:    int maxcount = (int)(0.1 / epicsThreadSleepQuantum());
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:    // skip busy-waiting for small epicsThreadSleepQuantum
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:    if (epicsThreadSleepQuantum() <= 0.01) index = 100;
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:    // skip busy-waiting for small epicsThreadSleepQuantum
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:    if (epicsThreadSleepQuantum() <= 0.01) itera = 2001;
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:            time += epicsThreadSleepQuantum();
./motor-6-9/motorApp/OmsAsynSrc/omsMAXv.cpp:            epicsThreadSleep(epicsThreadSleepQuantum());
./motor-6-9/motorApp/AttocubeSrc/drvANC150Asyn.cc:        pAxis->moveinterval = epicsThreadSleepQuantum();
./motor-6-9/motorApp/MotorSrc/motordrvCom.cc:    const double quantum = epicsThreadSleepQuantum();
./mca-7-7/mcaApp/SISSrc/sis3820_jtag_prom_epics.c:            epicsThreadSleep(2*epicsThreadSleepQuantum());
./mca-7-7/mcaApp/SISSrc/sis3820_jtag_prom_epics.c:        epicsThreadSleep(2*epicsThreadSleepQuantum());
./mca-7-7/mcaApp/SISSrc/drvSIS3801.cpp:        status = epicsEventWaitWithTimeout(readFIFOEventId_, epicsThreadSleepQuantum());
./mca-7-7/mcaApp/SISSrc/drvSIS3820.cpp:        status = epicsEventWaitWithTimeout(readFIFOEventId_, epicsThreadSleepQuantum());
./mca-7-7/mcaApp/CanberraSrc/nmc_comm_subs_1.c:        epicsThreadSleep(epicsThreadSleepQuantum());
./dxp-5-0/dxpApp/src/NDDxp.cpp:            epicsThreadSleep(epicsThreadSleepQuantum());
./dxpSITORO-1-1/dxpApp/src/NDDxp.cpp:            epicsThreadSleep(epicsThreadSleepQuantum());
./devIocStats-3-1-15/devIocStats/devIocStatsTest.c:     double   delay = (double)tick_delay * epicsThreadSleepQuantum();
./calc-3-7/calcApp/src/sseqRecord.c:            plinkGroup->dly = epicsThreadSleepQuantum() *
./calc-3-7/calcApp/src/sseqRecord.c:                    NINT(plinkGroup->dly/epicsThreadSleepQuantum());
./calc-3-7/calcApp/src/sseqRecord.c:            plinkGroup->dly = epicsThreadSleepQuantum() *
./calc-3-7/calcApp/src/sseqRecord.c:                    NINT(plinkGroup->dly/epicsThreadSleepQuantum());
./sscan-2-11-1/sscanApp/src/sscanRecord.c: *                      skip it.  Replace #define'd ticsPerSecond with 1./epicsThreadSleepQuantum();
./sscan-2-11-1/sscanApp/src/sscanRecord.c:#include <epicsThread.h>      /* for epicsThreadSleepQuantum() */
./sscan-2-11-1/sscanApp/src/sscanRecord.c:              ticsPerSecond = NINT(1./epicsThreadSleepQuantum());
./sscan-2-11-1/sscanApp/src/recDynLink.c:                       epicsThreadSleep(epicsThreadSleepQuantum());
./sscan-2-11-1/sscanApp/src/recDynLink.c:               epicsThreadSleep(epicsThreadSleepQuantum());
./sscan-2-11-1/sscanApp/src/recDynLink.c:               epicsThreadSleep(epicsThreadSleepQuantum());
./quadEM-9-1/quadEMApp/src/drvAPS_EM.cpp:        epicsThreadSleep(epicsThreadSleepQuantum());
./quadEM-9-1/quadEMApp/src/drvAPS_EM.cpp:        sampleTime = epicsThreadSleepQuantum();
./quadEM-9-1/quadEMApp/src/drvAPS_EM.cpp:           fprintf(fp, "    Not using interrupts, scan time=%f\n", epicsThreadSleepQuantum());
./areaDetector-3-6/ADPSL/pslApp/src/PSL.cpp:                epicsThreadSleep(epicsThreadSleepQuantum());
./areaDetector-3-6/firewireDCAM/firewireDCAMApp/src/firewireDCAM.cpp:           if (fptr==NULL) epicsThreadSleep( epicsThreadSleepQuantum() );
./areaDetector-3-6/ADADSC/adscApp/src/adsc.cpp:        if (acquirePeriodDelay >= epicsThreadSleepQuantum()) {
./areaDetector-3-6/ADPvCam/pvcamApp/src/pvCam.cpp:            if (delay >= epicsThreadSleepQuantum())
./areaDetector-3-6/ADCore/ADApp/ADSrc/PVAttribute.cpp:            epicsThreadSleep(epicsThreadSleepQuantum());



Mark


________________________________
From: Michael Davidsaver <[email protected]>
Sent: Wednesday, June 12, 2019 11:50 AM
To: Mark Rivers; 'Konrad, Martin'; [email protected]
Subject: Re: epicsThreadSleep and epicsThreadSleepQuantum

On 6/11/19 6:57 AM, Mark Rivers via Core-talk wrote:
>> If we want to sleep for a minimum amount of time we might want to call nanosleep(0) instead.
>
> But that will not work on Windows or vxWorks.
>
> Mark
>
>
> -----Original Message-----
> From: Konrad, Martin <[email protected]>
> Sent: Tuesday, June 11, 2019 8:49 AM
> To: Mark Rivers <[email protected]>; [email protected]
> Subject: Re: epicsThreadSleep and epicsThreadSleepQuantum
>
> Hi,
>> I started a tech-talk thread on this topic 11 years ago:
>>
>> https://epics.anl.gov/tech-talk/2008/msg00987.php
> Thanks Mark, I wasn't aware of this thread. I'm not aware of any way to detect the sleep quantum reliably on modern machines either. The fact that epicsThreadSleepQuantum() only works correctly on old machines without high resolution timers suggests that we should avoid using it. I think it would make sense to

I'll second this.  Minimum sleep time is not a meaningful concept for a modern general purpose OS.

https://en.wikipedia.org/wiki/Tickless_kernel

All the usages of sleep(0) I've seen have been shortcuts to avoid using real synchronization primitives.
This is something I would discourage.


> a) Add a warning to the App Dev Guide.
> b) Consider marking epicsThreadSleepQuantum(), timerQueueActive::quantum(), and fdManager::quantum() as deprecated.

I'd be fine with this, provided all internal usages can be removed.

> c) Remove the "(ppsl->period < 2 * quantum)" part of the test in [1].

There is also a usage in timer::privateStart() to bias expiration time.
I wonder if this tweak is still relevant?

>    this->exp = expire - ( this->queue.notify.quantum () / 2.0 );

https://github.com/epics-base/epics-base/blob/655c5bed925137619d4a538f7893400b38c7c907/modules/libcom/src/timer/timer.cpp#L69

originally introduced by:

https://github.com/epics-base/epics-base/commit/0792aebf952dbc4f7e7291e6175c27b72a80c338

The remaining usage I find in Base, outside of test code, is in various epicsThreadOnce()
implementations which spin to avoid coupling, or copying, the internals of osdEvent.c into osdThread.c.

> If we want to sleep for a minimum amount of time we might want to call
> nanosleep(0) instead. If I'm understanding the man page correctly this should result at least in a context switch.

Maybe add a dedicated call?

> /* Ensure your epicsThread is fresh and ready to start the day */
> void epicsSnooze();

References:
epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
Re: epicsThreadSleep and epicsThreadSleepQuantum Konrad, Martin via Core-talk
RE: epicsThreadSleep and epicsThreadSleepQuantum Mark Rivers via Core-talk
Re: epicsThreadSleep and epicsThreadSleepQuantum Michael Davidsaver via Core-talk

Navigate by Date:
Prev: Re: epicsThreadSleep and epicsThreadSleepQuantum Michael Davidsaver via Core-talk
Next: Re: EPICS 7 PVA for Java Williams Jr., Ernest L. 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 
Navigate by Thread:
Prev: Re: epicsThreadSleep and epicsThreadSleepQuantum Michael Davidsaver via Core-talk
Next: Re: epicsThreadSleep and epicsThreadSleepQuantum Johnson, Andrew N. 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 
ANJ, 13 Jun 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·