From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966389AbcIHKen (ORCPT ); Thu, 8 Sep 2016 06:34:43 -0400 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:45870 "EHLO p3plsmtps2ded03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937116AbcIHKel (ORCPT ); Thu, 8 Sep 2016 06:34:41 -0400 x-originating-ip: 72.167.245.219 From: kys@exchange.microsoft.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com, leann.ogasawara@canonical.com, alexng@microsoft.com Cc: Alex Ng , "K. Y. Srinivasan" Subject: [PATCH 2/3] Drivers: hv: utils: Use TimeSync samples to adjust the clock after boot. Date: Thu, 8 Sep 2016 05:24:13 -0700 Message-Id: <1473337454-6097-2-git-send-email-kys@exchange.microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1473337454-6097-1-git-send-email-kys@exchange.microsoft.com> References: <1473337400-6050-1-git-send-email-kys@exchange.microsoft.com> <1473337454-6097-1-git-send-email-kys@exchange.microsoft.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfAxMDwCfp0UNXbAaYjI8iSl37/XHWzC9V/yGdCxlK97BjpPuEzCIddZZcKFMbyCfhD4lODlQBl5Trh1Ld66xSjPvfQHJBZVqfTU6iiqKeGnI/X0tApvU TM748z5O3Xvjk4ht8szNCONixG5hF9cOxoqtHvqWYdmuvff2vyq/y5M7Rt5PnMWWYgtxSYdspvF8VFfe02vaFXjR0R+Bv4Xjd9a3Mje/EjX8LjCywlez+J9q fPWkTJm6W17wmgd6XIwmBFd8B7oZgy48MyHkOhbOlGtwUCeqQ9RsQ07KnFBEMbLnyqmLxKdxcpQ9gKss4v+mU/5hCO59ThH7hZ1XV9Ultj1Qzh9XSv2uNR2v vwKRMaMK40CM1ORosCE4SSQwhHUwtvzBuYkwdHNNE4RPJsZMC9/YdWMaGatLFWSwQf81Kjsp0U+3vZCcRhxcqKSoEsLizfs0Xn8VfeOPJWHhlCjhgBQscq3K 1qZ5fXyWgZQx8NasLWAzTzQul1l8cUq0RtLjY9ELx21nEwyNACURZEh1ptYCFOoqSaMYJSMYAc7R5m2D Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Ng Only the first 50 samples after boot were being used to discipline the clock. After the first 50 samples, any samples from the host were ignored and the guest clock would eventually drift from the host clock. This patch allows TimeSync-enabled guests to continuously synchronize the clock with the host clock, even after the first 50 samples. Signed-off-by: Alex Ng Signed-off-by: K. Y. Srinivasan --- drivers/hv/hv_util.c | 20 +++++++------------- 1 files changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c index b27a8ee..4002b71 100644 --- a/drivers/hv/hv_util.c +++ b/drivers/hv/hv_util.c @@ -198,29 +198,23 @@ static void hv_set_host_time(struct work_struct *work) * ICTIMESYNCFLAG_SYNC flag bit indicates reboot, restore events of the VM. * After reboot the flag ICTIMESYNCFLAG_SYNC is included in the first time * message after the timesync channel is opened. Since the hv_utils module is - * loaded after hv_vmbus, the first message is usually missed. The other - * thing is, systime is automatically set to emulated hardware clock which may - * not be UTC time or in the same time zone. So, to override these effects, we - * use the first 50 time samples for initial system time setting. + * loaded after hv_vmbus, the first message is usually missed. This bit is + * considered a hard request to discipline the clock. + * + * ICTIMESYNCFLAG_SAMPLE bit indicates a time sample from host. This is + * typically used as a hint to the guest. The guest is under no obligation + * to discipline the clock. */ static inline void adj_guesttime(u64 hosttime, u8 flags) { struct adj_time_work *wrk; - static s32 scnt = 50; wrk = kmalloc(sizeof(struct adj_time_work), GFP_ATOMIC); if (wrk == NULL) return; wrk->host_time = hosttime; - if ((flags & ICTIMESYNCFLAG_SYNC) != 0) { - INIT_WORK(&wrk->work, hv_set_host_time); - schedule_work(&wrk->work); - return; - } - - if ((flags & ICTIMESYNCFLAG_SAMPLE) != 0 && scnt > 0) { - scnt--; + if ((flags & (ICTIMESYNCFLAG_SYNC | ICTIMESYNCFLAG_SAMPLE)) != 0) { INIT_WORK(&wrk->work, hv_set_host_time); schedule_work(&wrk->work); } else -- 1.7.4.1