Linux内核--wakeup_source机制流程简介

本文介绍了Linux内核中的wakeup_source机制,包括wakeup_source的初始化、注册、激活和去激活过程。通过wakeup_source_create、wakeup_source_register、__pm_stay_awake和__pm_relax等函数,详细阐述了如何管理和控制系统的唤醒事件,确保在适当的时候阻止系统进入休眠状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

timer.c

static void do_init_timer(struct timer_list *timer,
void (*func)(struct timer_list *),
unsigned int flags,
const char *name, struct lock_class_key *key)
{
timer->entry.pprev = NULL;
timer->function = func;
timer->flags = flags | raw_smp_processor_id();
lockdep_init_map(&timer->lockdep_map, name, key, 0);
}

/**

  • init_timer_key - initialize a timer
  • @timer: the timer to be initialized
  • @func: timer callback function
  • @flags: timer flags
  • @name: name of the timer
  • @key: lockdep class key of the fake lock used for tracking timer
  •   sync lock dependencies
    
  • init_timer_key() must be done to a timer prior calling any of the
  • other timer functions.
    */
    void init_timer_key(struct timer_list *timer,
    void (*func)(struct timer_list *), unsigned int flags,
    const char *name, struct lock_class_key *key)
    {
    debug_init(timer);
    do_init_timer(timer, func, flags, name, key);
    }
    EXPORT_SYMBOL(init_timer_key);

timer.h

#define __init_timer(_timer, _fn, _flags)
do {
static struct lock_class_key __key;
init_timer_key((_timer), (_fn), (_flags), #_timer, &__key);
} while (0)

/**

  • timer_setup - prepare a timer for first use
  • @timer: the timer in question
  • @callback: the function to call when timer expires
  • @flags: any TIMER_* flags
  • Regular timer initialization should use either DEFINE_TIMER() above,
  • or timer_setup(). For timers on the stack, timer_setup_on_stack() must
  • be used and must be balanced with a call to destroy_timer_on_stack().
    */
    #define timer_setup(timer, callback, flags)
    __init_timer((timer), (callback), (flags))

wake_stats.c

/**

  • wakeup_source_sysfs_add - Add wakeup_source attributes to sysfs.

  • @parent: Device given wakeup source is associated with (or NULL if virtual).

  • @ws: Wakeup source to be added in sysfs.
    */
    int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *ws)
    {
    struct device *dev;

    dev = wakeup_source_device_create(parent, ws);
    if (IS_ERR(dev))
    return PTR_ERR(dev);
    ws->dev = dev;

    return 0;
    }

wakeup.c
/**

  • wakeup_source_create - Create a struct wakeup_source object.

  • @name: Name of the new wakeup source.
    */
    struct wakeup_source *wakeup_source_create(const char *name)
    {
    struct wakeup_source *ws;
    const char *ws_name;
    int id;

    ws = kzalloc(sizeof(*ws), GFP_KERNEL);
    if (!ws)
    goto err_ws;

    ws_name = kstrdup_const(name, GFP_KERNEL);
    if (!ws_name)
    goto err_name;
    ws->name = ws_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值