7 ms·
Early 90s, doing the first implementation of scheduler activations in a real kernel on a real machine. There's an occasional bug that shows up, we think it's a
by PaulDavisThe1st 4y ago
Early 90s, doing the first implementation of scheduler activations in a real kernel on a real machine. There's an occasional bug that shows up, we think it's a race condition or something. After lots and lots of debugging and thinking, end up in the debugger approaching a line where we think the bug manifests (not caused, but manifests). Looks something this:
int g = 2;
if (g) {
printf ("yes\n");
} else {
printf ("no\n");
}
Obviously most of the time we see "yes", but every once in a while we see "no". Even in the debugger, using stepi, we hit the conditional, we confirm with the debugger that g is indeed non-zero. Totally impossible for the conditional to ever print "no", right?
------------
Well, when you're writing a re-entrant kernel context switch (as scheduler activations requires), you'd better damn well remember to restore ALL the registers on the processor, in particular the one that stores the result of a recent compare instruction.
We had skimped on this tiny step IIRC, one extra instruction in the context switch code); the kernel is interrupted after the compare instruction but before the jump; scheduler activations dictates switching to a new thread; when we come back to the original thread, the apparent result of the comparison is reversed, and we print "no".
At least the paper got an award at Usenix that year :)
- Tyr42 4y agoOi, I had the same big on an ARM chip. If ended up debugging by putting If (x) { If (!x) { Panic. ... I wasn't saving the comparison bits on context switch.
- rramadass 4y agoThat is clever and yet so simple !
- jesse__ 4y agoAwesome bug. Thanks for sharing
- hakeberio 4y agognarly bug! what's the name of the paper?
- ruds 4y agoI suspect that it's "Adding Scheduler Activations to Mach 3.0", presented at the Usenix Mach III Symposium in 1993. https://dada.cs.washington.edu/research/tr/1992/08/UW-CSE-92-08-03.pdf https://dada.cs.washington.edu/research/tr/1992/08/UW-CSE-92...