Skip to contentSkip to conversation

MIPS: Reduce code size for MIPS32R2 platforms.

PATCH In review Steven J. Hill 3 participants 5 messages Dec 7, 2012 – Sep 17, 2013 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: Reduce code size for MIPS32R2 platforms.

From: "Steven J. Hill" <[email protected]>

If the CPU type is selected to be a MIPS32R2 core, we surround some code with #ifdef's to reduce the kernel binary size.

---
 arch/mips/mm/tlbex.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/mips/mm/tlbex.c +6 -2
index cd9ad1b..4c23656 100644
@@ -364,6 +364,7 @@ static void __cpuinit build_restore_work_registers(u32 **p)
  */
 extern unsigned long pgd_current[];
 
+# ifndef CONFIG_CPU_MIPS32_R2
 /*
  * The R3000 TLB handler is simple.
  */
@@ -403,6 +404,7 @@ static void __cpuinit build_r3000_tlb_refill_handler(void)
 
 	dump_handler((u32 *)ebase, 32);
 }
+# endif /* !CONFIG_CPU_MIPS32_R2 */
 #endif /* CONFIG_MIPS_PGD_C0_CONTEXT */
 
 /*
@@ -1672,7 +1674,7 @@ build_pte_modifiable(u32 **p, struct uasm_reloc **r,
 	}
 }
 
-#ifndef CONFIG_MIPS_PGD_C0_CONTEXT
+#if !defined(CONFIG_MIPS_PGD_C0_CONTEXT) && !defined(CONFIG_CPU_MIPS32_R2)
 
 
 /*
@@ -1826,7 +1828,7 @@ static void __cpuinit build_r3000_tlb_modify_handler(void)
 
 	dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm));
 }
-#endif /* CONFIG_MIPS_PGD_C0_CONTEXT */
+#endif /* !CONFIG_MIPS_PGD_C0_CONTEXT && !CONFIG_CPU_MIPS32_R2 */
 
 /*
  * R4000 style TLB load/store/modify handlers.
@@ -2164,6 +2166,7 @@ void __cpuinit build_tlb_refill_handler(void)
 #endif
 
 	switch (current_cpu_type()) {
+#ifndef CONFIG_CPU_MIPS32_R2
 	case CPU_R2000:
 	case CPU_R3000:
 	case CPU_R3000A:
@@ -2193,6 +2196,7 @@ void __cpuinit build_tlb_refill_handler(void)
 		panic("No R8000 TLB refill handler yet");
 		break;
 
+#endif /* !CONFIG_CPU_MIPS32_R2 */
 	default:
 		if (!run_once) {
 			scratch_reg = allocate_kscratch();
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines · Steven J. Hill

From: "Steven J. Hill" <[email protected]>

If the CPU type is selected to be a MIPS32R2 core, we surround some code with #ifdef's to reduce the kernel binary size.

Yes, and a dozen more ifdefs would be needed to handle other places where things could be optimized for a particular CPU type. Best add more random ifdefs across the tree to handle MIPS32R1 and MIPS64R2 and of course Zumbitsu 8000 processors.

Below is a half-baked test version of a patch that I have in my git tree since you first posted your patch. For a Cavium kernel this shaves off around 6kB.

Obviously this patch relies on a halfway modern compiler's optimization capabilities.

Ralf

 arch/mips/cavium-octeon/csrc-octeon.c              |   1 +
 arch/mips/include/asm/cpu-features.h               |   4 -
 arch/mips/include/asm/cpu-type.h                   | 119 +++++++++++++++++++++
 .../include/asm/mach-ip22/cpu-feature-overrides.h  |   2 +
 .../include/asm/mach-ip27/cpu-feature-overrides.h  |   2 +
 .../include/asm/mach-ip28/cpu-feature-overrides.h  |   2 +
 arch/mips/kernel/cpu-probe.c                       |   5 +-
 arch/mips/kernel/time.c                            |   1 +
 arch/mips/kernel/traps.c                           |   1 +
 arch/mips/mm/c-octeon.c                            |   6 +-
 arch/mips/mm/dma-default.c                         |   1 +
 arch/mips/mm/page.c                                |   1 +
 arch/mips/mm/tlb-r4k.c                             |   1 +
 arch/mips/mm/tlbex.c                               |   1 +
 14 files changed, 139 insertions(+), 8 deletions(-)
arch/mips/cavium-octeon/csrc-octeon.c +1 -0
index ce6483a..3bbe8d6 100644
@@ -12,6 +12,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu-info.h>
+#include <asm/cpu-type.h>
 #include <asm/time.h>
 
 #include <asm/octeon/octeon.h>
arch/mips/include/asm/cpu-features.h +0 -4
index ca400f7..33a54c1 100644
@@ -13,10 +13,6 @@
 #include <asm/cpu-info.h>
 #include <cpu-feature-overrides.h>
 
-#ifndef current_cpu_type
-#define current_cpu_type()      current_cpu_data.cputype
-#endif
-
 /*
  * SMP assumption: Options of CPU 0 are a superset of all processors.
  * This is true for all known MIPS systems.
arch/mips/include/asm/cpu-type.h new file +119 -0

119 lines not on this page · raw message

arch/mips/include/asm/mach-ip22/cpu-feature-overrides.h +2 -0
index 9c87351..7b23f44 100644
@@ -8,6 +8,8 @@
 #ifndef __ASM_MACH_IP22_CPU_FEATURE_OVERRIDES_H
 #define __ASM_MACH_IP22_CPU_FEATURE_OVERRIDES_H
 
+#include <asm/cpu.h>
+
 /*
  * IP22 with a variety of processors so we can't use defaults for everything.
  */
arch/mips/include/asm/mach-ip27/cpu-feature-overrides.h +2 -0
index 7d3112b..53bcb73 100644
@@ -8,6 +8,8 @@
 #ifndef __ASM_MACH_IP27_CPU_FEATURE_OVERRIDES_H
 #define __ASM_MACH_IP27_CPU_FEATURE_OVERRIDES_H
 
+#include <asm/cpu.h>
+
 /*
  * IP27 only comes with R10000 family processors all using the same config
  */
arch/mips/include/asm/mach-ip28/cpu-feature-overrides.h +2 -0
index 9a53b32..0fb7cb5 100644
@@ -9,6 +9,8 @@
 #ifndef __ASM_MACH_IP28_CPU_FEATURE_OVERRIDES_H
 #define __ASM_MACH_IP28_CPU_FEATURE_OVERRIDES_H
 
+#include <asm/cpu.h>
+
 /*
  * IP28 only comes with R10000 family processors all using the same config
  */
arch/mips/kernel/cpu-probe.c +3 -2
index 8ea65c5..1bc2d80 100644
@@ -20,6 +20,7 @@
 
 #include <asm/bugs.h>
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/fpu.h>
 #include <asm/mipsregs.h>
 #include <asm/watch.h>
@@ -159,7 +160,7 @@ void __init check_wait(void)
 		return;
 	}
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_R3081:
 	case CPU_R3081E:
 		cpu_wait = r3081_wait;
@@ -252,7 +253,7 @@ static inline void check_errata(void)
 {
 	struct cpuinfo_mips *c = &current_cpu_data;
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_34K:
 		/*
 		 * Erratum "RPS May Cause Incorrect Instruction Execution"
arch/mips/kernel/time.c +1 -0
index 99d73b7..abd127e 100644
@@ -24,6 +24,7 @@
 #include <linux/export.h>
 
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/div64.h>
 #include <asm/smtc_ipi.h>
 #include <asm/time.h>
arch/mips/kernel/traps.c +1 -0
index 9260986..4c58568 100644
@@ -37,6 +37,7 @@
 #include <asm/break.h>
 #include <asm/cop2.h>
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/dsp.h>
 #include <asm/fpu.h>
 #include <asm/fpu_emulator.h>
arch/mips/mm/c-octeon.c +4 -2
index 44e69e7..e774176 100644
@@ -18,6 +18,7 @@
 #include <asm/bootinfo.h>
 #include <asm/cacheops.h>
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/r4kcache.h>
@@ -184,9 +185,10 @@ static void __cpuinit probe_octeon(void)
 	unsigned long dcache_size;
 	unsigned int config1;
 	struct cpuinfo_mips *c = &current_cpu_data;
+	int cputype = current_cpu_type();
 
 	config1 = read_c0_config1();
-	switch (c->cputype) {
+	switch (cputype) {
 	case CPU_CAVIUM_OCTEON:
 	case CPU_CAVIUM_OCTEON_PLUS:
 		c->icache.linesz = 2 << ((config1 >> 19) & 7);
@@ -197,7 +199,7 @@ static void __cpuinit probe_octeon(void)
 			c->icache.sets * c->icache.ways * c->icache.linesz;
 		c->icache.waybit = ffs(icache_size / c->icache.ways) - 1;
 		c->dcache.linesz = 128;
-		if (c->cputype == CPU_CAVIUM_OCTEON_PLUS)
+		if (cputype == CPU_CAVIUM_OCTEON_PLUS)
 			c->dcache.sets = 2; /* CN5XXX has two Dcache sets */
 		else
 			c->dcache.sets = 1; /* CN3XXX has one Dcache set */
arch/mips/mm/dma-default.c +1 -0
index 3fab204..72df1e4 100644
@@ -18,6 +18,7 @@
 #include <linux/highmem.h>
 
 #include <asm/cache.h>
+#include <asm/cpu-type.h>
 #include <asm/io.h>
 
 #include <dma-coherence.h>
arch/mips/mm/page.c +1 -0
index 98f530e..a37db2f 100644
@@ -18,6 +18,7 @@
 
 #include <asm/bugs.h>
 #include <asm/cacheops.h>
+#include <asm/cpu-type.h>
 #include <asm/inst.h>
 #include <asm/io.h>
 #include <asm/page.h>
arch/mips/mm/tlb-r4k.c +1 -0
index d2572cb..ac6a90a 100644
@@ -15,6 +15,7 @@
 #include <linux/hugetlb.h>
 
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/bootinfo.h>
 #include <asm/mmu_context.h>
 #include <asm/pgtable.h>
arch/mips/mm/tlbex.c +1 -0
index 03eb0ef..a89e523 100644
@@ -30,6 +30,7 @@
 #include <linux/cache.h>
 
 #include <asm/cacheflush.h>
+#include <asm/cpu-type.h>
 #include <asm/pgtable.h>
 #include <asm/war.h>
 #include <asm/uasm.h>
#2 lore raw

On Fri, Dec 07, 2012 at 04:09:46PM +0100, Ralf Baechle wrote:

It's a while already - but I haven't forgotten about this little optimization.

Quoted 14 lines · Steven J. Hill
Quoted 7 lines

From: "Steven J. Hill" <[email protected]>

If the CPU type is selected to be a MIPS32R2 core, we surround some code with #ifdef's to reduce the kernel binary size.

Yes, and a dozen more ifdefs would be needed to handle other places where things could be optimized for a particular CPU type. Best add more random ifdefs across the tree to handle MIPS32R1 and MIPS64R2 and of course Zumbitsu 8000 processors.

Quoted 6 lines

Below is a half-baked test version of a patch that I have in my git tree since you first posted your patch. For a Cavium kernel this shaves off around 6kB.

Obviously this patch relies on a halfway modern compiler's optimization capabilities.

A more elegant version of the previous patch which no longer requires a per platform implementation of current_cpu_type() results in the following size reductions for cavium_octeon_defconfig:

text data bss dec hex filename

5716440  513760  176944 6407144  61c3e8 vmlinux
5714712  513760  176944 6405416  61bd28 vmlinux

That's not a whole lot because cavium_octeon_defconfig still builds a kernel with support for 3 different processors.

Using a quick hack (not in below patch) I reduced CPU support to just a single type. Then not only code for the other 2 variants is dropped by the compiler but also dead code elimination can discard ifs and switches leaving a highly customized, smaller and faster kernel. The best of it is that it doesn't even rely on LTO, just a decent optimizer of a per-file compiler. Patch for your enjoyment below.

I've done my testing with plain old boring gcc 4.7 btw.

Ralf

 arch/mips/cavium-octeon/csrc-octeon.c              |   1 +
 arch/mips/include/asm/cpu-features.h               |   4 -
 arch/mips/include/asm/cpu-type.h                   | 196 +++++++++++++++++++++
 .../include/asm/mach-ip22/cpu-feature-overrides.h  |  25 ---
 .../include/asm/mach-ip27/cpu-feature-overrides.h  |  19 --
 .../include/asm/mach-ip28/cpu-feature-overrides.h  |  18 --
 arch/mips/kernel/cpu-probe.c                       |   3 +-
 arch/mips/kernel/idle.c                            |   3 +-
 arch/mips/kernel/time.c                            |   1 +
 arch/mips/kernel/traps.c                           |   3 +-
 arch/mips/mm/c-octeon.c                            |   6 +-
 arch/mips/mm/c-r4k.c                               |  12 +-
 arch/mips/mm/dma-default.c                         |   1 +
 arch/mips/mm/page.c                                |   1 +
 arch/mips/mm/sc-mips.c                             |   2 +-
 arch/mips/mm/tlb-r4k.c                             |   1 +
 arch/mips/mm/tlbex.c                               |   1 +
 17 files changed, 219 insertions(+), 78 deletions(-)
arch/mips/cavium-octeon/csrc-octeon.c +1 -0
index 0219395..b752c4e 100644
@@ -12,6 +12,7 @@
 #include <linux/smp.h>
 
 #include <asm/cpu-info.h>
+#include <asm/cpu-type.h>
 #include <asm/time.h>
 
 #include <asm/octeon/octeon.h>
arch/mips/include/asm/cpu-features.h +0 -4
index e5ec8fc..26dd4e9 100644
@@ -13,10 +13,6 @@
 #include <asm/cpu-info.h>
 #include <cpu-feature-overrides.h>
 
-#ifndef current_cpu_type
-#define current_cpu_type()	current_cpu_data.cputype
-#endif
-
 /*
  * SMP assumption: Options of CPU 0 are a superset of all processors.
  * This is true for all known MIPS systems.
arch/mips/include/asm/cpu-type.h new file +196 -0

196 lines not on this page · raw message

arch/mips/include/asm/mach-ip22/cpu-feature-overrides.h +0 -25
index 9fd2b50..1bcb642 100644
@@ -10,31 +10,6 @@
 
 #include <asm/cpu.h>
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define __current_cpu_type_unreachable() __builtin_unreachable()
-#else
-#define __current_cpu_type_unreachable() do { } while (0)
-#endif
-
-#define current_cpu_type()						\
-({									\
-	int __cpu = current_cpu_data.cputype;				\
-	switch (__cpu) {						\
-	case CPU_R4000PC:						\
-	case CPU_R4000SC:						\
-	case CPU_R4400PC:						\
-	case CPU_R4400SC:						\
-	case CPU_R4600:							\
-	case CPU_R5000:							\
-		break;							\
-	default:							\
-		__current_cpu_type_unreachable();			\
-		;							\
-	}								\
-	__cpu;								\
-})
-
-
 /*
  * IP22 with a variety of processors so we can't use defaults for everything.
  */
arch/mips/include/asm/mach-ip27/cpu-feature-overrides.h +0 -19
index 8884ba4..d6111aa 100644
@@ -10,25 +10,6 @@
 
 #include <asm/cpu.h>
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define __current_cpu_type_unreachable() __builtin_unreachable()
-#else
-#define __current_cpu_type_unreachable() do { } while (0)
-#endif
-
-#define current_cpu_type()						\
-({									\
-	int __cpu = current_cpu_data.cputype;				\
-	switch (__cpu) {						\
-	case CPU_R10000:						\
-	case CPU_R12000:						\
-		break;							\
-	default:							\
-		__current_cpu_type_unreachable();			\
-	}								\
-	__cpu;								\
-})
-
 /*
  * IP27 only comes with R10000 family processors all using the same config
  */
arch/mips/include/asm/mach-ip28/cpu-feature-overrides.h +0 -18
index c81c5d2..4cec06d 100644
@@ -11,24 +11,6 @@
 
 #include <asm/cpu.h>
 
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
-#define __current_cpu_type_unreachable() __builtin_unreachable()
-#else
-#define __current_cpu_type_unreachable() do { } while (0)
-#endif
-
-#define current_cpu_type()						\
-({									\
-	int __cpu = current_cpu_data.cputype;				\
-	switch (__cpu) {						\
-	case CPU_R10000:						\
-		break;							\
-	default:							\
-		__current_cpu_type_unreachable();			\
-	}								\
-	__cpu;								\
-})
-
 /*
  * IP28 only comes with R10000 family processors all using the same config
  */
arch/mips/kernel/cpu-probe.c +2 -1
index c6568bf..a1daa84 100644
@@ -20,6 +20,7 @@
 
 #include <asm/bugs.h>
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/fpu.h>
 #include <asm/mipsregs.h>
 #include <asm/watch.h>
@@ -55,7 +56,7 @@ static inline void check_errata(void)
 {
 	struct cpuinfo_mips *c = &current_cpu_data;
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_34K:
 		/*
 		 * Erratum "RPS May Cause Incorrect Instruction Execution"
arch/mips/kernel/idle.c +2 -1
index 0c655de..c768138 100644
@@ -18,6 +18,7 @@
 #include <linux/sched.h>
 #include <asm/cpu.h>
 #include <asm/cpu-info.h>
+#include <asm/cpu-type.h>
 #include <asm/idle.h>
 #include <asm/mipsregs.h>
 
@@ -136,7 +137,7 @@ void __init check_wait(void)
 		return;
 	}
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_R3081:
 	case CPU_R3081E:
 		cpu_wait = r3081_wait;
arch/mips/kernel/time.c +1 -0
index 9d686bf..175ec51 100644
@@ -24,6 +24,7 @@
 #include <linux/export.h>
 
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/div64.h>
 #include <asm/smtc_ipi.h>
 #include <asm/time.h>
arch/mips/kernel/traps.c +2 -1
index beba1e6..cc5ac82 100644
@@ -39,6 +39,7 @@
 #include <asm/break.h>
 #include <asm/cop2.h>
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/dsp.h>
 #include <asm/fpu.h>
 #include <asm/fpu_emulator.h>
@@ -622,7 +623,7 @@ static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
 		regs->regs[rt] = read_c0_count();
 		return 0;
 	case 3:		/* Count register resolution */
-		switch (current_cpu_data.cputype) {
+		switch (current_cpu_type()) {
 		case CPU_20KC:
 		case CPU_25KF:
 			regs->regs[rt] = 1;
arch/mips/mm/c-octeon.c +4 -2
index 8557fb5..e84d56e 100644
@@ -19,6 +19,7 @@
 #include <asm/bootinfo.h>
 #include <asm/cacheops.h>
 #include <asm/cpu-features.h>
+#include <asm/cpu-type.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include <asm/r4kcache.h>
@@ -186,9 +187,10 @@ static void __cpuinit probe_octeon(void)
 	unsigned long dcache_size;
 	unsigned int config1;
 	struct cpuinfo_mips *c = &current_cpu_data;
+	int cputype = current_cpu_type();
 
 	config1 = read_c0_config1();
-	switch (c->cputype) {
+	switch (cputype) {
 	case CPU_CAVIUM_OCTEON:
 	case CPU_CAVIUM_OCTEON_PLUS:
 		c->icache.linesz = 2 << ((config1 >> 19) & 7);
@@ -199,7 +201,7 @@ static void __cpuinit probe_octeon(void)
 			c->icache.sets * c->icache.ways * c->icache.linesz;
 		c->icache.waybit = ffs(icache_size / c->icache.ways) - 1;
 		c->dcache.linesz = 128;
-		if (c->cputype == CPU_CAVIUM_OCTEON_PLUS)
+		if (cputype == CPU_CAVIUM_OCTEON_PLUS)
 			c->dcache.sets = 2; /* CN5XXX has two Dcache sets */
 		else
 			c->dcache.sets = 1; /* CN3XXX has one Dcache set */
arch/mips/mm/c-r4k.c +6 -6
index 21813be..57d7975 100644
@@ -809,7 +809,7 @@ static void __cpuinit probe_pcache(void)
 	unsigned long config1;
 	unsigned int lsize;
 
-	switch (c->cputype) {
+	switch (currnt_cpu_type()) {
 	case CPU_R4600:			/* QED style two way caches? */
 	case CPU_R4700:
 	case CPU_R5000:
@@ -1045,7 +1045,7 @@ static void __cpuinit probe_pcache(void)
 	 * normally they'd suffer from aliases but magic in the hardware deals
 	 * with that for us so we don't need to take care ourselves.
 	 */
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_20KC:
 	case CPU_25KF:
 	case CPU_SB1:
@@ -1065,7 +1065,7 @@ static void __cpuinit probe_pcache(void)
 	case CPU_34K:
 	case CPU_74K:
 	case CPU_1004K:
-		if (c->cputype == CPU_74K)
+		if (current_cpu_type() == CPU_74K)
 			alias_74k_erratum(c);
 		if ((read_c0_config7() & (1 << 16))) {
 			/* effectively physically indexed dcache,
@@ -1078,7 +1078,7 @@ static void __cpuinit probe_pcache(void)
 			c->dcache.flags |= MIPS_CACHE_ALIASES;
 	}
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_20KC:
 		/*
 		 * Some older 20Kc chips doesn't have the 'VI' bit in
@@ -1207,7 +1207,7 @@ static void __cpuinit setup_scache(void)
 	 * processors don't have a S-cache that would be relevant to the
 	 * Linux memory management.
 	 */
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_R4000SC:
 	case CPU_R4000MC:
 	case CPU_R4400SC:
@@ -1386,7 +1386,7 @@ static void __cpuinit r4k_cache_error_setup(void)
 	extern char __weak except_vec2_sb1;
 	struct cpuinfo_mips *c = &current_cpu_data;
 
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_SB1:
 	case CPU_SB1A:
 		set_uncached_handler(0x100, &except_vec2_sb1, 0x80);
arch/mips/mm/dma-default.c +1 -0
index caf92ec..0f45890 100644
@@ -18,6 +18,7 @@
 #include <linux/highmem.h>
 
 #include <asm/cache.h>
+#include <asm/cpu-type.h>
 #include <asm/io.h>
 
 #include <dma-coherence.h>
arch/mips/mm/page.c +1 -0
index 4eb8dcf..819bec8 100644
@@ -18,6 +18,7 @@
 
 #include <asm/bugs.h>
 #include <asm/cacheops.h>
+#include <asm/cpu-type.h>
 #include <asm/inst.h>
 #include <asm/io.h>
 #include <asm/page.h>
arch/mips/mm/sc-mips.c +1 -1
index df96da7..cceaaaf 100644
@@ -71,7 +71,7 @@ static inline int mips_sc_is_activated(struct cpuinfo_mips *c)
 	unsigned int tmp;
 
 	/* Check the bypass bit (L2B) */
-	switch (c->cputype) {
+	switch (current_cpu_type()) {
 	case CPU_34K:
 	case CPU_74K:
 	case CPU_1004K:
arch/mips/mm/tlb-r4k.c +1 -0
index c643de4..19968204889 100644
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 
 #include <asm/cpu.h>
+#include <asm/cpu-type.h>
 #include <asm/bootinfo.h>
 #include <asm/mmu_context.h>
 #include <asm/pgtable.h>
arch/mips/mm/tlbex.c +1 -0
index afeef93..767e297 100644
@@ -30,6 +30,7 @@
 #include <linux/cache.h>
 
 #include <asm/cacheflush.h>
+#include <asm/cpu-type.h>
 #include <asm/pgtable.h>
 #include <asm/war.h>
 #include <asm/uasm.h>
#3 lore raw
Quoted 4 lines · Ralf Baechle

On Fri, Dec 07, 2012 at 04:09:46PM +0100, Ralf Baechle wrote:

It's a while already - but I haven't forgotten about this little optimization.

[...]

Quoted 10 lines

Using a quick hack (not in below patch) I reduced CPU support to just a single type. Then not only code for the other 2 variants is dropped by the compiler but also dead code elimination can discard ifs and switches leaving a highly customized, smaller and faster kernel. The best of it is that it doesn't even rely on LTO, just a decent optimizer of a per-file compiler. Patch for your enjoyment below.

I've done my testing with plain old boring gcc 4.7 btw.

Much appreciated. I will test it out here and get back to you. Thanks.

Steve

#4 lore raw

Here's another, hopefully final iteration of this patch. I now have another patch, the fix for the get_cycles() issue that depends on this so would like to push this into 2.12, if still possible.

Ralf