LWN.net Logo

Driver porting: the workqueue interface.

Driver porting: the workqueue interface.

Posted Aug 16, 2004 1:16 UTC (Mon) by baisa (guest, #24024)
Parent article: Driver porting: the workqueue interface.

How do I schedule work tasks (if indeed this is the object I should be using) to execute every timer tick? In the book, in chap 6 "Flow of Time" it lists at least 3 kernel task queues, one of which was a timer queue that dispatched its tasks each tick. But the entire "linux/tqueue.h" functionality was deleted in 2.6, and now I can't figure out how to dispatch some code every timer tick.

Thanks! Brad


(Log in to post comments)

Driver porting: the workqueue interface.

Posted Sep 15, 2004 7:05 UTC (Wed) by Albert (guest, #24733) [Link]

I ran into the same problem. We ran a stepper motor from the timer interrupt. In 2.6 I used the RTC instead. Here is some code for a minimal module that uses RTC to generate IRQ8 at 1024 Hz and also registers an interrupt handler for IRQ8 (via the RTC module).

/*
* stepper.c - Stepper motor driver using RTC.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
#include <linux/init.h> /* Needed for the macros */
#include <linux/ioctl.h>

#if defined(CONFIG_RTC) || defined(CONFIG_RTC_MODULE)

#include <linux/rtc.h>

#define DRIVER_AUTHOR "John Doe <some@one>"
#define DRIVER_DESC "Stepper motor driver using RTC"

static rtc_task_t rtc_task;
static atomic_t rtc_inc = ATOMIC_INIT(0);
static int stepper_freq = 1024; /* Frequency Hz */

static void stepper_interrupt(void *private_data)
{
int ticks;

atomic_inc(&rtc_inc);
ticks = atomic_read(&rtc_inc);

/* Add some code here to drive the stepper motor */
if (ticks % stepper_freq == 0) {
printk(KERN_WARNING "stepper_interrupt: %d\n", ticks);
}
}

static int __init stepper_init(void)
{
int err;
printk(KERN_ALERT "stepper_init: registering task\n");

rtc_task.func = stepper_interrupt;
err = rtc_register(&rtc_task);
if (err < 0)
return err;
rtc_control(&rtc_task, RTC_IRQP_SET, stepper_freq);
rtc_control(&rtc_task, RTC_PIE_ON, 0);
atomic_set(&rtc_inc, 0);
return 0;
}

static void __exit stepper_exit(void)
{
rtc_control(&rtc_task, RTC_PIE_OFF, 0);
rtc_unregister(&rtc_task);
printk(KERN_ALERT "stepper_exit: rtc_task unregistered\n");
}

module_init(stepper_init);
module_exit(stepper_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);

#endif /* CONFIG_RTC || CONFIG_RTC_MODULE */

Driver porting: the workqueue interface.

Posted Jan 20, 2005 6:17 UTC (Thu) by amit2030 (guest, #27378) [Link]

Hi,

I wanted to know whether the workqueue gets scheduled before a kernel thread (created by kthread_run()). I have a function that runs in the thread created by kthread_run(). If I use the workqueue interface, then will it be scheduled before other threads created by kthread_run().

Regards,

Driver porting: the workqueue interface.

Posted May 16, 2005 0:44 UTC (Mon) by Freiberg (guest, #29960) [Link]

Could you please tell me more about Work Queue synchronization?
Are they cumulative? If I scheduled the same work several times inside
one isr handler or different isr handlers will all of them run or not and in which sequence?

Thanks,
Vlad

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds