tarefa de repetição do hrtimer no kernel do Linux
Meu objetivo é criar uma tarefa recorrente no kernel do Linux usando ohrtimer
struct. Eu gostaria que se repetisse a cada 500 ms.
No entanto, estou um pouco confuso sobre comohrtimer
funciona no kernel do linux (vejalinux/hrtimer.h
). Eu sei que o tempo é especificado, e o retorno de chamada deve retornarHRTIMER_RESTART
ouHRTIMER_NORESTART
. Eu encontrei algumas fontes on-line que afirmam que o timer precisa ser redefinido no retorno de chamada usando ohrtimer_forward
método. No entanto, as fontes que vi são um pouco incertas sobre como adicionar o tempo funciona. Aqui está o código que tenho até agora:
static struct hrtimer timer;
static enum hrtimer_restart timer_callback(struct hrtimer *timer)
{
printk(KERN_ERR "Callback\n");
//I know something needs to go here to reset the timer
return HRTIMER_RESTART;
}
static int init_timer(void)
{
ktime_t ktime;
unsigned long delay_in_ms = 500L;
printk(KERN_ERR "Timer being set up\n");
ktime = ktime_set(0,delay_in_ms*1E6L);
hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timer.function = &timer_callback;
printk(KERN_ERR "Timer starting to fire\n");
printk(KERN_ERR "in %ldms %ld\n", delay_in_ms, jiffies);
hrtimer_start(&timer, ktime, HRTIMER_MODE_REL);
return 0;
}
static void clean_load_balancing_timer(void)
{
int cancelled = hrtimer_cancel(&timer);
if (cancelled)
printk(KERN_ERR "Timer still running\n");
else
printk(KERN_ERR "Timer cancelled\n");
}
Alguém pode explicar exatamente como redefinir o timer funcionaria na função de retorno de chamada? Obrigado!