<div dir="ltr"><div dir="ltr">Hi Vedant,<br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr"><br></div><div dir="ltr" class="gmail_attr">On Tue, Jul 27, 2021 at 10:42 PM Vedant Kumar <<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.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>Hi Zequan,<div><div><br><blockquote type="cite"><div>On Jul 27, 2021, at 6:50 PM, Zequan Wu <<a href="mailto:zequanwu@google.com" target="_blank">zequanwu@google.com</a>> wrote:</div><br><div><div dir="ltr">Hi,<div><br></div><div>When merging is disabled, a possible solution is to unmap the mapped file region, copy the old profile file to the new file, and then mmap the CounterBegin to the new file region. Does this sound correct?</div></div></div></blockquote><div><br></div><div>If the instrumented program is multithreaded, it might be possible for a thread to racily update a counter in the un-<span style="color:rgb(0,0,0)">mmap'd region.</span></div><div><span style="color:rgb(0,0,0)"><br></span></div></div></div></div></blockquote><div>I thought that the instrumented program can only update counters in the mmapped regions which are setup during the initialization. How does it access un-mmaped regions?</div><div><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><div><div><div><span style="color:rgb(0,0,0)"></span></div><div><font color="#000000"><span>Do you think it's viable to sidestep the issue by restricting how/when __llvm_profile_set_file_object can be called, e.g. either by documenting or requiring that no other threads are active at the time of the call?</span></font></div><div><br></div></div></div></div></blockquote><div> This looks viable.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div><div></div><blockquote type="cite"><div><div dir="ltr"><div>When merging is enabled, multiple profile files will be created. I'm not sure how to set the file object in this case as only one file descriptor is passed to __llvm_profile_set_file_object.</div></div></div></blockquote><div><br></div><div>Can you share how __llvm_profile_set_file_object(..., EnableMerge = true) works in non-continuous mode? It's not something I'm familiar with.</div><div><br></div></div></div></div></blockquote><div>By looking at existing tests, __llvm_profile_set_file_object(..., EnableMerge = true) allows instrumented programs to accumulate profile files from different runs. My guess is that when running two instrumented programs, this function allows them to write to the same profile file in appending mode, but I'm not sure how it handles the case when multiple profile files are created during initialization for non-continuous mode.<br></div></div></div></div>