Skip to content

Commit 7f34142

Browse files
jmberg-intelrichardweinberger
authored andcommitted
um: time: fix initialization in time-travel mode
In time-travel mode, since my previous patch, the start time was initialized too late, so that the system would read it before we set it, thus always starting system time at 0 (1970-01-01). This happens because timekeeping_init() reads the time and is called before time_init(). Unfortunately, I didn't see this before because I was testing it only with the RTC patch applied (and enabled), and then the time is read again by the RTC a little - after time_init() this time. Fix this by just doing the initialization whenever necessary. Fixes: 2701c1b ("um: time: Fix read_persistent_clock64() in time-travel") Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 9868c20 commit 7f34142

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

arch/um/kernel/time.c

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,31 @@ static int time_travel_connect_external(const char *socket)
535535

536536
return 1;
537537
}
538+
539+
static void time_travel_set_start(void)
540+
{
541+
if (time_travel_start_set)
542+
return;
543+
544+
switch (time_travel_mode) {
545+
case TT_MODE_EXTERNAL:
546+
time_travel_start = time_travel_ext_req(UM_TIMETRAVEL_GET_TOD, -1);
547+
/* controller gave us the *current* time, so adjust by that */
548+
time_travel_ext_get_time();
549+
time_travel_start -= time_travel_time;
550+
break;
551+
case TT_MODE_INFCPU:
552+
case TT_MODE_BASIC:
553+
if (!time_travel_start_set)
554+
time_travel_start = os_persistent_clock_emulation();
555+
break;
556+
case TT_MODE_OFF:
557+
/* we just read the host clock with os_persistent_clock_emulation() */
558+
break;
559+
}
560+
561+
time_travel_start_set = true;
562+
}
538563
#else /* CONFIG_UML_TIME_TRAVEL_SUPPORT */
539564
#define time_travel_start_set 0
540565
#define time_travel_start 0
@@ -553,6 +578,10 @@ static void time_travel_set_interval(unsigned long long interval)
553578
{
554579
}
555580

581+
static inline void time_travel_set_start(void)
582+
{
583+
}
584+
556585
/* fail link if this actually gets used */
557586
extern u64 time_travel_ext_req(u32 op, u64 time);
558587

@@ -731,6 +760,8 @@ void read_persistent_clock64(struct timespec64 *ts)
731760
{
732761
long long nsecs;
733762

763+
time_travel_set_start();
764+
734765
if (time_travel_mode != TT_MODE_OFF)
735766
nsecs = time_travel_start + time_travel_time;
736767
else
@@ -742,25 +773,6 @@ void read_persistent_clock64(struct timespec64 *ts)
742773

743774
void __init time_init(void)
744775
{
745-
#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT
746-
switch (time_travel_mode) {
747-
case TT_MODE_EXTERNAL:
748-
time_travel_start = time_travel_ext_req(UM_TIMETRAVEL_GET_TOD, -1);
749-
/* controller gave us the *current* time, so adjust by that */
750-
time_travel_ext_get_time();
751-
time_travel_start -= time_travel_time;
752-
break;
753-
case TT_MODE_INFCPU:
754-
case TT_MODE_BASIC:
755-
if (!time_travel_start_set)
756-
time_travel_start = os_persistent_clock_emulation();
757-
break;
758-
case TT_MODE_OFF:
759-
/* we just read the host clock with os_persistent_clock_emulation() */
760-
break;
761-
}
762-
#endif
763-
764776
timer_set_signal_handler();
765777
late_time_init = um_timer_setup;
766778
}

0 commit comments

Comments
 (0)