当前位置:   article > 正文

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

linux wakesource

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
    
    • 1
  • 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_name;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/818041
推荐阅读
相关标签
  

闽ICP备14008679号