--- nono/vm/rtc.cpp 2026/04/29 17:05:51 1.1.1.13 +++ nono/vm/rtc.cpp 2026/04/29 17:06:01 1.1.1.14 @@ -11,6 +11,7 @@ #include "rtc.h" #include "config.h" #include "event.h" +#include "mytime.h" #include "scheduler.h" #include "syncer.h" @@ -38,7 +39,7 @@ RTCDevice::Init() // ゲストの状態が毎回異なることになるため、 // いつ何時も同じ値を返すことで、世界から隔絶された // VM を作り、パフォーマンス測定を安定させる。 - force_fixed = gConfig->Find(".rtc-force-fixed").AsInt(); + force_fixed = gConfig->Find(".rtc-force-fixed").AsBool(); sync_rt = syncer->GetSyncRealtime(); @@ -86,7 +87,6 @@ RTCDevice::Init() "RTC ClockIn"); event->time = period; - return true; } @@ -94,7 +94,8 @@ RTCDevice::Init() void RTCDevice::StartTime() { - struct timeval tv; + time_t now_sec; + uint64 now_usec; struct tm tm; if (force_fixed) { @@ -107,17 +108,19 @@ RTCDevice::StartTime() .tm_mon = 7 - 1, .tm_year = 2018 - 1900, }; - tv.tv_sec = timegm(&fixed); - tv.tv_usec = 0; + now_sec = timegm(&fixed); + now_usec = 0; } else { // 起動した時の現在時刻で設定する - gettimeofday(&tv, NULL); + auto usec = get_hosttime_usec(); + now_sec = usec / 1000'000U; + now_usec = usec % 1000'000U; } if (use_localtime) { - localtime_r(&tv.tv_sec, &tm); + localtime_r(&now_sec, &tm); } else { - gmtime_r(&tv.tv_sec, &tm); + gmtime_r(&now_sec, &tm); } // 日付、時刻の直接指定があればここで差し替える。 @@ -136,7 +139,7 @@ RTCDevice::StartTime() } // 秒未満の初期値もそれなりの精度にしておく (1000*1000 / 32 = 31250) - cnt = tv.tv_usec / 31250; + cnt = now_usec / 31250; SetSec(tm.tm_sec); SetMin(tm.tm_min); SetHour(tm.tm_hour);