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

1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de>
24 if (fd == -1) in sysfs_read_file()
27 numread = read(fd, buf, buflen - 1); in sysfs_read_file()
40 * Detect whether a CPU is online
43 * 1 -> if CPU is online
44 * 0 -> if CPU is offline
47 int sysfs_is_cpu_online(unsigned int cpu) in sysfs_is_cpu_online() argument
57 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u", cpu); in sysfs_is_cpu_online()
64 * -> cpuX directory exists, but not cpuX/online file in sysfs_is_cpu_online()
66 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/online", cpu); in sysfs_is_cpu_online()
71 if (fd == -1) in sysfs_is_cpu_online()
72 return -errno; in sysfs_is_cpu_online()
74 numread = read(fd, linebuf, MAX_LINE_LEN - 1); in sysfs_is_cpu_online()
77 return -EIO; in sysfs_is_cpu_online()
84 return -EINVAL; in sysfs_is_cpu_online()
89 /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */
92 /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */
97 * For example the functionality to disable c-states was introduced in later
103 unsigned int sysfs_idlestate_file_exists(unsigned int cpu, in sysfs_idlestate_file_exists() argument
111 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in sysfs_idlestate_file_exists()
112 cpu, idlestate, fname); in sysfs_idlestate_file_exists()
119 * helper function to read file from /sys into given buffer
124 unsigned int sysfs_idlestate_read_file(unsigned int cpu, unsigned int idlestate, in sysfs_idlestate_read_file() argument
131 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in sysfs_idlestate_read_file()
132 cpu, idlestate, fname); in sysfs_idlestate_read_file()
135 if (fd == -1) in sysfs_idlestate_read_file()
138 numread = read(fd, buf, buflen - 1); in sysfs_idlestate_read_file()
157 unsigned int sysfs_idlestate_write_file(unsigned int cpu, in sysfs_idlestate_write_file() argument
166 snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/cpuidle/state%u/%s", in sysfs_idlestate_write_file()
167 cpu, idlestate, fname); in sysfs_idlestate_write_file()
170 if (fd == -1) in sysfs_idlestate_write_file()
184 /* read access to files which contain one numeric value */
203 static unsigned long long sysfs_idlestate_get_one_value(unsigned int cpu, in sysfs_idlestate_get_one_value() argument
215 len = sysfs_idlestate_read_file(cpu, idlestate, in sysfs_idlestate_get_one_value()
229 /* read access to files which contain one string */
243 static char *sysfs_idlestate_get_one_string(unsigned int cpu, in sysfs_idlestate_get_one_string() argument
254 len = sysfs_idlestate_read_file(cpu, idlestate, in sysfs_idlestate_get_one_string()
264 if (result[strlen(result) - 1] == '\n') in sysfs_idlestate_get_one_string()
265 result[strlen(result) - 1] = '\0'; in sysfs_idlestate_get_one_string()
274 * -1 if idlestate is not available
275 * -2 if disabling is not supported by the kernel
277 int sysfs_is_idlestate_disabled(unsigned int cpu, in sysfs_is_idlestate_disabled() argument
280 if (sysfs_get_idlestate_count(cpu) <= idlestate) in sysfs_is_idlestate_disabled()
281 return -1; in sysfs_is_idlestate_disabled()
283 if (!sysfs_idlestate_file_exists(cpu, idlestate, in sysfs_is_idlestate_disabled()
285 return -2; in sysfs_is_idlestate_disabled()
286 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_DISABLE); in sysfs_is_idlestate_disabled()
294 * -1 if idlestate is not available
295 * -2 if disabling is not supported by the kernel
296 * -3 No write access to disable/enable C-states
298 int sysfs_idlestate_disable(unsigned int cpu, in sysfs_idlestate_disable() argument
305 if (sysfs_get_idlestate_count(cpu) <= idlestate) in sysfs_idlestate_disable()
306 return -1; in sysfs_idlestate_disable()
308 if (!sysfs_idlestate_file_exists(cpu, idlestate, in sysfs_idlestate_disable()
310 return -2; in sysfs_idlestate_disable()
314 bytes_written = sysfs_idlestate_write_file(cpu, idlestate, "disable", in sysfs_idlestate_disable()
318 return -3; in sysfs_idlestate_disable()
321 unsigned long sysfs_get_idlestate_latency(unsigned int cpu, in sysfs_get_idlestate_latency() argument
324 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_LATENCY); in sysfs_get_idlestate_latency()
327 unsigned long sysfs_get_idlestate_usage(unsigned int cpu, in sysfs_get_idlestate_usage() argument
330 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_USAGE); in sysfs_get_idlestate_usage()
333 unsigned long long sysfs_get_idlestate_time(unsigned int cpu, in sysfs_get_idlestate_time() argument
336 return sysfs_idlestate_get_one_value(cpu, idlestate, IDLESTATE_TIME); in sysfs_get_idlestate_time()
339 char *sysfs_get_idlestate_name(unsigned int cpu, unsigned int idlestate) in sysfs_get_idlestate_name() argument
341 return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_NAME); in sysfs_get_idlestate_name()
344 char *sysfs_get_idlestate_desc(unsigned int cpu, unsigned int idlestate) in sysfs_get_idlestate_desc() argument
346 return sysfs_idlestate_get_one_string(cpu, idlestate, IDLESTATE_DESC); in sysfs_get_idlestate_desc()
350 * Returns number of supported C-states of CPU core cpu
352 * Zero if cpuidle does not export any C-states
354 unsigned int sysfs_get_idlestate_count(unsigned int cpu) in sysfs_get_idlestate_count() argument
365 snprintf(file, SYSFS_PATH_MAX, PATH_TO_CPU "cpu%u/cpuidle/state0", cpu); in sysfs_get_idlestate_count()
371 "cpu%u/cpuidle/state%d", cpu, idlestates); in sysfs_get_idlestate_count()
374 idlestates--; in sysfs_get_idlestate_count()
378 /* CPUidle general /sys/devices/system/cpu/cpuidle/ sysfs access ********/
381 * helper function to read file from /sys into given buffer
382 * fname is a relative path under "cpu/cpuidle/" dir
396 /* read access to files which contain one string */
430 if (result[strlen(result) - 1] == '\n') in sysfs_cpuidle_get_one_string()
431 result[strlen(result) - 1] = '\0'; in sysfs_cpuidle_get_one_string()
449 /* CPUidle idlestate specific /sys/devices/system/cpu/cpuX/cpuidle/ access */
459 return -ENODEV; in sysfs_get_sched()
470 return -ENODEV; in sysfs_set_sched()