Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4008706imm; Mon, 15 Oct 2018 07:43:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV61WUcg5C0pwxmp0alq9L1MV8x83Q4awTHhzcUP2xlOQZEUF9ioreQLp0RwMDmnqw2+4zQUo X-Received: by 2002:a62:b87:: with SMTP id 7-v6mr17820240pfl.67.1539614623146; Mon, 15 Oct 2018 07:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539614623; cv=none; d=google.com; s=arc-20160816; b=l8szSL9HogT2S7VbW3hQoU5uluEpAPHG8IF7yZUS9sdGnL9icCzDUYA1kdHe3Fj3nI Gh2SMyAfGxcVABsaBUch2SBnke1ghOjHv9lOoUpRdZeteWR5658sYpk/2tLUD1JnqMCl vx7Xp2txuj39oqpNR+fqC8xkTrhmS2oAVAF/1bj2SYOQrtjHSx2V/5A1qoQpE4Sy44eO 08R7e4QrBANcRxNhP3TxnHyQ5ln9+zaToqkz84jHl1R/WerFzRh9ez+NNH1Zr1gCzWJP yJOgVtgi94xhDzUjzCxlikFxphLMjaichTvRpImfQRW6YQQj2myQqoxWx3AZDUo7imB1 Ey/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=9QEw1YzmDcJcaO/r6rtKbz/wM2Wfj5qTqaU0sMGYU7g=; b=QMpopyfGWKnmyXATjgtCh+mboRAAIC43UOUxhT0pJ1Hb1ftPwim5GI5yT+xe4ziYrR 5jZERh1n5vDLNT+mDPd5mmgDnQVyGiNVrJWCI05rRt/uk5vbNXD/pkazxeqG2ZTtWWru 0V+oGnmKylKALmx4GEfj6hZ/OzoiBA0KKcAp3t0TmDSPeFiFhn95xqVlcU6oQ1sJTdAv hI5x45f+PDKASwseMUH1u9bQiqOBwa8TYlJ0SE9IGMt7DvELc7xzTaYB89a40p3SiMy/ D6lLIp+fahTOKJJLRtVsvHmtO3bsrt8EAgl8gguEjk3e+mLJ4W0s0PcDcmUaN5qujeWF t6DA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21-v6si10644385plr.327.2018.10.15.07.43.28; Mon, 15 Oct 2018 07:43:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbeJOW2V (ORCPT + 99 others); Mon, 15 Oct 2018 18:28:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50363 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726614AbeJOW2U (ORCPT ); Mon, 15 Oct 2018 18:28:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AE16307D943; Mon, 15 Oct 2018 14:42:47 +0000 (UTC) Received: from amt.cnet (ovpn-112-3.gru2.redhat.com [10.97.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06E4C7A26E; Mon, 15 Oct 2018 14:42:44 +0000 (UTC) Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 619A01050ED; Mon, 15 Oct 2018 10:40:12 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id w9FDdvDr003285; Mon, 15 Oct 2018 10:39:57 -0300 Date: Mon, 15 Oct 2018 10:39:56 -0300 From: Marcelo Tosatti To: Andy Lutomirski Cc: 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 Subject: Re: [patch 00/11] x86/vdso: Cleanups, simmplifications and CLOCK_TAI support Message-ID: <20181015133952.GA2932@amt.cnet> References: <499807AB-E779-40C3-AA3F-E8C77A7770EC@amacapital.net> <20181006202731.GC7129@amt.cnet> <20181008152650.GB27822@amt.cnet> <20181008193632.GA31729@amt.cnet> <20181011222744.GA17955@amt.cnet> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 15 Oct 2018 14:42:47 +0000 (UTC) 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 04:00:29PM -0700, Andy Lutomirski wrote: > 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. Can you outline how that would work ?