浏览代码

[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>
tags/v1.20.1
Michael Brown 8 年前
父节点
当前提交
e6111c1517
共有 3 个文件被更改,包括 19 次插入3 次删除
  1. 3
    0
      src/core/time.c
  2. 14
    1
      src/include/ipxe/time.h
  3. 2
    2
      src/include/time.h

+ 3
- 0
src/core/time.c 查看文件

43
  * 400.
43
  * 400.
44
  */
44
  */
45
 
45
 
46
+/** Current system clock offset */
47
+signed long time_offset;
48
+
46
 /** Days of week (for debugging) */
49
 /** Days of week (for debugging) */
47
 static const char *weekdays[] = {
50
 static const char *weekdays[] = {
48
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
51
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"

+ 14
- 1
src/include/ipxe/time.h 查看文件

50
 /* Include all architecture-dependent time API headers */
50
 /* Include all architecture-dependent time API headers */
51
 #include <bits/time.h>
51
 #include <bits/time.h>
52
 
52
 
53
+extern signed long time_offset;
54
+
53
 /**
55
 /**
54
- * Get current time in seconds
56
+ * Get current time in seconds (ignoring system clock offset)
55
  *
57
  *
56
  * @ret time		Time, in seconds
58
  * @ret time		Time, in seconds
57
  */
59
  */
58
 time_t time_now ( void );
60
 time_t time_now ( void );
59
 
61
 
62
+/**
63
+ * Adjust system clock
64
+ *
65
+ * @v delta		Clock adjustment, in seconds
66
+ */
67
+static inline __attribute__ (( always_inline )) void
68
+time_adjust ( signed long delta ) {
69
+
70
+	time_offset += delta;
71
+}
72
+
60
 #endif /* _IPXE_TIME_H */
73
 #endif /* _IPXE_TIME_H */

+ 2
- 2
src/include/time.h 查看文件

39
  * @v t			Time to fill in, or NULL
39
  * @v t			Time to fill in, or NULL
40
  * @ret time		Current time
40
  * @ret time		Current time
41
  */
41
  */
42
-static inline time_t time ( time_t *t ) {
42
+static inline __attribute__ (( always_inline )) time_t time ( time_t *t ) {
43
 	time_t now;
43
 	time_t now;
44
 
44
 
45
-	now = time_now();
45
+	now = ( time_now() + time_offset );
46
 	if ( t )
46
 	if ( t )
47
 		*t = now;
47
 		*t = now;
48
 	return now;
48
 	return now;

正在加载...
取消
保存