Re: Using %cr2 to reference "current"

Jamie Lokier
2001-11-09T21:53:48Z

Alan Cox wrote:
> True enough, but then we can go to
>
> andl %%esp, %0
> movl (%%eax), %%eax
>
> which doesnt really change the cost much, lets us colour the task structs
> nicely, and lets us colour the stack somewhat by offseting esp from the base
> - and all in standard instructions

A variant lets you put the pointer at the top of the stack, where it can
sometimes share a cache line with the freshly pushed context:

movl $0x1ffc,%0
orl %esp,%0
movl (%0), %0

This works because GCC keeps the stack aligned to 4 bytes at all times,
I believe.

Both this simple sequence, and Alan's code, suffer from the problem that
the pointer itself is not cache-coloured, but it is a lot better than
having the whole context and task state on the same colour.

This perhaps be improved using Linus' idea of shifting upper address
bits to colour the pointer as well.

-- Jamie