首页 > 解决方案 > hrtimer_init() 中的 hrtimer 定时器模式与 hrtimer_start() 中的到期模式

问题描述

我很难理解为什么我们有两种 hrtimer 模式。hrtimer_start()(和相关函数)中的到期模式与 hrtimer_init() 中的定时器模式相比有什么影响?

标签: clinuxkernel

解决方案


在中,和hrtimer_init(timer, clock_id, mode)之间的唯一区别是函数可以用if替换值:HRTIMER_MODE_ABSHRTIMER_MODE_RELclock_idCLOCK_REALTIMECLOCK_MONOTONICHRTIMER_MODE_REL

    /*
     * POSIX magic: Relative CLOCK_REALTIME timers are not affected by
     * clock modifications, so they needs to become CLOCK_MONOTONIC to
     * ensure POSIX compliance.
     */
    if (clock_id == CLOCK_REALTIME && mode & HRTIMER_MODE_REL)
        clock_id = CLOCK_MONOTONIC;

hrtimer_start(timer, tim, mode)中,mode & HRTIMER_MODE_REL表示tim相对于当前时间。


推荐阅读