From patchwork Fri Sep 6 19:12:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11135863 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 1EFC715E6 for ; Fri, 6 Sep 2019 19:16:43 +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 D96C8206BB for ; Fri, 6 Sep 2019 19:16:42 +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="WQJHHJsL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D96C8206BB 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]:59568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6Jir-0007Kw-88 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Sep 2019 15:16:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42353) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6Jem-0002bN-VT for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6Jel-0004D2-6u for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:28 -0400 Received: from mail-eopbgr820050.outbound.protection.outlook.com ([40.107.82.50]:34880 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 1i6Jek-0004Cr-W3 for qemu-devel@nongnu.org; Fri, 06 Sep 2019 15:12:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RTT6ejQa+X488o3dcqdUmVkIxK3KB2+ycHniD5n7DsJ0sIZ5qYuSVv/jvSeL+IiNPn8nzTA8rAsjY2CeY5QgAzW0xaTQA0hqyjmCfkg9jU1yIxQOhV0K8U0b/Fb1QoGPyvvYIeLi5QL3BZ8yJ+gx2gUJDBfUn+lPnOQ9GiH2LrTatLMV0wFKROP16MtALiRhXl+gtVb8tKWIs3mdYx3jj75sMBk4R+uVHW4A+FkNcVqrW3J66116y1al8UrB50ek2twIf/X8x+2SmsczApCSCn1rLIGD97JQrM4RN+QuSmFZ8iaQCcfvdBmldl1ymOcsrlLCI3rhSR+vFsI8U55Egg== 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=RKSYjCHoLWPfY8NEMMvNduZzQLPSAI5hqsjfbCDTk3A=; b=EIdD/9OQ1GhhcsnuLiXYu0YGNNJYJCSyCHGb6AeIkzC4l2ExGvwOw3AWwMMefhUo4/NcUyjldM/kgDckwXRa3YOunQkfcQ/E1z7wHnUOkS+nds7bjkd/0+NWF1ctLNMbm1rm87hc9AtbQ4C2UHiaO6ssLHFXsmP4N7B/7Erp2EsRBI7IOGUQrn7fLr66XI/b0jWM0nYduQGY5Ov8MAWZZ7Nfdh6iZ3wtWvTP84liWYKZU/R2UVPlGEAV38NZo5wHbYpRh1LmEn+kUNr3yS08Des/ougWlPx8So/14v7EompCsEJT5JRr7DqBNfLunKMWhv8oeCUA0OuwCDr/wOeusQ== 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=RKSYjCHoLWPfY8NEMMvNduZzQLPSAI5hqsjfbCDTk3A=; b=WQJHHJsLXgsAKCA2zspUUMrnpZCJ7gUh+2U7BbWRCdc6f/TwAxw3oQ9cYzOmekVLGuZzLf/LuE5pw6BX0EJimJYzvwBftx94JVZ4MNLUtVmcyyMEtzkujs+Lc4YWJZXKYJZh+nn/taGxWhMZ0oEPmCRxlhWwMJ7+0Gp+2Y4Kj7c= 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:25 +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:25 +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 07/16] hw/386: Add new epyc mode topology decoding functions Thread-Index: AQHVZOcEityrOa9ypkyXmr/sF3Gefg== Date: Fri, 6 Sep 2019 19:12:25 +0000 Message-ID: <156779714362.21957.2682347975717100335.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: SN4PR0601CA0004.namprd06.prod.outlook.com (2603:10b6:803:2f::14) 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: ff7bec2b-4285-43ab-bc84-08d732fe26c2 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-ms-exchange-purlcount: 1 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:1002; 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)(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)(6306002)(53936002)(966005)(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: Tfq2H2jLhZ01g6EHT0dOPv61CPb55dDzSMN+KuMEVPOj4nRn6Rv9nAmjtochp5eRe+et5oCbtwIMMIdCF7q3Vo8aOqE7vw0eareFxsWqZAzyekliUL0/KurvO/mzQiniqjHwjRyotXplRHiU3vp5LNZSQ7L0Pr+eE5sQ4NZwidpqLaaJtAK6LMI33+skwSTL9mSk1qmtW9CbPGNDaQ+eaOThelIiWYanTWlVdX9SwITy54P4IHVeUEBPh14hQY8kIpzvgxITBjZeLDF2HvwHyfelM0xBdsgpoT/AFu3YgRMuUrHrCnKWu2sZjQ1EyT0tAngTuBZM+bgpONZmFMAbsKRQTn/2V7shajMXEfrU23ewWBfUxAwuGh0XzKcI4Eep20cUKAqHJxfQNxXF6gP54hB0Qb4VEOKEilNhnP8aPR0= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff7bec2b-4285-43ab-bc84-08d732fe26c2 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Sep 2019 19:12:25.1411 (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: gENzf0u0WsQ66HBiYHdb3LA0uHtvsUOYvOugkGmxtzSqQ2yLCRcUx1PgFQZETd/5 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.50 Subject: [Qemu-devel] [RFC 2 PATCH 07/16] hw/386: Add new epyc mode topology decoding 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" These functions add support for building new epyc mode topology given smp details like numa nodes, cores, threads and sockets. Subsequent patches will use these functions to build the topology. The topology details are available in Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors. It is available at https://www.amd.com/en/support/tech-docs Signed-off-by: Babu Moger --- include/hw/i386/topology.h | 174 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index 5a61d53f05..6fd4184f07 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -62,6 +62,22 @@ typedef struct X86CPUTopoInfo { unsigned nr_threads; } X86CPUTopoInfo; +/* + * 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 + /* Return the bit width needed for 'count' IDs */ static unsigned apicid_bitwidth_for_count(unsigned count) @@ -116,6 +132,164 @@ static inline unsigned apicid_pkg_offset(unsigned nr_dies, apicid_die_width(nr_dies); } +/* Bit offset of the CCX_ID field */ +static inline unsigned apicid_ccx_offset(unsigned nr_cores, + unsigned nr_threads) +{ + return apicid_core_offset(nr_threads) + + apicid_core_width(nr_cores); +} + +/* Bit width of the Die_ID field */ +static inline unsigned apicid_ccx_width(unsigned nr_ccxs) +{ + return apicid_bitwidth_for_count(nr_ccxs); +} + +/* Bit offset of the node_id field */ +static inline unsigned apicid_node_offset(unsigned nr_ccxs, + unsigned nr_cores, + unsigned nr_threads) +{ + return apicid_ccx_offset(nr_cores, nr_threads) + + apicid_ccx_width(nr_ccxs); +} + +/* Bit width of the node_id field */ +static inline unsigned apicid_node_width(unsigned nr_nodes) +{ + return apicid_bitwidth_for_count(nr_nodes); +} + +/* Bit offset of the node_id field */ +static inline unsigned apicid_pkg_offset_epyc(unsigned nr_nodes, + unsigned nr_ccxs, + unsigned nr_cores, + unsigned nr_threads) +{ + return apicid_node_offset(nr_ccxs, nr_cores, nr_threads) + + apicid_node_width(nr_nodes); +} + +/* + * Figure out the number of nodes required to build this config. + * Max cores in a nodes is 8 + */ +static inline int nodes_in_pkg(X86CPUTopoInfo *topo_info) +{ + /* + * Create a config with user given (nr_nodes > 1) numa node config, + * else go with a standard configuration + */ + if (topo_info->numa_nodes > 1) { + return DIV_ROUND_UP(topo_info->numa_nodes, topo_info->nr_sockets); + } else { + return DIV_ROUND_UP(topo_info->nr_cores, MAX_CORES_IN_NODE); + } +} + +/* + * 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_DIE 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 inline int cores_in_ccx(X86CPUTopoInfo *topo_info) +{ + int nodes; + + /* Get the number of nodes required to build this config */ + nodes = nodes_in_pkg(topo_info); + + /* + * Divide the cores accros all the core complexes + * Return rounded up value + */ + return DIV_ROUND_UP(topo_info->nr_cores, nodes * MAX_CCX); +} + +/* + * 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) +{ + unsigned nr_ccxs = MAX_CCX; + unsigned nr_nodes = nodes_in_pkg(topo_info); + unsigned nr_cores = MAX_CORES_IN_CCX; + unsigned nr_threads = topo_info->nr_threads; + + return (topo_ids->pkg_id << apicid_pkg_offset_epyc(nr_nodes, nr_ccxs, + nr_cores, nr_threads)) | + (topo_ids->node_id << apicid_node_offset(nr_ccxs, nr_cores, + nr_threads)) | + (topo_ids->ccx_id << apicid_ccx_offset(nr_cores, nr_threads)) | + (topo_ids->core_id << apicid_core_offset(nr_threads)) | + topo_ids->smt_id; +} + +static inline void x86_topo_ids_from_idx_epyc(X86CPUTopoInfo *topo_info, + unsigned cpu_index, + X86CPUTopoIDs *topo_ids) +{ + unsigned nr_cores = topo_info->nr_cores; + unsigned nr_threads = topo_info->nr_threads; + unsigned core_index = cpu_index / nr_threads % nr_cores; + unsigned ccx_cores = cores_in_ccx(topo_info); + + topo_ids->smt_id = cpu_index % nr_threads; + topo_ids->core_id = core_index % ccx_cores; /* core id inside the ccx */ + topo_ids->ccx_id = (core_index % (ccx_cores * MAX_CCX)) / ccx_cores; + topo_ids->node_id = core_index / (ccx_cores * MAX_CCX); + topo_ids->pkg_id = cpu_index / (nr_cores * 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) +{ + unsigned nr_nodes = nodes_in_pkg(topo_info); + unsigned nr_cores = MAX_CORES_IN_CCX; + unsigned nr_threads = topo_info->nr_threads; + unsigned nr_ccxs = MAX_CCX; + + topo_ids->smt_id = apicid & + ~(0xFFFFFFFFUL << apicid_smt_width(nr_threads)); + + topo_ids->core_id = (apicid >> apicid_core_offset(nr_threads)) & + ~(0xFFFFFFFFUL << apicid_core_width(nr_cores)); + + topo_ids->ccx_id = (apicid >> apicid_ccx_offset(nr_cores, nr_threads)) & + ~(0xFFFFFFFFUL << apicid_ccx_width(nr_ccxs)); + + topo_ids->node_id = (apicid >> apicid_node_offset(nr_ccxs, nr_cores, + nr_threads)) & + ~(0xFFFFFFFFUL << apicid_node_width(nr_nodes)); + + topo_ids->pkg_id = apicid >> apicid_pkg_offset_epyc(nr_nodes, nr_ccxs, + nr_cores, nr_threads); +} + +/* + * 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.