From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yah3A-0007pA-Gm for qemu-devel@nongnu.org; Wed, 25 Mar 2015 04:52:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yah2z-000417-VM for qemu-devel@nongnu.org; Wed, 25 Mar 2015 04:52:32 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:33348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yah2z-000403-CX for qemu-devel@nongnu.org; Wed, 25 Mar 2015 04:52:21 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Mar 2015 14:22:17 +0530 Date: Wed, 25 Mar 2015 14:22:08 +0530 From: Bharata B Rao Message-ID: <20150325085208.GE32581@in.ibm.com> References: <1427117764-23008-1-git-send-email-bharata@linux.vnet.ibm.com> <1427117764-23008-15-git-send-email-bharata@linux.vnet.ibm.com> <20150325032329.GY25043@voom.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150325032329.GY25043@voom.fritz.box> Subject: Re: [Qemu-devel] [RFC PATCH v2 14/23] cpus: Convert cpu_index into a bitmap Reply-To: bharata@linux.vnet.ibm.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de On Wed, Mar 25, 2015 at 02:23:29PM +1100, David Gibson wrote: > On Mon, Mar 23, 2015 at 07:05:55PM +0530, Bharata B Rao wrote: > > 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); > > +} > > AFAICT, this function is never called, which seems like a bug. It is called in subsequent patch. If you are suggesting that a function shouldn't be defined in a patch where it not used, I can move this down to the other patch. Regards, Bharata.