Lines Matching +full:1 +full:- +full:cpu

1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
19 if (access(path, F_OK) == -1) in is_valid_path()
21 return 1; in is_valid_path()
30 if (fd == -1) in cpupower_read_sysfs()
33 numread = read(fd, buf, buflen - 1); in cpupower_read_sysfs()
34 if (numread < 1) { in cpupower_read_sysfs()
51 if (fd == -1) in cpupower_write_sysfs()
54 numwritten = write(fd, buf, buflen - 1); in cpupower_write_sysfs()
55 if (numwritten < 1) { in cpupower_write_sysfs()
58 return -1; in cpupower_write_sysfs()
67 * Detect whether a CPU is online
70 * 1 -> if CPU is online
71 * 0 -> if CPU is offline
74 int cpupower_is_cpu_online(unsigned int cpu) in cpupower_is_cpu_online() argument
84 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u", cpu); in cpupower_is_cpu_online()
91 * -> cpuX directory exists, but not cpuX/online file in cpupower_is_cpu_online()
93 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/online", cpu); in cpupower_is_cpu_online()
95 return 1; in cpupower_is_cpu_online()
98 if (fd == -1) in cpupower_is_cpu_online()
99 return -errno; in cpupower_is_cpu_online()
101 numread = read(fd, linebuf, MAX_LINE_LEN - 1); in cpupower_is_cpu_online()
102 if (numread < 1) { in cpupower_is_cpu_online()
104 return -EIO; in cpupower_is_cpu_online()
110 if (value > 1) in cpupower_is_cpu_online()
111 return -EINVAL; in cpupower_is_cpu_online()
116 /* returns -1 on failure, 0 on success */
117 static int sysfs_topology_read_file(unsigned int cpu, const char *fname, int *result) in sysfs_topology_read_file() argument
123 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s", in sysfs_topology_read_file()
124 cpu, fname); in sysfs_topology_read_file()
126 return -1; in sysfs_topology_read_file()
129 return -1; in sysfs_topology_read_file()
137 if (top1->pkg < top2->pkg) in __compare()
138 return -1; in __compare()
139 else if (top1->pkg > top2->pkg) in __compare()
140 return 1; in __compare()
141 else if (top1->core < top2->core) in __compare()
142 return -1; in __compare()
143 else if (top1->core > top2->core) in __compare()
144 return 1; in __compare()
145 else if (top1->cpu < top2->cpu) in __compare()
146 return -1; in __compare()
147 else if (top1->cpu > top2->cpu) in __compare()
148 return 1; in __compare()
157 * Array is sorted after ->pkg, ->core, then ->cpu
161 int cpu, last_pkg, cpus = sysconf(_SC_NPROCESSORS_CONF); in get_cpu_topology() local
163 cpu_top->core_info = malloc(sizeof(struct cpuid_core_info) * cpus); in get_cpu_topology()
164 if (cpu_top->core_info == NULL) in get_cpu_topology()
165 return -ENOMEM; in get_cpu_topology()
166 cpu_top->pkgs = cpu_top->cores = 0; in get_cpu_topology()
167 for (cpu = 0; cpu < cpus; cpu++) { in get_cpu_topology()
168 cpu_top->core_info[cpu].cpu = cpu; in get_cpu_topology()
169 cpu_top->core_info[cpu].is_online = cpupower_is_cpu_online(cpu); in get_cpu_topology()
171 cpu, in get_cpu_topology()
173 &(cpu_top->core_info[cpu].pkg)) < 0) { in get_cpu_topology()
174 cpu_top->core_info[cpu].pkg = -1; in get_cpu_topology()
175 cpu_top->core_info[cpu].core = -1; in get_cpu_topology()
179 cpu, in get_cpu_topology()
181 &(cpu_top->core_info[cpu].core)) < 0) { in get_cpu_topology()
182 cpu_top->core_info[cpu].pkg = -1; in get_cpu_topology()
183 cpu_top->core_info[cpu].core = -1; in get_cpu_topology()
188 qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info), in get_cpu_topology()
194 last_pkg = cpu_top->core_info[0].pkg; in get_cpu_topology()
195 for(cpu = 1; cpu < cpus; cpu++) { in get_cpu_topology()
196 if (cpu_top->core_info[cpu].pkg != last_pkg && in get_cpu_topology()
197 cpu_top->core_info[cpu].pkg != -1) { in get_cpu_topology()
199 last_pkg = cpu_top->core_info[cpu].pkg; in get_cpu_topology()
200 cpu_top->pkgs++; in get_cpu_topology()
203 if (!(cpu_top->core_info[0].pkg == -1)) in get_cpu_topology()
204 cpu_top->pkgs++; in get_cpu_topology()
209 for (cpu = 0; cpu_top->core_info[cpu].pkg = 0 && cpu < cpus; cpu++) { in get_cpu_topology()
210 if (cpu_top->core_info[cpu].core == 0) in get_cpu_topology()
211 cpu_top->cores++; in get_cpu_topology()