From patchwork Tue Oct 16 17:56:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 1602021 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 10FC5E0196 for ; Tue, 16 Oct 2012 17:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755599Ab2JPR7v (ORCPT ); Tue, 16 Oct 2012 13:59:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17267 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755436Ab2JPR7t (ORCPT ); Tue, 16 Oct 2012 13:59:49 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9GHxlgL017668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 16 Oct 2012 13:59:47 -0400 Received: from amt.cnet (vpn-200-116.tlv.redhat.com [10.35.200.116]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9GHxjj5031222; Tue, 16 Oct 2012 13:59:46 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 6A54E68A2EF; Tue, 16 Oct 2012 14:59:29 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.5/8.14.5/Submit) id q9GHxQQf008650; Tue, 16 Oct 2012 14:59:26 -0300 Message-Id: <20121016180137.923799800@redhat.com> User-Agent: quilt/0.47-1 Date: Tue, 16 Oct 2012 14:56:33 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: johnstul@us.ibm.com, jeremy@goop.org, Marcelo Tosatti Subject: [patch 14/15] time: export time information for KVM pvclock References: <20121016175619.194848607@redhat.com> Content-Disposition: inline; filename=13-time-add-pvclock-gtod-data X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org As suggested by John, export time data similarly to how its by vsyscall support. This allows KVM to retrieve necessary information to implement vsyscall support in KVM guests. Signed-off-by: Marcelo Tosatti --- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: vsyscall/include/linux/pvclock_gtod.h =================================================================== --- /dev/null +++ vsyscall/include/linux/pvclock_gtod.h @@ -0,0 +1,23 @@ +#ifndef _PVCLOCK_GTOD_H +#define _PVCLOCK_GTOD_H + +#include + +struct pvclock_gtod_data { + seqcount_t seq; + + struct { /* extract of a clocksource struct */ + int vclock_mode; + cycle_t cycle_last; + cycle_t mask; + u32 mult; + u32 shift; + } clock; + + /* open coded 'struct timespec' */ + u64 monotonic_time_snsec; + time_t monotonic_time_sec; +}; +extern struct pvclock_gtod_data pvclock_gtod_data; + +#endif /* _PVCLOCK_GTOD_H */ 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,37 @@ static inline s64 timekeeping_get_ns_raw return nsec + arch_gettimeoffset(); } +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 vsyscall 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); +} + /* must hold write on timekeeper.lock */ static void timekeeping_update(struct timekeeper *tk, bool clearntp) { @@ -188,6 +220,7 @@ static void timekeeping_update(struct ti ntp_clear(); } update_vsyscall(tk); + update_pvclock_gtod(tk); } /**