Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp88161imm; Thu, 11 Oct 2018 16:01:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV60XuzHsrKDg/Wk/NCSsqbIT6M4A2clYvWurinQOO5wqb7me6sT4eKJIGmIAirUp07ero2x7 X-Received: by 2002:a63:fd09:: with SMTP id d9-v6mr3244536pgh.164.1539298901967; Thu, 11 Oct 2018 16:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539298901; cv=none; d=google.com; s=arc-20160816; b=j5rXmPUOJc4JX0MflZ16856saMTCuyi8lOaAGIoyshTrKC/LW29SVSSvDP7aBB5fbu +Pn3b4VctAJ6NsD+E4sE4/4pmFIkUdDbWl+tnX8M5YO+Tg7NV38/MlXSWibYvxeyMdjp iq53XMTJrq+in9ChAcZ7kYBGoGeNBPbjHtoeQVBp4iV12hU1+xhthJdIY8bAoavxY7Sw jadddNQkpQhA21pVX/uZGlBcppyZTIhTMz8ywiT9y8UEeBjG8SXuAdYCUJ/kbOU37a2f 0IR0Tn6BB+6L9UGDg9wPi1x+em6Lbf1MZg3YMLStuNU9tzKS2YtyTGzjRxTbvEU2Ky1k N8fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jlrj3ijpVqlA0nmYJLkymBmP7ahRDIMRXpLZtrsHAQc=; b=g1MbLK4ZrLqBggK7t5OjZgg89dErlmw6/fwxu0Ii+w1pzDyYhgmEMvfoJK78BrIDQ5 3PxoSmRYrGCMJe6Do5NBjpT93XarrEJFItzYlfn/A6FCAbH1WcNe7vVqGD4vxtGk8zhB CiWiupID7511bQ4+7x+mPxJDnfdoiuaJn796nqF6shEJruwUVDovfc4hlPANMLJaZ+8i BwYGhvk2h2S5hyz8vF4dlq+OEwcdXWHldVKIK6eei2nhO5s9LmnHWozyFWaQXvyoCamB zCDeiPeI1rEStLldM9Og7uP4sOH4GlUP2ffdnuva4J3ygvdTnff7q7FnTqq0pc6noIaD A/fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vyOVeUh6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q137-v6si36205726pfq.178.2018.10.11.16.01.27; Thu, 11 Oct 2018 16:01:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vyOVeUh6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbeJLGaL (ORCPT + 99 others); Fri, 12 Oct 2018 02:30:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:60218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbeJLGaL (ORCPT ); Fri, 12 Oct 2018 02:30:11 -0400 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 686D9214C4 for ; Thu, 11 Oct 2018 23:00:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539298844; bh=jeNCpfa8w1IQM3+VGFadd6JfiNb1m/3VN3xklLz3EPc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vyOVeUh6/8ls2ZXmmIOnF9CAyJYfEqSZqgughSIj1xg5Dsg0IdTiO5gUebhkbUHfs Kdmwmw66zxNRJU//ZV1MXRzOAMEsh3ocY8+sHNpywNLCeuAp/DCUmZj8vGFGCVapfq Mtq3rTsBiUwfDo8VoKPSo0EaXTflLkmAB7l5i4es= Received: by mail-wm1-f54.google.com with SMTP id y140-v6so16766627wmd.0 for ; Thu, 11 Oct 2018 16:00:44 -0700 (PDT) X-Gm-Message-State: ABuFfogFi3uYi3u0KZxjIbBiCgjoVgBMuf7SbKwaJNVIXlxcG/IeXVti LYn3vP6g+y1bbxoM8jlPp1cvHJ20OY4MdX4gobk1TQ== X-Received: by 2002:a1c:4054:: with SMTP id n81-v6mr3330398wma.82.1539298842721; Thu, 11 Oct 2018 16:00:42 -0700 (PDT) MIME-Version: 1.0 References: <20181004193150.GQ19272@hirez.programming.kicks-ass.net> <499807AB-E779-40C3-AA3F-E8C77A7770EC@amacapital.net> <20181006202731.GC7129@amt.cnet> <20181008152650.GB27822@amt.cnet> <20181008193632.GA31729@amt.cnet> <20181011222744.GA17955@amt.cnet> In-Reply-To: <20181011222744.GA17955@amt.cnet> From: Andy Lutomirski Date: Thu, 11 Oct 2018 16:00:29 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [patch 00/11] x86/vdso: Cleanups, simmplifications and CLOCK_TAI support To: Marcelo Tosatti Cc: Andrew Lutomirski , Peter Zijlstra , Vitaly Kuznetsov , Thomas Gleixner , Paolo Bonzini , Radim Krcmar , Wanpeng Li , LKML , X86 ML , Matt Rickard , Stephen Boyd , John Stultz , Florian Weimer , KY Srinivasan , devel@linuxdriverproject.org, Linux Virtualization , Arnd Bergmann , Juergen Gross Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 11, 2018 at 3:28 PM Marcelo Tosatti wrote: > > On Tue, Oct 09, 2018 at 01:09:42PM -0700, Andy Lutomirski wrote: > > On Tue, Oct 9, 2018 at 8:28 AM Marcelo Tosatti wrote: > > > > > > On Mon, Oct 08, 2018 at 10:38:22AM -0700, Andy Lutomirski wrote: > > > > On Mon, Oct 8, 2018 at 8:27 AM Marcelo Tosatti wrote: > > > > > > I read the comment three more times and even dug through the git > > > > history. It seems like what you're saying is that, under certain > > > > conditions (which arguably would be bugs in the core Linux timing > > > > code), > > > > > > I don't see that as a bug. Its just a side effect of reading two > > > different clocks (one is CLOCK_MONOTONIC and the other is TSC), > > > and using those two clocks to as a "base + offset". > > > > > > As the comment explains, if you do that, can't guarantee monotonicity. > > > > > > > actually calling ktime_get_boot_ns() could be non-monotonic > > > > with respect to the kvmclock timing. But get_kvmclock_ns() isn't used > > > > for VM timing as such -- it's used for the IOCTL interfaces for > > > > updating the time offset. So can you explain how my patch is > > > > incorrect? > > > > > > ktime_get_boot_ns() has frequency correction applied, while > > > reading masterclock + TSC offset does not. > > > > > > So the clock reads differ. > > > > > > > Ah, okay, I finally think I see what's going on. In the kvmclock data > > exposed to the guest, tsc_shift and tsc_to_system_mul come from > > tgt_tsc_khz, whereas master_kernel_ns and master_cycle_now come from > > CLOCK_BOOTTIME. So the kvmclock and kernel clock drift apart at a > > rate given by the frequency shift and then suddenly agree again every > > time the pvclock data is updated. > > Yes. > > > Is there a reason to do it this way? > > Since pvclock updates which update system_timestamp are expensive (must stop all vcpus), > they should be avoided. > Fair enough. > So only HW TSC counts makes sense. >, and used as offset against vcpu's tsc_timestamp. > Why don't you just expose CLOCK_MONTONIC_RAW or CLOCK_MONOTONIC_RAW plus suspend time, though? Then you would actually be tracking a real kernel timekeeping mode, and you wouldn't need all this complicated offsetting work to avoid accidentally going backwards.