[crac] RFR: Correct System.nanotime() value after restore [v4]
Anton Kozlov
akozlov at openjdk.org
Fri Apr 21 14:57:13 UTC 2023
On Thu, 20 Apr 2023 08:09:26 GMT, Radim Vansa <duke at openjdk.org> wrote:
>> There are various places both inside JDK and in libraries that rely on monotonicity of `System.nanotime()`. When the process is restored on a different machine the value will likely differ as the implementation provides time since machine boot. This PR records wall clock time before checkpoint and after restore and tries to adjust the value provided by nanotime() to reasonably correct value.
>
> Radim Vansa has updated the pull request incrementally with one additional commit since the last revision:
>
> Set nanotime only if bootid changes
src/hotspot/os/linux/os_linux.cpp line 6605:
> 6603:
> 6604: bool os::read_bootid(char *dest, size_t size) {
> 6605: int fd = ::open("/proc/sys/kernel/random/boot_id", O_RDONLY);
Bood_id looks interesting! But AFAICS it remains the same for each new container, and the boot time may have been adjusted for that container.
anton at mercury:~$ docker run -it ubuntu:20.04 cat /proc/sys/kernel/random/boot_id
9b913973-3082-471a-add5-6b802a04a9b2
anton at mercury:~$ docker run -it ubuntu:20.04 cat /proc/sys/kernel/random/boot_id
9b913973-3082-471a-add5-6b802a04a9b2
anton at mercury:~$ cat /proc/sys/kernel/random/boot_id
9b913973-3082-471a-add5-6b802a04a9b2
Should not we mix something extra to boot_id, for example, a hostname (which is different for each container)?
src/hotspot/share/runtime/os.cpp line 2045:
> 2043: char buf[UUID_LENGTH + 1];
> 2044: // We will change the nanotime offset only if this is not the same boot
> 2045: // to prevent reducing the accuracy of System.nanoTime() unnecessarily
But it would be nice to ensure monotonicity even if it looks like the same boot. Like
if (!same_boot) {
...
} else if ((diff = (checkpoint_nanos - javaTimeNanos()) > 0) {
javaTimeNanos_offset = diff + 1;
}
src/hotspot/share/runtime/os.cpp line 2055:
> 2053: // Make the javaTimeNanos() on the next line return true monotonic time
> 2054: javaTimeNanos_offset = 0;
> 2055: javaTimeNanos_offset = checkpoint_nanos - javaTimeNanos() + diff_millis * 1000000L;
First assignment does not make effect.
-------------
PR Review Comment: https://git.openjdk.org/crac/pull/53#discussion_r1173871537
PR Review Comment: https://git.openjdk.org/crac/pull/53#discussion_r1173867249
PR Review Comment: https://git.openjdk.org/crac/pull/53#discussion_r1173862993
More information about the crac-dev
mailing list