Lines Matching +full:cpu +full:- +full:read

1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
22 * For example the functionality to disable c-states was introduced in later
29 unsigned int cpuidle_state_file_exists(unsigned int cpu,
37 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",
38 cpu, idlestate, fname);
45 * helper function to read file from /sys into given buffer
51 unsigned int cpuidle_state_read_file(unsigned int cpu,
60 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",
61 cpu, idlestate, fname);
64 if (fd == -1)
67 numread = read(fd, buf, buflen - 1);
86 unsigned int cpuidle_state_write_file(unsigned int cpu,
95 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s",
96 cpu, idlestate, fname);
99 if (fd == -1)
113 /* read access to files which contain one numeric value */
135 unsigned long long cpuidle_state_get_one_value(unsigned int cpu,
147 len = cpuidle_state_read_file(cpu, idlestate,
161 /* read access to files which contain one string */
175 static char *cpuidle_state_get_one_string(unsigned int cpu,
186 len = cpuidle_state_read_file(cpu, idlestate,
196 if (result[strlen(result) - 1] == '\n')
197 result[strlen(result) - 1] = '\0';
206 * -1 if idlestate is not available
207 * -2 if disabling is not supported by the kernel
209 int cpuidle_is_state_disabled(unsigned int cpu,
212 if (cpuidle_state_count(cpu) <= idlestate)
213 return -1;
215 if (!cpuidle_state_file_exists(cpu, idlestate,
217 return -2;
218 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_DISABLE);
226 * -1 if idlestate is not available
227 * -2 if disabling is not supported by the kernel
228 * -3 No write access to disable/enable C-states
230 int cpuidle_state_disable(unsigned int cpu,
238 if (cpuidle_state_count(cpu) <= idlestate)
239 return -1;
241 if (!cpuidle_state_file_exists(cpu, idlestate,
243 return -2;
247 bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable",
251 return -3;
254 unsigned long cpuidle_state_latency(unsigned int cpu,
257 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_LATENCY);
260 unsigned long cpuidle_state_residency(unsigned int cpu,
263 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_RESIDENCY);
266 unsigned long cpuidle_state_usage(unsigned int cpu,
269 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_USAGE);
272 unsigned long long cpuidle_state_time(unsigned int cpu,
275 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_TIME);
278 char *cpuidle_state_name(unsigned int cpu, unsigned int idlestate)
280 return cpuidle_state_get_one_string(cpu, idlestate, IDLESTATE_NAME);
283 char *cpuidle_state_desc(unsigned int cpu, unsigned int idlestate)
285 return cpuidle_state_get_one_string(cpu, idlestate, IDLESTATE_DESC);
289 * Returns number of supported C-states of CPU core cpu
291 * Zero if cpuidle does not export any C-states
293 unsigned int cpuidle_state_count(unsigned int cpu)
304 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu);
310 "cpu%u/cpuidle/state%d", cpu, idlestates);
313 idlestates--;
317 /* CPUidle general /sys/devices/system/cpu/cpuidle/ sysfs access ********/
320 * helper function to read file from /sys into given buffer
321 * fname is a relative path under "cpu/cpuidle/" dir
335 /* read access to files which contain one string */
369 if (result[strlen(result) - 1] == '\n')
370 result[strlen(result) - 1] = '\0';
388 /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */