From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvoCr-0006vn-1a for qemu-devel@nongnu.org; Mon, 09 Nov 2015 10:18:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvoCl-0002o7-MF for qemu-devel@nongnu.org; Mon, 09 Nov 2015 10:18:04 -0500 Received: from e39.co.us.ibm.com ([32.97.110.160]:35240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvoCl-0002o3-6r for qemu-devel@nongnu.org; Mon, 09 Nov 2015 10:17:59 -0500 Received: from localhost by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Nov 2015 08:17:58 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 7B0901FF0049 for ; Mon, 9 Nov 2015 08:06:06 -0700 (MST) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tA9FGST33801428 for ; Mon, 9 Nov 2015 08:16:28 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tA9FHshL020578 for ; Mon, 9 Nov 2015 08:17:54 -0700 From: Matthew Rosato Date: Mon, 9 Nov 2015 10:17:39 -0500 Message-Id: <1447082260-427-4-git-send-email-mjrosato@linux.vnet.ibm.com> In-Reply-To: <1447082260-427-1-git-send-email-mjrosato@linux.vnet.ibm.com> References: <1447082260-427-1-git-send-email-mjrosato@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 3/4] s390x/cpu: Add function to set CPU state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com, borntraeger@de.ibm.com, agraf@suse.de, afaerber@suse.de, rth@twiddle.net 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 Acked-by: David Hildenbrand --- 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