i386: inline restore_fpu
Quoted 9 lines · Andrew Morton
Quoted 6 lines · Chuck Ebbert
After:
12534
math_state_restore130.5625
8354device_not_available203.7561
-----
20888
Quoted 5 lines
Quoted 3 lines
Next step should be to physically place
math_state_restore()afterdevice_not_available(). Would such a patch be accepted? (Yes it would be ugly and require linker script changes.)Depends on the benefit/ugly ratio ;)
This patch (may not apply cleanly to unpatched -rc3) drops overhead a few more percent:
11835 math_state_restore 144.3293
8096 device_not_available 197.4634
-----
19931
Most of the exception/interrupt handlers should get the same treatment but the linker script would grow.
arch/i386/kernel/entry.S +3 -0
@@ -469,6 +469,7 @@ pushl $do_simd_coprocessor_error jmp error_code + .section ".text.i387_1", "a" ENTRY(device_not_available) pushl $-1 # mark this as an int SAVE_ALL
@@ -484,6 +485,8 @@ addl $4, %esp jmp ret_from_exception + .previous + /* * Debug traps and NMI can happen at the one SYSENTER instruction * that sets up the real kernel stack. Check here, since we can't
arch/i386/kernel/traps.c +2 -1
@@ -972,7 +972,8 @@* Must be called with kernel preemption disabled (in this case, * local interrupts are disabled at the call-site in entry.S). */ -asmlinkage void math_state_restore(struct pt_regs regs) +asmlinkage void __attribute__((__section__(".text.i387_2"))) +math_state_restore(struct pt_regs regs) {struct thread_info *thread =current_thread_info ();struct task_struct *tsk = thread->task;
arch/i386/kernel/vmlinux.lds.S +2 -0
@@ -20,6 +20,8 @@ _text = .; /* Text and read-only data */ .text : AT(ADDR(.text) - LOAD_OFFSET) { *(.text) + *(.text.i387_1) + *(.text.i387_2) SCHED_TEXT LOCK_TEXT *(.fixup)
__
Chuck
Quoted 3 lines · Chuck Ebbert
This patch (may not apply cleanly to unpatched -rc3) drops overhead a few more percent:
That really is pretty ugly.
I'd rather hope for something like function-sections to just make games like this be unnecessary. The linker really should be able to do things like this for us (ie if it sees that the only reference to a function is from another function, it should be able to just put them next to each other anyway).
And yes, I realize that "should be able" isn't the same thing as "does", but the thing is, doing it by hand ends up being a maintenance problem in the long run. It also misses all the other cases where it might be beneficial, but where you don't happen to run the right benchmark or look at the right place.
So maybe a few hints to the binutils people might just make them go: "try this patch/cmdline flag", and solve many more problems. They likely have a lot of this kind of code _already_, or have at least been thinking about it.
I personally believe that there's likely a lot more to be had from code (and data) layout than there is from things like alias analysis or aggressive inlining.
Linus
Quoted 8 lines · Linus Torvalds
So maybe a few hints to the binutils people might just make them go: "try this patch/cmdline flag", and solve many more problems. They likely have a lot of this kind of code _already_, or have at least been thinking about it.
I personally believe that there's likely a lot more to be had from code (and data) layout than there is from things like alias analysis or aggressive inlining.
for userland it's not that complex and exists already; basically gprof has this analysis capability, and from that there's tooling (well I wrote it and I'm sure others did too) to create a linker script automatically to order things according to their gprof desired order. This gprof based approach is taking actual runtime patterns into account not just static callgraph analysis.
For the kernel the runtime measurement is obviously tricky (kgprof anyone?) but the static analysis method really shouldn't be too hard. (well I guess "optimal" will be NP complete, but "pretty damn close" ought to be reasonable)
Quoted 3 lines · Arjan van de Ven
For the kernel the runtime measurement is obviously tricky (kgprof anyone?)
Ehh, doesn't "opgprof" do that already?
Anyway, judging by real life, people just don't _do_ profile runs. Any build automation that depends on the user profiling the result is a total wet dream by compiler developers - it just doesn't happen in real life.
So:
Quoted 1 line
but the static analysis method really shouldn't be too hard.
I really think that the static analysis is the only one that actually would matter in real life. It's also the only one that is repeatable, which is a big big bonus, since at least that way different people are running basically the same code (heisenbugs, anyone?) and benchmarks are actually meaningful, since they don't depend on whatever load was picked to generate the layout.
So dynamic analysis with dynamic profile data is just one big theoretical compiler-writer masturbation session, in my not-so-humble opinion. I bet static analysis (with possibly some hints from the programmer, the same way we use likely/unlikely) gets you 90% of the way, without all the downsides.
Linus