Repetición de tareas en el kernel de Linux.

Mi objetivo es crear una tarea recurrente en el kernel de Linux usando elhrtimer estructura Me gustaría que se repita cada 500 ms.

Sin embargo, estoy un poco confundido acerca de cómohrtimer trabaja en el kernel de linux (verlinux/hrtimer.h). Sé que el tiempo está especificado, y la devolución de llamada debe devolver cualquieraHRTIMER_RESTART oHRTIMER_NORESTART. He encontrado algunas fuentes en línea que indican que el temporizador debe restablecerse en la devolución de llamada utilizando elhrtimer_forward método. Sin embargo, las fuentes que he visto son un poco confusas sobre cómo agregar el tiempo funciona. Aquí está el código que tengo hasta ahora:

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");
}

¿Alguien puede explicar exactamente cómo restablecer el temporizador funcionaría en la función de devolución de llamada? ¡Gracias!

Respuestas a la pregunta(2)

Su respuesta a la pregunta