2020-01-15 08:16:50

by Tony W Wang-oc

[permalink] [raw]
Subject: [PATCH] x86/cpu: remove redundant cpu_detect_cache_sizes

Before call cpu_detect_cache_sizes get l2size from CPUID.80000006,
these CPUs have called init_intel_cacheinfo get l2size/l3size from
CPUID.4.

So remove the redundant function to simplify the code.

Signed-off-by: Tony W Wang-oc <[email protected]>
---
arch/x86/kernel/cpu/centaur.c | 2 --
arch/x86/kernel/cpu/zhaoxin.c | 2 --
2 files changed, 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 14433ff..b98529e 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -71,8 +71,6 @@ static void init_c3(struct cpuinfo_x86 *c)
c->x86_cache_alignment = c->x86_clflush_size * 2;
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
}
-
- cpu_detect_cache_sizes(c);
}

enum {
diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c
index 8e6f2f4..452fd0a 100644
--- a/arch/x86/kernel/cpu/zhaoxin.c
+++ b/arch/x86/kernel/cpu/zhaoxin.c
@@ -58,8 +58,6 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c)

if (c->x86 >= 0x6)
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-
- cpu_detect_cache_sizes(c);
}

static void early_init_zhaoxin(struct cpuinfo_x86 *c)
--
2.7.4


2020-01-17 18:48:37

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] x86/cpu: remove redundant cpu_detect_cache_sizes

On Wed, Jan 15, 2020 at 04:00:57PM +0800, Tony W Wang-oc wrote:
> Before call cpu_detect_cache_sizes get l2size from CPUID.80000006,
> these CPUs have called init_intel_cacheinfo get l2size/l3size from
> CPUID.4.

Questions:

* Does CPUID(4) give the same result as CPUID(80000006) on those CPUs?

* cpu_detect_cache_sizes() sets c->x86_tlbsize while
init_intel_cacheinfo() would set it only when it calls the former
function - cpu_detect_cache_sizes() - at the end:

if (!l2)
cpu_detect_cache_sizes(c);

Does that happen on those CPUs?

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

2020-01-18 02:19:42

by Tony W Wang-oc

[permalink] [raw]
Subject: Re: [PATCH] x86/cpu: remove redundant cpu_detect_cache_sizes



On 18/01/2020 02:47, Borislav Petkov wrote:
> On Wed, Jan 15, 2020 at 04:00:57PM +0800, Tony W Wang-oc wrote:
>> Before call cpu_detect_cache_sizes get l2size from CPUID.80000006,
>> these CPUs have called init_intel_cacheinfo get l2size/l3size from
>> CPUID.4.
>
> Questions:
>
> * Does CPUID(4) give the same result as CPUID(80000006) on those CPUs?

Yes.
On these CPUs, CPUID(80000006).EBX for x86_tlbsize is reserved,
CPUID(80000006).ECX for l2size has the same result as CPUID(4).

>
> * cpu_detect_cache_sizes() sets c->x86_tlbsize while
> init_intel_cacheinfo() would set it only when it calls the former
> function - cpu_detect_cache_sizes() - at the end:
>
> if (!l2)
> cpu_detect_cache_sizes(c);
>
> Does that happen on those CPUs?

No.
On these CPUs, will not call the function cpu_detect_cache_sizes(c).
l2size will get from CPUID(4) and c->x86_tlbsize remain its default
value of 0.

Sincerely
TonyWWang-oc

2020-01-20 15:40:51

by tip-bot2 for Jacob Pan

[permalink] [raw]
Subject: [tip: x86/cpu] x86/cpu: Remove redundant cpu_detect_cache_sizes() call

The following commit has been merged into the x86/cpu branch of tip:

Commit-ID: 283bab9809786cf41798512f5c1e97f4b679ba96
Gitweb: https://git.kernel.org/tip/283bab9809786cf41798512f5c1e97f4b679ba96
Author: Tony W Wang-oc <[email protected]>
AuthorDate: Wed, 15 Jan 2020 16:00:57 +08:00
Committer: Borislav Petkov <[email protected]>
CommitterDate: Mon, 20 Jan 2020 16:32:35 +01:00

x86/cpu: Remove redundant cpu_detect_cache_sizes() call

Both functions call init_intel_cacheinfo() which computes L2 and L3 cache
sizes from CPUID(4). But then they also call cpu_detect_cache_sizes() a
bit later which computes ->x86_tlbsize and L2 size from CPUID(80000006).

However, the latter call is not needed because

- on these CPUs, CPUID(80000006).EBX for ->x86_tlbsize is reserved

- CPUID(80000006).ECX for the L2 size has the same result as CPUID(4)

Therefore, remove the latter call to simplify the code.

[ bp: Rewrite commit message. ]

Signed-off-by: Tony W Wang-oc <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/kernel/cpu/centaur.c | 2 --
arch/x86/kernel/cpu/zhaoxin.c | 2 --
2 files changed, 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 02d99fe..4267925 100644
--- a/arch/x86/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
@@ -64,8 +64,6 @@ static void init_c3(struct cpuinfo_x86 *c)
c->x86_cache_alignment = c->x86_clflush_size * 2;
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
}
-
- cpu_detect_cache_sizes(c);
}

enum {
diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c
index 6b2d3b0..df1358b 100644
--- a/arch/x86/kernel/cpu/zhaoxin.c
+++ b/arch/x86/kernel/cpu/zhaoxin.c
@@ -51,8 +51,6 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c)

if (c->x86 >= 0x6)
set_cpu_cap(c, X86_FEATURE_REP_GOOD);
-
- cpu_detect_cache_sizes(c);
}

static void early_init_zhaoxin(struct cpuinfo_x86 *c)