diff options
| -rw-r--r-- | arch/sparc/include/asm/backoff.h | 42 | ||||
| -rw-r--r-- | arch/sparc/include/asm/processor_64.h | 7 | ||||
| -rw-r--r-- | arch/sparc/kernel/entry.h | 4 | ||||
| -rw-r--r-- | arch/sparc/kernel/setup_64.c | 4 | ||||
| -rw-r--r-- | arch/sparc/kernel/vmlinux.lds.S | 8 |
5 files changed, 55 insertions, 10 deletions
diff --git a/arch/sparc/include/asm/backoff.h b/arch/sparc/include/asm/backoff.h index 20f01df0871b..4e02086b839c 100644 --- a/arch/sparc/include/asm/backoff.h +++ b/arch/sparc/include/asm/backoff.h | |||
| @@ -1,6 +1,46 @@ | |||
| 1 | #ifndef _SPARC64_BACKOFF_H | 1 | #ifndef _SPARC64_BACKOFF_H |
| 2 | #define _SPARC64_BACKOFF_H | 2 | #define _SPARC64_BACKOFF_H |
| 3 | 3 | ||
| 4 | /* The macros in this file implement an exponential backoff facility | ||
| 5 | * for atomic operations. | ||
| 6 | * | ||
| 7 | * When multiple threads compete on an atomic operation, it is | ||
| 8 | * possible for one thread to be continually denied a successful | ||
| 9 | * completion of the compare-and-swap instruction. Heavily | ||
| 10 | * threaded cpu implementations like Niagara can compound this | ||
| 11 | * problem even further. | ||
| 12 | * | ||
| 13 | * When an atomic operation fails and needs to be retried, we spin a | ||
| 14 | * certain number of times. At each subsequent failure of the same | ||
| 15 | * operation we double the spin count, realizing an exponential | ||
| 16 | * backoff. | ||
| 17 | * | ||
| 18 | * When we spin, we try to use an operation that will cause the | ||
| 19 | * current cpu strand to block, and therefore make the core fully | ||
| 20 | * available to any other other runnable strands. There are two | ||
| 21 | * options, based upon cpu capabilities. | ||
| 22 | * | ||
| 23 | * On all cpus prior to SPARC-T4 we do three dummy reads of the | ||
| 24 | * condition code register. Each read blocks the strand for something | ||
| 25 | * between 40 and 50 cpu cycles. | ||
| 26 | * | ||
| 27 | * For SPARC-T4 and later we have a special "pause" instruction | ||
| 28 | * available. This is implemented using writes to register %asr27. | ||
| 29 | * The cpu will block the number of cycles written into the register, | ||
| 30 | * unless a disrupting trap happens first. SPARC-T4 specifically | ||
| 31 | * implements pause with a granularity of 8 cycles. Each strand has | ||
| 32 | * an internal pause counter which decrements every 8 cycles. So the | ||
| 33 | * chip shifts the %asr27 value down by 3 bits, and writes the result | ||
| 34 | * into the pause counter. If a value smaller than 8 is written, the | ||
| 35 | * chip blocks for 1 cycle. | ||
| 36 | * | ||
| 37 | * To achieve the same amount of backoff as the three %ccr reads give | ||
| 38 | * on earlier chips, we shift the backoff value up by 7 bits. (Three | ||
| 39 | * %ccr reads block for about 128 cycles, 1 << 7 == 128) We write the | ||
| 40 | * whole amount we want to block into the pause register, rather than | ||
| 41 | * loop writing 128 each time. | ||
| 42 | */ | ||
| 43 | |||
| 4 | #define BACKOFF_LIMIT (4 * 1024) | 44 | #define BACKOFF_LIMIT (4 * 1024) |
| 5 | 45 | ||
| 6 | #ifdef CONFIG_SMP | 46 | #ifdef CONFIG_SMP |
| @@ -16,7 +56,7 @@ | |||
| 16 | 88: rd %ccr, %g0; \ | 56 | 88: rd %ccr, %g0; \ |
| 17 | rd %ccr, %g0; \ | 57 | rd %ccr, %g0; \ |
| 18 | rd %ccr, %g0; \ | 58 | rd %ccr, %g0; \ |
| 19 | .section .pause_patch,"ax"; \ | 59 | .section .pause_3insn_patch,"ax";\ |
| 20 | .word 88b; \ | 60 | .word 88b; \ |
| 21 | sllx tmp, 7, tmp; \ | 61 | sllx tmp, 7, tmp; \ |
| 22 | wr tmp, 0, %asr27; \ | 62 | wr tmp, 0, %asr27; \ |
diff --git a/arch/sparc/include/asm/processor_64.h b/arch/sparc/include/asm/processor_64.h index 9cdf52eec48a..721e25f0e2ea 100644 --- a/arch/sparc/include/asm/processor_64.h +++ b/arch/sparc/include/asm/processor_64.h | |||
| @@ -196,11 +196,16 @@ extern unsigned long get_wchan(struct task_struct *task); | |||
| 196 | #define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc) | 196 | #define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc) |
| 197 | #define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP]) | 197 | #define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP]) |
| 198 | 198 | ||
| 199 | /* Please see the commentary in asm/backoff.h for a description of | ||
| 200 | * what these instructions are doing and how they have been choosen. | ||
| 201 | * To make a long story short, we are trying to yield the current cpu | ||
| 202 | * strand during busy loops. | ||
| 203 | */ | ||
| 199 | #define cpu_relax() asm volatile("\n99:\n\t" \ | 204 | #define cpu_relax() asm volatile("\n99:\n\t" \ |
| 200 | "rd %%ccr, %%g0\n\t" \ | 205 | "rd %%ccr, %%g0\n\t" \ |
| 201 | "rd %%ccr, %%g0\n\t" \ | 206 | "rd %%ccr, %%g0\n\t" \ |
| 202 | "rd %%ccr, %%g0\n\t" \ | 207 | "rd %%ccr, %%g0\n\t" \ |
| 203 | ".section .pause_patch,\"ax\"\n\t"\ | 208 | ".section .pause_3insn_patch,\"ax\"\n\t"\ |
| 204 | ".word 99b\n\t" \ | 209 | ".word 99b\n\t" \ |
| 205 | "wr %%g0, 128, %%asr27\n\t" \ | 210 | "wr %%g0, 128, %%asr27\n\t" \ |
| 206 | "nop\n\t" \ | 211 | "nop\n\t" \ |
diff --git a/arch/sparc/kernel/entry.h b/arch/sparc/kernel/entry.h index 51742df63c75..cc3c5cb47cda 100644 --- a/arch/sparc/kernel/entry.h +++ b/arch/sparc/kernel/entry.h | |||
| @@ -63,8 +63,8 @@ struct pause_patch_entry { | |||
| 63 | unsigned int addr; | 63 | unsigned int addr; |
| 64 | unsigned int insns[3]; | 64 | unsigned int insns[3]; |
| 65 | }; | 65 | }; |
| 66 | extern struct pause_patch_entry __pause_patch, | 66 | extern struct pause_patch_entry __pause_3insn_patch, |
| 67 | __pause_patch_end; | 67 | __pause_3insn_patch_end; |
| 68 | 68 | ||
| 69 | extern void __init per_cpu_patch(void); | 69 | extern void __init per_cpu_patch(void); |
| 70 | extern void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *, | 70 | extern void sun4v_patch_1insn_range(struct sun4v_1insn_patch_entry *, |
diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c index b45cff408de3..0eaf0059aaef 100644 --- a/arch/sparc/kernel/setup_64.c +++ b/arch/sparc/kernel/setup_64.c | |||
| @@ -320,8 +320,8 @@ static void __init pause_patch(void) | |||
| 320 | { | 320 | { |
| 321 | struct pause_patch_entry *p; | 321 | struct pause_patch_entry *p; |
| 322 | 322 | ||
| 323 | p = &__pause_patch; | 323 | p = &__pause_3insn_patch; |
| 324 | while (p < &__pause_patch_end) { | 324 | while (p < &__pause_3insn_patch_end) { |
| 325 | unsigned long i, addr = p->addr; | 325 | unsigned long i, addr = p->addr; |
| 326 | 326 | ||
| 327 | for (i = 0; i < 3; i++) { | 327 | for (i = 0; i < 3; i++) { |
diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S index 847f9f793618..0bacceb19150 100644 --- a/arch/sparc/kernel/vmlinux.lds.S +++ b/arch/sparc/kernel/vmlinux.lds.S | |||
| @@ -132,10 +132,10 @@ SECTIONS | |||
| 132 | *(.popc_6insn_patch) | 132 | *(.popc_6insn_patch) |
| 133 | __popc_6insn_patch_end = .; | 133 | __popc_6insn_patch_end = .; |
| 134 | } | 134 | } |
| 135 | .pause_patch : { | 135 | .pause_3insn_patch : { |
| 136 | __pause_patch = .; | 136 | __pause_3insn_patch = .; |
| 137 | *(.pause_patch) | 137 | *(.pause_3insn_patch) |
| 138 | __pause_patch_end = .; | 138 | __pause_3insn_patch_end = .; |
| 139 | } | 139 | } |
| 140 | PERCPU_SECTION(SMP_CACHE_BYTES) | 140 | PERCPU_SECTION(SMP_CACHE_BYTES) |
| 141 | 141 | ||
