当前位置: 技术问答>linux和unix
linux内核main.C
来源: 互联网 发布时间:2016-11-16
本文导语: 这个是linux最新版中内核代码的main.c其中一小部分, #include #include #include #include #include "power.h" DEFINE_MUTEX(pm_mutex); unsigned int pm_flags; EXPORT_SYMBOL(pm_flags); #ifdef CONFIG_PM_SLEEP /* Routines for PM-transition notifications ...
这个是linux最新版中内核代码的main.c其中一小部分,
#include
#include
#include
#include
#include "power.h"
DEFINE_MUTEX(pm_mutex);
unsigned int pm_flags;
EXPORT_SYMBOL(pm_flags);
#ifdef CONFIG_PM_SLEEP
/* Routines for PM-transition notifications */
static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
int register_pm_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pm_chain_head, nb);
}
EXPORT_SYMBOL_GPL(register_pm_notifier);
int unregister_pm_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pm_chain_head, nb);
}
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
int pm_notifier_call_chain(unsigned long val)
{
return (blocking_notifier_call_chain(&pm_chain_head, val, NULL)
== NOTIFY_BAD) ? -EINVAL : 0;
}
/* If set, devices may be suspended and resumed asynchronously. */
int pm_async_enabled = 1;
static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sprintf(buf, "%dn", pm_async_enabled);
}
static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
{
unsigned long val;
if (strict_strtoul(buf, 10, &val))
return -EINVAL;
if (val > 1)
return -EINVAL;
pm_async_enabled = val;
return n;
}
power_attr(pm_async);
我想请问一下其中的以下函数的作用:
BLOCKING_NOTIFIER_HEAD(pm_chain_head);
register_pm_notifier(struct notifier_block *nb)
unregister_pm_notifier(struct notifier_block *nb)
pm_notifier_call_chain(unsigned long val)
ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
power_attr(pm_async);
希望能讲详细些,谢谢
#include
#include
#include
#include
#include "power.h"
DEFINE_MUTEX(pm_mutex);
unsigned int pm_flags;
EXPORT_SYMBOL(pm_flags);
#ifdef CONFIG_PM_SLEEP
/* Routines for PM-transition notifications */
static BLOCKING_NOTIFIER_HEAD(pm_chain_head);
int register_pm_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&pm_chain_head, nb);
}
EXPORT_SYMBOL_GPL(register_pm_notifier);
int unregister_pm_notifier(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&pm_chain_head, nb);
}
EXPORT_SYMBOL_GPL(unregister_pm_notifier);
int pm_notifier_call_chain(unsigned long val)
{
return (blocking_notifier_call_chain(&pm_chain_head, val, NULL)
== NOTIFY_BAD) ? -EINVAL : 0;
}
/* If set, devices may be suspended and resumed asynchronously. */
int pm_async_enabled = 1;
static ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
return sprintf(buf, "%dn", pm_async_enabled);
}
static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
{
unsigned long val;
if (strict_strtoul(buf, 10, &val))
return -EINVAL;
if (val > 1)
return -EINVAL;
pm_async_enabled = val;
return n;
}
power_attr(pm_async);
我想请问一下其中的以下函数的作用:
BLOCKING_NOTIFIER_HEAD(pm_chain_head);
register_pm_notifier(struct notifier_block *nb)
unregister_pm_notifier(struct notifier_block *nb)
pm_notifier_call_chain(unsigned long val)
ssize_t pm_async_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
power_attr(pm_async);
希望能讲详细些,谢谢
|
我对这个也不懂,请允许我提个建议,既然自己在看源代码为什么不认真研究下呢
BLOCKING_NOTIFIER_HEAD(pm_chain_head);这不是一个函数,是声明了一个atomic_notifier_head类型的局部变量而已。
register_pm_notifier(struct notifier_block *nb)和unregister_pm_notifier(struct notifier_block *nb)
就是注册和取消电源管理notifier的操作,notifier是Linux中提供一种在内核子系统中共享事件信息的方法
BLOCKING_NOTIFIER_HEAD(pm_chain_head);这不是一个函数,是声明了一个atomic_notifier_head类型的局部变量而已。
register_pm_notifier(struct notifier_block *nb)和unregister_pm_notifier(struct notifier_block *nb)
就是注册和取消电源管理notifier的操作,notifier是Linux中提供一种在内核子系统中共享事件信息的方法