aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/hv
diff options
context:
space:
mode:
authorHaiyang Zhang <haiyangz@microsoft.com>2010-05-11 11:11:24 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-11 18:31:52 -0400
commite9ec36030cca2549cb656d94347dafecfcf218f6 (patch)
tree93fc1ac781dfa7ae63a8e7d2f4b0f46b81cc5f05 /drivers/staging/hv
parentce7f6389790f24e07e7e32518c798451e799a830 (diff)
staging: hv: Optimize adj_guesttime function and add more detailed comments
Credits go to Joe Perches <joe@perches.com> for suggesting the changes. Cc: Joe Perches <joe@perches.com> Signed-off-by: Hank Janssen <hjanssen@microsoft.com> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/hv')
-rw-r--r--drivers/staging/hv/hv_utils.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c
index 8f1d3ba7e09..db45d97a3a7 100644
--- a/drivers/staging/hv/hv_utils.c
+++ b/drivers/staging/hv/hv_utils.c
@@ -106,31 +106,44 @@ static void shutdown_onchannelcallback(void *context)
106 orderly_poweroff(false); 106 orderly_poweroff(false);
107} 107}
108 108
109
110/* 109/*
111 * Synchronize time with host after reboot, restore, etc. 110 * Set guest time to host UTC time.
112 */ 111 */
113static void adj_guesttime(u64 hosttime, u8 flags) 112static inline void do_adj_guesttime(u64 hosttime)
114{ 113{
115 s64 host_tns; 114 s64 host_tns;
116 struct timespec host_ts; 115 struct timespec host_ts;
117 static s32 scnt = 50;
118 116
119 host_tns = (hosttime - WLTIMEDELTA) * 100; 117 host_tns = (hosttime - WLTIMEDELTA) * 100;
120 host_ts = ns_to_timespec(host_tns); 118 host_ts = ns_to_timespec(host_tns);
121 119
120 do_settimeofday(&host_ts);
121}
122
123/*
124 * Synchronize time with host after reboot, restore, etc.
125 *
126 * ICTIMESYNCFLAG_SYNC flag bit indicates reboot, restore events of the VM.
127 * After reboot the flag ICTIMESYNCFLAG_SYNC is included in the first time
128 * message after the timesync channel is opened. Since the hv_utils module is
129 * loaded after hv_vmbus, the first message is usually missed. The other
130 * thing is, systime is automatically set to emulated hardware clock which may
131 * not be UTC time or in the same time zone. So, to override these effects, we
132 * use the first 50 time samples for initial system time setting.
133 */
134static inline void adj_guesttime(u64 hosttime, u8 flags)
135{
136 static s32 scnt = 50;
137
122 if ((flags & ICTIMESYNCFLAG_SYNC) != 0) { 138 if ((flags & ICTIMESYNCFLAG_SYNC) != 0) {
123 do_settimeofday(&host_ts); 139 do_adj_guesttime(hosttime);
124 return; 140 return;
125 } 141 }
126 142
127 if ((flags & ICTIMESYNCFLAG_SAMPLE) != 0 && 143 if ((flags & ICTIMESYNCFLAG_SAMPLE) != 0 && scnt > 0) {
128 scnt > 0) {
129 scnt--; 144 scnt--;
130 do_settimeofday(&host_ts); 145 do_adj_guesttime(hosttime);
131 } 146 }
132
133 return;
134} 147}
135 148
136/* 149/*