Hi all

i am wondering how could i manipulate the TLBs of a pentium.

any code available would be greatly appreciated !!!


Chris
Posted on 2005-01-10 05:57:17 by Chris_a
It is not allowed in Win32asm AFAIK, maybe in your own OS or in a kernel mode driver ;)
Posted on 2005-01-10 10:27:41 by BogdanOntanu
Hi all

i am wondering how could i manipulate the TLBs of a pentium.

any code available would be greatly appreciated !!!


Chris


you can flush them by writing CR3 ;) Good luck doing it from the OS ( requires privilege level 0)


invlpg - also requires privilege level 0.
Posted on 2005-01-10 16:18:26 by mark_larson
Doesn't that only flush the TLBs if the CR3 value actually changes? Good thing to know for an OS scheduler / context switcher :). I'm even considering whether it would be better to keep a single page directory, and patching PTEs on context switch...
Posted on 2005-01-10 16:24:53 by f0dder
> Doesn't that only flush the TLBs if the CR3 value actually changes?

I once wondered as well and did some tests for my dpmi server
(see code below). IIRC there was a speed increase of about 3% if the
move to cr3 was skipped if the value wouldnt change. But this was
possibly true only for the 80486 (or pentium) and is no longer valid for
newer cpus.

if ?CMPCR3
mov eax,cr3
cmp eax,cs:
jz @F
endif
mov eax,cs:
mov cr3,eax
@@:
Posted on 2005-01-10 18:14:12 by japheth
Any chance you could repeat the tests on more modern hardware? Otherwise, I'll do the test if/when I get to that point :)
Posted on 2005-01-10 18:21:49 by f0dder
It seems to be still true for P4 cpus. So if there is a good chance that if cr3 hasn't changed it is faster to add a compare.
Posted on 2005-01-11 03:12:00 by japheth
I believe the best way to read-write the TLBs are through the TR6, TR7 reg or their respective ones at each CPU. The major problem is that we need CPL 0. That can be done in two ways. First I start in real mode and then I pass to protected with software so I control my application to have CPL 0 but at that point there is no paging and so although I can test the TLBs there no hit so it?s not very useful. What could be more interesting is to use code that lowers the CPL of an application and just read the contexts of the TLBs.
Does anyone have such a code ready to use ?

Chris
Posted on 2005-01-11 03:27:30 by Chris_a