EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: epicsThreadSleep() and epicsThreadSleepQuantum()
From: "Mark Rivers" <[email protected]>
To: <[email protected]>
Date: Mon, 29 Sep 2008 14:57:02 -0500
Folks,

I've just discovered a problem relating to epicsThreadSleep() and
epicsThreadSleepQuantum() on linux-x86 and win32-x86.

Here is the documentation from the Application Developer's Guide
(3.14.9) for epicsThreadSleepQuantum:

********************************************
epicsThreadSleepQuantum 

This function returns the minimum slumber interval obtainable with
epicsThreadSleep() in seconds. On most OS there is a system scheduler
interrupt
interval which determines the value of this parameter. Knowledge of this
parameter is used by the various components of EPICS to improve
scheduling of software tasks in time when the reduction of average time
scheduling errors is important. If this parameter is unknown or is
unpredictable for a particular OS then it is safe to return zero.
*******************************************

I was seeing some behavior I did not expect in a Windows IOC, so I wrote
a little test program that I ran on Linux and Windows.  This program
simply prints out the value of epicsThreadSleepQuantum, and then sleeps
for various amounts of time, ranging from .0001 second to .020 seconds,
and reports the actual length of the sleep.  These sleeps are done in a
loop 1000 times to improve the precision.

Here is the program, testTimer.c:

*********************************************
#include <stdio.h>
#include <epicsThread.h>
#include <epicsTime.h>


#define MAX_TIMES 8
#define MAX_LOOPS 1000

int main(int argc, char **argv)
{
    double times[MAX_TIMES] = {.0001, .0002, .0005, .001, .002, .005,
.010, .020};
    int iloop, itime;
    epicsTimeStamp startTime, endTime;
    double elapsedTime;
    
    printf("epicsThreadSleepQuantum=%f\n", epicsThreadSleepQuantum());
    
    for (itime=0; itime<MAX_TIMES; itime++) {
        epicsTimeGetCurrent(&startTime);
        for (iloop=0; iloop<MAX_LOOPS; iloop++) {
            epicsThreadSleep(times[itime]);
        }
        epicsTimeGetCurrent(&endTime);
        elapsedTime = epicsTimeDiffInSeconds(&endTime, &startTime);
        printf("Elapsed time to sleep for %f seconds %d times=%f\n", 
            times[itime], MAX_LOOPS, elapsedTime);
    }
    return(0);
}
********************************************

Here are the results on linux-x86:

********************************
corvette:1-2/ADApp/simDetectorSrc>../../bin/linux-x86/testTimer 
epicsThreadSleepQuantum=0.010000
Elapsed time to sleep for 0.000100 seconds 1000 times=0.109260
Elapsed time to sleep for 0.000200 seconds 1000 times=0.209482
Elapsed time to sleep for 0.000500 seconds 1000 times=0.509600
Elapsed time to sleep for 0.001000 seconds 1000 times=1.010766
Elapsed time to sleep for 0.002000 seconds 1000 times=2.010574
Elapsed time to sleep for 0.005000 seconds 1000 times=5.011690
Elapsed time to sleep for 0.010000 seconds 1000 times=10.012555
Elapsed time to sleep for 0.020000 seconds 1000 times=20.014360
*******************************

Note that epicsThreadSleepQuantum is 10 milliseconds.  However, this is
NOT the actual "minimum slumber interval obtainable" with
epicsThreadSleep.  We are able to sleep for 100 microseconds quite
accurately with epicsThreadSleep().

Here are the results for win32-x86:

************************************
$ ../../bin/win32-x86/testTimer.exe
epicsThreadSleepQuantum=0.015625
Elapsed time to sleep for 0.000100 seconds 1000 times=1.953120
Elapsed time to sleep for 0.000200 seconds 1000 times=1.956814
Elapsed time to sleep for 0.000500 seconds 1000 times=1.964528
Elapsed time to sleep for 0.001000 seconds 1000 times=1.961861
Elapsed time to sleep for 0.002000 seconds 1000 times=2.931468
Elapsed time to sleep for 0.005000 seconds 1000 times=5.860293
Elapsed time to sleep for 0.010000 seconds 1000 times=10.748225
Elapsed time to sleep for 0.020000 seconds 1000 times=20.517168
***********************************

Note that epicsThreadSleepQuantum is 15.6 milliseconds.  However, again
this is NOT the actual "minimum slumber interval obtainable" with
epicsThreadSleep.  We are able to sleep for about 1 millisecond with
epicsThreadSleep().  Requests for intervals of 1 millisecond or less
result in the same time.

These tests were done under EPICS 3.14.8.2.  I have not yet installed a
more recent version, so I can't be sure if this behavior has changed.
However, I don't see anything in the release notes for 3.14.9 or 3.14.10
about epicsThreadSleep.

This is rather important, because I know there are EPICS applications
that assume that epicsThreadSleepQuantum is truly the minimum time it
makes sense to request a sleep interval for.  This is clearly not the
case on Windows and Linux, so perhaps epicsThreadSleepQuantum needs to
be rewritten for those platforms.

Mark






Replies:
Re: epicsThreadSleep() and epicsThreadSleepQuantum() Eric Norum
RE: epicsThreadSleep() and epicsThreadSleepQuantum() Jeff Hill
Re: epicsThreadSleep() and epicsThreadSleepQuantum() Andrew Johnson

Navigate by Date:
Prev: Re: SEQ tools Andrew Johnson
Next: Re: epicsThreadSleep() and epicsThreadSleepQuantum() Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: EDM font sizes Kevin Anderson
Next: Re: epicsThreadSleep() and epicsThreadSleepQuantum() Eric Norum
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·