Ejemplo n.º 1
0
/**
 * cpufreq_apply_cooling - function to apply frequency clipping.
 * @cpufreq_device: cpufreq_cooling_device pointer containing frequency
 *	clipping data.
 * @cooling_state: value of the cooling state.
 *
 * Function used to make sure the cpufreq layer is aware of current thermal
 * limits. The limits are applied by updating the cpufreq policy.
 *
 * Return: 0 on success, an error code otherwise (-EINVAL in case wrong
 * cooling state).
 */
static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
				 unsigned long cooling_state)
{
	unsigned int cpuid, clip_freq;
	struct cpumask *mask = &cpufreq_device->allowed_cpus;
	unsigned int cpu = cpumask_any(mask);


	/* Check if the old cooling action is same as new cooling action */
	if (cpufreq_device->cpufreq_state == cooling_state)
		return 0;

	clip_freq = get_cpu_frequency(cpu, cooling_state);
	if (!clip_freq)
		return -EINVAL;

	cpufreq_device->cpufreq_state = cooling_state;
	cpufreq_device->cpufreq_val = clip_freq;
	notify_device = cpufreq_device;

	for_each_cpu(cpuid, mask) {
		if (is_cpufreq_valid(cpuid))
			cpufreq_update_policy(cpuid);
	}

	notify_device = NOTIFY_INVALID;

	return 0;
}
Ejemplo n.º 2
0
/* Dumps the DRAM configuration. */
void dram_dump_config(FILE *stream)
{
  fprintf(stream, "===================== DRAM config ======================\n");
  print_dram_type( dram_system.config.dram_type, stream );
  fprintf(stream, "  dram_frequency: %d MHz\n", dram_system.config.dram_type != FBD_DDR2 ? dram_system.config.memory_frequency : dram_system.config.dram_frequency );
  fprintf(stream, "  memory_frequency: %d MHz\n", dram_system.config.memory_frequency);
  fprintf(stream, "  cpu_frequency: %d MHz\n", get_cpu_frequency(global_biu));
  fprintf(stream, "  dram_clock_granularity: %d\n", dram_system.config.dram_clock_granularity);
  fprintf(stream, "  memfreq2cpufreq ration: %f \n", (float)global_biu->mem2cpu_clock_ratio);
  fprintf(stream, "  memfreq2dramfreq ration: %f \n", dram_system.config.memory2dram_freq_ratio);
  fprintf(stream, "  critical_word_first_flag: %d\n", dram_system.config.critical_word_first_flag);
  print_pa_mapping_policy( dram_system.config.physical_address_mapping_policy, stream);
  print_row_policy( dram_system.config.row_buffer_management_policy, stream);
  print_trans_policy( get_transaction_selection_policy(global_biu), stream);
  fprintf(stream, "  cacheline_size: %d\n", dram_system.config.cacheline_size);
  fprintf(stream, "  chan_count: %d\n", dram_system.config.channel_count);
  fprintf(stream, "  rank_count: %d\n", dram_system.config.rank_count);
  fprintf(stream, "  bank_count: %d\n", dram_system.config.bank_count);
  fprintf(stream, "  row_count: %d\n", dram_system.config.row_count);
  fprintf(stream, "  col_count: %d\n", dram_system.config.col_count);
  fprintf(stream, "  buffer count: %d\n", dram_system.config.up_buffer_cnt);
  fprintf(stream, "  t_rcd: %d\n", dram_system.config.t_rcd);
  fprintf(stream, "  t_cac: %d\n", dram_system.config.t_cac);
  fprintf(stream, "  t_cas: %d\n", dram_system.config.t_cas);
  fprintf(stream, "  t_ras: %d\n", dram_system.config.t_ras);
  fprintf(stream, "  t_rp: %d\n", dram_system.config.t_rp);
  fprintf(stream, "  t_cwd: %d\n", dram_system.config.t_cwd);
  fprintf(stream, "  t_rtr: %d\n", dram_system.config.t_rtr);
  fprintf(stream, "  t_burst: %d\n", dram_system.config.t_burst);
  fprintf(stream, "  t_rc: %d\n", dram_system.config.t_rc);
  fprintf(stream, "  t_rfc: %d\n", dram_system.config.t_rfc);
  fprintf(stream, "  t_al: %d\n", dram_system.config.t_al);
  fprintf(stream, "  t_wr: %d\n", dram_system.config.t_wr);
  fprintf(stream, "  t_rtp: %d\n", dram_system.config.t_rtp);
  fprintf(stream, "  t_dqs: %d\n", dram_system.config.t_dqs);

  // FBDIMM RELATED
  fprintf(stream, "  t_amb_up: %d\n", dram_system.config.t_amb_up);
  fprintf(stream, "  t_amb_down: %d\n", dram_system.config.t_amb_down);
  fprintf(stream, "  t_bundle: %d\n", dram_system.config.t_bundle);
  fprintf(stream, "  t_bus: %d\n", dram_system.config.t_bus);

  fprintf(stream, "  posted_cas: %d\n", dram_system.config.posted_cas_flag);
  fprintf(stream, "  row_command_duration: %d\n", dram_system.config.row_command_duration);
  fprintf(stream, "  col_command_duration: %d\n", dram_system.config.col_command_duration);

  // REFRESH POLICY
  fprintf(stream, "  auto_refresh_enabled: %d\n", dram_system.config.auto_refresh_enabled);
  fprintf(stream, "  auto_refresh_policy: %d\n", dram_system.config.refresh_policy);
  fprintf(stream, "  refresh_time: %f\n", dram_system.config.refresh_time);
  fprintf(stream, "  refresh_cycle_count: %d\n", dram_system.config.refresh_cycle_count);

  fprintf(stream, "  strict_ordering_flag: %d\n", dram_system.config.strict_ordering_flag);

  // DEBUG
  fprintf(stream, "  dram_debug: %d\n", dram_system.config.dram_debug);
  fprintf(stream, "  addr_debug: %d\n", dram_system.config.addr_debug);
  fprintf(stream, "  wave_debug: %d\n", dram_system.config.wave_debug);
  fprintf(stream, "========================================================\n\n\n");
}
Ejemplo n.º 3
0
void _init_uart(int baudrate)
{
	unsigned int frequency, reload_value, fdv;
	unsigned int dfreq;

	/* initialize vector and trap tables */
	_init_vectab();

	/* Install handlers for transmit and receive interrupts.  */
	_install_int_handler(XMIT_INTERRUPT, (void (*) (int)) _uart_tx_handler, 0);
	_install_int_handler(RECV_INTERRUPT, (void (*) (int)) _uart_rx_handler, 0);

	/* Set TXD to "output" and "high" */
	/* set P3.1 to output and high */
	port->IOCR0.bits.PC1 = OUT_PPALT1;
	port->OMR.bits.PS1 = 1;

	/* Compute system frequency and reload value for ASC0 */
	frequency = get_cpu_frequency();

	if (baudrate <= 0)
		baudrate = BAUDRATE;

	/*  reload_value = fdv/512 * freq/16/baudrate -1  ==>
		reload_value = (512*freq)/(baudrate * 512*16) - 1
		fdv = (reload_value + 1) * (baudrate*512*16/freq)
		reload_value = (frequency / 32) / BAUDRATE - 1;
	*/
	reload_value = (frequency / (baudrate * 16)) - 1;
	dfreq = frequency / (16*512);
	fdv = (reload_value + 1) * (unsigned int)baudrate / dfreq;

	/* Enable ASCn */
	unlock_wdtcon();
	asc->CLC.bits.RMC = 1;
	asc->CLC.bits.DISR = 0;
	lock_wdtcon();

	/* Program ASCn */
	asc->CON.reg = 0;
	asc->BG.reg  = reload_value;
	asc->FDV.reg = fdv;

	asc->TSRC.reg = ASCn_TSRC_SRE_MASK | XMIT_INTERRUPT;
	asc->RSRC.reg = ASCn_RSRC_SRE_MASK | RECV_INTERRUPT;

	asc->CON.bits.M = ASCM_8ASYNC;
	asc->CON.bits.R = 1;
	asc->CON.bits.REN = 1;
	asc->CON.bits.FDE = 1;
}
Ejemplo n.º 4
0
static void
fix_cpu_node( void )
{
	static struct { int id; char *resname; } ntab[] = {
		{1,	"ppc601_cpu"}, 
		{3,	"ppc603_cpu"}, 
		{4,	"ppc604_cpu"},
		{8,	"ppc750_cpu"}, 
		{0xc,	"ppc7400_cpu"},
		{0x800c,"ppc7410_cpu"},
		{0x8000,"ppc7450_cpu"},
		{0,NULL}
	}, *ci;
	mol_device_node_t *dn, *par;
	int tbase, busf, clockf;
	char *filename;
	
	for( ci=&ntab[0]; ci->id && ci->id != mregs->processor; ci++ )
		;
	assert(ci->resname);

	/* add the correct CPU node to the device tree */
	par = (dn=prom_find_type("cpu"))? dn->parent : prom_find_type("cpus");
	assert(par);
	while( (dn=prom_find_type("cpu")) )
		prom_delete_node( dn );
	if( !(filename=get_str_res(ci->resname)) || !prom_import_node(par, filename) )
		fatal("import of cpu device node '%s' [%s] failed", filename, ci->resname );

	tbase = get_timebase_frequency();
	busf = get_bus_frequency();
	clockf = get_cpu_frequency();

	/* If the bus frequency check returned 0, guess it's 4 * timebase
	 * This is a valid guess for older G4s and lower */
	if (busf == 0) busf = tbase * 4;

	if( !(dn=prom_find_type("cpu")) )
		fatal("CPU node missing");	/* should never occur */
	prom_add_property( dn, "timebase-frequency", (char*)&tbase, sizeof(int) );
	prom_add_property( dn, "bus-frequency", (char*)&busf, sizeof(int) );
	prom_add_property( dn, "clock-frequency", (char*)&clockf, sizeof(int) );

	printm("Timebase: %02d.%02d MHz, Bus: %02d.%02d MHz, Clock: %02d MHz\n",
	       (tbase / 1000000), ((tbase/10000) % 100),
	       (busf / 1000000), ((busf/10000) % 100),
	       clockf / 1000000 );
}
Ejemplo n.º 5
0
  MachineInfo() {
    m_cpu_num = sysconf(_SC_NPROCESSORS_CONF);
    m_cpu_frequencies = get_cpu_frequency_from_file("/proc/cpuinfo", m_cpu_num);

    if (m_cpu_frequencies)
      return;
    m_cpu_frequencies = new int64[m_cpu_num];
    for (int i = 0; i < m_cpu_num; i++) {
      cpu_set_t prev_mask;
      sched_getaffinity(0, sizeof(cpu_set_t), &prev_mask);
      BindToCPU(i);
      // Make sure the current process gets scheduled to the target cpu. This
      // might not be necessary though.
      usleep(0);
      m_cpu_frequencies[i] = get_cpu_frequency();
      sched_setaffinity(0, sizeof(cpu_set_t), &prev_mask);
    }
  }
Ejemplo n.º 6
0
// init a timer handle and return a pointer to it;
// return NULL in case of error
timer_handle *timer_init(void)
{
  timer_handle *handle;
  
  // allocte the timer handle
  if((handle = (timer_handle *)malloc(sizeof(timer_handle))) == NULL) 
    {
      WARNING("Could not allocate memory for the timer");
      return NULL;
    }

  // store CPU frequency
  handle->cpu_frequency = get_cpu_frequency();

  // reset the timer so that 'zero' has a reasonable value
  timer_reset(handle);

  return handle;
}
Ejemplo n.º 7
0
void _init_uart(int baudrate)
{
	unsigned int frequency, reload_value, fdv;
	unsigned int dfreq;

	/* Set TXD to "output" and "high" */
	/* set P5.1 to output and high */
	port->IOCR0.bits.PC1 = OUT_PPALT1;
	port->OMR.bits.PS1 = 1;

	/* Compute system frequency and reload value for ASC0 */
	frequency = get_cpu_frequency();

	if (baudrate <= 0)
		baudrate = BAUDRATE;

	/*  reload_value = fdv/512 * freq/16/baudrate -1  ==>
		reload_value = (512*freq)/(baudrate * 512*16) - 1
		fdv = (reload_value + 1) * (baudrate*512*16/freq)
		reload_value = (frequency / 32) / BAUDRATE - 1;
	*/
	reload_value = (frequency / (baudrate * 16)) - 1;
	dfreq = frequency / (16*512);
	fdv = (reload_value + 1) * (unsigned int)baudrate / dfreq;

	/* Enable ASC0 */
	unlock_wdtcon();
	asc->CLC.bits.RMC = 1;
	asc->CLC.bits.DISR = 0;
	lock_wdtcon();

	/* Program ASC0 */
	asc->CON.reg = 0;
	asc->BG.reg  = reload_value;
	asc->FDV.reg = fdv;
	asc->CON.bits.M = ASCM_8ASYNC;
	asc->CON.bits.R = 1;
	asc->CON.bits.REN = 1;
	asc->CON.bits.FDE = 1;

	START_TX;
}
Ejemplo n.º 8
0
void check_scheduling(void)
{
	uint32_t prio = get_highest_priority();
	task_t* curr_task = per_core(current_task);

	if (prio > curr_task->prio) {
		reschedule();
#ifdef DYNAMIC_TICKS
	} else if ((prio > 0) && (prio == curr_task->prio)) {
		// if a task is ready, check if the current task runs already one tick (one time slice)
		// => reschedule to realize round robin

		const uint64_t diff_cycles = get_rdtsc() - curr_task->last_tsc;
		const uint64_t cpu_freq_hz = 1000000ULL * (uint64_t) get_cpu_frequency();

		if (((diff_cycles * (uint64_t) TIMER_FREQ) / cpu_freq_hz) > 0) {
			LOG_DEBUG("Time slice expired for task %d on core %d. New task has priority %u.\n", curr_task->id, CORE_ID, prio);
			reschedule();
		}
#endif
	}
}
Ejemplo n.º 9
0
int main (int argc, char **argv)
{
  if (argc != 4) {
    printf ("Usage: %s <basisset> <xyz>\n", argv[0]);
    return -1;
  }
  
  const uint64_t freq = get_cpu_frequency();
  const int nthreads = atoi(argv[3]);
  /*
#ifdef _OPENMP
  omp_set_num_threads(nthreads);
#else
  assert(nthreads == 1);
#endif
  */
  // load basis set
  BasisSet_t basis;
  CInt_createBasisSet(&basis);
  CInt_loadBasisSet(basis, argv[1], argv[2]);
  
  printf("Molecule info:\n");
  printf("  #Atoms\t= %d\n", CInt_getNumAtoms(basis));
  printf("  #Shells\t= %d\n", CInt_getNumShells(basis));
  printf("  #Funcs\t= %d\n", CInt_getNumFuncs(basis));
  printf("  #OccOrb\t= %d\n", CInt_getNumOccOrb(basis));

  ERD_t erd;
  CInt_createERD(basis, &erd, nthreads);

  printf("Computing Lazy Evaluation Cholesky of ERIs\n");
  // reset profiler
  //  erd_reset_profile();

  int n = CInt_getNumFuncs(basis);
  int n2 = n * n;
  int n3 = n2 * n;
  int n4 = n3 * n;
  
  double* G_ERI;
  double tol = 1e-6;
  int max_rank = n2;
  //int max_rank = (1-floor(log10(tol)))*n;
  int rank;
  const uint64_t start_clock = __rdtsc();
  cholERI(basis, erd, &G_ERI, tol, max_rank, &rank);
  const uint64_t end_clock = __rdtsc();
  const uint64_t total_ticks = end_clock - start_clock;
  const double timepass = ((double) total_ticks) / freq;
  printf("Done\n");
  printf("Total GigaTicks: %.3lf, freq = %.3lf GHz\n", (double) (total_ticks) * 1.0e-9, (double)freq/1.0e9);
  printf("Total time: %.4lf secs\n", timepass);

  printf("n: %d, rank: %d, 7n: %d, n2: %d\n",n,rank,7*n,n2);
  double* diag = (double*) malloc(n2*sizeof(double));
  computeDiag(basis, erd, diag);
  for (int i = 0; i < n2; i++) {
    double aii = 0;
    for (int j = 0; j < rank; j++) {
      aii += G_ERI[i+j*n2] * G_ERI[i+j*n2];
    }
    double abserror2 = (diag[i] - aii)*(diag[i] - aii);
    if (abserror2 > tol)
      printf("i=%d, truth=%1.2e, approx=%1.2e, error: %1.2e\n", i, diag[i], aii, abserror2);
  }
  free(diag);

  printf("Testing accuracy for each shell quartet\n");
  double chol_time_total = 0;
  double CInt_time_total = 0;
  int nshell = CInt_getNumShells(basis);
  int shellIndexM, shellIndexN, shellIndexP, shellIndexQ;
  int correct = 1;
  for (shellIndexM = 0; shellIndexM < nshell; shellIndexM++) {
    for (shellIndexN = 0; shellIndexN < nshell; shellIndexN++) {
      for (shellIndexP = 0; shellIndexP < nshell; shellIndexP++) {
	for (shellIndexQ = 0; shellIndexQ < nshell; shellIndexQ++) {
	  int dimM = CInt_getShellDim (basis, shellIndexM);
	  int dimN = CInt_getShellDim (basis, shellIndexN);
	  int dimP = CInt_getShellDim (basis, shellIndexP);
	  int dimQ = CInt_getShellDim (basis, shellIndexQ);

	  // Compute shell with Cholesky
	  double *cholintegrals;
	  int cholnints;
	  const uint64_t chol_start = __rdtsc();
	  cholComputeShellQuartet(basis, G_ERI, rank, shellIndexM, shellIndexN, shellIndexP, shellIndexQ, &cholintegrals, &cholnints);
	  const uint64_t chol_end = __rdtsc();
	  chol_time_total += ((double) chol_end - chol_start) / freq;
	  
	  // Compute the same shell quartet with CInt
	  double *integrals;
	  int nints;
	  const uint64_t CInt_start = __rdtsc();
	  CInt_computeShellQuartet(basis, erd, 0, shellIndexM, shellIndexN, shellIndexP, shellIndexQ, &integrals, &nints);
	  const uint64_t CInt_end = __rdtsc();
	  CInt_time_total += ((double) CInt_end - CInt_start) / freq;
	  
	  // Compare each integral individually
	  for (int iM = 0; iM < dimM; iM++) {
	    for (int iN = 0; iN < dimN; iN++) {
	      for (int iP = 0; iP < dimP; iP++) {
		for (int iQ = 0; iQ < dimQ; iQ++) {
		  int idx = iM + dimM * (iN + dimN * (iP + dimP *(iQ)));
		  double abserror2 = (integrals[idx] - cholintegrals[idx]);
		  abserror2 = abserror2*abserror2;
		  if (abserror2 > tol) {
		    correct = 0;
		    printf("Integral does not satisfy error tolerance: error = %1.2e\n",abserror2);
		  }
		}
	      }
	    }
	  }
	  free(cholintegrals);
	}
      }
    }
  }
  if (correct) {
    printf("All integrals in all shell quartets satisfy error tolerance\n");
  } else {
    printf("Some integrals did not satisfy error tolerance\n");
  }
  printf("Total time to eval shells from Cholesky factor: %.4lf secs\n", chol_time_total);
  printf("Total time to eval shells with CInt: %.4lf secs\n", CInt_time_total);
  printf("Total time to compute Cholesky factor and eval shells from Cholesky factor: %.4lf secs\n", timepass+chol_time_total);

  printf("Computing Structured Lazy Evaluation Cholesky of ERIs\n");
  double* G_structERI;
  max_rank = (n*(n+1))/2;
  const uint64_t struct_start_clock = __rdtsc();
  structcholERI(basis, erd, &G_structERI, tol, max_rank, &rank);
  const uint64_t struct_end_clock = __rdtsc();
  const uint64_t struct_total_ticks = struct_end_clock - struct_start_clock;
  const double struct_timepass = ((double) struct_total_ticks) / freq;
  printf("Done\n");
  printf("Total GigaTicks: %.3lf, freq = %.3lf GHz\n", (double) (struct_total_ticks) * 1.0e-9, (double)freq/1.0e9);
  printf("Total time: %.4lf secs\n", struct_timepass);
  
  
  double* structdiag = (double*) malloc(max_rank*sizeof(double));
  computeStructDiag(basis, erd, structdiag);
  for (int i = 0; i < max_rank; i++) {
    double aii = 0;
    for (int j = 0; j < rank; j++) {
      aii += G_structERI[i+j*max_rank] * G_structERI[i+j*max_rank];
    }
    double abserror2 = (structdiag[i] - aii)*(structdiag[i] - aii);
    if (abserror2 > tol)
      printf("i=%d, truth=%1.2e, approx=%1.2e, error: %1.2e\n", i, structdiag[i], aii, abserror2);
  }
  free(structdiag);
  printf("Testing accuracy for each shell quartet\n");
  double struct_chol_time_total = 0;
  CInt_time_total = 0;
  correct = 1;
  for (shellIndexM = 0; shellIndexM < nshell; shellIndexM++) {
    for (shellIndexN = 0; shellIndexN < nshell; shellIndexN++) {
      for (shellIndexP = 0; shellIndexP < nshell; shellIndexP++) {
	for (shellIndexQ = 0; shellIndexQ < nshell; shellIndexQ++) {
	  int dimM = CInt_getShellDim (basis, shellIndexM);
	  int dimN = CInt_getShellDim (basis, shellIndexN);
	  int dimP = CInt_getShellDim (basis, shellIndexP);
	  int dimQ = CInt_getShellDim (basis, shellIndexQ);

	  // Compute shell with structured Cholesky
	  double *cholintegrals;
	  int cholnints;
	  const uint64_t struct_chol_start = __rdtsc();
	  structcholComputeShellQuartet(basis, G_structERI, rank, shellIndexM, shellIndexN, shellIndexP, shellIndexQ, &cholintegrals, &cholnints);
	  const uint64_t struct_chol_end = __rdtsc();
	  struct_chol_time_total += ((double) struct_chol_end - struct_chol_start) / freq;
	  
	  // Compute the same shell quartet with CInt  
	  double *integrals;
	  int nints;
	  const uint64_t CInt_start = __rdtsc();
	  CInt_computeShellQuartet(basis, erd, 0, shellIndexM, shellIndexN, shellIndexP, shellIndexQ, &integrals, &nints);
	  const uint64_t CInt_end = __rdtsc();
	  CInt_time_total += ((double) CInt_end - CInt_start) / freq;
	  
	  // Compare each integral individually
	  for (int iM = 0; iM < dimM; iM++) {
	    for (int iN = 0; iN < dimN; iN++) {
	      for (int iP = 0; iP < dimP; iP++) {
		for (int iQ = 0; iQ < dimQ; iQ++) {
		  int idx = iM + dimM * (iN + dimN * (iP + dimP *(iQ)));
		  double abserror2 = (integrals[idx] - cholintegrals[idx]);
		  abserror2 = abserror2*abserror2;
		  if (abserror2 > tol) {
		    correct = 0;
		    printf("Integral does not satisfy error tolerance: error = %1.2e\n",abserror2);
		  }
		}
	      }
	    }
	  }
	  free(cholintegrals);
	}
      }
    }
  }
  if (correct) {
    printf("All integrals in all shell quartets satisfy error tolerance\n");
  } else {
    printf("Some integrals did not satisfy error tolerance\n");
  }
  printf("Total time to eval shells from structured Cholesky factor: %.4lf secs\n", struct_chol_time_total);
  printf("Total time to eval shells with CInt: %.4lf secs\n", CInt_time_total);
  printf("Total time to compute Cholesky factor and eval shells from Cholesky factor: %.4lf secs\n", struct_timepass+struct_chol_time_total);

  free(G_structERI);  
  free(G_ERI);
  return 0;
}
Ejemplo n.º 10
0
 /**
 * This is used to find out the Mhz of the machine for the scale
 * factor.  If there are any problems getting it, we just return 1
 * (the default).
 */
 static unsigned int cpu_frequency() {
     static unsigned int s_scale_factor = get_cpu_frequency();
     return s_scale_factor;
 }