diff options
Diffstat (limited to 'tools/perf/util/cpumap.c')
-rw-r--r-- | tools/perf/util/cpumap.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index adc72f09914d..2b32ffa9ebdb 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -38,24 +38,19 @@ static struct cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) | |||
38 | return cpus; | 38 | return cpus; |
39 | } | 39 | } |
40 | 40 | ||
41 | static struct cpu_map *cpu_map__read_all_cpu_map(void) | 41 | struct cpu_map *cpu_map__read(FILE *file) |
42 | { | 42 | { |
43 | struct cpu_map *cpus = NULL; | 43 | struct cpu_map *cpus = NULL; |
44 | FILE *onlnf; | ||
45 | int nr_cpus = 0; | 44 | int nr_cpus = 0; |
46 | int *tmp_cpus = NULL, *tmp; | 45 | int *tmp_cpus = NULL, *tmp; |
47 | int max_entries = 0; | 46 | int max_entries = 0; |
48 | int n, cpu, prev; | 47 | int n, cpu, prev; |
49 | char sep; | 48 | char sep; |
50 | 49 | ||
51 | onlnf = fopen("/sys/devices/system/cpu/online", "r"); | ||
52 | if (!onlnf) | ||
53 | return cpu_map__default_new(); | ||
54 | |||
55 | sep = 0; | 50 | sep = 0; |
56 | prev = -1; | 51 | prev = -1; |
57 | for (;;) { | 52 | for (;;) { |
58 | n = fscanf(onlnf, "%u%c", &cpu, &sep); | 53 | n = fscanf(file, "%u%c", &cpu, &sep); |
59 | if (n <= 0) | 54 | if (n <= 0) |
60 | break; | 55 | break; |
61 | if (prev >= 0) { | 56 | if (prev >= 0) { |
@@ -95,6 +90,19 @@ static struct cpu_map *cpu_map__read_all_cpu_map(void) | |||
95 | cpus = cpu_map__default_new(); | 90 | cpus = cpu_map__default_new(); |
96 | out_free_tmp: | 91 | out_free_tmp: |
97 | free(tmp_cpus); | 92 | free(tmp_cpus); |
93 | return cpus; | ||
94 | } | ||
95 | |||
96 | static struct cpu_map *cpu_map__read_all_cpu_map(void) | ||
97 | { | ||
98 | struct cpu_map *cpus = NULL; | ||
99 | FILE *onlnf; | ||
100 | |||
101 | onlnf = fopen("/sys/devices/system/cpu/online", "r"); | ||
102 | if (!onlnf) | ||
103 | return cpu_map__default_new(); | ||
104 | |||
105 | cpus = cpu_map__read(onlnf); | ||
98 | fclose(onlnf); | 106 | fclose(onlnf); |
99 | return cpus; | 107 | return cpus; |
100 | } | 108 | } |