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, in cpuidle_state_file_exists() argument
37 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in cpuidle_state_file_exists()
38 cpu, idlestate, fname); in cpuidle_state_file_exists()
45 * helper function to read file from /sys into given buffer
51 unsigned int cpuidle_state_read_file(unsigned int cpu, in cpuidle_state_read_file() argument
60 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in cpuidle_state_read_file()
61 cpu, idlestate, fname); in cpuidle_state_read_file()
64 if (fd == -1) in cpuidle_state_read_file()
67 numread = read(fd, buf, buflen - 1); in cpuidle_state_read_file()
86 unsigned int cpuidle_state_write_file(unsigned int cpu, in cpuidle_state_write_file() argument
95 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in cpuidle_state_write_file()
96 cpu, idlestate, fname); in cpuidle_state_write_file()
99 if (fd == -1) in cpuidle_state_write_file()
113 /* read access to files which contain one numeric value */
135 unsigned long long cpuidle_state_get_one_value(unsigned int cpu, in cpuidle_state_get_one_value() argument
147 len = cpuidle_state_read_file(cpu, idlestate, in cpuidle_state_get_one_value()
161 /* read access to files which contain one string */
175 static char *cpuidle_state_get_one_string(unsigned int cpu, in cpuidle_state_get_one_string() argument
186 len = cpuidle_state_read_file(cpu, idlestate, in cpuidle_state_get_one_string()
196 if (result[strlen(result) - 1] == '\n') in cpuidle_state_get_one_string()
197 result[strlen(result) - 1] = '\0'; in cpuidle_state_get_one_string()
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, in cpuidle_is_state_disabled() argument
212 if (cpuidle_state_count(cpu) <= idlestate) in cpuidle_is_state_disabled()
213 return -1; in cpuidle_is_state_disabled()
215 if (!cpuidle_state_file_exists(cpu, idlestate, in cpuidle_is_state_disabled()
217 return -2; in cpuidle_is_state_disabled()
218 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_DISABLE); in cpuidle_is_state_disabled()
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, in cpuidle_state_disable() argument
237 if (cpuidle_state_count(cpu) <= idlestate) in cpuidle_state_disable()
238 return -1; in cpuidle_state_disable()
240 if (!cpuidle_state_file_exists(cpu, idlestate, in cpuidle_state_disable()
242 return -2; in cpuidle_state_disable()
246 bytes_written = cpuidle_state_write_file(cpu, idlestate, "disable", in cpuidle_state_disable()
250 return -3; in cpuidle_state_disable()
253 unsigned long cpuidle_state_latency(unsigned int cpu, in cpuidle_state_latency() argument
256 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); in cpuidle_state_latency()
259 unsigned long cpuidle_state_residency(unsigned int cpu, in cpuidle_state_residency() argument
262 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_RESIDENCY); in cpuidle_state_residency()
265 unsigned long cpuidle_state_usage(unsigned int cpu, in cpuidle_state_usage() argument
268 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_USAGE); in cpuidle_state_usage()
271 unsigned long long cpuidle_state_time(unsigned int cpu, in cpuidle_state_time() argument
274 return cpuidle_state_get_one_value(cpu, idlestate, IDLESTATE_TIME); in cpuidle_state_time()
277 char *cpuidle_state_name(unsigned int cpu, unsigned int idlestate) in cpuidle_state_name() argument
279 return cpuidle_state_get_one_string(cpu, idlestate, IDLESTATE_NAME); in cpuidle_state_name()
282 char *cpuidle_state_desc(unsigned int cpu, unsigned int idlestate) in cpuidle_state_desc() argument
284 return cpuidle_state_get_one_string(cpu, idlestate, IDLESTATE_DESC); in cpuidle_state_desc()
288 * Returns number of supported C-states of CPU core cpu
290 * Zero if cpuidle does not export any C-states
292 unsigned int cpuidle_state_count(unsigned int cpu) in cpuidle_state_count() argument
303 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu); in cpuidle_state_count()
309 "cpu%u/cpuidle/state%d", cpu, idlestates); in cpuidle_state_count()
312 idlestates--; in cpuidle_state_count()
316 /* CPUidle general /sys/devices/system/cpu/cpuidle/ sysfs access ********/
319 * helper function to read file from /sys into given buffer
320 * fname is a relative path under "cpu/cpuidle/" dir
334 /* read access to files which contain one string */
368 if (result[strlen(result) - 1] == '\n') in sysfs_cpuidle_get_one_string()
369 result[strlen(result) - 1] = '\0'; in sysfs_cpuidle_get_one_string()
387 /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */