|
@@ -225,28 +225,20 @@ void cpu_map__put(struct cpu_map *map)
|
|
|
cpu_map__delete(map);
|
|
|
}
|
|
|
|
|
|
-int cpu_map__get_socket_id(int cpu)
|
|
|
+static int cpu__get_topology_int(int cpu, const char *name, int *value)
|
|
|
{
|
|
|
- FILE *fp;
|
|
|
- const char *mnt;
|
|
|
char path[PATH_MAX];
|
|
|
- int socket_id, ret;
|
|
|
-
|
|
|
- mnt = sysfs__mountpoint();
|
|
|
- if (!mnt)
|
|
|
- return -1;
|
|
|
|
|
|
snprintf(path, PATH_MAX,
|
|
|
- "%s/devices/system/cpu/cpu%d/topology/physical_package_id",
|
|
|
- mnt, cpu);
|
|
|
+ "devices/system/cpu/cpu%d/topology/%s", cpu, name);
|
|
|
|
|
|
- fp = fopen(path, "r");
|
|
|
- if (!fp)
|
|
|
- return -1;
|
|
|
- ret = fscanf(fp, "%d", &socket_id);
|
|
|
- fclose(fp);
|
|
|
+ return sysfs__read_int(path, value);
|
|
|
+}
|
|
|
|
|
|
- return ret == 1 ? socket_id : -1;
|
|
|
+int cpu_map__get_socket_id(int cpu)
|
|
|
+{
|
|
|
+ int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value);
|
|
|
+ return ret ?: value;
|
|
|
}
|
|
|
|
|
|
int cpu_map__get_socket(struct cpu_map *map, int idx)
|
|
@@ -299,26 +291,8 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
|
|
|
|
|
|
int cpu_map__get_core_id(int cpu)
|
|
|
{
|
|
|
- FILE *fp;
|
|
|
- const char *mnt;
|
|
|
- char path[PATH_MAX];
|
|
|
- int core_id, ret;
|
|
|
-
|
|
|
- mnt = sysfs__mountpoint();
|
|
|
- if (!mnt)
|
|
|
- return -1;
|
|
|
-
|
|
|
- snprintf(path, PATH_MAX,
|
|
|
- "%s/devices/system/cpu/cpu%d/topology/core_id",
|
|
|
- mnt, cpu);
|
|
|
-
|
|
|
- fp = fopen(path, "r");
|
|
|
- if (!fp)
|
|
|
- return -1;
|
|
|
- ret = fscanf(fp, "%d", &core_id);
|
|
|
- fclose(fp);
|
|
|
-
|
|
|
- return ret == 1 ? core_id : -1;
|
|
|
+ int value, ret = cpu__get_topology_int(cpu, "core_id", &value);
|
|
|
+ return ret ?: value;
|
|
|
}
|
|
|
|
|
|
int cpu_map__get_core(struct cpu_map *map, int idx)
|