summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2016-06-13 16:29:05 +0200
committerMichael Brown2016-06-13 16:29:05 +0200
commite6111c151794c4c15a0988e259666ef5be24ffcc (patch)
tree6e4febac53299a9ecbf4bff3c0a5dd676de75094 /src
parent[tg3] Add missing memory barrier (diff)
downloadipxe-e6111c151794c4c15a0988e259666ef5be24ffcc.tar.gz
ipxe-e6111c151794c4c15a0988e259666ef5be24ffcc.tar.xz
ipxe-e6111c151794c4c15a0988e259666ef5be24ffcc.zip
[time] Allow system clock to be adjusted at runtime
Provide a mechanism to allow an arbitrary adjustment to be applied to all subsequent calls to time(). Note that the underlying clock source (e.g. the RTC clock) will not be changed; only the time as reported within iPXE will be affected. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/core/time.c3
-rw-r--r--src/include/ipxe/time.h15
-rw-r--r--src/include/time.h4
3 files changed, 19 insertions, 3 deletions
diff --git a/src/core/time.c b/src/core/time.c
index 29a924ebe..c353ac5bd 100644
--- a/src/core/time.c
+++ b/src/core/time.c
@@ -43,6 +43,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* 400.
*/
+/** Current system clock offset */
+signed long time_offset;
+
/** Days of week (for debugging) */
static const char *weekdays[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
diff --git a/src/include/ipxe/time.h b/src/include/ipxe/time.h
index 4c5bb2a00..89bf90e03 100644
--- a/src/include/ipxe/time.h
+++ b/src/include/ipxe/time.h
@@ -50,11 +50,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/* Include all architecture-dependent time API headers */
#include <bits/time.h>
+extern signed long time_offset;
+
/**
- * Get current time in seconds
+ * Get current time in seconds (ignoring system clock offset)
*
* @ret time Time, in seconds
*/
time_t time_now ( void );
+/**
+ * Adjust system clock
+ *
+ * @v delta Clock adjustment, in seconds
+ */
+static inline __attribute__ (( always_inline )) void
+time_adjust ( signed long delta ) {
+
+ time_offset += delta;
+}
+
#endif /* _IPXE_TIME_H */
diff --git a/src/include/time.h b/src/include/time.h
index 462ac6999..ab93a3dbb 100644
--- a/src/include/time.h
+++ b/src/include/time.h
@@ -39,10 +39,10 @@ struct tm {
* @v t Time to fill in, or NULL
* @ret time Current time
*/
-static inline time_t time ( time_t *t ) {
+static inline __attribute__ (( always_inline )) time_t time ( time_t *t ) {
time_t now;
- now = time_now();
+ now = ( time_now() + time_offset );
if ( t )
*t = now;
return now;