高分辨率定時(shí)器(hrtimer
)以ktime_t
來定義時(shí)間, 精度可以達(dá)到納秒級(jí)別 ,ktime_t
定義如下:
typedef s64 ktime_t;
可以用ktime_set
來初始化一個(gè)ktime
對(duì)象,常用方法如下:
ktime_t t = ktime_set(secs, nsecs);
高分辨率hrtimer
結(jié)構(gòu)體定義如下:
struct hrtimer {
struct timerqueue_node node;
ktime_t _softexpires;
enum hrtimer_restart (*function)(struct hrtimer *);
struct hrtimer_clock_base *base;
unsigned long state;
......
};
enum hrtimer_restart {
HRTIMER_NORESTART, /* Timer is not restarted */
HRTIMER_RESTART, /* Timer must be restarted */
};
struct hrtimer
結(jié)構(gòu)體中最主要的成員就是回調(diào)函數(shù)function
,回調(diào)函數(shù)的返回值可以為HRTIMER_NORESTART
或HRTIMER_RESTART
。HRTIMER_NORESTART
代表不需要重啟定時(shí)器,HRTIMER_RESTART
代表需要重啟定時(shí)器。
最常用的接口如下:
hrtimer_init(struct hrtimer *timer, clockid_t clock_id , enum hrtimer_mode mode)
hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
hrtimer_forward_now(struct hrtimer *timer,ktime_t interval)
hrtimer_cancel(struct hrtimer *timer)
hrtimer_init
:初始化 struct hrtimer
結(jié)構(gòu)對(duì)象。clockid_t
是時(shí)鐘的類型, 種類很多,常見的有四種:
CLOCK_REALTIME
:系統(tǒng)實(shí)時(shí)時(shí)間。CLOCK_MONOTONIC
:從系統(tǒng)啟動(dòng)時(shí)開始計(jì)時(shí),自系統(tǒng)開機(jī)以來的單調(diào)遞增時(shí)間CLOCK_PROCESS_CPUTIME_ID
:本進(jìn)程到當(dāng)前代碼系統(tǒng)CPU花費(fèi)的時(shí)間,包含該進(jìn)程下的所有線程。CLOCK_THREAD_CPUTIME_ID
:本線程到當(dāng)前代碼系統(tǒng)CPU花費(fèi)的時(shí)間。
mode
是時(shí)間的模式,可以是 HRTIMER_MODE_ABS
, 表示絕對(duì)時(shí)間, 也可以是 HRTIMER_MODE_REL,
表 示相對(duì)時(shí)間。hrtimer_start
:啟動(dòng)定時(shí)器。tim
是設(shè)定的到期時(shí)間, mode
和hrtimer_init
中的mode
參數(shù)含義相同。hrtimer_forward_now
: 修改到期時(shí)間為從現(xiàn)在開始之后的 interval
時(shí)間。hrtimer_cancel
:取消定時(shí)器。
-
驅(qū)動(dòng)
+關(guān)注
關(guān)注
12文章
1898瀏覽量
86509 -
Linux
+關(guān)注
關(guān)注
87文章
11456瀏覽量
212749 -
定時(shí)器
+關(guān)注
關(guān)注
23文章
3287瀏覽量
117168
發(fā)布評(píng)論請(qǐng)先 登錄

#硬聲創(chuàng)作季 #Linux 學(xué)Linux-2.18.1 高精度延時(shí)實(shí)驗(yàn)-GPT定時(shí)器原理-2
GPT高精度延時(shí)定時(shí)器簡介
長時(shí)間高精度定時(shí)器

Linux時(shí)間子系統(tǒng)中的高精度定時(shí)器(HRTIMER)的原理和實(shí)現(xiàn)
LINUX內(nèi)核定時(shí)器(高精度&低精度)
詳解高精度定時(shí)器與高級(jí)控制定時(shí)器
Linux驅(qū)動(dòng)開發(fā)高精度定時(shí)器的精度測量評(píng)測
工程師筆記|高精度定時(shí)器的同步功能
高精度定時(shí)器與高級(jí)控制定時(shí)器 PWM 封波后再恢復(fù)的區(qū)別

評(píng)論