mirror of
https://github.com/torvalds/linux.git
synced 2024-11-18 18:11:56 +00:00
f9ceffb605
When "perf record" was used on a large machine with a lot of CPUs, the perf post-processing time (the time after the workload was done until the perf command itself exited) could take a lot of minutes and even hours depending on how large the resulting perf.data file was. While running AIM7 1500-user high_systime workload on a 80-core x86-64 system with a 3.9 kernel (with only the -s -a options used), the workload itself took about 2 minutes to run and the perf.data file had a size of 1108.746 MB. However, the post-processing step took more than 10 minutes. With a gprof-profiled perf binary, the time spent by perf was as follows: % cumulative self self total time seconds seconds calls s/call s/call name 96.90 822.10 822.10 192156 0.00 0.00 dsos__find 0.81 828.96 6.86 172089958 0.00 0.00 rb_next 0.41 832.44 3.48 48539289 0.00 0.00 rb_erase So 97% (822 seconds) of the time was spent in a single dsos_find() function. After analyzing the call-graph data below: ----------------------------------------------- 0.00 822.12 192156/192156 map__new [6] [7] 96.9 0.00 822.12 192156 vdso__dso_findnew [7] 822.10 0.00 192156/192156 dsos__find [8] 0.01 0.00 192156/192156 dsos__add [62] 0.01 0.00 192156/192366 dso__new [61] 0.00 0.00 1/45282525 memdup [31] 0.00 0.00 192156/192230 dso__set_long_name [91] ----------------------------------------------- 822.10 0.00 192156/192156 vdso__dso_findnew [7] [8] 96.9 822.10 0.00 192156 dsos__find [8] ----------------------------------------------- It was found that the vdso__dso_findnew() function failed to locate VDSO__MAP_NAME ("[vdso]") in the dso list and have to insert a new entry at the end for 192156 times. This problem is due to the fact that there are 2 types of name in the dso entry - short name and long name. The initial dso__new() adds "[vdso]" to both the short and long names. After that, vdso__dso_findnew() modifies the long name to something like /tmp/perf-vdso.so-NoXkDj. The dsos__find() function only compares the long name. As a result, the same vdso entry is duplicated many time in the dso list. This bug increases memory consumption as well as slows the symbol processing time to a crawl. To resolve this problem, the dsos__find() function interface was modified to enable searching either the long name or the short name. The vdso__dso_findnew() will now search only the short name while the other call sites search for the long name as before. With this change, the cpu time of perf was reduced from 848.38s to 15.77s and dsos__find() only accounted for 0.06% of the total time. 0.06 15.73 0.01 192151 0.00 0.00 dsos__find Signed-off-by: Waiman Long <Waiman.Long@hp.com> Acked-by: Ingo Molnar <mingo@kernel.org> Cc: "Chandramouleeswaran, Aswin" <aswin@hp.com> Cc: "Norton, Scott J" <scott.norton@hp.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1368110568-64714-1-git-send-email-Waiman.Long@hp.com [ replaced TRUE/FALSE with stdbool.h equivalents, fixing builds where those macros are not present (NO_LIBPYTHON=1 NO_LIBPERL=1), fix from Jiri Olsa ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
112 lines
1.7 KiB
C
112 lines
1.7 KiB
C
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <linux/kernel.h>
|
|
|
|
#include "vdso.h"
|
|
#include "util.h"
|
|
#include "symbol.h"
|
|
#include "linux/string.h"
|
|
|
|
static bool vdso_found;
|
|
static char vdso_file[] = "/tmp/perf-vdso.so-XXXXXX";
|
|
|
|
static int find_vdso_map(void **start, void **end)
|
|
{
|
|
FILE *maps;
|
|
char line[128];
|
|
int found = 0;
|
|
|
|
maps = fopen("/proc/self/maps", "r");
|
|
if (!maps) {
|
|
pr_err("vdso: cannot open maps\n");
|
|
return -1;
|
|
}
|
|
|
|
while (!found && fgets(line, sizeof(line), maps)) {
|
|
int m = -1;
|
|
|
|
/* We care only about private r-x mappings. */
|
|
if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
|
|
start, end, &m))
|
|
continue;
|
|
if (m < 0)
|
|
continue;
|
|
|
|
if (!strncmp(&line[m], VDSO__MAP_NAME,
|
|
sizeof(VDSO__MAP_NAME) - 1))
|
|
found = 1;
|
|
}
|
|
|
|
fclose(maps);
|
|
return !found;
|
|
}
|
|
|
|
static char *get_file(void)
|
|
{
|
|
char *vdso = NULL;
|
|
char *buf = NULL;
|
|
void *start, *end;
|
|
size_t size;
|
|
int fd;
|
|
|
|
if (vdso_found)
|
|
return vdso_file;
|
|
|
|
if (find_vdso_map(&start, &end))
|
|
return NULL;
|
|
|
|
size = end - start;
|
|
|
|
buf = memdup(start, size);
|
|
if (!buf)
|
|
return NULL;
|
|
|
|
fd = mkstemp(vdso_file);
|
|
if (fd < 0)
|
|
goto out;
|
|
|
|
if (size == (size_t) write(fd, buf, size))
|
|
vdso = vdso_file;
|
|
|
|
close(fd);
|
|
|
|
out:
|
|
free(buf);
|
|
|
|
vdso_found = (vdso != NULL);
|
|
return vdso;
|
|
}
|
|
|
|
void vdso__exit(void)
|
|
{
|
|
if (vdso_found)
|
|
unlink(vdso_file);
|
|
}
|
|
|
|
struct dso *vdso__dso_findnew(struct list_head *head)
|
|
{
|
|
struct dso *dso = dsos__find(head, VDSO__MAP_NAME, true);
|
|
|
|
if (!dso) {
|
|
char *file;
|
|
|
|
file = get_file();
|
|
if (!file)
|
|
return NULL;
|
|
|
|
dso = dso__new(VDSO__MAP_NAME);
|
|
if (dso != NULL) {
|
|
dsos__add(head, dso);
|
|
dso__set_long_name(dso, file);
|
|
}
|
|
}
|
|
|
|
return dso;
|
|
}
|