Beispiel #1
0
void
inittime()
{
  /* start the time clock at zero */
  sttime = 0.;
  sttime = get_cputime();
}
Beispiel #2
0
int
main(int ac, char **av)
{
	double srt;
	double pollrate;
	int ch;
	char buf[64];
	int monbat;

	srt = 8.0;	/* time for samples - 8 seconds */
	pollrate = 1.0;	/* polling rate in seconds */

	while ((ch = getopt(ac, av, "b:cdefh:l:p:r:tu:B:L:P:QT:")) != -1) {
		switch(ch) {
		case 'b':
			BackLightPct = strtol(optarg, NULL, 10);
			break;
		case 'c':
			AdjustCstate = 1;
			break;
		case 'd':
			DebugOpt = 1;
			break;
		case 'e':
			HasPerfbias = 1;
			break;
		case 'f':
			AdjustCpuFreq = 0;
			break;
		case 'h':
			HighestCpuFreq = strtol(optarg, NULL, 10);
			break;
		case 'l':
			LowestCpuFreq = strtol(optarg, NULL, 10);
			break;
		case 'p':
			Hysteresis = (int)strtol(optarg, NULL, 10);
			break;
		case 'r':
			pollrate = strtod(optarg, NULL);
			break;
		case 't':
			TurboOpt = 0;
			break;
		case 'u':
			TriggerUp = (double)strtol(optarg, NULL, 10) / 100;
			break;
		case 'B':
			BatLifeMin = strtol(optarg, NULL, 10);
			break;
		case 'L':
			BatShutdownLingerSet = strtol(optarg, NULL, 10);
			if (BatShutdownLingerSet < 0)
				BatShutdownLingerSet = 0;
			break;
		case 'P':
			BatLifePollIntvl = strtol(optarg, NULL, 10);
			break;
		case 'Q':
			BatShutdownAudioAlert = 0;
			break;
		case 'T':
			srt = strtod(optarg, NULL);
			break;
		default:
			usage();
			/* NOT REACHED */
		}
	}
	ac -= optind;
	av += optind;

	setlinebuf(stdout);

	/* Get number of cpus */
	get_ncpus();

	if (0 > Hysteresis || Hysteresis > 99) {
		fprintf(stderr, "Invalid hysteresis value\n");
		exit(1);
	}

	if (0 > TriggerUp || TriggerUp > 1) {
		fprintf(stderr, "Invalid load limit value\n");
		exit(1);
	}

	if (BackLightPct > 100 || BackLightPct <= 0) {
		fprintf(stderr, "Invalid backlight setting, ignore\n");
		BackLightPct = 100;
	}

	TriggerDown = TriggerUp - (TriggerUp * (double) Hysteresis / 100);

	/*
	 * Make sure powerd is not already running.
	 */
	PowerFd = open("/var/run/powerd.pid", O_CREAT|O_RDWR, 0644);
	if (PowerFd < 0) {
		fprintf(stderr,
			"Cannot create /var/run/powerd.pid, "
			"continuing anyway\n");
	} else {
		if (flock(PowerFd, LOCK_EX|LOCK_NB) < 0) {
			fprintf(stderr, "powerd is already running\n");
			exit(1);
		}
	}

	/*
	 * Demonize and set pid
	 */
	if (DebugOpt == 0) {
		daemon(0, 0);
		openlog("powerd", LOG_CONS | LOG_PID, LOG_DAEMON);
	}

	if (PowerFd >= 0) {
		ftruncate(PowerFd, 0);
		snprintf(buf, sizeof(buf), "%d\n", (int)getpid());
		write(PowerFd, buf, strlen(buf));
	}

	/* Do we need to monitor battery life? */
	if (BatLifePollIntvl <= 0)
		monbat = 0;
	else
		monbat = has_battery();

	/* Do we have perfbias(4)? */
	if (HasPerfbias)
		HasPerfbias = has_perfbias();

	/* Could we adjust C-state? */
	if (AdjustCstate)
		AdjustCstate = probe_cstate();

	/*
	 * Wait hw.acpi.cpu.px_dom* sysctl to be created by kernel.
	 *
	 * Since hw.acpi.cpu.px_dom* creation is queued into ACPI
	 * taskqueue and ACPI taskqueue is shared across various
	 * ACPI modules, any delay in other modules may cause
	 * hw.acpi.cpu.px_dom* to be created at quite a later time
	 * (e.g. cmbat module's task could take quite a lot of time).
	 */
	for (;;) {
		/* Prime delta cputime calculation. */
		get_cputime(pollrate);

		/* Wait for all cpus to appear */
		if (acpi_get_cpupwrdom())
			break;
		usleep((int)(pollrate * 1000000.0));
	}

	/*
	 * Catch some signals so that max performance could be restored.
	 */
	signal(SIGINT, sigintr);
	signal(SIGTERM, sigintr);

	/* Initialize performance states */
	init_perf();

	srt = srt / pollrate;	/* convert to sample count */
	if (DebugOpt)
		printf("samples for downgrading: %5.2f\n", srt);

	/*
	 * Monitoring loop
	 */
	while (!stopped) {
		/*
		 * Monitor performance
		 */
		get_cputime(pollrate);
		mon_perf(srt);

		/*
		 * Monitor battery
		 */
		if (monbat)
			monbat = mon_battery();

		usleep((int)(pollrate * 1000000.0));
	}

	/*
	 * Set to maximum performance if killed.
	 */
	syslog(LOG_INFO, "killed, setting max and exiting");
	restore_perf();
	restore_backlight();

	exit(0);
}
Beispiel #3
0
int
main (int argc, char *argv[])
{
  struct stats s, s0;
  int print = 0;

  FILE *fp = fopen(STATS_FILE, "rb");
  if (fp != NULL)
    {
      fread(&s0, sizeof(struct stats), 1, fp);
      fclose(fp);
      print = 1;
    }

  get_times(&s);
  get_temp(&s);
  get_mail(&s);
  get_cputime(&s);
  get_power(&s);
  get_mem(&s);
  get_txrx(&s);

  if (print)
    {
      int i;
      double temp = 1e-3*s.temp;
      double charge = 100*s.charge_now/s.charge_full;
      double tx = (s.tx-s0.tx)/(s.t-s0.t);
      double rx = (s.rx-s0.rx)/(s.t-s0.t);
      double mem = s.mem*9.5367431640625e-07;
      double cpu_pct[MAX_CPUS];
      for (i=0; i < s.n_cpus; i++)
        {
          double idle = s.cpu_idle[i] - s0.cpu_idle[i];
          double total = s.cpu_total[i] - s0.cpu_total[i];
          cpu_pct[i] = 1-idle/total;
        }

      fputs(" [", stdout);
      begin_color(color_bar);
      fputs(th_spc, stdout);
      for (i=0; i < s.n_cpus; i++)
        {
          print_bar(cpu_pct[i]);
          fputs(th_spc, stdout);
        }
      end_color();
      fputc(']', stdout);

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      end_color();

      begin_color_coded (temp, LO_TEMP, HI_TEMP);
      num_print (temp, 3, degc);
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      begin_color_coded (mem, LO_MEM, HI_MEM);
      num_print (mem, 4, "MB");
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      begin_color (s.ac_connected ? "cyan" : "red");
      fputs(s.ac_connected ? acon : acoff, stdout);
      fputc(' ', stdout);
      end_color();
      begin_color_coded (100-charge, LO_CHARGE, HI_CHARGE);
      num_print (charge, 3, "%");
      end_color();

      begin_color (color_div);
      fputs(spc, stdout);
      fputs(divider, stdout);
      end_color();

      begin_color_coded (tx, LO_RATE, HI_RATE);
      num_print (tx, 0, "B/s  ");
      end_color();
      begin_color (color_up);
      fputs(up, stdout);
      end_color();
      begin_color_coded (rx, LO_RATE, HI_RATE);
      fputs(spc, stdout);
      num_print (rx, 0, "B/s  ");
      end_color();
      begin_color (color_down);
      fputs(down, stdout);
      end_color();

      fputs(spc, stdout);
      begin_color (color_div);
      fputs(divider, stdout);
      fputs(spc, stdout);
      end_color();

      if (s.gmail)
        {
          begin_color (color_mail);
          printf ("%2d/g", s.gmail);
          end_color();
        }
          
      if (s.uiucmail)
        {
          begin_color (color_mail);
          printf ("%2d/u", s.uiucmail);
          end_color();
        }

      if (s.uiucmail || s.gmail)
        {
          fputs(spc, stdout);
          begin_color (color_div);
          fputs(divider, stdout);
          fputs(spc, stdout);
          end_color();
        }
      
      begin_color (color_date);
      fputs(s.date, stdout);
      end_color();

      fputs(spc, stdout);
      begin_color (color_div);
      fputs(divider, stdout);
      end_color();
    }

  fp = fopen(STATS_FILE, "wb");
  fwrite(&s, sizeof(struct stats), 1, fp);
  fclose(fp);

  return 0;
}
Beispiel #4
0
void
itime()
{
  apush(createreal(get_cputime()));
}
Beispiel #5
0
int main(int argc, char** argv)
{
  // Parameters
  std::string filename = "system.dat";
  float temperature = 1.0f;
  float epsilon = 0;
  uint64_t seed = 0;
  int phi_card = 0;

  // Get parameters
  for(int i = 1; i < argc; i++)
  {
    if(strlen(argv[i]) != 2 || argv[i][0] != '-' || i+1 == argc)
    {
      std::cout << "Invalid option " << argv[i] << std::endl;
      return EXIT_FAILURE;
    }

    switch(argv[i][1])
    {
      case 'o': // Output file
        filename = argv[i+1];
        break;
      case 't': // Temperature
        temperature = std::stof(argv[i+1]);
        break;
      case 'e': // Epsilon
        epsilon = std::stof(argv[i+1]);
        break;
      case 's': // RNG Seed
        seed = std::stoull(argv[i+1]);
        break;
      case 'p': // Numer of Phi card to use
        phi_card = std::stoi(argv[i+1]);
        break;
      default:
        std::cout << "Invalid option " << argv[i] << std::endl;
        return EXIT_FAILURE;
    }
    i++;
  }

  // Required timesteps
  std::set<uint64_t> times;
  uint64_t maxT = 10000000;
  for(uint64_t j = 1; j <= maxT/10; j*=10)
  {
    times.insert(j);
    for(uint64_t i = 1; i < maxT; i+=(i+1)/2)
      times.insert(j+i);
  }
  size_t system_size = 2*4*N*N*N;
  std::cout << "Timesteps to save: " << times.size() << std::endl;
  std::cout << "Space required: " << times.size()*system_size/1024/1024 << " MB" << std::endl;

  // Info
  float field = epsilon * temperature;
  std::cout << "Temperature: " << temperature << std::endl;
  std::cout << "Field: " << field << std::endl;
  std::cout << "Seed: " << seed << std::endl;
  std::cout << "Dimension: " << N << "^3" << std::endl;

  // Initialize
  uint32_t* systemState = (uint32_t*)_mm_malloc(system_size, 64);
  uint32_t* system0;
  #pragma offload target(mic:phi_card)       \
    in(systemState : length(2*N*N*N) ALLOC)  \
    nocopy(system0)
  {
    system0 = (uint32_t*)_mm_malloc(sizeof(uint32_t)*(N*N*N*4 + OFFSET), ALIGN);
    uint32_t* system1 = system0 + N*N*N + OFFSET/4;
    uint32_t* field0 = system1 + N*N*N + OFFSET/4;
    uint32_t* field1 = field0 + N*N*N + OFFSET/4;
    setParameters(temperature, field);
  
    randomize(system0, seed++);
    randomize(system1, seed++);
    randomize(field0, seed++);
    randomize(field1, seed++);
  }

  // Open output file
  SystemManager mgr;
  mgr.CreateFile(filename, N, 2*4);
  mgr.SetParameters(temperature, field);

  // Set precision
  std::cout.precision(2);
  std::cout << std::fixed;
  
  // Start simulation
  times.insert(0);
  auto prev = times.begin();
  uint64_t maxTime = *times.rbegin();
  double startTime = get_cputime();
  for(auto it = std::next(prev); it != times.end(); ++it)
  {
    // Necessary steps for next system
    uint64_t steps = *it - *prev;
    prev = it;
    
    // Do steps
    #pragma offload target(mic:phi_card)        \
      out(systemState : length(2*N*N*N) REUSE)  \
      nocopy(system0)
    {
      uint32_t* system1 = system0 + N*N*N + OFFSET/4;
      uint32_t* field0 = system1 + N*N*N + OFFSET/4;
      uint32_t* field1 = field0 + N*N*N + OFFSET/4;

      for(uint64_t i = 0; i < steps; ++i)
      {
        spinFlip(system0, system1, field0, seed++);
        spinFlip(system1, system0, field1, seed++);
      }
      
      // Rearrange system for output
      for(unsigned int z = 0; z < N; z++)
      for(unsigned int y = 0; y < N; y++)
      for(unsigned int x = 0; x < N; x++)
      {
        if((x+y+z)%2)
        {
          systemState[2*(z*N*N + y*N + x)]   = system0[z*N*N + y*N + x];
          systemState[2*(z*N*N + y*N + x)+1] = system1[z*N*N + y*N + x];
        }
        else
        {
          systemState[2*(z*N*N + y*N + x)]   = system1[z*N*N + y*N + x];
          systemState[2*(z*N*N + y*N + x)+1] = system0[z*N*N + y*N + x];
        }
      }
    }
    
    // Write out system
    mgr.SaveSystem(*it, reinterpret_cast<const char*>(systemState), system_size);
    
    // Statistics
    std::cout << "\r" << *it * 100.f/maxTime << "% finished" << std::flush;
  }
  
  double stopTime = get_cputime();
  double delta = stopTime-startTime;
  double timePerSpin = delta/64/N/N/N/maxTime;
  std::cout << "\r" << 100.0 << "% finished" << std::endl;
  std::cout << "Elapsed time: " << delta << std::endl;
  std::cout << "Time per spin: " << timePerSpin*1E12 << " ps" << std::endl;
  
  // Free memory
  #pragma offload target(mic:phi_card)       \
    out(systemState : length(2*N*N*N) FREE)  \
    nocopy(system0)
  {
    _mm_free(system0);
  }
}