From patchwork Mon Mar 23 13:35:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 453467 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 BCF2C140082 for ; Tue, 24 Mar 2015 00:47:59 +1100 (AEDT) Received: from localhost ([::1]:55947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya2hx-0007bb-VY for incoming@patchwork.ozlabs.org; Mon, 23 Mar 2015 09:47:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya2YQ-00073e-4q for qemu-devel@nongnu.org; Mon, 23 Mar 2015 09:38:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ya2YL-0002fV-4f for qemu-devel@nongnu.org; Mon, 23 Mar 2015 09:38:06 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:37085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya2YK-0002ex-Hs for qemu-devel@nongnu.org; Mon, 23 Mar 2015 09:38:01 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Mar 2015 23:37:58 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Mar 2015 23:37:55 +1000 Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id ECA9B357804C; Tue, 24 Mar 2015 00:37:54 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2NDbk4643778154; Tue, 24 Mar 2015 00:37:54 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2NDbLOI005282; Tue, 24 Mar 2015 00:37:21 +1100 Received: from bharata.in.ibm.com ([9.79.179.162]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t2NDaUNY004204; Tue, 24 Mar 2015 00:37:18 +1100 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Mon, 23 Mar 2015 19:05:55 +0530 Message-Id: <1427117764-23008-15-git-send-email-bharata@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427117764-23008-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1427117764-23008-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15032313-0013-0000-0000-000000FC40CE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.146 Cc: Bharata B Rao , mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de, david@gibson.dropbear.id.au Subject: [Qemu-devel] [RFC PATCH v2 14/23] cpus: Convert cpu_index into a bitmap 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 Currently CPUState.cpu_index is monotonically increasing and a newly created CPU always gets the next higher index. The next available index is calculated by counting the existing number of CPUs. This is fine as long as we only add CPUs, but there are architectures which are starting to support CPU removal too. For an architecture like PowerPC which derives its CPU identifier (device tree ID) from cpu_index, the existing logic of generating cpu_index values causes problems. With the currently proposed method of handling vCPU removal by parking the vCPU fd in QEMU (Ref: http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg02604.html), generating cpu_index this way will not work for PowerPC. This patch changes the way cpu_index is handed out by maintaining a bit map of the CPUs that tracks both addition and removal of CPUs. Signed-off-by: Bharata B Rao --- exec.c | 37 ++++++++++++++++++++++++++++++++++--- include/qom/cpu.h | 8 ++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index e1ff6b0..9bbab02 100644 --- a/exec.c +++ b/exec.c @@ -527,21 +527,52 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as) } #endif +#ifndef CONFIG_USER_ONLY +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); + +static int cpu_get_free_index(Error **errp) +{ + int cpu = find_first_zero_bit(cpu_index_map, max_cpus); + + if (cpu == max_cpus) { + error_setg(errp, "Trying to use more CPUs than allowed max of %d\n", + max_cpus); + return max_cpus; + } else { + bitmap_set(cpu_index_map, cpu, 1); + return cpu; + } +} + +void cpu_exec_exit(CPUState *cpu) +{ + bitmap_clear(cpu_index_map, cpu->cpu_index, 1); +} +#endif + void cpu_exec_init(CPUArchState *env, Error **errp) { CPUState *cpu = ENV_GET_CPU(env); CPUClass *cc = CPU_GET_CLASS(cpu); - CPUState *some_cpu; int cpu_index; - #if defined(CONFIG_USER_ONLY) + CPUState *some_cpu; + cpu_list_lock(); -#endif cpu_index = 0; CPU_FOREACH(some_cpu) { cpu_index++; } cpu->cpu_index = cpu_index; +#else + Error *local_err = NULL; + + cpu_index = cpu->cpu_index = cpu_get_free_index(&local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } +#endif cpu->numa_node = 0; QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 48fd6fb..5241cf4 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -659,6 +659,14 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask); void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +#ifndef CONFIG_USER_ONLY +void cpu_exec_exit(CPUState *cpu); +#else +static inline void cpu_exec_exit(CPUState *cpu) +{ +} +#endif + #ifdef CONFIG_SOFTMMU extern const struct VMStateDescription vmstate_cpu_common; #else