コード例 #1
0
ファイル: util.c プロジェクト: davidn/wicrawl-debian
void init_prof(prof_t * prof)
{
  int i;
  FILE * fp;
  uint32_t olddelta;
  uint32_t delta;
  prof_t nothing;

  fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
  if(fp == NULL) {
    fprintf(stderr, "Could not open cpuinfo from sysfs: %s\n", strerror(errno));
    return;
  }

  fscanf(fp, "%u", &kHz);
  printf("DEBUG: detected %u MHz CPU\n", kHz / 1000);

  start_prof(&nothing);
  end_prof(&nothing);
  olddelta = tsc_delta(nothing.t1_upper, nothing.t1_lower, 
		       nothing.t2_upper, nothing.t2_lower);
  for(i = 0; i < 100; ++i) {
    start_prof(&nothing);
    end_prof(&nothing);
    delta = tsc_delta(nothing.t1_upper, nothing.t1_lower, 
		      nothing.t2_upper, nothing.t2_lower);
    if(delta != olddelta) {
      printf("DEBUG: cycle count for a no-op is changing!\n");
    }
    olddelta = delta;
  }

  noop_cycles = delta;
  printf("DEBUG: noop cycles: %u\n", noop_cycles);

  fclose(fp);
}
コード例 #2
0
ファイル: mttest.c プロジェクト: dhaley/dcp
int
main(int argc, char **argv, char **envp)
{
	int	i;

	scale_init(argc, argv);

#define ALIGNMENTOFFSET 2 /* adjust alignment */
        i = sizeof(workStruct_t)*
            (narrays+ALIGNMENTOFFSET);
        element = memalign(64, i);
	if ( element == NULL ) {
	    perror("calloc( narrays, sizeof(workStruct_t) )");
	    exit(1);
	}
        compute_set(element);
        memset(element, 0, i);
        element+=ALIGNMENTOFFSET;

#ifdef SELFTEST
	start_prof();
#endif

	fid = open_output("mttest.acct");
	if (job_index == -1) {
		i = (sizeof(scripttab)/sizeof( struct scripttab) -1 );
	} else {
		i = 1;
	}
	fprintf(fid, "Number of tests: %d  Repeat count: %d\n",
		i, repeat_count);

	fprintf(fid, "MHz: %d\n", get_clock_rate() );

	fprintf(fid,
	    "X    Incl. Total   Incl. CPU   Incl. Sync. Wait   Name (%s)\n",
		model);
	fflush(fid);
  
	name = strdup(argv[0]);

	init_micro_acct();
#if OS(Solaris) 
	if(uniprocessor != 0) {
	    /* call processor_bind to force single CPU */
	    processor_bind(P_PID, P_MYID, cpuid, NULL);
	}
#endif /* OS(Solaris) */

#ifdef SOLARIS
	sema_init(&global_sema_lock, count, USYNC_THREAD, NULL);
#endif
#ifdef POSIX
	pthread_attr_init(&attr);

    #ifdef BOUND
	pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    #endif

	sem_init(&global_sema_lock, 0, count);
#endif

#if 0
	if ((s5_sema_id = semget(IPC_PRIVATE, 1, 0600)) == -1)
		perror("semget: IPC_PRIVATE");

	arg.val = count;
	if (semctl(s5_sema_id, 0, SETVAL, arg) == -1)
		perror("semctl: SETVAL");
#endif

	resolve_symbols();

	i = locktest();
#if 0
	if (semctl(s5_sema_id, 0, IPC_RMID) == -1)
		perror("semctl: IPC_RMID");
#endif

	close_file(fid);

#ifdef SELFTEST
        finish_prof();
#endif

	return 0;
}