timer.h 中的计时器在内核模块中不起作用

问题描述 投票:0回答:1

我正在制作一个每 100 毫秒写入一个文件的内核模块。使用 arch linux 和内核 6.4。 kernel/timer.h 中的计时器似乎不起作用。它已被弃用吗?我应该用什么?

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/timer.h>
#include <linux/jiffies.h>

static int freq_sec;
static char *filepath;

static struct timer_list my_timer;

void timer_callback(struct timer_list * data) {
    printk("Hallo, Kernel %d! %s\n", freq_sec, filepath);
    file_write(filepath, "Hello from kernel module\n", 25);
}

static int __init my_init(void) {
    timer_setup(&my_timer, timer_callback, 0);
    mod_timer(&my_timer, jiffies + msecs_to_jiffies(100));
    
    return 0;
}


c linux kernel arch
1个回答
0
投票

不幸的是,我无法测试您的代码,但我可以建议您像我一样使用 HR 计时器:

© www.soinside.com 2019 - 2024. All rights reserved.