From: Alexander Graf <agraf@suse.de>
To: qemu-devel Developers <qemu-devel@nongnu.org>
Cc: blauwirbel@gmail.com, Christian Borntraeger <borntraeger@de.ibm.com>
Subject: [Qemu-devel] [PATCH 08/12] s390: Fix cpu shutdown for KVM
Date: Mon, 14 Nov 2011 18:06:36 +0100 [thread overview]
Message-ID: <1321290400-32717-9-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1321290400-32717-1-git-send-email-agraf@suse.de>
From: Christian Borntraeger <borntraeger@de.ibm.com>
On s390 a shutdown is the state of all CPUs being either stopped
or disabled (for interrupts) waiting. We have to track the overall
number of running CPUs to call the shutdown sequence accordingly.
This patch implements the counting and shutdown handling for the
kvm path in qemu.
Lets also wrap changes to env->halted and env->exception_index.
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
hw/s390-virtio.c | 32 ++++++++++++++++++++++++++++++--
target-s390x/cpu.h | 2 ++
target-s390x/kvm.c | 19 +++++++------------
3 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index ee850f0..37945d5 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -121,6 +121,34 @@ int s390_virtio_hypercall(CPUState *env, uint64_t mem, uint64_t hypercall)
return r;
}
+/*
+ * 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(CPUState *env)
+{
+ if (env->halted) {
+ s390_running_cpus++;
+ env->halted = 0;
+ env->exception_index = -1;
+ }
+}
+
+unsigned s390_del_running_cpu(CPUState *env)
+{
+ if (env->halted == 0) {
+ assert(s390_running_cpus >= 1);
+ s390_running_cpus--;
+ env->halted = 1;
+ env->exception_index = EXCP_HLT;
+ }
+ return s390_running_cpus;
+}
+
/* PC hardware initialisation */
static void s390_init(ram_addr_t my_ram_size,
const char *boot_device,
@@ -179,8 +207,8 @@ static void s390_init(ram_addr_t my_ram_size,
tmp_env->storage_keys = storage_keys;
}
- env->halted = 0;
- env->exception_index = 0;
+ /* One CPU has to run */
+ s390_add_running_cpu(env);
if (kernel_filename) {
kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 95abe59..a66aa01 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -309,6 +309,8 @@ static inline void kvm_s390_interrupt_internal(CPUState *env, int type,
}
#endif
CPUState *s390_cpu_addr2state(uint16_t cpu_addr);
+void s390_add_running_cpu(CPUState *env);
+unsigned s390_del_running_cpu(CPUState *env);
/* from s390-virtio-bus */
extern const target_phys_addr_t virtio_size;
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 4beb794..40b0ab1 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -185,8 +185,7 @@ void kvm_s390_interrupt_internal(CPUState *env, int type, uint32_t parm,
return;
}
- env->halted = 0;
- env->exception_index = -1;
+ s390_add_running_cpu(env);
qemu_cpu_kick(env);
kvmint.type = type;
@@ -299,8 +298,7 @@ static int handle_diag(CPUState *env, struct kvm_run *run, int ipb_code)
static int s390_cpu_restart(CPUState *env)
{
kvm_s390_interrupt(env, KVM_S390_RESTART, 0);
- env->halted = 0;
- env->exception_index = -1;
+ s390_add_running_cpu(env);
qemu_cpu_kick(env);
dprintf("DONE: SIGP cpu restart: %p\n", env);
return 0;
@@ -425,17 +423,16 @@ static int handle_intercept(CPUState *env)
r = handle_instruction(env, run);
break;
case ICPT_WAITPSW:
- /* XXX What to do on system shutdown? */
- env->halted = 1;
- env->exception_index = EXCP_HLT;
+ case ICPT_CPU_STOP:
+ if (s390_del_running_cpu(env) == 0) {
+ qemu_system_shutdown_request();
+ }
+ r = EXCP_HALTED;
break;
case ICPT_SOFT_INTERCEPT:
fprintf(stderr, "KVM unimplemented icpt SOFT\n");
exit(1);
break;
- case ICPT_CPU_STOP:
- qemu_system_shutdown_request();
- break;
case ICPT_IO:
fprintf(stderr, "KVM unimplemented icpt IO\n");
exit(1);
@@ -468,8 +465,6 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
if (ret == 0) {
ret = EXCP_INTERRUPT;
- } else if (ret > 0) {
- ret = 0;
}
return ret;
}
--
1.6.0.2
next prev parent reply other threads:[~2011-11-14 17:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-14 17:06 [Qemu-devel] [PULL 00/12] s390 patch queue 2011-11-14 1.0 Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 01/12] s390x: add ldeb instruction Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 02/12] s390x: make ipte 31-bit aware Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 03/12] s390x: update R and C bits in storage key Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 04/12] s390x: implement rrbe instruction properly Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 05/12] s390x: implement SIGP restart and shutdown Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 06/12] s390: fix reset hypercall to reset the status Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 07/12] s390: fix short kernel command lines Alexander Graf
2011-11-14 17:06 ` Alexander Graf [this message]
2011-11-14 17:06 ` [Qemu-devel] [PATCH 09/12] s390x: Add shutdown for TCG s390-virtio machine Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 10/12] tcg: Standardize on TCGReg as the enum for hard registers Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 11/12] tcg: Use TCGReg for standard tcg-target entry points Alexander Graf
2011-11-14 17:06 ` [Qemu-devel] [PATCH 12/12] s390x: initialize virtio dev region Alexander Graf
2011-11-19 13:58 ` [Qemu-devel] [PULL 00/12] s390 patch queue 2011-11-14 1.0 Blue Swirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321290400-32717-9-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=blauwirbel@gmail.com \
--cc=borntraeger@de.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).