From patchwork Wed Jul 31 23:20:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11069789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FCCF13AC for ; Wed, 31 Jul 2019 23:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 909D228173 for ; Wed, 31 Jul 2019 23:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 821EB282EC; Wed, 31 Jul 2019 23:23:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 146F9282EC for ; Wed, 31 Jul 2019 23:23:10 +0000 (UTC) Received: from localhost ([::1]:45012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxw5-0003LS-F8 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 19:23:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50783) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxtr-0006qI-J0 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsxtq-0008LC-E5 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:51 -0400 Received: from mail-eopbgr760058.outbound.protection.outlook.com ([40.107.76.58]:41104 helo=NAM02-CY1-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 1hsxtq-0008JS-97 for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YJWvKKkoK7Ni6rhi5lro38yANCdDXrw8prpruevS0FbTTQdVrT2igKISQlOFiMDTcVd1ufHCuiw3YtnNqHPqWYCFVrpojamN1OusMxuFz/PfUkmKb0rKMgUyB8zEsNn0ptteuK0E1A4j+BYXnVKBNSwBL7IYY3MnpWsFG1ev/JqnL0dzxr3LhWUFxJugV/Lmw8XHEpkd9e8DLtE3dc7Si3SxvE8VAPfkrNOI87uYtOXaM18YSzlOV/6G8tlB1aCmhMOGcV4ZsavILcRvefP7gC0OEqAw7OcAvKW9xLPl/NdqmufxPPiPpzkA2LlTd8wr70cKPshD3FjGtzt/SDearA== 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=c6sFDgWbAq8TJDAg7wykmL5vrYP49jvqWhrlVCwSXwk=; b=TeDSb3Y6gM+bigz4d6sHrnwBtzzIKYLR3gyV3UhpoaVtQg6n/ItSSuWRsi3Ujdi/ixOlWrx1zV5Hn7lV8eUmRgKsyCEZ7xNGH5whJL04nubUA7HvTPXhGQ7BdBVfTlHHiuOEVjC59+UMD3cgyaDaKYs6ugis3PNkIuG4BhkmRW11y6sFyS3Ku3myFP5VSSQUhGiXGNvvSDxfguusmxe7lHvreymMNd7BSMiOnCMaC3TKeVyqv6sMs2jRWJYmDKcXLoKJHvU5VEZODU36ZLw5E8hyx+nJxtLpG+HJmCJsjDm1XAPo68WvbeDM60KCBl3IcJOLOfR4SrdJJlI3Qrot+g== 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=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c6sFDgWbAq8TJDAg7wykmL5vrYP49jvqWhrlVCwSXwk=; b=sZ4SZqV6dTI3UT73NY+c0SONuFxQXSSUdC7savJOfRQ7nXBWpr5Oz0PNuXqBrguWYVZcmnjlt6AcpN51omK3MjZTB8k/KExbUXw2abRA0H7jXkPbj/EKNlPymj6PBuFDTFGoKCB8kVJAtK9RF8ztrRRn7YFNGIDlY8JeRxTK3yI= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2550.namprd12.prod.outlook.com (52.132.141.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Wed, 31 Jul 2019 23:20:47 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67%7]) with mapi id 15.20.2136.010; Wed, 31 Jul 2019 23:20:47 +0000 From: "Moger, Babu" To: "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "imammedo@redhat.com" Thread-Topic: [RFC PATCH 1/5] hw/boards: Add sockets in CpuTopology structure Thread-Index: AQHVR/aVBapKuUuGJEu2eneWm/XN9Q== Date: Wed, 31 Jul 2019 23:20:46 +0000 Message-ID: <20190731232032.51786-2-babu.moger@amd.com> References: <20190731232032.51786-1-babu.moger@amd.com> In-Reply-To: <20190731232032.51786-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) 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-mailer: git-send-email 2.20.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 733e30e4-3113-4b40-7eff-08d7160db793 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB2550; x-ms-traffictypediagnostic: DM5PR12MB2550: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4714; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39860400002)(346002)(136003)(376002)(366004)(199004)(189003)(8936002)(7736002)(2501003)(50226002)(36756003)(1076003)(11346002)(8676002)(6436002)(81166006)(81156014)(305945005)(68736007)(54906003)(110136005)(53936002)(6486002)(66066001)(478600001)(64756008)(2906002)(316002)(5660300002)(14454004)(66556008)(102836004)(386003)(256004)(71200400001)(6506007)(71190400001)(86362001)(486006)(26005)(99286004)(76176011)(186003)(66476007)(3846002)(66946007)(4326008)(6512007)(66446008)(6116002)(2201001)(25786009)(2616005)(476003)(52116002)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2550; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: 2Pdz3eTAKr2RauXl+VnD3iM18EvCnhAk46McAdkjcZ5QCR63FcxSz6jIMiUdl2qhsfqD6p3zP0QskZluqXvzCvPu7b0CuInz4FmFo/R6TbEVWKV/Jz1+zED2BATGmiEgjRBmYdETXDqpASKG+V6a074LC9YNbpeKu2h2LIBupCYTFzgLktlmkExpn6XEyxHHC3RfSsqM7FyAGtsXx89aANPNYQamANL5AJc39dlom7OlmbJp4jrwOPs2wjepMZ9HZcJvmE/fi0/z1fQ9vZvJCZhhBuhdRUz0tEEiflUZSHbffyb+3WIXK/aeOh0gVZZfX/MaRV8/BHL62lmAFt0WLwV5y4GLDc6PgS10JgkPe4dyT3WkE+oMuVgUbvYmKxSNEgjfBENFkrGXuVjYKqfgZ54VZn/BB9BqiCGR8bzCSbo= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 733e30e4-3113-4b40-7eff-08d7160db793 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2019 23:20:46.9935 (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: bmoger@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2550 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.76.58 Subject: [Qemu-devel] [RFC PATCH 1/5] hw/boards: Add sockets in CpuTopology structure 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: "Moger, Babu" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add sockets in CpuTopology. This is required when building the CPU topology. Signed-off-by: Babu Moger --- hw/core/machine.c | 1 + hw/i386/pc.c | 1 + include/hw/boards.h | 2 ++ vl.c | 1 + 4 files changed, 5 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index c58a8e594e..4034b7e903 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -795,6 +795,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 549c437050..ef39463fd5 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1605,6 +1605,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; pcms->smp_dies = dies; } diff --git a/include/hw/boards.h b/include/hw/boards.h index a71d1a53a5..12eb5032a5 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -245,12 +245,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/vl.c b/vl.c index b426b32134..d8faf5ab43 100644 --- a/vl.c +++ b/vl.c @@ -3981,6 +3981,7 @@ int main(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 Jul 31 23:20:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11069779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E073D13B1 for ; Wed, 31 Jul 2019 23:21:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB49D27FE4 for ; Wed, 31 Jul 2019 23:21:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEFBF282E8; Wed, 31 Jul 2019 23:21:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC71F282E8 for ; Wed, 31 Jul 2019 23:21:29 +0000 (UTC) Received: from localhost ([::1]:44986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxuS-0008WV-Kt for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 19:21:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50805) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxts-0006rg-EF for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsxtq-0008LZ-OA for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:52 -0400 Received: from mail-eopbgr760058.outbound.protection.outlook.com ([40.107.76.58]:41104 helo=NAM02-CY1-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 1hsxtq-0008JS-Il for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BX1ByXTU4KUd2BQbgw9jN8kNgOsPs0dlpcd1zYr7YXyDzMjW5yyGirBolU8NMoY4+f6xN6lzZLisuhMcIIDCGtJ7v0RIJ2GWVicr1ow5tmOyJql2W/5m956gCPOdfW1GtvAoeuP+9gRH5R5wlqq42cYorphGc99PRbcEpCQahwLBxJB7Gy27pLksBQaaYN40zlxT0SijsZ0BUWwuk2VP/N248r7FUoIZgY2P4nEZtW6NHSsS1RbN0I1Cth3jGhavq3H9tW54fKYufkOe8JKQ/egArlq1fDHBG2d6g8k/O3ySA2ow+aNVXdqLGwxbiD+CLkejcT6yNPFMWW7hVEBBSw== 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=lFwLwbGIMSPg67QIr8CTwZREW/AKNOazu3DwwETQysM=; b=YFqaOt1pgb33QXyoc8hV4/BZmiq8QMv1WX5yqHYNh1QNs/dj3XvrrQ+V2kcZHGGlh2lWOzClR6km9Dg/LgKhdF2OCBncndSdAjxJ6/ByjgxIgy78uu/Ul1RrCkhu29y5KSJ+lTjTbrc4Jd3SmwQCXLiZWzYgg0Dbg9z+YW+tUeGUwS4J8VsHIO59l3+ZtgdzjKWFxGzBm4FB7dNLhUk4mkW3PUQ12tiDww35uzVwTTtJ5AlQQHiAPbepenv6nnLut27qeCv8pE7xKJ2MLshz6jvsaIUszEawN/3xfygMBL9lhc4qARx0HRhbPN8AhorsEScnR+jDXNa2TTlSxc16Tw== 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=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lFwLwbGIMSPg67QIr8CTwZREW/AKNOazu3DwwETQysM=; b=Hztx48zrJMYL+bKfRAUWFNcyci+lODeY9VGhZd0P1dlNtcCAIMSCr39tbh6a1fKOgzFNeWOXEiJZZjMhyrrmRiZ10rfMT+4Ov7vaWbRbPTiZmvQHNtlNYsYjIy1xHMOIzCXeWa+eOC5tDhUFXf95iezuUQaY4ko6NT6vjKFXhOQ= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2550.namprd12.prod.outlook.com (52.132.141.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Wed, 31 Jul 2019 23:20:48 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67%7]) with mapi id 15.20.2136.010; Wed, 31 Jul 2019 23:20:48 +0000 From: "Moger, Babu" To: "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "imammedo@redhat.com" Thread-Topic: [RFC PATCH 2/5] hw/i386: Add AMD EPYC topology encoding Thread-Index: AQHVR/aV9ViYHJWvEUuFAqiDPvghww== Date: Wed, 31 Jul 2019 23:20:48 +0000 Message-ID: <20190731232032.51786-3-babu.moger@amd.com> References: <20190731232032.51786-1-babu.moger@amd.com> In-Reply-To: <20190731232032.51786-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) 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-mailer: git-send-email 2.20.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 272570c1-5ca8-4dcd-0619-08d7160db843 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB2550; x-ms-traffictypediagnostic: DM5PR12MB2550: x-ms-exchange-purlcount: 1 x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2000; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39860400002)(346002)(136003)(376002)(366004)(199004)(189003)(8936002)(7736002)(2501003)(50226002)(36756003)(1076003)(11346002)(8676002)(6436002)(81166006)(81156014)(305945005)(68736007)(54906003)(110136005)(53936002)(6486002)(66066001)(478600001)(64756008)(2906002)(316002)(5660300002)(14454004)(66556008)(102836004)(386003)(14444005)(256004)(71200400001)(6506007)(71190400001)(86362001)(486006)(26005)(99286004)(76176011)(186003)(66476007)(3846002)(66946007)(4326008)(6512007)(966005)(66446008)(6116002)(2201001)(25786009)(2616005)(476003)(52116002)(446003)(6306002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2550; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: gNs4PldozFdfMO+ZAIGwBxvuzWsa2Id4AMolHT15wwnfBRF1DJnDXRhFCuFTpEBfGGt7I5WkDOyuYk1wAJvN1PvsFQk34XxI89guogRbwuwOiw6ALyzDoMg9xq0YYhnNzywv2xeBW3XmR6Wm68+J6QB0p0Zya0ry8Es+tPbt+JgHeDo1+u0mI3uKBiGBYu5wYz2V3fVgg6VAHJxNVvs7Ytd5I42oVi1rS7Vp0+yDgrJScRPrTrPYMZOB6qENtsNR/m09pKo6ePSTrlWpcll21/NcuhCi+KCsE4McW6URI3YBxcAgkGGoCAMXqC9jMtK0ngE85EMWDI2AOMcOT+cm8/LmTNW9aVg+riRNDfv9oisGfX7tq1Np9xIWTb/gM/qVCHf5xgzgrVyNoVjCp7yRLfhWThZQ8KUwxCfaC0ZauSQ= Content-ID: <9BA5D2A2B9BAEC42ACECB7AB2341A41C@namprd12.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 272570c1-5ca8-4dcd-0619-08d7160db843 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2019 23:20:48.1448 (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: bmoger@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2550 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.76.58 Subject: [Qemu-devel] [RFC PATCH 2/5] hw/i386: Add AMD EPYC topology encoding 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: "Moger, Babu" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, the apicid is a sequential number in x86 cpu models. This works fine for most of the cases. But, in certain cases this will result into cpu topology inconsistency. This problem was observed in AMD EPYC cpu models. To address that we need to build apicid as per the hardware specification. We are attempting to build the topology close to the hardware as much as possible. Per Processor Programming Reference (PPR) for AMD Family 17h Models, we need to follow the following decoding. 2.1.10.2.1.3 ApicId Enumeration Requirements Operating systems are expected to use Core::X86::Cpuid::SizeId[ApicIdCoreIdSize], 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[ApicIdCoreIdSize] 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]}. Add the structures and functions to decode the ApicId for AMD EPYC models. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1728166 Signed-off-by: Babu Moger --- include/hw/i386/topology.h | 140 +++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index 4ff5b2da6c..0b2fd46b41 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -50,6 +50,7 @@ typedef struct X86CPUTopoInfo { unsigned die_id; unsigned core_id; unsigned smt_id; + unsigned ccx_id; } X86CPUTopoInfo; /* Return the bit width needed for 'count' IDs @@ -179,4 +180,143 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_dies, return apicid_from_topo_ids(nr_dies, nr_cores, nr_threads, &topo); } +/* 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_DIE 8 +#define CCX_OFFSET_EPYC 3 +#define DIE_OFFSET_EPYC 4 +#define PKG_OFFSET_EPYC 6 + +/* Figure out the number of dies required to build this config. + * Max cores in a die is 8 + */ +static inline int dies_in_socket(int numa_nodes, int smp_sockets, int smp_cores) +{ + /* + * Create a config with user given (nr_nodes > 1) numa node config, + * else go with a standard configuration + */ + if (numa_nodes > 1) + return DIV_ROUND_UP(numa_nodes, smp_sockets); + else + return DIV_ROUND_UP(smp_cores, MAX_CORES_IN_DIE); +} + +/* 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(int numa_nodes, int smp_sockets, int smp_cores) +{ + int dies; + + /* Check if we can fit all the cores in one core complex */ + if (smp_cores <= MAX_CORES_IN_CCX) { + return smp_cores; + } + + /* Get the number of nodes required to build this config */ + dies = dies_in_socket(numa_nodes, smp_sockets, smp_cores); + + /* + * Divide the cores accros all the core complexes + * Return rounded up value + */ + return DIV_ROUND_UP(smp_cores, dies * MAX_CCX); +} + +/* 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, + unsigned smp_dies, + unsigned smp_cores, + unsigned smp_threads, + X86CPUTopoInfo *topo) +{ + topo->smt_id = apicid & + ~(0xFFFFFFFFUL << apicid_smt_width(smp_dies, smp_cores, smp_threads)); + topo->core_id = (apicid >> apicid_core_offset(smp_dies, smp_cores, smp_threads)) & + ~(0xFFFFFFFFUL << apicid_core_width(smp_dies, smp_cores, smp_threads)); + topo->ccx_id = (apicid >> CCX_OFFSET_EPYC) & 1; + topo->die_id = (apicid >> DIE_OFFSET_EPYC) & 3; + topo->pkg_id = apicid >> PKG_OFFSET_EPYC; +} + +/* Calculate thread/core/package IDs for a specific topology, + * based on (contiguous) CPU index + * Processor Programming Reference (PPR) for AMD Family 17h Model 01h, + * Revision B1 Processors + * ApicId Enumeration Requirements + • 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]}. + */ +static inline void x86_topo_ids_from_idx_epyc(unsigned numa_nodes, + unsigned smp_sockets, + unsigned smp_cores, + unsigned smp_threads, + unsigned cpu_index, + X86CPUTopoInfo *topo) +{ + unsigned core_index = cpu_index / smp_threads; + unsigned core_id = core_index % smp_cores; /* Core id inside the socket */ + unsigned ccx_cores; + + topo->smt_id = cpu_index % smp_threads; + + ccx_cores = cores_in_ccx(numa_nodes, smp_sockets, smp_cores); + + topo->core_id = core_id % ccx_cores; /* core id inside the ccx */ + topo->ccx_id = (core_id % (ccx_cores * MAX_CCX)) / ccx_cores; + topo->die_id = core_id / (ccx_cores * MAX_CCX); + topo->pkg_id = core_index / smp_cores; +} + +/* 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 apicid_from_topo_ids_epyc(unsigned smp_cores, + unsigned smp_threads, + const X86CPUTopoInfo *topo) +{ + if (smp_threads - 1) + return ((topo->pkg_id << PKG_OFFSET_EPYC) | (topo->die_id << DIE_OFFSET_EPYC) | + (topo->ccx_id << CCX_OFFSET_EPYC) | (topo->core_id << 1) | (topo->smt_id)); + else + return ((topo->pkg_id << PKG_OFFSET_EPYC) | (topo->die_id << DIE_OFFSET_EPYC) | + (topo->ccx_id << CCX_OFFSET_EPYC) | (topo->core_id)); +} + +/* 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(unsigned numa_nodes, + unsigned smp_sockets, + unsigned smp_cores, + unsigned smp_threads, + unsigned cpu_index) +{ + X86CPUTopoInfo topo; + x86_topo_ids_from_idx_epyc(numa_nodes, smp_sockets, smp_cores, smp_threads, + cpu_index, &topo); + return apicid_from_topo_ids_epyc(smp_cores, smp_threads, &topo); +} + #endif /* HW_I386_TOPOLOGY_H */ From patchwork Wed Jul 31 23:20:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11069781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CF7213AC for ; Wed, 31 Jul 2019 23:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DD0D27CF3 for ; Wed, 31 Jul 2019 23:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71D4F2832D; Wed, 31 Jul 2019 23:21:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9D8B327CF3 for ; Wed, 31 Jul 2019 23:21:30 +0000 (UTC) Received: from localhost ([::1]:44988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxuT-000079-Ts for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 19:21:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50808) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxts-0006se-Lm for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsxtr-0008M0-1p for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:52 -0400 Received: from mail-eopbgr760058.outbound.protection.outlook.com ([40.107.76.58]:41104 helo=NAM02-CY1-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 1hsxtq-0008JS-Ss for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=leiY34j72zbbc8NX8CFK6Ba2R7ZQft53ntxckw0odXjupsWFOzQrsG1OFw4+mUbMVV11g9xzihC3ka/m1AutWc2efJb79Fb4oXTOaOUJa8EtWcBpIwix/BASB+ZCHEj8RH1pgvh9vNUhkXsyOmGgxatA05R6hiL6AIMQytPLCIenCLsIEGqj/52IS8ohKcmlPpynrtWkvJgF990cae2BvX0URIF5AHVzf3Q53qQ+2knpakTUHlJyM7LJ4+03FX1vhOveXEJ/dNTXVVzlsPenl/DKcU5hWqNKganwOEafNiMhK4HZjofnWFa354g+q77KminlLvdeh4BppHeD0nVIgQ== 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=Av6BCYbfU5SJ4uPC2uqYfZPaoz2uPjANkK0ldpN2Zu4=; b=NqueLdJA26AGZDB0Zp8bjtb4bqzfKCfkgLZgJUIB6MP0N9di9Om5y0ox5/6N4xlvvfSv9QeX9AF3y8AfB3yxoae4LBg9C1lxY5AnxQGo8nhqUDxfcjTJrQ1vweWcCsRQpAMGcvZLRt28Sk1VjxylwG2PJK70NPF8/P3XyCBBLbJZT/CQJKRMVGxNwoltgi+Ek0JYkmbRwKoKoC7apGSXvqS7MiHodvjBJ8F3JurYiZMMwbS10ivEVDEf2zB66oMocqCPRvf2XSIIgP3XPWTYnbQj7dNmzKs+Bv/Dpi+Ys/VE2F+nReUrEt2zZtLIbQl+4QOy+rrL+7hyZwXc+7v01g== 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=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Av6BCYbfU5SJ4uPC2uqYfZPaoz2uPjANkK0ldpN2Zu4=; b=QIMPGKyoxfKgiHD94ur8hNKoL4cnYFoNq6i0x+1qIJx4ktiIKhqXd/BXdqnrOG3FjrVrxOx8a96vjXn1RT/YdIb/JDIoaT+j2dRU2GGhtc71CKakYHqeIxWDz65RCX8tm+2QZhsuClR6ygmacni04C3qRCrHo88KAXCPUa8Z1r8= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB2550.namprd12.prod.outlook.com (52.132.141.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Wed, 31 Jul 2019 23:20:49 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67%7]) with mapi id 15.20.2136.010; Wed, 31 Jul 2019 23:20:49 +0000 From: "Moger, Babu" To: "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "imammedo@redhat.com" Thread-Topic: [RFC PATCH 3/5] i386: Use topology functions from topology.h Thread-Index: AQHVR/aW8Ua7gUfnaUKb5pcZCkrx1A== Date: Wed, 31 Jul 2019 23:20:49 +0000 Message-ID: <20190731232032.51786-4-babu.moger@amd.com> References: <20190731232032.51786-1-babu.moger@amd.com> In-Reply-To: <20190731232032.51786-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) 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-mailer: git-send-email 2.20.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4092d601-e9d3-4388-ec92-08d7160db8f3 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB2550; x-ms-traffictypediagnostic: DM5PR12MB2550: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3826; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39860400002)(346002)(136003)(376002)(366004)(199004)(189003)(8936002)(7736002)(2501003)(50226002)(36756003)(1076003)(11346002)(8676002)(6436002)(81166006)(81156014)(305945005)(68736007)(54906003)(110136005)(53936002)(6486002)(66066001)(478600001)(64756008)(2906002)(316002)(5660300002)(14454004)(66556008)(102836004)(386003)(256004)(71200400001)(6506007)(71190400001)(86362001)(486006)(26005)(99286004)(76176011)(186003)(66476007)(3846002)(66946007)(4326008)(6512007)(66446008)(6116002)(2201001)(25786009)(2616005)(476003)(52116002)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2550; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: thyc5x66iKW3qBcHIuwmhTiijhLI2kCqAXuB/Ud9tz0lMnOLdhx7SfkLtORw72842z4/BLkWQNL1b5hgFkYn/T8yNVOCbpVjiWKlTy5/8k9EBxVyTHuLAgPkW0QM1Y7E5x0EOYIYzjIB95EMNhU5mgG7jIepIQJee07mkRDvaYyEw6YJ7lXzuqvbw+DqCSmOHoLVGYCkxCh3o0T+aHV7u0Bo7GgyppU9UrtBK83VHHZAeGKZ8PsXfaQppqnTrZpZXSP2NBFZPnfPL5q9qOWBkhKvwVCADIrW2Ej6vKrdwn4KocB2BC6z1T0V6/R5bfWS22dhixUMzinR6v7ZXhxvJbWcp+9fC+Yv0chkmF2plXoJuj5ozXqN/nL5TZ9cfOPdZDWX9l6eBrHT/keIRIaeES1m3koDWSD6o4quNcpM2Io= Content-ID: <2A245B38C2352846B0BA0A59F72C8E74@namprd12.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4092d601-e9d3-4388-ec92-08d7160db8f3 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2019 23:20:49.2312 (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: bmoger@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2550 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.76.58 Subject: [Qemu-devel] [RFC PATCH 3/5] i386: Use topology functions from topology.h 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: "Moger, Babu" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the functions defined in topology.h and remove the old code. Signed-off-by: Babu Moger --- target/i386/cpu.c | 146 +++++++++------------------------------------- 1 file changed, 27 insertions(+), 119 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 19751e37a7..be4583068c 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,64 +339,8 @@ 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, +static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, MachineState *ms, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { @@ -408,10 +353,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(nb_numa_nodes, ms->smp.sockets, ms->smp.cores); + *eax |= ((l3_cores * ms->smp.threads) - 1) << 14; } else { - *eax |= ((cs->nr_threads - 1) << 14); + *eax |= ((ms->smp.threads - 1) << 14); } assert(cache->line_size > 0); @@ -431,55 +376,19 @@ 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(MachineState *ms, X86CPU *cpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { - struct core_topology topo = {0}; - unsigned long nodes; - int shift; + X86CPUTopoInfo topo = {0}; + unsigned long dies, temp_dies, shift; + CPUX86State *env = &cpu->env; + + dies = dies_in_socket(nb_numa_nodes, ms->smp.sockets, ms->smp.cores); + x86_topo_ids_from_apicid_epyc(cpu->apic_id, env->nr_dies, ms->smp.cores, + ms->smp.threads, &topo); - build_core_topology(cs->nr_cores, cpu->core_id, &topo); *eax = cpu->apic_id; /* * CPUID_Fn8000001E_EBX @@ -496,11 +405,11 @@ 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) | + if (ms->smp.threads - 1) { + *ebx = ((ms->smp.threads - 1) << 8) | (topo.die_id << 3) | (topo.ccx_id << 2) | topo.core_id; } else { - *ebx = (topo.node_id << 4) | (topo.ccx_id << 3) | topo.core_id; + *ebx = (topo.die_id << 4) | (topo.ccx_id << 3) | topo.core_id; } /* * CPUID_Fn8000001E_ECX @@ -510,9 +419,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 (dies <= 4) { + *ecx = ((dies - 1) << 8) | (topo.pkg_id << 2) | topo.die_id; } else { /* * Node id fix up. Actual hardware supports up to 4 nodes. But with @@ -527,10 +435,9 @@ 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; - shift = find_last_bit(&nodes, 8); - *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << (shift + 1)) | - topo.node_id; + temp_dies = dies - 1; + shift = find_last_bit(&temp_dies, 8); + *ecx = ((dies - 1) << 8) | (topo.pkg_id << (shift + 1)) | topo.die_id; } *edx = 0; } @@ -4169,6 +4076,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { + MachineState *ms = MACHINE(qdev_get_machine()); X86CPU *cpu = env_archcpu(env); CPUState *cs = env_cpu(env); uint32_t die_offset; @@ -4584,19 +4492,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, ms, 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, ms, 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, ms, 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, ms, eax, ebx, ecx, edx); break; default: /* end of info */ @@ -4606,7 +4514,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(ms, cpu, eax, ebx, ecx, edx); break; case 0xC0000000: From patchwork Wed Jul 31 23:20:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11069783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8839D13B1 for ; Wed, 31 Jul 2019 23:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 794F027F81 for ; Wed, 31 Jul 2019 23:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DEDF28346; Wed, 31 Jul 2019 23:21:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFD0827F81 for ; Wed, 31 Jul 2019 23:21:33 +0000 (UTC) Received: from localhost ([::1]:44990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxuX-0000I0-7D for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 19:21:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50844) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxtv-0006zg-Lc for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsxtu-0008R6-2X for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:55 -0400 Received: from mail-eopbgr720053.outbound.protection.outlook.com ([40.107.72.53]:30923 helo=NAM05-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 1hsxtt-0008P5-PC for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PngItcifDRi5l8sUtacs7MfSNn1tHA6Yz6sxOLyaNn9Zhq5XaTLVgB97hsjeZOyRtm0KmrsT8cdnKytwYZ2Wgvd21EO4xazQwor/2y9/jnL9zoPS5qLjOjYxOTtj5p86fcu+VVm6Cb8wGmXoD+4bgN9Z70s7XLkF91qxPo68gdlXd5Nbj1ImW21VPijZrfwx7mI91bihjqSR8/x3GI23yw+W46J09ZJK/waHIrn4L010JydJZ+dFaf/BgqTG3DKcpFtK/KGUBgEQPXxcvub5zufLb7emwIIcv9o+WEc6pYPThl1j36MMssFU41aQOISI88+7cnGfTttLzw9nYDYFpw== 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=UnDxsRvroJRPcCLozpmbXk4usK3uhc1+r25Diea4d2I=; b=c0HQJZQe8/m2pafNFqB+8V1wO34iDEtUAtp8djUt3JiTd5HbZ62q+TgBTrLYVZhSZ+hJtR25B0MflkHpgWdRWWAw1KY79f4haAO+xnsib4cLrpAoELf/5q04JdKivaItEDY2aHxHtIdOeByKAvDoyLvvM7NB0piR1UMhB7zaEiA8wkcnuItwKxD6OWdNVYpyjaJyo7WaqH4uQuJvjNZJg+nS7Vmy0JIVwi8yqSUdmODx3G+RV0Tv0p1B248cmPf9N5RcthPAVaXvLOjotF6vq1a/mWxZJ/osoZf0JXy+LtO33/OzaLLtq/wXinFUM8gbHYR+RkQcfvIe4Fz29mk7nQ== 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=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UnDxsRvroJRPcCLozpmbXk4usK3uhc1+r25Diea4d2I=; b=SSNJMk+t/+RVggw5MFE4N8zGzt47ZotMQcwCAoL+JI2P1gw3J7N084VvZLCYZqJpojPwF2EinpYCNIHzmkp9imZ2ud2bjKU2bygd508GrINtY4h/itbQZB3C/CfqvcQm0DFfH4sHk/WXig7fAp4Fe8XMlFYJQ3cFR3HTeZKBJNM= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1657.namprd12.prod.outlook.com (10.172.38.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Wed, 31 Jul 2019 23:20:50 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67%7]) with mapi id 15.20.2136.010; Wed, 31 Jul 2019 23:20:50 +0000 From: "Moger, Babu" To: "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "imammedo@redhat.com" Thread-Topic: [RFC PATCH 4/5] hw/i386: Generate apicid based on cpu_type Thread-Index: AQHVR/aXbkLSW+hCAEaO8Uc/WmhXTw== Date: Wed, 31 Jul 2019 23:20:50 +0000 Message-ID: <20190731232032.51786-5-babu.moger@amd.com> References: <20190731232032.51786-1-babu.moger@amd.com> In-Reply-To: <20190731232032.51786-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) 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-mailer: git-send-email 2.20.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bcd9c1e5-0831-4207-afd3-08d7160db9ab x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB1657; x-ms-traffictypediagnostic: DM5PR12MB1657: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2657; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(346002)(39860400002)(376002)(136003)(396003)(366004)(199004)(189003)(50226002)(7736002)(316002)(14444005)(256004)(102836004)(2201001)(66446008)(66556008)(6506007)(54906003)(2616005)(66476007)(76176011)(66066001)(1076003)(2906002)(8676002)(446003)(26005)(66946007)(53936002)(476003)(2501003)(305945005)(110136005)(64756008)(52116002)(4326008)(81156014)(68736007)(86362001)(14454004)(6512007)(386003)(99286004)(25786009)(11346002)(3846002)(6436002)(71200400001)(71190400001)(36756003)(6116002)(81166006)(8936002)(6486002)(478600001)(486006)(186003)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1657; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: daOIdJK4L8Ue4waZFU6hO0FgYUDv0xPgvbEQ8+QQcizO6FDF+5pcBrTKzX/dpcSrQ7KtRUsoVQAyP/yJsVrL9rX3ebqAXkNnfGVUJ0vPiBYwusRhDfq7k/kc/u+1QwdVzkFHYnMlpIv94qSB+aJaAmJs7XPsbX+4jR6IYUGDpTVkOEOSuW4A60H4Mn6nX4mj6i06a2hWEhE61gvNkFkwexEt3GWjGAVJ2xQ7KUCGlBaRqsSMoyJRYxZjQbGkAlP3yvo284fLLIKVOOS3+ifgBO7xk4rCiPqSO5YOKJzPhNOSEpVEwuzg2F6e8kZgPL/ZfN+Z46XLc1ZJTYfemtuNa0ITMEuiDQPzh07rhxETTi9zct1dUUlZ8Vhj6xRy9LWuKlnTpiPosZGq++6Ec9vtNjHlVeFAPGuLtlMAAZ45l+0= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcd9c1e5-0831-4207-afd3-08d7160db9ab X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2019 23:20:50.4315 (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: bmoger@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1657 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.72.53 Subject: [Qemu-devel] [RFC PATCH 4/5] hw/i386: Generate apicid based on cpu_type 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: "Moger, Babu" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Check the cpu_type before calling the apicid functions from topology.h. Signed-off-by: Babu Moger --- hw/i386/pc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ef39463fd5..dad55c940f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -947,6 +947,36 @@ static uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, } } +/* Calculates initial APIC ID for a specific CPU index + * + * Currently we need to be able to calculate the APIC ID from the CPU index + * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have + * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of + * all CPUs up to max_cpus. + */ +static uint32_t x86_cpu_apic_id_from_index_epyc(PCMachineState *pcms, + unsigned int cpu_index) +{ + MachineState *ms = MACHINE(pcms); + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); + uint32_t correct_id; + static bool warned; + + correct_id = x86_apicid_from_cpu_idx_epyc(nb_numa_nodes, ms->smp.sockets, + ms->smp.cores, ms->smp.threads, + cpu_index); + if (pcmc->compat_apic_id_mode) { + if (cpu_index != correct_id && !warned && !qtest_enabled()) { + error_report("APIC IDs set in compatibility mode, " + "CPU topology won't match the configuration"); + warned = true; + } + return cpu_index; + } else { + return correct_id; + } +} + static void pc_build_smbios(PCMachineState *pcms) { uint8_t *smbios_tables, *smbios_anchor; @@ -1619,7 +1649,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp) { PCMachineState *pcms = PC_MACHINE(ms); - int64_t apic_id = x86_cpu_apic_id_from_index(pcms, id); + int64_t apic_id; Error *local_err = NULL; if (id < 0) { @@ -1627,6 +1657,11 @@ void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp) return; } + if(!strncmp(ms->cpu_type, "EPYC", 4)) + apic_id = x86_cpu_apic_id_from_index_epyc(pcms, id); + else + apic_id = x86_cpu_apic_id_from_index(pcms, id); + if (apic_id >= ACPI_CPU_HOTPLUG_ID_LIMIT) { error_setg(errp, "Unable to add CPU: %" PRIi64 ", resulting APIC ID (%" PRIi64 ") is too large", @@ -1658,8 +1693,13 @@ void pc_cpus_init(PCMachineState *pcms) * * This is used for FW_CFG_MAX_CPUS. See comments on bochs_bios_init(). */ - pcms->apic_id_limit = x86_cpu_apic_id_from_index(pcms, - ms->smp.max_cpus - 1) + 1; + if(!strncmp(ms->cpu_type, "EPYC", 4)) + pcms->apic_id_limit = x86_cpu_apic_id_from_index_epyc(pcms, + ms->smp.max_cpus - 1) + 1; + else + pcms->apic_id_limit = x86_cpu_apic_id_from_index(pcms, + ms->smp.max_cpus - 1) + 1; + possible_cpus = mc->possible_cpu_arch_ids(ms); for (i = 0; i < ms->smp.cpus; i++) { pc_new_cpu(pcms, possible_cpus->cpus[i].arch_id, &error_fatal); @@ -2387,6 +2427,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, PCMachineState *pcms = PC_MACHINE(hotplug_dev); unsigned int smp_cores = ms->smp.cores; unsigned int smp_threads = ms->smp.threads; + unsigned int smp_sockets = ms->smp.sockets; if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", @@ -2437,16 +2478,26 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, topo.die_id = cpu->die_id; topo.core_id = cpu->core_id; topo.smt_id = cpu->thread_id; - cpu->apic_id = apicid_from_topo_ids(pcms->smp_dies, smp_cores, - smp_threads, &topo); + if (!strncmp(ms->cpu_type, "EPYC", 4)) { + x86_topo_ids_from_idx_epyc(nb_numa_nodes, smp_sockets, smp_cores, + smp_threads, idx, &topo); + cpu->apic_id = apicid_from_topo_ids_epyc(smp_cores, smp_threads, + &topo); + } else + cpu->apic_id = apicid_from_topo_ids(pcms->smp_dies, smp_cores, + smp_threads, &topo); } 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, pcms->smp_dies, - smp_cores, smp_threads, &topo); + if(!strncmp(ms->cpu_type, "EPYC", 4)) + x86_topo_ids_from_apicid_epyc(cpu->apic_id, pcms->smp_dies, + smp_cores, smp_threads, &topo); + else + x86_topo_ids_from_apicid(cpu->apic_id, pcms->smp_dies, + smp_cores, smp_threads, &topo); error_setg(errp, "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with" " APIC ID %" PRIu32 ", valid index range 0:%d", @@ -2874,10 +2925,18 @@ static const CPUArchIdList *pc_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(pcms, i); - x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, - pcms->smp_dies, ms->smp.cores, - ms->smp.threads, &topo); + if(!strncmp(ms->cpu_type, "EPYC", 4)) { + ms->possible_cpus->cpus[i].arch_id = + x86_cpu_apic_id_from_index_epyc(pcms, i); + x86_topo_ids_from_apicid_epyc(ms->possible_cpus->cpus[i].arch_id, + pcms->smp_dies, ms->smp.cores, + ms->smp.threads, &topo); + } else { + ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(pcms, i); + x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, + pcms->smp_dies, ms->smp.cores, + ms->smp.threads, &topo); + } ms->possible_cpus->cpus[i].props.has_socket_id = true; ms->possible_cpus->cpus[i].props.socket_id = topo.pkg_id; ms->possible_cpus->cpus[i].props.has_die_id = true; From patchwork Wed Jul 31 23:20:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 11069787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38BA513AC for ; Wed, 31 Jul 2019 23:22:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29A3027F81 for ; Wed, 31 Jul 2019 23:22:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DAE228346; Wed, 31 Jul 2019 23:22:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB92227F81 for ; Wed, 31 Jul 2019 23:22:53 +0000 (UTC) Received: from localhost ([::1]:45008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxvp-0002jP-2e for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Jul 2019 19:22:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50842) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsxtv-0006z9-Gi for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsxtu-0008Rb-Hp for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:55 -0400 Received: from mail-eopbgr720053.outbound.protection.outlook.com ([40.107.72.53]:30923 helo=NAM05-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 1hsxtu-0008P5-Aj for qemu-devel@nongnu.org; Wed, 31 Jul 2019 19:20:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y73Ck/yayK1/E+08z6qo/p7mJ0/uo/AClfROdsv+xBw4praazterN9krVBjv3P2duby1Datg47ZLTtvh75BXRpp/l0WDcyBkyxCe0Or9EpIcdGRn8rCtoSTctVH2E1c3Mpdk+37kUzOyb8e2Z8ISItvdNYLdoyRE9Atlwa2TrNAvam5nHHn6Mia8q1E9zLuNxuVcxEMgONqMRQddo2W8yP4aRxwBER7QrMaIDu7KDZvGw5iDH7NJdrhmH1mHMWU4vAjtJuMkH2n049hXwufLA3A6qxM8K8RGgdz8fuJfrg8f6m9cQcdaUOWDUHNbUUYqqSdBh4KB7wgYAIadOnh0zw== 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=0jb2oLu/YXMn8C8zTSuCIbXvWmCyUHcgsH19ILPn+fo=; b=TdJ0mDBmFyLhSWkcu5mZzWhVIkdofuAhAEKXMAlvmuYyBzmkjNhWg19p7I/WL0c8+tFhZAoODJRwZC7nCWoUziNeQmEIYJdQguojRz1DEbfFM+jet2TDuNpHf2Ikx2CmyDV1aDOwuELZdwwzxTLWxUZDHIxWp9WzH58MGMwvPeEwWNi+kLWHwmuZBdkon1Jy5EIMU2y+AZ1C9BoFXTtUmlRlAQ5voErhVx7mZ6IM/o3Nna+uzGpTZF7DQyrjhyCeUO/p57RYdOJegxK4BhSsdPW2W0F0w0/AGqCiD0y9SCG8iYO3lBLD/Fja91n0S9JRfzGg9jyyHGjUefnlK9WFeg== 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=selector1-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0jb2oLu/YXMn8C8zTSuCIbXvWmCyUHcgsH19ILPn+fo=; b=YQff77a7d844Qe9lkUJNoOVui44Xku39RPgmIkH+HrmIguWTLlaaoLA4h6v90Zv6fUYylVWm7RH+a1arAcKPz2WRchByv/Dq/kCPssIu1e5PEnnlhxP4xZGCeFkvNvXGGPa4/lKoZPVXdO/gSCK194LnBHtJ2GGTwMHrzJsVy3Y= Received: from DM5PR12MB2471.namprd12.prod.outlook.com (52.132.141.138) by DM5PR12MB1657.namprd12.prod.outlook.com (10.172.38.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.15; Wed, 31 Jul 2019 23:20:51 +0000 Received: from DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67]) by DM5PR12MB2471.namprd12.prod.outlook.com ([fe80::ecb0:375b:9347:fe67%7]) with mapi id 15.20.2136.010; Wed, 31 Jul 2019 23:20:51 +0000 From: "Moger, Babu" To: "ehabkost@redhat.com" , "marcel.apfelbaum@gmail.com" , "mst@redhat.com" , "pbonzini@redhat.com" , "rth@twiddle.net" , "imammedo@redhat.com" Thread-Topic: [RFC PATCH 5/5] i386: Fix pkg_id offset EPYC Thread-Index: AQHVR/aXpDsOnsB4hUqhnkMdXogqLw== Date: Wed, 31 Jul 2019 23:20:51 +0000 Message-ID: <20190731232032.51786-6-babu.moger@amd.com> References: <20190731232032.51786-1-babu.moger@amd.com> In-Reply-To: <20190731232032.51786-1-babu.moger@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) 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-mailer: git-send-email 2.20.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 89f0f405-669a-460d-c6f3-08d7160dba4f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DM5PR12MB1657; x-ms-traffictypediagnostic: DM5PR12MB1657: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1824; x-forefront-prvs: 011579F31F x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(346002)(39860400002)(376002)(136003)(396003)(366004)(199004)(189003)(50226002)(7736002)(316002)(14444005)(256004)(102836004)(2201001)(66446008)(66556008)(6506007)(54906003)(2616005)(66476007)(76176011)(66066001)(1076003)(2906002)(8676002)(446003)(26005)(66946007)(53936002)(476003)(2501003)(305945005)(110136005)(64756008)(52116002)(4326008)(81156014)(68736007)(86362001)(14454004)(6512007)(386003)(99286004)(25786009)(11346002)(3846002)(6436002)(71200400001)(71190400001)(36756003)(6116002)(81166006)(8936002)(6486002)(478600001)(486006)(186003)(5660300002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB1657; H:DM5PR12MB2471.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: 8RFhaqRb3BPlTowAHVq0Avww/zg94SrNddEaMS9rXpL4UEUPwSNjOGOsUjHr2QTAztNMmb5TTv7CJ0UQOUxjbtQMrt3m880NxHMdMaeSby9qXIZwbriGcuEU7+W5LgMWnVLLStUcRhHeHiQ1Y+6Wlnnkmg9TEwA/14JoP5zGygFKWPwOxdyjWQPLfB69/UXMzob872AijmbLRMqPoTCN7XPnMVBzkyYhRNBF2cZPQsFVrP2sncvNTM7VqVkqbxC0eJUTk0CBxKGQuRCJM4LVnXvg/frW3NytZ0rwGbBT69Q4DuerftOU0i/LGtUsWA0kwMW+zYj5VBBDmAuELNlWuLnGJbkw+MiillGHyCHyExbZzLN5RTaA5UbBbBTKNQE7Ir/L6zR7C5lqKOpp8BYpf6ZVuyz1SJlwEqQ+gKjHj3U= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89f0f405-669a-460d-c6f3-08d7160dba4f X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2019 23:20:51.4929 (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: bmoger@amd.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1657 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.72.53 Subject: [Qemu-devel] [RFC PATCH 5/5] i386: Fix pkg_id offset EPYC 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: "Moger, Babu" , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Per Processor Programming Reference (PPR) for AMD Family 17h Models, the pkg_id offset in apicid is 6. Fix the offset based on EPYC models. Signed-off-by: Babu Moger --- target/i386/cpu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index be4583068c..235496a9c1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4079,7 +4079,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, MachineState *ms = MACHINE(qdev_get_machine()); X86CPU *cpu = env_archcpu(env); CPUState *cs = env_cpu(env); - uint32_t die_offset; + uint32_t die_offset, pkg_offset; uint32_t limit; uint32_t signature[3]; @@ -4102,6 +4102,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, index = env->cpuid_level; } + if (!strncmp(ms->cpu_type, "EPYC", 4)) + pkg_offset = PKG_OFFSET_EPYC; + else + pkg_offset = apicid_pkg_offset(env->nr_dies, cs->nr_cores, + cs->nr_threads); + switch(index) { case 0: *eax = env->cpuid_level; @@ -4260,8 +4266,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(env->nr_dies, - cs->nr_cores, cs->nr_threads); + *eax = pkg_offset; *ebx = cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_CORE; break; @@ -4297,8 +4302,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(env->nr_dies, cs->nr_cores, - cs->nr_threads); + *eax = pkg_offset; *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads; *ecx |= CPUID_TOPOLOGY_LEVEL_DIE; break;