From nobody Wed Dec 17 09:08:23 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE9EE2586C3 for ; Wed, 19 Mar 2025 12:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742386938; cv=none; b=rnXCh4be9s7QWiSyEwrr2Vyd5jW8EXnWKxihmx+Ks3Xsf0Mq5e8y+QACwc95T+MDm7JCkEA/VUeyNZ9tCgN+dvaFBua5X2nrCxHptKwaXZRXzZ4+dCZKG8PKZW69/2NWYZX90YKAWo6z8ua0Ihx6VR9SutSWD/mqOy4r/r52Yog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742386938; c=relaxed/simple; bh=aE016W8b9s8G1p7pMupUW4RrDDEGtwwRil1/PDlHSqI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HbnDSDfFnpcF7CF4BwbRsX5e8mItBKu90DkeU8F/fNpB54Y/vsTnP6X1pjeMANZSshgHUj7K0+8CJynujeiBIaX+Tll7DqxazK2ajKrTPgcjkv42KzQsqsFW1i1OksNLBJXD2xdgbyBAIZp5GKsZjY+DG4lO791q7nxu4gNYLf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sDGOPGYA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qwFtRq91; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sDGOPGYA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qwFtRq91" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742386935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NIS91U2B+xF0EmmM6VIYVMN1YLL1xaHjZJ8dOVwZViY=; b=sDGOPGYAbmejRvFa1kEIwz7Z277/kdrW3SIQXjoOwk+hqhPvY63dlNGkgG/J+6/mzjddv3 s3rb7bQO6Lf3jdYmF0w3Neu5AU+V59mGGxQjNhiSwtAX9URnL3UUAFtrltdiJfkOAqBuP0 Qi8jG8DUuYEyq4yPPRlkS9zayuyaJYI29ifhAJVw0SnOGM+kfBT3ucnOX7ZQ7WRACkd1tg TRLxDyKdId6RIR12ecF0rSFn55Sy33riTQHAQ1gBwMYeyYGvY6RgZpeJr7K4MtjmM1LYyI oqAnhp5hVxL+zSalhRbKu5zd2zB/fvs0KrGMhPmpZWiRG7tlt6UrFu9ySwouxw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742386935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NIS91U2B+xF0EmmM6VIYVMN1YLL1xaHjZJ8dOVwZViY=; b=qwFtRq91QngcJ13824oXWPcxRUax+DcFqYWQ68tITOHmbrZm4zsouOX5sH+jHyezhqzka7 fHdAG+LXGA4pV9Dw== To: Ingo Molnar , Borislav Petkov , Dave Hansen Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v3 10/29] x86/cacheinfo: Standardize _cpuid4_info_regs instance naming Date: Wed, 19 Mar 2025 13:21:18 +0100 Message-ID: <20250319122137.4004-11-darwi@linutronix.de> In-Reply-To: <20250319122137.4004-1-darwi@linutronix.de> References: <20250319122137.4004-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The cacheinfo code frequently uses the output registers from CPUID leaf 0x4. Such registers are cached at struct _cpuid4_info_regs, augmented with related information, and are then passed across functions. The naming of these _cpuid4_info_regs instances is confusing at best. Some instances are called "this_leaf", which is vague as "this" lacks context and "leaf" is overly generic given that other CPUID leaves are also processed within cacheinfo. Other _cpuid4_info_regs instances are just called "base", adding further ambiguity. Standardize on id4 for all instances. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 97 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index b273ecf3f538..1b2a2bf97d7f 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -573,7 +573,7 @@ cache_get_priv_group(struct cacheinfo *ci) return &cache_private_group; } =20 -static void amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf, int ind= ex) +static void amd_init_l3_cache(struct _cpuid4_info_regs *id4, int index) { int node; =20 @@ -582,16 +582,16 @@ static void amd_init_l3_cache(struct _cpuid4_info_reg= s *this_leaf, int index) return; =20 node =3D topology_amd_node_id(smp_processor_id()); - this_leaf->nb =3D node_to_amd_nb(node); - if (this_leaf->nb && !this_leaf->nb->l3_cache.indices) - amd_calc_l3_indices(this_leaf->nb); + id4->nb =3D node_to_amd_nb(node); + if (id4->nb && !id4->nb->l3_cache.indices) + amd_calc_l3_indices(id4->nb); } #else #define amd_init_l3_cache(x, y) #endif /* CONFIG_AMD_NB && CONFIG_SYSFS */ =20 static int -cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *this_leaf) +cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -604,11 +604,11 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_in= fo_regs *this_leaf) &ebx.full, &ecx.full, &edx); else amd_cpuid4(index, &eax, &ebx, &ecx); - amd_init_l3_cache(this_leaf, index); + amd_init_l3_cache(id4, index); } else if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { cpuid_count(0x8000001d, index, &eax.full, &ebx.full, &ecx.full, &edx); - amd_init_l3_cache(this_leaf, index); + amd_init_l3_cache(id4, index); } else { cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); } @@ -616,13 +616,14 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_in= fo_regs *this_leaf) if (eax.split.type =3D=3D CTYPE_NULL) return -EIO; /* better error ? */ =20 - this_leaf->eax =3D eax; - this_leaf->ebx =3D ebx; - this_leaf->ecx =3D ecx; - this_leaf->size =3D (ecx.split.number_of_sets + 1) * - (ebx.split.coherency_line_size + 1) * - (ebx.split.physical_line_partition + 1) * - (ebx.split.ways_of_associativity + 1); + id4->eax =3D eax; + id4->ebx =3D ebx; + id4->ecx =3D ecx; + id4->size =3D (ecx.split.number_of_sets + 1) * + (ebx.split.coherency_line_size + 1) * + (ebx.split.physical_line_partition + 1) * + (ebx.split.ways_of_associativity + 1); + return 0; } =20 @@ -754,29 +755,29 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) * parameters cpuid leaf to find the cache details */ for (i =3D 0; i < ci->num_leaves; i++) { - struct _cpuid4_info_regs this_leaf =3D {}; + struct _cpuid4_info_regs id4 =3D {}; int retval; =20 - retval =3D cpuid4_cache_lookup_regs(i, &this_leaf); + retval =3D cpuid4_cache_lookup_regs(i, &id4); if (retval < 0) continue; =20 - switch (this_leaf.eax.split.level) { + switch (id4.eax.split.level) { case 1: - if (this_leaf.eax.split.type =3D=3D CTYPE_DATA) - new_l1d =3D this_leaf.size/1024; - else if (this_leaf.eax.split.type =3D=3D CTYPE_INST) - new_l1i =3D this_leaf.size/1024; + if (id4.eax.split.type =3D=3D CTYPE_DATA) + new_l1d =3D id4.size/1024; + else if (id4.eax.split.type =3D=3D CTYPE_INST) + new_l1i =3D id4.size/1024; break; case 2: - new_l2 =3D this_leaf.size/1024; - num_threads_sharing =3D 1 + this_leaf.eax.split.num_threads_sharing; + new_l2 =3D id4.size/1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); break; case 3: - new_l3 =3D this_leaf.size/1024; - num_threads_sharing =3D 1 + this_leaf.eax.split.num_threads_sharing; + new_l3 =3D id4.size/1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); break; @@ -841,7 +842,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { struct cpu_cacheinfo *this_cpu_ci; struct cacheinfo *ci; @@ -867,7 +868,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { unsigned int apicid, nshared, first, last; =20 - nshared =3D base->eax.split.num_threads_sharing + 1; + nshared =3D id4->eax.split.num_threads_sharing + 1; apicid =3D cpu_data(cpu).topo.apicid; first =3D apicid - (apicid % nshared); last =3D first + nshared - 1; @@ -898,7 +899,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } =20 static void __cache_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci, *sibling_ci; @@ -908,12 +909,12 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, =20 if (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_VENDOR_HYGON) { - if (__cache_amd_cpumap_setup(cpu, index, base)) + if (__cache_amd_cpumap_setup(cpu, index, id4)) return; } =20 ci =3D this_cpu_ci->info_list + index; - num_threads_sharing =3D 1 + base->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; =20 cpumask_set_cpu(cpu, &ci->shared_cpu_map); if (num_threads_sharing =3D=3D 1) @@ -934,18 +935,18 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, } =20 static void ci_info_init(struct cacheinfo *ci, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { - ci->id =3D base->id; + ci->id =3D id4->id; ci->attributes =3D CACHE_ID; - ci->level =3D base->eax.split.level; - ci->type =3D cache_type_map[base->eax.split.type]; - ci->coherency_line_size =3D base->ebx.split.coherency_line_size + 1; - ci->ways_of_associativity =3D base->ebx.split.ways_of_associativity + 1; - ci->size =3D base->size; - ci->number_of_sets =3D base->ecx.split.number_of_sets + 1; - ci->physical_line_partition =3D base->ebx.split.physical_line_partition += 1; - ci->priv =3D base->nb; + ci->level =3D id4->eax.split.level; + ci->type =3D cache_type_map[id4->eax.split.type]; + ci->coherency_line_size =3D id4->ebx.split.coherency_line_size + 1; + ci->ways_of_associativity =3D id4->ebx.split.ways_of_associativity + 1; + ci->size =3D id4->size; + ci->number_of_sets =3D id4->ecx.split.number_of_sets + 1; + ci->physical_line_partition =3D id4->ebx.split.physical_line_partition + = 1; + ci->priv =3D id4->nb; } =20 int init_cache_level(unsigned int cpu) @@ -964,15 +965,15 @@ int init_cache_level(unsigned int cpu) * ECX as cache index. Then right shift apicid by the number's order to get * cache id for this cache node. */ -static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4_regs) +static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4) { struct cpuinfo_x86 *c =3D &cpu_data(cpu); unsigned long num_threads_sharing; int index_msb; =20 - num_threads_sharing =3D 1 + id4_regs->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); - id4_regs->id =3D c->topo.apicid >> index_msb; + id4->id =3D c->topo.apicid >> index_msb; } =20 int populate_cache_leaves(unsigned int cpu) @@ -980,15 +981,15 @@ int populate_cache_leaves(unsigned int cpu) unsigned int idx, ret; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci =3D this_cpu_ci->info_list; - struct _cpuid4_info_regs id4_regs =3D {}; + struct _cpuid4_info_regs id4 =3D {}; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { - ret =3D cpuid4_cache_lookup_regs(idx, &id4_regs); + ret =3D cpuid4_cache_lookup_regs(idx, &id4); if (ret) return ret; - get_cache_id(cpu, &id4_regs); - ci_info_init(ci++, &id4_regs); - __cache_cpumap_setup(cpu, idx, &id4_regs); + get_cache_id(cpu, &id4); + ci_info_init(ci++, &id4); + __cache_cpumap_setup(cpu, idx, &id4); } this_cpu_ci->cpu_map_populated =3D true; =20 --=20 2.48.1