qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 3/4] s390x/cpu: Add function to set CPU state


From: Matthew Rosato
Subject: [Qemu-devel] [PATCH 3/4] s390x/cpu: Add function to set CPU state
Date: Mon, 9 Nov 2015 10:17:39 -0500

Introduce s390_cpu_set_cpustate, which will set/update the
machine/cpu[n] link with the current CPU state.  Additionally,
maintain an array of state pointers indexed by CPU id for fast lookup
during interrupt handling.

Signed-off-by: Matthew Rosato <address@hidden>
Acked-by: David Hildenbrand <address@hidden>
---
 hw/s390x/s390-virtio.c | 29 ++++++++++++++++++++---------
 target-s390x/cpu.c     |  3 ++-
 target-s390x/cpu.h     |  1 +
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index b9cf058..ea867e0 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -62,15 +62,30 @@
 #define S390_TOD_CLOCK_VALUE_PRESENT    0x01
 
 static VirtIOS390Bus *s390_bus;
-static S390CPU **ipi_states;
+static S390CPU **cpu_states;
 
 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
 {
-    if (cpu_addr >= smp_cpus) {
+    if (cpu_addr >= max_cpus) {
         return NULL;
     }
 
-    return ipi_states[cpu_addr];
+    /* Fast lookup via CPU ID */
+    return cpu_states[cpu_addr];
+}
+
+void s390_cpu_set_cpustate(uint16_t cpu_addr, S390CPU *state)
+{
+    gchar *name;
+
+    cpu_states[cpu_addr] = state;
+    name = g_strdup_printf("cpu[%i]", cpu_addr);
+    object_property_add_link(qdev_get_machine(), name, TYPE_S390_CPU,
+                             (Object **) &cpu_states[cpu_addr],
+                             object_property_allow_set_link,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
+                             &error_abort);
+    g_free(name);
 }
 
 static int s390_virtio_hcall_notify(const uint64_t *args)
@@ -176,14 +191,10 @@ void s390_init_cpus(MachineState *machine)
         machine->cpu_model = "host";
     }
 
-    ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
+    cpu_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
 
     for (i = 0; i < smp_cpus; i++) {
-        S390CPU *cpu;
-
-        cpu = cpu_s390x_init(machine->cpu_model);
-
-        ipi_states[i] = cpu;
+        cpu_s390x_init(machine->cpu_model);
     }
 }
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index aafbbdc..3228c3b 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -221,6 +221,7 @@ static void s390_cpu_initfn(Object *obj)
     cs->halted = 1;
     cs->exception_index = EXCP_HLT;
     cpu_exec_init(cs, &error_abort);
+    env->cpu_num = cpu_num++;
 #if !defined(CONFIG_USER_ONLY)
     qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
@@ -230,8 +231,8 @@ static void s390_cpu_initfn(Object *obj)
     env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
     env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
     s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
+    s390_cpu_set_cpustate(env->cpu_num, cpu);
 #endif
-    env->cpu_num = cpu_num++;
 
     if (tcg_enabled() && !inited) {
         inited = true;
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 658cd9d..803841b 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -531,6 +531,7 @@ static inline int s390_set_clock(uint8_t *tod_high, 
uint64_t *tod_low)
 }
 
 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr);
+void s390_cpu_set_cpustate(uint16_t cpu_addr, S390CPU *state);
 unsigned int s390_cpu_halt(S390CPU *cpu);
 void s390_cpu_unhalt(S390CPU *cpu);
 unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu);
-- 
1.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]