diff options
Diffstat (limited to 'tools/power/cpupower/utils/helpers/topology.c')
-rw-r--r-- | tools/power/cpupower/utils/helpers/topology.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tools/power/cpupower/utils/helpers/topology.c b/tools/power/cpupower/utils/helpers/topology.c index 4eae2c47ba48..216f3e3466ce 100644 --- a/tools/power/cpupower/utils/helpers/topology.c +++ b/tools/power/cpupower/utils/helpers/topology.c | |||
@@ -20,9 +20,8 @@ | |||
20 | #include <helpers/sysfs.h> | 20 | #include <helpers/sysfs.h> |
21 | 21 | ||
22 | /* returns -1 on failure, 0 on success */ | 22 | /* returns -1 on failure, 0 on success */ |
23 | int sysfs_topology_read_file(unsigned int cpu, const char *fname) | 23 | static int sysfs_topology_read_file(unsigned int cpu, const char *fname, int *result) |
24 | { | 24 | { |
25 | unsigned long value; | ||
26 | char linebuf[MAX_LINE_LEN]; | 25 | char linebuf[MAX_LINE_LEN]; |
27 | char *endp; | 26 | char *endp; |
28 | char path[SYSFS_PATH_MAX]; | 27 | char path[SYSFS_PATH_MAX]; |
@@ -31,10 +30,10 @@ int sysfs_topology_read_file(unsigned int cpu, const char *fname) | |||
31 | cpu, fname); | 30 | cpu, fname); |
32 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0) | 31 | if (sysfs_read_file(path, linebuf, MAX_LINE_LEN) == 0) |
33 | return -1; | 32 | return -1; |
34 | value = strtoul(linebuf, &endp, 0); | 33 | *result = strtol(linebuf, &endp, 0); |
35 | if (endp == linebuf || errno == ERANGE) | 34 | if (endp == linebuf || errno == ERANGE) |
36 | return -1; | 35 | return -1; |
37 | return value; | 36 | return 0; |
38 | } | 37 | } |
39 | 38 | ||
40 | struct cpuid_core_info { | 39 | struct cpuid_core_info { |
@@ -82,13 +81,19 @@ int get_cpu_topology(struct cpupower_topology *cpu_top) | |||
82 | for (cpu = 0; cpu < cpus; cpu++) { | 81 | for (cpu = 0; cpu < cpus; cpu++) { |
83 | cpu_top->core_info[cpu].cpu = cpu; | 82 | cpu_top->core_info[cpu].cpu = cpu; |
84 | cpu_top->core_info[cpu].is_online = sysfs_is_cpu_online(cpu); | 83 | cpu_top->core_info[cpu].is_online = sysfs_is_cpu_online(cpu); |
85 | cpu_top->core_info[cpu].pkg = | 84 | if(sysfs_topology_read_file( |
86 | sysfs_topology_read_file(cpu, "physical_package_id"); | 85 | cpu, |
86 | "physical_package_id", | ||
87 | &(cpu_top->core_info[cpu].pkg)) < 0) | ||
88 | return -1; | ||
87 | if ((int)cpu_top->core_info[cpu].pkg != -1 && | 89 | if ((int)cpu_top->core_info[cpu].pkg != -1 && |
88 | cpu_top->core_info[cpu].pkg > cpu_top->pkgs) | 90 | cpu_top->core_info[cpu].pkg > cpu_top->pkgs) |
89 | cpu_top->pkgs = cpu_top->core_info[cpu].pkg; | 91 | cpu_top->pkgs = cpu_top->core_info[cpu].pkg; |
90 | cpu_top->core_info[cpu].core = | 92 | if(sysfs_topology_read_file( |
91 | sysfs_topology_read_file(cpu, "core_id"); | 93 | cpu, |
94 | "core_id", | ||
95 | &(cpu_top->core_info[cpu].core)) < 0) | ||
96 | return -1; | ||
92 | } | 97 | } |
93 | cpu_top->pkgs++; | 98 | cpu_top->pkgs++; |
94 | 99 | ||