From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Stultz Subject: Re: [patch 14/18] time: export time information for KVM pvclock Date: Fri, 09 Nov 2012 17:02:52 -0800 Message-ID: <509DA7BC.2050208@us.ibm.com> References: <20121024131340.742340256@redhat.com> <20121024131621.941019009@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, jeremy@goop.org, glommer@parallels.com, zamsden@gmail.com, gleb@redhat.com, avi@redhat.com, pbonzini@redhat.com To: Marcelo Tosatti Return-path: Received: from e38.co.us.ibm.com ([32.97.110.159]:60746 "EHLO e38.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005Ab2KJBDZ (ORCPT ); Fri, 9 Nov 2012 20:03:25 -0500 Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2012 18:03:24 -0700 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 5D0803E4003E for ; Fri, 9 Nov 2012 18:02:57 -0700 (MST) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qAA12vKc230424 for ; Fri, 9 Nov 2012 18:02:57 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qAA12ve4020967 for ; Fri, 9 Nov 2012 18:02:57 -0700 In-Reply-To: <20121024131621.941019009@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 10/24/2012 06:13 AM, Marcelo Tosatti wrote: > As suggested by John, export time data similarly to how its > done by vsyscall support. This allows KVM to retrieve necessary > information to implement vsyscall support in KVM guests. > > Signed-off-by: Marcelo Tosatti Thanks Marcelo, I like this much better then what you were proposing privately earlier! Fairly minor nit below. > Index: vsyscall/kernel/time/timekeeping.c > =================================================================== > --- vsyscall.orig/kernel/time/timekeeping.c > +++ vsyscall/kernel/time/timekeeping.c > @@ -21,6 +21,7 @@ > #include > #include > #include > +#include > > > static struct timekeeper timekeeper; > @@ -180,6 +181,79 @@ static inline s64 timekeeping_get_ns_raw > return nsec + arch_gettimeoffset(); > } > > +static RAW_NOTIFIER_HEAD(pvclock_gtod_chain); > + > +/** > + * pvclock_gtod_register_notifier - register a pvclock timedata update listener > + * > + * Must hold write on timekeeper.lock > + */ > +int pvclock_gtod_register_notifier(struct notifier_block *nb) > +{ > + struct timekeeper *tk = &timekeeper; > + unsigned long flags; > + int ret; > + > + write_seqlock_irqsave(&tk->lock, flags); > + ret = raw_notifier_chain_register(&pvclock_gtod_chain, nb); > + write_sequnlock_irqrestore(&tk->lock, flags); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(pvclock_gtod_register_notifier); > + > +/** > + * pvclock_gtod_unregister_notifier - unregister a pvclock > + * timedata update listener > + * > + * Must hold write on timekeeper.lock > + */ > +int pvclock_gtod_unregister_notifier(struct notifier_block *nb) > +{ > + struct timekeeper *tk = &timekeeper; > + unsigned long flags; > + int ret; > + > + write_seqlock_irqsave(&tk->lock, flags); > + ret = raw_notifier_chain_unregister(&pvclock_gtod_chain, nb); > + write_sequnlock_irqrestore(&tk->lock, flags); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier); > + > +struct pvclock_gtod_data pvclock_gtod_data; > +EXPORT_SYMBOL_GPL(pvclock_gtod_data); > + > +static void update_pvclock_gtod(struct timekeeper *tk) > +{ > + struct pvclock_gtod_data *vdata = &pvclock_gtod_data; > + > + write_seqcount_begin(&vdata->seq); > + > + /* copy pvclock gtod data */ > + vdata->clock.vclock_mode = tk->clock->archdata.vclock_mode; > + vdata->clock.cycle_last = tk->clock->cycle_last; > + vdata->clock.mask = tk->clock->mask; > + vdata->clock.mult = tk->mult; > + vdata->clock.shift = tk->shift; > + > + vdata->monotonic_time_sec = tk->xtime_sec > + + tk->wall_to_monotonic.tv_sec; > + vdata->monotonic_time_snsec = tk->xtime_nsec > + + (tk->wall_to_monotonic.tv_nsec > + << tk->shift); > + while (vdata->monotonic_time_snsec >= > + (((u64)NSEC_PER_SEC) << tk->shift)) { > + vdata->monotonic_time_snsec -= > + ((u64)NSEC_PER_SEC) << tk->shift; > + vdata->monotonic_time_sec++; > + } > + > + write_seqcount_end(&vdata->seq); > + raw_notifier_call_chain(&pvclock_gtod_chain, 0, NULL); > +} > + My only request is could the update_pvclock_gtod() be implemented similarly to the update_vsyscall, where the update function lives in the pvclock code (maybe using a weak symbol or something) so we don't have to have all these pvclock details in the timekeeping core? thanks -john