Skip to content

Commit 6610e08

Browse files
RTC: Rework RTC code to use timerqueue for events
This patch reworks a large portion of the generic RTC code to in-effect virtualize the rtc interrupt code. The current RTC interface is very much a raw hardware interface. Via the proc, /dev/, or sysfs interfaces, applciations can set the hardware to trigger interrupts in one of three modes: AIE: Alarm interrupt UIE: Update interrupt (ie: once per second) PIE: Periodic interrupt (sub-second irqs) The problem with this interface is that it limits the RTC hardware so it can only be used by one application at a time. The purpose of this patch is to extend the RTC code so that we can multiplex multiple applications event needs onto a single RTC device. This is done by utilizing the timerqueue infrastructure to manage a list of events, which cause the RTC hardware to be programmed to fire an interrupt for the next event in the list. In order to preserve the functionality of the exsting proc,/dev/ and sysfs interfaces, we emulate the different interrupt modes as follows: AIE: We create a rtc_timer dedicated to AIE mode interrupts. There is only one per device, so we don't change existing interface semantics. UIE: Again, a dedicated rtc_timer, set for periodic mode, is used to emulate UIE interrupts. Again, only one per device. PIE: Since PIE mode interrupts fire faster then the RTC's clock read granularity, we emulate PIE mode interrupts using a hrtimer. Again, one per device. With this patch, the rtctest.c application in Documentation/rtc.txt passes fine on x86 hardware. However, there may very well still be bugs, so greatly I'd appreciate any feedback or testing! Signed-off-by: John Stultz <[email protected]> LKML Reference: <[email protected]> Acked-by: Alessandro Zummo <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> CC: Alessandro Zummo <[email protected]> CC: Thomas Gleixner <[email protected]> CC: Richard Cochran <[email protected]>
1 parent b007c38 commit 6610e08

File tree

4 files changed

+428
-230
lines changed

4 files changed

+428
-230
lines changed

drivers/rtc/class.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/kdev_t.h>
1717
#include <linux/idr.h>
1818
#include <linux/slab.h>
19+
#include <linux/workqueue.h>
1920

2021
#include "rtc-core.h"
2122

@@ -152,6 +153,18 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
152153
spin_lock_init(&rtc->irq_task_lock);
153154
init_waitqueue_head(&rtc->irq_queue);
154155

156+
/* Init timerqueue */
157+
timerqueue_init_head(&rtc->timerqueue);
158+
INIT_WORK(&rtc->irqwork, rtctimer_do_work);
159+
/* Init aie timer */
160+
rtctimer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc);
161+
/* Init uie timer */
162+
rtctimer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc);
163+
/* Init pie timer */
164+
hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
165+
rtc->pie_timer.function = rtc_pie_update_irq;
166+
rtc->pie_enabled = 0;
167+
155168
strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
156169
dev_set_name(&rtc->dev, "rtc%d", id);
157170

0 commit comments

Comments
 (0)