Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4868392ybe; Mon, 9 Sep 2019 16:20:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ3N6DyPNQXgzyBZp3P818A8e8K1x8pWPqDZfzR3pAPuuUFufGWpngQ+LEHC68RZUmCM+i X-Received: by 2002:a05:6402:614:: with SMTP id n20mr27249985edv.237.1568071200515; Mon, 09 Sep 2019 16:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568071200; cv=none; d=google.com; s=arc-20160816; b=EaPMU3bKXxu/pE0U/gBQI9yG/dECMxQShuNyS2xLa6E7TUAqh2HX8Gdej5GqxQEHh1 mvK39ywcrlim+aXBsMN5RzN65wi7cuYnB5gKO0SAmhAaAz6OyB3+5WHijVByo2SoVWJC eeI19Oj4FuUJWA2CxcCh1JFDGAd7h3SIayeIBda4N+Y9KAVUd1fH3+rkS7H3axpJ/i/F MSAd8FrSC5za3dMfsXLp/ukzBJmBD15GE/o7QrK86U1yhrU0NI1ra+/rqJfUr2W4PpWu zx1nzIxUKMCNrmShNulWIinUaW6DZZrJ0ArmDEi2eTw1qwRNFnU8osVUzMzsQTItTV2P x9kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:organization:user-agent :references:in-reply-to:subject:cc:to:from:message-id:date; bh=Jsq/pSJSeixU6wSO1kK0+w5gYaT6ChfKQ8Pg79hUL5E=; b=eujZJeSzNmxfDbJ7G9WVlJ0Ixno6UNbBubnVro9rXOQd1kYHJXY+AKXWGjokb/7Cdy CeN0gWg9Ur4GZFd3Jt/tzSBgMSuLb5wq+Omq3eHYAKXGyFqiSakuSjctCTLL28Y8Ahw5 S/KE7tF2Qsh0YOwtmkfGEKjTLONBzPZrysXX9CmxcoUrTXgaKETd3Wpt1ZAzAvAjPqvl QOLzDv53d0PJh/zX6tfI7VGfqUQPIJUBUByT8e7lIxv6DQfkUFlpUN1sX4sdb/r0J4IZ rpYxaRkhQkGGSs6o2DB/Yq5vHKe5Vi1D0li+R6077aYUvlb35JXGib8rY0L9OXCigiUv eH0Q== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e24si9528930edq.167.2019.09.09.16.19.35; Mon, 09 Sep 2019 16:20:00 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390951AbfIILZF (ORCPT + 99 others); Mon, 9 Sep 2019 07:25:05 -0400 Received: from foss.arm.com ([217.140.110.172]:48220 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730361AbfIILZF (ORCPT ); Mon, 9 Sep 2019 07:25:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 676AA28; Mon, 9 Sep 2019 04:25:04 -0700 (PDT) Received: from big-swifty.misterjones.org (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 841D23F71F; Mon, 9 Sep 2019 04:25:01 -0700 (PDT) Date: Mon, 09 Sep 2019 12:24:59 +0100 Message-ID: <86blvtsodw.wl-maz@kernel.org> From: Marc Zyngier To: "Jianyong Wu (Arm Technology China)" Cc: "netdev@vger.kernel.org" , "pbonzini@redhat.com" , "sean.j.christopherson@intel.com" , "richardcochran@gmail.com" , Mark Rutland , Will Deacon , Suzuki Poulose , "linux-kernel@vger.kernel.org" , Steve Capper , "Kaly Xin (Arm Technology China)" , "Justin He (Arm Technology China)" Subject: Re: [RFC PATCH 3/3] Enable ptp_kvm for arm64 In-Reply-To: References: <20190829063952.18470-1-jianyong.wu@arm.com> <20190829063952.18470-4-jianyong.wu@arm.com> <4d04867c-2188-9574-fbd1-2356c6b99b7d@kernel.org> <86h85osbzz.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: Approximate MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 09 Sep 2019 11:17:24 +0100, "Jianyong Wu (Arm Technology China)" wrote: Hi Jianyoung, [...] > > > > I'm definitely not keen on exposing the internals of the arch_timer > > > > driver to random subsystems. Furthermore, you seem to expect that > > > > the guest kernel will only use the arch timer as a clocksource, and > > > > nothing really guarantees that (in which case > > get_device_system_crosststamp will fail). > > > > > > > The code here is really ugly, I need a better solution to offer a > > > clock source For the guest. > > > > > > > It looks to me that we'd be better off exposing a core timekeeping > > > > API that populates a struct system_counterval_t based on the > > > > *current* timekeeper monotonic clocksource. This would simplify the > > > > split between generic and arch-specific code. > > > > > > > I think it really necessary. > > > > > > > Whether or not tglx will be happy with the idea is another problem, > > > > but I'm certainly not taking any change to the arch timer code based on > > this. > > > > > > > I can have a try, but the detail is not clear for me now. > > > > Something along those lines: > > > > From 5f1c061e55c691d64012bc7c1490a1a8c4432c67 Mon Sep 17 00:00:00 2001 > > From: Marc Zyngier > > Date: Sat, 7 Sep 2019 10:11:49 +0100 > > Subject: [PATCH] timekeeping: Expose API allowing retrival of current > > clocksource and counter value > > > > Signed-off-by: Marc Zyngier > > --- > > include/linux/timekeeping.h | 5 +++++ > > kernel/time/timekeeping.c | 12 ++++++++++++ > > 2 files changed, 17 insertions(+) > > > > diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index > > b27e2ffa96c1..6df26a913711 100644 > > --- a/include/linux/timekeeping.h > > +++ b/include/linux/timekeeping.h > > @@ -275,6 +275,11 @@ extern int get_device_system_crosststamp( > > struct system_time_snapshot *history, > > struct system_device_crosststamp *xtstamp); > > > > +/* > > + * Obtain current monotonic clock and its counter value */ extern void > > +get_current_counterval(struct system_counterval_t *sc); > > + > > /* > > * Simultaneously snapshot realtime and monotonic raw clocks > > */ > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index > > d911c8470149..de689bbd3808 100644 > > --- a/kernel/time/timekeeping.c > > +++ b/kernel/time/timekeeping.c > > @@ -1098,6 +1098,18 @@ static bool cycle_between(u64 before, u64 test, > > u64 after) > > return false; > > } > > > > +/** > > + * get_current_counterval - Snapshot the current clocksource and counter > > value > > + * @sc: Pointer to a struct containing the current clocksource and its > > value > > + */ > > +void get_current_counterval(struct system_counterval_t *sc) { > > + struct timekeeper *tk = &tk_core.timekeeper; > > + > > + sc->cs = READ_ONCE(tk->tkr_mono.clock); > > + sc->cycles = sc->cs->read(sc->cs); > > +} > > + > > /** > > * get_device_system_crosststamp - Synchronously capture system/device > > timestamp > > * @get_time_fn: Callback to get simultaneous device time and > > > > which should do the right thing. > > > It is a good news for me. These code is indeed what I need! So > what's your plan about this patch? Is there any problem with you if > I include these code into my patch ? Just add this patch as part of your series (I'll try to write an actual commit log for that). [...] > > > > Other questions: how does this works with VM migration? Specially > > > > when moving from a hypervisor that supports the feature to one that > > doesn't? > > > > > > > I think it won't solve the problem generated by VM migration and only > > > for VMs in a single machine. Ptp_kvm only works for VMs in the same > > > machine. But using ptp (not ptp_kvm) clock, all the machines in a low > > > latency network environment can keep time sync in high precision, Then > > > VMs move from one machine to another will obtain a high precision time > > > sync. > > > > That's a problem. Migration must be possible from one host to another, even > > if that means temporarily loosing some (or a lot of) precision. The service > > must be discoverable from userspace on the host so that the MVV can decie > > whether a migration is possible or not. > > > Don't worry, things will be not that bad. ptp_kvm will not trouble > the VM migration. This ptp_kvm is one clocksource of the clock pool > for chrony. Chrony will choose the highest precision clock from the > pool. If host does not support ptp_kvm, the ptp_kvm will not be > chosen as the clocksouce of chrony. We have roughly the same logic > of implementation of ptp_kvm with x86, and ptp_kvm works well in > x86. so I think that will be the case for arm64. > > Maybe I miss your point, I have no idea of MVV and can't get related > info from google. Also I'm not clear of your last words of how to > decide VM migration is possible? Sorry. s/MVV/VMM/. Basically userspace, such as QEMU. Here's an example: The guest runs on a PTP aware host, starts using the PTP service and uses HVC calls to get its clock. We now migrate the guest to a non PTP-aware host. The hypercalls are now going to fail unexpectedly. Is that something that is acceptable? I don't think it is. Once you've allowed a guest to use a service, this service should be preserved. I'd be more confident if we gave to userspace the indication that the hypervisor supports PTP. Userspace can then decide whether to perform migration or not. Thanks, M. -- Jazz is not dead, it just smells funny.