Wrong System Time in OS/2 Guest

Discussions about using non Windows and Linux guests such as FreeBSD, DOS, OS/2, OpenBSD, etc.
mipri
Posts: 23
Joined: 20. Sep 2016, 16:05

Wrong System Time in OS/2 Guest

Post by mipri »

Hello,

there is a problem with the system clock in my OS/2 guest.

I am running VirtualBox 6.1.24 on a Windows 10 (version 20H2) host. The system clock is running at local time with timezone "Europe/Berlin" and automatically switching to DST enabled. Actually my local time is GMT+2h, without DST it is GMT+1h

The guest is OS/2 Version 4.50 with guest additions 6.1.24 installed. Since the system clock on OS/2 is always running at local time it should be the same time as on the host.

The TZ environment variable for the guest is set to
TZ=MET-1DST,3,-1,0,7200,10,-1,0,10800,3600

meaning that the standard time zone is Middle European Time (MET) with a time zone offset of -1 (1h east of GMT). There is a daylight saving time (DST) starting in March (3) on the last (-1) sunday (0) at 2:00 (7200 sec after midnight). It is ending in October (10) on the last (-1) sunday (0) at 3:00 (10800 sec after midnight), and the offset to the standard time is 1h (3600s).

This is working for most OS/2 applications and also e.g. with gcc/emx.

When I am starting the guest with this TZ variable, the system time is wrong. When it is 10:00 (local time in DST) on the host, the time on the guest is 9:00. It is not possible to fix this by setting the correct time inside the guest, because vboxservice.exe is changing the clock back to the wrong value immediately.

When I am starting the guest without TZ set, the guest's time is back 2h. So at 10:00 on the host it is 8:00 for the guest.

To get the correct time for the guest, I have to set TZ=-2 now in summer and manually change it to TZ=-1 in winter.

It does not make a difference if 'Hardware Clock in UTC' in the VM's settings is checked or not!

Earlier versions of VirtualBox did not have this problem.

IMO the Guest Additions should not change the guest's clock at all. But if they do, they should treat TZ correctly also in the long format.
LewisR
Posts: 24
Joined: 7. Sep 2008, 02:12
Primary OS: openSUSE
VBox Version: OSE self-compiled
Guest OSses: OS/2, Windows, Linux, Android, NetWare

Re: Wrong System Time in OS/2 Guest

Post by LewisR »

Indeed, this is a known issue with a fixed libc (not yet packaged and released to netlabs-exp, as yet). See:
https://github.com/bitwiseworks/libc/issues/109

HTH
Lewis
--------
Lewis G Rosenthal, CNA, CLE, CLP, CWTS
Arca Noae, LLC
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Wrong System Time in OS/2 Guest

Post by mpack »

mipri wrote: IMO the Guest Additions should not change the guest's clock at all.
They don't, unless you explicitly chose to set a time offset.

The time comes from the Real Time Clock (RTC), a piece of virtual hardware - not Guest Addition software. The RTC in turn of course gets current wall clock time from the host OS, and turns it into UTC.

If your guest OS ignores the RTC and reads a network time server, that's up to you to fix. Likewise if you configure an incorrect time zone in host or guest. These (plus the explicit offset) are the only possible ways for the guest time to differ from the host time.
LewisR
Posts: 24
Joined: 7. Sep 2008, 02:12
Primary OS: openSUSE
VBox Version: OSE self-compiled
Guest OSses: OS/2, Windows, Linux, Android, NetWare

Re: Wrong System Time in OS/2 Guest

Post by LewisR »

The problem here affects VMs as well as bare metal systems. The calculation of the TZ offset is incorrect beginning in 2021, as a result of a previous Y2038 bug. The following post in the previously-referenced ticket summarizes the problem nicely:

https://github.com/bitwiseworks/libc/is ... -882764025

So, no, it's not an issue with the Guest Additions per se. Rather, it's a problem with all modern kLIBC applications which rely on the offset calculation. So, even if using a NTP server, the OS/2 system's offset will be "off" as a result of this issue.
Lewis
--------
Lewis G Rosenthal, CNA, CLE, CLP, CWTS
Arca Noae, LLC
mipri
Posts: 23
Joined: 20. Sep 2016, 16:05

Re: Wrong System Time in OS/2 Guest

Post by mipri »

Thank you both for your answers.
LewisR wrote:this is a known issue with a fixed libc
With this information I was able to fix the problem for the moment (see below).
mpack wrote:If your guest OS ignores the RTC and reads a network time server, that's up to you to fix. Likewise if you configure an incorrect time zone in host or guest.
Neither my guest is using a network time server nor did I configure an incorrect time zone anywhere. And in both cases it should be possible to correct the clock manually. But instead I observed this:
  • After booting the guest, the system clock was wrong by 1h (and 1h different to the host clock).
  • Then I opened an OS/2 command window and tried to set the correct time using the 'time' command.
  • While vboxservice.exe was running, the clock was changed back to the wrong time after a few seconds. I also tried "net time" to get the time from another machine, with the same result.
  • However, after killing vboxservice.exe it was possible to set the correct time permanently.
After this it is clear it must have to do with Guest Additions.
mpack wrote:The time comes from the Real Time Clock (RTC), a piece of virtual hardware - not Guest Addition software.
After digging a bit through the source code I found the following: there is a "Guest Additions TimeSync Service" as part of VBoxService (see /src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp) which periodically(!) synchronizes the guest OS walltime with the host. Because of this the Guest Addditions have big impact on the guest's clock, and they also prevent any changes to the guest's system clock. Now obviously in the Guest Additions for OS/2 this TimeSync Service is affected the the bug in libc and (periodically) sets the guest's time wrong.

For me, the solution is to disable this "TimeSync Service" until libc gets fixed. This can be done by starting vboxservice.exe (in startup.cmd) with command line parameter --disable-timesync.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Wrong System Time in OS/2 Guest

Post by fth0 »

mipri wrote:This can be done by starting vboxservice.exe (in startup.cmd) with command line parameter --disable-timesync.
An alternative way to do this is by changing the VM configuration with the following command, while the VM is not running:

Code: Select all

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Wrong System Time in OS/2 Guest

Post by mpack »

fth0 wrote:

Code: Select all

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
Are you sure about that? That sounds like it would leave the RTC uninitialized entirely, rather than just disable the resync part of it.

I see this command is taken from section 9.11.4 of the user manual. That section doesn't really answer my question either. According to it, the effect of that config is to "forbid the guest service from reading the host clock".
Martin
Volunteer
Posts: 2560
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: Wrong System Time in OS/2 Guest

Post by Martin »

What happens if you configure the OS/2 timezone to a zone one hour later?
mipri
Posts: 23
Joined: 20. Sep 2016, 16:05

Re: Wrong System Time in OS/2 Guest

Post by mipri »

Then the walltime would be correct, but applications not using the buggy version of libc would use the wrong time zone and therefore calculate a wrong value for GMT. Remember: in OS/2 the RTC runs local time, not UTC, and OS/2 itself does not really care about time zones.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Wrong System Time in OS/2 Guest

Post by mpack »

mipri wrote:Remember: in OS/2 the RTC runs local time, not UTC
I'm pretty sure the simulated RTC in VirtualBox returns UTC, i.e. the host clock is automatically compensated for time zone before passing it to the VM, otherwise time zone would never be treated correctly in any VM - except when the time is GMT+0.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Wrong System Time in OS/2 Guest

Post by fth0 »

mpack wrote:Are you sure about that? That sounds like it would leave the RTC uninitialized entirely, rather than just disable the resync part of it.
We'll have to split some hairs here: ;)

The VBoxService - Guest Additions TimeSync Service is implemented in VBoxServiceTimeSync.cpp, and its workhorse vgsvcTimeSyncWorker() is the only function (indirectly) calling vmmdevReqHandler_GetHostTime() in VMMDev.cpp, which has the only code evaluating GetHostTimeDisabled.

In consequence, I'm pretty sure that this setting has more or less the same effect as running VBoxService without TimeSync. But: Although vgsvcTimeSyncWorker() contains an initial time synchronization before looping forever, there could be another previous first initialization somewhere else, so it doesn't follow if the RTC is left uninitialized or not.
Last edited by fth0 on 12. Aug 2021, 21:56, edited 1 time in total.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Wrong System Time in OS/2 Guest

Post by fth0 »

mpack wrote:I'm pretty sure the simulated RTC in VirtualBox returns UTC
What's doing System > Motherboard > Hardware Clock in UTC Time then?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Wrong System Time in OS/2 Guest

Post by mpack »

fth0 wrote:What's doing System > Motherboard > Hardware Clock in UTC Time then?
Are you asking what that setting does? I dunno. I convinced myself as above that if the host does TZ correction, and then the VM applies the same correction again (*), then the VM clock would always be wrong (double offset always applied). I can't see how else it could work.

(*) ISTM to that someone living (say) in Paris will choose the Paris TZ in host, guest, and every other PC in their vicinity: so the host would apply an offset, and then the VM would apply the same offset again. If the host time was already correct the VM time can't be.

All my VMs are set up to use network time, and I'm not willing to mess with that to examine this: too many things can get upset if they see clock tampering.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Wrong System Time in OS/2 Guest

Post by fth0 »

No, I'm not really asking what that setting does, it was rather meant as a hint or reminder, because I couldn't imagine that you don't really know. Also, I forgot to put in the :wink: smiley, which I usually use to mark friendly hinting. I'll try and explain:

On a physical PC, a Linux host interprets the time in the RTC as UTC and adds the local time offset (UTC + TZ + DST) itself. When it acquires the network time via NTP, it subtracts TZ + DST before writing the result to the RTC. A Windows host however interprets the RTC as local time and writes the network time to the RTC unmodified.

In the VirtualBox configuration templates, System > Motherboard > Hardware Clock in UTC Time is set for Linux guests and unset for Windows and OS/2 guests, and VirtualBox provides the virtual RTC to the guest OS accordingly.
Last edited by fth0 on 12. Aug 2021, 22:50, edited 1 time in total.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Wrong System Time in OS/2 Guest

Post by fth0 »

@mipri, @LewisR:

Since I know that Oracle prefers static linking in some places, a question about the VBoxService.exe from the VirtualBox GA for OS/2, just to be sure:

Is the VBoxService.exe dynamically linked to the OS/2 C library and you're waiting for the fix in OS/2, or is the VBoxService.exe statically linked to its own C library and you're waiting for a fix from Oracle?
Post Reply