]> www.infradead.org Git - linux.git/commitdiff
perf dso: Add dso__filename_with_chroot() to reduce number of accesses to dso->nsinfo...
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Apr 2023 21:28:01 +0000 (18:28 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Apr 2023 21:47:55 +0000 (18:47 -0300)
We'll need to reference count dso->nsinfo, so reduce the number of
direct accesses by having a shorter form of obtaining a filename with
a chroot (namespace one).

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/lkml/ZD26ZlqSbgSyH5lX@kernel.org
[ Used nsinfo__pid(dso->nsinfo), as it was already present ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-inject.c
tools/perf/util/annotate.c
tools/perf/util/dso.c
tools/perf/util/dso.h
tools/perf/util/dsos.c
tools/perf/util/symbol.c

index 76723ac314b60b808c8410d09ea8706e3527b997..61766eead4f48e348f5498272485989d23b2a033 100644 (file)
@@ -630,10 +630,8 @@ static int dso__read_build_id(struct dso *dso)
        if (filename__read_build_id(dso->long_name, &dso->bid) > 0)
                dso->has_build_id = true;
        else if (dso->nsinfo) {
-               char *new_name;
+               char *new_name = dso__filename_with_chroot(dso, dso->long_name);
 
-               new_name = filename_with_chroot(dso->nsinfo->pid,
-                                               dso->long_name);
                if (new_name && filename__read_build_id(new_name, &dso->bid) > 0)
                        dso->has_build_id = true;
                free(new_name);
index e2693a1c28d5989fdda81500e6dfa4686fc7ad8e..ca9f0add68f461e43b7f885dafa0d3ed8b0339c8 100644 (file)
@@ -1692,8 +1692,7 @@ fallback:
 
                mutex_lock(&dso->lock);
                if (access(filename, R_OK) && errno == ENOENT && dso->nsinfo) {
-                       char *new_name = filename_with_chroot(dso->nsinfo->pid,
-                                                             filename);
+                       char *new_name = dso__filename_with_chroot(dso, filename);
                        if (new_name) {
                                strlcpy(filename, new_name, filename_size);
                                free(new_name);
index e36b418df2c68cc2658f0c43b26240bf042876c3..a86614599269467dbc9c1ac8b7ff0c0b9f9ecc15 100644 (file)
@@ -491,6 +491,11 @@ static int do_open(char *name)
        return -1;
 }
 
+char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
+{
+       return filename_with_chroot(nsinfo__pid(dso->nsinfo), filename);
+}
+
 static int __open_dso(struct dso *dso, struct machine *machine)
 {
        int fd = -EINVAL;
@@ -515,7 +520,7 @@ static int __open_dso(struct dso *dso, struct machine *machine)
                if (errno != ENOENT || dso->nsinfo == NULL)
                        goto out;
 
-               new_name = filename_with_chroot(dso->nsinfo->pid, name);
+               new_name = dso__filename_with_chroot(dso, name);
                if (!new_name)
                        goto out;
 
index 58d94175e7148049b5a7a4f5346ed2cbe8b594cb..0b7c7633b9f6667d815cc0d4393a71fcd027519c 100644 (file)
@@ -266,6 +266,8 @@ static inline bool dso__has_symbols(const struct dso *dso)
        return !RB_EMPTY_ROOT(&dso->symbols.rb_root);
 }
 
+char *dso__filename_with_chroot(const struct dso *dso, const char *filename);
+
 bool dso__sorted_by_name(const struct dso *dso);
 void dso__set_sorted_by_name(struct dso *dso);
 void dso__sort_by_name(struct dso *dso);
index 2bd23e4cf19efaa76be391f04130fb856b67e386..cf80aa42dd07b036e3ed7816a22e90e96ef94581 100644 (file)
@@ -91,8 +91,7 @@ bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
                        have_build_id     = true;
                        pos->has_build_id = true;
                } else if (errno == ENOENT && pos->nsinfo) {
-                       char *new_name = filename_with_chroot(pos->nsinfo->pid,
-                                                             pos->long_name);
+                       char *new_name = dso__filename_with_chroot(pos, pos->long_name);
 
                        if (new_name && filename__read_build_id(new_name,
                                                                &pos->bid) > 0) {
index 91ebf93e0c20bd241390b19896fee9085560f5af..e7f63670688e8e594aa5683fe6df600794481671 100644 (file)
@@ -1963,8 +1963,7 @@ int dso__load(struct dso *dso, struct map *map)
 
                is_reg = is_regular_file(name);
                if (!is_reg && errno == ENOENT && dso->nsinfo) {
-                       char *new_name = filename_with_chroot(dso->nsinfo->pid,
-                                                             name);
+                       char *new_name = dso__filename_with_chroot(dso, name);
                        if (new_name) {
                                is_reg = is_regular_file(new_name);
                                strlcpy(name, new_name, PATH_MAX);