高分辨率定時(shí)器(hrtimer
)以ktime_t
來(lái)定義時(shí)間, 精度可以達(dá)到納秒級(jí)別 ,ktime_t
定義如下:
typedef s64 ktime_t;
可以用ktime_set
來(lái)初始化一個(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í)鐘的類(lèi)型, 種類(lèi)很多,常見(jiàn)的有四種:
CLOCK_REALTIME
:系統(tǒng)實(shí)時(shí)時(shí)間。CLOCK_MONOTONIC
:從系統(tǒng)啟動(dòng)時(shí)開(kāi)始計(jì)時(shí),自系統(tǒng)開(kāi)機(jī)以來(lái)的單調(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
:?jiǎn)?dòng)定時(shí)器。tim
是設(shè)定的到期時(shí)間, mode
和hrtimer_init
中的mode
參數(shù)含義相同。hrtimer_forward_now
: 修改到期時(shí)間為從現(xiàn)在開(kāi)始之后的 interval
時(shí)間。hrtimer_cancel
:取消定時(shí)器。
-
驅(qū)動(dòng)
+關(guān)注
關(guān)注
12文章
1844瀏覽量
85355 -
Linux
+關(guān)注
關(guān)注
87文章
11319瀏覽量
209830 -
定時(shí)器
+關(guān)注
關(guān)注
23文章
3251瀏覽量
115003
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
![](https://file1.elecfans.com/web2/M00/85/8B/wKgaomRmM5GAVbQ4AAGrDj-iw-8882.png)
#硬聲創(chuàng)作季 #Linux 學(xué)Linux-2.18.1 高精度延時(shí)實(shí)驗(yàn)-GPT定時(shí)器原理-2
GPT高精度延時(shí)定時(shí)器簡(jiǎn)介
長(zhǎng)時(shí)間高精度定時(shí)器
![長(zhǎng)時(shí)間<b class='flag-5'>高精度</b><b class='flag-5'>定時(shí)器</b>](https://file1.elecfans.com//web2/M00/A4/46/wKgZomUMM3WAYrUFAAHTdFB4e5Y502.jpg)
Linux時(shí)間子系統(tǒng)中的高精度定時(shí)器(HRTIMER)的原理和實(shí)現(xiàn)
LINUX內(nèi)核定時(shí)器(高精度&低精度)
詳解高精度定時(shí)器與高級(jí)控制定時(shí)器
Linux驅(qū)動(dòng)開(kāi)發(fā)高精度定時(shí)器的精度測(cè)量評(píng)測(cè)
工程師筆記|高精度定時(shí)器的同步功能
高精度定時(shí)器與高級(jí)控制定時(shí)器 PWM 封波后再恢復(fù)的區(qū)別
![<b class='flag-5'>高精度</b><b class='flag-5'>定時(shí)器</b>與高級(jí)控制<b class='flag-5'>定時(shí)器</b> PWM 封波后再恢復(fù)的區(qū)別](https://file1.elecfans.com/web2/M00/A4/9E/wKgaomUD58mAUywTAADbtBLKvFo028.png)
評(píng)論