Ejemplo n.º 1
0
// by Ged, 4-1-2004
int inactive_duration(int thresh) 
{
    double value;
    start_counter();
    while(value = get_counter())
      if(value > thresh) return (int) value;
      else start_counter(); //resets counter, so we check between reads 
}
Ejemplo n.º 2
0
/* while sleeping for sleeptime seconds */
double mhz(int verbose, int sleeptime)
{
    double rate;

    start_counter();
    sleep(sleeptime);
    rate = get_counter() / (1e6*sleeptime);
    if (verbose)
        printf("Processor clock rate ?= %.1f MHz\n", rate);
    start_counter();
   printf("delay is %.1f. ", get_counter());
    return rate;
}
Ejemplo n.º 3
0
void run(int len, int trials, unsigned seed) {
    double t1, t2;
    int t;
    for (t = 0; t < trials; t++) {
	init(seed);
	start_counter();
	minmax1(a1, b1, len);
	t1 = get_counter();
	start_counter();
	minmax2(a2, b2, len);
	t2 = get_counter();
	printf("%d\t%.2f\t%.2f\n", len, t1/len, t2/len);
    }
}
Ejemplo n.º 4
0
int main()
{
    setter();
    saver();
    clearer();
    start_counter();
    loader();
    stop_counter();
    dumper();
    clearer();
    start_counter();
    loader_mem();
    stop_counter();
    dumper();
}
Ejemplo n.º 5
0
    void operator() (const char * event,
                     T func,
                     long int bytes_read = 0,
                     long int ops = 0,
                     long int bytes_written = 0) {
#ifdef CYCLE_PROFILING
        if (currentevent==maxevents) {
            func();
        } else {
            const auto countfd = thread_counter_fds.get_counter_fd();
            start_counter(countfd);
            func();
            long long cycs = stop_counter(countfd);

            // Store the profiling data
            std::lock_guard<std::mutex> lock_events(event_lock);
            events[currentevent++] = {
              get_event_id(event), bytes_read, ops, bytes_written, cycs
            };
        }
#else
      (void) event;
      (void) bytes_read;
      (void) ops;
      (void) bytes_written;
      func();
#endif  // CYCLE_PROFILING
    }
Ejemplo n.º 6
0
/* Attempt to see how much time is used by timer interrupt */
static void callibrate(int verbose)
{
  double oldt;
  struct tms t;
  clock_t oldc;
  int e = 0;
  times(&t);
  oldc = t.tms_utime;
  start_counter();
  oldt = get_counter();
  while (e <NEVENT) {
    double newt = get_counter();
    if (newt-oldt >= THRESHOLD) {
      clock_t newc;
      times(&t);
      newc = t.tms_utime;
      if (newc > oldc) {
	double cpt = (newt-oldt)/(newc-oldc);
	if ((cyc_per_tick == 0.0 || cyc_per_tick > cpt) && cpt > RECORDTHRESH)
	  cyc_per_tick = cpt;
	/*
	if (verbose)
	  printf("Saw event lasting %.0f cycles and %d ticks.  Ratio = %f\n",
		 newt-oldt, (int) (newc-oldc), cpt);
	*/
	e++;
	oldc = newc;
      }
      oldt = newt;
    }
  }
  if (verbose)
    printf("Setting cyc_per_tick to %f\n", cyc_per_tick);
}
Ejemplo n.º 7
0
/* $begin time_p_warm */
double time_P_warm() 
{
    P(); /* Warm up the cache */
    start_counter(); 
    P(); 
    return get_counter(); 
}
Ejemplo n.º 8
0
/* $begin time_p_cold */
double time_P_cold() 
{
    P(); /* Warm up instruction cache */ 
    clear_cache(); /* Clear data cache */ 
    start_counter(); 
    P(); 
    return get_counter(); 
}
Ejemplo n.º 9
0
int main()
{
    int i,j;
    unsigned time1, time2, time3;
    start_counter();
    for (i = 0; i < SQSIZE; i++)
    {
		for (j = 0; j < SQSIZE; j++)
		{
			square[i][j].c = 0;
			square[i][j].m = 0;
			square[i][j].y = 1;
			square[i][j].k = 0;
		}
    }
    time1 = get_counter();

    start_counter();
    for (i = 0; i < SQSIZE; i++)
    {
		for (j = 0; j < SQSIZE; j++)
		{
			square[i][j].c = 0;
			square[i][j].m = 0;
			square[i][j].y = 1;
			square[i][j].k = 0;
		}
    }
    time2 = get_counter();
    
    start_counter();
    for (i = 0; i < SQSIZE; i++)
    {
		for (j = 0; j < SQSIZE; j++)
		{
			square[j][i].c = 0;
			square[j][i].m = 0;
			square[j][i].y = 1;
			square[j][i].k = 0;
		}
    }
    time3 = get_counter();
    printf("T1 (Cold cache time):    %12u  (%.1fx)\n", time1,(double)time1/time2);
    printf("T2 (Warm cache time):    %12u  (1.0x)\n", time2);
    printf("T3 (Poor locality time): %12u  (%.1fx)\n", time3,(double)time3/time2);
}
Ejemplo n.º 10
0
void start_comp_counter() {
  struct tms t;
  if (cyc_per_tick == 0.0)
    callibrate(1);
  times(&t);
  start_tick = t.tms_utime;
  start_counter();
}
Ejemplo n.º 11
0
/* return MHz rating of CPU */
double mhz(void)
{
    int sleeptime = 1;
    double rate;

    start_counter();
    sleep(sleeptime);
    rate = dget_counter() / (1e6 * sleeptime); 
    return (rate);
}
Ejemplo n.º 12
0
/* Determine clock rate by measuring cycles
   elapsed while sleeping for sleeptime seconds */
double mhz_full(int verbose, int sleeptime)
{
  double rate;
  start_counter();
  sleep(sleeptime);
  rate = get_counter()/(1e6*sleeptime);
  if (verbose) 
    printf("Processor Clock Rate ~= %.1f MHz\n", rate);
  return rate;
}
Ejemplo n.º 13
0
double fcyc(test_funct f, long int *params)
{
    double result;
    init_sampler();
    if (compensate) {
	do {
	    double cyc;
	    if (clear_cache)
		clear();
	    start_counter();
	    f(params);
	    cyc = get_counter();
	    if (cyc > 0.0)
		add_sample(cyc);
	} while (!has_converged() && samplecount < maxsamples);
    } else {
	do {
	    double cyc;
	    if (clear_cache)
		clear();
	    start_counter();
	    f(params);
	    cyc = get_counter();
	    if (cyc > 0.0)
		add_sample(cyc);
	} while (!has_converged() && samplecount < maxsamples);
    }
#ifdef DEBUG
    {
	long int i;
	printf(" %ld smallest values: [", kbest);
	for (i = 0; i < kbest; i++)
	    printf("%.0f%s", values[i], i==kbest-1 ? "]\n" : ", ");
    }
#endif
    result = values[0];
#if !KEEP_VALS
    free(values); 
    values = NULL;
#endif
    return result;  
}
Ejemplo n.º 14
0
double ovhd()
{
  /* Do it twice to eliminate cache effects */
  int i;
  double result;
  for (i = 0; i < 2; i++) {
    start_counter();
    result = get_counter();
  }
  return result;
}
Ejemplo n.º 15
0
Archivo: clock.c Proyecto: 0x0nil/csapp
double mhz(int verbose, int sleeptime)
{
	double rate;

	start_counter();
	sleep(sleeptime);
	rate = get_counter();
	if(verbose)
		printf("processor clock rate ~= %.1f MHz\n",rate);
	return rate;
}
Ejemplo n.º 16
0
double ovhd() {
    /* Find lowest among multiple samples */
    int i;
    double result = 1E10;
    for (i = 0; i < 100; i++) {
	double sample;
	start_counter();
	sample = get_counter();
	if (sample < result)
	    result = sample;
    }
    return result;
}
Ejemplo n.º 17
0
/* repeatedly calls the function to measure -- argument is iteration
 * count */ 
unsigned measure(int iter)
{
    int i;
    unsigned cmeas,cycles;
    volatile int res = 0;  /* don't let compiler optimize away fn
			    * calls */
    
    res += absdiff(0,1);  /* warm up cache */
    start_counter();
    for (i = 0; i < iter; i++)
	res += absdiff(valA[i],valB[i]);
    cmeas = get_counter();
    cycles = cmeas / iter;
    return cycles;
}
Ejemplo n.º 18
0
int main (int argc, char *argv[])
{
  int iters = 1000000;
  double MHz = mhz(1);
  int i;
  int sum = 0;
  double cycs;
  start_counter();
  for (i = 0; i < iters; i++) {
    sum += i;
    cycs = get_counter();
  }
  printf("%d calls in %.0f clock cycles = %.3f usec/call\n",
	 iters, cycs, cycs / (MHz * iters));
  return 0;
}
Ejemplo n.º 19
0
Archivo: tabs.c Proyecto: di/school
int main(int argc, char * argv[])
{
   int i,j,n,gen,repeat,t;
   double cycles;

   printf("Enter count: ");
   scanf("%d",&n);
  
   printf("Enter (0=constant, 1 = random:");
   scanf("%d",&gen);

   printf("Enter repeat count:");
   scanf("%d",&repeat);

   switch (gen) {
   case 0 :  
            for (i=0;i<n;i++)
            {
              a[i] = 1;
            }
            break;
   case 1 :  
            for (i=0;i<n;i+=repeat)
            {
              t = (-1) * (lrand48() % 2) ;
              for (j=0;j<repeat;j++)
                 a[i+j] = t;
            }
            for (;i<n;i++)
              a[i] = t;
            break;
  default : printf("illegal case\n");  exit(1);
  }

   start_counter();
   for (i=0;i<n;i++)
   {
     a[i] = absval(a[i]);
   }
   cycles = get_counter();
  
   printf("cycles for absval = %.0f\n",cycles);

}
Ejemplo n.º 20
0
/* repeatedly calls the function to measure until the total execution
 * time (in cycles) is above specified threshold, returns iteraction count */
int measurecnt(void)
{
    unsigned cmeas, cycles;
    int cnt = 1;
    volatile int res = 0;  /* don't let compiler optimize away fn
			      calls */
    do 
    {
	int c = cnt;
	res += absdiff(0,1);    /* first call to warm up cache */
	start_counter();
	while (c-- > 0)
	    res += absdiff(0,1);
	cmeas = get_counter();
	cycles = cmeas / cnt;
	cnt += cnt;
    } while (cmeas < CMIN);  /* make sure long enough */
    return cnt;
}
Ejemplo n.º 21
0
double fcyc2_full(test_funct f, int param1, int param2, int clear_cache,
		 int k, double epsilon, int maxsamples, int compensate) 
{
  double result;
  init_sampler(k, maxsamples);
  if (compensate) {
    do {
      double cyc;
      if (clear_cache)
	clear();
      f(param1, param2);   /* warm cache */
      start_comp_counter();
      f(param1, param2);
      cyc = get_comp_counter();
      add_sample(cyc, k);
    } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples);
  } else {
    do {
      double cyc;
      if (clear_cache)
	clear();
      f(param1, param2); /* warm cache */
      start_counter();
      f(param1, param2);
      cyc = get_counter();
      add_sample(cyc, k);
    } while (!has_converged(k, epsilon, maxsamples) && samplecount < maxsamples);
  }
#ifdef DEBUG
  {
    int i;
    printf(" %d smallest values: [", k);
    for (i = 0; i < k; i++)
      printf("%.0f%s", values[i], i==k-1 ? "]\n" : ", ");
  }
#endif
  result = values[0];
#if !KEEP_VALS
  free(values); 
  values = NULL;
#endif
  return result;  
}
Ejemplo n.º 22
0
/* repeatedly calls the function to measure until the total execution
 * time (in cycles) is above specified threshold */
unsigned measure(void)
{
    unsigned cmeas, cycles;
    int cnt = 1;
    do 
    {
	int c = cnt;
	dotproduct7(V1,V2,&result);    /* first call to warm up cache */
	start_counter();
	while (c-- > 0)
	    dotproduct7(V1,V2,&result);
	cmeas = get_counter();
	cycles = cmeas / cnt;
	cnt += cnt;
    } while (cmeas < CMIN);  /* make sure long enough */
    return cycles;
    
    /* printf("Measured function required %u clock cycles (per call)\n", cycles);
       printf("  cnt = %d, cmeas = %u\n", cnt, cmeas); */
}
/* Returns the estimated value of the CPU frequncy in cycles per second (Hz)
 */
long get_cpu_frequency()
{
	u_int64_t samples[MAX_SAMPLES];
	u_int64_t sample;
	int sample_count = 0;

	// Init sample array
	init_sample_array(samples, MAX_SAMPLES);

	// Initialize the counter
	start_counter();

	do {
		if (!get_sample(SLEEP_TIME, &sample)) {
			continue;
		}
		add_sample(samples, MAX_SAMPLES, sample);
		sample_count++;
	} while (!k_lowest_tolerance(samples, sample_count, K, TOLERANCE) && sample_count <= MAX_SAMPLES);

	return (long)(samples[0] / ((double)SLEEP_TIME / 1000));
}
Ejemplo n.º 24
0
int main (int argc, char *argv[])
{
	start_counter();
	(void) argv; //supress warning.
	//0)  Compute CPU speed experimentally.
	mhz = get_cpu_mhz();  // on a 3.5 ghz proc this is usually ~3 4xx xyz xyz, indicating cycles/second.
	printf("# Cpu_mhz: %lu\n", mhz);
	fflush(stdout);
	if (single_affinity) {
		set_single_cpu_affinity();
	}

	// Just passing an arg will branch to context switch experiment.
	if (argc == 2) {
		context_switch_experiment();
		return 0;
	} else {
		inactive_time_experiment();
	}

  printf("\n\n"); //clear screen.
  return 0;
}
Ejemplo n.º 25
0
int main() {
  int64_t value = -1;

  // Lock to cpu0
  cpu_set_t mask;
  CPU_ZERO(&mask);
  CPU_SET(0, &mask);
  assert(!sched_setaffinity(0, sizeof(mask), &mask));

  while (1) {
    int fd = start_counter();

    timing_computation();

    ssize_t nread = read(fd, &value, sizeof(value));
    assert(nread == sizeof(value));
    close(fd);

    printf("%lld\n", value);
  }

  return 0;
}
Ejemplo n.º 26
0
int main()
{
    double ctime,ptime,mhzest;
    pid_t pid;
    
    /* get estimate of mhz rating of cpu */
    mhzest = mhz();
    start_counter();
    if ((pid = fork()) == 0)
    {
	ctime = dget_counter();
	printf("Child:  %.8d ticks (%.2f ms)\n", (int) ctime, 
	       ctime/(mhzest * 1e3));
	exit(0);
    }
    else
    {
	ptime = dget_counter();
	printf("Parent: %.8d ticks (%.2f ms)\n", (int) ptime,
	       ptime/(mhzest * 1e3));
	waitpid(pid,NULL,0);
    }
}
Ejemplo n.º 27
0
Archivo: main.c Proyecto: imclab/rest
void handle_press_select(ClickRecognizerRef recognizer, void *context) {
  start_counter(settings.select);
}
Ejemplo n.º 28
0
Archivo: main.c Proyecto: imclab/rest
void handle_press_up(ClickRecognizerRef recognizer, void *context) {
  start_counter(settings.up);
}
Ejemplo n.º 29
0
void start_comp_counter()
{
    start_counter();
}
Ejemplo n.º 30
0
double time_funct(test_funct f, double *a)
{
  start_counter();
  f(a);
  return get_counter();
}