summaryrefslogtreecommitdiff
path: root/kern/mach_clock.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2015-07-25 18:23:10 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-07-25 20:12:14 +0200
commit3db15a3f80f193826e144b1944727a65c13340fe (patch)
treef6eef1e163de6a5dccdc1067300c5fce333d722b /kern/mach_clock.c
parentbb23879791cf015f17cb50b6443bac44b1cfbc72 (diff)
kern: add boot-time clock, use it for time stampsHEADmaster
The kernel keeps track of task and thread creation times by saving a time stamp. Previously, the real-time clock was used for this. When the real-time clock is changed, however, the reference frame for the time stamps is lost. This surfaced in Hurd systems reporting spuriously long uptimes. Fix this by creating a boot-time clock and use it as reference frame for the time stamps. * kern/mach_clock.c (clock_boottime_offset): Create clock by keeping track of the offset from the real-time. (clock_boottime_update): New function. (record_time_stamp): Use the boot-time clock for time stamps. (read_time_stamp): New function to convert it back to real-time. (host_set_time): Call `clock_boottime_update'. * kern/mach_clock.h (record_time_stamp): Amend comment. (read_time_stamp): New declaration. * kern/task.c (task_info): Use `read_time_stamp'. * kern/thread.c (thread_info): Likewise.
Diffstat (limited to 'kern/mach_clock.c')
-rw-r--r--kern/mach_clock.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/kern/mach_clock.c b/kern/mach_clock.c
index b627b89..655adf4 100644
--- a/kern/mach_clock.c
+++ b/kern/mach_clock.c
@@ -367,9 +367,30 @@ void init_timeout(void)
elapsed_ticks = 0;
}
+
+/*
+ * We record timestamps using the boot-time clock. We keep track of
+ * the boot-time clock by storing the difference to the real-time
+ * clock.
+ */
+struct time_value clock_boottime_offset;
+
+/*
+ * Update the offset of the boot-time clock from the real-time clock.
+ * This function must be called when the real-time clock is updated.
+ * This function must be called at SPLHIGH.
+ */
+void
+clock_boottime_update(struct time_value *new_time)
+{
+ struct time_value delta = time;
+ time_value_sub(&delta, new_time);
+ time_value_add(&clock_boottime_offset, &delta);
+}
/*
- * Record a timestamp in STAMP.
+ * Record a timestamp in STAMP. Records values in the boot-time clock
+ * frame.
*/
void
record_time_stamp (time_value_t *stamp)
@@ -378,6 +399,18 @@ record_time_stamp (time_value_t *stamp)
stamp->seconds = mtime->seconds;
stamp->microseconds = mtime->microseconds;
} while (stamp->seconds != mtime->check_seconds);
+ time_value_add(stamp, &clock_boottime_offset);
+}
+
+/*
+ * Read a timestamp in STAMP into RESULT. Returns values in the
+ * real-time clock frame.
+ */
+void
+read_time_stamp (time_value_t *stamp, time_value_t *result)
+{
+ *result = *stamp;
+ time_value_sub(result, &clock_boottime_offset);
}
@@ -423,6 +456,7 @@ host_set_time(host, new_time)
#endif /* NCPUS > 1 */
s = splhigh();
+ clock_boottime_update(&new_time);
time = new_time;
update_mapped_time(&time);
resettodr();