diff options
| author | zy <[email protected]> | 2023-11-08 14:16:36 +0800 |
|---|---|---|
| committer | zy <[email protected]> | 2023-11-08 14:16:36 +0800 |
| commit | c3c426e9cbb74a7197318f8e699dc1d90c13117c (patch) | |
| tree | fe60c5e6aaf7efa390af0412902b430f20267194 | |
| parent | a45b2f21f9b1adfe3d9a36bc3312017fb67955af (diff) | |
hrTimer
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | README_zh.md | 4 | ||||
| -rw-r--r-- | watch_module.c | 4 | ||||
| -rw-r--r-- | watch_module.h | 6 | ||||
| -rw-r--r-- | watch_module_lib.c | 14 |
5 files changed, 16 insertions, 16 deletions
@@ -48,7 +48,7 @@ typedef struct ``` An initialization example: -- When testing in hyper-v virtual machine, setting any value less than 1000ns for hwTimer will freeze the system, so unable to test ns level timing; +- When testing in hyper-v virtual machine, setting any value less than 1000ns for hrTimer will freeze the system, so unable to test ns level timing; ```c watch_arg watch_arg = { @@ -86,4 +86,4 @@ The program is divided into two parts: character device and user space interface User space address access - The user program passes in a virtual address, get_user_pages_remote is used to obtain the memory page where the address is located, and kmap maps it to the kernel. -- The memory page address + offset is stored in the global variable k_watch_arg, and hwTimer polls to access k_watch_arg to get the real value. +- The memory page address + offset is stored in the global variable k_watch_arg, and hrTimer polls to access k_watch_arg to get the real value. diff --git a/README_zh.md b/README_zh.md index 3ba6f22..0f2d9cd 100644 --- a/README_zh.md +++ b/README_zh.md @@ -48,7 +48,7 @@ typedef struct ``` 一个初始化示例 -- 测试环境为 hyper-v 虚拟机时,直接为 hwTimer 设置任何小于 1000ns 的值,系统卡死,故未能测试 ns 级别定时; +- 测试环境为 hyper-v 虚拟机时,直接为 hrTimer 设置任何小于 1000ns 的值,系统卡死,故未能测试 ns 级别定时; ```c watch_arg watch_arg = { @@ -87,4 +87,4 @@ rmmod watch_module.ko && make clean 用户空间地址访问 - 用户程序传入了 虚拟地址, 使用 `get_user_pages_remote` 获取地址所在内存页, `kmap` 将其映射到内核. -- 内存页地址 + 偏移量存入全局变量 `k_watch_arg` 中, hwTimer 轮询时访问 `k_watch_arg` 得到真实值.
\ No newline at end of file +- 内存页地址 + 偏移量存入全局变量 `k_watch_arg` 中, hrTimer 轮询时访问 `k_watch_arg` 得到真实值.
\ No newline at end of file diff --git a/watch_module.c b/watch_module.c index 6e97941..a53e279 100644 --- a/watch_module.c +++ b/watch_module.c @@ -28,7 +28,7 @@ static int device_release(struct inode *inode, struct file *file) if (page) put_page(page); // cancel timer - cancel_hwTimer(); + cancel_hrTimer(); return 0; } @@ -66,7 +66,7 @@ static long device_ioctl(struct file *file, unsigned int ioctl_num, unsigned lon k_watch_arg.unsigned_flag = warg.unsigned_flag; k_watch_arg.greater_flag = warg.greater_flag; // start timer - start_hwTimer(warg.time); + start_hrTimer(warg.time); printk(KERN_INFO "Start watching\n"); return 0; diff --git a/watch_module.h b/watch_module.h index 8975741..336bbbb 100644 --- a/watch_module.h +++ b/watch_module.h @@ -40,10 +40,10 @@ static void *kaddr = NULL; void *access_user_space_ptr(pid_t pid, unsigned long kaddr); -// hwTimer +// hrTimer enum hrtimer_restart hrtimer_hander(struct hrtimer *timer); -int start_hwTimer(unsigned long timeout); -void cancel_hwTimer(void); +int start_hrTimer(unsigned long timeout); +void cancel_hrTimer(void); unsigned char read_and_compare(kernel_watch_arg *k_arg); diff --git a/watch_module_lib.c b/watch_module_lib.c index 4783c90..896b1d0 100644 --- a/watch_module_lib.c +++ b/watch_module_lib.c @@ -56,7 +56,7 @@ void *access_user_space_ptr(pid_t pid, unsigned long addr) static struct hrtimer hr_timer; static ktime_t kt; -/// @brief hwTimer handler +/// @brief hrTimer handler enum hrtimer_restart hrtimer_hander(struct hrtimer *timer) { if (read_and_compare(&k_watch_arg)) @@ -75,12 +75,12 @@ enum hrtimer_restart hrtimer_hander(struct hrtimer *timer) return HRTIMER_RESTART; } -/// @brief start hwTimer +/// @brief start hrTimer /// @param timeout: timeout in us /// @return 0 is success -int start_hwTimer(unsigned long timeout) +int start_hrTimer(unsigned long timeout) { - printk("HWTimer Start\n"); + printk("HrTimer Start\n"); kt = ktime_set(0, (unsigned long)timeout * US2NS); // us -> ns // CLOCK_MONOTONIC: time since boot | HRTIMER_MODE_REL : relative time @@ -91,12 +91,12 @@ int start_hwTimer(unsigned long timeout) return 0; } -/// @brief cancel hwTimer +/// @brief cancel hrTimer /// @param -void cancel_hwTimer(void) +void cancel_hrTimer(void) { hrtimer_cancel(&hr_timer); - printk("HWTimer End\n"); + printk("HrTimer End\n"); } // for read_and_compare |
