Re: [PATCH v1 0/4] Perf tool LTO support

From: Ian Rogers
Date: Mon Jul 24 2023 - 17:48:28 EST


On Mon, Jul 24, 2023 at 2:15 PM Nick Desaulniers
<ndesaulniers@xxxxxxxxxx> wrote:
>
> On Mon, Jul 24, 2023 at 1:12 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> >
> > Add a build flag, LTO=1, so that perf is built with the -flto
> > flag. Address some build errors this configuration throws up.
>
> Hi Ian,
> Thanks for the performance numbers. Any sense of what the build time
> numbers might look like for building perf with LTO?
>
> Does `-flto=thin` in clang's case make a meaningful difference of
> `-flto`? I'd recommend that over "full LTO" `-flto` when the
> performance difference of the result isn't too meaningful. ThinLTO
> should be faster to build, but I don't know that I've ever built perf,
> so IDK what to expect.

Hi Nick,

I'm not sure how much the perf build will benefit from LTO to say
whether thin is good enough or not. Things like "perf record" are
designed to spend the majority of their time blocking on a poll system
call. We have benchmarks at least :-)

I grabbed some clang build times in an unscientific way on my loaded laptop:

no LTO
real 0m48.846s
user 3m11.452s
sys 0m29.598s

-flto=thin
real 0m55.910s
user 4m2.342s
sys 0m30.120s

real 0m50.330s
user 3m36.986s
sys 0m28.519s

-flto
real 1m12.002s
user 3m27.676s
sys 0m30.305s

real 1m5.187s
user 3m19.348s
sys 0m29.031s

So perhaps thin LTO increases total build time by 10%, whilst full LTO
increases it by 50%.

Gathering some clang performance numbers:

no LTO
$ perf bench internals synthesize
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 178.694 usec (+- 0.171 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 3.436 usec
Average data synthesis took: 194.545 usec (+- 0.088 usec)
Average num. events: 277.000 (+- 0.000)
Average time per event 0.702 usec
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 175.381 usec (+- 0.105 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 3.373 usec
Average data synthesis took: 188.980 usec (+- 0.071 usec)
Average num. events: 278.000 (+- 0.000)
Average time per event 0.680 usec

-flto=thin
$ perf bench internals synthesize
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 183.122 usec (+- 0.082 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 3.522 usec
Average data synthesis took: 196.468 usec (+- 0.102 usec)
Average num. events: 277.000 (+- 0.000)
Average time per event 0.709 usec
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 177.684 usec (+- 0.094 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 3.417 usec
Average data synthesis took: 190.079 usec (+- 0.077 usec)
Average num. events: 275.000 (+- 0.000)
Average time per event 0.691 usec

-flto
$ perf bench internals synthesize
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 112.599 usec (+- 0.040 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 2.165 usec
Average data synthesis took: 119.012 usec (+- 0.070 usec)
Average num. events: 278.000 (+- 0.000)
Average time per event 0.428 usec
# Running 'internals/synthesize' benchmark:
Computing performance of single threaded perf event synthesis by
synthesizing events on the perf process itself:
Average synthesis took: 107.606 usec (+- 0.147 usec)
Average num. events: 52.000 (+- 0.000)
Average time per event 2.069 usec
Average data synthesis took: 114.633 usec (+- 0.159 usec)
Average num. events: 279.000 (+- 0.000)
Average time per event 0.411 usec

The performance win from thin LTO doesn't look to be there. Full LTO
appears to be reducing event synthesis time down to 60% of what it
was. The clang numbers are looking better than the GCC ones. I think
from this it makes sense to use -flto.

Thanks,
Ian

> --
> Thanks,
> ~Nick Desaulniers