Skip to content
Snippets Groups Projects
  • Nadav Har'El's avatar
    ae65b676
    Document clock::time() and fix its implementation on kvmclock · ae65b676
    Nadav Har'El authored
    
    Our clock::time() function returns the current wall-clock time (number of
    nanoseconds since the Unix epoch). We never clearly documented this, so this
    patch adds this documentation.
    
    Moreover, in kvmclock, we assumed that the host never adjusts its
    wall-clock time, which is not a good assumption because it prevents us
    from benefiting from NTP running on the host. As Avi Kivity explains:
    
       "For the wall clock, you need to sample the wall clock base every time,
        since it can be changed by the host."
    
    So this patch changes kvmclock::time() to sample the wall-clock-at-boot
    reported by the paravirtual clock, on every time() call, and not just once.
    
    The downsite of this patch is that clock::get::time(), and therefore
    nanotime(), become a bit slower on kvmclock, as they need to sample
    the wall_clock_boot() every time, require a couple of barriers and
    arithmetic operations. But note that we shouldn't even be using the
    non-monotonic clock::get::time() for our timers - we should be using the
    monotonic clock::get::uptime() - and when we switch to using that we'll
    get back the bit of performance lost in this patch.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
    ae65b676
    History
    Document clock::time() and fix its implementation on kvmclock
    Nadav Har'El authored
    
    Our clock::time() function returns the current wall-clock time (number of
    nanoseconds since the Unix epoch). We never clearly documented this, so this
    patch adds this documentation.
    
    Moreover, in kvmclock, we assumed that the host never adjusts its
    wall-clock time, which is not a good assumption because it prevents us
    from benefiting from NTP running on the host. As Avi Kivity explains:
    
       "For the wall clock, you need to sample the wall clock base every time,
        since it can be changed by the host."
    
    So this patch changes kvmclock::time() to sample the wall-clock-at-boot
    reported by the paravirtual clock, on every time() call, and not just once.
    
    The downsite of this patch is that clock::get::time(), and therefore
    nanotime(), become a bit slower on kvmclock, as they need to sample
    the wall_clock_boot() every time, require a couple of barriers and
    arithmetic operations. But note that we shouldn't even be using the
    non-monotonic clock::get::time() for our timers - we should be using the
    monotonic clock::get::uptime() - and when we switch to using that we'll
    get back the bit of performance lost in this patch.
    
    Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
    Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
java NaN GiB