EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  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  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: scan periods
From: Andrew Johnson <[email protected]>
To: john sinclair <[email protected]>
Cc: tech talk <[email protected]>
Date: Wed, 05 Apr 2006 13:51:47 -0500
john sinclair wrote:
After adding two additional scans: 0.01 and 0.005, it seems to me that the EPICS scan loops use delays instead of timers. Is this true? If so, can this be changed easily? If so ...

The code that runs in the periodic scan tasks is in src/db/dbScan.c:


static void periodicTask(void *arg)
{
    scan_list *psl = (scan_list *)arg;

    epicsTimeStamp	start_time,end_time;
    double	diff;
    double	delay;

    taskwdInsert(epicsThreadGetIdSelf(), NULL, NULL);
    epicsTimeGetCurrent(&start_time);
    while(TRUE) {
	if (interruptAccept) scanList(psl);
        epicsTimeGetCurrent(&end_time);
        diff = epicsTimeDiffInSeconds(&end_time, &start_time);
	delay = psl->period - diff;
        delay = (delay <= 0.0) ? .1 : delay;
	epicsThreadSleep(delay);
        epicsTimeGetCurrent(&start_time);
    }
}

Hmm, I suspect that the magic ".1" number in the delay calculation could probably be reduced to something a little smaller nowadays, but the correct value is likely to be processor-specific.

If you have any alternative robust cross-platform suggestions for this code I'd be interested in seeing them. In particular, it must behave sensibly if the scanList() call that processes the records takes longer than a whole scan period to execute - the above delay calculation ensures that the slower scan periods will always get some time to execute even if the faster scans always overrun their periods. This is most important on OSs where threads are scheduled strictly by priority so the slower scans could suffer from CPU starvation.

- Andrew
--
There is no S in exprexxo.

References:
scan periods john sinclair

Navigate by Date:
Prev: scan periods john sinclair
Next: Ethernet/IP Device Support and CompactLogix John Dobbins
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: scan periods john sinclair
Next: Ethernet/IP Device Support and CompactLogix John Dobbins
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  <20062007  2008  2009  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 ·