<div dir="ltr"><div dir="ltr">Hi Clement,<div><br></div><div>thanks for the feedback!</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 17, 2020 at 11:47 AM Clement Courbet <<a href="mailto:courbet@google.com">courbet@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 16, 2020 at 6:32 PM Ondrej Sykora via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>In a <a href="http://groups.csail.mit.edu/commit/papers/19/ithemal-measurement.pdf" target="_blank">recent IISWC paper</a>, we've proposed BHive - a new methodology for benchmarking arbitrary basic blocks that has several advantages over the one currently used in llvm-exegesis. In particular, the new methodology:<br></div><div>- automatically handles memory accesses in the basic block, without the need to manually annotate live-ins,<br>- maps all memory addresses accessed by the basic block to the same page, significantly reducing the probability of cache misses during benchmarking,<br>- the benchmarked code runs in a separate process, reducing risks of compromising the monitor process memory,<br>- computes the throughput in a way that subtracts away the effects of the scaffolding code.<br></div></div></blockquote><div><br></div><div>I've never actually seen a case where the scaffolding code had much influence on the results (at least on X86), especially in loop mode. However, I can see some value in snippet mode (not generated code mode): this allows the snippet code to exhaust all available registers and still be measurable.</div></div></div></blockquote><div><br></div><div>Yes, our main goal is benchmarking arbitrary basic blocks, where we do not control the register allocation.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>A possible challenge is increased complexity of the code: BHive uses a separate process to run the benchmarked basic block and changes memory mapping of the process to ensure that all memory accesses lead to the same page. Most operating systems have the necessary APIs, but these may differ significantly. In particular, the Windows API for memory mapping and process creation/control is very different from the Unix world. Initially, we might be able to support the new methodology only on Linux and Unix-like systems.</div></div></blockquote><div> </div><div>Though I think it's fine to have linux only as an initial implementation, I think there should be a clear plan to support windows: there are  people in the LLVM community who are using llvm-exegesis on windows (e.g. folks at Sony). Note that you might be able to reuse some code in LLVM: compiler-rt already has an abstraction layer in "WindowsMMap.c" on top of MapViewOfFile.</div></div></div></blockquote><div><br></div><div>Thanks for the pointers! That said, replacing mmap is relatively straightforward. The difficult part is replacing munmap, which does not have a direct equivalent on Windows and you need to query the system for all mapped blocks, and then unmap them one by one. This is a very specific functionality, and I'd be surprised if someone implemented that.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Before we start the implementation, we would like to collect feedback on the proposed design:<br>- We're planning to implement the methodology as a new implementation of BenchmarkRunner::FunctionExecutor that will exist alongside the current runner. The existing functionality will be preserved, and the user will be able to select the benchmark runner using a command-line flag.<br></div></div></blockquote><div><br></div><div>LGTM.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>- We're considering using the LLDB API to control the execution of the benchmarking process in a platform-independent way.<br></div></div></blockquote><div><br></div><div><i> </i>I think it's a great idea to avoid introducing any other external dependencies.</div></div></div></blockquote></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Ondrej</div></div></div></div>