Beispiel #1
0
//! Configure and start counters
static int intel_snb_pcu_begin(struct stats_type *type)
{
  int nr = 0;
  uint64_t pcu_events[4] = {
    FREQ_MAX_TEMP_CYCLES,
    FREQ_MAX_POWER_CYCLES,
    FREQ_MIN_IO_CYCLES,
    FREQ_MIN_SNOOP_CYCLES
  };


  int i;
  for (i = 0; i < nr_cpus; i++) {
    char cpu[80];
    int pkg_id = -1;
    int core_id = -1;
    int smt_id = -1;
    int nr_events;
    int nr_cores = 0;
    snprintf(cpu, sizeof(cpu), "%d", i);
    if (signature(SANDYBRIDGE, cpu, &nr_events)) {      
      topology(cpu, &pkg_id, &core_id, &smt_id, &nr_cores);
      if (core_id == 0 && smt_id == 0)
	if (intel_snb_pcu_begin_socket(cpu, pcu_events,4) == 0)
	  nr++;
    }
  }
  
  if (nr == 0)
    type->st_enabled = 0;

  return nr > 0 ? 0 : -1;
}
//! Configure and start counters
static int intel_snb_pcu_begin(struct stats_type *type)
{
    int nr = 0;

    uint64_t pcu_events[4] = {FREQ_MAX_TEMP_CYCLES,
                              FREQ_MAX_POWER_CYCLES,
                              FREQ_MIN_IO_CYCLES,
                              FREQ_MIN_SNOOP_CYCLES
                             };


    int i;
    for (i = 0; i < nr_cpus; i++) {
        char cpu[80];
        char core_id_path[80];
        int core_id = -1;
        /* Only program uncore counters on core 0 of a socket. */

        snprintf(core_id_path, sizeof(core_id_path), "/sys/devices/system/cpu/cpu%d/topology/core_id", i);
        if (pscanf(core_id_path, "%d", &core_id) != 1) {
            ERROR("cannot read core id file `%s': %m\n", core_id_path); /* errno */
            continue;
        }

        if (core_id != 0)
            continue;

        snprintf(cpu, sizeof(cpu), "%d", i);

        if (cpu_is_sandybridge(cpu))
        {
            if (intel_snb_pcu_begin_socket(cpu, pcu_events,4) == 0)
                nr++; /* HARD */
        }
    }

    return nr > 0 ? 0 : -1;
}