void Sim::run()
{
    Guard G(lock);
    while(!stop) {
        if(!doSim) {
            UnGuard U(G);
            event.wait();
            continue;
        }

        doSim = false;

        epicsTimeStamp start;
        epicsTimeGetCurrent(&start);

        try {
            std::auto_ptr<StateBase> state(machine->allocState());

            machine->propagate(state.get());

            valid = true;
        }catch(std::exception& e){
            last_msg = e.what();
            valid = false;
        }

        epicsTimeGetCurrent(&last_run);
        last_duration = epicsTimeDiffInSeconds(&last_run, &start);

        scanIoRequest(aftersim);
    }
}
Exemple #2
0
void epicsSpinPerformance ()
{
    static const unsigned N = 10000;
    unsigned i;
    epicsSpinId spin;
    epicsTimeStamp begin;
    epicsTimeStamp end;
    double delay;

    /* Initialize spinlock */
    spin = epicsSpinCreate();
    if (!spin)
        testAbort("epicsSpinCreate() returned NULL");

    /* test a single lock pair */
    epicsTimeGetCurrent(&begin);
    for ( i = 0; i < N; i++ ) {
        tenLockPairsSquared(spin);
    }
    epicsTimeGetCurrent(&end);

    delay = epicsTimeDiffInSeconds(&end, &begin);
    delay /= N * 100u;  /* convert to delay per lock pair */
    delay *= 1e6;       /* convert to micro seconds */
    testDiag("lock()*1/unlock()*1 takes %f microseconds", delay);
    epicsSpinDestroy(spin);
}
Exemple #3
0
static void initAuxmrWait() {
    epicsTimeStamp stime,etime;
    double elapsedTime = 0.0;
    int ntimes = 1;
    static int nloops = 1000000;
    double totalLoops;

    while(elapsedTime<1.0) {
        int i;
        ntimes *= 2;
        epicsTimeGetCurrent(&stime);
        for(i=0; i<ntimes; i++) wasteTime(nloops);
        epicsTimeGetCurrent(&etime);
        elapsedTime = epicsTimeDiffInSeconds(&etime,&stime);
    }
    totalLoops = ((double)ntimes) * ((double)nloops);
    nloopsPerMicrosecond = (totalLoops/elapsedTime)/1e6 + .99;
    if(ni1014Debug) {
        printf("totalLoops %f elapsedTime %f nloopsPerMicrosecond %ld\n",
             totalLoops,elapsedTime,nloopsPerMicrosecond);
        epicsTimeGetCurrent(&stime);
        microSecondDelay(1000000);
        epicsTimeGetCurrent(&etime);
        elapsedTime = epicsTimeDiffInSeconds(&etime,&stime);
        printf("elapsedTime %f\n",elapsedTime);
    }
}
Exemple #4
0
asynStatus drvFastSweep::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int command = pasynUser->reason;
    asynStatus status=asynSuccess;

    /* Set the parameter in the parameter library. */
    status = setIntegerParam(command, value);
    if (command == mcaStartAcquire_) {
        if (!acquiring_) {
            acquiring_ = 1;
            setIntegerParam(mcaAcquiring_, acquiring_);
            epicsTimeGetCurrent(&startTime_);
        }
    }  
    else if (command == mcaStopAcquire_) {
        stopAcquire();
    }
    else if (command == mcaErase_) {
        memset(pData_, 0, maxPoints_ * maxSignals_ * sizeof(int));
        numAcquired_ = 0;
        /* Reset the elapsed time */
        elapsedTime_ = 0;
        setDoubleParam(mcaElapsedRealTime_, elapsedTime_);
        epicsTimeGetCurrent(&startTime_);
    }
    else if (command == mcaNumChannels_) {
        if ((value < 1) || (value > maxPoints_))
            status = asynError;
        else
            numPoints_ = value;
    }
    callParamCallbacks();
    return(status);
}
Exemple #5
0
int main(int argc, char **argv)
{
    int i, j, loop;
    int ignore=0;
    epicsTimeStamp tStart, tEnd;
    int status;

    printf("Initializing ...\n");
    xiaSetLogLevel(2);
    xiaInit("test4.ini");
    xiaStartSystem();
    for (i=0; i<NUM_SCAS; i++) {
        sca_lo[i] = calloc(1, SCA_NAME_LEN);
        sprintf(sca_lo[i], "sca%d_lo", i);
        sca_hi[i] = calloc(1, SCA_NAME_LEN);
        sprintf(sca_hi[i], "sca%d_hi", i);
    }
    for (loop=0; loop<NUM_LOOPS; loop++) {
        printf("Loop = %d/%d\n", loop+1, NUM_LOOPS);
        epicsTimeGetCurrent(&tStart);
        for (i=0; i<NUM_CHANNELS; i++) {
            printf("  channel=%d\n", i);
            for (j=0; j<NUM_SCAS; j++) {
                setSCAs(i);
            }
        }
        status = xiaBoardOperation(0, "apply", &ignore);
        CHECK_STATUS(status);
        epicsTimeGetCurrent(&tEnd);
        printf("Time = %f\n", epicsTimeDiffInSeconds(&tEnd, &tStart));
    } 
    return(0);
}
Exemple #6
0
static double cpuBurn(void)
{
    epicsTimeStamp then, now;
    double         diff;

    /* poll the clock for 500us */
    epicsTimeGetCurrent(&then);
    do {
        epicsTimeGetCurrent(&now);
        diff = epicsTimeDiffInSeconds(&now,&then);
    } while ( diff < 0.0005 );
    return diff;
}
ServerContextImpl::ServerContextImpl():
    _state(NOT_INITIALIZED),
    _beaconAddressList(),
    _ignoreAddressList(),
    _autoBeaconAddressList(true),
    _beaconPeriod(15.0),
    _broadcastPort(PVA_BROADCAST_PORT),
    _serverPort(PVA_SERVER_PORT),
    _receiveBufferSize(MAX_TCP_RECV),
    _timer(),
    _beaconEmitter(),
    _acceptor(),
    _transportRegistry(),
    _channelProviderRegistry(),
    _channelProviderNames(PVACCESS_DEFAULT_PROVIDER),
    _channelProviders(),
    _beaconServerStatusProvider(),
    _startTime()

{
    epicsTimeGetCurrent(&_startTime);

    // TODO maybe there is a better place for this (when there will be some factory)
    epicsSignalInstallSigAlarmIgnore ();
    epicsSignalInstallSigPipeIgnore ();

    generateGUID();
    initializeLogger();
}
static void harnessExit(void *dummy) {
    epicsTimeStamp ended;
    int Faulty;

    if (!Harness) return;

    epicsTimeGetCurrent(&ended);

    printf("\n\n    EPICS Test Harness Results"
             "\n    ==========================\n\n");

    Faulty = ellCount(&faults);
    if (!Faulty)
        printf("All tests successful.\n");
    else {
        int Failures = 0;
        testFailure *f;

        printf("Failing Program           Tests  Faults\n"
               "---------------------------------------\n");
        while ((f = (testFailure *)ellGet(&faults))) {
            Failures += f->failures;
            printf("%-25s %5d   %5d\n", f->name, f->tests, f->failures);
            if (f->skips)
                printf("%d subtests skipped\n", f->skips);
            free(f);
        }
        printf("\nFailed %d/%d test programs. %d/%d subtests failed.\n",
               Faulty, Programs, Failures, Tests);
    }

    printf("Programs=%d, Tests=%d, %.0f wallclock secs\n\n",
           Programs, Tests, epicsTimeDiffInSeconds(&ended, &started));
}
void epicsAssert (const char *pFile, const unsigned line,
    const char *pExp, const char *pAuthorName)
{
    epicsTimeStamp current;

    errlogPrintf("\n\n\n"
        "A call to 'assert(%s)'\n"
        "    by thread '%s' failed in %s line %u.\n",
        pExp, epicsThreadGetNameSelf(), pFile, line);
    errlogPrintf("EPICS Release %s.\n", epicsReleaseVersion);

    if (epicsTimeGetCurrent(&current) == 0) {
        char date[64];

        epicsTimeToStrftime(date, sizeof(date),
            "%Y-%m-%d %H:%M:%S.%f %Z", &current);
        errlogPrintf("Local time is %s\n", date);
    }

    if (!pAuthorName) {
        pAuthorName = "the author";
    }
    errlogPrintf("Please E-mail this message to %s or to [email protected]\n",
        pAuthorName);

    errlogPrintf("Calling epicsThreadSuspendSelf()\n");
    epicsThreadSuspendSelf ();
}
static void myCallback(CALLBACK *pCallback)
{
    myPvt *pmyPvt;
    epicsTimeStamp now;
    double delay, error;

    epicsTimeGetCurrent(&now);
    callbackGetUser(pmyPvt, pCallback);

    if (pmyPvt->pass++ == 0) {
        delay = 0.0;
        error = epicsTimeDiffInSeconds(&now, &pmyPvt->start);
        pmyPvt->start = now;
        callbackRequestDelayed(&pmyPvt->cb2, pmyPvt->delay);
    } else if (pmyPvt->pass == 2) {
        double diff = epicsTimeDiffInSeconds(&now, &pmyPvt->start);
        delay = pmyPvt->delay;
        error = fabs(delay - diff);
    } else {
        testFail("pass = %d for delay = %f", pmyPvt->pass, pmyPvt->delay);
        return;
    }
    testOk(error < 0.05, "delay %f seconds, callback time error %f",
        delay, error);
}
void motorSimController::motorSimTask()
{
  epicsTimeStamp now;
  double delta;
  int axis;
  motorSimAxis *pAxis;

  while ( 1 )
  {
    /* Get a new timestamp */
    epicsTimeGetCurrent( &now );
    delta = epicsTimeDiffInSeconds( &now, &(prevTime_) );
    prevTime_ = now;

    if ( delta > (DELTA/4.0) && delta <= (4.0*DELTA) )
    {
      /* A reasonable time has elapsed, it's not a time step in the clock */
      for (axis=0; axis<numAxes_; axis++) 
      {     
        this->lock();
        pAxis = getAxis(axis);
        pAxis->process(delta );
        this->unlock();
      }
    }
    epicsThreadSleep( DELTA );
  }
}
Exemple #12
0
static void motorProcTask( motorSim_t *pDrv)
{
  epicsTimeStamp now;
  double delta;
  AXIS_HDL pAxis;

  /* Get a new timestamp */
  epicsTimeGetCurrent( &now );
  delta = epicsTimeDiffInSeconds( &now, &(pDrv->now) );
  pDrv->now = now;

  if ( delta > (DELTA/4.0) && delta <= (4.0*DELTA) )
  {
    /* A reasonable time has elapsed, it's not a time step in the clock */

    for (pAxis = pDrv->pFirst; pAxis != NULL; pAxis = pAxis->pNext )
    {
      if (epicsMutexLock( pAxis->axisMutex ) == epicsMutexLockOK)
      {
        motorSimProcess( pAxis, delta );
        motorParam->callCallback( pAxis->params );
        epicsMutexUnlock( pAxis->axisMutex );
      }
    }
  }
}
Exemple #13
0
void drvFastSweep::nextPoint(epicsInt32 *newData)
{
    int i;
    int offset;
    epicsTimeStamp now;

    if (!acquiring_) return;

    offset = numAcquired_;
    for (i = 0; i < maxSignals_; i++) {
        pData_[offset] = newData[i];
        offset += maxPoints_;
    }
    numAcquired_++;
    if (numAcquired_ >= numPoints_) {
       stopAcquire();
    }
    epicsTimeGetCurrent(&now);
    elapsedTime_ = epicsTimeDiffInSeconds(&now, &startTime_);
    if ((realTime_ > 0) && (elapsedTime_ >= realTime_)) {
        stopAcquire();
    }
    setIntegerParam(fastSweepCurrentChannel_, numAcquired_);
    setDoubleParam(mcaElapsedRealTime_, elapsedTime_);
    callParamCallbacks();
}
/* print list of stopped records, and breakpoints set in locksets */
long epicsShareAPI dbstat(void)
{
  struct LS_LIST *pnode;
  struct BP_LIST *pbl;
  struct EP_LIST *pqe;
  epicsTimeStamp time;

  epicsMutexMustLock(bkpt_stack_sem);

  epicsTimeGetCurrent(&time);

 /*
  *  Traverse list, reporting stopped records
  */
  pnode = (struct LS_LIST *) ellFirst(&lset_stack);
  while (pnode != NULL) {
    if (pnode->precord != NULL) {

       printf("LSet: %lu  Stopped at: %-28.28s  #B: %5.5d  T: %p\n",
             pnode->l_num, pnode->precord->name, ellCount(&pnode->bp_list), pnode->taskid);

      /* for each entrypoint detected, print out entrypoint statistics */
       pqe = (struct EP_LIST *) ellFirst(&pnode->ep_queue); 
       while (pqe != NULL) {
          double diff = epicsTimeDiffInSeconds(&time,&pqe->time);
          if (diff) {
             printf("             Entrypoint: %-28.28s  #C: %5.5lu  C/S: %7.1f\n",
                 pqe->entrypoint->name, pqe->count,diff);
          }
          pqe = (struct EP_LIST *) ellNext((ELLNODE *)pqe);
       }
    }
    else {
       printf("LSet: %lu                                            #B: %5.5d  T: %p\n",
         pnode->l_num, ellCount(&pnode->bp_list), pnode->taskid);
    }

   /*
    *  Print out breakpoints set in the lock set
    */
    pbl = (struct BP_LIST *) ellFirst(&pnode->bp_list);
    while (pbl != NULL) {
        printf("             Breakpoint: %-28.28s", pbl->precord->name);

       /* display auto print flag */
        if (pbl->precord->bkpt & BKPT_PRINT_MASK)
           printf(" (ap)\n");
        else
           printf("\n");

        pbl = (struct BP_LIST *) ellNext((ELLNODE *)pbl);
    }

    pnode = (struct LS_LIST *) ellNext((ELLNODE *)pnode);
  }

  epicsMutexUnlock(bkpt_stack_sem);
  return(0);
}
Exemple #15
0
int epicsShareAPI epicsTimeGetEvent(epicsTimeStamp *pDest, int eventNumber)
{
    if (eventNumber == epicsTimeEventCurrentTime) {
        return epicsTimeGetCurrent(pDest);
    } else {
        return generalTimeGetEventPriority(pDest, eventNumber, NULL);
    }
}
Exemple #16
0
/* get date,time as yymmdd-HHMMSS */
int	fGetDateStr( char datetime[])
{ 
	epicsTimeStamp now;

	epicsTimeGetCurrent(&now);
	epicsTimeToStrftime(datetime, 28, "%y%m%d-%H%M%S", &now);
	return(0);
}
Exemple #17
0
static void printTime(void)
{
    epicsTimeStamp ts;

    epicsTimeGetCurrent(&ts);
    printf("%s %s %s %d %d ",
        pvname,pvalue,
        epicsThreadGetNameSelf(),ts.secPastEpoch,ts.nsec/1000000);
}
Exemple #18
0
void
vxStats_busyloop(unsigned busyperc)
{
    epicsTimeStamp then, now;
    double         fac = vxStats_busyloop_period/(double)100.0;

    if ( busyperc > 100 )
        busyperc = 100;

    while ( vxStats_busyloop_run ) {
        epicsTimeGetCurrent(&then);
        do {
            epicsTimeGetCurrent(&now);
        } while ( epicsTimeDiffInSeconds(&now,&then) < (double)busyperc*fac );

        epicsThreadSleep((double)(100-busyperc)*fac);
    }
}
void testHarness(void) {
    epicsThreadOnce(&onceFlag, testOnce, NULL);
    epicsAtExit(harnessExit, NULL);
    Harness = 1;
    Programs = 0;
    Tests = 0;
    ellInit(&faults);
    epicsTimeGetCurrent(&started);
}
Exemple #20
0
epicsTime epicsTime::getCurrent ()
{
    epicsTimeStamp current;
    int status = epicsTimeGetCurrent (&current);
    if (status) {
        throwWithLocation ( unableToFetchCurrentTime () );
    }
    return epicsTime ( current );
}
Exemple #21
0
static void myCallback(CALLBACK *pCallback)
{
    myPvt *pmyPvt;

    callbackGetUser(pmyPvt, pCallback);
    
    pmyPvt->pass++;

    if (pmyPvt->pass == 1) {
        epicsTimeGetCurrent(&pmyPvt->pass1Time);
        callbackRequestDelayed(&pmyPvt->cb2, pmyPvt->delay);
    } else if (pmyPvt->pass == 2) {
        epicsTimeGetCurrent(&pmyPvt->pass2Time);
    } else {
        pmyPvt->resultFail = 1;
        return;
    }
}
Exemple #22
0
int Eiger::waitFile (const char *filename, double timeout)
{
    const char *functionName = "waitFile";

    epicsTimeStamp start, now;

    request_t request;
    char requestBuf[MAX_MESSAGE_SIZE];
    request.data      = requestBuf;
    request.dataLen   = sizeof(requestBuf);
    request.actualLen = epicsSnprintf(request.data, request.dataLen,
            REQUEST_HEAD, sysStr[SSData], filename);

    response_t response;
    char responseBuf[MAX_MESSAGE_SIZE];
    response.data    = responseBuf;
    response.dataLen = sizeof(responseBuf);

    epicsTimeGetCurrent(&start);

    do
    {
        if(doRequest(&request, &response))
        {
            ERR_ARGS("[file=%s] HEAD request failed", filename);
            return EXIT_FAILURE;
        }

        if(response.code == 200)
            return EXIT_SUCCESS;

        if(response.code != 404)
        {
            ERR_ARGS("[file=%s] server returned error code %d", filename,
                    response.code);
            return EXIT_FAILURE;
        }

        epicsTimeGetCurrent(&now);
    }while(epicsTimeDiffInSeconds(&now, &start) < timeout);

    //ERR_ARGS("timeout waiting for file %s", filename);
    return EXIT_FAILURE;
}
Exemple #23
0
/********* ai record **********/
static int getCurrentTime(double * pseconds)
{
    epicsTimeStamp ts;

    if (epicsTimeERROR != epicsTimeGetCurrent(&ts)) {
        *pseconds = ts.secPastEpoch + ((double)(ts.nsec)) * 1e-9;
        return 0;
    }
    return -1;
}
Exemple #24
0
int devIocStatsInitCpuUsage(void)
{
    int    nBurnNoContention = 0;
    double tToWait = SECONDS_TO_BURN;
    epicsTimeStamp tStart, tEnd;
    
    if (cpuUsage.startSem) return 0;
    /* Initialize only if OS wants to spin */
    if (tToWait > 0) {
        /*wait for a tick*/
        epicsTimeGetCurrent(&tStart);
        do {
            epicsTimeGetCurrent(&tEnd);
        } while ( epicsTimeDiffInSeconds(&tEnd, &tStart) <= 0.0 );
        epicsTimeGetCurrent(&tStart);
        while(TRUE)
        {
            cpuBurn();
            epicsTimeGetCurrent(&tEnd);
            cpuUsage.tNow = epicsTimeDiffInSeconds(&tEnd, &tStart);
            if (cpuUsage.tNow >= tToWait ) break;
            nBurnNoContention++;
        }
        cpuUsage.nBurnNoContention = nBurnNoContention;
        cpuUsage.nBurnNow          = nBurnNoContention;
        cpuUsage.startSem = epicsEventMustCreate(epicsEventFull);
        cpuUsage.tNoContention = cpuUsage.tNow;
  /*
        * FIXME: epicsThreadPriorityMin is not really the lowest
        *        priority. We could use a native call to
        *        lower our priority further but OTOH there is not
        *        much going on at these low levels...
  */
        epicsThreadCreate("cpuUsageTask",
                          epicsThreadPriorityMin,
                          epicsThreadGetStackSize(epicsThreadStackMedium),
                                  (EPICSTHREADFUNC)cpuUsageTask,
                                   0);
    } else {
        cpuUsage.startSem = 0;
    }
    return 0;
}
Exemple #25
0
static void cpuUsageTask(void *parm)
{
    while(TRUE)
    {
        int	 i;
        epicsTimeStamp tStart, tEnd;

        epicsEventWait(cpuUsage.startSem);
        cpuUsage.nBurnNow=0;
        epicsTimeGetCurrent(&tStart);
        for(i=0; i< cpuUsage.nBurnNoContention; i++)
        {
            cpuBurn();
            epicsTimeGetCurrent(&tEnd);
            cpuUsage.tNow = epicsTimeDiffInSeconds(&tEnd, &tStart);
            ++cpuUsage.nBurnNow;
        }
        cpuUsage.didNotComplete = FALSE;
    }
}
Exemple #26
0
/*
 * clean_addrq
 */
static void clean_addrq(void)
{
    struct channel_in_use * pciu;
    struct channel_in_use * pnextciu;
    epicsTimeStamp current;
    double delay;
    double maxdelay = 0;
    unsigned ndelete=0;
    double timeout = TIMEOUT;
    int s;

    epicsTimeGetCurrent ( &current );

    epicsMutexMustLock ( prsrv_cast_client->chanListLock );
    pnextciu = (struct channel_in_use *) 
            prsrv_cast_client->chanList.node.next;

    while( (pciu = pnextciu) ) {
        pnextciu = (struct channel_in_use *)pciu->node.next;

        delay = epicsTimeDiffInSeconds(&current,&pciu->time_at_creation);
        if (delay > timeout) {

            ellDelete(&prsrv_cast_client->chanList, &pciu->node);
            LOCK_CLIENTQ;
            s = bucketRemoveItemUnsignedId (
                pCaBucket,
                &pciu->sid);
            if(s){
                errMessage (s, "Bad id at close");
            }
            else {
                rsrvChannelCount--;
            }
            UNLOCK_CLIENTQ;
            if ( ! s ) {
                freeListFree(rsrvChanFreeList, pciu);
                ndelete++;
            }
            if(delay>maxdelay) maxdelay = delay;
        }
    }
    epicsMutexUnlock ( prsrv_cast_client->chanListLock );

#   ifdef DEBUG
    if(ndelete){
        epicsPrintf ("CAS: %d CA channels have expired after %f sec\n",
            ndelete, maxdelay);
    }
#   endif

}
Exemple #27
0
static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
    epicsTimeStamp now;
    epicsTimeGetCurrent(&now);

    /* If string or array, must make a copy (to ensure coherence between time and data) */
    if (pfl->type == dbfl_type_rec) {
        dbScanLock(dbChannelRecord(chan));
        dbChannelMakeArrayCopy(pvt, pfl, chan);
        dbScanUnlock(dbChannelRecord(chan));
    }

    pfl->time = now;
    return pfl;
}
Exemple #28
0
int Eiger::trigger (int timeout, double exposure)
{
    // Trigger for INTS mode
    if(!exposure)
        return put(SSCommand, "trigger", "", 0, NULL, timeout);

    // Tigger for INTE mode
    // putDouble should block for the whole exposure duration, but it doesn't
    // (Eiger's fault)

    epicsTimeStamp start, end;

    epicsTimeGetCurrent(&start);
    if(putDouble(SSCommand, "trigger", exposure, NULL, timeout))
        return EXIT_FAILURE;
    epicsTimeGetCurrent(&end);

    double diff = epicsTimeDiffInSeconds(&end, &start);
    if(diff < exposure)
        epicsThreadSleep(exposure - diff);

    return EXIT_SUCCESS;
}
Exemple #29
0
/*
 * Return channel time stamp.
 */
epicsShareFunc epicsTimeStamp seq_pvTimeStamp(SS_ID ss, CH_ID chId)
{
	CHAN	*ch = ss->prog->chan + chId;
	PVMETA	*meta = metaPtr(ch,ss);
	if (ch->dbch)
	{
		return meta->timeStamp;
	}
	else
	{
		epicsTimeStamp ts;
		epicsTimeGetCurrent(&ts);
		return ts;
	}
}
Exemple #30
0
asynStatus mar345::waitForCompletion(const char *doneString, double timeout)
{
    char response[MAX_MESSAGE_SIZE];
    asynStatus status;
    double elapsedTime;
    epicsTimeStamp start, now;
    const char *functionName = "waitForCompletion";
 
    epicsTimeGetCurrent(&start);
    while (1) {
        status = readServer(response, sizeof(response), MAR345_POLL_DELAY);
        if (status == asynSuccess) {
            if (strstr(response, doneString)) return(asynSuccess);
        }
        epicsTimeGetCurrent(&now);
        elapsedTime = epicsTimeDiffInSeconds(&now, &start);
        if (elapsedTime > timeout) {
            asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s: error waiting for response from marServer\n",
                driverName, functionName);
            return(asynError);
        }
    }
}