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

From: Linus Torvalds
Date: Sun Nov 05 2006 - 12:20:53 EST




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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/