Skip to contentSkip to conversation

How to measure enable_kernel_fpu overhead?

DISCUSSION George Spelvin 2 participants 5 messages Jun 3, 2011 – Jun 5, 2011

lore
Share & tools
lore
#0 lore raw

I'm working on some crypto primitives, and have MMX and SSE2 accelerated versions. I plan on writing AltiVec (PPC) and NEON (ARM) ones, too.

But the performance varies, so I think I need to do some run-time benchmarking, like the RAID6 code.

But what's even more annoying is that unlike the RAID6 code, I can't assume I'll alawys be working on large blocks. So it's not so much about choosing one version as choosing a size threshold at which to switch over.

Which leads us into the overhead of enable_kernel_fpu(), enable_kernel_altivec(), and whatever the ARM equivalent is. (Um, did a little searching... does it even exist?)

To complicate it a little more, there are at two timing cases, depending on the value of current_thread_info()->status & TS_USEDFPU. (For PowerPC, it's current->thread.regs->msr & MSR_VEC.)

There may be additional timing variation depending on how clever XSAVE is with e.g. the high half of the ymm registers.

So I think the thing to do is benchmark a few different sizes in the two timing cases and fit a linear function to the results. (More simply, subtract the timings from the integer code and find the X-intercept of that function.)

But I'm not sure how to create, a suitably dirty user FPU state. Especially as it might be early boot and there might not be any user processes yet to save it to.

Does anyone have any suggestions?

Thank you!

#1 lore raw
Quoted 2 lines · George Spelvin

Does anyone have any suggestions?

This seems to clever for its own good. Even if you come up with some number on one CPU it could be completely different on another. I would suggest KISS.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#2 lore raw
Quoted 3 lines

This seems to clever for its own good. Even if you come up with some number on one CPU it could be completely different on another. I would suggest KISS.

I don't understand. Do you mean different CPUs of the same SMP system? That would be really bad...

The whole point is to, like the RAID6 code, benchmark after boot time so that the numbers reflect the individual hardware instance.

Doing that in a clean maintainable way suitabkle for merging into Linus's tree is the problem. If I just needed a one-off rude hack to measure on my systems, it would be easy. But that's so obviously not useful that I didn't bother to mention it.

"Too clever for its own good" would be to keep more statistics, including confidence intervals, on actual calls, and randomly dispatch requests to code paths based on the current estimated probabilities of A being faster than B.

That avoids doing redundant work just for benchmarking, but does entail quite a lot of bookkeeping overhead. I'd rather just measure once at boot (or module load) and be done with it.

Anyway, thanks for thinking about the problem.

#3 lore raw
Quoted 6 lines · George Spelvin
Quoted 3 lines

This seems to clever for its own good. Even if you come up with some number on one CPU it could be completely different on another. I would suggest KISS.

I don't understand. Do you mean different CPUs of the same SMP system? That would be really bad...

Different CPU models. This years CPUs does this and next years that.

Quoted 2 lines

on my systems, it would be easy. But that's so obviously not useful that I didn't bother to mention it.

AFAIK you cannot merge anyways as anonymous, so it's moot.

-Andi

#4 lore raw
Quoted 1 line

Different CPU models. This years CPUs does this and next years that.

Er, yes, exactly. That's why we have multiple code paths, and run-time selection of the best. The basic principle is used rather a lot in the Linux kernel, e.g. the alternative() feature.

To me the closest equivalent is the RAID6 code, which has no less than 12 different versions (5 integer, 4 AltiVec, 1 MMX, 1 SSE1, and 1 SSE2), and on x86 it benchmarks the 8 different versions at boot time and chooses the best.

What confuses me is:

Quoted 1 line

I would suggest KISS.

This suggestion is not quite clear to me; I'm not quite sure what you think is "simple". Do you mean always use the integer code and ignore the SSE registers? Or something else?

Could you expand on that remark a little, please?

Thank you!