perf dso: Move dso functions out of dsos.c

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>
This commit is contained in:
Ian Rogers 2024-04-09 23:42:06 -07:00 committed by Arnaldo Carvalho de Melo
parent 73f3fea2e1
commit 1d6eff9305
3 changed files with 65 additions and 61 deletions

View 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);

View 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);

View 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;