Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf cpu_map: Use sysfs__read_int in get_{core,socket}_id()

We have the tools/lib/ sysfs__read_int() for that, avoid code
duplication.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-fqg6vt5ku72pbf54ljg6tmoy@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+10 -36
+10 -36
tools/perf/util/cpumap.c
··· 225 225 cpu_map__delete(map); 226 226 } 227 227 228 - int cpu_map__get_socket_id(int cpu) 228 + static int cpu__get_topology_int(int cpu, const char *name, int *value) 229 229 { 230 - FILE *fp; 231 - const char *mnt; 232 230 char path[PATH_MAX]; 233 - int socket_id, ret; 234 - 235 - mnt = sysfs__mountpoint(); 236 - if (!mnt) 237 - return -1; 238 231 239 232 snprintf(path, PATH_MAX, 240 - "%s/devices/system/cpu/cpu%d/topology/physical_package_id", 241 - mnt, cpu); 233 + "devices/system/cpu/cpu%d/topology/%s", cpu, name); 242 234 243 - fp = fopen(path, "r"); 244 - if (!fp) 245 - return -1; 246 - ret = fscanf(fp, "%d", &socket_id); 247 - fclose(fp); 235 + return sysfs__read_int(path, value); 236 + } 248 237 249 - return ret == 1 ? socket_id : -1; 238 + int cpu_map__get_socket_id(int cpu) 239 + { 240 + int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value); 241 + return ret ?: value; 250 242 } 251 243 252 244 int cpu_map__get_socket(struct cpu_map *map, int idx) ··· 291 299 292 300 int cpu_map__get_core_id(int cpu) 293 301 { 294 - FILE *fp; 295 - const char *mnt; 296 - char path[PATH_MAX]; 297 - int core_id, ret; 298 - 299 - mnt = sysfs__mountpoint(); 300 - if (!mnt) 301 - return -1; 302 - 303 - snprintf(path, PATH_MAX, 304 - "%s/devices/system/cpu/cpu%d/topology/core_id", 305 - mnt, cpu); 306 - 307 - fp = fopen(path, "r"); 308 - if (!fp) 309 - return -1; 310 - ret = fscanf(fp, "%d", &core_id); 311 - fclose(fp); 312 - 313 - return ret == 1 ? core_id : -1; 302 + int value, ret = cpu__get_topology_int(cpu, "core_id", &value); 303 + return ret ?: value; 314 304 } 315 305 316 306 int cpu_map__get_core(struct cpu_map *map, int idx)