Revert "semaphore: fix"

This reverts commit bf726eab3711cf192405d21688a4b21e07b6188a, as it has
been reported to cause a regression with processes stuck in __down(),
apparently because some missing wakeup.

Quoth Sven Wegener:
"I'm currently investigating a regression that has showed up with my
last git pull yesterday. Bisecting the commits showed bf726e
"semaphore: fix" to be the culprit, reverting it fixed the issue.

Symptoms: During heavy filesystem usage (e.g. a kernel compile) I get
several compiler processes in uninterruptible sleep, blocking all i/o
on the filesystem. System is an Intel Core 2 Quad running a 64bit
kernel and userspace. Filesystem is xfs on top of lvm. See below for
the output of sysrq-w."

See

http://lkml.org/lkml/2008/5/10/45

for full report.

In the meantime, we can just fix the BKL performance regression by
reverting back to the good old BKL spinlock implementation instead,
since any sleeping lock will generally perform badly, especially if it
tries to be fair.

Reported-by: Sven Wegener <sven.wegener@stealer.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+34 -30
+34 -30
kernel/semaphore.c
··· 54 unsigned long flags; 55 56 spin_lock_irqsave(&sem->lock, flags); 57 - if (unlikely(!sem->count)) 58 __down(sem); 59 - sem->count--; 60 spin_unlock_irqrestore(&sem->lock, flags); 61 } 62 EXPORT_SYMBOL(down); ··· 77 int result = 0; 78 79 spin_lock_irqsave(&sem->lock, flags); 80 - if (unlikely(!sem->count)) 81 - result = __down_interruptible(sem); 82 - if (!result) 83 sem->count--; 84 spin_unlock_irqrestore(&sem->lock, flags); 85 86 return result; ··· 103 int result = 0; 104 105 spin_lock_irqsave(&sem->lock, flags); 106 - if (unlikely(!sem->count)) 107 - result = __down_killable(sem); 108 - if (!result) 109 sem->count--; 110 spin_unlock_irqrestore(&sem->lock, flags); 111 112 return result; ··· 157 int result = 0; 158 159 spin_lock_irqsave(&sem->lock, flags); 160 - if (unlikely(!sem->count)) 161 - result = __down_timeout(sem, jiffies); 162 - if (!result) 163 sem->count--; 164 spin_unlock_irqrestore(&sem->lock, flags); 165 166 return result; ··· 179 unsigned long flags; 180 181 spin_lock_irqsave(&sem->lock, flags); 182 - sem->count++; 183 - if (unlikely(!list_empty(&sem->wait_list))) 184 __up(sem); 185 spin_unlock_irqrestore(&sem->lock, flags); 186 } ··· 192 struct semaphore_waiter { 193 struct list_head list; 194 struct task_struct *task; 195 }; 196 197 /* ··· 205 { 206 struct task_struct *task = current; 207 struct semaphore_waiter waiter; 208 - int ret = 0; 209 210 - waiter.task = task; 211 list_add_tail(&waiter.list, &sem->wait_list); 212 213 for (;;) { 214 - if (state == TASK_INTERRUPTIBLE && signal_pending(task)) { 215 - ret = -EINTR; 216 - break; 217 - } 218 - if (state == TASK_KILLABLE && fatal_signal_pending(task)) { 219 - ret = -EINTR; 220 - break; 221 - } 222 - if (timeout <= 0) { 223 - ret = -ETIME; 224 - break; 225 - } 226 __set_task_state(task, state); 227 spin_unlock_irq(&sem->lock); 228 timeout = schedule_timeout(timeout); 229 spin_lock_irq(&sem->lock); 230 - if (sem->count > 0) 231 - break; 232 } 233 234 list_del(&waiter.list); 235 - return ret; 236 } 237 238 static noinline void __sched __down(struct semaphore *sem) ··· 258 { 259 struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list, 260 struct semaphore_waiter, list); 261 wake_up_process(waiter->task); 262 }
··· 54 unsigned long flags; 55 56 spin_lock_irqsave(&sem->lock, flags); 57 + if (likely(sem->count > 0)) 58 + sem->count--; 59 + else 60 __down(sem); 61 spin_unlock_irqrestore(&sem->lock, flags); 62 } 63 EXPORT_SYMBOL(down); ··· 76 int result = 0; 77 78 spin_lock_irqsave(&sem->lock, flags); 79 + if (likely(sem->count > 0)) 80 sem->count--; 81 + else 82 + result = __down_interruptible(sem); 83 spin_unlock_irqrestore(&sem->lock, flags); 84 85 return result; ··· 102 int result = 0; 103 104 spin_lock_irqsave(&sem->lock, flags); 105 + if (likely(sem->count > 0)) 106 sem->count--; 107 + else 108 + result = __down_killable(sem); 109 spin_unlock_irqrestore(&sem->lock, flags); 110 111 return result; ··· 156 int result = 0; 157 158 spin_lock_irqsave(&sem->lock, flags); 159 + if (likely(sem->count > 0)) 160 sem->count--; 161 + else 162 + result = __down_timeout(sem, jiffies); 163 spin_unlock_irqrestore(&sem->lock, flags); 164 165 return result; ··· 178 unsigned long flags; 179 180 spin_lock_irqsave(&sem->lock, flags); 181 + if (likely(list_empty(&sem->wait_list))) 182 + sem->count++; 183 + else 184 __up(sem); 185 spin_unlock_irqrestore(&sem->lock, flags); 186 } ··· 190 struct semaphore_waiter { 191 struct list_head list; 192 struct task_struct *task; 193 + int up; 194 }; 195 196 /* ··· 202 { 203 struct task_struct *task = current; 204 struct semaphore_waiter waiter; 205 206 list_add_tail(&waiter.list, &sem->wait_list); 207 + waiter.task = task; 208 + waiter.up = 0; 209 210 for (;;) { 211 + if (state == TASK_INTERRUPTIBLE && signal_pending(task)) 212 + goto interrupted; 213 + if (state == TASK_KILLABLE && fatal_signal_pending(task)) 214 + goto interrupted; 215 + if (timeout <= 0) 216 + goto timed_out; 217 __set_task_state(task, state); 218 spin_unlock_irq(&sem->lock); 219 timeout = schedule_timeout(timeout); 220 spin_lock_irq(&sem->lock); 221 + if (waiter.up) 222 + return 0; 223 } 224 225 + timed_out: 226 list_del(&waiter.list); 227 + return -ETIME; 228 + 229 + interrupted: 230 + list_del(&waiter.list); 231 + return -EINTR; 232 } 233 234 static noinline void __sched __down(struct semaphore *sem) ··· 256 { 257 struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list, 258 struct semaphore_waiter, list); 259 + list_del(&waiter->list); 260 + waiter->up = 1; 261 wake_up_process(waiter->task); 262 }