int newFunc()
{
  unsigned int functionStart, t, functionEnd;
  int a, b;
  access_counter(&t,&functionStart);
  a = a+b;
  b = a+ b;
  access_counter(&t, &functionEnd);
  return functionEnd - functionStart;
}
void *newUtil(void *t)
{
	unsigned int highs;
        unsigned int *ptr;
	access_counter(&highs,t);
        ptr = (int *)(t);
	return ;
}
示例#3
0
u_int64_t get_counter()
{
  unsigned ncyc_hi, ncyc_lo;

  /* Get the cycle counter */
  access_counter(&ncyc_hi, &ncyc_lo);

  return (((u_int64_t)ncyc_hi << 32) | ncyc_lo) - start;

}
示例#4
0
文件: cyc.c 项目: coconan/Compilers
/* Return the number of cycles since the last call to start_counter. */
unsigned long get_counter()
{
	unsigned ncyc_hi, ncyc_lo;
	unsigned long now, before;

	/* Get cycle counter */
	access_counter(&ncyc_hi, &ncyc_lo);
	now = to64(ncyc_hi, ncyc_lo);
	before = to64(cyc_hi, cyc_lo);
	return (now - before);
}
示例#5
0
文件: timer.c 项目: kywe665/ECEn-324
/* return # cycles since start_counter as unsigned */
unsigned get_counter(void)
{
    access_counter(&end_hi, &end_lo);
    if (end_hi == start_hi)
	return end_lo - start_lo;
    else if (end_hi == start_hi+1 && end_lo < start_lo)
	return end_lo - start_lo;
    else
    {
	fprintf(stderr, "Cycle counter overflow: measurement interval too long\n");
	exit(-1);
    }
}
示例#6
0
文件: timer.c 项目: kywe665/ECEn-324
/* return # cycles since start_counter as double */
double dget_counter(void)
{
    unsigned hi, lo, borrow;
    double result;
    
    access_counter(&end_hi, &end_lo);
    lo = end_lo - start_lo;
    borrow = lo > end_lo;
    hi = end_hi - start_hi - borrow;
    result = (double) hi * (double) (1 << 30) * 4.0 + (double) lo;
    if (result < 0.0)
	fprintf(stderr, "Counter returned negative value in dget_counter()\n");
    return result;
}
示例#7
0
/* Return the number of cycles since the last call to start_counter. */
double get_counter()
{
    unsigned ncyc_hi, ncyc_lo;
    unsigned hi, lo, borrow;
    double result;

    /* Get cycle counter */
    access_counter(&ncyc_hi, &ncyc_lo);

    /* Do double precision subtraction */
    lo = ncyc_lo - cyc_lo;
    borrow = cyc_lo > ncyc_lo;
    hi = ncyc_hi - cyc_hi - borrow;
    result = (double) hi * (1 << 30) * 4 + lo;
    return result;
}
示例#8
0
double get_counter()
{
  unsigned ncyc_hi, ncyc_lo;
  unsigned hi, lo, borrow;
  double result;
  /* Get cycle counter */
  access_counter(&ncyc_hi, &ncyc_lo);
  /* Do double precision subtraction */
  lo = ncyc_lo - cyc_lo;
  borrow = lo > ncyc_lo;
  hi = ncyc_hi - cyc_hi - borrow;
  result = (double) hi * (1 << 30) * 4 + lo;
  if (result < 0) {
    fprintf(stderr, "Error: Cycle counter returning negative value: %.0f\n", result);
  }
  return result;
}
void measure_cyclecounter3(float mhz) {
  unsigned int high_s, low_s, high_e, low_e;
  unsigned int high_s1, low_s1, high_e1, low_e1;
  unsigned int high_s2, low_s2, high_e2, low_e2;
  unsigned int high_s3, low_s3, high_e3, low_e3;
  unsigned int high_s4, low_s4, high_e4, low_e4;
  unsigned int high_s5, low_s5, high_e5, low_e5;
  unsigned int high_s6, low_s6, high_e6, low_e6;
  unsigned int high_s7, low_s7, high_e7, low_e7;
  unsigned int high_s0, low_s0, high_e0, low_e0;
  unsigned int passed, t, buf;
  int pipefd[2];
  size_t nbytes;
  float latency_with_read, latency_no_read;
  float latency_with_func0;
  float latency_with_func1;
  float latency_with_func2;
  float latency_with_func3;
  float latency_with_func4;
  float latency_with_func5;
  float latency_with_func6;
  float latency_with_func7;
  float latency_with_func0_in, taskCreationTime, taskCreationTime2, taskCreationTime3, contextSwitch1;
  unsigned int beforeFunction, afterFunction, functionTime, t1, t2 = 0, t3, start1, start2, start3, start4, start5, temp;
  float baseFunctionTime;
  // warm up all the caches by exercising the functions
  access_counter(&high_s, &low_s);
  // read(5, buf, 4);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);

  // now do it for real
  access_counter(&high_s, &low_s);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);
  latency_with_read = ((float) (low_e - low_s) / mhz);

  access_counter(&high_s, &low_s);
  access_counter(&high_e, &low_e);
  latency_no_read = ((float) (low_e - low_s) / mhz);

     pthread_t thread;
     int rc = pthread_create(&thread,NULL,newUtil,(void *) &start5);
     access_counter(&t2, &start4);
     pthread_join(thread,NULL);
     taskCreationTime3 = ((float) (start5 - start4) / mhz);
     pthread_exit(NULL);
}
示例#10
0
文件: clock.c 项目: 0x0nil/csapp
/* return the number of cycles since the last call to start_counter.*/
double get_counter()
{
	unsigned ncyc_hi, ncyc_lo;
	unsigned hi, lo, borrow;
	double result;

	access_counter(&ncyc_hi, &ncyc_lo);

	lo = ncyc_lo - cyc_lo;
	borrow = lo > ncyc_lo;
	hi = ncyc_hi - cyc_hi -borrow;
	result = (double)hi * (1 << 30) *4 +lo;
	if(result < 0 )
	{
		fprintf(stderr,"error: counter returns neg vaule: %.0f\n",result);
	}
	return result;
}
示例#11
0
文件: timer.c 项目: kywe665/ECEn-324
/* records the counter value at start of interval */
void start_counter(void)
{
    access_counter(&start_hi, &start_lo);
}
示例#12
0
void start_counter()
{
  access_counter(&cyc_hi, &cyc_lo);
}
示例#13
0
void start_counter()
{
  unsigned hi, lo;
  access_counter(&hi, &lo);
  start = ((u_int64_t)hi << 32) | lo;
}
示例#14
0
void measure_cyclecounter(float mhz) {
  unsigned int high_s, low_s, high_e, low_e;
  unsigned int high_s1, low_s1, high_e1, low_e1;
  unsigned int high_s2, low_s2, high_e2, low_e2;
  unsigned int high_s3, low_s3, high_e3, low_e3;
  unsigned int high_s4, low_s4, high_e4, low_e4;
  unsigned int high_s5, low_s5, high_e5, low_e5;
  unsigned int high_s6, low_s6, high_e6, low_e6;
  unsigned int high_s7, low_s7, high_e7, low_e7;
  unsigned int high_s0, low_s0, high_e0, low_e0;
  unsigned int passed, t;
  size_t nbytes;
  float latency_with_read, latency_no_read;
  float latency_with_func0;
  float latency_with_func1;
  float latency_with_func2;
  float latency_with_func3;
  float latency_with_func4;
  float latency_with_func5;
  float latency_with_func6;
  float latency_with_func7;
  float latency_with_func0_in, taskCreationTime, taskCreationTime2, taskCreationTime3, taskCreationProcess;
  unsigned int beforeFunction, afterFunction, functionTime, t1, t2, t3, start1, start2, start3, start4, start5, temp;
  float baseFunctionTime;
  // warm up all the caches by exercising the functions
  access_counter(&high_s, &low_s);
  // read(5, buf, 4);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);

  // now do it for real
  access_counter(&high_s, &low_s);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);
  latency_with_read = ((float) (low_e - low_s) / mhz);

  access_counter(&high_s, &low_s);
  access_counter(&high_e, &low_e);
  latency_no_read = ((float) (low_e - low_s) / mhz);

  // now do it for real
//  access_counter(&high_s0, &low_s0);
//  passed = procedure_call0();
//  access_counter(&high_e0, &low_e0);
//  latency_with_func0 = ((float) (low_e0 - low_s0) / mhz);
//  latency_with_func0_in = ((float) (passed - low_s0) / mhz);

  // now do it for real
  access_counter(&high_s1, &low_s1);
  procedure_call1(1);
  access_counter(&high_e1, &low_e1);
  latency_with_func1 = ((float) (low_e1 - low_s1) / mhz);

  // now do it for real
  access_counter(&high_s2, &low_s2);
  procedure_call2(1,1);
  access_counter(&high_e2, &low_e2);
  latency_with_func2 = ((float) (low_e2 - low_s2) / mhz);

  // now do it for real
  access_counter(&high_s3, &low_s3);
  procedure_call3(1,1,1);
  access_counter(&high_e3, &low_e3);
  latency_with_func3 = ((float) (low_e3 - low_s3) / mhz);

  // now do it for real
  access_counter(&high_s4, &low_s4);
  procedure_call4(1,1,1,1);
  access_counter(&high_e4, &low_e4);
  latency_with_func4 = ((float) (low_e4 - low_s4) / mhz);

  // now do it for real
  access_counter(&high_s5, &low_s5);
  procedure_call5(1,1,1,1,1);
  access_counter(&high_e5, &low_e5);
  latency_with_func5 = ((float) (low_e5 - low_s5) / mhz);

  // now do it for real
  access_counter(&high_s6, &low_s6);
  procedure_call6(1,1,1,1,1,1);
  access_counter(&high_e6, &low_e6);
  latency_with_func6 = ((float) (low_e6 - low_s6) / mhz);

  // now do it for real
  access_counter(&high_s7, &low_s7);
  procedure_call7(1,1,1,1,1,1,1);
  access_counter(&high_e7, &low_e7);
  latency_with_func7 = ((float) (low_e7 - low_s7) / mhz);

  access_counter(&t, &beforeFunction);
  functionTime = newFunc();
  access_counter(&t,  &afterFunction);
  baseFunctionTime = ((afterFunction - beforeFunction) - functionTime) / mhz;
  
  access_counter(&t1,&start1);
  pid_t pID= fork();
  if (pID == 0)
  {
    access_counter(&t2,&start2);
    // access_counter(&t3,&start3);
    taskCreationTime = ((float) (start2 - start1) / mhz);
    taskCreationProcess = taskCreationTime - latency_no_read;
  }
  else
  {
    access_counter(&t3,&start3);
    // access_counter(&t3,&start3);
    taskCreationTime2 = ((float) (start3 - start1) / mhz);
    taskCreationProcess = taskCreationTime2 - latency_no_read;
  }


  if (pID != 0)
  {
   
   pthread_t thread;
   access_counter(&t1,&start4);
   int rc = pthread_create(&thread,NULL,procedure_call0,NULL);
   access_counter(&t2,&start5);
   taskCreationTime3 = ((float) (start5 - start4) / mhz);
   printf("%f %f \n", taskCreationProcess, taskCreationTime3 - latency_no_read - (latency_with_func4 - latency_no_read));
   pthread_exit(NULL);
  }
}
示例#15
0
void measure_cyclecounter2(float mhz) {
  unsigned int high_s, low_s, high_e, low_e;
  unsigned int high_s1, low_s1, high_e1, low_e1;
  unsigned int high_s2, low_s2, high_e2, low_e2;
  unsigned int high_s3, low_s3, high_e3, low_e3;
  unsigned int high_s4, low_s4, high_e4, low_e4;
  unsigned int high_s5, low_s5, high_e5, low_e5;
  unsigned int high_s6, low_s6, high_e6, low_e6;
  unsigned int high_s7, low_s7, high_e7, low_e7;
  unsigned int high_s0, low_s0, high_e0, low_e0;
  unsigned int passed, t, buf;
  int pipefd[2];
  size_t nbytes;
  float latency_with_read, latency_no_read;
  float latency_with_func0;
  float latency_with_func1;
  float latency_with_func2;
  float latency_with_func3;
  float latency_with_func4;
  float latency_with_func5;
  float latency_with_func6;
  float latency_with_func7;
  float latency_with_func0_in, taskCreationTime, taskCreationTime2, taskCreationTime3, contextSwitch1, taskCreationProcess;
  unsigned int beforeFunction, afterFunction, functionTime, t1, t2 = 0, t3, start1, start2, start3, start4, start5, temp;
  float baseFunctionTime;
  // warm up all the caches by exercising the functions
  access_counter(&high_s, &low_s);
  // read(5, buf, 4);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);

  // now do it for real
  access_counter(&high_s, &low_s);
  DO_SYSCALL;
  access_counter(&high_e, &low_e);
  latency_with_read = ((float) (low_e - low_s) / mhz);

  access_counter(&high_s, &low_s);
  access_counter(&high_e, &low_e);
  latency_no_read = ((float) (low_e - low_s) / mhz);

  access_counter(&t1,&start1);
  if (pipe(pipefd) == -1)
    exit(EXIT_FAILURE);

  pid_t pID= fork();
  if (pID == 0)
  {
    access_counter(&t2,&start2);
    write(pipefd[1],&start2,sizeof(start2));
    close(pipefd[1]);
    close(pipefd[0]);
    _exit(EXIT_SUCCESS);
  }
  else
  {
    
    access_counter(&t3,&start3);
    wait(NULL);
    read(pipefd[0],&buf, 4); 
    close(pipefd[0]);
    close(pipefd[1]);
    contextSwitch1 = ((float) (buf - start3) / mhz);
    printf("%f \n", contextSwitch1 - latency_no_read);
  }
}