From patchwork Wed Nov 21 14:46:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Borntraeger X-Patchwork-Id: 200786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6369A2C008F for ; Thu, 22 Nov 2012 01:46:25 +1100 (EST) Received: from localhost ([::1]:58167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbBZH-0007yy-K7 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2012 09:46:23 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbBYt-0007KQ-FZ for qemu-devel@nongnu.org; Wed, 21 Nov 2012 09:46:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbBYm-0001qT-VB for qemu-devel@nongnu.org; Wed, 21 Nov 2012 09:45:59 -0500 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:38719) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbBYm-0001qF-Jk for qemu-devel@nongnu.org; Wed, 21 Nov 2012 09:45:52 -0500 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Nov 2012 14:45:51 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 21 Nov 2012 14:45:49 -0000 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qALEjfgX54853854 for ; Wed, 21 Nov 2012 14:45:42 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qALEjnwq020060 for ; Wed, 21 Nov 2012 07:45:49 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qALEjmNx020045; Wed, 21 Nov 2012 07:45:48 -0700 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 25651) id C08AA122442E; Wed, 21 Nov 2012 15:45:48 +0100 (CET) From: Christian Borntraeger To: Alexander Graf Date: Wed, 21 Nov 2012 15:46:03 +0100 Message-Id: <1353509165-26865-2-git-send-email-borntraeger@de.ibm.com> X-Mailer: git-send-email 1.7.10.1 In-Reply-To: <1353509165-26865-1-git-send-email-borntraeger@de.ibm.com> References: <1353509165-26865-1-git-send-email-borntraeger@de.ibm.com> x-cbid: 12112114-4966-0000-0000-000004272354 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.106 Cc: Christian Borntraeger , Jens Freimann , Heinz Graalfs , qemu-devel , "Jason J. herne" Subject: [Qemu-devel] [PATCH 1/3] s390/migration: Provide a cpu save for initial life migration work 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This provides a simple cpu load and save function. With the recent addition of sync regs we have the crs,acrs, the prefix and the PSW already up to date. Lets also save the fpu via pre/post hooks. This patch also changes the license of machine.c to GPLv2 or later. (The old code was just empty glue code, so there is no need to go the "contributions after" way). Signed-off-by: Christian Borntraeger --- target-s390x/cpu.h | 1 + target-s390x/machine.c | 115 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 13 deletions(-) diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 0f9a1f7..ba695dd 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -27,6 +27,7 @@ #define ELF_MACHINE EM_S390 #define CPUArchState struct CPUS390XState +#define CPU_SAVE_VERSION 1 #include "cpu-defs.h" #define TARGET_PAGE_BITS 12 diff --git a/target-s390x/machine.c b/target-s390x/machine.c index 3e79be6..02706fd 100644 --- a/target-s390x/machine.c +++ b/target-s390x/machine.c @@ -2,29 +2,118 @@ * QEMU S390x machine definitions * * Copyright (c) 2009 Alexander Graf + * Copyright IBM Corp. 2012 * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . + * This work is licensed under the terms of the GNU GPL, version 2 or (at your + * option) any later version. See the COPYING file in the top-level directory. */ #include "hw/hw.h" #include "hw/boards.h" +#include "cpu.h" +#include "kvm.h" + +#if defined CONFIG_KVM +static void cpu_pre_save(void *opaque) +{ + CPUS390XState *env = opaque; + struct kvm_fpu fpu; + int i, r; + + if (!kvm_enabled()) { + return; + } + + r = kvm_vcpu_ioctl(env, KVM_GET_FPU, &fpu); + assert(r == 0); + for (i = 0; i < 16; i++) { + env->fregs[i].ll = fpu.fprs[i]; + } + env->fpc = fpu.fpc; +} + +static int cpu_post_load(void *opaque, int version_id) +{ + CPUS390XState *env = opaque; + struct kvm_fpu fpu; + int i, r; + + if (!kvm_enabled()) { + return 0; + } + + for (i = 0; i < 16; i++) { + fpu.fprs[i] = env->fregs[i].ll; + } + fpu.fpc = env->fpc; + + r = kvm_vcpu_ioctl(env, KVM_SET_FPU, &fpu); + assert(r == 0); + + return 0; +} +#else +static int cpu_post_load(void *opaque, int version_id) +{ + return 0; +} + +static void cpu_pre_save(void *opaque) +{ +} +#endif + + +static const VMStateDescription vmstate_cpu = { + .name = "cpu", + .version_id = CPU_SAVE_VERSION, + .pre_save = cpu_pre_save, + .post_load = cpu_post_load, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT64(fregs[0].ll, CPUS390XState), + VMSTATE_UINT64(fregs[1].ll, CPUS390XState), + VMSTATE_UINT64(fregs[2].ll, CPUS390XState), + VMSTATE_UINT64(fregs[3].ll, CPUS390XState), + VMSTATE_UINT64(fregs[4].ll, CPUS390XState), + VMSTATE_UINT64(fregs[5].ll, CPUS390XState), + VMSTATE_UINT64(fregs[6].ll, CPUS390XState), + VMSTATE_UINT64(fregs[7].ll, CPUS390XState), + VMSTATE_UINT64(fregs[8].ll, CPUS390XState), + VMSTATE_UINT64(fregs[9].ll, CPUS390XState), + VMSTATE_UINT64(fregs[10].ll, CPUS390XState), + VMSTATE_UINT64(fregs[11].ll, CPUS390XState), + VMSTATE_UINT64(fregs[12].ll, CPUS390XState), + VMSTATE_UINT64(fregs[13].ll, CPUS390XState), + VMSTATE_UINT64(fregs[14].ll, CPUS390XState), + VMSTATE_UINT64(fregs[15].ll, CPUS390XState), + VMSTATE_UINT64_ARRAY(regs, CPUS390XState, 16), + VMSTATE_UINT64(psw.mask, CPUS390XState), + VMSTATE_UINT64(psw.addr, CPUS390XState), + VMSTATE_UINT64(psa, CPUS390XState), + VMSTATE_UINT32(fpc, CPUS390XState), + VMSTATE_UINT32_ARRAY(aregs, CPUS390XState, 16), + VMSTATE_UINT64_ARRAY(cregs, CPUS390XState, 16), + VMSTATE_END_OF_LIST() + }, + .subsections = (VMStateSubsection[]) { + { + /* empty */ + } + } + +}; + + + void cpu_save(QEMUFile *f, void *opaque) { + vmstate_save_state(f, &vmstate_cpu, opaque); } int cpu_load(QEMUFile *f, void *opaque, int version_id) { - return 0; + return vmstate_load_state(f, &vmstate_cpu, opaque, version_id); }