示例#1
0
MY_EXPORT void adv_delayn(uint32_t interval)
{
    uint64_t current, cycles, start;

    start = RDTSC();

    if (usec == 0)
    {
        adv_delay_setup();
    }

    cycles = (usec * interval) / 1000;

    while(1)
    {
        current = RDTSC();
        if ((current <= 0xffffffff)&&(start > 0xffffffff))
        {
            if (~(start - current) >= cycles)
            {
                break;
            }
        }
        else
        {
            if (current - start >= cycles)
            {
                break;
            }
        }
    }
}
BOOL KScriptManager::Call(DWORD dwScriptID, const char* pszFuncName, int nResults)
{
    BOOL        bResult  = false;
	BOOL        bRetCode = false;
    uint64_t    uTime    = 0;
    BOOL        bStat    = m_bStatFlag;  
	assert(nResults >= 0);
    assert(pszFuncName);

    if (bStat)
    {
        uTime = RDTSC();
    }

    bRetCode = m_piScript->CallFunction(dwScriptID, pszFuncName, nResults);
    KG_PROCESS_ERROR(bRetCode);

    if (bStat)
    {
        uTime = RDTSC() - uTime;

        UpdateStatInfo(dwScriptID, pszFuncName, uTime);
    }

	bResult = true;
Exit0:
	return bResult;
}
示例#3
0
文件: tests.c 项目: rostislawk/ONB
void test_invONB2(size_t m)
{
	size_t field_size = m;
	size_t field_size_word_length = size_in_words(field_size);
	word *A = (word *)malloc((2 * field_size - 1) * sizeof(word));
	word *b = (word *)malloc(field_size_word_length * sizeof(word));
	word *res = (word *)malloc(field_size_word_length * sizeof(word));
	word *unity = (word *)malloc(field_size_word_length * sizeof(word));
	size_t index;
	uint64 start, overhead, freq1, freq2;
	generateONB2_A(A, field_size);
	wordSetZero(b, field_size_word_length);
	b[0] = 1;
	printBinaryRepresentation2(b, field_size_word_length, field_size);
	normalize(b, field_size_word_length, field_size);
	start = RDTSC();
    overhead = RDTSC() - start;
	for (index = 0; index < 1000; ++index) {
        inv(res, b, A, field_size_word_length, field_size);
	}
    freq1 = RDTSC() - start - overhead;	
	
	printBinaryRepresentation2(res, field_size_word_length, field_size);
	mul(unity, b, res, A, field_size_word_length, field_size);
	printBinaryRepresentation2(unity, field_size_word_length, field_size);
	printf("\nProcessor ticks for multiplication in the field with m = %u equals = %u\n", field_size, freq1/1000);
	free(A);
	free(unity);
	free(b);
	free(res);
}
示例#4
0
文件: tests.c 项目: rostislawk/ONB
void test_mulONB2(size_t m)
{
	size_t field_size_word_length = size_in_words(m);
	word *A = (word *)malloc((2 * m - 1) * sizeof(word));
	word *a = (word *)malloc(field_size_word_length * sizeof(word));
	word *b = (word *)malloc(field_size_word_length * sizeof(word));
	word *res = (word *)malloc(field_size_word_length * 2 * sizeof(word));
	size_t index;
	uint64 start, overhead, freq1, freq2;
	generateONB2_A(A, m);
	wordSetZero(a, field_size_word_length);
	wordSetZero(b, field_size_word_length);
	a[0] = 1;
	b[0] = 1;
	normalize(a, field_size_word_length, m);
	printBinaryRepresentation2(a, field_size_word_length, m);
	printf("\n");
	normalize(b, field_size_word_length, m);
	printBinaryRepresentation2(b, field_size_word_length, m);
	printf("\n");
	start = RDTSC();
    overhead = RDTSC() - start;
	for (index = 0; index < 1000; ++index) {
        mul(res, a, b, A, field_size_word_length, m);
	}
    freq1 = RDTSC() - start - overhead;	
	printBinaryRepresentation2(res, field_size_word_length, m);
	printf("\n");
	printf("Processor ticks for multiplication in the field with m = %u equals = %u\n", m, freq1/1000);
	free(A);
	free(a);
	free(b);
	free(res);
}
示例#5
0
/*
 * microbench: timing setup
 * x: input vector
 * y: output vector
 * n: length of the input vector
 * dest: used to avoid deadcode eliminiation
 */
double microbench_exp( double * x, double * y, double *dest, size_t n) {
  int i, num_runs;
  double cycles;
  tsc_counter start, end;
  
  num_runs = NUM_RUNS;
  
  // Cache warm-up for at least CYCLES_REQUIRED cycles,
  // recording the required number of executions

  CPUID(); RDTSC(start); RDTSC(end);
  CPUID(); RDTSC(start); RDTSC(end);
  CPUID(); RDTSC(start); RDTSC(end);

  while(1) {


    CPUID(); RDTSC(start);

    for(i = 0; i < num_runs; i++) {
	exp_bench(x,y,n);		     
    }
    
    RDTSC(end); CPUID();

    for (i = 0; i< n; i++)
	*dest += y[i]; //this is done to avoid dead code eliminiation    

    
    cycles = ((double)COUNTER_DIFF(end, start));

    if(cycles >= CYCLES_REQUIRED) break;

    num_runs *= 2;

  }
  
  //Measurement of the selected function
  CPUID(); RDTSC(start);

  for(i = 0; i < num_runs; i++) {
	exp_bench(x,y,n);
  }

  
  
  RDTSC(end); CPUID();
 
  for (i = 0; i< n; i++)
     *dest += y[i]; //this is done to avoid dead code eliminiation

 
  cycles = ((double)COUNTER_DIFF(end, start)) / ((double) num_runs);

  return cycles;
}
示例#6
0
int main(int argc,char* argv[]) {
  uint64_t a,b;
  RDTSC(a);
  if (!fork()) { execve(argv[1],argv+1,environ); exit(1); }
  wait(0);
  RDTSC(b);
  printf("%llu cycles\n",b-a);

  return 0;
}
示例#7
0
文件: lcd.c 项目: LGTMCU/f32c
static void
lcd_delay(int us)
{
	uint32_t start, stop;
	uint32_t ticks = us * 128; /* XXX assumes <= 128 MHz clock */

	RDTSC(start);
	do {
		RDTSC(stop);
	} while (stop - start <= ticks);
}
示例#8
0
文件: ipc.c 项目: Quest-V/quest
static void
testR (void)
{
  u32 arg1, arg2;
  DLOG ("testR: hello from 0x%x", testR_id);
  fast_recv_m (&arg1, &arg2);
  for (;;) {
    RDTSC (finish);
    DLOG ("testR: MEM: cycles=0x%.08llX: got 0x%X and 0x%X", finish - start, arg1, arg2);
    RDTSC (start);
    fast_sendrecv_m (testS_id, arg1 + arg2, arg1 | arg2, &arg1, &arg2);
  }
}
示例#9
0
void
delay(uint32_t ms)
{
	int32_t t, target;
	RDTSC(target);
	while (ms--)
	{
		target += F_CPU/1000;
		do
			RDTSC(t);
		while((target-t) > 0);
	}
}
示例#10
0
文件: smp.c 项目: HelpFSme/memtest
// Silly way of busywaiting, but we don't have a timer
void delay(unsigned us) 
{
   unsigned freq = 1000; // in MHz, assume 1GHz CPU speed
   uint64_t cycles = us * freq;
   uint64_t t0 = RDTSC();
   uint64_t t1;
   volatile unsigned k;

   do {
      for (k = 0; k < 1000; k++) continue;
      t1 = RDTSC();
   } while (t1 - t0 < cycles);
}
示例#11
0
文件: ipc.c 项目: Quest-V/quest
static void
testS (void)
{
  u32 arg1, arg2;
  DLOG ("testS: hello from 0x%x", testS_id);
  for (;;) {
    RDTSC (start);
    fast_call_m (testR_id, 0xCAFEBABE, 0xDEADBEEF, &arg1, &arg2);
    RDTSC (finish);
    DLOG ("testS: MEM: cycles=0x%.08llX: answer was 0x%X and 0x%X", finish - start, arg1, arg2);
    sched_usleep (1000000);
  }
}
示例#12
0
void timer_start(void)
{
#if defined(USE_GETTIMEOFDAY)
  {
    struct timeval ts;
    gettimeofday(&ts, (struct timezone*)0);
    t1 = (double)ts.tv_sec*1000000000.0 + (double)ts.tv_usec*1000.0; 
  }
#elif defined(USE_RDTSC)
  {
    unsigned long long ticks;
    if ( cps == 0 )
      cps = cycles_per_second();
    RDTSC(ticks);
    t1 = (ticks / (double)cps) * 1.0e9;
  }
#else
  {
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME,&ts);
    t1 = (double)ts.tv_sec*1000000000.0 + (double)ts.tv_nsec;
  }
#endif
  DBG(printf("START %f\n",t1))
}
示例#13
0
/*! \fn void Alloc(int nb, int dim)
 *  \brief Gaussian Mixture initialisations and allocations
 *  \param nb the number of gaussians in the mixture
 *  \param dim the gaussians dimension
 */
void GaussianMixture::Alloc(int nb, int dim, double *m, double *cov)
{
  //printf("nb = %d  et dim = %d\n",nb,dim);
  this->nb = this->curnb = nb;
  
  glist = new Gaussian*[nb];
  coeff = new double[nb];
  coeffCumul = new double[nb];
  
  this->areEquiprob = 1;
  this->EquiprobCoeff = 1.0/(double)nb;
  
  glist[0] = GaussianAlloc(dim,m,cov,dispdec);
  if(cov || m) glist[0]->Init(m,cov);
  coeff[0] = this->EquiprobCoeff;  
  coeffCumul[0] =  coeff[0];
  for(int i=1;i<nb;i++)
    {
      glist[i] = GaussianAlloc(dim,m,cov,dispdec);
      if(cov || m) glist[i]->Init(m,cov);
      coeff[i] = this->EquiprobCoeff;  
      coeffCumul[i] =  coeffCumul[i-1] + coeff[i];
    }
  
  /* Generateur aleatoire init en fonction de l'horloge */
  //rng_state = cvRNG(0xffffffff);
  rng_state = cvRNG((uint64)RDTSC());
}
示例#14
0
void timer_stop(void)
{
#if defined(USE_GETTIMEOFDAY)
  {
    struct timeval ts;
    gettimeofday(&ts, (struct timezone*)0);
    t2 = (double)ts.tv_sec*1000000000.0 + (double)ts.tv_usec*1000.0; 
  }
#elif defined(USE_RDTSC)
  {
    unsigned long long ticks;
    if ( cps == 0 )
      cps = cycles_per_second();  /* probably not necessary, but safe */
    RDTSC(ticks);
    t2 = (ticks / (double)cps) * 1.0e9;
  }
#else
  {
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME,&ts);
    t2 = (double)ts.tv_sec*1000000000.0 + (double)ts.tv_nsec;
  }
#endif
  DBG(printf("STOP %f\n",t2))
}
示例#15
0
文件: sum.c 项目: helenarth/cs61c
void benchmark( int n, int *a, int (*computeSum)(int,int*), char *name )
{
    /* warm up */
    int sum = computeSum( n, a );

    /* measure */
    unsigned long long cycles = RDTSC();
    sum += computeSum( n, a );
    cycles = RDTSC()-cycles;
    
    double microseconds = cycles/CLOCK_RATE_GHZ*1e6;
    
    /* report */
    printf( "%20s: ", name );
    if( sum == 2*sum_naive(n,a) ) printf( "%.2f microseconds\n", microseconds );
    else	                  printf( "ERROR!\n" );
}
示例#16
0
文件: tests.c 项目: rostislawk/ONB
void test_generationONB3_A(size_t m)
{
	word *a = (word *)malloc((2 * m - 1) * sizeof(word));
	size_t index;
	uint64 start, overhead, freq1, freq2;
	start = RDTSC();
    overhead = RDTSC() - start;
	for (index = 0; index < 1000; ++index) {
		generateONB3_A(a, m);
	}
    freq1 = RDTSC() - start - overhead;	
	printf("Processor ticks for multiplication in the field with m = %u equals = %u\n", m, freq1/1000);
	for (index = 0; index < 2 * m - 1; ++index) {
		printf("%u -> %u\n", (index + 1) / 2, a[index]);
	}
	free(a);
}
示例#17
0
文件: equal.c 项目: Ricky54326/CS-736
void* pthread_func(void* argument)
{
    uint high;
    uint low;
    ull start;
    ull end;
    unsigned long diff;

    pthread_t cmp_1 = 0x12345678;
    pthread_t cmp_2 = pthread_self();

    uint val;
    RDTSC(start);
    pthread_equal(cmp_1, cmp_2);
    RDTSC(end);

    return (void*)diff;
}
示例#18
0
static unsigned long long cycles_per_second()
{
  double seconds;
  unsigned long long starttick, endtick;
  unsigned long long starttime, endtime;
  struct timeval tv;

  gettimeofday(&tv, 0);
  starttime = tv.tv_sec*1000 + tv.tv_usec/1000;
  while ( 1 )
    {
      gettimeofday(&tv, 0);
      endtime = tv.tv_sec*1000 + tv.tv_usec/1000;
      if ( endtime != starttime )
        {
          break;
        }
    }

  while ( 1 )
    {
      gettimeofday(&tv, 0);
      endtime = tv.tv_sec*1000 + tv.tv_usec/1000;
      if ( (endtime - starttime) > 1 )
        {
          RDTSC(starttick);
          break;
        }
    }

  starttime = endtime;
  while ( 1 )
    {
      gettimeofday(&tv, 0);
      endtime = tv.tv_sec*1000 + tv.tv_usec/1000;
      if ( (endtime - starttime) > 1000 )
        {
          RDTSC(endtick);
          break;
        }
    }

  return (endtick - starttick);
}
示例#19
0
int main()
{
    int fd, len;
    char *buf = "a";
    unsigned long long start, end, passed;
            
    len = strlen(buf);    
    fd = open("./test.txt", O_RDWR | O_CREAT, 0666);

    RDTSC(start);
    while (1) {
        write(fd, buf, len);
        
        RDTSC(end);
        passed = (end - start) / CLOCK;
        if (passed >= WORKLOAD_TIME) break;
    }
    close(fd);
    printf("passed : %llu\n", passed);
}
示例#20
0
static void CalibrateTicks() {
    struct timespec begints, endts;
    uint64_t begin = 0, end = 0;
    clock_gettime(CLOCK_MONOTONIC, &begints);
    begin = RDTSC();
    
    for( ; i < 300000000 ; i++) {
      j = (j * 1.12345) / 1.054321;
    }
    
    end = RDTSC();
    
    clock_gettime(CLOCK_MONOTONIC, &endts);
    struct timespec *tmpts = TimeSpecDiff(&endts, &begints);
    uint64_t nsecElapsed = tmpts->tv_sec * 1000000000LL + tmpts->tv_nsec;
    
    g_TicksPerNanoSec = (double)(end - begin)/(double)nsecElapsed;
    
    printf( "calibrateTicks timeMS=%d, ticksPerNanoSec=%f\n", (nsecElapsed/1000000), g_TicksPerNanoSec );
}
示例#21
0
int main()
{
  /*buf data initialization .*/
  long long i;
  for(i=0; i<1024/4; i++)
    {
      buf[i]=1;
    }
  
  unsigned long int count_begin, count_end;
  count_begin=RDTSC();//Start!

  /*create K plaint text files, and each file name is stored in name[].*/
  long k;
  char name[30];
  
  for(k=0; k<1000000; k++)
    {
      sprintf(name, "%lu", k);/*Convert long int k to char*/
      
      int filedir;
      filedir = open(name, O_WRONLY | O_CREAT | O_EXCL, 0644);

      if(filedir == -1)
	{
	  perror("File cannot be opened!");
	}
      
      else
	{
	  write(filedir, buf, sizeof(buf));
	}
      
      close(filedir);
    }

  count_end = RDTSC();//End!
  printf("CPU Tick Time: %lu\n", count_end-count_begin);
  
  return 0;
}
示例#22
0
static void
update_tsc(void)
{
	uint32_t tsc;

	RDTSC(tsc);

	/* check for 32-bit overflow */
	if (tsc < tsc_lo)
		tsc_hi++;
	tsc_lo = tsc;
}
示例#23
0
JNIEXPORT jlong JNICALL Java_com_rr_core_os_NativeHooksImpl_jniNanoTimeMonotonicRaw(JNIEnv *env, jclass clazz) {
#ifndef CLOCK_MONOTONIC_RAW
    return( RDTSC() / g_TicksPerNanoSec );
#else
    struct timespec ts;
 
    clock_gettime(CLOCK_MONOTONIC_RAW,&ts);

    uint64_t nsecElapsed = ts.tv_sec * 1000000000LL + ts.tv_nsec;
    
    return nsecElapsed;
#endif    
}
示例#24
0
文件: sum.c 项目: hansongcal/CS61C
void benchmark(int n, int *a, int(*computeSum)(int, int*), char *name)
{
    // warm up cache
    int sum = computeSum(n, a);

    // measure
    uint64_t beginCycle = RDTSC();
    sum += computeSum(n, a);
	uint64_t cycles = RDTSC() - beginCycle;
    
    double microseconds = cycles/CLOCK_RATE_GHZ*1e6;
    
    // print results
	printf("%20s: ", name);
	if (sum == 2 * sum_naive(n, a))
	{
		printf("%.2f microseconds\n", microseconds);
	}
	else
	{
		printf("ERROR!\n");
	}
}
示例#25
0
void rt_accumulate(int ix) {
  if(selectedClock == OMC_CLOCK_REALTIME)
  {
    LARGE_INTEGER tock_tp;
    QueryPerformanceCounter(&tock_tp);
    acc_tp[ix].QuadPart += tock_tp.QuadPart - tick_tp[ix].QuadPart;
  }
  else
  {
    LARGE_INTEGER tock_tp;
    tock_tp.QuadPart = RDTSC();
    acc_tp[ix].QuadPart += tock_tp.QuadPart - tick_tp[ix].QuadPart;
  }
}
示例#26
0
int SetInputFile(const char *fname)
{
    FileInputSrc *in = malloc(sizeof(FileInputSrc));
    memset(in, 0, sizeof(FileInputSrc));
    if (fname) {
        if (!Cg->options.Quiet)
            printf("%s\n", fname);
        in->base.name = LookUpAddString(atable, fname);
        in->fd = fopen(fname, "r");
        if (!in->fd) {
            printf(OPENSL_TAG ": cannot open input file \"%s\"\n", fname);
            free(in);
            return 0;
        }
    } else {
        in->fd = stdin;
        in->base.name = LookUpAddString(atable, "<stdin>");
    }
    in->base.line = 1;
    in->base.scan = byte_scan;
    in->base.getch = (int (*)(InputSrc *)) nextchar;
    in->base.ungetch = (void (*)(InputSrc *, int)) ungetchar;
    in->base.prev = Cg->currentInput;
    Cg->currentInput = &in->base;
#if 0 && !defined(_DEBUG)
    if (Cg->options.TraceScanner) {
        __int64 s,e;
        s = RDTSC();
        while (Cg->currentInput->scan(Cg->currentInput) > 0)
            /* empty statement */ ;
        e = RDTSC();
        printf("%d cycles\n", (int)(e-s));
        return 0;
    }
#endif
    return 1;
} // SetInputFile
示例#27
0
int main(void) {

     struct timeval inicio, fim;
     tsc_counter tsc1, tsc2;
     long long unsigned int clock;
     double tempo;
	unsigned long count;

     //wurmup
     fft();

     //mede o tempo de execução da funcao f0 (media de NITER repeticoes) 
     gettimeofday(&inicio, NULL);
     RDTSC(tsc1);
	for(count=0;count<NUM_ITERACOES;count++){
     	inicializaArray();
          ordenaBitReverso();
         	fft();
	}

     RDTSC(tsc2);
     gettimeofday(&fim, NULL);
     tempo = (fim.tv_sec - inicio.tv_sec)*1000 + (fim.tv_usec - inicio.tv_usec)/1000; //calcula tempo em milisegundos
     //printf("tempo:%lf",tempo);
     clock = tsc2.int64 - tsc1.int64; //calcula numero de ciclos de CPU gastos
     printf("Tempo FFT : %.1lf(ms) Clocks: %.2e \n", tempo/NUM_ITERACOES, (double)clock/NUM_ITERACOES);
     printf("Clock/tempo: %.2e\n", clock/tempo);
     printf("QtdElementos:%d Threads: %d Peso:%d\n",QTD_ELEMENTOS,QTD_CORES,PESO_THREADS);
     printf("%.1lf\t%.2e\t%.2e\n\n\n",tempo/NUM_ITERACOES,(double)clock/NUM_ITERACOES,clock/tempo);

	//imprimeVetor();

     pthread_exit (NULL);
	return 0;

}
示例#28
0
int main()
{
  int filedir = open("1GB_data.txt", O_RDONLY);/*Read-Only*/

  if(filedir==-1)
    {
      perror("File cannot be opened!");
    }

  else
    {
      unsigned long int count_begin, count_end;
     
      count_begin=RDTSC(); 
      read(filedir, buf, sizeof(buf));
      count_end = RDTSC();

      printf("CPU Tick Time: %lu\n", count_end-count_begin);
    }
  
  close(filedir);

  return 0;
}
示例#29
0
double rt_tock(int ix) {
  if(selectedClock == OMC_CLOCK_REALTIME)
  {
    LARGE_INTEGER tock_tp;
    double d1, d2;
    QueryPerformanceCounter(&tock_tp);
    d1 = (double) (tock_tp.QuadPart - tick_tp[ix].QuadPart);
    d2 = (double) performance_frequency.QuadPart;
    return d1 / d2;
  }
  else
  {
    LARGE_INTEGER tock_tp;
    tock_tp.QuadPart = RDTSC();
    return (double) (tock_tp.QuadPart - tick_tp[ix].QuadPart);
  }
}
示例#30
0
文件: stopwatch.c 项目: huangl0/funcy
void timestamp_now(struct timestamp *dest)
{
  struct timeval tv;

  /* Highest precision first */
#ifdef HAVE_RDTSC
  RDTSC(dest->cycles);
#endif
  gettimeofday(&tv, NULL);
  dest->micros = 1000000 * (tsc_t)tv.tv_sec + tv.tv_usec;
  //times(&dest->cpu);
  dest->cpu.tms_utime = 0;
  dest->cpu.tms_stime = 0;
  dest->cpu.tms_cutime = 0;
  dest->cpu.tms_cstime = 0;

}