Skip to content

Commit 79ab11c

Browse files
Christian Borntraegeringomolnar
authored andcommitted
locking/core: Introduce cpu_relax_yield()
For spinning loops people do often use barrier() or cpu_relax(). For most architectures cpu_relax and barrier are the same, but on some architectures cpu_relax can add some latency. For example on power,sparc64 and arc, cpu_relax can shift the CPU towards other hardware threads in an SMT environment. On s390 cpu_relax does even more, it uses an hypercall to the hypervisor to give up the timeslice. In contrast to the SMT yielding this can result in larger latencies. In some places this latency is unwanted, so another variant "cpu_relax_lowlatency" was introduced. Before this is used in more and more places, lets revert the logic and provide a cpu_relax_yield that can be called in places where yielding is more important than latency. By default this is the same as cpu_relax on all architectures. Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Noam Camus <noamc@ezchip.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: linuxppc-dev@lists.ozlabs.org Cc: virtualization@lists.linux-foundation.org Cc: xen-devel@lists.xenproject.org Link: http://lkml.kernel.org/r/1477386195-32736-2-git-send-email-borntraeger@de.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 0f5225b commit 79ab11c

33 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎arch/alpha/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ unsigned long get_wchan(struct task_struct *p);
5858
((tsk) == current ? rdusp() : task_thread_info(tsk)->pcb.usp)
5959

6060
#define cpu_relax() barrier()
61+
#define cpu_relax_yield() cpu_relax()
6162
#define cpu_relax_lowlatency() cpu_relax()
6263

6364
#define ARCH_HAS_PREFETCH

‎arch/arc/include/asm/processor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ struct task_struct;
6060
#ifndef CONFIG_EZNPS_MTM_EXT
6161

6262
#define cpu_relax() barrier()
63+
#define cpu_relax_yield() cpu_relax()
6364
#define cpu_relax_lowlatency() cpu_relax()
6465

6566
#else
6667

6768
#define cpu_relax() \
6869
__asm__ __volatile__ (".word %0" : : "i"(CTOP_INST_SCHD_RW) : "memory")
6970

71+
#define cpu_relax_yield() cpu_relax()
7072
#define cpu_relax_lowlatency() barrier()
7173

7274
#endif

‎arch/arm/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ unsigned long get_wchan(struct task_struct *p);
8282
#define cpu_relax() barrier()
8383
#endif
8484

85+
#define cpu_relax_yield() cpu_relax()
8586
#define cpu_relax_lowlatency() cpu_relax()
8687

8788
#define task_pt_regs(p) \

‎arch/arm64/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static inline void cpu_relax(void)
149149
asm volatile("yield" ::: "memory");
150150
}
151151

152+
#define cpu_relax_yield() cpu_relax()
152153
#define cpu_relax_lowlatency() cpu_relax()
153154

154155
/* Thread switching */

‎arch/avr32/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern struct avr32_cpuinfo boot_cpu_data;
9292
#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
9393

9494
#define cpu_relax() barrier()
95+
#define cpu_relax_yield() cpu_relax()
9596
#define cpu_relax_lowlatency() cpu_relax()
9697
#define cpu_sync_pipeline() asm volatile("sub pc, -2" : : : "memory")
9798

‎arch/blackfin/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ unsigned long get_wchan(struct task_struct *p);
9292
#define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
9393

9494
#define cpu_relax() smp_mb()
95+
#define cpu_relax_yield() cpu_relax()
9596
#define cpu_relax_lowlatency() cpu_relax()
9697

9798
/* Get the Silicon Revision of the chip */

‎arch/c6x/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ extern unsigned long get_wchan(struct task_struct *p);
121121
#define KSTK_ESP(task) (task_pt_regs(task)->sp)
122122

123123
#define cpu_relax() do { } while (0)
124+
#define cpu_relax_yield() cpu_relax()
124125
#define cpu_relax_lowlatency() cpu_relax()
125126

126127
extern const struct seq_operations cpuinfo_op;

‎arch/cris/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ static inline void release_thread(struct task_struct *dead_task)
6363
#define init_stack (init_thread_union.stack)
6464

6565
#define cpu_relax() barrier()
66+
#define cpu_relax_yield() cpu_relax()
6667
#define cpu_relax_lowlatency() cpu_relax()
6768

6869
void default_idle(void);

‎arch/frv/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ unsigned long get_wchan(struct task_struct *p);
107107
#define KSTK_ESP(tsk) ((tsk)->thread.frame0->sp)
108108

109109
#define cpu_relax() barrier()
110+
#define cpu_relax_yield() cpu_relax()
110111
#define cpu_relax_lowlatency() cpu_relax()
111112

112113
/* data cache prefetch */

‎arch/h8300/include/asm/processor.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ unsigned long get_wchan(struct task_struct *p);
127127
#define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
128128

129129
#define cpu_relax() barrier()
130+
#define cpu_relax_yield() cpu_relax()
130131
#define cpu_relax_lowlatency() cpu_relax()
131132

132133
#define HARD_RESET_NOW() ({ \

0 commit comments

Comments
 (0)