Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: R12000: Enable branch prediction global history

The R12000 added a new feature to enhance branch prediction called
"global history". Per the Vr10000 Series User Manual (U10278EJ4V0UM),
Coprocessor 0, Diagnostic Register (22):

"""
If bit 26 is set, branch prediction uses all eight bits of the global
history register. If bit 26 is not set, then bits 25:23 specify a count
of the number of bits of global history to be used. Thus if bits 26:23
are all zero, global history is disabled.

The global history contains a record of the taken/not-taken status of
recently executed branches, and when used is XOR'ed with the PC of a
branch being predicted to produce a hashed value for indexing the BPT.
Some programs with small "working set of conditional branches" benefit
significantly from the use of such hashing, some see slight performance
degradation.
"""

This patch enables global history on R12000 CPUs and up by setting bit
26 in the branch prediction diagnostic register (CP0 $22) to '1'. Bits
25:23 are left alone so that all eight bits of the global history
register are available for branch prediction.

Signed-off-by: Joshua Kinard <kumba@gentoo.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Joshua Kinard and committed by
Ralf Baechle
8d5ded16 0ebb2f41

+23 -2
+3
arch/mips/include/asm/cpu-features.h
··· 108 108 #ifndef cpu_has_llsc 109 109 #define cpu_has_llsc (cpu_data[0].options & MIPS_CPU_LLSC) 110 110 #endif 111 + #ifndef cpu_has_bp_ghist 112 + #define cpu_has_bp_ghist (cpu_data[0].options & MIPS_CPU_BP_GHIST) 113 + #endif 111 114 #ifndef kernel_uses_llsc 112 115 #define kernel_uses_llsc cpu_has_llsc 113 116 #endif
+1
arch/mips/include/asm/cpu.h
··· 381 381 #define MIPS_CPU_RW_LLB 0x1000000000ull /* LLADDR/LLB writes are allowed */ 382 382 #define MIPS_CPU_XPA 0x2000000000ull /* CPU supports Extended Physical Addressing */ 383 383 #define MIPS_CPU_CDMM 0x4000000000ull /* CPU has Common Device Memory Map */ 384 + #define MIPS_CPU_BP_GHIST 0x8000000000ull /* R12K+ Branch Prediction Global History */ 384 385 385 386 /* 386 387 * CPU ASE encodings
+13
arch/mips/include/asm/mipsregs.h
··· 707 707 #define TX39_CONF_DRSIZE_SHIFT 0 708 708 #define TX39_CONF_DRSIZE_MASK 0x00000003 709 709 710 + /* 711 + * Interesting Bits in the R10K CP0 Branch Diagnostic Register 712 + */ 713 + /* Disable Branch Target Address Cache */ 714 + #define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27) 715 + /* Enable Branch Prediction Global History */ 716 + #define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26) 717 + /* Disable Branch Return Cache */ 718 + #define R10K_DIAG_D_BRC (_ULCAST_(1) << 22) 710 719 711 720 /* 712 721 * Coprocessor 1 (FPU) register names ··· 1277 1268 1278 1269 #define read_c0_diag() __read_32bit_c0_register($22, 0) 1279 1270 #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val) 1271 + 1272 + /* R10K CP0 Branch Diagnostic register is 64bits wide */ 1273 + #define read_c0_r10k_diag() __read_64bit_c0_register($22, 0) 1274 + #define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val) 1280 1275 1281 1276 #define read_c0_diag1() __read_32bit_c0_register($22, 1) 1282 1277 #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
+6 -2
arch/mips/kernel/cpu-probe.c
··· 945 945 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX | 946 946 MIPS_CPU_FPU | MIPS_CPU_32FPR | 947 947 MIPS_CPU_COUNTER | MIPS_CPU_WATCH | 948 - MIPS_CPU_LLSC; 948 + MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST; 949 949 c->tlbsize = 64; 950 950 break; 951 951 case PRID_IMP_R14000: ··· 960 960 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX | 961 961 MIPS_CPU_FPU | MIPS_CPU_32FPR | 962 962 MIPS_CPU_COUNTER | MIPS_CPU_WATCH | 963 - MIPS_CPU_LLSC; 963 + MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST; 964 964 c->tlbsize = 64; 965 965 break; 966 966 case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */ ··· 1479 1479 cpu_set_fpu_opts(c); 1480 1480 else 1481 1481 cpu_set_nofpu_opts(c); 1482 + 1483 + if (cpu_has_bp_ghist) 1484 + write_c0_r10k_diag(read_c0_r10k_diag() | 1485 + R10K_DIAG_E_GHIST); 1482 1486 1483 1487 if (cpu_has_mips_r2_r6) { 1484 1488 c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;