Exemplo n.º 1
0
static void check_timespec_diff(void)
{
    unsigned long long diff;
    struct timespec start, end;

    timespec_set(start, 1, 30000);

    timespec_set(end, start.tv_sec, start.tv_nsec + 10000);
    timespec_diff(start, end, &diff);

    printf("Checking 10000 == %llu\n", diff);

    if (diff != 10000) {
        printf("Failure!\n");
        exit(FAIL);
    }

    timespec_set(end, start.tv_sec + 5, start.tv_nsec - 5000);
    timespec_diff(start, end, &diff);

    printf("Checking 4999995000 == %llu\n", diff);

    if (diff != 4999995000llu) {
        printf("Failure!\n");
        exit(FAIL);
    }
}
Exemplo n.º 2
0
/* Dump the events to stdout, if verbose is set. */
static void
dump_pass_data (void)
{
  size_t i, j;

  for (i = 0; i < NR_TEST_PASSES; ++i) {
    printf ("pass %zu\n", pass_data[i].pass);
    printf ("    number of events collected %zu\n", pass_data[i].nr_events);
    printf ("    elapsed time %" PRIi64 " ns\n", pass_data[i].elapsed_ns);
    for (j = 0; j < pass_data[i].nr_events; ++j) {
      int64_t ns, diff_ns;
      CLEANUP_FREE char *source_str = NULL;

      ns = timespec_diff (&pass_data[i].start_t, &pass_data[i].events[j].t);
      source_str = source_to_string (pass_data[i].events[j].source);
      printf ("    %.1fms ", ns / 1000000.0);
      if (j > 0) {
	diff_ns = timespec_diff (&pass_data[i].events[j-1].t,
				 &pass_data[i].events[j].t);
	printf ("(+%.1f) ", diff_ns / 1000000.0);
      }
      printf ("[%s] \"", source_str);
      print_escaped_string (pass_data[i].events[j].message);
      printf ("\"\n");
    }
  }

  fflush (stdout);
}
Exemplo n.º 3
0
static void
age_flow_entries_walker( flow_entry *entry, void *user_data ) {
  assert( entry != NULL );
  assert( user_data != NULL );

  struct timespec *now = user_data;
  struct timespec diff = { 0, 0 };

  timespec_diff( entry->created_at, *now, &diff );
  entry->duration_sec = ( uint32_t ) diff.tv_sec;
  entry->duration_nsec = ( uint32_t ) diff.tv_nsec;

  if ( entry->hard_timeout > 0 ) {
    if ( diff.tv_sec >= entry->hard_timeout ) {
      flow_table *table = get_flow_table( entry->table_id );
      delete_flow_entry_from_table( table, entry, OFPRR_HARD_TIMEOUT, true );
      return;
    }
  }

  if ( entry->idle_timeout > 0 ) {
    timespec_diff( entry->last_seen, *now, &diff );
    if ( diff.tv_sec >= entry->idle_timeout ) {
      flow_table *table = get_flow_table( entry->table_id );
      delete_flow_entry_from_table( table, entry, OFPRR_IDLE_TIMEOUT, true );
    }
  }

}
Exemplo n.º 4
0
celix_status_t producer_sendSamples(producer_thread_data_pt th_data, int samplesPerSec)
{
    celix_status_t status = CELIX_SUCCESS;
    struct sample_queue_service* queueService = th_data->service;
    struct sample smpl;
    struct timespec ts_start;
    struct timespec ts_end;
    struct timespec ts_diff;
    int singleSampleCnt = 0;

    clock_gettime(CLOCK_REALTIME, &ts_start);
    timespec_diff(&ts_diff,&ts_start,&ts_start);

    // send single samples per second
    for (ts_end = ts_start; (singleSampleCnt < samplesPerSec) && (ts_diff.tv_sec<=0);) {
        bool ret = false;

        memset(&smpl, 0, sizeof(struct sample));
        producer_fillSample(&smpl);

        if (queueService != NULL) {
            queueService->put(queueService->sampleQueue, smpl, &ret);

            if (ret == true) {
                msg(3, "PRODUCER: Sample {Time:%llu | V1=%f | V2=%f} stored.", smpl.time, smpl.value1,
                    smpl.value2);
                singleSampleCnt++;
            }
            else {
                msg(2, "PRODUCER: Could not store sample.");
            }
        }
        else {
            status = CELIX_BUNDLE_EXCEPTION;
        }

        clock_gettime(CLOCK_REALTIME, &ts_end);
        timespec_diff(&ts_diff,&ts_start,&ts_end);
    }

    /* Update the statistic */
    pthread_rwlock_rdlock(&th_data->throughputLock);
    th_data->single_throughput = singleSampleCnt;
    pthread_rwlock_unlock(&th_data->throughputLock);

    msg(1, "PRODUCER: %d single samples sent.", singleSampleCnt);

    usleep(WAIT_TIME_USECONDS);

    return status;
}
long double
stopwatch_elapsed (struct stopwatch_t* T)
{
    long double dt = 0;
    if (T) {
        if (T->is_running_) {
            struct timespec t_cur;
            get_time (&t_cur);
            dt = timespec_diff (T->t_start_, t_cur);
        } else {
            dt = timespec_diff (T->t_start_, T->t_stop_);
        }
    }
    return dt;
}
Exemplo n.º 6
0
static void grate_profile_dump(struct grate_profile *profile, FILE *fp)
{
	float time = timespec_diff(&profile->start, &profile->end);

	fprintf(fp, "%u frames in %.3f seconds: %.2f fps\n", profile->frames,
		time, profile->frames / time);
}
Exemplo n.º 7
0
void checkTimeout()
{
    time_t t;
    int i;

    t = now();

    /* Check all timeouts that are used and armed, but not passed yet. */
    for (i = 0; i < TIMEOUTS; i++)
    {
        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED))
                == TIMEOUT_USED)
        {
            const time_t seconds = timespec_diff(timeout_list[i].timeout_time,
                    t);

            if (seconds <= 0)
            {
                /* timeout [i] fires! */
                timeout_list[i].timeout_state = TIMEOUT_UNUSED;
                if (timeout_list[i].cb)
                {
                    timeout_list[i].cb();
                }
            }
        }
    }
}
Exemplo n.º 8
0
int  main(void)
{
	long now, then;
	struct timespec ts;

	int clock_type 		= CLOCK_REALTIME;
	int flag 		= TIMER_ABSTIME;
	long long sleeptime	= NSEC_PER_SEC/2;

	clock_gettime(clock_type, &ts);
	now = then = ts.tv_sec;
	while(now - then < 10){
		struct timespec target, diff, rem;
		rem.tv_sec = 0;
		rem.tv_nsec = 0;

		target = timespec_add(ts, sleeptime);

		clock_nanosleep(clock_type, TIMER_ABSTIME, &target, &rem);
		clock_gettime(clock_type, &ts);

		diff = timespec_diff(ts, target);
		printf("diff: %Lf\n", diff.tv_sec + ((long double)0.000000001 * diff.tv_nsec));
		now = ts.tv_sec;
	}

	return 0;
}
Exemplo n.º 9
0
/* Sanity check the collected events. */
static void
check_pass_data (void)
{
  size_t i, j, len;
  int64_t ns;
  const char *message;

  for (i = 0; i < NR_TEST_PASSES; ++i) {
    assert (pass_data[i].pass == i);
    assert (pass_data[i].elapsed_ns > 1000);
    assert (pass_data[i].nr_events > 0);
    assert (pass_data[i].events != NULL);

    for (j = 0; j < pass_data[i].nr_events; ++j) {
      assert (pass_data[i].events[j].t.tv_sec > 0);
      if (j > 0) {
        ns = timespec_diff (&pass_data[i].events[j-1].t,
                            &pass_data[i].events[j].t);
        assert (ns >= 0);
      }
      assert (pass_data[i].events[j].source != 0);
      message = pass_data[i].events[j].message;
      assert (message != NULL);
      assert (pass_data[i].events[j].source != GUESTFS_EVENT_APPLIANCE ||
              strchr (message, '\n') == NULL);
      len = strlen (message);
      assert (len == 0 || message[len-1] != '\r');
    }
  }
}
Exemplo n.º 10
0
static void enqueue_sound(int sound_id)
{
	struct timespec now, elapsed;
	long elapsed_ms;
	long min_interval;

	if (sound_id == NO_SOUND)
		return;

	min_interval = sounds[sound_id].min_interval;

	if (min_interval > 0) {
		clock_gettime(CLOCK_REALTIME, &now);
		elapsed = timespec_diff(&now, &(sounds[sound_id].timestamp));
		elapsed_ms = timespec2ms(&elapsed);

		if (elapsed_ms < min_interval)
			return;
	}

	pthread_mutex_lock(&events.lock);
	if (min_interval > 0)
		sounds[sound_id].timestamp = now;
	events.next = (events.next + 1) % NUM_EVENTS;
	debugmsg("cur = %d, next = %d\n", events.cur, events.next);
	if (events.next == events.cur) {
		events.next--;
		fprintf(stderr, "WARNING: event queue overflow! sound dropped\n");
	} else {
		events.entry[events.next].sound_id = sound_id;
	}
	pthread_cond_signal(&events.events_available);
	pthread_mutex_unlock(&events.lock);

}
Exemplo n.º 11
0
int main(void) {

	int i, j;
	timing_t time1, time2;
	pthread_t threads[THREADS];
	ma = (int *) malloc(2048*1024 * sizeof(int));

	for(i=0;i<(2048*1024); i++){
		ma[i] = i%16+1;
	}


	ESAYdreierzaehler(ma);

	//start counter
	get_time(&time1);
	for(j=0; j<THREADS; j++) {
		pthread_create(&threads[j], NULL, (void*) dreierzaehler, (void*)j);
	}
	for(j=0; j<THREADS ; j++) {
		pthread_join(threads[j], NULL);
	}

	//stop counter time
	get_time(&time2);
	long double difftime = timespec_diff(time1, time2);

	printf("\nZahl der Threads:\t%d", THREADS);
	printf("\nAnzahl der 3en:\t\t%d", cnt);
	printf("\nZeit der Suche:\t\t%Lf\n", difftime);

	return 0;
}
Exemplo n.º 12
0
/**
 * -[acm]{min,time} tests.
 */
bool eval_acmtime(const struct expr *expr, struct eval_state *state) {
	const struct stat *statbuf = fill_statbuf(state);
	if (!statbuf) {
		return false;
	}

	const struct timespec *time;
	switch (expr->timefield) {
	case ATIME:
		time = &statbuf->st_atim;
		break;
	case CTIME:
		time = &statbuf->st_ctim;
		break;
	case MTIME:
		time = &statbuf->st_mtim;
		break;
	}

	time_t diff = timespec_diff(&expr->reftime, time);
	switch (expr->timeunit) {
	case MINUTES:
		diff /= 60;
		break;
	case DAYS:
		diff /= 60*60*24;
		break;
	}

	return do_cmp(expr, diff);
}
Exemplo n.º 13
0
float grate_profile_time_elapsed(struct grate_profile *profile)
{
	struct timespec now;

	clock_gettime(CLOCK_MONOTONIC, &now);

	return timespec_diff(&profile->start, &now);
}
Exemplo n.º 14
0
static uint64_t timespec_diff_us(struct timespec *a, struct timespec *b)
{
	struct timespec res;

	timespec_diff(a, b, &res);

	return res.tv_sec * 1000000ll + res.tv_nsec / 1000ll;
}
Exemplo n.º 15
0
 // Timer
 virtual long TimerCurrentMs() {
     timespec current_time;
     if (clock_gettime(CLOCK_MONOTONIC, &current_time) != 0) {
         MICROFLO_DEBUG(debug, DebugLevelError, DebugIoFailure);
     }
     timespec since_start = timespec_diff(start_time, current_time);
     return (since_start.tv_sec*1000)+(since_start.tv_nsec/1000000);
 }
Exemplo n.º 16
0
/**
 * Called to clean-up after waiting for a thread pool to end the current work.
 * It is only required when  cppadcg_pool_verbose  was enabled.
 *
 * @param thpool
 */
void thpool_cleanup(ThPool* thpool) {
    // for debugging only

    struct timespec diffTime;
    int gid = 0;
    Thread* thread;
    WorkGroup* workGroup;
    WorkGroup* workGroupPrev;

    if (!cppadcg_pool_verbose) {
        return;
    }

    for (int j = 0; j < thpool->num_threads; ++j) {
        thread = thpool->threads[j];

        workGroup = thread->processed_groups;
        while (workGroup != NULL) {
            timespec_diff(&workGroup->endTime, &workGroup->startTime, &diffTime);
            fprintf(stdout, "# Thread %i, Group %i, started at %ld.%.9ld, ended at %ld.%.9ld, elapsed %ld.%.9ld, executed %i jobs\n",
                    thread->id, gid, workGroup->startTime.tv_sec, workGroup->startTime.tv_nsec, workGroup->endTime.tv_sec, workGroup->endTime.tv_nsec, diffTime.tv_sec,
                    diffTime.tv_nsec, workGroup->size);

            for (int i = 0; i < workGroup->size; ++i) {
                Job* job = &workGroup->jobs[i];

                timespec_diff(&job->endTime, &job->startTime, &diffTime);
                fprintf(stdout, "## Thread %i, Group %i, Job %i, started at %ld.%.9ld, ended at %ld.%.9ld, elapsed %ld.%.9ld\n",
                        thread->id, gid, job->id, job->startTime.tv_sec, job->startTime.tv_nsec, job->endTime.tv_sec, job->endTime.tv_nsec, diffTime.tv_sec,
                        diffTime.tv_nsec);
            }

            gid++;

            workGroupPrev = workGroup->prev;

            // clean-up
            free(workGroup->jobs);
            free(workGroup);

            workGroup = workGroupPrev;
        }

        thread->processed_groups = NULL;
    }
}
Exemplo n.º 17
0
sds push_stopwatch(struct timespec *sofar) {
	struct timespec ends;
	time_now(&ends);
	struct timespec diff;
	timespec_diff(sofar, &ends, &diff);
	*sofar = ends;
	sds log = sdscatprintf(sdsempty(), "Step time = %gs.\n", diff.tv_sec + diff.tv_nsec / (double)BILLION);
	return log;
}
Exemplo n.º 18
0
time_t registerTimer(const time_t seconds, int *id, void *cb)
{
    time_t now, then;
    time_t next;
    int i, idx;

    if (0 == thread_id)
    {
        initThread();
    }

    if (seconds <= 0)
        return -1 ;

    // get the current time
    time(&now);

    for (idx = 0; idx < TIMEOUTS; ++idx)
        if (!((timeout_list[idx].timeout_state & TIMEOUT_USED) & TIMEOUT_USED))
            break;

    if (TIMEOUTS == idx) // reach to end of timer list
        return -1;

    // idx th timeout will be used.
    // Reset and set state of the timer
    timeout_list[idx].timeout_state = 0;
    timeout_list[idx].timeout_state |= TIMEOUT_USED;

    // calculate when the timeout should fire
    then = now;
    timespec_add(&then, seconds);

    timeout_list[idx].timeout_time = then;
    timeout_list[idx].timeout_seconds = seconds;

    // printf( "\nbefore timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
    timeout_list[idx].cb = cb;
    // printf( " after timeout_list[idx].cb = %X\n", timeout_list[idx].cb);

    // How long till the next timeout?
    next = seconds;
    for (i = 0; i < TIMEOUTS; i++)
    {
        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED)) == TIMEOUT_USED)
        {
            const time_t secs = timespec_diff(timeout_list[i].timeout_time, now);

            if (secs >= 0 && secs < next)
                next = secs;
        }
    }

    *id = idx;
    /* Return the timeout number. */
    return timeout_list[idx].timeout_time;
}
Exemplo n.º 19
0
void print_time(void)
{
        static struct timespec last;
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC, &ts);
        fprintf(stderr, "TIME %9ld %9ld\n",
                timespec_diff(&ts, &last), (long)ts.tv_nsec);
        last = ts;
}
Exemplo n.º 20
0
struct timespec
get_device_uptime( ether_device *device ) {
    assert( device != NULL );

    struct timespec now = { 0, 0 };
    time_now( &now );
    struct timespec diff = { 0, 0 };
    timespec_diff( device->created_at, now, &diff );

    return diff;
}
Exemplo n.º 21
0
struct timespec
Yardstick::end()
{
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_end);
    running = false;
    
    struct timespec elapsed = timespec_diff(ts_start, ts_end);
    time_trials.push_back(elapsed);

    return elapsed;
}
Exemplo n.º 22
0
int test_treesort(const intmax_t *orig_array, size_t size, bool print, struct timespec *diff) {
	struct tree *t;
	struct timespec start, end;
	get_clock(&start);
	treesort(orig_array, size, &t);
	get_clock(&end);
       	timespec_diff(start, end, diff);
	if (print) {
		print_tree(stdout, t);
	}
       	tree_free(t);
	return 0;
}
Exemplo n.º 23
0
Arquivo: util.c Projeto: xiph/flac
double
benchmark_function (void (*testfunc) (void), unsigned count)
{	struct timespec start, end;
	unsigned k ;

	clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start) ;

	for (k = 0 ; k < count ; k++)
		testfunc () ;

	clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &end) ;

	return timespec_diff (&start, &end) / count ;
} /* benchmark_function */
Exemplo n.º 24
0
static void universal5420_power_hint(struct power_module *module, power_hint_t hint,
                       void *data) {
    struct universal5420_power_module *universal5420 = (struct universal5420_power_module *) module;
    struct timespec now, diff;
    char buf[80];
    int len;
    switch (hint) {
    case POWER_HINT_INTERACTION:
        if (boostpulse_open(universal5420) >= 0) {
            pthread_mutex_lock(&universal5420->lock);
            len = write(universal5420->boostpulse_fd, "1", 1);

            if (len < 0) {
                strerror_r(errno, buf, sizeof(buf));
                ALOGE("Error writing to %s: %s\n", BOOSTPULSE_PATH, buf);
            } else {
                clock_gettime(CLOCK_MONOTONIC, &last_touch_boost);
                touch_boost = true;
            }
            pthread_mutex_unlock(&universal5420->lock);
        }

        break;

    case POWER_HINT_VSYNC:
        pthread_mutex_lock(&universal5420->lock);
        if (data) {
            if (vsync_count < UINT_MAX)
                vsync_count++;
        } else {
            if (vsync_count)
                vsync_count--;
            if (vsync_count == 0 && touch_boost) {
                touch_boost = false;
                clock_gettime(CLOCK_MONOTONIC, &now);
                diff = timespec_diff(now, last_touch_boost);
                if (check_boostpulse_on(diff)) {
                    sysfs_write(BOOST_PATH, "0");
                }
            }
        }
        pthread_mutex_unlock(&universal5420->lock);
        break;

    default:
        break;
    }
}
Exemplo n.º 25
0
static
int time_to_sync(const struct timespec *now)
{
    int res;

    if (now == NULL)
    {
        res = 1; /* assuming TIMESPEC_ZERO */
    }
    else
    {
        res = (timespec_diff(now, &next_sync, NULL) >= 0)?1:0;
    }

    return res;
}
Exemplo n.º 26
0
int test_quicksort(const intmax_t *orig_array, size_t size, intptr_t (*choose_pivot)(const intmax_t *array, intptr_t begin, intptr_t end), bool print, struct timespec *diff)
{
	intmax_t *array = NULL;
	struct timespec start, end;
	dup_array(orig_array, size, &array);
	get_clock(&start);
	quicksort(array, 0, size-1, choose_pivot);
	get_clock(&end);
       	timespec_diff(start, end, diff);
	if (print) {
		print_array(stdout, array, size);
	}
	if (array) {
		free(array);
	}
	return 0;
}
Exemplo n.º 27
0
int test_insertion_sort(const intmax_t *orig_array, size_t size, bool print, struct timespec *diff)
{
	intmax_t *array = NULL;
	struct timespec start, end;
	dup_array(orig_array, size, &array);
	get_clock(&start);
	insertion_sort(array, size);
	get_clock(&end);
	timespec_diff(start, end, diff);
	if (print) {
		print_array(stdout, array, size);
	}
	if (array) {
		free(array);
	}
	return 0;
}
Exemplo n.º 28
0
void ESAYdreierzaehler(int *ma){
	int i;
	timing_t timeESAY2, timeESAY1;

	get_time(&timeESAY1);
	for(i=0; i<2097152; i++){
		if(ma[i] == 3)
			cnt++;
	}

	get_time(&timeESAY2);
	long double difftimeESAY = timespec_diff(timeESAY1, timeESAY2);

	printf("\nZahl der Threads:\t1");
	printf("\nAnzahl der 3en:\t\t%d", cnt);
	printf("\nZeit der Suche:\t\t%Lf\n", difftimeESAY);
}
Exemplo n.º 29
0
void driver ( int nx, int ny, int nz, long int it_max, double tol,
              double xlo, double ylo, double zlo,
              double xhi, double yhi, double zhi, int io_interval){
    double *f, *u;
    char * rb;
    int i,j,k;
    double secs = -1.0;
    struct timespec start, finish;

    /* Allocate and initialize  */
    f = ( double * ) malloc ( nx * ny * nz * sizeof ( double ) );  
    u = ( double * ) malloc ( nx * ny * nz * sizeof ( double ) );
    rb = ( char * ) malloc (nx * ny * nz * sizeof ( char ) );

    get_time( &start );
    omp_set_num_threads(6);
    #pragma omp parallel for default(none)\
    	shared(nx, ny, nz, u) private(i, j, k) 
    for ( k = 0; k < nz; k++ ) 
      for ( j = 0; j < ny; j++ ) 
        for ( i = 0; i < nx; i++ ) 
          U(i,j,k) = 0.0;  /* note use of array indexing macro */

    /* set rhs, and exact bcs in u */
    init_prob ( nx, ny, nz, f, u , xlo, ylo, zlo, xhi, yhi, zhi);
    // rb has the red and black positions
    rb_vector(rb, nx, ny, nz);
    /* Solve the Poisson equation  */
    //jacobi ( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval );
    //gauss_seidel ( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval, rb );

    SOR( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval , rb);
    /* Determine the error  */
    calc_error ( nx, ny, nz, u, f, xlo, ylo, zlo, xhi, yhi, zhi );

    /* get time for initialization and iteration.  */
    get_time(&finish);
    secs = timespec_diff(start,finish);
    printf(" Total time: %15.7e seconds\n",secs);

    free ( u );
    free ( f );
    free (rb);
    return;
}
Exemplo n.º 30
0
void output_partial_results(void)
{
    struct timespec end_sys_clock;
    struct timespec total_time;
    double elapsed_time;
    char str[32];

    clock_gettime(CLOCK_MONOTONIC, &end_sys_clock);
    total_time = timespec_diff(start_sys_clock, end_sys_clock);

    elapsed_time = (double)total_time.tv_sec + (double)(total_time.tv_nsec)/1000000000 ;
 
    printf("Total Time      : %f\n",elapsed_time);
    
    sprintf(str, "%f;", elapsed_time);
    fwrite(str, strlen(str), 1, g_fp);

    clock_gettime(CLOCK_MONOTONIC, &start_sys_clock);
}