How to add periodic timer callbacks in Linux kernel modules
I’m working on a Linux kernel module that registers callbacks for interrupts from custom boards and puts the received data into a queue behind the character device interface for application processing. Even if there are no interrupts from the line card, the module needs to constantly monitor and measure the interrupts and data from the line card, so it has another callback that is triggered based on the time.
The current implementation uses RTC interrupts as a constant timer source. I disable the kernel RTC driver (
CONFIG_RTC_DRV_CMOS) and request IRQ 8 and hook the timer callback to the RTC interrupt handler. The RTC chip generates an interrupt every second.
The problem is that we have to lose some Linux ability to manage time in this way, since only
rtc-cmos or one of the board modules can be loaded at a time (apparently we chose the board module).
The Linux kernel comes from the
linux-source package that comes with Debian 7.2 stable, version
3.2+46. The target architecture is the i386 PC.
I’m not a kernel developer and therefore don’t have a comprehensive understanding of kernel module development, but I’m struggling to find my own methods, and these are the closest solutions I can think of:
- Somehow sharing IRQ 8 between two modules (possibly like
request_irq(8, rtc_handler, IRQF_SHARED, rtc_handler)?) ) or chain-loaded IRQ handler.
- Look for another way to hook up handlers from kernel modules to RTC interrupts instead of registering IRQ 8.
- Looking for another source of 1 second timer events that can be used in kernel modules, maybe there is a standard kernel API, I don’t know.
I guess there might be a simple and standard way to do this, and I’d be happy if anyone commented on any of these solutions or suggested other solutions.