From patchwork Fri Sep 6 19:12:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11135871 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 70E461398 for ; Fri, 6 Sep 2019 19:20:30 +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 38A2D206BB for ; Fri, 6 Sep 2019 19:20:30 +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="mAtmrteC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38A2D206BB 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]:59602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6JmW-0002eK-W3 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Sep 2019 15:20:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42386) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6Jev-0002ly-9r for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6Jet-0004Fr-FR for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:37 -0400 Received: from mail-eopbgr820075.outbound.protection.outlook.com ([40.107.82.75]:54279 helo=NAM01-SN1-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 1i6Jet-0004F5-89 for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KmmODF7CAbQiRPcYPNoVL8u0ftEFwlVkuKoj9IraUn57IUY5q/pz/VwFK4CPEqdBqHipAQoKYSatnEqc0iyhwFBYCUxAjXWfWT4zjtcyCHHffGyv17OsCmdRLaJ51TDPeO/9nt6MDhv+SUpBTuymrZ2RU30wz54CSER2UwxYjCzOPg65T+T74u5HetJvq5x1vzGan34qB4wRk5XeAsa4GoT2ikA1TEuPXfkMxiX+qatmVS4i7aL467lAYjrbgZs/bn6GRR4eWxJeLpbj/G8ozzah5uNPi7w2PPpLkuRglYdbg3264JXF03hJ538n8mYrIGAHH+ND+QLGrzVSk/5mfw== 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=mOxzSPhHpOv/CCGwmUnyYDOfWEeoovk3/t3PSLSvz8I=; b=Wo9w4fisuZ1eYQFqoHY9iYzhasM+8wXr1DrkYqKrLLcU+5eAM56oZneTQssHZSWr6LYuIh392Me1tmfvo52L9hw+QW2Ss+B+NSSzhrQovsxMuPZa5bgLv3lzcvCuZ8y1wjq2qHYctL88syWEPjOE6DaFm5ZGs/bV1zVxSn66xOTYEFjaT26A1RuAe76R/9uuzq8vR3DPyX4nkxSkLJw4YSc3M3dvE0/AFjdfB19q6vhugAQcz40WvPjifvm2AKnZUwgCFl9AfVDg2QLmzCisZHCEfKnkWm+1aAY5/AgFvcgjPBcr7K8gLYFZekmC9teTUFo5codDUZwA1pwPyCMTiw== 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=mOxzSPhHpOv/CCGwmUnyYDOfWEeoovk3/t3PSLSvz8I=; b=mAtmrteClKnopmViV+ssdz8lamBy5Aau8VCJPMeaqiBevLCcmrbRQS/fYoBO70RhyGVtU5fk7Cw1PXx8zehbO8+JZBvSg2a57K7Zj6aYmJfipqfWgShT7/QypH+ZEtKlKuOXnwTRy8+BaJHIDNE/8OFSHO6oRLzuKlIlmvpH7Eg= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1179.namprd12.prod.outlook.com (10.168.234.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.14; Fri, 6 Sep 2019 19:12:33 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::6c7c:4b6d:f136:1bf8]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::6c7c:4b6d:f136:1bf8%3]) with mapi id 15.20.2220.022; Fri, 6 Sep 2019 19:12:33 +0000 From: "Moger, Babu" To: ssg.sos.staff , "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "eblake@redhat.com" , "armbru@redhat.com" , "imammedo@redhat.com" Thread-Topic: [RFC 2 PATCH 08/16] i386: Cleanup and use the new epyc mode topology functions Thread-Index: AQHVZOcJUr5O2hUIukO4Iv4t3TEIVA== Date: Fri, 6 Sep 2019 19:12:33 +0000 Message-ID: <156779715031.21957.17374671669134234845.stgit@localhost.localdomain> References: <156779689013.21957.1631551572950676212.stgit@localhost.localdomain> In-Reply-To: <156779689013.21957.1631551572950676212.stgit@localhost.localdomain> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0201CA0043.namprd02.prod.outlook.com (2603:10b6:803:2e::29) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 82f0a3e5-b343-4ba6-0a78-08d732fe2ad9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB1179; x-ms-traffictypediagnostic: DM5PR12MB1179: x-ld-processed: 3dd8961f-e488-4e60-8e11-a82d994e183d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3826; x-forefront-prvs: 0152EBA40F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(346002)(366004)(396003)(39860400002)(136003)(189003)(199004)(6116002)(103116003)(76176011)(305945005)(86362001)(256004)(14444005)(2201001)(71190400001)(71200400001)(81156014)(81166006)(2906002)(476003)(3846002)(446003)(8676002)(11346002)(486006)(102836004)(7736002)(6506007)(386003)(6486002)(26005)(8936002)(5660300002)(186003)(4326008)(66066001)(6436002)(14454004)(25786009)(52116002)(9686003)(6512007)(53936002)(99286004)(2501003)(110136005)(478600001)(316002)(66476007)(64756008)(66446008)(66556008)(66946007); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1179; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 84NGGFez93ks1F+zr+lG9uzFgsQQiljPAD0E7DCfVjqrLYaBi4cqsZuS6YE3VABKXw1K1kfGc/xkOQIcSkkun7RhhaSvZyFX39uxdGboQJY0wHzhtam4URSKpgLVfxyHbx3Jozkv/X8DTdwQ0+Ovvg8RhRiY/iQ5fM3EQ7tDDFhLJKquRKO5fQSIwPe+P39vP3FAv9DWn5Sw7VDIRDZPtq0i/Z2cqLVJ2CZlr88viYmBtSec4WQaQEHxg4JPmjtt82Uiq8+zlhx3ccOUQUX5sDz0IkCfR0O7Yxfb6VpuFNaXOyFAh5Tj8tWt5ZEBuRhC2LDPk9oATzLHNmKw2BcjeJU0XesKKH8JNxb9R3Mt3VDBnNivOWt8+feIuIo9JHmwbvq6wfz/4tQS/t0p9MQxLtR40jEwRUqIBuJG4WaWwpM= Content-ID: <2E1F7309F869144FA47702FF2F1055EF@namprd12.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82f0a3e5-b343-4ba6-0a78-08d732fe2ad9 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Sep 2019 19:12:33.2805 (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: u/VkRXBi/+kEcqF95VL3d+YixiYBeZq16C3MG4c3+5u5i/sKGx3A1GXuWUYE/UJ8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1179 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.82.75 Subject: [Qemu-devel] [RFC 2 PATCH 08/16] i386: Cleanup and use the new epyc mode topology functions 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 epyc mode functions and delete the unused code. Signed-off-by: Babu Moger --- target/i386/cpu.c | 171 +++++++++++++++-------------------------------------- 1 file changed, 48 insertions(+), 123 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ca02bc21ec..f25491a029 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -28,6 +28,7 @@ #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/cpus.h" +#include "sysemu/numa.h" #include "kvm_i386.h" #include "sev_i386.h" @@ -338,67 +339,19 @@ 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, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { + MachineState *ms = MACHINE(qdev_get_machine()); + X86CPUTopoInfo topo_info = { + .numa_nodes = nb_numa_nodes, + .nr_sockets = ms->smp.sockets, + .nr_cores = ms->smp.cores, + .nr_threads = ms->smp.threads, + }; + uint32_t l3_cores; assert(cache->size == cache->line_size * cache->associativity * cache->partitions * cache->sets); @@ -408,10 +361,10 @@ 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 = cores_in_ccx(&topo_info); + *eax |= ((l3_cores * topo_info.nr_threads) - 1) << 14; } else { - *eax |= ((cs->nr_threads - 1) << 14); + *eax |= ((topo_info.nr_threads - 1) << 14); } assert(cache->line_size > 0); @@ -431,56 +384,28 @@ 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, - uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx) +static void encode_topo_cpuid8000001e(CPUX86State *env, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { - struct core_topology topo = {0}; - unsigned long nodes; - int shift; + X86CPUTopoIDs topo_ids = { 0 }; + unsigned long nodes, shift; + X86CPU *cpu = env_archcpu(env); + CPUState *cs = env_cpu(env); + MachineState *ms = MACHINE(qdev_get_machine()); + X86CPUTopoInfo topo_info = { + .numa_nodes = nb_numa_nodes, + .nr_sockets = ms->smp.sockets, + .nr_cores = ms->smp.cores, + .nr_threads = ms->smp.threads, + }; + + nodes = nodes_in_pkg(&topo_info); + x86_topo_ids_from_idx_epyc(&topo_info, cs->cpu_index, &topo_ids); - build_core_topology(cs->nr_cores, cpu->core_id, &topo); *eax = cpu->apic_id; + /* * CPUID_Fn8000001E_EBX * 31:16 Reserved @@ -496,11 +421,12 @@ 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; + if (topo_info.nr_threads - 1) { + *ebx = ((topo_info.nr_threads - 1) << 8) | (topo_ids.node_id << 3) | + (topo_ids.ccx_id << 2) | topo_ids.core_id; } else { - *ebx = (topo.node_id << 4) | (topo.ccx_id << 3) | topo.core_id; + *ebx = (topo_ids.node_id << 4) | (topo_ids.ccx_id << 3) | + topo_ids.core_id; } /* * CPUID_Fn8000001E_ECX @@ -510,9 +436,8 @@ 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,12 +452,12 @@ 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 = 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; + } /* @@ -4580,19 +4505,19 @@ 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, + encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, cs, + encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, cs, + encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, cs, + encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -4602,7 +4527,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, + encode_topo_cpuid8000001e(env, eax, ebx, ecx, edx); break; case 0xC0000000: