Re: Using %cr2 to reference "current"

From: H. Peter Anvin (hpa@zytor.com)
Date: Tue Nov 06 2001 - 14:09:50 EST


Followup to: <20011106134234.A27718@redhat.com>
By author: Benjamin LaHaise <bcrl@redhat.com>
In newsgroup: linux.dev.kernel
>
> On Tue, Nov 06, 2001 at 09:49:15AM -0800, Linus Torvalds wrote:
> > That said, how expensive is loading %cr2 anyway? We can do all the same
> > tricks with a 16kB stack and just playing games with using the higher bits
> > as the "offset", ie things like
>
> Here are some numbers:
>
> read cr2 best: 11 av: 11.12
> write cr2 cr2 best: 61 av: 64.42
> read cr2 best: 11 av: 11.12
> write cr2 cr2 best: 61 av: 65.01
> read stk best: 10 av: 11.03
> write cr2 stk best: 61 av: 64.95
> read stk best: 10 av: 11.03
> write cr2 stk best: 61 av: 65.23
>
> Which come from insmod of the below two modules. I didn't test writing to
> the stack register, but I expect it's similarly expensive as it affects the
> call return stack and other behind the scenes dependancies. Suffice it to
> say that reading %cr2 is essentially free on my box (athlon mp). Maybe
> we should use it as a pointer into a per-cpu area to avoid writing it?
>

You still have to write it every time you take a page fault. You're
adding 60-odd cycles to the page fault path at least.

Not to mention any system which does microcoded reads of %cr2, which
apparently the Athlon XP doesn't.

        -hpa

-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<amsp@zytor.com>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Nov 07 2001 - 21:00:31 EST