Re: Dramatic speed effect of code-data proximity
- From: "robertwessel2@xxxxxxxxx" <spamtrap@xxxxxxxxxx>
- Date: 29 Aug 2006 11:26:25 -0700
spamtrap@xxxxxxxxxx wrote:
Can somebody please explain this effect, observed using a Pentium 4 HT?
The following 32-bit code executes at a dramatically different speed
depending on whether or not the address 'var' is in the same 1 Kbyte
memory page as the code accessing it:
mov ecx,10000000H
test:
mov [var],eax
loop test
The measured timing was about 250 ms when the address 'var' was not in
the same 1 Kbyte page as the code (above or below) but about 36000 ms
(i.e. more than 100 times slower!) when the address 'var' was in the
same 1 Kbyte page as the code. I didn't believe this when I first saw
it but it seems to be easily reproducible.
I'm guessing that the data write invalidates the code cache, requiring
it to be reloaded from main memory each time around the loop. That
would explain the dramatic effect, but I'm not too sure why it should
be necessary.
While I can't verify the effect for that particular processor, it's
quite common on CPUs that have split i- and d-caches. It also would
not surprise me that it's somewhat more expensive than usual on the P4
because of the trace cache. The reason it's done is to detect (and
handle) self-modifying code. Most commonly the conflicting area is the
size of a cache line (although the trace cache complicates that) - any
store into that area results in (at least) a flush of that cache line
from the i-cache. Could this be made less painful? Sure, although it
would clearly add complexity and slow down the i-cache. But why
bother? Code and modifiable storage shouldn't normally even be on the
same *page*.
.
- References:
- Dramatic speed effect of code-data proximity
- From: spamtrap
- Dramatic speed effect of code-data proximity
- Prev by Date: Dramatic speed effect of code-data proximity
- Next by Date: Re: Could not switch back to Real-Address mode from Protected Mode. Help?
- Previous by thread: Dramatic speed effect of code-data proximity
- Next by thread: Re: Dramatic speed effect of code-data proximity
- Index(es):
Relevant Pages
|