Exemple #1
0
//! Collect values of counters
static void intel_snb_pcu_collect(struct stats_type *type)
{
  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_cores = 0;
    snprintf(cpu, sizeof(cpu), "%d", i);
    topology(cpu, &pkg_id, &core_id, &smt_id, &nr_cores);
  
    if (core_id == 0 && smt_id == 0)
      intel_snb_pcu_collect_socket(type, cpu, pkg_id);
  }
}
//! Collect values of counters
static void intel_snb_pcu_collect(struct stats_type *type)
{
    // CPUs 0 and 8 have core_id 0 on Stampede at least

    int i;
    for (i = 0; i < nr_cpus; i++) {
        char cpu[80];
        char core_id_path[80];
        int core_id = -1;

        char socket[80];
        char socket_id_path[80];
        int socket_id = -1;

        char pcu[80];

        /* Only collect 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;

        /* Get socket number. */
        snprintf(socket_id_path, sizeof(socket_id_path),
                 "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i);
        if (pscanf(socket_id_path, "%d", &socket_id) != 1) {
            ERROR("cannot read socket id file `%s': %m\n", socket_id_path);
            continue;
        }

        snprintf(cpu, sizeof(cpu), "%d", i);
        snprintf(socket, sizeof(socket), "%d", socket_id);
        if (cpu_is_sandybridge(cpu))
        {
            snprintf(pcu, sizeof(pcu), "%d", socket_id);
            intel_snb_pcu_collect_socket(type, cpu, pcu);
        }
    }
}