diff options
| author | Stefan Fritsch <sf@sfritsch.de> | 2012-09-16 06:55:40 -0400 |
|---|---|---|
| committer | Marcelo Tosatti <mtosatti@redhat.com> | 2012-09-17 13:10:23 -0400 |
| commit | 879238fecc051d95037ae76332916209a7770709 (patch) | |
| tree | 078ae5712c8dd13865b2c245e19cfdbf246abe66 /Documentation/virtual/kvm | |
| parent | 9fc77441e5e1bf80b794cc546d2243ee9f4afb75 (diff) | |
KVM: clarify kvmclock documentation
- mention that system time needs to be added to wallclock time
- positive tsc_shift means left shift, not right
- mention additional 32bit right shift
Signed-off-by: Stefan Fritsch <sf@sfritsch.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'Documentation/virtual/kvm')
| -rw-r--r-- | Documentation/virtual/kvm/msr.txt | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Documentation/virtual/kvm/msr.txt b/Documentation/virtual/kvm/msr.txt index 73047104858..6d470ae7b07 100644 --- a/Documentation/virtual/kvm/msr.txt +++ b/Documentation/virtual/kvm/msr.txt | |||
| @@ -34,9 +34,12 @@ MSR_KVM_WALL_CLOCK_NEW: 0x4b564d00 | |||
| 34 | time information and check that they are both equal and even. | 34 | time information and check that they are both equal and even. |
| 35 | An odd version indicates an in-progress update. | 35 | An odd version indicates an in-progress update. |
| 36 | 36 | ||
| 37 | sec: number of seconds for wallclock. | 37 | sec: number of seconds for wallclock at time of boot. |
| 38 | 38 | ||
| 39 | nsec: number of nanoseconds for wallclock. | 39 | nsec: number of nanoseconds for wallclock at time of boot. |
| 40 | |||
| 41 | In order to get the current wallclock time, the system_time from | ||
| 42 | MSR_KVM_SYSTEM_TIME_NEW needs to be added. | ||
| 40 | 43 | ||
| 41 | Note that although MSRs are per-CPU entities, the effect of this | 44 | Note that although MSRs are per-CPU entities, the effect of this |
| 42 | particular MSR is global. | 45 | particular MSR is global. |
| @@ -82,20 +85,25 @@ MSR_KVM_SYSTEM_TIME_NEW: 0x4b564d01 | |||
| 82 | time at the time this structure was last updated. Unit is | 85 | time at the time this structure was last updated. Unit is |
| 83 | nanoseconds. | 86 | nanoseconds. |
| 84 | 87 | ||
| 85 | tsc_to_system_mul: a function of the tsc frequency. One has | 88 | tsc_to_system_mul: multiplier to be used when converting |
| 86 | to multiply any tsc-related quantity by this value to get | 89 | tsc-related quantity to nanoseconds |
| 87 | a value in nanoseconds, besides dividing by 2^tsc_shift | ||
| 88 | 90 | ||
| 89 | tsc_shift: cycle to nanosecond divider, as a power of two, to | 91 | tsc_shift: shift to be used when converting tsc-related |
| 90 | allow for shift rights. One has to shift right any tsc-related | 92 | quantity to nanoseconds. This shift will ensure that |
| 91 | quantity by this value to get a value in nanoseconds, besides | 93 | multiplication with tsc_to_system_mul does not overflow. |
| 92 | multiplying by tsc_to_system_mul. | 94 | A positive value denotes a left shift, a negative value |
| 95 | a right shift. | ||
| 93 | 96 | ||
| 94 | With this information, guests can derive per-CPU time by | 97 | The conversion from tsc to nanoseconds involves an additional |
| 95 | doing: | 98 | right shift by 32 bits. With this information, guests can |
| 99 | derive per-CPU time by doing: | ||
| 96 | 100 | ||
| 97 | time = (current_tsc - tsc_timestamp) | 101 | time = (current_tsc - tsc_timestamp) |
| 98 | time = (time * tsc_to_system_mul) >> tsc_shift | 102 | if (tsc_shift >= 0) |
| 103 | time <<= tsc_shift; | ||
| 104 | else | ||
| 105 | time >>= -tsc_shift; | ||
| 106 | time = (time * tsc_to_system_mul) >> 32 | ||
| 99 | time = time + system_time | 107 | time = time + system_time |
| 100 | 108 | ||
| 101 | flags: bits in this field indicate extended capabilities | 109 | flags: bits in this field indicate extended capabilities |
