This topic has been somewhat covered in other posts, but in my example I need to find more than what is shown on the other examples, and I struggle to clearly understand what exactly is going on.
Suppose I have the following system properties (and worked example I know the solutions to, but do not understand clearly):
And suppose I want to translate the virtual address 0x0712
to a physical address:
I would first convert 0x0712
to binary: 000011100010010
(knowing the VA is 15-bit wide)
I know the page size is 128 bytes, so log2(128) = 7
, which is my offset bits.
I then need to answer the following:
What is the Virtual Page Number?
What is the TLB index?
What is the TLB tag?
Was it a TLB hit or miss?
Was there a Page fault?
What is the Physical Page Number?
How do I go about answering these? I know the VPN can be shown as E (or 0E), which makes sense as the 15-bit virtual address minus the offset bits (7) would leave: 00001110 = E
. I also understand why there is no PPN, as there is no match for VPN 0E
in the page table.
My guess would be the page fault is Y, exactly because there is no match to the VPN 0E
in the page table? However, I come to this using just intuition.
But I dont understand the remaining parts, and how I answer these? Again I know the solutions as:
What is the Virtual Page Number? = 0E
What is the TLB index? = 2
What is the TLB tag? = 03
Was it a TLB hit or miss? = M
Was there a Page fault? = Y
What is the Physical Page Number? none
But I cant seem to grasp how they arrive at those answers from the worked example above. I've tried to read up on different posts in here, but I fail to spot anyone covering how to find the TLB index and tags properly, and in that case how to see whether is was a TLB hit/miss and if a Page fault happened.
Can anyone explain these concepts to me?
EDIT: I found the solution elsewhere, I posted it as a comment below to showcase the worked example.
My examining more examples toturials I stumbled upon a solution that made sense to me. In the case from above I have the following:
What is the Virtual Page Number?
Virtual address: 0x0712
which maps to binary address: 000011100010010
I know the offset bits are found by log2(128) = 7 bits
which leaves the remaining 8-bits for the actual Virtual Address.
What is the TLB index?
As I have 4 sets in the TLB, I have 2 index bits (2^k = 4, for k = 2 which is the actual number of index bits needed to cover all 4 sets in the TLB-cache) and thus I can read the TLB index from the 2 least significant bits of the Virtual Address: 10
= 2
.
What is the TLB tag?
The TLB tag, is the remaining 8-2 = 6-bits of the Virtual Address, in this case 000011
= 03
.
Was it a TLB hit or miss?
To check if I have a TLB hit, I check the TLB table, lookup in set 2
(which was the TLB index) and see if there is a match to the tag 03
(which was the TLB tag). In this case I have no match, and thus there is a TLB MISS.
Was there a Page fault?
As the TLB-cache did not provide an answer, I need to lookup the translation from the Virtual Address using the page table instead. So I check the table for a VPN match of 0E
, which there is not, and thus I have a Page Fault. In case I actually found a match, I would need to check the valid bit is 1
, as it indicates if the data is loaded into the page table.
What is the Physical Page Number?
As there was no match in the TLB-cache translation, or the actual page table for the Virtual Address 0E
, there is no PPN matching.