hrtimer是Linux内核中实现高精度定时器的一种方式,它提供了更精确的时间控制和更灵活的定时器管理能力。hrtimer_init函数就是用来初始化这种高精度定时器的函数。 hrtimer_init函数的主要作用就是初始化并注册一个hrtimer任务,以便在以后的使用中能够准确地定时执行。在调用hrtimer_init函数之前,需要先定义一个hrtimer结构...
hrtimer_start:启动定时器。tim是设定的到期时间,mode和hrtimer_init中的mode参数含义相同。hrtimer_forward_now: 修改到期时间为从现在开始之后的interval时间。hrtimer_cancel:取消定时器。 使用示例 单次定时 加载驱动一秒后输出“hrtimer handler”: #include <linux/init.h>#include <linux/kernel.h>#include <lin...
*/ hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); hrtimer->function = watchdog_timer_fn; hrtimer_start(hrtimer, ns_to_ktime(sample_period), HRTIMER_MODE_REL_PINNED_HARD); ... } static void watchdog_disable(unsigned int cpu) { struct hrtimer *hrtimer = this_cpu_ptr(...
structhrtimer*hrtimer=this_cpu_ptr(&watchdog_hrtimer); /* * Start the timer first to prevent the NMI watchdog triggering * before the timer has a chance to fire. */ hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hrtimer->function = watchdog_timer_fn; hrtimer_start(hrtimer, n...
hrtimer_init(&cfs_b->slack_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); cfs_b->slack_timer.function = sched_cfs_slack_timer; cfs_b->distribute_running = 0; } void start_cfs_bandwidth(struct cfs_bandwidth *cfs_b) { u64 overrun;
void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode); which_clock可以是CLOCK_REALTIME、CLOCK_MONOTONIC、CLOCK_BOOTTIME中的一种,mode则可以是相对时间HRTIMER_MODE_REL,也可以是绝对时间HRTIMER_MODE_ABS。设定回调函数: ...
struct hrtimer结构体中最主要的成员就是回调函数function,回调函数的返回值可以为HRTIMER_NORESTART或HRTIMER_RESTART。HRTIMER_NORESTART代表不需要重启定时器,HRTIMER_RESTART代表需要重启定时器。 最常用的接口如下: hrtimer_init(structhrtimer *timer, clockid_t clock_id ,enumhrtimer_mode mode) ...
1. struct hrtimer { 2. struct timerqueue_node node; 3. ktime_t _softexpires; 4. enum hrtimer_restart (*function)(struct hrtimer *); 5. struct hrtimer_clock_base *base; 6. long state; 7. ... 8. }; 1. 2. 3. 4. 5.
hrtimer_init 用于初始化一个hrtimer extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode);- timer:表示hrtimer定时器- which_clock:表示选择系统的哪种时钟,主要包括两种:CLOCK_REALTIME、CLOCK_MONOTONIC,两种时钟的区别是,CLOCK_REALTIME表示绝对时间,而CLOCK_MONOTONI...
enumhrtimer_restart (*function)(structhrtimer *); structhrtimer_clock_base *base; unsignedlongstate; ... }; 定时器的到期时间用ktime_t来表示,_softexpires字段记录了时间,定时器一旦到期,function字段指定的回调函数会被调用,该函数的返回值为一个枚举值,它决定了该hrtimer是否需要被重新激活: [cpp...