Received: from eggs.gnu.org ([2001:4830:134:3::10]:47193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJd94-0006LZ-VA for qemu-devel@nongnu.org; Wed, 11 Sep 2013 01:39:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJd8x-0006bb-Pm for qemu-devel@nongnu.org; Wed, 11 Sep 2013 01:39:18 -0400 Received: from [222.73.24.84] (port=8211 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJd8x-0006au-CU for qemu-devel@nongnu.org; Wed, 11 Sep 2013 01:39:11 -0400 Message-ID: <1378877823.17949.20.camel@G08FNSTD131468> From: chenfan Date: Wed, 11 Sep 2013 13:37:03 +0800 In-Reply-To: <522F0D99.5050508@suse.de> References: <20130910140926.091ea307@nial.usersys.redhat.com> <522F0D99.5050508@suse.de> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Subject: Re: [Qemu-devel] [RFC qom-cpu v2 1/8] apic: remove apic_no from apic_init_common() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?ISO-8859-1?Q?F=E4rber?= Cc: Igor Mammedov , qemu-devel@nongnu.org On Tue, 2013-09-10 at 14:16 +0200, Andreas F=C3=A4rber wrote: > Am 10.09.2013 14:09, schrieb Igor Mammedov: > > On Tue, 10 Sep 2013 17:43:41 +0800 > > Chen Fan wrote: > >=20 > >> the 'apic_no' is increased by one when initialize/create a vCPU each t= ime, > >> which causes APICCommonState s->idx always is increased. > >> but if we want to re-add a vCPU after removing a vCPU, we need to re-u= se the > >> vacant s->idx which the corresponding vCPU had been removed.=20 > >> so we could use the unique cpu apic_id instead of the progressive s->i= dx. > >> > >> Signed-off-by: Chen Fan > >> --- > >> hw/intc/apic_common.c | 4 +--- > >> target-i386/cpu.c | 1 + > >> 2 files changed, 2 insertions(+), 3 deletions(-) > >> > >> diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c > >> index a0beb10..5568621 100644 > >> --- a/hw/intc/apic_common.c > >> +++ b/hw/intc/apic_common.c > >> @@ -289,13 +289,11 @@ static int apic_init_common(ICCDevice *dev) > >> APICCommonState *s =3D APIC_COMMON(dev); > >> APICCommonClass *info; > >> static DeviceState *vapic; > >> - static int apic_no; > >> static bool mmio_registered; > >> =20 > >> - if (apic_no >=3D MAX_APICS) { > >> + if (s->idx >=3D MAX_APICS) { > >> return -1; > >> } > >> - s->idx =3D apic_no++; > >> =20 > >> info =3D APIC_COMMON_GET_CLASS(s); > >> info->init(s); > >> diff --git a/target-i386/cpu.c b/target-i386/cpu.c > >> index 42c5de0..2b99683 100644 > >> --- a/target-i386/cpu.c > >> +++ b/target-i386/cpu.c > >> @@ -2322,6 +2322,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Err= or **errp) > >> /* TODO: convert to link<> */ > >> apic =3D APIC_COMMON(env->apic_state); > >> apic->cpu =3D cpu; > >> + apic->idx =3D env->cpuid_apic_id; > > earlier here we set: > > qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id); > > so apic->idx =3D env->cpuid_apic_id is redundant. > >=20 > > it would be better to search by apic->id and preferably replace O(MAX_A= PIC) scans with > > a faster approach since for TCG iqr delivery might be a hot path, dropp= ing MAX_APIC > > altogether and using dynamic present APICs list. >=20 > Independent of that, the recent removal of X86_CPU() cast from > x86_env_get_cpu() should allow us to finally tackle the TODO above, > moving apic_state field from CPUX86State to X86CPU. >=20 I will send V3 patches later including modification pointed out above.=20 Thanks > Andreas >=20 > >=20 > >> } > >> =20 > >> static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) > >=20 >=20 >=20