perf core: avoid traverse dsos list while find vdso
PATCH 1/2 perf core: avoid traverse dsos list while find vdso
From: Chenggang Qin <[email protected]>
Vdso is only one in a system. It is not necessory to traverse the macine->user_dsos list while finding the dso of vdso.
The flag vdso_found should be replaced by a pointor that point to the dso of vdso. If the pointer is NULL, dso of vdso have not been created. Else, the pointor can be returned directly in function vdso__dso_findnew(). The list traversing can be avoided by this method.
Thanks.
--- tools/perf/util/vdso.c | 22 ++++++++-------------- 1 files changed, 8 insertions(+), 14 deletions(-)
tools/perf/util/vdso.c +8 -14
@@ -13,7 +13,7 @@#include "symbol.h" #include "linux/string.h" -static bool vdso_found; +static struct dso *vdso_dso =NULL ;static char vdso_file[] ="/tmp/perf-vdso.so-XXXXXX" ;static int find_vdso_map (void **start,void **end)
@@ -55,9 +55,6 @@ static char *get_file(void)size_t size;int fd; -if (vdso_found) -return vdso_file; -if (find_vdso_map (&start, &end))return NULL ;
@@ -79,33 +76,30 @@ static char *get_file(void) out:free (buf); - vdso_found = (vdso !=NULL );return vdso; }void vdso__exit (void ) { -if (vdso_found) +if (vdso_dso)unlink (vdso_file); }struct dso *vdso__dso_findnew (struct list_head *head) { -struct dso *dso =dsos__find (head,VDSO__MAP_NAME , true); - -if (!dso) { +if (!vdso_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); + vdso_dso =dso__new (VDSO__MAP_NAME ); +if (vdso_dso !=NULL ) { +dsos__add (head, vdso_dso); +dso__set_long_name (vdso_dso, file); } } -return dso; +return vdso_dso; }
Signature · 1 line
1.7.8.rc2.5.g815b
PATCH 2/2 perf core: remove short name compare in dsos__find()
From: Chenggang Qin <[email protected]>
If the list traversal is avoided by the last patch, the short name compare in dsos__find() is unnecessary. The purpose of short name compare is only to find the dso of vdso. If the vdso can be found by a pointor, the short name compare can be removed.
Thanks
--- tools/perf/util/dso.c | 10 ++-------- tools/perf/util/dso.h | 3 +-- 2 files changed, 3 insertions(+), 10 deletions(-)
tools/perf/util/dso.c +2 -8
@@ -513,16 +513,10 @@ void dsos__add(struct list_head *head, struct dso *dso)list_add_tail (&dso->node, head); } -struct dso *dsos__find (struct list_head *head,const char *name,bool cmp_short) +struct dso *dsos__find (struct list_head *head,const char *name) {struct dso *pos; -if (cmp_short) { -list_for_each_entry (pos, head, node) -if (strcmp (pos->short_name, name) ==0 ) -return pos; -return NULL ; - }list_for_each_entry (pos, head, node)if (strcmp (pos->long_name, name) ==0 )return pos;
@@ -531,7 +525,7 @@ struct dso *dsos__find(struct list_head *head, const char *name, bool cmp_short)struct dso *__dsos__findnew (struct list_head *head,const char *name) { -struct dso *dso =dsos__find (head, name, false); +struct dso *dso =dsos__find (head, name);if (!dso) { dso =dso__new (name);
tools/perf/util/dso.h +1 -2
@@ -133,8 +133,7 @@ struct dso *dso__kernel_findnew(struct machine *machine, const char *name, const char *short_name, int dso_type);void dsos__add (struct list_head *head,struct dso *dso); -struct dso *dsos__find (struct list_head *head,const char *name, -bool cmp_short); +struct dso *dsos__find (struct list_head *head,const char *name);struct dso *__dsos__findnew (struct list_head *head,const char *name);bool __dsos__read_build_ids (struct list_head *head,bool with_hits);
Signature · 1 line
1.7.8.rc2.5.g815b
Peter Zijlstra
maintainerQuoted 3 lines
Subject: [PATCH 1/2] perf core: avoid traverse dsos list while find vdso
tools/perf/util/vdso.c | 22 ++++++++--------------
That's not perf core that's perf tools.