From patchwork Wed Nov 5 21:53:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 407180 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 7C48F140098 for ; Thu, 6 Nov 2014 08:54:51 +1100 (AEDT) Received: from localhost ([::1]:48659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm8XP-0004YE-GN for incoming@patchwork.ozlabs.org; Wed, 05 Nov 2014 16:54:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm8Wu-0003ox-HI for qemu-devel@nongnu.org; Wed, 05 Nov 2014 16:54:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xm8Wo-00074Y-BW for qemu-devel@nongnu.org; Wed, 05 Nov 2014 16:54:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xm8Wo-00074M-2z for qemu-devel@nongnu.org; Wed, 05 Nov 2014 16:54:10 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sA5Ls93D020099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Nov 2014 16:54:09 -0500 Received: from potion (dhcp-1-135.brq.redhat.com [10.34.1.135]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id sA5Ls6HL019690; Wed, 5 Nov 2014 16:54:07 -0500 Received: by potion (sSMTP sendmail emulation); Wed, 05 Nov 2014 22:54:06 +0100 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: qemu-devel@nongnu.org Date: Wed, 5 Nov 2014 22:53:31 +0100 Message-Id: <1415224413-13972-2-git-send-email-rkrcmar@redhat.com> In-Reply-To: <1415224413-13972-1-git-send-email-rkrcmar@redhat.com> References: <1415224413-13972-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id sA5Ls93D020099 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Richard Henderson , Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 1/3] target-i386: add apicid_pkg_width to topology.h 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 ID topology is made of three elements: smt, core and pkg id; bit width of first two is determined by the actual number of hyperthreads/cores and pkg gets the rest. Basic xAPIC unit tests are included. Signed-off-by: Radim Krčmář --- target-i386/topology.h | 13 +++++++++++++ tests/test-x86-cpuid.c | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/target-i386/topology.h b/target-i386/topology.h index 07a6c5f..e87a685 100644 --- a/target-i386/topology.h +++ b/target-i386/topology.h @@ -70,6 +70,19 @@ static inline unsigned apicid_core_width(unsigned nr_cores, unsigned nr_threads) return apicid_bitwidth_for_count(nr_cores); } +/* Bit width of the Pkg_ID field + */ +static inline unsigned apicid_pkg_width(unsigned nr_cores, + unsigned nr_threads, + unsigned apicid_limit) +{ + unsigned core_smt_width = apicid_core_width(nr_cores, nr_threads) + + apicid_smt_width(nr_cores, nr_threads); + unsigned apicid_width = apicid_bitwidth_for_count(apicid_limit); + + return apicid_width > core_smt_width ? apicid_width - core_smt_width : 0; +} + /* Bit offset of the Core_ID field */ static inline unsigned apicid_core_offset(unsigned nr_cores, diff --git a/tests/test-x86-cpuid.c b/tests/test-x86-cpuid.c index 8d9f96a..6b74f08 100644 --- a/tests/test-x86-cpuid.c +++ b/tests/test-x86-cpuid.c @@ -31,6 +31,8 @@ static void test_topo_bits(void) /* simple tests for 1 thread per core, 1 core per socket */ g_assert_cmpuint(apicid_smt_width(1, 1), ==, 0); g_assert_cmpuint(apicid_core_width(1, 1), ==, 0); + g_assert_cmpuint(apicid_pkg_width(1, 1, 255), ==, 8); + g_assert_cmpuint(apicid_pkg_width(1, 1, 256), ==, 8); g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 0), ==, 0); g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1), ==, 1); @@ -55,6 +57,13 @@ static void test_topo_bits(void) g_assert_cmpuint(apicid_core_width(32, 2), ==, 5); g_assert_cmpuint(apicid_core_width(33, 2), ==, 6); + g_assert_cmpuint(apicid_pkg_width( 2, 2, 255), ==, 6); + g_assert_cmpuint(apicid_pkg_width(16, 16, 255), ==, 0); + g_assert_cmpuint(apicid_pkg_width(99, 99, 255), ==, 0); + g_assert_cmpuint(apicid_pkg_width( 7, 3, 255), ==, 3); + g_assert_cmpuint(apicid_pkg_width( 8, 3, 255), ==, 3); + g_assert_cmpuint(apicid_pkg_width( 9, 3, 255), ==, 2); + g_assert_cmpuint(apicid_pkg_width(12, 6, 255), ==, 1); /* build a weird topology and see if IDs are calculated correctly */