-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alarm: fix new alarm insertion when one of the alarms overflows
Fixes #466 When inserting an alarm into the virtual alarm queue, comparing two alarms needs to account for alarms that may wrap beyond the clock overflow. Simply comparing computed expirations against the new alarm's reference isn't sufficient, as the current alarm may overflow, resulting in an expiration that is earlies by absolute value, but should still expire later.
- Loading branch information
Showing
6 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../../.. | ||
|
||
# Which files to compile. | ||
C_SRCS := $(wildcard *.c) | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Test Multiple Alarms (With Overflow) | ||
|
||
This tests the virtual alarms available to userspace. It sets two | ||
alarms, first one that overflows the alarm, such that it's expiration | ||
is small in absolute value (but should shouldn't fire until after the | ||
clock overflows) and one after 1s. When successful, the second (1s) | ||
alarm should fire after 1 second, while the second alarm should fire | ||
after the clock overflows (approximately 7 minutes if the clock is at | ||
32kHz). | ||
|
||
If the virtual alarm library is buggy, this test might fail by | ||
scheduling the 1 second alarm _after_ the longer wrapping alarm, and | ||
it won't fire immediately. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <libtock-sync/services/alarm.h> | ||
|
||
static void event_cb(uint32_t now, uint32_t expiration, void* ud) { | ||
int i = (int)ud; | ||
printf("%d %lu %lu\n", i, now, expiration); | ||
} | ||
|
||
int main(void) { | ||
libtock_alarm_t t1; | ||
libtock_alarm_t t2; | ||
|
||
uint32_t now; | ||
libtock_alarm_command_read(&now); | ||
|
||
uint32_t overflow_ms = libtock_alarm_ticks_to_ms(UINT32_MAX); | ||
|
||
libtock_alarm_in_ms(overflow_ms, event_cb, (void*)1, &t1); | ||
libtock_alarm_in_ms(1000, event_cb, (void*)2, &t2); | ||
|
||
while (1) { | ||
yield(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters