From patchwork Mon Dec 16 06:18:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lijun X-Patchwork-Id: 301474 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 6BF8F2C007C for ; Mon, 16 Dec 2013 17:18:49 +1100 (EST) Received: from localhost ([::1]:53959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsRVt-0001AS-Lc for incoming@patchwork.ozlabs.org; Mon, 16 Dec 2013 01:18:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsRVb-0001AL-3i for qemu-devel@nongnu.org; Mon, 16 Dec 2013 01:18:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsRVa-0003cz-03 for qemu-devel@nongnu.org; Mon, 16 Dec 2013 01:18:27 -0500 Received: from mail-ob0-x232.google.com ([2607:f8b0:4003:c01::232]:49390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsRVZ-0003cv-QD for qemu-devel@nongnu.org; Mon, 16 Dec 2013 01:18:25 -0500 Received: by mail-ob0-f178.google.com with SMTP id uz6so4351867obc.37 for ; Sun, 15 Dec 2013 22:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=MUmbOoVBUzl4B4BsLsu64lGMIia4KRrfoFIV3MP8cGk=; b=iPdj+iH9lwgcBwxi/hdkopuNnbw9i7LJJedmSzPP2cMHoudNsti9Eb6Itkg1Ndu5pR WDSbtHrjVpEc4FHE+B2NKMuMhHtq2JUGMHxJfkSDdo4IjF9Aa3BbngXXdjkup9hcWgIk a+/jeiQFoAIb6qFipsNshRDphJE4rfKfy6/JaLgP6XNEq2+2sqifFKrsM48QSp9ki8AC W+UJgLvop/CAwwHzrql/JJhuw+7VpIaJbziVcsOrBxJfVe3AagB5fOqQtdUkdTtI78HJ G8ic2ye+XXVfWB9GENTszpXgc+yvdFBw7IAoU53ot82+iukqKuZWIuaPICZtWexxlbh6 wAZw== MIME-Version: 1.0 X-Received: by 10.182.29.98 with SMTP id j2mr10082802obh.30.1387174705031; Sun, 15 Dec 2013 22:18:25 -0800 (PST) Received: by 10.60.10.37 with HTTP; Sun, 15 Dec 2013 22:18:24 -0800 (PST) Date: Mon, 16 Dec 2013 14:18:24 +0800 Message-ID: From: jun muzi To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::232 Cc: blauwirbel@gmail.com, afaerber@suse.de, ehabkost@redhat.com, rth@twiddle.net Subject: Re: [Qemu-devel] [PATCH] qemu will core dump with "-smp 254, sockets=2, cores=3, threads=2" 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 As Peter's suggestion, mv this patch to file target-i386/topology.h. If someone has any good idea, please give me a commit in the followings. Thanks. --- target-i386/topology.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) * 'cpu_index' is a sequential, contiguous ID for the CPU. @@ -126,6 +139,13 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_cores, unsigned cpu_index) { unsigned pkg_id, core_id, smt_id; + + /* check whether nr_cores and nr_threads is a power of 2 */ + if (!is_2_power(smp_cores) || !is_2_power(smp_threads)) { + nr_cores = 1; + nr_threads = 1; + } + x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index, &pkg_id, &core_id, &smt_id); return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, core_id, smt_id); diff --git a/target-i386/topology.h b/target-i386/topology.h index 07a6c5f..cda6bf5 100644 --- a/target-i386/topology.h +++ b/target-i386/topology.h @@ -117,6 +117,19 @@ static inline void x86_topo_ids_from_idx(unsigned nr_cores, *pkg_id = core_index / nr_cores; } +/* This function will return whether @num is power of 2. + * + * Returns: 1 indicate @num is power of 2, 0 indicate @num is not. + */ +static int is_2_power(int num) +{ + if (num < 0 || num > 256) { + return 1; + } + + return !(num & (num - 1)); +} + /* Make APIC ID for the CPU 'cpu_index' *