Skip to content

Commit 6c8cd5b

Browse files
Philipp HachtmannMartin Schwidefsky
authored andcommitted
s390/spinlock: optimize spinlock code sequence
Use lowcore constant to improve the code generated for spinlocks. [ Martin Schwidefsky: patch breakdown and code beautification ] Signed-off-by: Philipp Hachtmann <phacht@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 5b3f683 commit 6c8cd5b

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎arch/s390/include/asm/lowcore.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct _lowcore {
139139
__u32 percpu_offset; /* 0x02f0 */
140140
__u32 machine_flags; /* 0x02f4 */
141141
__u32 ftrace_func; /* 0x02f8 */
142-
__u8 pad_0x02fc[0x0300-0x02fc]; /* 0x02fc */
142+
__u32 spinlock_lockval; /* 0x02fc */
143143

144144
/* Interrupt response block */
145145
__u8 irb[64]; /* 0x0300 */
@@ -285,7 +285,8 @@ struct _lowcore {
285285
__u64 machine_flags; /* 0x0388 */
286286
__u64 ftrace_func; /* 0x0390 */
287287
__u64 gmap; /* 0x0398 */
288-
__u8 pad_0x03a0[0x0400-0x03a0]; /* 0x03a0 */
288+
__u32 spinlock_lockval; /* 0x03a0 */
289+
__u8 pad_0x03a0[0x0400-0x03a4]; /* 0x03a4 */
289290

290291
/* Interrupt response block. */
291292
__u8 irb[64]; /* 0x0400 */

‎arch/s390/include/asm/spinlock.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <linux/smp.h>
1313

14+
#define SPINLOCK_LOCKVAL (S390_lowcore.spinlock_lockval)
15+
1416
extern int spin_retry;
1517

1618
static inline int
@@ -40,6 +42,11 @@ int arch_spin_trylock_retry(arch_spinlock_t *);
4042
void arch_spin_relax(arch_spinlock_t *);
4143
void arch_spin_lock_wait_flags(arch_spinlock_t *, unsigned long flags);
4244

45+
static inline u32 arch_spin_lockval(int cpu)
46+
{
47+
return ~cpu;
48+
}
49+
4350
static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
4451
{
4552
return lock.lock == 0;
@@ -52,16 +59,12 @@ static inline int arch_spin_is_locked(arch_spinlock_t *lp)
5259

5360
static inline int arch_spin_trylock_once(arch_spinlock_t *lp)
5461
{
55-
unsigned int new = ~smp_processor_id();
56-
57-
return _raw_compare_and_swap(&lp->lock, 0, new);
62+
return _raw_compare_and_swap(&lp->lock, 0, SPINLOCK_LOCKVAL);
5863
}
5964

6065
static inline int arch_spin_tryrelease_once(arch_spinlock_t *lp)
6166
{
62-
unsigned int old = ~smp_processor_id();
63-
64-
return _raw_compare_and_swap(&lp->lock, old, 0);
67+
return _raw_compare_and_swap(&lp->lock, SPINLOCK_LOCKVAL, 0);
6568
}
6669

6770
static inline void arch_spin_lock(arch_spinlock_t *lp)

‎arch/s390/kernel/setup.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ static void __init setup_lowcore(void)
373373
mem_assign_absolute(S390_lowcore.restart_source, lc->restart_source);
374374
mem_assign_absolute(S390_lowcore.restart_psw, lc->restart_psw);
375375

376+
#ifdef CONFIG_SMP
377+
lc->spinlock_lockval = arch_spin_lockval(0);
378+
#endif
379+
376380
set_prefix((u32)(unsigned long) lc);
377381
lowcore_ptr[0] = lc;
378382
}

‎arch/s390/kernel/smp.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
170170
lc->panic_stack = pcpu->panic_stack + PAGE_SIZE
171171
- STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
172172
lc->cpu_nr = cpu;
173+
lc->spinlock_lockval = arch_spin_lockval(cpu);
173174
#ifndef CONFIG_64BIT
174175
if (MACHINE_HAS_IEEE) {
175176
lc->extended_save_area_addr = get_zeroed_page(GFP_KERNEL);
@@ -226,6 +227,7 @@ static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
226227
cpumask_set_cpu(cpu, mm_cpumask(&init_mm));
227228
atomic_inc(&init_mm.context.attach_count);
228229
lc->cpu_nr = cpu;
230+
lc->spinlock_lockval = arch_spin_lockval(cpu);
229231
lc->percpu_offset = __per_cpu_offset[cpu];
230232
lc->kernel_asce = S390_lowcore.kernel_asce;
231233
lc->machine_flags = S390_lowcore.machine_flags;
@@ -809,6 +811,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
809811
void __init smp_setup_processor_id(void)
810812
{
811813
S390_lowcore.cpu_nr = 0;
814+
S390_lowcore.spinlock_lockval = arch_spin_lockval(0);
812815
}
813816

814817
/*

‎arch/s390/lib/spinlock.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ __setup("spin_retry=", spin_retry_setup);
2727
void arch_spin_lock_wait(arch_spinlock_t *lp)
2828
{
2929
int count = spin_retry;
30-
unsigned int cpu = ~smp_processor_id();
30+
unsigned int cpu = SPINLOCK_LOCKVAL;
3131
unsigned int owner;
3232

3333
while (1) {
@@ -54,7 +54,7 @@ EXPORT_SYMBOL(arch_spin_lock_wait);
5454
void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags)
5555
{
5656
int count = spin_retry;
57-
unsigned int cpu = ~smp_processor_id();
57+
unsigned int cpu = SPINLOCK_LOCKVAL;
5858
unsigned int owner;
5959

6060
local_irq_restore(flags);

0 commit comments

Comments
 (0)