From nobody Thu Nov 6 16:23:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542193111858783.6435843811705; Wed, 14 Nov 2018 02:58:31 -0800 (PST) Received: from localhost ([::1]:59455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMssQ-0004Pc-Oj for importer@patchew.org; Wed, 14 Nov 2018 05:58:30 -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) 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) 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 *c= ache, CPUState *cs, (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); } =20 +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 =3D=3D 0); + if (c->sets > 0) { + uint32_t sets =3D sz / (c->line_size * c->associativity * c->parti= tions); + + if (sets =3D=3D 0) + return; + c->sets =3D sets; + } + c->size =3D 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 =3D 0; } else { + if (cpu->l3_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid2.l3_cache, + cpu->l3_cache_size); *ecx =3D cpuid2_cache_descriptor(env->cache_info_cpuid2.l3_cac= he); } + if (cpu->l2_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid2.l2_cache, + cpu->l2_cache_size); *edx =3D (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 =3D apicid_pkg_offset(cs->nr_cores, cs->nr_thre= ads); if (cpu->enable_l3_cache) { + if (cpu->l3_cache_size > 0) + set_custom_cache_size(env->cache_info_cpuid4.l3_ca= che, + cpu->l3_cache_size); encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache, (1 << pkg_offset), cs->nr_cores, eax, ebx, ecx, edx);