From patchwork Thu May 24 15:43:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10425031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F324D60327 for ; Thu, 24 May 2018 15:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCACD296AD for ; Thu, 24 May 2018 15:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C10E7296D5; Thu, 24 May 2018 15:44:08 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15AC2296AD for ; Thu, 24 May 2018 15:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968202AbeEXPoE (ORCPT ); Thu, 24 May 2018 11:44:04 -0400 Received: from mail-bl2nam02on0059.outbound.protection.outlook.com ([104.47.38.59]:26944 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967988AbeEXPn4 (ORCPT ); Thu, 24 May 2018 11:43:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D0kUTnB3toZSxHqYp3fZn71ixSvGlo2QKKAJHtFlk/c=; b=ycOvKFIgKcVpcSY88TbUHbgXYhbgXTr6zBzu42/NE8D4ajvF8vqk1v7Zx61/kEHohXwg+Nd1NeUcIBb89BiiAbHrr/XaHbgEywo+4yjs8D495R8AfBJCqIdiHGT1w7L1IdXBNvv6hl6KF56KOSD44ybbz3V9RYfIxEJg02awKGQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Thu, 24 May 2018 15:43:48 +0000 From: Babu Moger To: mst@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, babu.moger@amd.com, kash@tripleback.net, geoff@hostfission.com Subject: [PATCH v11 2/5] i386: Populate AMD Processor Cache Information for cpuid 0x8000001D Date: Thu, 24 May 2018 11:43:31 -0400 Message-Id: <1527176614-26271-3-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527176614-26271-1-git-send-email-babu.moger@amd.com> References: <1527176614-26271-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0024.namprd05.prod.outlook.com (2603:10b6:803:40::37) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DM5PR12MB2471; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 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ihDgRr5DWzMGhTodh0L1PAKVu43Wjc1dIKp46SKh1Zp9OkNTie4McK7hxYJa/jGa6i7ga4/u+jJgRW9eqWmHdPMq0YacvGF8N7KJTx2VMxGAU7g+0HmInRDOPr9ph8EhY7KtDaGueKghpLC1opZqvr8dMdPE2J6k1TNCAjQ9f7s6j1OERhdw6pDOHxmYKQR+GtXJjaW7A0fl83m892AmkqOpp3jjPvhYpYG7yltHYjImMj0lVR+/NWDrsUn1bUA6QwvUJ9LkFBjE5IhfWAIifeooQXb+M47Pl0Bg6q4a8ngaNZCJ5HQFjq17H6nlEhfDOBUVfNoQY2rLTEDb3PUlYTsdWLM3Jj9jKNR3; 4:oZpgCLL6tpv4CkntlSAZeuQ+br3S690kHpeiRc+Nyx96+c9Pdahsm7GY+k5JlR6GdFLACMS007YZrh62SjC6GYox9DnaZP0nXmdtq+XzCoaU/H1JuLpKxJ+vyfLLuMEK60Ex7v1lKrd0BdDuMJeJDRpo0LpBPLo0mg3WwnX+Nw40g+C/4TBdluTVB4yysdEas2qi+btduM85fZ/ElVgTJMNagmrXAPij8IuEbrgSuKhK7Qar0wYniwHcSW2Zk1kknxpZLTzsIa/I1c1VBePOpwRTYA8qNN+4c2eKseEd946I/LJRKkV3kmtknwHmkmet X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DM5PR12MB2471; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB2471; X-Forefront-PRVS: 0682FC00E8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(346002)(39380400002)(366004)(39860400002)(396003)(376002)(189003)(199004)(5660300001)(53416004)(6666003)(2616005)(446003)(11346002)(956004)(476003)(486006)(44832011)(7416002)(4326008)(25786009)(478600001)(53936002)(39060400002)(26005)(47776003)(316002)(186003)(16526019)(23676004)(386003)(86362001)(7696005)(52116002)(66066001)(68736007)(76176011)(97736004)(2906002)(50466002)(3846002)(2870700001)(6116002)(72206003)(4720700003)(7736002)(6486002)(305945005)(36756003)(50226002)(8676002)(8936002)(81166006)(81156014)(105586002)(106356001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2471; H:linux-h3ml.amd.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-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIyNDcxOzIzOjJvU1JuZjROUlVUbnZ4SFF2YUpSMkNzMWcv?= =?utf-8?B?dDEzRFVpdkduUzMrUWdLcEFtNGF4SndCQ2ZFYmhvMHpkRzV4REJnbGwzV1Y1?= =?utf-8?B?RlZtREVmRzN3L1IxZWxoZlZIYUFiRG1UN1hSM1hWN1N3RkhCN3k5Y0RxOHFl?= =?utf-8?B?YzdiRjU0Zk5jVDN2WFZCQXRZeUFxVmZ0OXRoZSszVzcrNXNralRTSjU0ajlo?= =?utf-8?B?cDhIcFNRUGxhT3BDanRmVnlMclVTRVN6Z1NiY3RNYjFMMFdIbUkrWThYNS9H?= =?utf-8?B?My90dWFRdjlWQTJhNFdtZGxxR3NaeFh0NEQ1cHplTjNJNHhIRU12U0VIekZp?= =?utf-8?B?L3dWZDhYYTlYYUJXbGpzRGxXSFlBMXZEY1lvbkZ6a0hsVm1oYllSUXltaGQ2?= =?utf-8?B?THlpOUdwQXJnNnRBZXhBWUZWKzc3MytzVE5FSWJPdG93Mk9BbS9zQjVYWVVV?= =?utf-8?B?MUs1UzRiZ0srVm96NndGR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-Office365-Filtering-Correlation-Id: 88d87d23-816e-45dd-67f6-08d5c18d248f X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2018 15:43:48.0564 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88d87d23-816e-45dd-67f6-08d5c18d248f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2471 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add information for cpuid 0x8000001D leaf. Populate cache topology information for different cache types (Data Cache, Instruction Cache, L2 and L3) supported by 0x8000001D leaf. Please refer to the Processor Programming Reference (PPR) for AMD Family 17h Model for more details. Signed-off-by: Babu Moger Reviewed-by: Eduardo Habkost --- target/i386/cpu.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ target/i386/kvm.c | 29 ++++++++++++-- 2 files changed, 143 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5c9bdc9..0d423e5 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -337,6 +337,99 @@ 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) +{ + uint32_t l3_cores; + assert(cache->size == cache->line_size * cache->associativity * + cache->partitions * cache->sets); + + *eax = CACHE_TYPE(cache->type) | CACHE_LEVEL(cache->level) | + (cache->self_init ? CACHE_SELF_INIT_LEVEL : 0); + + /* 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; + } else { + *eax |= ((cs->nr_threads - 1) << 14); + } + + assert(cache->line_size > 0); + assert(cache->partitions > 0); + assert(cache->associativity > 0); + /* We don't implement fully-associative caches */ + assert(cache->associativity < cache->sets); + *ebx = (cache->line_size - 1) | + ((cache->partitions - 1) << 12) | + ((cache->associativity - 1) << 22); + + assert(cache->sets > 0); + *ecx = cache->sets - 1; + + *edx = (cache->no_invd_sharing ? CACHE_NO_INVD_SHARING : 0) | + (cache->inclusive ? CACHE_INCLUSIVE : 0) | + (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); +} + +/* * Definitions of the hardcoded cache entries we expose: * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs @@ -4005,6 +4098,30 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *edx = 0; } break; + case 0x8000001D: + *eax = 0; + switch (count) { + case 0: /* L1 dcache info */ + encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, cs, + eax, ebx, ecx, edx); + break; + case 1: /* L1 icache info */ + encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, cs, + eax, ebx, ecx, edx); + break; + case 2: /* L2 cache info */ + encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, cs, + eax, ebx, ecx, edx); + break; + case 3: /* L3 cache info */ + encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, cs, + eax, ebx, ecx, edx); + break; + default: /* end of info */ + *eax = *ebx = *ecx = *edx = 0; + break; + } + break; case 0xC0000000: *eax = env->cpuid_xlevel2; *ebx = 0; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 0c656a9..871d1ef 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -980,9 +980,32 @@ int kvm_arch_init_vcpu(CPUState *cs) } c = &cpuid_data.entries[cpuid_i++]; - c->function = i; - c->flags = 0; - cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + switch (i) { + case 0x8000001d: + /* Query for all AMD cache information leaves */ + for (j = 0; ; j++) { + c->function = i; + c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + c->index = j; + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->edx); + + if (c->eax == 0) { + break; + } + if (cpuid_i == KVM_MAX_CPUID_ENTRIES) { + fprintf(stderr, "cpuid_data is full, no space for " + "cpuid(eax:0x%x,ecx:0x%x)\n", i, j); + abort(); + } + c = &cpuid_data.entries[cpuid_i++]; + } + break; + default: + c->function = i; + c->flags = 0; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + break; + } } /* Call Centaur's CPUID instructions they are supported. */