/* * helper function to check whether a file under "../cpuX/cpuidle/stateX/" dir * exists. * For example the functionality to disable c-states was introduced in later * kernel versions, this function can be used to explicitly check for this * feature. * * returns 1 if the file exists, 0 otherwise.
*/ static unsignedint cpuidle_state_file_exists(unsignedint cpu, unsignedint idlestate, constchar *fname)
{ char path[SYSFS_PATH_MAX]; struct stat statbuf;
/* * helper function to read file from /sys into given buffer * fname is a relative path under "cpuX/cpuidle/stateX/" dir * cstates starting with 0, C0 is not counted as cstate. * This means if you want C1 info, pass 0 as idlestate param
*/ static unsignedint cpuidle_state_read_file(unsignedint cpu, unsignedint idlestate, constchar *fname, char *buf,
size_t buflen)
{ char path[SYSFS_PATH_MAX]; int fd;
ssize_t numread;
/* * helper function to write a new value to a /sys file * fname is a relative path under "../cpuX/cpuidle/cstateY/" dir * * Returns the number of bytes written or 0 on error
*/ static unsignedint cpuidle_state_write_file(unsignedint cpu, unsignedint idlestate, constchar *fname, constchar *value, size_t len)
{ char path[SYSFS_PATH_MAX]; int fd;
ssize_t numwrite;
/* * Returns: * 1 if disabled * 0 if enabled * -1 if idlestate is not available * -2 if disabling is not supported by the kernel
*/ int cpuidle_is_state_disabled(unsignedint cpu, unsignedint idlestate)
{ if (cpuidle_state_count(cpu) <= idlestate) return -1;
/* * Pass 1 as last argument to disable or 0 to enable the state * Returns: * 0 on success * negative values on error, for example: * -1 if idlestate is not available * -2 if disabling is not supported by the kernel * -3 No write access to disable/enable C-states
*/ int cpuidle_state_disable(unsignedint cpu, unsignedint idlestate, unsignedint disable)
{ char value[SYSFS_PATH_MAX]; int bytes_written; int len;
if (cpuidle_state_count(cpu) <= idlestate) return -1;
if (!cpuidle_state_file_exists(cpu, idlestate,
idlestate_value_files[IDLESTATE_DISABLE])) return -2;
len = snprintf(value, SYSFS_PATH_MAX, "%u", disable);
/* * Returns number of supported C-states of CPU core cpu * Negativ in error case * Zero if cpuidle does not export any C-states
*/ unsignedint cpuidle_state_count(unsignedint cpu)
{ char file[SYSFS_PATH_MAX]; struct stat statbuf; int idlestates = 1;
/* CPUidle general /sys/devices/system/cpu/cpuidle/ sysfs access ********/
/* * helper function to read file from /sys into given buffer * fname is a relative path under "cpu/cpuidle/" dir
*/ staticunsignedint sysfs_cpuidle_read_file(constchar *fname, char *buf,
size_t buflen)
{ char path[SYSFS_PATH_MAX];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.