aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/lib/spinlock.c
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2006-10-01 02:27:45 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-01 03:39:22 -0400
commit3c1fcfe229e99752c74efb945a4a3f560be04204 (patch)
tree44085d9b599e06a92426141811a6f712beac17aa /arch/s390/lib/spinlock.c
parentcdc39363d33506b0e067d41fc91f89d186bdf7f7 (diff)
[PATCH] Directed yield: direct yield of spinlocks for s390.
Use the new diagnose 0x9c in the spinlock implementation for s390. It yields the remaining timeslice of the virtual cpu that tries to acquire a lock to the virtual cpu that is the current holder of the lock. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/s390/lib/spinlock.c')
-rw-r--r--arch/s390/lib/spinlock.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
index b9b7958a226a..8d76403fcf89 100644
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -24,57 +24,76 @@ static int __init spin_retry_setup(char *str)
24} 24}
25__setup("spin_retry=", spin_retry_setup); 25__setup("spin_retry=", spin_retry_setup);
26 26
27static inline void 27static inline void _raw_yield(void)
28_diag44(void)
29{ 28{
30#ifdef CONFIG_64BIT
31 if (MACHINE_HAS_DIAG44) 29 if (MACHINE_HAS_DIAG44)
32#endif
33 asm volatile("diag 0,0,0x44"); 30 asm volatile("diag 0,0,0x44");
34} 31}
35 32
36void 33static inline void _raw_yield_cpu(int cpu)
37_raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc) 34{
35 if (MACHINE_HAS_DIAG9C)
36 asm volatile("diag %0,0,0x9c"
37 : : "d" (__cpu_logical_map[cpu]));
38 else
39 _raw_yield();
40}
41
42void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
38{ 43{
39 int count = spin_retry; 44 int count = spin_retry;
45 unsigned int cpu = ~smp_processor_id();
40 46
41 while (1) { 47 while (1) {
42 if (count-- <= 0) { 48 if (count-- <= 0) {
43 _diag44(); 49 unsigned int owner = lp->owner_cpu;
50 if (owner != 0)
51 _raw_yield_cpu(~owner);
44 count = spin_retry; 52 count = spin_retry;
45 } 53 }
46 if (__raw_spin_is_locked(lp)) 54 if (__raw_spin_is_locked(lp))
47 continue; 55 continue;
48 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) 56 if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) {
57 lp->owner_pc = pc;
49 return; 58 return;
59 }
50 } 60 }
51} 61}
52EXPORT_SYMBOL(_raw_spin_lock_wait); 62EXPORT_SYMBOL(_raw_spin_lock_wait);
53 63
54int 64int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
55_raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
56{ 65{
57 int count = spin_retry; 66 unsigned int cpu = ~smp_processor_id();
67 int count;
58 68
59 while (count-- > 0) { 69 for (count = spin_retry; count > 0; count--) {
60 if (__raw_spin_is_locked(lp)) 70 if (__raw_spin_is_locked(lp))
61 continue; 71 continue;
62 if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) 72 if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) {
73 lp->owner_pc = pc;
63 return 1; 74 return 1;
75 }
64 } 76 }
65 return 0; 77 return 0;
66} 78}
67EXPORT_SYMBOL(_raw_spin_trylock_retry); 79EXPORT_SYMBOL(_raw_spin_trylock_retry);
68 80
69void 81void _raw_spin_relax(raw_spinlock_t *lock)
70_raw_read_lock_wait(raw_rwlock_t *rw) 82{
83 unsigned int cpu = lock->owner_cpu;
84 if (cpu != 0)
85 _raw_yield_cpu(~cpu);
86}
87EXPORT_SYMBOL(_raw_spin_relax);
88
89void _raw_read_lock_wait(raw_rwlock_t *rw)
71{ 90{
72 unsigned int old; 91 unsigned int old;
73 int count = spin_retry; 92 int count = spin_retry;
74 93
75 while (1) { 94 while (1) {
76 if (count-- <= 0) { 95 if (count-- <= 0) {
77 _diag44(); 96 _raw_yield();
78 count = spin_retry; 97 count = spin_retry;
79 } 98 }
80 if (!__raw_read_can_lock(rw)) 99 if (!__raw_read_can_lock(rw))
@@ -86,8 +105,7 @@ _raw_read_lock_wait(raw_rwlock_t *rw)
86} 105}
87EXPORT_SYMBOL(_raw_read_lock_wait); 106EXPORT_SYMBOL(_raw_read_lock_wait);
88 107
89int 108int _raw_read_trylock_retry(raw_rwlock_t *rw)
90_raw_read_trylock_retry(raw_rwlock_t *rw)
91{ 109{
92 unsigned int old; 110 unsigned int old;
93 int count = spin_retry; 111 int count = spin_retry;
@@ -103,14 +121,13 @@ _raw_read_trylock_retry(raw_rwlock_t *rw)
103} 121}
104EXPORT_SYMBOL(_raw_read_trylock_retry); 122EXPORT_SYMBOL(_raw_read_trylock_retry);
105 123
106void 124void _raw_write_lock_wait(raw_rwlock_t *rw)
107_raw_write_lock_wait(raw_rwlock_t *rw)
108{ 125{
109 int count = spin_retry; 126 int count = spin_retry;
110 127
111 while (1) { 128 while (1) {
112 if (count-- <= 0) { 129 if (count-- <= 0) {
113 _diag44(); 130 _raw_yield();
114 count = spin_retry; 131 count = spin_retry;
115 } 132 }
116 if (!__raw_write_can_lock(rw)) 133 if (!__raw_write_can_lock(rw))
@@ -121,8 +138,7 @@ _raw_write_lock_wait(raw_rwlock_t *rw)
121} 138}
122EXPORT_SYMBOL(_raw_write_lock_wait); 139EXPORT_SYMBOL(_raw_write_lock_wait);
123 140
124int 141int _raw_write_trylock_retry(raw_rwlock_t *rw)
125_raw_write_trylock_retry(raw_rwlock_t *rw)
126{ 142{
127 int count = spin_retry; 143 int count = spin_retry;
128 144