From patchwork Wed Nov 14 10:57:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 10682351 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 E003B1709 for ; Wed, 14 Nov 2018 10:58:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D230D2978F for ; Wed, 14 Nov 2018 10:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C68712997A; Wed, 14 Nov 2018 10:58:12 +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,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B770E2978F for ; Wed, 14 Nov 2018 10:58:11 +0000 (UTC) Received: from localhost ([::1]:59455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMss7-0004Pc-4L for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Nov 2018 05:58:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMsqx-00039W-TX for qemu-devel@nongnu.org; Wed, 14 Nov 2018 05:57:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMsqm-0007xx-DG for qemu-devel@nongnu.org; Wed, 14 Nov 2018 05:56:55 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46790) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gMsql-0007xS-Si for qemu-devel@nongnu.org; Wed, 14 Nov 2018 05:56:48 -0500 Received: by mail-wr1-f67.google.com with SMTP id l9so3876703wrt.13 for ; Wed, 14 Nov 2018 02:56:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=pOG+EZxr7+WbAbeqxvYU403kCPWA7FhfD0as/JuGO1w=; b=Yzu1D+/aMvKz0iJaSFScTl6lavUoLHw1A7Nf+vVEjw2QEUhmZj+Fgaqn/vRwFWXSnF 9znm6CS3AqwiK99C9EdFS8uZwsL99ss4LLIlrEwmowpwgr7BrNUMnzEIBCA+sSADYRRP uJcWimo/WlG4XqXtFMTAgWkNxCPhjsTFmih3yVWMesCnjkTJK7bhJrlj/6OoKZzqqgN7 x0nHke+NhSU0eKqBpVUCa7tYxnxMcG6OSi5qunW1hnDSGYhXfrEQpXAbiC9m2fIGAsMH W9JuRJoKa+PmlqoN+yBLD/FvIsTIIhV1FEBRQlqZ2mRmlD1u69gDUktACo1NTA/oIuZE vPtw== X-Gm-Message-State: AGRZ1gJNrtlLN5a4GBBJIE81y2Ex/j/Uw+oV0OTXmQVqXtR9J08JQ5Lw 9AgTzVh/6Ur0D1PusXVRrmk= X-Google-Smtp-Source: AJdET5dyEA1vTJpcgv5Bo/l/0TsclMBmWSoPFTvVrVy1QfSXdug3HT9oB50jqsCRwxsS1pYiajb2Ag== X-Received: by 2002:adf:eb48:: with SMTP id u8-v6mr1291085wrn.22.1542193006551; Wed, 14 Nov 2018 02:56:46 -0800 (PST) Received: from [127.0.0.1] (96-210-66-80.hosts.abilene.it. [80.66.210.96]) by smtp.gmail.com with ESMTPSA id t4-v6sm10649106wrb.67.2018.11.14.02.56.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 02:56:45 -0800 (PST) From: Dario Faggioli To: qemu-devel@nongnu.org Date: Wed, 14 Nov 2018 11:57:02 +0100 Message-ID: <154219302196.19470.10725052065694275300.stgit@wayrath> In-Reply-To: <154219299016.19470.9372139354280787961.stgit@wayrath> References: <154219299016.19470.9372139354280787961.stgit@wayrath> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.221.67 Subject: [Qemu-devel] [RFC PATCH 2/3] i386: custom cache size in CPUID2 and CPUID4 descriptors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If specified on the command line, alter the cache(s) properties accordingly, before encoding them in the CPUID descriptors. Tweak the number of sets (if defined), to retain consistency. Unless some specific size values are used (either by chance or voluntarily), we won't find any matching CPUID-2 descriptor, and 0xFF will be used. This shouldn't be a problem, as we have CPUID-4. Signed-off-by: Dario Faggioli --- I'm no CPUID expert. I'm not sure I've fully understodd the relationship between CPUID-2 and CPUID-4. The solution implemented here, is the best I could come up with, and it worked on all the CPU types that I've tried. If it's wrong/suboptimal, I'm happy to think to something else/rework. --- Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost --- 0 files changed diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b8ccb2be04..17aff19561 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -426,6 +426,24 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs, (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); } +static void set_custom_cache_size(CPUCacheInfo *c, uint64_t sz) +{ + /* + * Descriptors that have 'sets', also have 'partitions' initialized, + * so we can compute the new number of sets. For others, just tweak the + * size. + */ + assert(c->partitions > 0 || c->sets == 0); + if (c->sets > 0) { + uint32_t sets = sz / (c->line_size * c->associativity * c->partitions); + + if (sets == 0) + return; + c->sets = sets; + } + c->size = sz; +} + /* Data structure to hold the configuration info for a given core index */ struct core_topology { /* core complex id of the current core index */ @@ -4193,8 +4211,14 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, if (!cpu->enable_l3_cache) { *ecx = 0; } else { + if (cpu->l3_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid2.l3_cache, + cpu->l3_cache_size); *ecx = cpuid2_cache_descriptor(env->cache_info_cpuid2.l3_cache); } + if (cpu->l2_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid2.l2_cache, + cpu->l2_cache_size); *edx = (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1d_cache) << 16) | (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1i_cache) << 8) | (cpuid2_cache_descriptor(env->cache_info_cpuid2.l2_cache)); @@ -4222,6 +4246,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ + if (cpu->l2_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid4.l2_cache, + cpu->l2_cache_size); encode_cache_cpuid4(env->cache_info_cpuid4.l2_cache, cs->nr_threads, cs->nr_cores, eax, ebx, ecx, edx); @@ -4229,6 +4256,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, case 3: /* L3 cache info */ pkg_offset = apicid_pkg_offset(cs->nr_cores, cs->nr_threads); if (cpu->enable_l3_cache) { + if (cpu->l3_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid4.l3_cache, + cpu->l3_cache_size); encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache, (1 << pkg_offset), cs->nr_cores, eax, ebx, ecx, edx);