X86: Clear out duplicate TLB entries when adding a new one.
authorGabe Black <gblack@eecs.umich.edu>
Tue, 24 Apr 2012 07:48:41 +0000 (00:48 -0700)
committerGabe Black <gblack@eecs.umich.edu>
Tue, 24 Apr 2012 07:48:41 +0000 (00:48 -0700)
It's possible for two page table walks to overlap which will go in the same
place in the TLB's trie. They would land on top of each other, so this change
adds some code which detects if an address already matches an entry and if so
throws away the new one.

src/arch/x86/tlb.cc

index caa3efc1e4e59888b5bcdd6e37ef7cda1df12a23..8dad84dc4e695c4563c823c78c59a12c1c07ab62 100644 (file)
@@ -98,11 +98,16 @@ TLB::evictLRU()
 TlbEntry *
 TLB::insert(Addr vpn, TlbEntry &entry)
 {
-    //TODO Deal with conflicting entries
+    // If somebody beat us to it, just use that existing entry.
+    TlbEntry *newEntry = trie.lookup(vpn);
+    if (newEntry) {
+        assert(newEntry->vaddr = vpn);
+        return newEntry;
+    }
 
-    TlbEntry *newEntry = NULL;
     if (freeList.empty())
         evictLRU();
+
     newEntry = freeList.front();
     freeList.pop_front();
 
@@ -110,7 +115,7 @@ TLB::insert(Addr vpn, TlbEntry &entry)
     newEntry->lruSeq = nextSeq();
     newEntry->vaddr = vpn;
     newEntry->trieHandle =
-        trie.insert(vpn, TlbEntryTrie::MaxBits - entry.logBytes, newEntry);
+    trie.insert(vpn, TlbEntryTrie::MaxBits - entry.logBytes, newEntry);
     return newEntry;
 }