jarin added a comment.

Looking at the code for flushing L1 cache 
<https://github.com/llvm/llvm-project/blob/e609fe68b2c59b145c0a5c66bedbee2bff545200/lldb/source/Target/Memory.cpp#L59-L71>,
 it appears broken. I am guessing that is the reason for the failure of my 
patch on the bots.

Here is the L1 <https://reviews.llvm.org/L1> flushing code (after checking L1 
<https://reviews.llvm.org/L1> is not empty).

  AddrRange flush_range(addr, size);
  BlockMap::iterator pos = m_L1_cache.upper_bound(addr);
  if (pos != m_L1_cache.begin()) {
    --pos;
  }
  while (pos != m_L1_cache.end()) {
    AddrRange chunk_range(pos->first, pos->second->GetByteSize());
    if (!chunk_range.DoesIntersect(flush_range))
      break;
    pos = m_L1_cache.erase(pos);
  }

For instance, let the cache contains two chunks (10, 10) and (30, 10). Let us 
flush (25, 10). Then the while loop chunk_range will be (10, 10), which is not 
intersecting with (25, 10), so we do not flush anything. This is clearly wrong 
because (30, 10) should be flushed.

I am wondering whether something like this would be correct (I am still a bit 
worried about the case of overlapping things in L1 
<https://reviews.llvm.org/L1>).

  AddrRange flush_range(addr, size);
  BlockMap::iterator pos = m_L1_cache.upper_bound(addr);
  if (pos != m_L1_cache.begin()) {
    // If we are not in the beginning, the previous range might be also 
intersecting.
    BlockMap::iterator previous = pos;
    previous--;
    AddrRange previous_range(previous->first, previous->second->GetByteSize()) 
    if (!previous_range.DoesIntersect(flush_range))
      pos = m_L1_cache.erase(previous);
  }
  while (pos != m_L1_cache.end()) {
    AddrRange chunk_range(pos->first, pos->second->GetByteSize());
    if (!chunk_range.DoesIntersect(flush_range))
      break;
    pos = m_L1_cache.erase(pos);
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74398/new/

https://reviews.llvm.org/D74398



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to