Re: [rfc patch] i386: don't save eflags on task switch

Linus Torvalds
2006-11-05T17:20:36Z

On Sun, 5 Nov 2006, Andi Kleen wrote:
>
> > - mispredicted branches on a P4 are potentially worse than
> > the popf cost.
>
> They are far less than 48 cycles. The P4 is not _that_ bad in this
> area.

You wanna bet? Use the newer P4 cores. A branch mispredict is over 20
cycles, and I bet the "sti" isn't cheap either.

In other words, I suspect the difference between "popfl" and "conditional
jump over sti" is basically zero - exactly because the sti isn't exactly a
no-op.

(Enabling interrupts is actually much more complex than you'd expect.
Interrupt delivery in a HT core is not simple in itself, and "sti" in many
ways is actually more complex than "popf", because it has the additional
"single-cycle interrupt shadow", ie the interrupt isn't actually enabled
after the sti, it's enabled after the _next_ instruction after the sti. So
from a uarch standpoint, "popf" is actually somewhat simpler.)

Anyway, what both you and Chuck seem to be missing is that trying to save
a couple of CPU cycles is NOT WORTH IT, if it makes the code harder and
more fragile. The "save eflags over context switch" that we do now is
_obvious_ code. That's worth a lot in itself. And the costs of context
switching isn't actually a couple of cycles - the real costs are all
elsewhere.

Linus