semaphore problem
as i suspected, the pipe problem was a semaphore problem. here's how it works:
P1: down() count = 0
P2: down() -> __down() -> schedule() count = -1
P1: up() -> wake_up() [P1 placed on runqueue] count = 0
P1: down() -> __down() -> schedule() count = -1
now P2 gets scheduled, sees count is -1, assumes it missed the wakeup and goes back to sleep. both tasks are now sleeping on the same semaphore.
i'm going to bed now. 'night!
Signature · 1 line
Revolutions do not require corporate support.
Quoted 3 lines · Matthew Wilcox
as i suspected, the pipe problem was a semaphore problem. here's how it works:
OK, I've redesigned the semaphore code on the whiteboard. Here's how it works.
The `count' variable is initialised to N for N simultaneous accesses. A value of 0 indicates there are no processes waiting. A value of -1 indicates there are processes waiting. Each up() increments the count by 1 if non-negative. if negative, it _decrements the count. So we can distinguish between the following cases:
N : N more processes allowed in
0 : no new processes allowed in, none waiting
-1 : processes waiting, no wakeups in flight
-N : N - 1 wakeups in flight
This allows us to implement wakeup stealing if we want. Unsure about starvation issues in that case. Think about two processes; process A down down() up() down() up() very frequently. process B does a down(). do we want to switch to B the next time A does an up()? or do we want A to steal B's wakeup?
i shan't implement it now, but it's something to consider.
Signature · 1 line
Revolutions do not require corporate support.
Quoted 7 lines · Matthew Wilcox
Quoted 3 lines · Matthew Wilcox
as i suspected, the pipe problem was a semaphore problem. here's how it works:
OK, I've redesigned the semaphore code on the whiteboard. Here's how it works.
The theoretical design doesn't seem to be buggy, but the implementation was, alas. Fortunately, the bug would only show up with semaphores that allowed multiple accesses simultaneously. Here was the situation:
sema_init(2);
P1 down() 2 -> 1 P2 down() 1 -> 0 P3 down() 0 -> -1
P1 up() -1 -> -2
P2 up() -2 -> -3
P3 wakes up and sets -3 -> 0
P3 up() 0 -> 1
and we've lost one of the slots.
the rewrite makes P3 set -3 to 1 when it wakes up, so we don't lose a slot.
Quoted 1 line
This allows us to implement wakeup stealing if we want. Unsure about
i noticed it now will steal wakeups. Ah well. We probably want to do that anyway.
Signature · 1 line
Revolutions do not require corporate support.