There are two exceptions handled to provide updating of TLB entries:
tlbrefill()
function.
tlbinvalid()
function.
There are only 256 values (0 - 255) of ASIDs available so if we want to allow running more "processes"3 simultaneously we have to assign ASIDs dynamicaly. ASID 255 is reserved. This number means invalid value.
ASID assigned to a thread is written in its _thread
structure in the asid field unless some
pagetable is associated with the thread. If so, the value of the asid
field is undefined and the current ASID is written in the
pagetable_thread structure. Value 255 means no ASID has
been assigned to this thread. If thread with no ASID assigned wants to
access memory at some virtual address then appropriate entry must be written to
TLB. That's why we need some valid ASID assign to that thread in such case.
Process of determination the current thread's ASID follows:
used_asids
array which is described later)? Return it if so.
asids_in_tlb_bitmap
bitmap which is described later. If there is some
ASID with associated bit in this bitmap zeroed (so the
ASID is not in the TLB) then we assign this ASID to the current
thread. The invalid ASID is assigned to a thread whose ASID has been
assigned now.
asids_in_tlb_bitmap
bitmap are set. In such a case the bitmap is refreshed by curreent values
from the TLB. This operation makes it possible to perform the
step number 4 now successfully. So go to 4.used_asids arrayasids_in_tlb_bitmap bitmapasid_last_assignedasid_last_assigned.used_asids array
we start searching after the asid_last_assigned
index, so we have chance that the search for unused ASID takes fewer steps.
1) Virtual Page Number is 20-bits long number of 4KB block in 4GB address space. All addresses that points to the same 4KB block of memory have the same VPN. Simply, VPN is upper 20 bits from 32-bits long virtual address.
2) Physical Frame Number is 24-bits long number of 4KB block in 64GB physical address space. Same as VPN in virtual addres space, so upper 24 bits of physical address creates PFN of block of physical addres space to that address belongs.
3) Process means group of threads sharing one address space. There is no structure associated with process in kernel right now.