Skip to contentSkip to conversation

Really lazy fpu

PATCH George Spelvin 2 participants 3 messages Jun 16, 2010 – Jun 17, 2010

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

But on busy servers where most wakeups are IRQ based the chance of being on the right CPU is 1/nr_cpus - i.e. decreasing with every new generation of CPUs.

That doesn't seem right. If the server is busy with FPU-using tasks, then the FPU state has already been swapped out, and no IPI is necessary.

The worst-case seems to be a lot of non-FPU CPU hogs, and a few FPU-using tasks that get bounced around the CPUs like pinballs.

It is an explicit scheduler goal to keep tasks on the same CPU across schedules, so they get to re-use their cache state. The IPI only happens when that goal is not met, *and* the FPU state has not been forced out by another FPU-using task.

Not completely trivial to arrange.

(An halfway version of this optimization whoch sould avoid the need for an IPI would be *save* the FPU state, but mark it "clean", so the re-load can be skipped if we're lucky. If the code supported this as well as the IPI alternative, you could make a heuristic guess at switch-out time whether to save immediately or hope the odds of needing the IPI are less than the fxsave/IPI cost ratio.)

#1 lore raw
Quoted 8 lines · George Spelvin

(An halfway version of this optimization whoch sould avoid the need for an IPI would be *save* the FPU state, but mark it "clean", so the re-load can be skipped if we're lucky. If the code supported this as well as the IPI alternative, you could make a heuristic guess at switch-out time whether to save immediately or hope the odds of needing the IPI are less than the fxsave/IPI cost ratio.)

That's an interesting optimization - and we already have something similar in the form of fpu preload. Shouldn't be too hard to do.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 2 lines

That's an interesting optimization - and we already have something similar in the form of fpu preload. Shouldn't be too hard to do.

Unfortunately, there's no dirty flag for the preloaded FPU state. Unless you take an interrupt, which defeats the whole purpose of preload.

AFAIK, I should add; there's a lot of obscure stuff in the x86 system-level architecture. But a bit of searching around the source didn't show me anything; once we've used the CPU for 5 context switches, the kernel calls __math_state_restore when loading the new state, which sets TS_USEDFPU.

(While you're mucking about in there, do you suppose the gas < 2.16 workaround in arch/x86/include/asm/i387.h:fxsave() can be yanked yet?)