[PATCH] D126827: [llvm-profgen] Fix a loading address bug for pseudo probe profile

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 17:48:33 PDT 2022


hoy added inline comments.


================
Comment at: llvm/tools/llvm-profgen/PerfReader.cpp:1195
+  // preferred loading address in order to match pseduo probe address correctly.
+  Binary->setBaseAddress(Binary->getPreferredBaseAddress());
+
----------------
wlei wrote:
> wlei wrote:
> > hoy wrote:
> > > wenlei wrote:
> > > > Where do we use getBaseAddress in probe queries? Can we use getPreferredBaseAddress directly there? Ideally there should be one definition for base address which is the actual executable segment load address, and changing it here makes it inconsistent. 
> > > Agreed that `setBaseAddress` should be called once to be consistent. Pseudo probe decoding is based on the preferred address. I think a reasonable fix could be 
> > > 
> > > 1) make the decoding offset-based. This will require a change to the bolt code. base; or
> > > 2) do an offset to preferred addr translation for every probe look up in llvm-profgen. This is being done in some places, eg, `extractPrefixContextStack`. 
> > > 
> > > #2 sounds more practical. WDYT?
> > Hmm, I found it's very tricky case.
> > 
> > > Where do we use getBaseAddress in probe queries? 
> > 
> > We call it in `Binary->offsetToVirtualAddr`.
> > 
> > However, we call `IP.advance()` to iterate all the address in the range, in `IP` it will convert the `Address` back to `offset` using the base address. like  `Offset + preferred Address - Mmap loading address`. That's another inconsistency..  Then we need to change code inside of the IP. but IP also used in `PerfReader`
> > 
> > 
> > 
> > 
> >  
> Or can we use virtual address(`Offset + preferred Address`) for all the code(PerfReader and ProfileGenerator)? to do this, we can convert the address at the very beginning of PerfReader. like `Address = PhysicalAddress - Mmap loading address + PreferredAddress`
I see. This is complicated. How about we always use preferred address when doing this offset to virtual addr conversion, and we rebase all LBR and stack sample addresses to be on the preferred load address in the the perf reader ? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126827



More information about the llvm-commits mailing list