summaryrefslogtreecommitdiff
path: root/tools/perf/util/dso.h
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-06-02 14:53:26 (GMT)
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-06-08 13:31:40 (GMT)
commitd3a7c489c7fd2463e3b2c3a2179c7be879dd9cb4 (patch)
tree5b89c379e629ed3c23f22102be66a99025c496da /tools/perf/util/dso.h
parente88078442232f3bbcb4ff1d24b3f9ab3dca472b9 (diff)
downloadlinux-d3a7c489c7fd2463e3b2c3a2179c7be879dd9cb4.tar.xz
perf tools: Reference count struct dso
This has a different model than the 'thread' and 'map' struct lifetimes: there is not a definitive "don't use this DSO anymore" event, i.e. we may get many 'struct map' holding references to the '/usr/lib64/libc-2.20.so' DSO but then at some point some DSO may have no references but we still don't want to straight away release its resources, because "soon" we may get a new 'struct map' that needs it and we want to reuse its symtab or other resources. So we need some way to garbage collect it when crossing some memory usage threshold, which is left for anoter patch, for now it is sufficient to release it when calling dsos__exit(), i.e. when deleting the whole list as part of deleting the 'struct machine' containing it, which will leave only referenced objects being used. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/n/tip-majzgz07cm90t2tejrjy4clf@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/dso.h')
-rw-r--r--tools/perf/util/dso.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index c16ab5d..2fe98bb 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -1,6 +1,7 @@
#ifndef __PERF_DSO
#define __PERF_DSO
+#include <linux/atomic.h>
#include <linux/types.h>
#include <linux/rbtree.h>
#include <stdbool.h>
@@ -179,7 +180,7 @@ struct dso {
void *priv;
u64 db_id;
};
-
+ atomic_t refcnt;
char name[0];
};
@@ -206,6 +207,17 @@ void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
int dso__name_len(const struct dso *dso);
+struct dso *dso__get(struct dso *dso);
+void dso__put(struct dso *dso);
+
+static inline void __dso__zput(struct dso **dso)
+{
+ dso__put(*dso);
+ *dso = NULL;
+}
+
+#define dso__zput(dso) __dso__zput(&dso)
+
bool dso__loaded(const struct dso *dso, enum map_type type);
bool dso__sorted_by_name(const struct dso *dso, enum map_type type);