From patchwork Sun Jan 31 19:19:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Cave-Ayland X-Patchwork-Id: 8174841 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 59E5B9FBE9 for ; Sun, 31 Jan 2016 19:20:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCE582012B for ; Sun, 31 Jan 2016 19:20:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1252F20103 for ; Sun, 31 Jan 2016 19:20:22 +0000 (UTC) Received: from localhost ([::1]:42903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPxXp-0003Fl-Da for patchwork-qemu-devel@patchwork.kernel.org; Sun, 31 Jan 2016 14:20:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPxXa-000351-Bm for qemu-devel@nongnu.org; Sun, 31 Jan 2016 14:20:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPxXW-00058p-D3 for qemu-devel@nongnu.org; Sun, 31 Jan 2016 14:20:06 -0500 Received: from s16892447.onlinehome-server.info ([82.165.15.123]:52579) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPxXW-00058g-6o; Sun, 31 Jan 2016 14:20:02 -0500 Received: from host86-175-36-142.range86-175.btcentralplus.com ([86.175.36.142] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1aPxXR-0005Ro-2c; Sun, 31 Jan 2016 19:19:58 +0000 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, agraf@suse.de, david@gibson.dropbear.id.au, aik@ozlabs.ru Date: Sun, 31 Jan 2016 19:19:35 +0000 Message-Id: <1454267976-27242-3-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1454267976-27242-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1454267976-27242-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 86.175.36.142 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCH 2/3] ppc: add support for timebase migration on non-PPC hosts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch provides support for migration of the PPC guest timebase on non-PPC host architectures (i.e those using QEMU's virtual emulated timebase). Signed-off-by: Mark Cave-Ayland --- hw/ppc/ppc.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 19f4570..9b80c1d 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -832,6 +832,15 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq) cpu_ppc_store_purr(cpu, 0x0000000000000000ULL); } +static int host_cpu_is_ppc(void) +{ +#if defined(_ARCH_PPC) + return -1; +#else + return 0; +#endif +} + static void timebase_pre_save(void *opaque) { PPCTimebase *tb = opaque; @@ -844,11 +853,16 @@ static void timebase_pre_save(void *opaque) } tb->time_of_the_day_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST); - /* - * tb_offset is only expected to be changed by migration so - * there is no need to update it from KVM here - */ - tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset; + + if (host_cpu_is_ppc()) { + /* + * tb_offset is only expected to be changed by migration so + * there is no need to update it from KVM here + */ + tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset; + } else { + tb->guest_timebase = cpu_ppc_load_tbl(&first_ppc_cpu->env); + } } static int timebase_post_load(void *opaque, int version_id) @@ -879,7 +893,14 @@ static int timebase_post_load(void *opaque, int version_id) NANOSECONDS_PER_SECOND); guest_tb = tb_remote->guest_timebase + migration_duration_tb; - tb_off_adj = guest_tb - cpu_get_host_ticks(); + if (host_cpu_is_ppc()) { + /* Hardware timebase */ + tb_off_adj = guest_tb - cpu_get_host_ticks(); + } else { + /* Software timebase */ + tb_off_adj = guest_tb - muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + freq, get_ticks_per_sec()); + } tb_off = first_ppc_cpu->env.tb_env->tb_offset; trace_ppc_tb_adjust(tb_off, tb_off_adj, tb_off_adj - tb_off,