From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEygn-0000xY-6L for qemu-devel@nongnu.org; Tue, 14 Jul 2015 07:47:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEygj-0000eX-TQ for qemu-devel@nongnu.org; Tue, 14 Jul 2015 07:47:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEygj-0000eH-Lu for qemu-devel@nongnu.org; Tue, 14 Jul 2015 07:47:53 -0400 Date: Tue, 14 Jul 2015 13:47:48 +0200 From: Igor Mammedov Message-ID: <20150714134748.5331caaa@nial.brq.redhat.com> In-Reply-To: <20150714103854.GB4827@in.ibm.com> References: <1436448252-1916-1-git-send-email-afaerber@suse.de> <1436448252-1916-6-git-send-email-afaerber@suse.de> <20150714103854.GB4827@in.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PULL v3 05/22] cpu: Convert cpu_index into a bitmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: qemu-devel@nongnu.org, Paolo Bonzini , Peter Crosthwaite , Andreas =?UTF-8?B?RsOkcmJlcg==?= , david@gibson.dropbear.id.au On Tue, 14 Jul 2015 16:08:54 +0530 Bharata B Rao wrote: > On Thu, Jul 09, 2015 at 03:23:55PM +0200, Andreas F=C3=A4rber wrote: > > From: Bharata B Rao > >=20 > > 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 Powe= rPC > > which derives its CPU identifier (device tree ID) from cpu_index, the > > existing logic of generating cpu_index values causes problems. > >=20 > > 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.htm= l), > > generating cpu_index this way will not work for PowerPC. > >=20 > > 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. > >=20 > > The CPU bitmap allocation logic is part of cpu_exec_init(), which is > > called by instance_init routines of various CPU targets. Newly added > > cpu_exec_exit() API handles the deallocation part and this routine is > > called from generic CPU instance_finalize. > >=20 > > Note: This new CPU enumeration is for !CONFIG_USER_ONLY only. > > CONFIG_USER_ONLY continues to have the old enumeration logic. > >=20 > > Signed-off-by: Bharata B Rao > > Reviewed-by: Eduardo Habkost > > Reviewed-by: Igor Mammedov > > Reviewed-by: David Gibson > > Reviewed-by: Peter Crosthwaite > > Acked-by: Paolo Bonzini > > Signed-off-by: Peter Crosthwaite > > [AF: max_cpus -> MAX_CPUMASK_BITS] > > Signed-off-by: Andreas F=C3=A4rber > > --- > > exec.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++= +++----- > > include/qom/cpu.h | 1 + > > qom/cpu.c | 7 +++++++ > > 3 files changed, 61 insertions(+), 5 deletions(-) > >=20 > > diff --git a/exec.c b/exec.c > > index ce5fadd..d817e5f 100644 > > --- a/exec.c > > +++ b/exec.c > > @@ -526,12 +526,57 @@ void tcg_cpu_address_space_init(CPUState *cpu, Ad= dressSpace *as) > > } > > #endif > >=20 > > +#ifndef CONFIG_USER_ONLY > > +static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); > > + > > +static int cpu_get_free_index(Error **errp) > > +{ > > + int cpu =3D find_first_zero_bit(cpu_index_map, MAX_CPUMASK_BITS); > > + > > + if (cpu >=3D MAX_CPUMASK_BITS) { > > + error_setg(errp, "Trying to use more CPUs than max of %d", > > + MAX_CPUMASK_BITS); > > + return -1; > > + } >=20 > If this routine and hence cpu_exec_init() (which is called from realize > routine) don't error out when max_cpus is reached, archs supporting CPU > hotplug using device_add will find it difficult to fail the realization of > CPU when hotplugging of more than max_cpus is attempted. >=20 > An alternative is to explicitly check for the returned cpu_index > in realize call within each arch and fail if the cpu_index obtained > is greater than max_cpus. So for ppc, I could put such a check in > target-ppc/translate_init:ppc_cpu_realizefn(), but ppc_cpu_realizefn() > is a common routine for all targets under ppc and some targets like > ppc64abi32-linux-user don't have visibility to max_cpus which is > in vl.c. >=20 > Any thoughts on the above problem ? we already have MachineClass.max_cpus which is max supported limit of machine type. Perhaps make max_cpus a property of MashineState >=20 > Also, is it possible to revisit the problem that use of max_cpus instead > of MAX_CPUMASK_BITS caused to xlnx-ep108 ? >=20 > Regards, > Bharata. >=20 >=20