mirror of
https://github.com/schoebel/mars
synced 2025-01-11 17:19:53 +00:00
infra: lamport clock can never appear as stopped
In case CONFIG_HIGH_RES_TIMERS is not set (or when it does not work as expected), the lamport clock could "stop" in some extremely rare cases. Theoretically, a symlink update could be missed, or two transaction log records could accidentally get the same timestamp. We want any timestamps to be unique (at least on the same host). This patch ensures that true forward stepping always takes place, even when the system clock fails (or at other problems). For now, the dependency from CONFIG_HIGH_RES_TIMERS is left in Kconfig as a precondition for MARS. After some tests and some observational time, it could probably be removed some day.
This commit is contained in:
parent
08d4f863ff
commit
105bc07b58
@ -581,8 +581,10 @@ void get_lamport(struct timespec *now)
|
||||
//*now = current_kernel_time();
|
||||
*now = CURRENT_TIME;
|
||||
diff = timespec_compare(now, &lamport_now);
|
||||
if (diff > 0) {
|
||||
if (diff >= 0) {
|
||||
timespec_add_ns(now, 1);
|
||||
memcpy(&lamport_now, now, sizeof(lamport_now));
|
||||
timespec_add_ns(&lamport_now, 1);
|
||||
} else {
|
||||
timespec_add_ns(&lamport_now, 1);
|
||||
memcpy(now, &lamport_now, sizeof(*now));
|
||||
@ -600,8 +602,9 @@ void set_lamport(struct timespec *old)
|
||||
down(&lamport_sem);
|
||||
|
||||
diff = timespec_compare(old, &lamport_now);
|
||||
if (diff > 0) {
|
||||
if (diff >= 0) {
|
||||
memcpy(&lamport_now, old, sizeof(lamport_now));
|
||||
timespec_add_ns(&lamport_now, 1);
|
||||
}
|
||||
|
||||
up(&lamport_sem);
|
||||
|
Loading…
Reference in New Issue
Block a user