Hi Peter, On 9/6/2018 12:44 PM, Peter Zijlstra wrote: > On Thu, Sep 06, 2018 at 12:21:59PM -0700, Reinette Chatre wrote: >> If you do have suggestions on how I can improve the implementation while >> maintaining (or improving) the accuracy of the measurements I would >> greatly appreciate it. > > You can reduce the code duplication by using __always_inline functions > with const function arguments. >
Could you please elaborate? I am unable to see how that would help in, for example: if (need_l2) { rdpmcl(l2_hit_pmcnum, l2_hits_after); rdpmcl(l2_miss_pmcnum, l2_miss_after); } if (need_l3) { rdpmcl(l3_hit_pmcnum, l3_hits_after); rdpmcl(l3_miss_pmcnum, l3_miss_after); } Two issues with the above are: - the measurements captured in l2_hits_after and l2_miss_after would include the hits/misses associated with the "if (need_l2)" test - the measurements captured in l3_hits_after and l3_miss_after would include the hits/misses associated with both the "if (need_l2)" and "if (need_l3)" tests. When I separate the above into the two functions it just becomes either: rdpmcl(l2_hit_pmcnum, l2_hits_after); rdpmcl(l2_miss_pmcnum, l2_miss_after); or: rdpmcl(l3_hit_pmcnum, l3_hits_after); rdpmcl(l3_miss_pmcnum, l3_miss_after); Reinette