Curious about VM & TLB
#1
VM means Virtual Memory.

TLB apparently means Translation Lookaside Buffer, which is a (nowadays hardware) feature to speed up virtual address translation. So, TLB is a feature to speed up VM.

Now, the labeling of the two versions confuses me. Just what is the TLB version doing differently from the VM version?
Reply

Sponsored links

#2
The VM version has the data structure that represents the PS2 memory at a known location, so that the location can be baked into many of the instructions used to read/write PS2 memory. Instead of having to do some math to work out the location at run time, it can be done at compile time.

The TLB version has to use a buffer to read/write to the structure, and is in general slower because it takes longer. The offset is essentially a variable that doesn't change, but still needs to be referenced very often.

This is not technically correct, but is good enough to get the idea. As far as I know the OS alone has access to the hardware TLB, not individual programs.

e: Window's definition of 'virtual memory' and PCSX2's aren't exactly the same. Just trust that the devs know what they are doing I guess Tongue
"This thread should be closed immediately, it causes parallel imagination and multiprocess hallucination" --ardhi
Reply
#3
Ah, so I guess the VM version causes the recompiler to compile instructions using host, not guest addresses? But that doesn't explain why the VM version sometimes fails to start. Does it need a contiguous chunk of memory?
Reply
#4
(12-19-2008, 02:29 AM)heftig Wrote: Ah, so I guess the VM version causes the recompiler to compile instructions using host, not guest addresses? But that doesn't explain why the VM version sometimes fails to start. Does it need a contiguous chunk of memory?

Basically, yes that is one of the potential reason it can fail to start. It gets complicated, but that's basically what happens.

The VM version uses a neat trick to skip an intermediate calculation that the TLB version must do. If you're interested in the how's and why's, I'd brush up on your C and dive into the code. Google has lots of great reference material for the design and use of a TLB, if this is the sort of stuff you're interested in it's cool.
"This thread should be closed immediately, it causes parallel imagination and multiprocess hallucination" --ardhi
Reply
#5
I'd really like to point out that we're planning to take away the vm version of pcsx2 from the emulator real soon XD

Of course, the svn will be buggier and slower for a while, but it's well worth it to take away the messy, hacky and buggy vm version.
Reply
#6
If it doesn't have a cool acronym to replaced VM or TLB with, it isn't worth it.
"This thread should be closed immediately, it causes parallel imagination and multiprocess hallucination" --ardhi
Reply
#7
(12-18-2008, 10:22 PM)heftig Wrote: VM means Virtual Memory.

TLB apparently means Translation Lookaside Buffer, which is a (nowadays hardware) feature to speed up virtual address translation. So, TLB is a feature to speed up VM.

Now, the labeling of the two versions confuses me. Just what is the TLB version doing differently from the VM version?

The TLB version is named such pretty much because it's just a straight up emulation of the PS2's TLB; so the "TLB" is referring to the PS2's TLB. The VM version is named such because it uses your operating system's virtual memory to simplify the code needed to emulate the PS2's TLB; so the "VM" is referring to your computer's own virtual memory system.

The VM version is faster for Pcsx2 for the same reasons it's faster to use VM on the PS2. It simplifies the code by allowing the programmer to make assumptions regarding memory addresses. So, for example, references to an allocated memory block can simply be accessed with a constant value instead of a dynamically assigned variable.

Normally, an allocation works like this:

char* buffer = malloc( datasize );
*(buffer+32) = value;

... where-by the buffer is located "somewhere" in memory -- a location picked by malloc and which could be picked differently every time the app runs. That location must be loaded into a cpu register and offset by 32 to access the element. Under VM, you can specify the exact location of the buffer as a hard-coded value:

char* buffer = VM_MapMemory( 0x05000, datasize );
*(0x05032) = value;

This code uses a single constant expression instead, 0x5032, which bypasses both loading the "buffer" address into a cpu register, and offsetting it by 32. So it generates smaller and faster code.

This is how the VM system in Pcsx2 works, more or less. But it has drawbacks also, one of which is the fact that it doesn't always initialize on everyone's computers (depending on operating system and drivers), and it also limits our ability to provide full-on proper emulation of the PS2's TLB implementation. Perhaps though, most importantly, is that it's really not that big of a speedup as far as our x86/x64 CPUs are concerned. The current VM build is faster then the current TLB build partly for the benefits of VM, but more so because the VM build is coded better and utilizes a full suite of recompiler optimizations. If the TLB build were implemented properly, the real difference in speed between the two would likely be around 5% on most games.

.. but emulation quality would be better, the recompiler would be easier to maintain and debug, and Pcsx2 would be a sure bet to start and run on everyone's PC without tossing VM alloc errors or making you log off or restart. Smile So it's probably not a bad idea.
Jake Stine (Air) - Programmer - PCSX2 Dev Team
Reply
#8
Well I got the feeling that the VM version is not worth it...
From times to times I have problem with it , and instead of rebooting to get rid of the problem, I just switch to TLB.
Usually I see no performance difference.

Quote:If the TLB build were implemented properly, the real difference in speed between the two would likely be around 5% on most games
.
So what is the real performance difference ? Seriously, if it's only 5%,
then just get rid of the VM version.
Reply
#9
(12-19-2008, 05:03 AM)bigmehdi Wrote: Well I got the feeling that the VM version is not worth it...
From times to times I have problem with it , and instead of rebooting to get rid of the problem, I just switch to TLB.
Usually I see no performance difference.

Actual performance difference is about 15-20% currently, but can vary heavily based on game. For example, the VM does little to help speed up the VUs and nothing to speed up the GS/GPU, so any game that is either using lots of VU micro-code or is GPU limited will see less performance differences. And 10% usually isn't all that much if games are already running quite well. I don't notice any differences in most of my games for example, since they all run well above the 60fps line most of the time, and I usually like to use framelimiting enabled.

And yes, the Playground team is on the job -- one of our goals is to remove the VM build and replace it with an improved TLB codebase. Smile
Jake Stine (Air) - Programmer - PCSX2 Dev Team
Reply
#10
@Air
Quote:one of our goals is to remove the VM build and replace it with an improved TLB codebase
Great ...
Reply




Users browsing this thread: 1 Guest(s)