Re: [PATCH v3 00/14] perf, x86: Haswell LBR call stack support

From: David Ahern
Date: Wed Feb 26 2014 - 16:34:55 EST


On 2/26/14, 1:53 PM, Andi Kleen wrote:
Is there some reason not to enable frame pointers?

It makes code slower.

Sure there is some overhead because of the push, mov, pop instructions per function. But, take for example the simple program below. Compile with and without frame pointers

gcc -Wall -fno-omit-frame-pointer fp-test.c -owith-fp
gcc -Wall -fomit-frame-pointer fp-test.c -ono-fp

$ time ./with-fp
real 0m9.187s
user 0m9.174s
sys 0m0.001s

$ time ./no-fp
real 0m11.749s
user 0m11.731s
sys 0m0.001s


Especially on Atom CPUs, where it causes pipeline stalls, but
also to some degree on others, because you lose one register and
spend a little bit of time setting it up, so making small
functions more expensive.

Another issue is that you can't enable it on a lot of existing
libraries, sometimes not even with a recompile. For example
glibc assembler functions do not support it at all, which
is a very common case.

They are designed to use dwarf, but in practice dwarf
is very slow (perf has to save the stack for every sample)
and in practice doesn't always work (too small stack saving,
wrong annotations, out of date or broken dwarf library etc.)

dwarf is often just not usable:

$ perf record --call-graph dwarf -- ./no-fp
[ perf record: Woken up 1521 times to write data ]
[ perf record: Captured and wrote 380.567 MB perf.data (~16627233 samples) ]
0x4003cf0 [0]: failed to process type: 0

Compared to the fp route:
$ perf record -g -- ./with-fp
[ perf record: Woken up 12 times to write data ]
[ perf record: Captured and wrote 2.948 MB perf.data (~128816 samples) ]

That is a huge difference. Not to mention the fact the dwarf file is useless which means radically lowering sample rate and increasing mmap size.

The efficiency of fp is worth the small amount of (theoretical) overhead -- at least for us with xeon CPUs.

LBR callstack mode is not perfect either, and it has
its own tradeoffs, but in many cases it seems to be a good
and more efficient replacement for dwarf, when FP is not available.

Haswell only option -- based on the subject line?

David

--

$ cat fp-test.c

#include <stdlib.h>

static int i;

void e(void)
{
i++;
}
void d(void)
{
e();
}
void c(void)
{
d();
}
void b(void)
{
c();
}
void a(void)
{
b();
}

int main(int argc, char *argv[])
{
int iter = 1000000000;

if (argc > 1)
iter = atoi(argv[1]);

while (--iter > 0)
a();

return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/