Пример #1
0
 /**
  * @brief elapsed Get the elapsed time
  * @return Elapsed time in seconds using clock_diff()
  */
 inline double elapsed() const
 {
     if (mode == 1 && allow_continuous)
     {
         timespec t_temp;
         clock_gettime(CLOCK_MONOTONIC, &t_temp);
         return clock_diff(t_start, t_temp);
     }
     else
     {
         assert(mode == 2);
         return clock_diff(t_start, t_end);
     }
 }
Пример #2
0
void Task::checkTask() {
    uint16_t clock = read_slowclock();
    if (clock_diff(lastExecution, clock) > interval || starting) {
      run();
      lastExecution = clock;
      starting = false;
    }
}
Пример #3
0
void CanPump::_wait_on_next_frames(const timespec_t &timeout)
{
    timespec_t current_time;
    clock_gettime(CLOCK_MONOTONIC, &current_time);
    timespec_t relative_timeout;
    while(clock_diff(timeout, current_time) > 0)
    {
        zero_clock(relative_timeout);
        increment_clock(relative_timeout, clock_diff(timeout, current_time));
        bool okay = _wait_on_frame(relative_timeout);
        if(!okay)
        {
            break;
        }
        
        clock_gettime(CLOCK_MONOTONIC, &current_time);
    }
}
Пример #4
0
void ButtonsClass::poll(uint8_t but) {
  uint8_t but_tmp = but;

  for (uint8_t i = 0; i < GUI_NUM_BUTTONS; i++) {
    STORE_B_CURRENT(i, IS_BIT_SET8(but_tmp, 0));

    if (BUTTON_PRESSED(i)) {
      B_PRESS_TIME(i) =  slowclock;
      
      if (B_PRESSED_ONCE(i)) {
	uint16_t diff = clock_diff(B_LAST_PRESS_TIME(i), B_PRESS_TIME(i));
	if (diff < DOUBLE_CLICK_TIME) {
	  SET_B_DOUBLE_CLICK(i);
	  CLEAR_B_PRESSED_ONCE(i);
	}
      } else {
	B_LAST_PRESS_TIME(i) = B_PRESS_TIME(i);
	SET_B_PRESSED_ONCE(i);
      }
    }
    
    if (BUTTON_DOWN(i) && B_PRESSED_ONCE(i)) {
      uint16_t diff = clock_diff(B_LAST_PRESS_TIME(i), slowclock);
      if (diff > LONG_CLICK_TIME) {
	SET_B_LONG_CLICK(i);
	CLEAR_B_PRESSED_ONCE(i);
      }
    }

    if (BUTTON_UP(i) && B_PRESSED_ONCE(i)) {
      uint16_t diff = clock_diff(B_LAST_PRESS_TIME(i), slowclock);
      if (diff > LONG_CLICK_TIME) {
	CLEAR_B_PRESSED_ONCE(i);
      } else if (diff > DOUBLE_CLICK_TIME) {
	CLEAR_B_PRESSED_ONCE(i);
	SET_B_CLICK(i);
      }
    }

    but_tmp >>= 1;
  }
}
Пример #5
0
long long Benchmark::timing (unsigned repetitions, bool (Benchmark::*proc)())
{
    timespec clock_before, clock_after;
    long long elapsed;
    // measure the loaded time
    if (clock_gettime (CLOCK_MONOTONIC, &clock_before) != 0)
        throw std::runtime_error (clockerr);
    for (unsigned itr = 0; itr != repetitions; ++itr)
        if (!(this->*proc) ())
            return -1;
    if (clock_gettime (CLOCK_MONOTONIC, &clock_after) != 0)
        throw std::runtime_error (clockerr);
    elapsed = clock_diff (clock_after, clock_before);
    return std::max (elapsed, (long long) 0);
}
Пример #6
0
static int __noinstrument ilatcurve_read_proc(
	char *page_buffer,
	char **my_first_byte,
	off_t virtual_start,
	int length,
	int *eof,
	void *data)
{
	int my_buffer_offset = 0;
	char * const my_base = page_buffer;
	int i;
	if (virtual_start == 0) {
		/* 
		 * Just been opened so display the header information 
		 * also stop logging  BUGBUG: stop logging while we are 
		 * reading, initialize the index numbers in the log array
		 */
		unsigned int usecs;
		g_read_completed = 0;

		usecs = clock_to_usecs(clock_diff(ilatency_start, ilatency_stop));;

		my_buffer_offset += sprintf(my_base+my_buffer_offset,
		    "#%lu samples logged\n#timer measured %u ticks per usec.\n"
		    "#interrupt overhead %u microseconds\n"
		    "#maximum interrupt off time %u microseconds\n"
		    "#usecs  samples\n", total_ilat_samples, 
		    (unsigned)ticks_per_usec, usecs, maximum_off);
	} else if (g_read_completed == BUCKETS) {
		 *eof = 1;
		 /* BUGBUG: start logging again */
		 return 0;
	}

	/* dump the sample log on the screen */
	for (i = 0; i < (BUCKETS-1); i++) {
		my_buffer_offset += sprintf(my_base + my_buffer_offset,
		    "%5u\t%8lu\n", (i + 1) * BUCKET_SIZE, bucketlog[i]);
		g_read_completed++;
	}
	my_buffer_offset += sprintf(my_base + my_buffer_offset,
	    "%5u\t%8lu(greater than this time)\n", i * BUCKET_SIZE,
	    bucketlog[LAST_BUCKET]);
	g_read_completed++;

	*my_first_byte = page_buffer;
	return  my_buffer_offset;
}
Пример #7
0
uint8_t MNMClass::getBlockingStatus(uint8_t type, uint16_t timeout) {
  uint16_t start_clock = read_slowclock();
  uint16_t current_clock = start_clock;;
  BlockCurrentStatusCallback cb(type);

  MNMSysexListener.addOnStatusResponseCallback
    (&cb, (mnm_status_callback_ptr_t)&BlockCurrentStatusCallback::onStatusResponseCallback);
  MNM.sendRequest(MNM_STATUS_REQUEST_ID, type);
  do {
    current_clock = read_slowclock();
    handleIncomingMidi();
  } while ((clock_diff(start_clock, current_clock) < timeout) && !cb.received);
  MNMSysexListener.removeOnStatusResponseCallback(&cb);

  return cb.value;
}
Пример #8
0
unsigned Benchmark::calibrate (bool (Benchmark::*proc) (), unsigned long long duration) // returns 0 on error, number of repetitions running in 'duration' ms on success
{
    unsigned long long repetitions = 1, iter;
    long long elapsed;
    timespec clock0, clock1;
    for (;;)
    {
        if (clock_gettime (CLOCK_MONOTONIC, &clock0) != 0)
            throw std::runtime_error (clockerr);
        for (iter = 0; iter != repetitions; ++iter)
            if (!(this->*proc) ()) 
                return 0;
        if (clock_gettime (CLOCK_MONOTONIC, &clock1) != 0)
            throw std::runtime_error (clockerr);
        elapsed = clock_diff (clock1, clock0);
#ifdef CALIBR_DBG
        std::cerr << "\r  Calibrated for " << repetitions << " in " <<  elapsed << " usec" << std::endl;
#endif
        if (elapsed <= 0)
            repetitions *= duration;
        else if ((unsigned) elapsed * 2 <= duration) // duration/elapsed >= 2, so that multiplication makes sense
        {
            repetitions *= duration;
            repetitions /= elapsed;
        }
        else if ((unsigned) elapsed < duration)
        {
            repetitions += repetitions - elapsed * repetitions / duration;
        }
        else if (repetitions > 2 && (unsigned) elapsed >= duration * 2)
        {
            repetitions *= duration;
            repetitions /= elapsed;
        }
        else
            break;
    }
#ifdef CALIBR_DBG
        o_ << "Calibration result is " << repetitions << " in " << elapsed  << " usec (requested duration " << duration << " usec)" << std::endl;
#endif
    return (unsigned) repetitions;
}
Пример #9
0
static void eps_dd_intersect(node * onode, node * inode,
           ddnature oitype, ddnature iotype)
{
#if defined newTimeTrials
    unsigned int count = 0;
    long epstime;
#endif


#if defined compareOmegaEpsilon
    resetAtomCount();
#endif

 /* nest level of loop around onode, inode, both nodes, max nest */
 unsigned int onest, inest, bnest, mnest;
         
dd_get_nests( onode, inode, &onest, &inest, &bnest );
dd_fix_nests( onode, inode, onest, inest, bnest );

/* mnest is the maximum nest with which we have to deal */
mnest = inest>onest?inest:onest;
    
if( bnest > maxCommonNest || mnest > maxnest ){
        fprintf( stderr, "*** too many nested loops ***\n" );
        Exit(2);
}
#if defined newTimeTrials
    timing1reset();
    storeResult = 1;
#endif

#if defined compareOmegaEpsilon
    if (petit_args.DDalgorithm == DDalg_epsilon)
      storeInf = 1;
#endif

dd_eps_test(onode,inode, oitype, iotype, onest, inest, bnest);

#if defined compareOmegaEpsilon

 /* if we're not checking the top level, don't print stats for it */
 if (bnest != 0 || !petit_args.omitTopLevel)
   {
   n_atom_output(DDalg_epsilon,  onode, inode);
   if (petit_args.DDalgorithm == DDalg_epsilon)
      class_inf_output(onode,inode);
 }
#endif

/* measure time */
#if defined(newTimeTrials) && ! defined(OMIT_GETRUSAGE)
  storeResult = 0;

#if defined compareOmegaEpsilon
  storeInf = 0;
#endif

 /* if we're not checking the top level, don't print stats for it */
 if (bnest == 0 && petit_args.omitTopLevel)
   return;



  start_clock();
  do {
	dd_eps_test(onode, inode, oitype, iotype, onest, inest, bnest);
	count++;
  } while (count<timeMaxReps &&
	     (count<timeMinReps || clock_diff()<timePeriod));
  epstime = clock_diff();
  eps_time_output(oitype, onode,inode, count,epstime);
#endif

} /* eps_dd_intersect */
Пример #10
0
/**
 * @brief Main function of the demonstration program
 * 
 * Call as ./demo [nvar n ncomp nobs noise]
 *
 * @param[in] argc The Number of input arguments
 * @param[in] argv The array of string argument(s)
 * @return 0 upon success and a number different than 0 otherwise
 */
int main(const int argc, const char **argv) {
  // Get program input parameter
  const unsigned long nvar = (argc > 1) ? strtoul(argv[1],NULL,10) : DEFAULT_NVAR;
  const unsigned long n = (argc > 2) ? strtoul(argv[2],NULL,10) : DEFAULT_N;
  const unsigned long ncomp = (argc > 3) ? strtoul(argv[3],NULL,10) : DEFAULT_NCOMP;
  const unsigned long nobs = (argc > 4) ? strtoul(argv[4],NULL,10) : DEFAULT_NOBS;
  const double noise = (argc > 5) ? strtod(argv[5],NULL) : DEFAULT_NOISE;
  double *T = NULL; // Pointer to templates
  double *s = NULL; // Pointer to the current observation
  double *w = NULL; // Pointer to the weights
  double *corr = NULL; // Pointer to the weighted cross correlation function
  double *L = NULL; // Pointer to the lookup table
  clock_t t0, t1; // Clock times
  double tqr,tneq; // Execution times respectively for the QRL algorithm and for the normal equation
  unsigned long shift, shiftqr, shiftneq; // Real shift and shift found by the two algorithms
  unsigned long i;
  
  // Allocate arrays
  T = (double *) calloc(nvar*ncomp,sizeof(double));
  s = (double *) calloc(n,sizeof(double));
  w = (double *) calloc(n,sizeof(double));
  corr = (double *) calloc(nvar,sizeof(double));
  L = wcorr_lookup_alloc(nvar, ncomp);
  
  // Check that all arrays were correctly allocated
  if(T == NULL || s == NULL || w == NULL || corr == NULL || L == NULL) {
    free(T);free(s);free(w);free(corr);free(L);
    fprintf(stderr, "An error occurs during array allocation\n");
    return -1;
  }
  
  // Init the random number generator
  srand(1);
  
  // Build mock templates
  build_mock_templates(T, nvar, ncomp);
  
  // Build the initial lookup table associated with T
  wcorr_lookup(L, T, nvar, ncomp);
  
  // Print the usage we made
  fprintf(stderr, "Usage: %s nvar=%lu n=%lu ncomp=%lu nobs=%lu noise=%g\n", argv[0], nvar, n, ncomp, nobs, noise);
  
  // Check if we will run in zero-optimized mode?
  if(nvar - n < ncomp)
    fprintf(stderr, "Running demonstration in classical mode\n");
  else
    fprintf(stderr, "Running demonstration in zero-optimized mode\n");

  // Print header line
  fprintf(stdout, "Observation | Real shift | QRL CPU time | QRL shift | Neq. CPU time | Neq. shift \n");
  
  // Compute weighted phase correlation for each observation
  for(i = 0; i < nobs; i++) {
    // Select a random shift
    shift = rand() % nvar;
    
    // Build a mock observation
    build_mock_observation(s,w,n,T,nvar,ncomp,shift,noise); 
    
    // Compute the weighted phase correlation function through factorized QR algorithm with lookup tables
    t0 = clock();
    wcorr(corr, L, T, nvar, ncomp, w, s, n, 1, 0.);
    t1 = clock();
    
    // Get the found shift
    shiftqr = find_shift(corr, nvar, max);
    
    // Get the CPU execution time
    tqr = clock_diff(t0, t1);
      
    // Compute the weighted phase correlation function through normal equations
    t0 = clock();
    wchi2_normeq(corr, T, nvar, ncomp,  w, s, n, 1);
    t1 = clock();
    
    // Get the found shift
    shiftneq = find_shift(corr, nvar, min);
    
    // Get the CPU execution time
    tneq = clock_diff(t0, t1);
    
    // Print result
    fprintf(stdout, "%11lu | %10lu |  %10.5fs |  %8lu |   %10.5fs | %10lu \n", i, shift, tqr, shiftqr, tneq, shiftneq);
    
    // 
    fflush(stdout);
  }
  
  // Free arrays
  free(T);
  free(s);
  free(w);
  free(corr);
  wcorr_lookup_free(L);
  
  return 0;
}
Пример #11
0
bool CanPump::pump()
{
    if(!_can_initialized)
    {
        std::cout << "WARNING: Attempting to pump the CanPump before the CAN "
                  << "communication has been initialized!" << std::endl;
        return false;
    }
    
    if(_can_error)
        return false;
    
    if(_first_tick)
    {
        if(clock_gettime(CLOCK_MONOTONIC, &_deadline) != 0)
        {
            std::cout << "ERROR: clock_gettime triggered error '"
                      << strerror(errno) << "' (" << errno << ")" << std::endl;
            return false;
        }
        _first_tick = false;
    }
    
    increment_clock(_deadline, _timestep);
    
    timespec_t time;
    clock_gettime(CLOCK_MONOTONIC, &time);
    double diff = clock_diff(_deadline, time);
    
    if(fabs(_timestep-diff) > period_threshold)
    {
        std::cout << "WARNING: CanPump is off schedule by " << _timestep-diff << " seconds" << std::endl;
    }
    
    int expectation = _get_max_frame_expectation();
    if(expectation * can_frame_bit_size > _bitrate * diff)
    {
        std::cout << "WARNING: Expected size of CAN frame transfer (" << expectation*can_frame_bit_size
                  << ") exceeds the bitrate setting (" << _bitrate * diff << ")\n"
                  << " -- This may result in frames being dropped!" << std::endl;

        if( diff < 0 )
        {
            std::cout << "Skipping this cycle" << std::endl;
            return true;
        }
    }

    for(size_t i=0; i<_devices.size(); ++i)
    {
        _devices[i]->update();
    }
    
    if(_get_max_frame_count() > 0)
    {
        double frame_dt = diff/(double)(_get_max_frame_count());
        while(clock_diff(_deadline, time) > 0)
        {
            _send_next_frames();

            if(_can_error)
                return false;

            increment_clock(time, frame_dt);
            _wait_on_next_frames(time);

            if(_can_error)
                return false;
        }
    }
    else
    {
        _wait_on_next_frames(_deadline);
    }
    
    for(size_t i=0; i<_channels.size(); ++i)
    {
        _channels[i].reset_counter();
    }
    
    return true;
}