From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939753AbdAINFv (ORCPT ); Mon, 9 Jan 2017 08:05:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43740 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939734AbdAINFr (ORCPT ); Mon, 9 Jan 2017 08:05:47 -0500 From: Vitaly Kuznetsov To: John Stultz Cc: "devel\@linuxdriverproject.org" , lkml , "K. Y. Srinivasan" , Haiyang Zhang , Thomas Gleixner , Alex Ng , Stephen Hemminger Subject: Re: [PATCH v2 4/4] hv_util: improve time adjustment accuracy by disabling interrupts References: <20170104172439.19683-1-vkuznets@redhat.com> <20170104172439.19683-5-vkuznets@redhat.com> Date: Mon, 09 Jan 2017 14:05:43 +0100 In-Reply-To: (John Stultz's message of "Fri, 6 Jan 2017 17:02:54 -0800") Message-ID: <8737gs8jtk.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Jan 2017 13:05:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org John Stultz writes: > On Wed, Jan 4, 2017 at 9:24 AM, Vitaly Kuznetsov wrote: >> If we happen to receive interrupts during hv_set_host_time() execution >> our adjustments may get inaccurate. Make the whole function atomic. >> Unfortunately, we can's call do_settimeofday64() with interrupts >> disabled as some cross-CPU work is being done but this call happens >> very rarely. >> >> Signed-off-by: Vitaly Kuznetsov >> --- >> drivers/hv/hv_util.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c >> index 7e97231..4e50a42 100644 >> --- a/drivers/hv/hv_util.c >> +++ b/drivers/hv/hv_util.c >> @@ -187,6 +187,9 @@ static void hv_set_host_time(struct work_struct *work) >> struct timespec64 host_ts, our_ts; >> struct timex txc = {0}; >> int ret; >> + unsigned long flags; >> + >> + local_irq_save(flags); >> >> wrk = container_of(work, struct adj_time_work, work); >> >> @@ -218,6 +221,7 @@ static void hv_set_host_time(struct work_struct *work) >> * ordered to sync our time by the host. >> */ >> if (abs(delta) > MAXPHASE || wrk->flags & ICTIMESYNCFLAG_SYNC) { >> + local_irq_restore(flags); >> do_settimeofday64(&host_ts); >> return; >> } >> @@ -232,6 +236,8 @@ static void hv_set_host_time(struct work_struct *work) >> ret = do_adjtimex(&txc); >> if (ret) >> pr_debug("Failed to adjust system time: %d\n", ret); >> + >> + local_irq_restore(flags); > > This seems like a long time to disable irqs for what your trying to > do. I'd guess you really only want to disable irqs while you aquire > the host and guest timestamps (so they are as close together as > possible). Since the delta is then calculated, I'm not sure what > disabling irqs for calling adjtimex gets you. > True, interrupts disabling would only be beneficial for the do_settimeofday64() case but we can't actually do it there. I'll shorten the interrupts disabling to the delta calculation only. -- Vitaly