Skip to content

Instantly share code, notes, and snippets.

@Geobm
Last active February 9, 2022 05:36
Show Gist options
  • Save Geobm/b7de5ccbeb067f59e42e54c6e94e9db0 to your computer and use it in GitHub Desktop.
Save Geobm/b7de5ccbeb067f59e42e54c6e94e9db0 to your computer and use it in GitHub Desktop.
linux kernel power source
power_attr(pm_async);
#ifdef CONFIG_SUSPEND
static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,char *buf){
char *s = buf;
suspend_state_t i;
for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++)
if (mem_sleep_states[i]) {
const char *label = mem_sleep_states[i];
if (mem_sleep_current == i)
s += sprintf(s, "[%s] ", label);
else
s += sprintf(s, "%s ", label);
}
if (s != buf)
*(s-1) = '\n';
return (s - buf);
}
static suspend_state_t decode_suspend_state(const char *buf, size_t n){
suspend_state_t state;
char *p;
int len;
p = memchr(buf, '\n', n);
len = p ? p - buf : n;
for (state = PM_SUSPEND_MIN; state < PM_SUSPEND_MAX; state++) {
const char *label = mem_sleep_states[state];
if (label && len == strlen(label) && !strncmp(buf, label, len))
return state;
}
return PM_SUSPEND_ON;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment