From patchwork Wed Mar 11 02:33:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2FBF138D for ; Wed, 11 Mar 2020 02:34:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A959A208C3 for ; Wed, 11 Mar 2020 02:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="qJFw68kh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A959A208C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCn-0000mn-QC for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:34:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37546) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrBa-0007oa-As for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrBY-00066d-CF for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:30 -0400 Received: from mail-dm6nam10on2041.outbound.protection.outlook.com ([40.107.93.41]:59616 helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrBY-00065s-5E for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jSuQga5E74WOJpCSkkN6GLOVu5wzIlVdvyB4PjuhWyMyVQfhRYOYKyVa21WPpe4BRhRNsIs0+Nmxnbnwb0b5TDoA108ToHoxxEoW9hQlT+Ce/HyOdfH9A/AqpizO/oOHEjFfDD06nJYa4R5S6GGKvgZ3TS7HgYzUPoWUwPlW2H/PJVDFoTpn4zRrXTuK12H+j8Y9bGFQap0Z3T7KrTGUFmFx5utW7SMKzp2iw772mkDAetrepE54djCa0aHWnyBFsJceulwTDm6YASjxahE9tB5HWH5dOzITdzEmBdeZRXmXPPqxI0KY6clyucZEbDYUUXUEX1S19CCt507heiPOjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T9SppP2H8YKS9kqR9/++blVpAWMaV5mM8v4LZR2cxjA=; b=GK1tCRO5Av+E9tUzh3Lf493yKtiUGQHtCSrJ0fImdEe66g+MS+NsQdH31Kc6Pr5FXo9uiOwMsDqHBrmRvvMF3SwVSROjZwr1FBzZ/ByhpskVy2UaWaSFXCvfnuf3TDfV25Wn5agcO0G5VifiMAQhm1kxSX36n/CPbrbqxgWytlEYcczbCY60J8qZzSfykfPDLwMAFb4sG/pfHVhXg7eT+kHBgX3bF2YhUnOOg1puPGCpowYBJJHPvO7JGYVSx9FZ5sfM3xNmcv8ip55HQIJ7tZpV+IZofb1YcwXi3Oa5VsLrEugv07qfu5WAfnXRw91y9feu972mR58pbcgynj7/UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T9SppP2H8YKS9kqR9/++blVpAWMaV5mM8v4LZR2cxjA=; b=qJFw68khqH9DhSYXse2JbBnFdLpMyyaKu+23jPC96Vfg4l8Smv4CJ4dBl1ITenBkSfNeAVSUtB4jaujCOujNif+alow52626t3SFR3d2VqgWyg6LzuJSInxLe5Lu6viixb70IN8e3uq+tYt5hGWZPdBrZQNIjjA+YFDWyvXBGEA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:26 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:26 +0000 Subject: [PATCH v6 01/13] hw/i386: Introduce X86CPUTopoInfo to contain topology info From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:25 -0500 Message-ID: <158389400579.22020.10755767480575663831.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: SN1PR12CA0077.namprd12.prod.outlook.com (2603:10b6:802:20::48) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by SN1PR12CA0077.namprd12.prod.outlook.com (2603:10b6:802:20::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.16 via Frontend Transport; Wed, 11 Mar 2020 02:33:26 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b6c95f25-a52d-490f-9ace-08d7c56493f0 X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(30864003)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3rvr3ZwN4kyZJ8Ld8goTtDxHM97zTWivVsu9tvN9Wc1LdjDAfETsDAjpczXF0ojGnSZaT7ShPICL6EL7KkzWeqZcfsESM+Pe2do3qNvQP9JEtaTrrB4SiVzHx4eBBNnMlwMlcBgxWBXdnpzl5q2GPhj3tFz/15pvJenmeeQkwraxlAJxHHQiK+CNPwfTRs59piL979AVxtN08vzNVakzwXjBk9HBXlHx8ejhRNARxoguiwMSMySnQuwAQzFeqAY/0tPvgKJNM1eQ33ZhIlnkvvrbJvt5iNpKaPNwVH+q0c82MJ0WfkBIKnGp+QGpAACH19cg+Z4gAYM7NLBkdRBWGLdQ2RpWWw+KGbsCA6xrSmu0YyBm2uk1eZlWTS36B8kcmOiHD1k7BlKhMKfkQ/W8pBQxXDl+FbJ8htpbllmmUj3zut/8YBKkFmJzEHDymk+t X-MS-Exchange-AntiSpam-MessageData: XoFx5zEe1Qd/LdsUindOg5s9jKxtJY4dyr20zNh4ZNsNcjDgHroDUn6Qdfx9WyEPGROKpeu7eKYRKXAA78Kvvg6I9OXzBg2O4ARkZPUPCLaZ/u/nL2UpZBf26Lcu3DwgYWbNAvEmVlmXL05sy6BPzA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6c95f25-a52d-490f-9ace-08d7c56493f0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:26.7473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YS78Fw8O47DHgEvWXyOlTOZ9OyGZZp9iun3xsgzfwronOrQATAEYZTdGTT+k2W7c X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.93.41 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This is an effort to re-arrange few data structure for better readability. 1. Add X86CPUTopoInfo which will have all the topology informations required to build the cpu topology. There is no functional changes. 2. Introduce init_topo_info to initialize X86CPUTopoInfo members from X86MachineState. 3. Update x86 unit tests for new calling convention with parameter X86CPUTopoInfo There is no functional changes. Signed-off-by: Babu Moger Acked-by: Igor Mammedov --- hw/i386/pc.c | 12 ++++++------ hw/i386/x86.c | 32 ++++++++++++++++++++++++-------- include/hw/i386/topology.h | 38 ++++++++++++++++++++++++-------------- include/hw/i386/x86.h | 3 +++ tests/test-x86-cpuid.c | 43 ++++++++++++++++++++++++------------------- 5 files changed, 81 insertions(+), 47 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f52e84b2ba..662abb549d 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1513,6 +1513,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, X86MachineState *x86ms = X86_MACHINE(pcms); unsigned int smp_cores = ms->smp.cores; unsigned int smp_threads = ms->smp.threads; + X86CPUTopoInfo topo_info; if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", @@ -1520,6 +1521,8 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, return; } + init_topo_info(&topo_info, x86ms); + env->nr_dies = x86ms->smp_dies; /* @@ -1575,16 +1578,14 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, topo_ids.die_id = cpu->die_id; topo_ids.core_id = cpu->core_id; topo_ids.smt_id = cpu->thread_id; - cpu->apic_id = apicid_from_topo_ids(x86ms->smp_dies, smp_cores, - smp_threads, &topo_ids); + cpu->apic_id = apicid_from_topo_ids(&topo_info, &topo_ids); } cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx); if (!cpu_slot) { MachineState *ms = MACHINE(pcms); - x86_topo_ids_from_apicid(cpu->apic_id, x86ms->smp_dies, - smp_cores, smp_threads, &topo_ids); + x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); error_setg(errp, "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with" " APIC ID %" PRIu32 ", valid index range 0:%d", @@ -1605,8 +1606,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn() * once -smp refactoring is complete and there will be CPU private * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */ - x86_topo_ids_from_apicid(cpu->apic_id, x86ms->smp_dies, - smp_cores, smp_threads, &topo_ids); + x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) { error_setg(errp, "property socket-id: %u doesn't match set apic-id:" " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 322fb6abbc..03b8962c98 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -57,6 +57,16 @@ /* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; +inline void init_topo_info(X86CPUTopoInfo *topo_info, + const X86MachineState *x86ms) +{ + MachineState *ms = MACHINE(x86ms); + + topo_info->dies_per_pkg = x86ms->smp_dies; + topo_info->cores_per_die = ms->smp.cores; + topo_info->threads_per_core = ms->smp.threads; +} + /* * Calculates initial APIC ID for a specific CPU index * @@ -68,13 +78,14 @@ static size_t pvh_start_addr; uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms, unsigned int cpu_index) { - MachineState *ms = MACHINE(x86ms); X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms); + X86CPUTopoInfo topo_info; uint32_t correct_id; static bool warned; - correct_id = x86_apicid_from_cpu_idx(x86ms->smp_dies, ms->smp.cores, - ms->smp.threads, cpu_index); + init_topo_info(&topo_info, x86ms); + + correct_id = x86_apicid_from_cpu_idx(&topo_info, cpu_index); if (x86mc->compat_apic_id_mode) { if (cpu_index != correct_id && !warned && !qtest_enabled()) { error_report("APIC IDs set in compatibility mode, " @@ -145,19 +156,22 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx) { X86CPUTopoIDs topo_ids; X86MachineState *x86ms = X86_MACHINE(ms); + X86CPUTopoInfo topo_info; + + init_topo_info(&topo_info, x86ms); assert(idx < ms->possible_cpus->len); x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id, - x86ms->smp_dies, ms->smp.cores, - ms->smp.threads, &topo_ids); + &topo_info, &topo_ids); return topo_ids.pkg_id % ms->numa_state->num_nodes; } const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) { X86MachineState *x86ms = X86_MACHINE(ms); - int i; unsigned int max_cpus = ms->smp.max_cpus; + X86CPUTopoInfo topo_info; + int i; if (ms->possible_cpus) { /* @@ -171,6 +185,9 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + sizeof(CPUArchId) * max_cpus); ms->possible_cpus->len = max_cpus; + + init_topo_info(&topo_info, x86ms); + for (i = 0; i < ms->possible_cpus->len; i++) { X86CPUTopoIDs topo_ids; @@ -179,8 +196,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(x86ms, i); x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, - x86ms->smp_dies, ms->smp.cores, - ms->smp.threads, &topo_ids); + &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id = true; ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id; if (x86ms->smp_dies > 1) { diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index 52def68610..7ea507f376 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -52,6 +52,12 @@ typedef struct X86CPUTopoIDs { unsigned smt_id; } X86CPUTopoIDs; +typedef struct X86CPUTopoInfo { + unsigned dies_per_pkg; + unsigned cores_per_die; + unsigned threads_per_core; +} X86CPUTopoInfo; + /* Return the bit width needed for 'count' IDs */ static unsigned apicid_bitwidth_for_count(unsigned count) @@ -119,11 +125,13 @@ static inline unsigned apicid_pkg_offset(unsigned nr_dies, * * The caller must make sure core_id < nr_cores and smt_id < nr_threads. */ -static inline apic_id_t apicid_from_topo_ids(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads, +static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info, const X86CPUTopoIDs *topo_ids) { + unsigned nr_dies = topo_info->dies_per_pkg; + unsigned nr_cores = topo_info->cores_per_die; + unsigned nr_threads = topo_info->threads_per_core; + return (topo_ids->pkg_id << apicid_pkg_offset(nr_dies, nr_cores, nr_threads)) | (topo_ids->die_id << @@ -136,12 +144,14 @@ static inline apic_id_t apicid_from_topo_ids(unsigned nr_dies, /* Calculate thread/core/package IDs for a specific topology, * based on (contiguous) CPU index */ -static inline void x86_topo_ids_from_idx(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads, +static inline void x86_topo_ids_from_idx(X86CPUTopoInfo *topo_info, unsigned cpu_index, X86CPUTopoIDs *topo_ids) { + unsigned nr_dies = topo_info->dies_per_pkg; + unsigned nr_cores = topo_info->cores_per_die; + unsigned nr_threads = topo_info->threads_per_core; + topo_ids->pkg_id = cpu_index / (nr_dies * nr_cores * nr_threads); topo_ids->die_id = cpu_index / (nr_cores * nr_threads) % nr_dies; topo_ids->core_id = cpu_index / nr_threads % nr_cores; @@ -152,11 +162,13 @@ static inline void x86_topo_ids_from_idx(unsigned nr_dies, * based on APIC ID */ static inline void x86_topo_ids_from_apicid(apic_id_t apicid, - unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads, + X86CPUTopoInfo *topo_info, X86CPUTopoIDs *topo_ids) { + unsigned nr_dies = topo_info->dies_per_pkg; + unsigned nr_cores = topo_info->cores_per_die; + unsigned nr_threads = topo_info->threads_per_core; + topo_ids->smt_id = apicid & ~(0xFFFFFFFFUL << apicid_smt_width(nr_dies, nr_cores, nr_threads)); topo_ids->core_id = @@ -173,14 +185,12 @@ static inline void x86_topo_ids_from_apicid(apic_id_t apicid, * * 'cpu_index' is a sequential, contiguous ID for the CPU. */ -static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads, +static inline apic_id_t x86_apicid_from_cpu_idx(X86CPUTopoInfo *topo_info, unsigned cpu_index) { X86CPUTopoIDs topo_ids; - x86_topo_ids_from_idx(nr_dies, nr_cores, nr_threads, cpu_index, &topo_ids); - return apicid_from_topo_ids(nr_dies, nr_cores, nr_threads, &topo_ids); + x86_topo_ids_from_idx(topo_info, cpu_index, &topo_ids); + return apicid_from_topo_ids(topo_info, &topo_ids); } #endif /* HW_I386_TOPOLOGY_H */ diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 41fe37b8a3..22babcb3bb 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -21,6 +21,7 @@ #include "exec/hwaddr.h" #include "qemu/notify.h" +#include "hw/i386/topology.h" #include "hw/boards.h" #include "hw/nmi.h" #include "hw/isa/isa.h" @@ -82,6 +83,8 @@ typedef struct { #define X86_MACHINE_CLASS(class) \ OBJECT_CLASS_CHECK(X86MachineClass, class, TYPE_X86_MACHINE) +void init_topo_info(X86CPUTopoInfo *topo_info, const X86MachineState *x86ms); + uint32_t x86_cpu_apic_id_from_index(X86MachineState *pcms, unsigned int cpu_index); diff --git a/tests/test-x86-cpuid.c b/tests/test-x86-cpuid.c index 1942287f33..66b953113b 100644 --- a/tests/test-x86-cpuid.c +++ b/tests/test-x86-cpuid.c @@ -28,15 +28,18 @@ static void test_topo_bits(void) { + X86CPUTopoInfo topo_info = {0}; + /* simple tests for 1 thread per core, 1 core per die, 1 die per package */ g_assert_cmpuint(apicid_smt_width(1, 1, 1), ==, 0); g_assert_cmpuint(apicid_core_width(1, 1, 1), ==, 0); g_assert_cmpuint(apicid_die_width(1, 1, 1), ==, 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1, 0), ==, 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1, 1), ==, 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1, 2), ==, 2); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 1, 1, 3), ==, 3); + topo_info = (X86CPUTopoInfo) {1, 1, 1}; + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1); + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2); + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 3), ==, 3); /* Test field width calculation for multiple values @@ -71,36 +74,38 @@ static void test_topo_bits(void) g_assert_cmpuint(apicid_die_offset(1, 6, 3), ==, 5); g_assert_cmpuint(apicid_pkg_offset(1, 6, 3), ==, 5); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 0), ==, 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 1), ==, 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 2), ==, 2); + topo_info = (X86CPUTopoInfo) {1, 6, 3}; + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1); + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 1 * 3 + 0), ==, + topo_info = (X86CPUTopoInfo) {1, 6, 3}; + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 0), ==, (1 << 2) | 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 1 * 3 + 1), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 1), ==, (1 << 2) | 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 1 * 3 + 2), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 2), ==, (1 << 2) | 2); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 2 * 3 + 0), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 0), ==, (2 << 2) | 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 2 * 3 + 1), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 1), ==, (2 << 2) | 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 2 * 3 + 2), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2 * 3 + 2), ==, (2 << 2) | 2); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 5 * 3 + 0), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 0), ==, (5 << 2) | 0); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 5 * 3 + 1), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 1), ==, (5 << 2) | 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, 5 * 3 + 2), ==, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 5 * 3 + 2), ==, (5 << 2) | 2); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 6 * 3 + 0 * 3 + 0), ==, (1 << 5)); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 6 * 3 + 1 * 3 + 1), ==, (1 << 5) | (1 << 2) | 1); - g_assert_cmpuint(x86_apicid_from_cpu_idx(1, 6, 3, + g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 3 * 6 * 3 + 5 * 3 + 2), ==, (3 << 5) | (5 << 2) | 2); } From patchwork Wed Mar 11 02:33:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0E9C138D for ; Wed, 11 Mar 2020 02:35:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A69ED222D9 for ; Wed, 11 Mar 2020 02:35:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="aoRCB1Sz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A69ED222D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrDN-0002A2-PW for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:35:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37649) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrBi-0007yt-0O for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrBg-0006HN-2V for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:37 -0400 Received: from mail-co1nam11on2076.outbound.protection.outlook.com ([40.107.220.76]:10848 helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrBf-0006ET-OF for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QxJO+eXNSVI1aR9s5fEI/ma5qPXohy5oJGMY6oruKu839748BSGbS5rlAGdqUvbEfEDFED/2BPXDp53MvzemmrduWQLtJvUloOL1oWEQ1FUExSWIe9BTquwVJTdDKxNx7UfoFFBQiPBrhaFHJMj2ZvLSdPnS0ZjkfSHVogj3SCS6D06u0wCP0FDxK6xvnlk0ATHLVc2LqyOzN3svWOnRyg70f6WXWFx0QPMLwSFLBTv59fUpQsz+8RwmlxWhn9afXp7gpsV/ylSVwgUsltnYNJ/WEBEiOzR5iBp2jq7FPZcZj9y6xSMhtrGOq3EsYilqkYmB9Gh5HxrrV6FK/lyGMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5OlO91gkjYoVB7elpFVrJW3hmvRxzUi8KMnNWPilSGQ=; b=VoqSULf9Z+1+VtgUtsUAREPey04dyqfxwMPyL9aifaUuY61vp2T3y4OUY21ZgImUGahnelCLFb0oY/v0lWAzlHOd1LF+WgY5c7mrIb3hP3jvAmnmvDC84/q/QhBe1S4gRhcdrd1oPDjhSsPRsRtJf7nuvFaQQLgns6GU3FJrmmQSH1VydjhYRLOSSAOwk6TYuI0priaAdlLxg4GiKxT86FUahc6olgmJ/Zj6a19s2CAApumLJjoxD+XDeCDlDJYrTn9J+fxDDHAQshkGvEpQ4kdhtTIFLijG1uRbw0+UWHXcx4Wp0RYPREOPfB2VRqz/dXX2f47pmdyKvreZkcFkNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5OlO91gkjYoVB7elpFVrJW3hmvRxzUi8KMnNWPilSGQ=; b=aoRCB1Sz26S+DW9Xk8FDfCTShSL999WywZ235q6ur3aCdC75Y9fbMcqfteAPw0GU6PMRU1K9QHPES0CUxFPbdoq1mdSHwc3nqBDbqR+Nphfl2eJh+okErhsK5PGLa3nOtUqdak+8MHA2N73g8XjOjJoUsAgnXgV/ZtVrJPFTryw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:33 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:33 +0000 Subject: [PATCH v6 02/13] hw/i386: Consolidate topology functions From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:32 -0500 Message-ID: <158389401201.22020.3435322250467814934.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: SN4PR0201CA0003.namprd02.prod.outlook.com (2603:10b6:803:2b::13) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by SN4PR0201CA0003.namprd02.prod.outlook.com (2603:10b6:803:2b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Wed, 11 Mar 2020 02:33:32 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: da829074-972b-4502-5f6b-08d7c56497b8 X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(30864003)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qScCKv5WTbftEuj3K+p0CafO/SAcmZX7SAKSKZkLmzoFlVqkJr85OhjpU5UwhMJoyyIddsMUA4EmBcl1emh3S1auJNyTA17bIKEkMbVXITWplLCFkivuv6JpSMlTzr9LatJb9dGfUkwZ+Nm/XvcT/ImnYzzvXtEFgTnhlea80790pQybG5VBxiSbdcj7WwVYx9UHf4hjFvY1vD8J9vSYE/rUt8I2PThqtEocjN3by9Mj+9VV24v+YkwqB54vfn6Wg4nLQwWwxh/t/uzk2hmaeQzPb3/hRgwH82WdQ02qeXgly7lneh3hgtAPnvLDAuvfZ1O+fGOn9GkMWmsFf5TlnIbMu5xr8lFV1XBDh5JqizPL2jV8FNWjdxYfEfvKEZHZqLA7yhjvpza4skFT5XA1YSsEIW6D3NJ6is+WhZKSDwsODT3W3RlWTQwvYv3QctcH X-MS-Exchange-AntiSpam-MessageData: al5LV+j574zi5vEpl0ODk3Cg+pTvbYtnDXWbUkVWKCM947V+O42+/B1lpLC0EdJgU2GHv7mtAHn0wFBJ/NKg367onX7OR/lA4vnGYFDzLjLdfUfCzZcTe/LmdzuAIq2aMGUjfeZhh5vnxCrbsTXhMA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: da829074-972b-4502-5f6b-08d7c56497b8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:33.5764 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cxXWF1ddfZI4R8WPIpzscRwN+KFuZaQ6UghI/5N0exGigESzWdwzjXY+UnQQGb9g X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.220.76 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Now that we have all the parameters in X86CPUTopoInfo, we can just pass the structure to calculate the offsets and width. Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- include/hw/i386/topology.h | 68 +++++++++++++------------------------------ target/i386/cpu.c | 23 +++++++-------- tests/test-x86-cpuid.c | 69 +++++++++++++++++++++++++++----------------- 3 files changed, 75 insertions(+), 85 deletions(-) diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index 7ea507f376..ba52d49079 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -69,56 +69,42 @@ static unsigned apicid_bitwidth_for_count(unsigned count) /* Bit width of the SMT_ID (thread ID) field on the APIC ID */ -static inline unsigned apicid_smt_width(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_smt_width(X86CPUTopoInfo *topo_info) { - return apicid_bitwidth_for_count(nr_threads); + return apicid_bitwidth_for_count(topo_info->threads_per_core); } /* Bit width of the Core_ID field */ -static inline unsigned apicid_core_width(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_core_width(X86CPUTopoInfo *topo_info) { - return apicid_bitwidth_for_count(nr_cores); + return apicid_bitwidth_for_count(topo_info->cores_per_die); } /* Bit width of the Die_ID field */ -static inline unsigned apicid_die_width(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_die_width(X86CPUTopoInfo *topo_info) { - return apicid_bitwidth_for_count(nr_dies); + return apicid_bitwidth_for_count(topo_info->dies_per_pkg); } /* Bit offset of the Core_ID field */ -static inline unsigned apicid_core_offset(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_core_offset(X86CPUTopoInfo *topo_info) { - return apicid_smt_width(nr_dies, nr_cores, nr_threads); + return apicid_smt_width(topo_info); } /* Bit offset of the Die_ID field */ -static inline unsigned apicid_die_offset(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_die_offset(X86CPUTopoInfo *topo_info) { - return apicid_core_offset(nr_dies, nr_cores, nr_threads) + - apicid_core_width(nr_dies, nr_cores, nr_threads); + return apicid_core_offset(topo_info) + apicid_core_width(topo_info); } /* Bit offset of the Pkg_ID (socket ID) field */ -static inline unsigned apicid_pkg_offset(unsigned nr_dies, - unsigned nr_cores, - unsigned nr_threads) +static inline unsigned apicid_pkg_offset(X86CPUTopoInfo *topo_info) { - return apicid_die_offset(nr_dies, nr_cores, nr_threads) + - apicid_die_width(nr_dies, nr_cores, nr_threads); + return apicid_die_offset(topo_info) + apicid_die_width(topo_info); } /* Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID @@ -128,16 +114,9 @@ static inline unsigned apicid_pkg_offset(unsigned nr_dies, static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info, const X86CPUTopoIDs *topo_ids) { - unsigned nr_dies = topo_info->dies_per_pkg; - unsigned nr_cores = topo_info->cores_per_die; - unsigned nr_threads = topo_info->threads_per_core; - - return (topo_ids->pkg_id << - apicid_pkg_offset(nr_dies, nr_cores, nr_threads)) | - (topo_ids->die_id << - apicid_die_offset(nr_dies, nr_cores, nr_threads)) | - (topo_ids->core_id << - apicid_core_offset(nr_dies, nr_cores, nr_threads)) | + return (topo_ids->pkg_id << apicid_pkg_offset(topo_info)) | + (topo_ids->die_id << apicid_die_offset(topo_info)) | + (topo_ids->core_id << apicid_core_offset(topo_info)) | topo_ids->smt_id; } @@ -165,20 +144,15 @@ static inline void x86_topo_ids_from_apicid(apic_id_t apicid, X86CPUTopoInfo *topo_info, X86CPUTopoIDs *topo_ids) { - unsigned nr_dies = topo_info->dies_per_pkg; - unsigned nr_cores = topo_info->cores_per_die; - unsigned nr_threads = topo_info->threads_per_core; - topo_ids->smt_id = apicid & - ~(0xFFFFFFFFUL << apicid_smt_width(nr_dies, nr_cores, nr_threads)); + ~(0xFFFFFFFFUL << apicid_smt_width(topo_info)); topo_ids->core_id = - (apicid >> apicid_core_offset(nr_dies, nr_cores, nr_threads)) & - ~(0xFFFFFFFFUL << apicid_core_width(nr_dies, nr_cores, nr_threads)); + (apicid >> apicid_core_offset(topo_info)) & + ~(0xFFFFFFFFUL << apicid_core_width(topo_info)); topo_ids->die_id = - (apicid >> apicid_die_offset(nr_dies, nr_cores, nr_threads)) & - ~(0xFFFFFFFFUL << apicid_die_width(nr_dies, nr_cores, nr_threads)); - topo_ids->pkg_id = - apicid >> apicid_pkg_offset(nr_dies, nr_cores, nr_threads); + (apicid >> apicid_die_offset(topo_info)) & + ~(0xFFFFFFFFUL << apicid_die_width(topo_info)); + topo_ids->pkg_id = apicid >> apicid_pkg_offset(topo_info); } /* Make APIC ID for the CPU 'cpu_index' diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 350b51b346..6df3127fd7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5497,6 +5497,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t die_offset; uint32_t limit; uint32_t signature[3]; + X86CPUTopoInfo topo_info; + + topo_info.dies_per_pkg = env->nr_dies; + topo_info.cores_per_die = cs->nr_cores; + topo_info.threads_per_core = cs->nr_threads; /* Calculate & apply limits for different index ranges */ if (index >= 0xC0000000) { @@ -5583,8 +5588,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - die_offset = apicid_die_offset(env->nr_dies, - cs->nr_cores, cs->nr_threads); + die_offset = apicid_die_offset(&topo_info); if (cpu->enable_l3_cache) { encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache, (1 << die_offset), cs->nr_cores, @@ -5675,14 +5679,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, switch (count) { case 0: - *eax = apicid_core_offset(env->nr_dies, - cs->nr_cores, cs->nr_threads); + *eax = apicid_core_offset(&topo_info); *ebx = cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_SMT; break; case 1: - *eax = apicid_pkg_offset(env->nr_dies, - cs->nr_cores, cs->nr_threads); + *eax = apicid_pkg_offset(&topo_info); *ebx = cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_CORE; break; @@ -5706,20 +5708,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *edx = cpu->apic_id; switch (count) { case 0: - *eax = apicid_core_offset(env->nr_dies, cs->nr_cores, - cs->nr_threads); + *eax = apicid_core_offset(&topo_info); *ebx = cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_SMT; break; case 1: - *eax = apicid_die_offset(env->nr_dies, cs->nr_cores, - cs->nr_threads); + *eax = apicid_die_offset(&topo_info); *ebx = cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_CORE; break; case 2: - *eax = apicid_pkg_offset(env->nr_dies, cs->nr_cores, - cs->nr_threads); + *eax = apicid_pkg_offset(&topo_info); *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_DIE; break; diff --git a/tests/test-x86-cpuid.c b/tests/test-x86-cpuid.c index 66b953113b..bfabc0403a 100644 --- a/tests/test-x86-cpuid.c +++ b/tests/test-x86-cpuid.c @@ -31,9 +31,10 @@ static void test_topo_bits(void) X86CPUTopoInfo topo_info = {0}; /* simple tests for 1 thread per core, 1 core per die, 1 die per package */ - g_assert_cmpuint(apicid_smt_width(1, 1, 1), ==, 0); - g_assert_cmpuint(apicid_core_width(1, 1, 1), ==, 0); - g_assert_cmpuint(apicid_die_width(1, 1, 1), ==, 0); + topo_info = (X86CPUTopoInfo) {1, 1, 1}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 0); + g_assert_cmpuint(apicid_core_width(&topo_info), ==, 0); + g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0); topo_info = (X86CPUTopoInfo) {1, 1, 1}; g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); @@ -44,35 +45,51 @@ static void test_topo_bits(void) /* Test field width calculation for multiple values */ - g_assert_cmpuint(apicid_smt_width(1, 1, 2), ==, 1); - g_assert_cmpuint(apicid_smt_width(1, 1, 3), ==, 2); - g_assert_cmpuint(apicid_smt_width(1, 1, 4), ==, 2); - - g_assert_cmpuint(apicid_smt_width(1, 1, 14), ==, 4); - g_assert_cmpuint(apicid_smt_width(1, 1, 15), ==, 4); - g_assert_cmpuint(apicid_smt_width(1, 1, 16), ==, 4); - g_assert_cmpuint(apicid_smt_width(1, 1, 17), ==, 5); - - - g_assert_cmpuint(apicid_core_width(1, 30, 2), ==, 5); - g_assert_cmpuint(apicid_core_width(1, 31, 2), ==, 5); - g_assert_cmpuint(apicid_core_width(1, 32, 2), ==, 5); - g_assert_cmpuint(apicid_core_width(1, 33, 2), ==, 6); - - g_assert_cmpuint(apicid_die_width(1, 30, 2), ==, 0); - g_assert_cmpuint(apicid_die_width(2, 30, 2), ==, 1); - g_assert_cmpuint(apicid_die_width(3, 30, 2), ==, 2); - g_assert_cmpuint(apicid_die_width(4, 30, 2), ==, 2); + topo_info = (X86CPUTopoInfo) {1, 1, 2}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 1); + topo_info = (X86CPUTopoInfo) {1, 1, 3}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); + topo_info = (X86CPUTopoInfo) {1, 1, 4}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); + + topo_info = (X86CPUTopoInfo) {1, 1, 14}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); + topo_info = (X86CPUTopoInfo) {1, 1, 15}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); + topo_info = (X86CPUTopoInfo) {1, 1, 16}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); + topo_info = (X86CPUTopoInfo) {1, 1, 17}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 5); + + + topo_info = (X86CPUTopoInfo) {1, 30, 2}; + g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); + topo_info = (X86CPUTopoInfo) {1, 31, 2}; + g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); + topo_info = (X86CPUTopoInfo) {1, 32, 2}; + g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); + topo_info = (X86CPUTopoInfo) {1, 33, 2}; + g_assert_cmpuint(apicid_core_width(&topo_info), ==, 6); + + topo_info = (X86CPUTopoInfo) {1, 30, 2}; + g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0); + topo_info = (X86CPUTopoInfo) {2, 30, 2}; + g_assert_cmpuint(apicid_die_width(&topo_info), ==, 1); + topo_info = (X86CPUTopoInfo) {3, 30, 2}; + g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2); + topo_info = (X86CPUTopoInfo) {4, 30, 2}; + g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2); /* build a weird topology and see if IDs are calculated correctly */ /* This will use 2 bits for thread ID and 3 bits for core ID */ - g_assert_cmpuint(apicid_smt_width(1, 6, 3), ==, 2); - g_assert_cmpuint(apicid_core_offset(1, 6, 3), ==, 2); - g_assert_cmpuint(apicid_die_offset(1, 6, 3), ==, 5); - g_assert_cmpuint(apicid_pkg_offset(1, 6, 3), ==, 5); + topo_info = (X86CPUTopoInfo) {1, 6, 3}; + g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); + g_assert_cmpuint(apicid_core_offset(&topo_info), ==, 2); + g_assert_cmpuint(apicid_die_offset(&topo_info), ==, 5); + g_assert_cmpuint(apicid_pkg_offset(&topo_info), ==, 5); topo_info = (X86CPUTopoInfo) {1, 6, 3}; g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); From patchwork Wed Mar 11 02:33:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DAD5D138D for ; Wed, 11 Mar 2020 02:36:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B195321927 for ; Wed, 11 Mar 2020 02:36:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="rPXKvIrG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B195321927 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrER-0004Uf-TU for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:36:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37735) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrBm-00088f-PH for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrBl-0006Z3-Jk for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:42 -0400 Received: from mail-dm6nam10on2061.outbound.protection.outlook.com ([40.107.93.61]:24451 helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrBl-0006We-Dd for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hyDjX/3YmqKiUPbAxIEL5j9kCWyBGmIPLeGuIopFIaWzpma/9MkhICT9boEW3LamIaBTTtNmKaNXfUrbezNSZx9XZ6N3gsW3gZSmgshCpbr2I2PfmfSHcrbFpu0W/h7zQOnjK2w5gjnUvAmyvB7zFizeLXuGSvc/19pKNEYdQepnDxpKUdqt6QbDWjIsJ5xSv9NyBYy9TQfi5X41sTwh22GWAhEmUPjbn+q9PFLYUIGTK+otQCRAt+OzgJR+8/Unyj2NPshESxA79UiCeCISx79dJee2UznvmnED3mqY4e3Idiwg8wyEBEy4Fh2jbx+XAREPmb7vzW2hvBWVTTwtvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r/CNt1p8YBYKlVd8s/6CN1lFk5MvgDBs7vZdCxCOBWE=; b=Jful+5dVnju/Kj5OU1Go/lxDM+Fz6CbOeB6+CnrX/1Yr+CjgedXvdFnFqIZ3z00+ke8D89RbDqtErwnPhWrye9pW7GI2K24cPKXkvklwx0qZV9mn8XhzgD0qnjH59vKEotnZE6BSXOx5hvJq+pzMEkSufhLuZAWSCisy1Cal6ONVwrJ6lv0y5l45r1FZGR0ZuI02LG4x9O6OED273YuB3yB/HeXf/Bl1juK8nfX1NeANb+blTG8JTEE4zhVAOgxa376tK/BvqQnXPAkWs+8XoslPm/lIuZhQK9gImrIvJmdpW6L03LIjzQGPPjtSO9zwacSRX9f1BW0YzRBMmgxijg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r/CNt1p8YBYKlVd8s/6CN1lFk5MvgDBs7vZdCxCOBWE=; b=rPXKvIrGfRM+0eaaiRXuBnqSIrjMny1ngTfo1HsAzjosLWezpH3cAAYynT0ow8JZHkKhB0ku8dpnvenXFuj3i5l17O+hNINfVolRZjhl3m+Nm5h+UtcFKWIw760gw1Qztuin3wAUyTUnWnafbN6vVNXR8aDPAzM9xQ1/JpPmuas= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:39 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:39 +0000 Subject: [PATCH v6 03/13] machine: Add SMP Sockets in CpuTopology From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:38 -0500 Message-ID: <158389401871.22020.15275663805151094425.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: SN1PR12CA0044.namprd12.prod.outlook.com (2603:10b6:802:20::15) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by SN1PR12CA0044.namprd12.prod.outlook.com (2603:10b6:802:20::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.16 via Frontend Transport; Wed, 11 Mar 2020 02:33:39 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bbd869b3-e4b0-4114-e88d-08d7c5649bab X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: riF2bWqFboW/CJZ9aD+I7GWG8et87o6AHXAv5wXVYgJHgH7HCDR/PLSIJnT9UPgX/ozO6YvJkmbcSTJmrWX7cHr+qjR8/qMPZkjkc2WlFHAcAx6k/1/s3cuAMozJ7LRu9HpKOc389TUuOlwoDhr0uS69r+MVPaTD4EGX5saK84DtHFSi2dT9iOsDBgltlpot/V6Pk6r+Sv8M+MJgSL1SNFC3Otxu+QHjqgjfuCYBMVMPPcfiMbMZKclg6Rbx9ZBB4Gz2JcRukl+4R+FJcQnhlaJdgEClxXKChY0+qoj+fwl1TuiNDBPpgHYv6o991Yn0H1wKd2SIf3gF2/SFByJ1AW/iYVSt3To/U2f4XV0RYB/4UEP4u1FiVZoRffUUm6kE1SzEvlk7DJXL0klRUUvPOMG9t3o8+RyTM3WXkh5/hECHplIsBI2qj67N4PmM5d17 X-MS-Exchange-AntiSpam-MessageData: 9+4ufrZSFZ3ZOZ/Fzi59t6LJDMrtpMt+MlBHx7Nd53TGZi9hmO1ob1ZJlXb4fF5rI+pP3H6YvMNbjmS7wGtxL91rY307Mw7qBI/Umsimy09j8EW9hASzeg7b3grEvPAW/5MiiF7xOifdnTTMIDXsRw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbd869b3-e4b0-4114-e88d-08d7c5649bab X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:39.6749 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: d7vwMaP85INcXVHKb1o5OcnSLuaEHSciy2IQm/tIAi2MEfB4y2abbAvlcaFcqmz0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.93.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Store the smp sockets in CpuTopology. The socket information required to build the apic id in EPYC mode. Right now socket information is not passed to down when decoding the apic id. Add the socket information here. Signed-off-by: Babu Moger Reviewed-by: Eduardo Habkost Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/core/machine.c | 1 + hw/i386/pc.c | 1 + include/hw/boards.h | 2 ++ softmmu/vl.c | 1 + 4 files changed, 5 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4778bc6b08..b958cd1b99 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -757,6 +757,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts) ms->smp.cpus = cpus; ms->smp.cores = cores; ms->smp.threads = threads; + ms->smp.sockets = sockets; } if (ms->smp.cpus > 1) { diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 662abb549d..05e7f1090f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -781,6 +781,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) ms->smp.cpus = cpus; ms->smp.cores = cores; ms->smp.threads = threads; + ms->smp.sockets = sockets; x86ms->smp_dies = dies; } diff --git a/include/hw/boards.h b/include/hw/boards.h index 9bc42dfb22..d01056286a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -236,12 +236,14 @@ typedef struct DeviceMemoryState { * @cpus: the number of present logical processors on the machine * @cores: the number of cores in one package * @threads: the number of threads in one core + * @sockets: the number of sockets on the machine * @max_cpus: the maximum number of logical processors on the machine */ typedef struct CpuTopology { unsigned int cpus; unsigned int cores; unsigned int threads; + unsigned int sockets; unsigned int max_cpus; } CpuTopology; diff --git a/softmmu/vl.c b/softmmu/vl.c index ff2685dff8..dadb798ac7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -3935,6 +3935,7 @@ void qemu_init(int argc, char **argv, char **envp) current_machine->smp.max_cpus = machine_class->default_cpus; current_machine->smp.cores = 1; current_machine->smp.threads = 1; + current_machine->smp.sockets = 1; machine_class->smp_parse(current_machine, qemu_opts_find(qemu_find_opts("smp-opts"), NULL)); From patchwork Wed Mar 11 02:33:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07A11138D for ; Wed, 11 Mar 2020 02:37:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D259621927 for ; Wed, 11 Mar 2020 02:37:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="TBlYy0xs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D259621927 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrFp-0008Hc-06 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:37:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37823) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrBt-0008LO-5x for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrBs-0006sm-57 for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:49 -0400 Received: from mail-co1nam11on2074.outbound.protection.outlook.com ([40.107.220.74]:34631 helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrBr-0006pV-T3 for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mCIbRqf7lcmjIpMilT0YK3U5YUEDZj8OJzCrec878tPBhAGgqvOfCxqvvUcqGeYVp+LQ7KEhIDygdULVIcNd4qXjccZUHPfACBqwO7KBsTB+4IYatY1rhoxnzDNuBHDZwLRasNQ8XW7bwlIdI3pXZHhBp/rqRE2BmR1Cy8c2CSUvp+Iyp2CPUDMNKqh/Ihl/G/gzuEr51KQIvwZPO7WL5ayGLhBl7nZfLYE87OgjreDmA18Wu5SZZxypkWEIOmnYa2PRLwN35seX/3Hff/kafwVSYmeWNVHPiwouVDC7j1mFtbLW7Qy69V2sodhKlkfr9KoTIFyd4z7TcL9oADjFWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WUEACMzjxBBMOrvSY6IyyV48F4VTD6Ww42kLfwPUHHE=; b=iqPvjXd5JFER5yBw+b6tr3jj5uSjAj8542YLG02o5rzOqnVAozkKbh2vcMgIz2gxAPhwCxeogmo7lHqsX8SQtzIoeEScLxSps6JjHfgVo4GOJRWVjloJxhiylAGxdrXdMe6vD5UhH2N8yaabii/GgqbWsO5KYQRhArUZiH7uwNukuYU0/6RRGLR7mmW0BH/1tWJQgXLAJlZA/vXWbGzsAo+REv7D3hpDBg3QZzQkW+tzg/m4KvO0wzz9/HNicAYsAZVJ+KOP8rmU+4OIZvQrAYQFtCR0mp171JI4IUYyoHt+PekBomu0UX3S6FLnOm/Hgt+Hk1JNXgqvlTMu2V9Cww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WUEACMzjxBBMOrvSY6IyyV48F4VTD6Ww42kLfwPUHHE=; b=TBlYy0xsCuDoEvJyqUN4Y+Y3PzLZ/BJP2F7OM67e6sb9uXy0dfD/2Vq6fSk5Ug0IvN0DK548T00EV7XCjwJCPUFfK9v2sEfXnQ2ugQBaOBZqA/3CNMAhqK3cS6xI33ebYSYcMuw65scQVtUXGoimxVVGuXkgf35/GOX3VZXhsOY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:46 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:46 +0000 Subject: [PATCH v6 04/13] hw/i386: Remove unnecessary initialization in x86_cpu_new From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:44 -0500 Message-ID: <158389402482.22020.17707923191340692971.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: SN4PR0501CA0136.namprd05.prod.outlook.com (2603:10b6:803:2c::14) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by SN4PR0501CA0136.namprd05.prod.outlook.com (2603:10b6:803:2c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2814.6 via Frontend Transport; Wed, 11 Mar 2020 02:33:45 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3f2e032a-2afe-44e7-0954-08d7c5649f65 X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(4744005)(956004)(8936002)(316002)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rd8lh+q2Qp5fkffoE1lG4Q0wX95cqGQcznCi/PwJRpI6d/xb856ku9ekdf/0Um2Cv7gLzzRZQlciaJ308fJCq7ovV24qjsVg/qXCN4qMiBTysvK77QSE9aOH9Etdx+uysEGyoV9F/nOFQCJzSAZnPfgssQ9ZbdOxCHD2miJ6p81uDx96oijVME1iobUFuXI8Z+XFJRcVJZyUwJ1n03W5pdkVi0k811fkgtiPtekJOy6FRCwVBy1gnd3feZU1C8n8+05copMJ+fxqeH/MZ0kPsO3f4jHGUQRSFJTGyqRVNymu+hidqY2F3KBCBQ5ducMS7prEKOAxuB4L+zcKvrlXB5GRqjzFrrg6nej97OSLw8wCugz+3PnO7XWN4wo0pzsIwg1sYBo8JLqwdRY8cTTeZhf2nBBXX3SmymqkajuPJTdWwoE+cT7F5Mw4A+c4gbby X-MS-Exchange-AntiSpam-MessageData: Xa3b9l9Q13fr1lptiP9txQTYAiLJ2rOXdiGhqOwcWAICvnU/rav03oUKhxHyHPu1Cfu4xa9Jn8DHf+PFE7rWWH2jZ4TOcxZHfNJDmifoGKKmGaNGRycmqfx2Pa+hrBtyxkHNnoqMcMlo1dK02FcY6w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f2e032a-2afe-44e7-0954-08d7c5649f65 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:45.9274 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /3IHy9T7p8UNa0apAD4QVWBPdY8edd0DnrZyUjlGJvXFJvt30NFEFdqA2AcuNYpW X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.220.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The function pc_cpu_pre_plug takes care of initialization of CPUX86State. So, remove the initialization here. Suggested-by: Igor Mammedov Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/i386/x86.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 03b8962c98..79badcc4ec 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -103,13 +103,9 @@ void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp) { Object *cpu = NULL; Error *local_err = NULL; - CPUX86State *env = NULL; cpu = object_new(MACHINE(x86ms)->cpu_type); - env = &X86_CPU(cpu)->env; - env->nr_dies = x86ms->smp_dies; - object_property_set_uint(cpu, apic_id, "apic-id", &local_err); object_property_set_bool(cpu, true, "realized", &local_err); From patchwork Wed Mar 11 02:33:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCB6F138D for ; Wed, 11 Mar 2020 02:39:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 734F420637 for ; Wed, 11 Mar 2020 02:39:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="RrJ7nOOm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 734F420637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrHX-0002su-Ie for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:39:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37923) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrC9-00009D-5z for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrC3-000733-Nc for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:01 -0400 Received: from mail-co1nam11on2053.outbound.protection.outlook.com ([40.107.220.53]:6137 helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrC3-0006zv-Bg for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:33:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YcHhAKOGoZaDsWrJtikMVx+hziGHuTd20E+47KstwhsYUiLI0mSR5PKkHDk9cvmgb7CqgLVIJPIVT/J7Ghb4PVd4UQ9/Qku14yQ8xk2YnDHDVv1gRJ8b9D4cAOK/E03I3z222lmzTnvXe3KfrKC7Cy41eFYANP/mbKDwB6Qr1zD/eMcfT6CfKBZ1PxUCSsJGKCm8o2/GHoz/lDHvi/YRa+p9y1FmZp59yHiCu0225lbWFshfWq3aLE+s7Iw4EL+rZmri6mfXCm1KMCk5gs2EHJSFCZOzZfGHMMcZBVDN5W8JPl6PvNMPn9t9rftTHk5eTj/EawcFwZZXswNrsjwHpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U38N/j8ekYDyGtvJbFj2sFEYNq03EM54VlFz8se/kEQ=; b=L+8WHn1LkQQXZZTpWcxsC7dOvuQ6JEMgnjo/3KLOVOaF7SIlYDvyIQp4FcMtPL2+YAp6FpxVwpw5hpafD04bynaFqRqpash7mR7rwaW4gAK4UOu5lImhatEO7zynZdpWVq1/Pk6VjrKuApIxC+fwBQ8GBTYymmbIZKxJZ3fJPCOkA0R88oHm7/kfM+glxznirFJcNfOjQKqEXAlTCrkQsREfnSc1K4fz5YSNl04prGJOjL58I5UyiDUrRVc2m7shBWAqUwTbQ6zmD6bg9yIRhikBMMAZbRiBzB/szbXKR9UY4ZeIglwobMLXxXMu/8ZYB/VhtdpDJ46VdHD982VD7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U38N/j8ekYDyGtvJbFj2sFEYNq03EM54VlFz8se/kEQ=; b=RrJ7nOOmgH8kxfwGSJ93x7T+UCJOgxKIW6mloz4rDpb84XUcrAYLyq2vaTDcQdILI0ygBXoeq+6kK7Q8mYLBf6I4CTlHowLCxe6oPP7cgukjkdHlNViabR085qORQWgtFVgbBn6wFJ55QxLBl8r+Hajt7LrAyovqTdDepSWHqAY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:53 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:53 +0000 Subject: [PATCH v6 05/13] hw/i386: Update structures to save the number of nodes per package From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:51 -0500 Message-ID: <158389403107.22020.18234003063551182953.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR2001CA0010.namprd20.prod.outlook.com (2603:10b6:4:16::20) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR2001CA0010.namprd20.prod.outlook.com (2603:10b6:4:16::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Wed, 11 Mar 2020 02:33:52 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 115e1910-ddca-4a08-898e-08d7c564a399 X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(15650500001)(16526019)(2906002)(186003)(81156014)(26005)(60793003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4fx610BuEW8cOqYOqAO39FTmfHQb8bF15djN3leVFiLBIzsjX5k58qbWsPry/+U2shNqsmPPcoejGT6u73yNvzHWXjFxNehau4VQQiMBchkbbcRDvHi+hHnoBKsMXDjjEzcUh9TPWd4TNUlrmwBdc+M5Ec7IuqyRQ8DImLtvsClHPveV79mvvidk7w0XNVcqlcX5/WjdC5b3x+XCAAusvIr1w5zgqpROZEWI1csC56Cuj/6ZZN1KU+Sm5uzaQzrEHrOzA6J5QN+9VdnD1poyNJsCTGdv11gi0/vvPh6lkImAW15aw7ksHnGMhIZhzcMOtmuOLUU9IKmyXOdYKiN3HevfFLiWp+oNOCYkPhRI5K9TFK7nRrRtrrsCqO7KXFW4F3vnG74HmimMyFHJfxAuhdpaqRbTA9rEE7y9U/FvldkFatkh1IXxilM/UOr+C5oRoKsp2vlcmcgRwfm4CsyHxv5Rb5AnQlk9HS5z0bPrfLTY9jzAMlK9uar6mAqYNtv5 X-MS-Exchange-AntiSpam-MessageData: q5iB7I8JbEZEmzoaQMEgRBffLMgrCAKG8Q7UFo5J2AIokNF56ztDEjbn9+3kr6m+Cw5sSHk9E07Mk621b+gynvGsFcytiNsAwQWEKyvtVrbq60lJ6QxHLYfRxoJGtd1SeiKBOpM3JKtxnvWboS97vQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 115e1910-ddca-4a08-898e-08d7c564a399 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:52.9963 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: D2Vye1Dsn9W/LN4etWZBL+ZSmsLhKYOeHgwuQgaoEeZ0QcGifhhv984vxFNcPSxL X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.220.53 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Update structures X86CPUTopoIDs and CPUX86State to hold the number of nodes per package. This is required to build EPYC mode topology. Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/i386/pc.c | 1 + hw/i386/x86.c | 1 + include/hw/i386/topology.h | 1 + target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + tests/test-x86-cpuid.c | 40 ++++++++++++++++++++-------------------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 05e7f1090f..ee89fcd1c3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1525,6 +1525,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, init_topo_info(&topo_info, x86ms); env->nr_dies = x86ms->smp_dies; + env->nr_nodes = topo_info.nodes_per_pkg; /* * If APIC ID is not set, diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 79badcc4ec..929b80c9c7 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -62,6 +62,7 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info, { MachineState *ms = MACHINE(x86ms); + topo_info->nodes_per_pkg = ms->numa_state->num_nodes / ms->smp.sockets; topo_info->dies_per_pkg = x86ms->smp_dies; topo_info->cores_per_die = ms->smp.cores; topo_info->threads_per_core = ms->smp.threads; diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index ba52d49079..04f01e2a09 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -53,6 +53,7 @@ typedef struct X86CPUTopoIDs { } X86CPUTopoIDs; typedef struct X86CPUTopoInfo { + unsigned nodes_per_pkg; unsigned dies_per_pkg; unsigned cores_per_die; unsigned threads_per_core; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6df3127fd7..2e5be37b21 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6957,6 +6957,7 @@ static void x86_cpu_initfn(Object *obj) FeatureWord w; env->nr_dies = 1; + env->nr_nodes = 1; cpu_set_cpustate_pointers(cpu); object_property_add(obj, "family", "int", diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 68b186d258..7e9e963d78 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1609,6 +1609,7 @@ typedef struct CPUX86State { TPRAccess tpr_access_type; unsigned nr_dies; + unsigned nr_nodes; } CPUX86State; struct kvm_msrs; diff --git a/tests/test-x86-cpuid.c b/tests/test-x86-cpuid.c index bfabc0403a..049030a50e 100644 --- a/tests/test-x86-cpuid.c +++ b/tests/test-x86-cpuid.c @@ -31,12 +31,12 @@ static void test_topo_bits(void) X86CPUTopoInfo topo_info = {0}; /* simple tests for 1 thread per core, 1 core per die, 1 die per package */ - topo_info = (X86CPUTopoInfo) {1, 1, 1}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 1}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 0); g_assert_cmpuint(apicid_core_width(&topo_info), ==, 0); g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0); - topo_info = (X86CPUTopoInfo) {1, 1, 1}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 1}; g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1); g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2); @@ -45,39 +45,39 @@ static void test_topo_bits(void) /* Test field width calculation for multiple values */ - topo_info = (X86CPUTopoInfo) {1, 1, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 2}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 1); - topo_info = (X86CPUTopoInfo) {1, 1, 3}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 3}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); - topo_info = (X86CPUTopoInfo) {1, 1, 4}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 4}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); - topo_info = (X86CPUTopoInfo) {1, 1, 14}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 14}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); - topo_info = (X86CPUTopoInfo) {1, 1, 15}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 15}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); - topo_info = (X86CPUTopoInfo) {1, 1, 16}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 16}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 4); - topo_info = (X86CPUTopoInfo) {1, 1, 17}; + topo_info = (X86CPUTopoInfo) {0, 1, 1, 17}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 5); - topo_info = (X86CPUTopoInfo) {1, 30, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 30, 2}; g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); - topo_info = (X86CPUTopoInfo) {1, 31, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 31, 2}; g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); - topo_info = (X86CPUTopoInfo) {1, 32, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 32, 2}; g_assert_cmpuint(apicid_core_width(&topo_info), ==, 5); - topo_info = (X86CPUTopoInfo) {1, 33, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 33, 2}; g_assert_cmpuint(apicid_core_width(&topo_info), ==, 6); - topo_info = (X86CPUTopoInfo) {1, 30, 2}; + topo_info = (X86CPUTopoInfo) {0, 1, 30, 2}; g_assert_cmpuint(apicid_die_width(&topo_info), ==, 0); - topo_info = (X86CPUTopoInfo) {2, 30, 2}; + topo_info = (X86CPUTopoInfo) {0, 2, 30, 2}; g_assert_cmpuint(apicid_die_width(&topo_info), ==, 1); - topo_info = (X86CPUTopoInfo) {3, 30, 2}; + topo_info = (X86CPUTopoInfo) {0, 3, 30, 2}; g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2); - topo_info = (X86CPUTopoInfo) {4, 30, 2}; + topo_info = (X86CPUTopoInfo) {0, 4, 30, 2}; g_assert_cmpuint(apicid_die_width(&topo_info), ==, 2); /* build a weird topology and see if IDs are calculated correctly @@ -85,18 +85,18 @@ static void test_topo_bits(void) /* This will use 2 bits for thread ID and 3 bits for core ID */ - topo_info = (X86CPUTopoInfo) {1, 6, 3}; + topo_info = (X86CPUTopoInfo) {0, 1, 6, 3}; g_assert_cmpuint(apicid_smt_width(&topo_info), ==, 2); g_assert_cmpuint(apicid_core_offset(&topo_info), ==, 2); g_assert_cmpuint(apicid_die_offset(&topo_info), ==, 5); g_assert_cmpuint(apicid_pkg_offset(&topo_info), ==, 5); - topo_info = (X86CPUTopoInfo) {1, 6, 3}; + topo_info = (X86CPUTopoInfo) {0, 1, 6, 3}; g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 0), ==, 0); g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1), ==, 1); g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 2), ==, 2); - topo_info = (X86CPUTopoInfo) {1, 6, 3}; + topo_info = (X86CPUTopoInfo) {0, 1, 6, 3}; g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 0), ==, (1 << 2) | 0); g_assert_cmpuint(x86_apicid_from_cpu_idx(&topo_info, 1 * 3 + 1), ==, From patchwork Wed Mar 11 02:33:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0032614B7 for ; Wed, 11 Mar 2020 02:37:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CB0EF20637 for ; Wed, 11 Mar 2020 02:37:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="mFvRkMSd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB0EF20637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrEx-0005xQ-Td for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:36:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37958) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCA-0000CH-GR for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrC9-00075v-Fg for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:06 -0400 Received: from mail-dm6nam10on20615.outbound.protection.outlook.com ([2a01:111:f400:7e88::615]:19297 helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrC9-000743-9f for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pw+E3ptXoHYWYx9pEu3kl03MoRAAubVmkzL6RzYFVrWtsZDJBo5YSXUM/gVfeTSpeP1xsJ9yZsfNWpivsM7iNsH1Wzr0MrcLHsj7BX0n2+DcMn4ccJSOeo4Pop74xNRSm3gI1FsWkL26RwTvgxKMS5dhYYOzOKAtQJEEaF/TkcAC8qeuSphlVk7bFHA0MyFT2GuuDytFNLff2LA8suXXwDhwMTxv2/Ad01ZWcxDyVdY0bYuMGyYDrNdM7KDUDLAtsczcD+Xh22O1sdwgUvJZUVvtVxlhUCm36V/RYZ2vxE16VEDrq7cZIGg2rCYf56BjzDekuODI6Xpad5z1/moEbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v7oU+Qnipw9z5TbfEZvYAYu9y74tQIsRx/5rqU6s+0c=; b=civskOQBD59L8Eezu+2Zd66O73lZaPzp9rp3OLY57yTMjWMDW78j4Icg4/1DEaItZOAIsxqgc/FO+ZVkIE2q+FzWiABvA+XpI9lps5+pIYPMwo48yD7gk/ouE5uPi7UbLZyqH9TusR3TffLFd61aI5+GSTr2NmXSEy4s96MUoBPV9k50MAorSSvkCrwebcT/h+IoqfnV2VHJ01OvE+A4OCjjvuvU9IKTLmEiweMY+2P6K49HaLjsOPJ+5tyMecTFQ8+MV+truhQO7WGZl4vQr8gzkktjLiW4pX9gUaiDvMnYQYMgbtREDAxqQOxmu9QCHfvmd9oMBUMfi/WysYHAcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v7oU+Qnipw9z5TbfEZvYAYu9y74tQIsRx/5rqU6s+0c=; b=mFvRkMSdsBPeiMwEeu6EYMquXLzld0/UIcTda7f48BCA75CFV+LvmoIeiZi/5Y2+W57Hou8rVeB5Udz/qIoMyS5cCY7GfA8gqxukNzCpTm3e9GLMnJ5SDpl0rpz4G44t8vzGSdCUdw7tZCKntGOIF7uDrlmpspMTYyMqCE2ZvBs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:33:59 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:33:59 +0000 Subject: [PATCH v6 06/13] hw/i386: Rename apicid_from_topo_ids to x86_apicid_from_topo_ids From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:33:58 -0500 Message-ID: <158389403816.22020.5329773045205545769.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM3PR12CA0083.namprd12.prod.outlook.com (2603:10b6:0:57::27) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM3PR12CA0083.namprd12.prod.outlook.com (2603:10b6:0:57::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.16 via Frontend Transport; Wed, 11 Mar 2020 02:33:59 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 01e761a6-91d4-42e6-89c3-08d7c564a7af X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:534; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(8676002)(5660300002)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dql0Qxiv/tT1ZeFEVSSrvM5jqDh0F3j0L/Z5/3q5W81NnI9zIkxq1NOr4tSS2Cse7zS8WlWP3avEYNJkWOgr0x7R/LmIfQ2H4+LsX3BIDOFOXxGZX9HE/3DoyGhG3v/vKT7SHUCe/LR8Z4B4UcK/2iRZVKf1RuUq1CgaMX4TJZnPRDaiGm/6ptk46NeZKpEIJQd8pqte4R9rbOxglkGg9SOWLS9PtWM+MDwd2F4h/RTFnFhlPQ3mB62ETZPIXPE6iDO/JhxdKStUlA0GPGmJtiLvOwIyEcnpWWAIq1G7HW8anEzxhCjg6PLO734EZzvtfdh2+mmyFKbskH9h6kDzviTUDajWdhuA2y2N1DrJijHsoi8hKqLiKK4woJLkWs0OtcOws2nDRxd+FuXqIlAPlYJVpuW7wYSukVFI2MAzVd423TYKYx3YXWE2hmTrxgw4 X-MS-Exchange-AntiSpam-MessageData: iKkvBfxR7kSJ/RT6RtX0Sd4iS/xJuolmlcgZApv2KfOHZmc33vkNbEw3HNz2mlByffgPLkTN1fZ6oSeGdFXK3TEVDM3sMPZXSIi0OGtt2MQGBOyrgA0RwScGx8UKhqczlIh13Yy3DkSLhIVaQdC9rw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01e761a6-91d4-42e6-89c3-08d7c564a7af X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:33:59.8664 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HxPoXqezHZHaRcqjLimUdc6MZto/3HvacLy6K6GAR5zeOpF3WqtOWPRzvbEkk7h/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:7e88::615 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" For consistancy rename apicid_from_topo_ids to x86_apicid_from_topo_ids. No functional change. Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/i386/pc.c | 2 +- include/hw/i386/topology.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ee89fcd1c3..98ee763f68 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1580,7 +1580,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, topo_ids.die_id = cpu->die_id; topo_ids.core_id = cpu->core_id; topo_ids.smt_id = cpu->thread_id; - cpu->apic_id = apicid_from_topo_ids(&topo_info, &topo_ids); + cpu->apic_id = x86_apicid_from_topo_ids(&topo_info, &topo_ids); } cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx); diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index 04f01e2a09..b9593b9905 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -112,8 +112,8 @@ static inline unsigned apicid_pkg_offset(X86CPUTopoInfo *topo_info) * * The caller must make sure core_id < nr_cores and smt_id < nr_threads. */ -static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info, - const X86CPUTopoIDs *topo_ids) +static inline apic_id_t x86_apicid_from_topo_ids(X86CPUTopoInfo *topo_info, + const X86CPUTopoIDs *topo_ids) { return (topo_ids->pkg_id << apicid_pkg_offset(topo_info)) | (topo_ids->die_id << apicid_die_offset(topo_info)) | @@ -165,7 +165,7 @@ static inline apic_id_t x86_apicid_from_cpu_idx(X86CPUTopoInfo *topo_info, { X86CPUTopoIDs topo_ids; x86_topo_ids_from_idx(topo_info, cpu_index, &topo_ids); - return apicid_from_topo_ids(topo_info, &topo_ids); + return x86_apicid_from_topo_ids(topo_info, &topo_ids); } #endif /* HW_I386_TOPOLOGY_H */ From patchwork Wed Mar 11 02:34:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAFCE1874 for ; Wed, 11 Mar 2020 02:35:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92271208C3 for ; Wed, 11 Mar 2020 02:35:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="sEQuhJ+g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92271208C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrDO-0002Cg-OM for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37990) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCG-0000H8-Vv for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCC-0007BM-O0 for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:12 -0400 Received: from mail-co1nam11on2056.outbound.protection.outlook.com ([40.107.220.56]:64080 helo=NAM11-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCC-00079S-Fg for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VbmWugvs+noH/H6Addvh8GTQ55KlJiSNpGgyWkc9Glhm5n7LGQ2PI8N3mKWfRTXMqPxaijUp/A3Hvd9ghldALqu+Qvivzf91Y+rC8rF9fvJ340mb+BjHVMHNVDhEUBPE9MD4kgqTKg25c4WL78gNd2WQjbNt13Kzp0KIxH34XdrpI68ytBcQm/hyVY159EUQKJyv4DoEay8X4uC2264Mh8UK4+CwgS2N6SX/ajsfRkYVBfDvdiAcQ1DPMyIqOKSEJHuLt0qH5jj57KWXwSLFQdtgiRBek0AhaiD3Wp98QNMmUh/76b3pp/R9OAb+6abEDddP11rdX1S2BNKU5rny/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4AG5OeKZNJ1qUCB6C+Kjzms0jEFjZ2iys33sUKi9JSg=; b=kVo0PqwhPuuMw1BXAqRSYlNjwlhepXKwHJ3ii6TdxFBTFGUTWq5oOE+oBQV4kdDJXkiyNnhtKCXyHwHdEJ5xCLrpFDstFNT0pzmTko+qi3C6qYTrZfPO1TVfouYMUe9SqgJqcmF4ADYMTunLvfVF3pdf/yFecf9YJzHt4FfgtS+ftrUzqEqEYQR7pOd8uf6T0EShIkWgWKZ+IR+k+kGlSw3lSlAqLMrDs3QoxMqV4api4iMvrVr6sZSzGvXfDRdNoe5how5w3VqJTCsrLqvNJD740XQU0zy3lnbThE42yTnlq9/HzbkaCwr92tocDK6yPhzP7WFXXFwoluuf6/XcNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4AG5OeKZNJ1qUCB6C+Kjzms0jEFjZ2iys33sUKi9JSg=; b=sEQuhJ+g5i0YvKIiIBKCWiQnVRyc937OnfEw1hU+tDM5zbuXE4lI/bmXl1a2wdmrVimeIWjKtsvHRHZzRWOiFKYRNzRHRgegrbnZkBEfaDB4OHnFQ6HldRKoF6LLDY33wa5Rb/28LpuSCFQUZLLHLs4J9StCmXzIb2M5JCNoXUQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2493.namprd12.prod.outlook.com (2603:10b6:802:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15; Wed, 11 Mar 2020 02:34:06 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:06 +0000 Subject: [PATCH v6 07/13] hw/386: Add EPYC mode topology decoding functions From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:05 -0500 Message-ID: <158389404513.22020.17449886885246869279.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM3PR12CA0068.namprd12.prod.outlook.com (2603:10b6:0:57::12) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM3PR12CA0068.namprd12.prod.outlook.com (2603:10b6:0:57::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Wed, 11 Mar 2020 02:34:06 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b44c8d35-670c-4ee0-bd3a-08d7c564abd1 X-MS-TrafficTypeDiagnostic: SN1PR12MB2493:|SN1PR12MB2493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(39860400002)(376002)(136003)(346002)(199004)(86362001)(44832011)(55016002)(66946007)(956004)(8936002)(316002)(8676002)(5660300002)(966005)(66476007)(52116002)(7696005)(103116003)(66556008)(81166006)(4326008)(478600001)(16526019)(2906002)(186003)(81156014)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2493; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WHhilLHj7VYW3FSd447VpNxYEk2DoBEN4Nho5j2tF1g3EIKP7EBtjMLXEFd/qWPOWvH+oUs9qR2KJLR1AEL7u5y0xaeCzHcjXmfhtANTwEehp0i5yTmGUO/I76KyGejQNF/XI/bH3CeVEGljygSWqBaDP+gpRJontM0/Kum7gdQdPgb8iIPPOvSm1YFgR1tk1wNWAc1pH12bIS39QlZl8iv0IFFWFoiZzyx1pGUY+K+ZxX4Dgb2gnIjOvc1m3Wd/tVODmXAkCpimNxKT94UxPtxZNy33hhycRqiRBV1iR4bptNi+6uoMFDh7fS5v/pN9W2Ny9postdAl3EoWsBn9qxIdnqBqFgx5BUAuGXgLO+HY6FVF1jlY5xKXrYmP/sAa8ptStU6dGWJ0/sSz56Bw4MyED+wO0Ubu4qpgTnxyrSaiBoT4MW+F1kMcNmfgLvdC0gkSomi9vvrrXLwfRTY+0/GoQ1NTWbIaVDhgRmWvG38AN7mgIanbH1NupKBi8vaj3PYNpyHsCC5CT66nnXL55g== X-MS-Exchange-AntiSpam-MessageData: INLEzeUlX2FlOaB61GSkIGsg2Xcy81ExyRyD5GLSs6gZV1PzM4NW5HhGx892ZpXJu8oTpJcsudPpSQPEpYBsLR985qG4pmxnhNkPi7pBEm11XZQ1L65QdlUCX0NzltTuHz+j6vO9YmrP3XsLKHIW1A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b44c8d35-670c-4ee0-bd3a-08d7c564abd1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:06.7614 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dQFSSe6Duh0t9/XrNhDaewLA1S+UVujljoe4F1X7qn0YLUd19umDejiHxgA0D9X1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2493 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.220.56 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" These functions add support for building EPYC mode topology given the smp details like numa nodes, cores, threads and sockets. The new apic id decoding is mostly similar to current apic id decoding except that it adds a new field node_id when numa configured. Removes all the hardcoded values. Subsequent patches will use these functions to build the topology. Following functions are added. apicid_llc_width_epyc apicid_llc_offset_epyc apicid_pkg_offset_epyc apicid_from_topo_ids_epyc x86_topo_ids_from_idx_epyc x86_topo_ids_from_apicid_epyc x86_apicid_from_cpu_idx_epyc The topology details are available in Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors. The revision guides are available from the bugzilla Link below. Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Signed-off-by: Babu Moger Acked-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- include/hw/i386/topology.h | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index b9593b9905..07239f95f4 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -47,6 +47,7 @@ typedef uint32_t apic_id_t; typedef struct X86CPUTopoIDs { unsigned pkg_id; + unsigned node_id; unsigned die_id; unsigned core_id; unsigned smt_id; @@ -88,6 +89,11 @@ static inline unsigned apicid_die_width(X86CPUTopoInfo *topo_info) return apicid_bitwidth_for_count(topo_info->dies_per_pkg); } +/* Bit width of the node_id field per socket */ +static inline unsigned apicid_node_width_epyc(X86CPUTopoInfo *topo_info) +{ + return apicid_bitwidth_for_count(MAX(topo_info->nodes_per_pkg, 1)); +} /* Bit offset of the Core_ID field */ static inline unsigned apicid_core_offset(X86CPUTopoInfo *topo_info) @@ -108,6 +114,100 @@ static inline unsigned apicid_pkg_offset(X86CPUTopoInfo *topo_info) return apicid_die_offset(topo_info) + apicid_die_width(topo_info); } +#define NODE_ID_OFFSET 3 /* Minimum node_id offset if numa configured */ + +/* + * Bit offset of the node_id field + * + * Make sure nodes_per_pkg > 0 if numa configured else zero. + */ +static inline unsigned apicid_node_offset_epyc(X86CPUTopoInfo *topo_info) +{ + unsigned offset = apicid_die_offset(topo_info) + + apicid_die_width(topo_info); + + if (topo_info->nodes_per_pkg) { + return MAX(NODE_ID_OFFSET, offset); + } else { + return offset; + } +} + +/* Bit offset of the Pkg_ID (socket ID) field */ +static inline unsigned apicid_pkg_offset_epyc(X86CPUTopoInfo *topo_info) +{ + return apicid_node_offset_epyc(topo_info) + + apicid_node_width_epyc(topo_info); +} + +/* + * Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID + * + * The caller must make sure core_id < nr_cores and smt_id < nr_threads. + */ +static inline apic_id_t +x86_apicid_from_topo_ids_epyc(X86CPUTopoInfo *topo_info, + const X86CPUTopoIDs *topo_ids) +{ + return (topo_ids->pkg_id << apicid_pkg_offset_epyc(topo_info)) | + (topo_ids->node_id << apicid_node_offset_epyc(topo_info)) | + (topo_ids->die_id << apicid_die_offset(topo_info)) | + (topo_ids->core_id << apicid_core_offset(topo_info)) | + topo_ids->smt_id; +} + +static inline void x86_topo_ids_from_idx_epyc(X86CPUTopoInfo *topo_info, + unsigned cpu_index, + X86CPUTopoIDs *topo_ids) +{ + unsigned nr_nodes = MAX(topo_info->nodes_per_pkg, 1); + unsigned nr_dies = topo_info->dies_per_pkg; + unsigned nr_cores = topo_info->cores_per_die; + unsigned nr_threads = topo_info->threads_per_core; + unsigned cores_per_node = DIV_ROUND_UP((nr_dies * nr_cores * nr_threads), + nr_nodes); + + topo_ids->pkg_id = cpu_index / (nr_dies * nr_cores * nr_threads); + topo_ids->node_id = (cpu_index / cores_per_node) % nr_nodes; + topo_ids->die_id = cpu_index / (nr_cores * nr_threads) % nr_dies; + topo_ids->core_id = cpu_index / nr_threads % nr_cores; + topo_ids->smt_id = cpu_index % nr_threads; +} + +/* + * Calculate thread/core/package IDs for a specific topology, + * based on APIC ID + */ +static inline void x86_topo_ids_from_apicid_epyc(apic_id_t apicid, + X86CPUTopoInfo *topo_info, + X86CPUTopoIDs *topo_ids) +{ + topo_ids->smt_id = apicid & + ~(0xFFFFFFFFUL << apicid_smt_width(topo_info)); + topo_ids->core_id = + (apicid >> apicid_core_offset(topo_info)) & + ~(0xFFFFFFFFUL << apicid_core_width(topo_info)); + topo_ids->die_id = + (apicid >> apicid_die_offset(topo_info)) & + ~(0xFFFFFFFFUL << apicid_die_width(topo_info)); + topo_ids->node_id = + (apicid >> apicid_node_offset_epyc(topo_info)) & + ~(0xFFFFFFFFUL << apicid_node_width_epyc(topo_info)); + topo_ids->pkg_id = apicid >> apicid_pkg_offset_epyc(topo_info); +} + +/* + * Make APIC ID for the CPU 'cpu_index' + * + * 'cpu_index' is a sequential, contiguous ID for the CPU. + */ +static inline apic_id_t x86_apicid_from_cpu_idx_epyc(X86CPUTopoInfo *topo_info, + unsigned cpu_index) +{ + X86CPUTopoIDs topo_ids; + x86_topo_ids_from_idx_epyc(topo_info, cpu_index, &topo_ids); + return x86_apicid_from_topo_ids_epyc(topo_info, &topo_ids); +} /* Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID * * The caller must make sure core_id < nr_cores and smt_id < nr_threads. From patchwork Wed Mar 11 02:34:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 162E7138D for ; Wed, 11 Mar 2020 02:36:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D05A7208E4 for ; Wed, 11 Mar 2020 02:36:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="TStUNjYS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D05A7208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrEI-0004E8-0D for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:36:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38074) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCO-0000P0-Tw for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCN-0007WF-3e for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:20 -0400 Received: from mail-dm6nam11on20620.outbound.protection.outlook.com ([2a01:111:f400:7eaa::620]:18177 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCM-0007T1-Rw for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aXWyV2rJUSR6+QsC3jL1FU4rCxdaiZ/qalWZ/JCm95Kde4PDau2x4RZwowS8ARQkdTiiRKVhS3oZUaLLbWPKNrORskaZw5zcPpshwl6Jtwm7kdUXip6HQp8Uut8cx+V8t2IxCaPykaAGY2KO+VzWMqcdTTAjavCI8uGRbCdrjgPQPqXntaChWJQU5RvtI2bVdvOnRzmM0vxrNnmNc4kd2PEP9vfKNRbZN83B+QvVgJJe+mG5r/zhMPNu8bvLFCfBIyB1TZGAxszuwDRSp9YIdeJZhIVB8ib0y9eOnFGl6BVKc9tCGrZsig2Q/o0AFJk4dBzWDtHWfmuK6njdKurnqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2sMPK/ZqK6Ssfe0HYSLx4sbMBKFqM9qbJAPTgMahLhY=; b=M6n1Ktn0y2AM/M38pfZHWkqN7Iw2zC4AOJ0lf39rQAXB0Q12JdT69MxHnG9wD0CgdmZa/w3AGfBGjzhf8Hg3LURI4icBlIbCFDtPFz+CqffC8Lb4zmJUNjMo5XkwlIQAnS6MZaLKoxg4/rwqZR0TT+P6vE3o4OeI3MVNHHwkWLbsXQL/6uj9O+Z2J9EJWXbQJoU8alEeWCgoUTDt9i4DRw92mTxKvSQR20fowhyFESL6WeYOwNqXEKbgME+DZA1PHQX4GeX7ShbVVrsVgq2/Ved6cO9UybeijP7n1ri8aKYT67/N8gscYUFPZUFfT+ni0wgp1EWUju3JEZKMDyp2QA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2sMPK/ZqK6Ssfe0HYSLx4sbMBKFqM9qbJAPTgMahLhY=; b=TStUNjYSxW9euOFZzY6fpJa2bTl9+3SOHYK2AHt4NW4Nu8zuAnQdXWJqHd8kh0sWXfoJQH2XbrlbuXSIGDBmwcV+Th5ClqBkFKS0Ec/K2HAv4mvFOeDH76/vlm+p8ZmlDHJMK7xFalnFerzLGiGUyfJe45nSd+DqZcGx+tzLph4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:13 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:13 +0000 Subject: [PATCH v6 08/13] target/i386: Cleanup and use the EPYC mode topology functions From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:11 -0500 Message-ID: <158389405195.22020.11480351700004650224.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM3PR12CA0088.namprd12.prod.outlook.com (2603:10b6:0:57::32) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM3PR12CA0088.namprd12.prod.outlook.com (2603:10b6:0:57::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.14 via Frontend Transport; Wed, 11 Mar 2020 02:34:12 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 90adf73d-6389-460f-e3db-08d7c564aff0 X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(66946007)(478600001)(316002)(4326008)(86362001)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0NgYm8g50RM5Xi3PYjEf02losJQL8bwVK/b622GOZxzib/qr+6Up+8U/ktNVdNcbdCVnMzIu28jrYA+pHlH4QW+M8Hbl9so2eH7T8v1ttGyJ38NioWoTs17yVVgFxaBuI/60DDpfawVzfV0oR/1PVPYDNhQSI9DulXZvdldzjYqPdXv8pquaCwK8bEETGggTDpxIyXTwLTQPWjSzZKQdNP601+EKFAdxrhg3Qw8aSb21zFRSPVoKC7puF2JiS82i0x3skcAON4/eGSvondp9gktkSInauZZL+8YkjXb9E5YOWM1wVrVs6bze4JtpPUsKh8wVFtmcf8fBczNBYRQriFwPUhMcju2OvF4bak2MOqqAp7vnOaSW2dMQEh89ILwdeZ4BF8UbVNGS6fwkgalq5iakPsATnMR0ZYq31HCAbNFi6dmcnb2zhQ1g8cGcjDbj X-MS-Exchange-AntiSpam-MessageData: CF1XZPGW9qW+hEl3uMVSRr/HIlglJgdEkzdSq6bZY0tJDf/R3CrDcBocV5B7FENK672NGDZ11NXFNrdn34WcytJAtb2oTxraaMF7pltEMp98LNr0FWVSDi1u/QjiaI2K75QurRfXxTT7EnTHN1RDSQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90adf73d-6389-460f-e3db-08d7c564aff0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:13.7794 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2nD3YQuye84ixrzDVGXmyWeBzV7JRVO4K3tMl8HhSoT2wXJ0+Ed8bETJKzRSIsNj X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a01:111:f400:7eaa::620 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Use the new functions from topology.h and delete the unused code. Given the sockets, nodes, cores and threads, the new functions generate apic id for EPYC mode. Removes all the hardcoded values. Signed-off-by: Babu Moger Acked-by: Michael S. Tsirkin Acked-by: Igor Mammedov --- target/i386/cpu.c | 162 +++++++++++------------------------------------------ 1 file changed, 35 insertions(+), 127 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 2e5be37b21..a3051524a2 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -338,68 +338,15 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, } } -/* - * Definitions used for building CPUID Leaf 0x8000001D and 0x8000001E - * Please refer to the AMD64 Architecture Programmer’s Manual Volume 3. - * Define the constants to build the cpu topology. Right now, TOPOEXT - * feature is enabled only on EPYC. So, these constants are based on - * EPYC supported configurations. We may need to handle the cases if - * these values change in future. - */ -/* Maximum core complexes in a node */ -#define MAX_CCX 2 -/* Maximum cores in a core complex */ -#define MAX_CORES_IN_CCX 4 -/* Maximum cores in a node */ -#define MAX_CORES_IN_NODE 8 -/* Maximum nodes in a socket */ -#define MAX_NODES_PER_SOCKET 4 - -/* - * Figure out the number of nodes required to build this config. - * Max cores in a node is 8 - */ -static int nodes_in_socket(int nr_cores) -{ - int nodes; - - nodes = DIV_ROUND_UP(nr_cores, MAX_CORES_IN_NODE); - - /* Hardware does not support config with 3 nodes, return 4 in that case */ - return (nodes == 3) ? 4 : nodes; -} - -/* - * Decide the number of cores in a core complex with the given nr_cores using - * following set constants MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE and - * MAX_NODES_PER_SOCKET. Maintain symmetry as much as possible - * L3 cache is shared across all cores in a core complex. So, this will also - * tell us how many cores are sharing the L3 cache. - */ -static int cores_in_core_complex(int nr_cores) -{ - int nodes; - - /* Check if we can fit all the cores in one core complex */ - if (nr_cores <= MAX_CORES_IN_CCX) { - return nr_cores; - } - /* Get the number of nodes required to build this config */ - nodes = nodes_in_socket(nr_cores); - - /* - * Divide the cores accros all the core complexes - * Return rounded up value - */ - return DIV_ROUND_UP(nr_cores, nodes * MAX_CCX); -} - /* Encode cache info for CPUID[8000001D] */ -static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs, - uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx) +static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, + X86CPUTopoInfo *topo_info, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { uint32_t l3_cores; + unsigned nodes = MAX(topo_info->nodes_per_pkg, 1); + assert(cache->size == cache->line_size * cache->associativity * cache->partitions * cache->sets); @@ -408,10 +355,13 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs, /* L3 is shared among multiple cores */ if (cache->level == 3) { - l3_cores = cores_in_core_complex(cs->nr_cores); - *eax |= ((l3_cores * cs->nr_threads) - 1) << 14; + l3_cores = DIV_ROUND_UP((topo_info->dies_per_pkg * + topo_info->cores_per_die * + topo_info->threads_per_core), + nodes); + *eax |= (l3_cores - 1) << 14; } else { - *eax |= ((cs->nr_threads - 1) << 14); + *eax |= ((topo_info->threads_per_core - 1) << 14); } assert(cache->line_size > 0); @@ -431,55 +381,17 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs, (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); } -/* Data structure to hold the configuration info for a given core index */ -struct core_topology { - /* core complex id of the current core index */ - int ccx_id; - /* - * Adjusted core index for this core in the topology - * This can be 0,1,2,3 with max 4 cores in a core complex - */ - int core_id; - /* Node id for this core index */ - int node_id; - /* Number of nodes in this config */ - int num_nodes; -}; - -/* - * Build the configuration closely match the EPYC hardware. Using the EPYC - * hardware configuration values (MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE) - * right now. This could change in future. - * nr_cores : Total number of cores in the config - * core_id : Core index of the current CPU - * topo : Data structure to hold all the config info for this core index - */ -static void build_core_topology(int nr_cores, int core_id, - struct core_topology *topo) -{ - int nodes, cores_in_ccx; - - /* First get the number of nodes required */ - nodes = nodes_in_socket(nr_cores); - - cores_in_ccx = cores_in_core_complex(nr_cores); - - topo->node_id = core_id / (cores_in_ccx * MAX_CCX); - topo->ccx_id = (core_id % (cores_in_ccx * MAX_CCX)) / cores_in_ccx; - topo->core_id = core_id % cores_in_ccx; - topo->num_nodes = nodes; -} - /* Encode cache info for CPUID[8000001E] */ -static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, +static void encode_topo_cpuid8000001e(X86CPUTopoInfo *topo_info, X86CPU *cpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { - struct core_topology topo = {0}; - unsigned long nodes; + X86CPUTopoIDs topo_ids = {0}; + unsigned long nodes = MAX(topo_info->nodes_per_pkg, 1); int shift; - build_core_topology(cs->nr_cores, cpu->core_id, &topo); + x86_topo_ids_from_apicid_epyc(cpu->apic_id, topo_info, &topo_ids); + *eax = cpu->apic_id; /* * CPUID_Fn8000001E_EBX @@ -496,12 +408,8 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, * 3 Core complex id * 1:0 Core id */ - if (cs->nr_threads - 1) { - *ebx = ((cs->nr_threads - 1) << 8) | (topo.node_id << 3) | - (topo.ccx_id << 2) | topo.core_id; - } else { - *ebx = (topo.node_id << 4) | (topo.ccx_id << 3) | topo.core_id; - } + *ebx = ((topo_info->threads_per_core - 1) << 8) | (topo_ids.node_id << 3) | + (topo_ids.core_id); /* * CPUID_Fn8000001E_ECX * 31:11 Reserved @@ -510,9 +418,9 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, * 2 Socket id * 1:0 Node id */ - if (topo.num_nodes <= 4) { - *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | - topo.node_id; + + if (nodes <= 4) { + *ecx = ((nodes - 1) << 8) | (topo_ids.pkg_id << 2) | topo_ids.node_id; } else { /* * Node id fix up. Actual hardware supports up to 4 nodes. But with @@ -527,10 +435,10 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, * number of nodes. find_last_bit returns last set bit(0 based). Left * shift(+1) the socket id to represent all the nodes. */ - nodes = topo.num_nodes - 1; + nodes -= 1; shift = find_last_bit(&nodes, 8); - *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << (shift + 1)) | - topo.node_id; + *ecx = (nodes << 8) | (topo_ids.pkg_id << (shift + 1)) | + topo_ids.node_id; } *edx = 0; } @@ -5499,6 +5407,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t signature[3]; X86CPUTopoInfo topo_info; + topo_info.nodes_per_pkg = env->nr_nodes; topo_info.dies_per_pkg = env->nr_dies; topo_info.cores_per_die = cs->nr_cores; topo_info.threads_per_core = cs->nr_threads; @@ -5918,20 +5827,20 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, cs, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, + &topo_info, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, cs, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, + &topo_info, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, cs, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, + &topo_info, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, cs, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, + &topo_info, eax, ebx, ecx, edx); break; default: /* end of info */ *eax = *ebx = *ecx = *edx = 0; @@ -5940,8 +5849,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 0x8000001E: assert(cpu->core_id <= 255); - encode_topo_cpuid8000001e(cs, cpu, - eax, ebx, ecx, edx); + encode_topo_cpuid8000001e(&topo_info, cpu, eax, ebx, ecx, edx); break; case 0xC0000000: *eax = env->cpuid_xlevel2; From patchwork Wed Mar 11 02:34:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93C241874 for ; Wed, 11 Mar 2020 02:37:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A92020637 for ; Wed, 11 Mar 2020 02:37:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="OU0xdN2M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A92020637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrEy-0005zp-Ie for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:37:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38115) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCT-0000SR-Ke for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCS-0007lm-Hm for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:25 -0400 Received: from mail-dm6nam11on2078.outbound.protection.outlook.com ([40.107.223.78]:6042 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCS-0007iP-Bm for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XUrmyH/t2Fc9fvROjX1oeSZEAWU1MPvz2inOQHQwfHNVYELRoRpVqIDwxpBhOioPl3zi4lGmIpGd91fz6X86e5OSv8P1sp+LWxlLbFHAGC/ga+XxsPUhrHWyjsE0SbJR0p/K+CYcX9oUcA+fKXIY11j1FPoTm9O0yemj+qV6pSHxskDJ5KNVMSjDFKUUL/9ZCehB8SdR2WjpH9xQNYP0tgXJxZipBaZ4FfBaZEBwWpiqQw/JrXZgcWNj0i+oytCljiKqaLM5SKkS/KQX+T5pe2Nb/9vAog8Txo6W8dYH004y6EaXu0DCJBAmcP2DsR2jUTPTTPQfBgMXfMPYvF7JeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LNV7gMlgQTAxe/RqRLGxnqKJeH5jczL2I/uZb/zUC9M=; b=hW96iDNFVCdILDeAWJvh97oRfYhWMgaP6NDiBPHKkdSRchUqOvGsBZBvHPzeNjNhtTIOR4eO1PThUBmHA3sPzgLQZaIlFU7Woyli2ZS4yq+obwD9ctpznNRzDp9sH45JlEQiN08AAq7DrB4PfPwSBBOEncUDb+IRk+PLDj3ZFSLy9EzdBOIzdr6A9oRVoGqOJOZOlgjoMkopnwzxzRxnTimaSVatZLewDkuhW3ChgJQGHRiu12D5U1voAg5FqbkqGamhWbRexJ5Qeg/QBHVLLbQ4RDZsIOIXyDqsKzvBzkOJ3pIHLF+ex1a+UsSKErP0TlcYbuCTvMpuncBZRx/Kog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LNV7gMlgQTAxe/RqRLGxnqKJeH5jczL2I/uZb/zUC9M=; b=OU0xdN2MYpta83carnWh34jA9VESVvvo2kL/3sVA5kD1r4nGLASg+jYz6NyL/o4NeE0JE1SltgKWgs1P/GNbYsIwsS+ElJNDrnBWXqw5TINgitKKO5aMhKRkn0L/Bf9hj1DSKlVnRuIJt/iEg+pJmcn2XqHi0th40Dzjrwz8zZY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:20 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:20 +0000 Subject: [PATCH v6 09/13] hw/i386: Introduce apicid functions inside X86MachineState From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:19 -0500 Message-ID: <158389405896.22020.5141725703704378222.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR06CA0071.namprd06.prod.outlook.com (2603:10b6:3:37::33) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR06CA0071.namprd06.prod.outlook.com (2603:10b6:3:37::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17 via Frontend Transport; Wed, 11 Mar 2020 02:34:19 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 75866c0b-5a11-4ce2-6561-08d7c564b413 X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(66946007)(478600001)(316002)(4326008)(86362001)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VNizpbPY80rKEXN9qqZkXMvvIef1Mz+qzA8ua/VR7RAjC5dX51ihh9j1JxL98KX0KHqSXthVfnAKe/DBB6vfvhxaiiDE1vpcRfHH67Npku8LyoArPOGnkSOU9AQxJdnGLaL4gls9N5efu8IFRIFZUT7259xSm2/396loJGad6sXMfINd20sHHGW+txcMppH4z6SGYMlGfsyZcRuuZWbUmfGHctpWJ+dfN3KKVkbmbkV0v+uevxkmYo5Y26+AYTPgKiF6UycSbPTaz99nklqF+KFl+Pf9j3OJTbhQoe6WnWnCAzcWQgBSWPc+B/1lNm+R2ikPsUe7Cnl4Pi74kiKeL72FVPu3+Yc3W1vJIapd/FgzSagBlYqZyshF4t1wiA821J7/bsFJVG5UGuc2H0CWVyC19DuIkg9z6DzJIxSFp8QkACTPcjE1cAea9J6zcFKG X-MS-Exchange-AntiSpam-MessageData: /rwog7yx79E86yqdunhqzJfjzp63Plb2dh2RSRpBj3EZrq34i3hRr1QvE8IueFmm5KbztwDJY4Iu3gRkVpM4Vk8GPH6L5RlOeGG7OS/p4HmFGy2573g3h32Zp+pA61Hl5ZDqSr17ppSTnJAGF9u78A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75866c0b-5a11-4ce2-6561-08d7c564b413 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:20.6285 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dvVUOymy7x/F9oLNXKocUPlS7Z1Yzs3TD78iWmXoga52a27DZKtMWIOF6pMKCYMF X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.223.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Introduce model specific apicid functions inside X86MachineState. These functions will be loaded from X86CPUDefinition. Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/i386/x86.c | 6 ++++++ include/hw/i386/x86.h | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 929b80c9c7..7dc237c014 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -911,6 +911,12 @@ static void x86_machine_initfn(Object *obj) x86ms->smm = ON_OFF_AUTO_AUTO; x86ms->max_ram_below_4g = 0; /* use default */ x86ms->smp_dies = 1; + + x86ms->apicid_from_cpu_idx = x86_apicid_from_cpu_idx; + x86ms->topo_ids_from_apicid = x86_topo_ids_from_apicid; + x86ms->topo_ids_from_idx = x86_topo_ids_from_idx; + x86ms->apicid_from_topo_ids = x86_apicid_from_topo_ids; + x86ms->apicid_pkg_offset = apicid_pkg_offset; } static void x86_machine_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 22babcb3bb..57c1d13483 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -65,6 +65,17 @@ typedef struct { OnOffAuto smm; + /* Apic id specific handlers */ + uint32_t (*apicid_from_cpu_idx)(X86CPUTopoInfo *topo_info, + unsigned cpu_index); + void (*topo_ids_from_apicid)(apic_id_t apicid, X86CPUTopoInfo *topo_info, + X86CPUTopoIDs *topo_ids); + void (*topo_ids_from_idx)(X86CPUTopoInfo *topo_info, unsigned idx, + X86CPUTopoIDs *topo_ids); + apic_id_t (*apicid_from_topo_ids)(X86CPUTopoInfo *topo_info, + const X86CPUTopoIDs *topo_ids); + uint32_t (*apicid_pkg_offset)(X86CPUTopoInfo *topo_info); + /* * Address space used by IOAPIC device. All IOAPIC interrupts * will be translated to MSI messages in the address space. From patchwork Wed Mar 11 02:34:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 780E014B7 for ; Wed, 11 Mar 2020 02:38:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E56C20637 for ; Wed, 11 Mar 2020 02:38:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="UNk2Mew/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E56C20637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrGa-00014D-DX for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:38:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38156) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCa-0000be-JN for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCZ-0007xN-0U for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:32 -0400 Received: from mail-dm6nam11on2048.outbound.protection.outlook.com ([40.107.223.48]:31967 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCY-0007tt-Ob for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cgxwLxgM1sMjhCsz+cTy+dUx2DtirlQs+zHS5TFEVgsgr0+xscYxrSO5TxSCaxr8zJ8rIwNpKn+R0Od6z26o/vGnhyOnsuNK69TNh2xiIGfLHg/U3lCEppwdtAp7+o8t4wH1qdWiZYbu3PoG5cE4OsmZWiVau86BZtoESxpLzSHekmtBJAXrBlH8eTwjJKdwYYMgh6r+LyoTdGHGzYOQl0bIaWmNxI43a2uI4gE9zrnHQTG7L82MGOWVnJqxXOVpEGtpkpLS/hiqStzHEl9bZy7bfVePfH8vYDg6Q9eQDE+/F6dgyGn70t0AUPbJK009Bio5SglNNpb7VXyppC7p8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9tqvj+UCh00OS508PbjxeUt8385/p9uHKHaIoiv2K8E=; b=hH036CnKChVcZ1Zgi/mTWmbdtz5swr9BknsYZm/smcqVrMFxEEd+t602mQWGWvUoz8Lh1bjlBD11eytnLv9qmjwTlGdlRZrYhSmG2oM7dOdVBYaaGqIo5e58APdBrTIneRphmAGR7zr0WXx4eWL8qJp3Gab4Q5TSKUZTvtG35C4558HhaiH8J8rRDBISPnXuWET0BU+rjeFtRxmxf7BUYZ2Z9Vw068Fj8dNLEHxlsaMsqWjMkA/D6QmavT6GCKpbSYKa+/7uTyNO3LbSk6e7whGlDdeInc/hqvMpK3raxtHasWIc8ZxOeYWJEDed0oJ3ZUHUeWljIYyI1m2tb39wmw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9tqvj+UCh00OS508PbjxeUt8385/p9uHKHaIoiv2K8E=; b=UNk2Mew/xMEZCbz5fC28hg7Ncc+vulQ4mtvmMOcaEwT+pUCw29leaHMj1JyVXRNI1MTrZg9XF8JctSyAhWh37qbmOuYJ8zMnf5CzCeUxkV3pk/LweEQZ6+cPEqmTOvxz25VxDS6sTjkp8ww1EvODw2/vN8+WVq5I+KCOHpsrDsE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:27 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:27 +0000 Subject: [PATCH v6 10/13] i386: Check for apic id encoding From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:25 -0500 Message-ID: <158389406581.22020.12203992175835061363.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR06CA0069.namprd06.prod.outlook.com (2603:10b6:3:37::31) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR06CA0069.namprd06.prod.outlook.com (2603:10b6:3:37::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17 via Frontend Transport; Wed, 11 Mar 2020 02:34:26 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9f1c247a-3bc5-4155-04f8-08d7c564b83a X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(66946007)(478600001)(316002)(4326008)(86362001)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wUL1Sb7sZwiqcqb6X0Tur4s101ABn9uA2f4fGSEY1nNjDG+i93MkollX/Z1KLlSIZ2VHwijIWgHji3pVHGkubNm13HYEHkwb4CiQhungEX5GHXqRDjl4b9wu3Zgr2Uj/DyZgE2sDnAS/fiRYKgkiY/mae54rbrSKiVsGPcg8Fk0XxK+RQntGawghiPQOSqVbpRLqTVwX8vCZxtO3sDmgo8sO0GjEOm50Wg6dTd2xak+bRjuQ9f7+LlP2kYfuqwKKGjc1GwigBFLxv/syDtl0L1k3Zf11GwQ+Q2vZkFM6ASxscW83QYMLEZFj7qpaXPZ2bBtLcLl17oSuM49iWlWiF760ZiLI6PC1NN9lw2/7QvnkHItgZpaCajwZHnqly6caPleu7vX1koDeeJ9BOYcSdAF3PVw8ob4t0MskoF9jmMbylYDdSftvtbBmh4ty9fOE X-MS-Exchange-AntiSpam-MessageData: odnCxhIcXWLwQmmsEp3JVxmKau7YxoF0uqCq55nxZeRsq7BnZkdYVikNqRZ8622ikW6pYecg0Y4ArHssbRfJuM29uW0St7CeJKrRzWLMACANEE4I3o/KrNqbD8dx7iPizH9zYtz5jb3KaT5qFmLD6A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f1c247a-3bc5-4155-04f8-08d7c564b83a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:27.6345 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8RByFY1fxXsrSZqMztRf2GKZl+b9H9UQ6jA7v7Ucb2ahSDAxDgTDV98/Djk4jwT4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.223.48 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Check X86CPUDefinition if use_epyc_apic_id_encoding is enabled. If enabled update X86MachineState with EPYC mode apic_id encoding handlers. Also update the calling convention to use apic_id handlers from X86MachineState. Signed-off-by: Babu Moger Acked-by: Michael S. Tsirkin --- hw/i386/pc.c | 6 +++--- hw/i386/x86.c | 32 +++++++++++++++++++++++++++----- target/i386/cpu.c | 11 +++++++++++ target/i386/cpu.h | 1 + 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 98ee763f68..2d7d611184 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1580,14 +1580,14 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, topo_ids.die_id = cpu->die_id; topo_ids.core_id = cpu->core_id; topo_ids.smt_id = cpu->thread_id; - cpu->apic_id = x86_apicid_from_topo_ids(&topo_info, &topo_ids); + cpu->apic_id = x86ms->apicid_from_topo_ids(&topo_info, &topo_ids); } cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx); if (!cpu_slot) { MachineState *ms = MACHINE(pcms); - x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); + x86ms->topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); error_setg(errp, "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with" " APIC ID %" PRIu32 ", valid index range 0:%d", @@ -1608,7 +1608,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn() * once -smp refactoring is complete and there will be CPU private * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */ - x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); + x86ms->topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) { error_setg(errp, "property socket-id: %u doesn't match set apic-id:" " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 7dc237c014..ad85347142 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -68,6 +68,25 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info, topo_info->threads_per_core = ms->smp.threads; } +/* + * Check for APIC ID encoding + * + * AMD uses different apic id encoding for their EPYC based cpus. + * Check if we need to use different handlers than the default. + */ +static void x86_check_apic_id_encoding(MachineState *machine) +{ + X86MachineState *x86ms = X86_MACHINE(machine); + + if (cpu_x86_use_epyc_apic_id_encoding(machine->cpu_type)) { + x86ms->apicid_from_cpu_idx = x86_apicid_from_cpu_idx_epyc; + x86ms->topo_ids_from_apicid = x86_topo_ids_from_apicid_epyc; + x86ms->topo_ids_from_idx = x86_topo_ids_from_idx_epyc; + x86ms->apicid_from_topo_ids = x86_apicid_from_topo_ids_epyc; + x86ms->apicid_pkg_offset = apicid_pkg_offset_epyc; + } +} + /* * Calculates initial APIC ID for a specific CPU index * @@ -86,7 +105,7 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms, init_topo_info(&topo_info, x86ms); - correct_id = x86_apicid_from_cpu_idx(&topo_info, cpu_index); + correct_id = x86ms->apicid_from_cpu_idx(&topo_info, cpu_index); if (x86mc->compat_apic_id_mode) { if (cpu_index != correct_id && !warned && !qtest_enabled()) { error_report("APIC IDs set in compatibility mode, " @@ -158,8 +177,8 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx) init_topo_info(&topo_info, x86ms); assert(idx < ms->possible_cpus->len); - x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id, - &topo_info, &topo_ids); + x86ms->topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id, + &topo_info, &topo_ids); return topo_ids.pkg_id % ms->numa_state->num_nodes; } @@ -179,6 +198,9 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) return ms->possible_cpus; } + /* Check for apicid encoding */ + x86_check_apic_id_encoding(ms); + ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + sizeof(CPUArchId) * max_cpus); ms->possible_cpus->len = max_cpus; @@ -192,8 +214,8 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) ms->possible_cpus->cpus[i].vcpus_count = 1; ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(x86ms, i); - x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, - &topo_info, &topo_ids); + x86ms->topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, + &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id = true; ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id; if (x86ms->smp_dies > 1) { diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a3051524a2..19de79d01c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1615,6 +1615,10 @@ typedef struct X86CPUDefinition { FeatureWordArray features; const char *model_id; CPUCaches *cache_info; + + /* Use AMD EPYC encoding for apic id */ + bool use_epyc_apic_id_encoding; + /* * Definitions for alternative versions of CPU model. * List is terminated by item with version == 0. @@ -1656,6 +1660,13 @@ static const X86CPUVersionDefinition *x86_cpu_def_get_versions(X86CPUDefinition return def->versions ?: default_version_list; } +bool cpu_x86_use_epyc_apic_id_encoding(const char *cpu_type) +{ + X86CPUClass *xcc = X86_CPU_CLASS(object_class_by_name(cpu_type)); + + return xcc->model->cpudef->use_epyc_apic_id_encoding; +} + static CPUCaches epyc_cache_info = { .l1d_cache = &(CPUCacheInfo) { .type = DATA_CACHE, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7e9e963d78..6e522fcd34 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1897,6 +1897,7 @@ void cpu_clear_apic_feature(CPUX86State *env); void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); void host_vendor_fms(char *vendor, int *family, int *model, int *stepping); +bool cpu_x86_use_epyc_apic_id_encoding(const char *cpu_type); /* helper.c */ bool x86_cpu_tlb_fill(CPUState *cs, vaddr address, int size, From patchwork Wed Mar 11 02:34:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A2A4F14B7 for ; Wed, 11 Mar 2020 02:38:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7754520637 for ; Wed, 11 Mar 2020 02:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="IlzGXVsz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7754520637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrGQ-0000y0-NE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:38:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38246) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCm-0000kz-1Z for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCf-0008JU-8p for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:43 -0400 Received: from mail-dm6nam11on2041.outbound.protection.outlook.com ([40.107.223.41]:12769 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCf-0008Gb-3O for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GL7bL4eLsSR0ZVCheenlUg7K+EDcGlzyOIi49iPbX+MmxpwnRX4nCwcuj3jIzwKjD8bXzFjbmfJda5KKqp9pDN2bAMWiKrFZW6DAVvpT9/oFLvJNliYFOWzdDx4ILbkbN1ABwaYNokbai/yAoIAmX3HF8Ofqy7umpBji24zIZDJ+znX24i6qPuMlpiR9rKu4QeQn25tb8KOud4EMTi101vOgxwMJrcJuUWygCwQwRIJZ3tzyldIXCXDGujtZJpNiUz0IgtGF+Y7x6jC61awRvz7rJZ11lJmSvSFBG/CBTb+ULn4zGu0dQkuDbviaB2jK3NAINadRAuP4cT8Fr7tucQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HToBpq4lqO1HP3/AXHPI45iWacBIykNE1mXi6WEgDaQ=; b=k0y+6CkM+2g67G0wbGq/wCXWVZIXKNAYQhp2P8445FUY3UB2ins129lGHTQUG6oNiyqQ9VbWjEsmN5w5kXTPSNXco6CfJkOrWIb+vwxw9Vs+uPHIizX1B2obJMLpQVKMiuo41RG7504zGZusOgirtV2MkvjXWKuQ4/FduG3WLBAZ2duthOx4Ld3uma+BU/d5AlEEPug31EiaxbQdsu0GDaAmE3HXOVHHq0HVRvdX8FcbAc5mWzk6cmcEE3h5jhAbcpVz249Vq9Zag5Ulp9IsgV17ra4ClIJPmZLhBs6qkfwny6t2NQVQ6pc3F+6eJhk6WFOXQAuMQFkFN36AOT2LUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HToBpq4lqO1HP3/AXHPI45iWacBIykNE1mXi6WEgDaQ=; b=IlzGXVsz/v7P36u7JWsVCosH7Hjksdb7gWKekEGOeJ8wtgUS2/IS2tm3HXF1aGE5MKQWeQhJ3rsDLz7oZTI3NrpIzODWlBYR+Kd6cISdumS+JQEqEtu8EGDnMkhNtBpC+r7pIG1b9FotwJcZrRSPFmm3fLgAYO7ORxry1xzb+08= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:34 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:34 +0000 Subject: [PATCH v6 11/13] target/i386: Enable new apic id encoding for EPYC based cpus models From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:32 -0500 Message-ID: <158389407283.22020.13704666183488372052.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR2001CA0002.namprd20.prod.outlook.com (2603:10b6:4:16::12) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR2001CA0002.namprd20.prod.outlook.com (2603:10b6:4:16::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.15 via Frontend Transport; Wed, 11 Mar 2020 02:34:33 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6d326265-95ba-49a8-7d97-08d7c564bc60 X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(966005)(66946007)(478600001)(316002)(4326008)(86362001)(26005)(170073001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YEovjQnt53QpEutwjsZbfRPaKygVciYvZ5aUszPo4GlA8FWP0km8h94Zg24fSdrddqgu45hlU/mPRFtQpYKBlUqnxh+r+31WCSx4um2WQ/WiaFP6GRNitpKFppqqrxUDI20tx8zcKIHVk9vaSL830YrJkPpjXQWtYUhePpPqcohw3e9cGft4jmBU40dHvwTytRyRI8bI+wQhanxVKhgstqQHQZbvekyGMurIvWufwI0yOsO8UAWeHlFkmuKw/DBYbOumAXuyT9fiN9cco7eH9HAb34z6oZFQWMGDDm9LVkrgR8620sYaTTm3/c5fnV92jb+x0asiuJ0gaZXCylKfgME7L0OU/1h6shjPNUHunVFnfeLl4lZLXdfzei1Gw5TgrFE83WiQo4ERaTxE/braBBc5OrumOkkqTE5hNU8tJ6llbh6RdLDSwiC1+uPqcb6StWY2ONQhbGSA05lYVZ4fYeMXf3w6mkn9LG95s9x7Nhf8E6cepiRKbBHoGZmoTDH7eXy94mJ5vs2M9TiooKU7uNpa7QujB8f5SI7v6o5h95Bn6PSX/qN9sJdKtMbNsMlJ X-MS-Exchange-AntiSpam-MessageData: oopNbXiKemt/oYaN/0x40Hdc8d6P6ejSG1G8OEU08TGCc3DOxPYVNUSikarurZ9vQEywpPV4evj8Nz/+IoTf1xV9STj1BmxGS5VcDc1rjFog436oqk0gEfgAD2zW1sm+vkHZQW/KhrCqumDCwMW+CQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d326265-95ba-49a8-7d97-08d7c564bc60 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:34.5955 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zctfcysSZq1NJqLG4QkHLUNhCaVvcdZKpK8HHOMLk8DYzfe9PinTxr/p/x7onBzT X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.223.41 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The APIC ID is decoded based on the sequence sockets->dies->cores->threads. This works fine for most standard AMD and other vendors' configurations, but this decoding sequence does not follow that of AMD's APIC ID enumeration strictly. In some cases this can cause CPU topology inconsistency. When booting a guest VM, the kernel tries to validate the topology, and finds it inconsistent with the enumeration of EPYC cpu models. The more details are in the bug https://bugzilla.redhat.com/show_bug.cgi?id=1728166. To fix the problem we need to build the topology as per the Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors. The documentation is available from the bugzilla Link below. Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 It is also available at https://www.amd.com/system/files/TechDocs/55570-B1_PUB.zip Here is the text from the PPR. Operating systems are expected to use Core::X86::Cpuid::SizeId[ApicIdSize], the number of least significant bits in the Initial APIC ID that indicate core ID within a processor, in constructing per-core CPUID masks. Core::X86::Cpuid::SizeId[ApicIdSize] determines the maximum number of cores (MNC) that the processor could theoretically support, not the actual number of cores that are actually implemented or enabled on the processor, as indicated by Core::X86::Cpuid::SizeId[NC]. Each Core::X86::Apic::ApicId[ApicId] register is preset as follows: • ApicId[6] = Socket ID. • ApicId[5:4] = Node ID. • ApicId[3] = Logical CCX L3 complex ID • ApicId[2:0]= (SMT) ? {LogicalCoreID[1:0],ThreadId} : {1'b0,LogicalCoreID[1:0]} The new apic id encoding is enabled for EPYC and EPYC-Rome models. Signed-off-by: Babu Moger Acked-by: Michael S. Tsirkin Acked-by: Igor Mammedov --- target/i386/cpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 19de79d01c..5d5734af76 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3921,6 +3921,7 @@ static X86CPUDefinition builtin_x86_defs[] = { .xlevel = 0x8000001E, .model_id = "AMD EPYC Processor", .cache_info = &epyc_cache_info, + .use_epyc_apic_id_encoding = 1, .versions = (X86CPUVersionDefinition[]) { { .version = 1 }, { @@ -4048,6 +4049,7 @@ static X86CPUDefinition builtin_x86_defs[] = { .xlevel = 0x8000001E, .model_id = "AMD EPYC-Rome Processor", .cache_info = &epyc_rome_cache_info, + .use_epyc_apic_id_encoding = 1, }, }; From patchwork Wed Mar 11 02:34:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A662313A4 for ; Wed, 11 Mar 2020 02:40:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C1E220637 for ; Wed, 11 Mar 2020 02:40:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="te+yGfOn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C1E220637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrId-00046U-Mw for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:40:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38278) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCn-0000p8-J3 for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCm-0008OH-CX for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:45 -0400 Received: from mail-dm6nam11on2050.outbound.protection.outlook.com ([40.107.223.50]:30681 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCm-0008ND-5d for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y4h01xljUYc34C/iZr7svZZF/e5of5WVxVuKQR6jtZXYAOM+lSn+nsL/rdNqFwZmF+wW1vFa6tJ02tsJbmtJoqxZ/iuwLDp69QCfeelBF3nLOvtqZW9IElpf1nEAOaJxK/g0qnVdctDu5Ca/mxIJK+Hgbx78FIvxRh36oJCB3Eh1jZsO0ryj/McWljsxH52haXyyO4XH4jLJbdSxH7lfS2r8NBTShGuuuxITzY6yFxNKPEAU8QBraCW8W7h2XT2M2Br2XOtKy+OgMivEMNNr8O4SnfTz0J7rRTCIxIASaPkMQ13TeiYDCB2AhgnKMu6HmCYrNNQncoVuSmz5ggAlGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kheVtia0FVluOWYg+yvdJxT0y1+9wRaQ7qR5fw59GBQ=; b=kqvRFsG2dWHEbpiKlr0mqm6dNek3MF1gE0EqNVj+8CVTiSJqW2R/yZ3ZytVu/oIGAnku8YW7Xmfb2MC6VALhpUjhJRTwXG/E9Cpp/5reowMgWQLIBxIu/+1AKneCx9PLjIp74avOBuE/QPmk5iUTqeeYAeSQ5raqdP8vBG1Z4sO9g0ZtMdaXFPE/SYc54DkXY/EAWe/uUm8bcM+6K87A/hjZLWqzGUl2KE6hJkgNm5rFG0vMbUMiIZ9yWQOB6LAHwR1dbtQ5/dQ9xFmzoV42OtA1f4Qb3XdU+8Kxb0IvwhrD+EjblR8CQrvnM3IVLqSKOVAyFselWCM/kzCTSJ14ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kheVtia0FVluOWYg+yvdJxT0y1+9wRaQ7qR5fw59GBQ=; b=te+yGfOnf7XIlguIg8c1tckS51cebLab6Xi1eNqMPpDErThKwgL9UU3LiKMCHBoM4b5UCWQ20H2LjLBNyDl2CFJvukTf9QOinFWcSgWWeKARe/qMXYJFSIXQbkObv7pU0uZNOw8OQlU1pF9ZWl5L/s8KSsm/w6Y7UGt4Tnvk8EI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:41 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:41 +0000 Subject: [PATCH v6 12/13] hw/i386: Move arch_id decode inside x86_cpus_init From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:39 -0500 Message-ID: <158389407977.22020.8482854741622304295.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR06CA0058.namprd06.prod.outlook.com (2603:10b6:3:37::20) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR06CA0058.namprd06.prod.outlook.com (2603:10b6:3:37::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.11 via Frontend Transport; Wed, 11 Mar 2020 02:34:40 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4e9a404d-4f95-4e3b-5f23-08d7c564c07b X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(66946007)(478600001)(316002)(4326008)(86362001)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k9NSR0E/9jKeNnUQmYG3vyOV97VlQj0mfEt+6EA7h9cmfjQZOcNwLx/ntJlfu3vbBweGIS1+zGGMvLawt7W2ZFPiyC1CAXvB8IIXJhdGE3JRmBT4XGSttCd/HitXnSwv7InU/t45nhTX1UYzEynwn0r2/oV+3li47vWTk8ip2m+ma9ihF+9qNryXdFHDYixlJHj/r44UsY20jUHC2kcPkal9dfuSzEutxi1sSHnNJAflhwURJdJHYFrxQgZQUDSbgYivlVvkaM8XrmhKDHEXXso9hd+VGYERbn26Evg2xYYeEOOzgkj95358kLTZ13Gj+0fuyGibyIOoSuL/I1YssLVLq1WAxgHdfwd41Wjj6j2BzAethJBFtm0gQ6hW+jE7Exmim/Vu8Lyh8gzqYRrT+iPvvyyzN0VmS0KFsEKnNRWbwCT70eGExQgO2TV7Pz2s X-MS-Exchange-AntiSpam-MessageData: jsx0OCbRzEivcj/0w+2lISoJmjogoTge14v+JZkjCQ3cawH0Zgs+MeXvM/o0AFK4WWRSKsaPEIre9u3jnyqOUEv0W1ixLKz0pG94vGWFH9O7t4JozOvcT6mhMPKNhUXiwlNorBQxlJVBwIPPHlMrAg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e9a404d-4f95-4e3b-5f23-08d7c564c07b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:41.4805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qb60H+wMPXjbxIMTeu8PmOa+YCapICs8y4QscUKTIr9Gh6W7QYgd6ez0gz692szk X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.223.50 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Apicid calculation depends on knowing the total number of numa nodes for EPYC cpu models. Right now, we are calculating the arch_id while parsing the numa(parse_numa). At this time, it is not known how many total numa nodes are configured in the system. Move the arch_id inside x86_cpus_init. At this time smp parse is already completed and numa node information is available. Signed-off-by: Babu Moger Acked-by: Michael S. Tsirkin --- hw/i386/x86.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index ad85347142..be93c1fd1b 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -140,6 +140,9 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) MachineState *ms = MACHINE(x86ms); MachineClass *mc = MACHINE_GET_CLASS(x86ms); + /* Check for apicid encoding */ + x86_check_apic_id_encoding(ms); + x86_cpu_set_default_version(default_cpu_version); /* @@ -153,6 +156,12 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms, ms->smp.max_cpus - 1) + 1; possible_cpus = mc->possible_cpu_arch_ids(ms); + + for (i = 0; i < ms->smp.cpus; i++) { + ms->possible_cpus->cpus[i].arch_id = + x86_cpu_apic_id_from_index(x86ms, i); + } + for (i = 0; i < ms->smp.cpus; i++) { x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); } @@ -177,8 +186,7 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx) init_topo_info(&topo_info, x86ms); assert(idx < ms->possible_cpus->len); - x86ms->topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id, - &topo_info, &topo_ids); + x86ms->topo_ids_from_idx(&topo_info, idx, &topo_ids); return topo_ids.pkg_id % ms->numa_state->num_nodes; } @@ -212,10 +220,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) ms->possible_cpus->cpus[i].type = ms->cpu_type; ms->possible_cpus->cpus[i].vcpus_count = 1; - ms->possible_cpus->cpus[i].arch_id = - x86_cpu_apic_id_from_index(x86ms, i); - x86ms->topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, - &topo_info, &topo_ids); + x86ms->topo_ids_from_idx(&topo_info, i, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id = true; ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id; if (x86ms->smp_dies > 1) { From patchwork Wed Mar 11 02:34:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Moger, Babu" X-Patchwork-Id: 11430573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFE1B14B7 for ; Wed, 11 Mar 2020 02:37:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5FB321927 for ; Wed, 11 Mar 2020 02:37:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="q97jvbb5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5FB321927 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrFl-00089J-R7 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 Mar 2020 22:37:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38362) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBrCx-00013g-GD for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBrCw-0008W7-6Q for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:55 -0400 Received: from mail-dm6nam11on2046.outbound.protection.outlook.com ([40.107.223.46]:6160 helo=NAM11-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBrCw-0008UC-0V for qemu-devel@nongnu.org; Tue, 10 Mar 2020 22:34:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jjUjk+RTs9c19vLsAiIUQRN4+tpSLQZzEik18VH1JBE08nz2qVGW26ypjP9b7GbDhm29GbJgWfNmtoGuPQT3RcPEICRjQ7AcIUFOwKcnOCwr3SVSjwAt0DCeyXz7tbTtfsnC543g7SxH2V5v99bK4ukA/NBtOw7kcmGdvs4JUIK7cwGUBK5FdmG224N3/ivTdPvAywT1T5x0eOKovdQcUd3hg9ZY2FnZoBHqbFqFawWjLpc0SOatxWiclQarlCw/o6pCuF5jtZW+JKuIZZ3ZKFpUgrnREotEtUpfEn5m6wfwSa6P1FUt5DRUY3i95dnJhJFI8GaR9qyO+yl0Dwr1Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8y3EZPQT1+kPHd47k2sB9bSXOhJOGW8qf3ckr7LOuCM=; b=gm0MhxZ9VjYqkyLEzSKe7jEl4ZL3g/5z0VRUekoFptA+RcOLAtcJ4UzHu12FVVS58v62lfqqzJmW9AQfjrc9EpHzilHYR6JA8O6NY/pDsEUEBBQCBzmRNjILQ3xBBkYF1FOkUSBT8qSui9/rSU9y5vyUnMtN4C/btvNVtaeKupbXUHT7nf74D8IvqAsqiXXfvy+x2ED/YWyEJ91613bSTvyBxm5vcY6I5l4ub5VvtAMPjiB1hco8LngMYyRaE2IeWGJHAZZackCylufjin8GHUMja6Xy6kBgWQ7CqyRcLK8SCJvfcLjw0IYRGYqD5/7nFuNHAdTncw4F2EkB7aCcTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8y3EZPQT1+kPHd47k2sB9bSXOhJOGW8qf3ckr7LOuCM=; b=q97jvbb5V39VZ85F6v6JUffTYb88VEkc6ZyCBv0gUBjGh4h63gf+KkDYlmbIQC6eRhocUqs/677MUVWKn4pB4pVl9yo2HI+4wii05t6yOP5UBSMhkAOF2Xqg1cAELyEo3RcpxoPzBajTPMxRMJRAAH9xNMXFGXhSoJ5fCwZJJdI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) by SN1PR12MB2575.namprd12.prod.outlook.com (2603:10b6:802:25::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17; Wed, 11 Mar 2020 02:34:48 +0000 Received: from SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93]) by SN1PR12MB2560.namprd12.prod.outlook.com ([fe80::382f:640c:215f:be93%5]) with mapi id 15.20.2793.013; Wed, 11 Mar 2020 02:34:48 +0000 Subject: [PATCH v6 13/13] i386: Fix pkg_id offset for EPYC cpu models From: Babu Moger To: ehabkost@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, imammedo@redhat.com Date: Tue, 10 Mar 2020 21:34:46 -0500 Message-ID: <158389408668.22020.13850625601123630051.stgit@naples-babu.amd.com> In-Reply-To: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> References: <158389385028.22020.7608244627303132902.stgit@naples-babu.amd.com> User-Agent: StGit/unknown-version X-ClientProxiedBy: DM5PR06CA0071.namprd06.prod.outlook.com (2603:10b6:3:37::33) To SN1PR12MB2560.namprd12.prod.outlook.com (2603:10b6:802:26::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from naples-babu.amd.com (165.204.78.2) by DM5PR06CA0071.namprd06.prod.outlook.com (2603:10b6:3:37::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2793.17 via Frontend Transport; Wed, 11 Mar 2020 02:34:47 +0000 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d64cd573-3cdd-4d69-4900-08d7c564c49b X-MS-TrafficTypeDiagnostic: SN1PR12MB2575:|SN1PR12MB2575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-Forefront-PRVS: 0339F89554 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(396003)(346002)(136003)(376002)(366004)(199004)(103116003)(81166006)(81156014)(8936002)(8676002)(7696005)(186003)(16526019)(66556008)(66476007)(2906002)(55016002)(5660300002)(52116002)(44832011)(956004)(66946007)(478600001)(316002)(4326008)(86362001)(26005)(170073001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2575; H:SN1PR12MB2560.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BCK01dbJUvIJ0iVHaxRgzsfOx8Cvw1pU4902r0g17P47TBPnVvbGKL+VjmN2gHxorpaj8fe/HwQTix0u88bSydISBF5Bvhb3et+v6MbT9OrG/Azw00Hr8EYCa4LhDhzyV+RNmXSdlFtqNzcgdhK29o/HP39PnZ+JNNxvOtoM0pZgnxnsVbr5g4O5ZL2N9aAmUCbmbBnOTMsNv9aXPZck7SG69T5dNInugNjbRwm4Xo95o/JzryLuUpeyqJps02/gWM2gJ2CtSKphtJAWFnI5yXnwMRWfl8KjM3ky3LL5BLtV3PEMSRqUh0AahFQx+wBa597VaC914vyw7gatq/p23X1y05U45lVoRuo3xB+kUDERkjF+pbx4zZBCZhaXk6D1gxy66g3dVrFagF7QsRayn+6NoQI6l0PtNPe7gemno0f7FvYMC33is9LNqeJe0hBSHTtco9MxV+3ndzn+qT8+tsk54bOGsb7UY8t/6CCsqFvyRszWUbSz0ZG5th7Vz4h1 X-MS-Exchange-AntiSpam-MessageData: jA5ga0pbh8Q0j4CQTKI3z/Wo8BHdrzHSXMgrKt7kp++ewt8mwhjEfoP7R7Yq8x81O+6OOYsVtIzBlot8V69Ou671ivEUwjzzHmDRFr8fVyUZYii/iOJbS7oqCCfrYeC+pGDUYHTuvFe1hIgDaqUygg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d64cd573-3cdd-4d69-4900-08d7c564c49b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2020 02:34:48.3506 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RWoTQecdLn9OF+4cvm43uB8X3BuEKRo+Y6yUj8tcPxPFQVp5EyybRrSrzTdBV4hz X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2575 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.223.46 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If the system is numa configured the pkg_offset needs to be adjusted for EPYC cpu models. Fix it calling the model specific handler. Signed-off-by: Babu Moger Reviewed-by: Igor Mammedov Acked-by: Michael S. Tsirkin --- hw/i386/pc.c | 1 + target/i386/cpu.c | 4 ++-- target/i386/cpu.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2d7d611184..ab6da19bab 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1526,6 +1526,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, env->nr_dies = x86ms->smp_dies; env->nr_nodes = topo_info.nodes_per_pkg; + env->pkg_offset = x86ms->apicid_pkg_offset(&topo_info); /* * If APIC ID is not set, diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5d5734af76..f205c56f9a 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5606,7 +5606,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *ecx |= CPUID_TOPOLOGY_LEVEL_SMT; break; case 1: - *eax = apicid_pkg_offset(&topo_info); + *eax = env->pkg_offset; *ebx = cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_CORE; break; @@ -5640,7 +5640,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *ecx |= CPUID_TOPOLOGY_LEVEL_CORE; break; case 2: - *eax = apicid_pkg_offset(&topo_info); + *eax = env->pkg_offset; *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_DIE; break; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 6e522fcd34..92872d2b7a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1610,6 +1610,7 @@ typedef struct CPUX86State { unsigned nr_dies; unsigned nr_nodes; + unsigned pkg_offset; } CPUX86State; struct kvm_msrs;