From patchwork Tue Sep 10 09:43:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenfan X-Patchwork-Id: 273805 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EE04E2C011E for ; Tue, 10 Sep 2013 19:46:34 +1000 (EST) Received: from localhost ([::1]:56682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWn-0000Jy-3I for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 05:46:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWJ-0000Ie-B0 for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJKWE-0006lS-PH for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:46:03 -0400 Received: from [222.73.24.84] (port=64787 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJKWE-0006ii-EC for qemu-devel@nongnu.org; Tue, 10 Sep 2013 05:45:58 -0400 X-IronPort-AV: E=Sophos;i="4.90,877,1371052800"; d="scan'208";a="8473927" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 10 Sep 2013 17:42:38 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r8A9jlhv024412; Tue, 10 Sep 2013 17:45:47 +0800 Received: from G08FNSTD131468.fnst.cn.fujitsu.com ([10.167.226.78]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013091017432879-1376617 ; Tue, 10 Sep 2013 17:43:28 +0800 From: Chen Fan To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 17:43:41 +0800 Message-Id: X-Mailer: git-send-email 1.8.1.4 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:28, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/09/10 17:43:30, Serialize complete at 2013/09/10 17:43:30 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [RFC qom-cpu v2 1/8] apic: remove apic_no from apic_init_common() 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 the 'apic_no' is increased by one when initialize/create a vCPU each time, 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-use the vacant s->idx which the corresponding vCPU had been removed. so we could use the unique cpu apic_id instead of the progressive s->idx. 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 = APIC_COMMON(dev); APICCommonClass *info; static DeviceState *vapic; - static int apic_no; static bool mmio_registered; - if (apic_no >= MAX_APICS) { + if (s->idx >= MAX_APICS) { return -1; } - s->idx = apic_no++; info = 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, Error **errp) /* TODO: convert to link<> */ apic = APIC_COMMON(env->apic_state); apic->cpu = cpu; + apic->idx = env->cpuid_apic_id; } static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)