perf dso: Move dso functions out of dsos.c
authorIan Rogers <irogers@google.com>
Wed, 10 Apr 2024 06:42:06 +0000 (23:42 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 12 Apr 2024 15:04:13 +0000 (12:04 -0300)
Move dso and dso_id functions to dso.c to match the struct declarations.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anne Macedo <retpolanne@posteo.net>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ben Gainey <ben.gainey@arm.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Chengen Du <chengen.du@canonical.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Li Dong <lidong@vivo.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paran Lee <p4ranlee@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Song Liu <song@kernel.org>
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20240410064214.2755936-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/dso.c
tools/perf/util/dso.h
tools/perf/util/dsos.c

index 6e2a7198b382acaf960cb3c252a51589e45bbb36..ad562743d769ebc01a2b8a9dc4748a7bed1bdbbf 100644 (file)
@@ -1269,6 +1269,67 @@ static void dso__set_long_name_id(struct dso *dso, const char *name, struct dso_
                __dsos__findnew_link_by_longname_id(root, dso, NULL, id);
 }
 
+static int __dso_id__cmp(struct dso_id *a, struct dso_id *b)
+{
+       if (a->maj > b->maj) return -1;
+       if (a->maj < b->maj) return 1;
+
+       if (a->min > b->min) return -1;
+       if (a->min < b->min) return 1;
+
+       if (a->ino > b->ino) return -1;
+       if (a->ino < b->ino) return 1;
+
+       /*
+        * Synthesized MMAP events have zero ino_generation, avoid comparing
+        * them with MMAP events with actual ino_generation.
+        *
+        * I found it harmful because the mismatch resulted in a new
+        * dso that did not have a build ID whereas the original dso did have a
+        * build ID. The build ID was essential because the object was not found
+        * otherwise. - Adrian
+        */
+       if (a->ino_generation && b->ino_generation) {
+               if (a->ino_generation > b->ino_generation) return -1;
+               if (a->ino_generation < b->ino_generation) return 1;
+       }
+
+       return 0;
+}
+
+bool dso_id__empty(struct dso_id *id)
+{
+       if (!id)
+               return true;
+
+       return !id->maj && !id->min && !id->ino && !id->ino_generation;
+}
+
+void dso__inject_id(struct dso *dso, struct dso_id *id)
+{
+       dso->id.maj = id->maj;
+       dso->id.min = id->min;
+       dso->id.ino = id->ino;
+       dso->id.ino_generation = id->ino_generation;
+}
+
+int dso_id__cmp(struct dso_id *a, struct dso_id *b)
+{
+       /*
+        * The second is always dso->id, so zeroes if not set, assume passing
+        * NULL for a means a zeroed id
+        */
+       if (dso_id__empty(a) || dso_id__empty(b))
+               return 0;
+
+       return __dso_id__cmp(a, b);
+}
+
+int dso__cmp_id(struct dso *a, struct dso *b)
+{
+       return __dso_id__cmp(&a->id, &b->id);
+}
+
 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
 {
        dso__set_long_name_id(dso, name, NULL, name_allocated);
index 3d4faad8d5dc31aca1998deaa529a6bc7277b279..2c295438226d7a8cf0d13ce321c7fe657a4c3b1f 100644 (file)
@@ -238,6 +238,9 @@ static inline void dso__set_loaded(struct dso *dso)
        dso->loaded = true;
 }
 
+int dso_id__cmp(struct dso_id *a, struct dso_id *b);
+bool dso_id__empty(struct dso_id *id);
+
 struct dso *dso__new_id(const char *name, struct dso_id *id);
 struct dso *dso__new(const char *name);
 void dso__delete(struct dso *dso);
@@ -245,6 +248,7 @@ void dso__delete(struct dso *dso);
 int dso__cmp_id(struct dso *a, struct dso *b);
 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated);
 void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated);
+void dso__inject_id(struct dso *dso, struct dso_id *id);
 
 int dso__name_len(const struct dso *dso);
 
index d43f64939b121b4bc9826bb566daf891375178a6..f816927a21ffbf777868356565adc85c9c05d0f7 100644 (file)
@@ -41,67 +41,6 @@ void dsos__exit(struct dsos *dsos)
        exit_rwsem(&dsos->lock);
 }
 
-static int __dso_id__cmp(struct dso_id *a, struct dso_id *b)
-{
-       if (a->maj > b->maj) return -1;
-       if (a->maj < b->maj) return 1;
-
-       if (a->min > b->min) return -1;
-       if (a->min < b->min) return 1;
-
-       if (a->ino > b->ino) return -1;
-       if (a->ino < b->ino) return 1;
-
-       /*
-        * Synthesized MMAP events have zero ino_generation, avoid comparing
-        * them with MMAP events with actual ino_generation.
-        *
-        * I found it harmful because the mismatch resulted in a new
-        * dso that did not have a build ID whereas the original dso did have a
-        * build ID. The build ID was essential because the object was not found
-        * otherwise. - Adrian
-        */
-       if (a->ino_generation && b->ino_generation) {
-               if (a->ino_generation > b->ino_generation) return -1;
-               if (a->ino_generation < b->ino_generation) return 1;
-       }
-
-       return 0;
-}
-
-static bool dso_id__empty(struct dso_id *id)
-{
-       if (!id)
-               return true;
-
-       return !id->maj && !id->min && !id->ino && !id->ino_generation;
-}
-
-static void dso__inject_id(struct dso *dso, struct dso_id *id)
-{
-       dso->id.maj = id->maj;
-       dso->id.min = id->min;
-       dso->id.ino = id->ino;
-       dso->id.ino_generation = id->ino_generation;
-}
-
-static int dso_id__cmp(struct dso_id *a, struct dso_id *b)
-{
-       /*
-        * The second is always dso->id, so zeroes if not set, assume passing
-        * NULL for a means a zeroed id
-        */
-       if (dso_id__empty(a) || dso_id__empty(b))
-               return 0;
-
-       return __dso_id__cmp(a, b);
-}
-
-int dso__cmp_id(struct dso *a, struct dso *b)
-{
-       return __dso_id__cmp(&a->id, &b->id);
-}
-
 bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits)
 {
        struct list_head *head = &dsos->head;