Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[host][linux] Change to use unix.SysInfo_t to get Uptime in Linux #945

Merged
merged 1 commit into from
Sep 28, 2020

Conversation

shirou
Copy link
Owner

@shirou shirou commented Sep 19, 2020

According to this and this comments, change to use unix.Sysinfo_t in Linux.

Unfortunately, other platform such as FreeBSD do not include "Uptime" in Sysinfo. So this only for Linux.

@Lomanic
Copy link
Collaborator

Lomanic commented Sep 23, 2020

Couldn't we base BootTime against Uptime like on the other platforms? This would improve performance I think (see #842 (comment)).

@shirou
Copy link
Owner Author

shirou commented Sep 27, 2020

Other platform uses time.Now().Unix() via timeSince() function. From my understanding, time.Now() has a monotonic clock but monotonic clock can work only against time object which has a monotonic clock. if not, fall back to wall clock.

Other platform get bootime as just a uint64 which does not have a monotonic clock, so ret value of timeSince() is also not a monotonic. This means, other platform has a problem same as #837 (but not confirmed....).

At least FreeBSD, perhaps we'd better to implement clock_gettime(CLOCK_UPTIME like w source code.

@Lomanic
Copy link
Collaborator

Lomanic commented Sep 28, 2020

In fact we're already using the same thing as timeSince() in host.BootTime() on docker/lxc guests

t := uint64(time.Now().Unix()) - uint64(b)

For the time being I'm merging this, it's already an improvement. 👍

@Lomanic Lomanic merged commit 8ece829 into master Sep 28, 2020
@Lomanic Lomanic deleted the host_linux_change_to_use_sysinfo_to_get_uptime branch September 28, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants