From patchwork Thu Oct 9 13:35:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 398033 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0F2A61400A0 for ; Fri, 10 Oct 2014 00:37:10 +1100 (EST) Received: from localhost ([::1]:42580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcDu0-00047N-3g for incoming@patchwork.ozlabs.org; Thu, 09 Oct 2014 09:37:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcDtF-00032y-IF for qemu-devel@nongnu.org; Thu, 09 Oct 2014 09:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcDt7-0005dz-NA for qemu-devel@nongnu.org; Thu, 09 Oct 2014 09:36:21 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:57651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcDt7-0005dr-FX for qemu-devel@nongnu.org; Thu, 09 Oct 2014 09:36:13 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 Oct 2014 14:36:12 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 9 Oct 2014 14:36:10 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7FD0D2190045 for ; Thu, 9 Oct 2014 14:35:47 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s99Da9dv14352658 for ; Thu, 9 Oct 2014 13:36:09 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s99Da7oI008789 for ; Thu, 9 Oct 2014 07:36:09 -0600 Received: from gondolin.boeblingen.de.ibm.com (dyn-9-152-224-210.boeblingen.de.ibm.com [9.152.224.210]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s99Da4Aq008595; Thu, 9 Oct 2014 07:36:06 -0600 From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 9 Oct 2014 15:35:55 +0200 Message-Id: <1412861761-22047-3-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1412861761-22047-1-git-send-email-cornelia.huck@de.ibm.com> References: <1412861761-22047-1-git-send-email-cornelia.huck@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14100913-0025-0000-0000-000001D20D13 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.112 Cc: borntraeger@de.ibm.com, qemu-devel@nongnu.org, agraf@suse.de, David Hildenbrand , jfrei@linux.vnet.ibm.com, Cornelia Huck , Andreas Faerber Subject: [Qemu-devel] [PULL 2/8] s390x/kvm: introduce proper states for s390 cpus 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 From: David Hildenbrand Until now, when a s390 cpu was stopped or halted, the number of running CPUs was tracked in a global variable. This was problematic for migration, so Jason came up with a per-cpu running state. As it turns out, we want to track the full logical state of a target vcpu, so we need real s390 cpu states. This patch is based on an initial patch by Jason Herne, but was heavily rewritten when adding the cpu states STOPPED and OPERATING. On the way we move add_del_running to cpu.c (the declaration is already in cpu.h) and modify the users where appropriate. Please note that the cpu is still set to be stopped when it is halted, which is wrong. This will be fixed in the next patch. The LOAD and CHECK-STOP state will not be used in the first step. Signed-off-by: David Hildenbrand [folded Jason's patch into David's patch to avoid add/remove same lines] Signed-off-by: Jens Freimann Reviewed-by: Cornelia Huck Reviewed-by: Christian Borntraeger CC: Andreas Faerber Tested-by: Christian Borntraeger Signed-off-by: Cornelia Huck --- hw/s390x/s390-virtio.c | 32 -------------------------------- target-s390x/cpu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu.h | 14 ++++++++++++++ 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c index 9c61246..af0004a 100644 --- a/hw/s390x/s390-virtio.c +++ b/hw/s390x/s390-virtio.c @@ -125,38 +125,6 @@ static void s390_virtio_register_hcalls(void) s390_virtio_hcall_set_status); } -/* - * The number of running CPUs. On s390 a shutdown is the state of all CPUs - * being either stopped or disabled (for interrupts) waiting. We have to - * track this number to call the shutdown sequence accordingly. This - * number is modified either on startup or while holding the big qemu lock. - */ -static unsigned s390_running_cpus; - -void s390_add_running_cpu(S390CPU *cpu) -{ - CPUState *cs = CPU(cpu); - - if (cs->halted) { - s390_running_cpus++; - cs->halted = 0; - cs->exception_index = -1; - } -} - -unsigned s390_del_running_cpu(S390CPU *cpu) -{ - CPUState *cs = CPU(cpu); - - if (cs->halted == 0) { - assert(s390_running_cpus >= 1); - s390_running_cpus--; - cs->halted = 1; - cs->exception_index = EXCP_HLT; - } - return s390_running_cpus; -} - void s390_init_ipl_dev(const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 2cfeb82..03cab74 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -229,6 +229,49 @@ static void s390_cpu_finalize(Object *obj) #endif } +#if !defined(CONFIG_USER_ONLY) +static unsigned s390_count_running_cpus(void) +{ + CPUState *cpu; + int nr_running = 0; + + CPU_FOREACH(cpu) { + uint8_t state = S390_CPU(cpu)->env.cpu_state; + if (state == CPU_STATE_OPERATING || + state == CPU_STATE_LOAD) { + nr_running++; + } + } + + return nr_running; +} + +void s390_add_running_cpu(S390CPU *cpu) +{ + CPUState *cs = CPU(cpu); + + if (cs->halted) { + cpu->env.cpu_state = CPU_STATE_OPERATING; + cs->halted = 0; + cs->exception_index = -1; + } +} + +unsigned s390_del_running_cpu(S390CPU *cpu) +{ + CPUState *cs = CPU(cpu); + + if (cs->halted == 0) { + assert(s390_count_running_cpus() >= 1); + cpu->env.cpu_state = CPU_STATE_STOPPED; + cs->halted = 1; + cs->exception_index = EXCP_HLT; + } + + return s390_count_running_cpus(); +} +#endif + static const VMStateDescription vmstate_s390_cpu = { .name = "cpu", .unmigratable = 1, diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 62940c3..f1a3ad2 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -141,6 +141,20 @@ typedef struct CPUS390XState { QEMUTimer *tod_timer; QEMUTimer *cpu_timer; + + /* + * The cpu state represents the logical state of a cpu. In contrast to other + * architectures, there is a difference between a halt and a stop on s390. + * If all cpus are either stopped (including check stop) or in the disabled + * wait state, the vm can be shut down. + */ +#define CPU_STATE_UNINITIALIZED 0x00 +#define CPU_STATE_STOPPED 0x01 +#define CPU_STATE_CHECK_STOP 0x02 +#define CPU_STATE_OPERATING 0x03 +#define CPU_STATE_LOAD 0x04 + uint8_t cpu_state; + } CPUS390XState; #include "cpu-qom.h"