2019-08-30 11:11:01 -03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "debug.h"
|
|
|
|
#include "dsos.h"
|
|
|
|
#include "dso.h"
|
2022-02-01 23:08:26 -08:00
|
|
|
#include "util.h"
|
2019-08-30 11:11:01 -03:00
|
|
|
#include "vdso.h"
|
|
|
|
#include "namespaces.h"
|
2022-02-01 23:08:26 -08:00
|
|
|
#include <errno.h>
|
2019-08-30 11:11:01 -03:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <symbol.h> // filename__read_build_id
|
2022-02-01 23:08:26 -08:00
|
|
|
#include <unistd.h>
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-04-09 23:42:03 -07:00
|
|
|
void dsos__init(struct dsos *dsos)
|
|
|
|
{
|
|
|
|
init_rwsem(&dsos->lock);
|
2024-05-04 14:37:57 -07:00
|
|
|
|
|
|
|
dsos->cnt = 0;
|
|
|
|
dsos->allocated = 0;
|
|
|
|
dsos->dsos = NULL;
|
|
|
|
dsos->sorted = true;
|
2024-04-09 23:42:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dsos__purge(struct dsos *dsos)
|
|
|
|
{
|
|
|
|
down_write(&dsos->lock);
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
for (unsigned int i = 0; i < dsos->cnt; i++) {
|
|
|
|
struct dso *dso = dsos->dsos[i];
|
|
|
|
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_dsos(dso, NULL);
|
2024-05-04 14:37:57 -07:00
|
|
|
dso__put(dso);
|
2024-04-09 23:42:03 -07:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
zfree(&dsos->dsos);
|
|
|
|
dsos->cnt = 0;
|
|
|
|
dsos->allocated = 0;
|
|
|
|
dsos->sorted = true;
|
|
|
|
|
2024-04-09 23:42:03 -07:00
|
|
|
up_write(&dsos->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dsos__exit(struct dsos *dsos)
|
|
|
|
{
|
|
|
|
dsos__purge(dsos);
|
|
|
|
exit_rwsem(&dsos->lock);
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
|
|
|
|
static int __dsos__for_each_dso(struct dsos *dsos,
|
|
|
|
int (*cb)(struct dso *dso, void *data),
|
|
|
|
void *data)
|
|
|
|
{
|
2024-05-04 14:37:57 -07:00
|
|
|
for (unsigned int i = 0; i < dsos->cnt; i++) {
|
|
|
|
struct dso *dso = dsos->dsos[i];
|
2024-04-09 23:42:07 -07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = cb(dso, data);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dsos__read_build_ids_cb_args {
|
|
|
|
bool with_hits;
|
|
|
|
bool have_build_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dsos__read_build_ids_cb(struct dso *dso, void *data)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__read_build_ids_cb_args *args = data;
|
2019-08-30 11:11:01 -03:00
|
|
|
struct nscookie nsc;
|
|
|
|
|
2024-05-04 14:38:01 -07:00
|
|
|
if (args->with_hits && !dso__hit(dso) && !dso__is_vdso(dso))
|
2024-04-09 23:42:07 -07:00
|
|
|
return 0;
|
2024-05-04 14:38:01 -07:00
|
|
|
if (dso__has_build_id(dso)) {
|
2024-04-09 23:42:07 -07:00
|
|
|
args->have_build_id = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2024-05-04 14:38:01 -07:00
|
|
|
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
|
|
|
|
if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0) {
|
2024-04-09 23:42:07 -07:00
|
|
|
args->have_build_id = true;
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_has_build_id(dso);
|
|
|
|
} else if (errno == ENOENT && dso__nsinfo(dso)) {
|
|
|
|
char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));
|
2024-04-09 23:42:07 -07:00
|
|
|
|
2024-05-04 14:38:01 -07:00
|
|
|
if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0) {
|
2024-04-09 23:42:07 -07:00
|
|
|
args->have_build_id = true;
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_has_build_id(dso);
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
2024-04-09 23:42:07 -07:00
|
|
|
free(new_name);
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
2024-04-09 23:42:07 -07:00
|
|
|
nsinfo__mountns_exit(&nsc);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
bool dsos__read_build_ids(struct dsos *dsos, bool with_hits)
|
|
|
|
{
|
|
|
|
struct dsos__read_build_ids_cb_args args = {
|
|
|
|
.with_hits = with_hits,
|
|
|
|
.have_build_id = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
dsos__for_each_dso(dsos, dsos__read_build_ids_cb, &args);
|
|
|
|
return args.have_build_id;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:38:00 -07:00
|
|
|
static int __dso__cmp_long_name(const char *long_name, const struct dso_id *id,
|
|
|
|
const struct dso *b)
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
{
|
2024-05-04 14:38:01 -07:00
|
|
|
int rc = strcmp(long_name, dso__long_name(b));
|
|
|
|
return rc ?: dso_id__cmp(id, dso__id_const(b));
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:38:00 -07:00
|
|
|
static int __dso__cmp_short_name(const char *short_name, const struct dso_id *id,
|
|
|
|
const struct dso *b)
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
{
|
2024-05-04 14:38:01 -07:00
|
|
|
int rc = strcmp(short_name, dso__short_name(b));
|
|
|
|
return rc ?: dso_id__cmp(id, dso__id_const(b));
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
static int dsos__cmp_long_name_id_short_name(const void *va, const void *vb)
|
|
|
|
{
|
|
|
|
const struct dso *a = *((const struct dso **)va);
|
|
|
|
const struct dso *b = *((const struct dso **)vb);
|
2024-05-04 14:38:01 -07:00
|
|
|
int rc = strcmp(dso__long_name(a), dso__long_name(b));
|
2024-05-04 14:37:57 -07:00
|
|
|
|
|
|
|
if (!rc) {
|
2024-05-04 14:38:01 -07:00
|
|
|
rc = dso_id__cmp(dso__id_const(a), dso__id_const(b));
|
2024-05-04 14:37:57 -07:00
|
|
|
if (!rc)
|
2024-05-04 14:38:01 -07:00
|
|
|
rc = strcmp(dso__short_name(a), dso__short_name(b));
|
2024-05-04 14:37:57 -07:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2024-05-04 14:38:00 -07:00
|
|
|
struct dsos__key {
|
|
|
|
const char *long_name;
|
|
|
|
const struct dso_id *id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dsos__cmp_key_long_name_id(const void *vkey, const void *vdso)
|
|
|
|
{
|
|
|
|
const struct dsos__key *key = vkey;
|
|
|
|
const struct dso *dso = *((const struct dso **)vdso);
|
|
|
|
|
|
|
|
return __dso__cmp_long_name(key->long_name, key->id, dso);
|
|
|
|
}
|
|
|
|
|
2019-08-30 11:11:01 -03:00
|
|
|
/*
|
|
|
|
* Find a matching entry and/or link current entry to RB tree.
|
|
|
|
* Either one of the dso or name parameter must be non-NULL or the
|
|
|
|
* function will not work.
|
|
|
|
*/
|
2024-05-04 14:37:59 -07:00
|
|
|
static struct dso *__dsos__find_by_longname_id(struct dsos *dsos,
|
|
|
|
const char *name,
|
|
|
|
struct dso_id *id,
|
|
|
|
bool write_locked)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-05-04 14:38:00 -07:00
|
|
|
struct dsos__key key = {
|
|
|
|
.long_name = name,
|
|
|
|
.id = id,
|
|
|
|
};
|
|
|
|
struct dso **res;
|
2024-05-04 14:37:57 -07:00
|
|
|
|
|
|
|
if (!dsos->sorted) {
|
|
|
|
if (!write_locked) {
|
2024-05-04 14:37:59 -07:00
|
|
|
struct dso *dso;
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
up_read(&dsos->lock);
|
|
|
|
down_write(&dsos->lock);
|
2024-05-04 14:37:59 -07:00
|
|
|
dso = __dsos__find_by_longname_id(dsos, name, id,
|
|
|
|
/*write_locked=*/true);
|
2024-05-04 14:37:57 -07:00
|
|
|
up_write(&dsos->lock);
|
|
|
|
down_read(&dsos->lock);
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
qsort(dsos->dsos, dsos->cnt, sizeof(struct dso *),
|
|
|
|
dsos__cmp_long_name_id_short_name);
|
|
|
|
dsos->sorted = true;
|
|
|
|
}
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-05-04 14:38:00 -07:00
|
|
|
res = bsearch(&key, dsos->dsos, dsos->cnt, sizeof(struct dso *),
|
|
|
|
dsos__cmp_key_long_name_id);
|
|
|
|
if (!res)
|
|
|
|
return NULL;
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-05-04 14:38:00 -07:00
|
|
|
return dso__get(*res);
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
int __dsos__add(struct dsos *dsos, struct dso *dso)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-05-04 14:37:57 -07:00
|
|
|
if (dsos->cnt == dsos->allocated) {
|
|
|
|
unsigned int to_allocate = 2;
|
|
|
|
struct dso **temp;
|
|
|
|
|
|
|
|
if (dsos->allocated > 0)
|
|
|
|
to_allocate = dsos->allocated * 2;
|
|
|
|
temp = realloc(dsos->dsos, sizeof(struct dso *) * to_allocate);
|
|
|
|
if (!temp)
|
|
|
|
return -ENOMEM;
|
|
|
|
dsos->dsos = temp;
|
|
|
|
dsos->allocated = to_allocate;
|
|
|
|
}
|
|
|
|
dsos->dsos[dsos->cnt++] = dso__get(dso);
|
|
|
|
if (dsos->cnt >= 2 && dsos->sorted) {
|
|
|
|
dsos->sorted = dsos__cmp_long_name_id_short_name(&dsos->dsos[dsos->cnt - 2],
|
|
|
|
&dsos->dsos[dsos->cnt - 1])
|
|
|
|
<= 0;
|
|
|
|
}
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_dsos(dso, dsos);
|
2024-05-04 14:37:57 -07:00
|
|
|
return 0;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
int dsos__add(struct dsos *dsos, struct dso *dso)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-05-04 14:37:57 -07:00
|
|
|
int ret;
|
|
|
|
|
2019-08-30 11:11:01 -03:00
|
|
|
down_write(&dsos->lock);
|
2024-05-04 14:37:57 -07:00
|
|
|
ret = __dsos__add(dsos, dso);
|
2019-08-30 11:11:01 -03:00
|
|
|
up_write(&dsos->lock);
|
2024-05-04 14:37:57 -07:00
|
|
|
return ret;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__find_id_cb_args {
|
|
|
|
const char *name;
|
|
|
|
struct dso_id *id;
|
|
|
|
struct dso *res;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dsos__find_id_cb(struct dso *dso, void *data)
|
|
|
|
{
|
|
|
|
struct dsos__find_id_cb_args *args = data;
|
|
|
|
|
|
|
|
if (__dso__cmp_short_name(args->name, args->id, dso) == 0) {
|
|
|
|
args->res = dso__get(dso);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, struct dso_id *id,
|
|
|
|
bool cmp_short, bool write_locked)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dso *res;
|
2019-08-30 11:11:01 -03:00
|
|
|
|
|
|
|
if (cmp_short) {
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__find_id_cb_args args = {
|
|
|
|
.name = name,
|
|
|
|
.id = id,
|
|
|
|
.res = NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
__dsos__for_each_dso(dsos, dsos__find_id_cb, &args);
|
|
|
|
return args.res;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
2024-05-04 14:37:59 -07:00
|
|
|
res = __dsos__find_by_longname_id(dsos, name, id, write_locked);
|
2024-04-09 23:42:07 -07:00
|
|
|
return res;
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:04 -07:00
|
|
|
struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
{
|
2024-04-09 23:42:04 -07:00
|
|
|
struct dso *res;
|
|
|
|
|
|
|
|
down_read(&dsos->lock);
|
2024-05-04 14:37:57 -07:00
|
|
|
res = __dsos__find_id(dsos, name, NULL, cmp_short, /*write_locked=*/false);
|
2024-04-09 23:42:04 -07:00
|
|
|
up_read(&dsos->lock);
|
|
|
|
return res;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dso__set_basename(struct dso *dso)
|
|
|
|
{
|
|
|
|
char *base, *lname;
|
|
|
|
int tid;
|
|
|
|
|
2024-05-04 14:38:01 -07:00
|
|
|
if (sscanf(dso__long_name(dso), "/tmp/perf-%d.map", &tid) == 1) {
|
2019-08-30 11:11:01 -03:00
|
|
|
if (asprintf(&base, "[JIT] tid %d", tid) < 0)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* basename() may modify path buffer, so we must pass
|
|
|
|
* a copy.
|
|
|
|
*/
|
2024-05-04 14:38:01 -07:00
|
|
|
lname = strdup(dso__long_name(dso));
|
2019-08-30 11:11:01 -03:00
|
|
|
if (!lname)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* basename() may return a pointer to internal
|
|
|
|
* storage which is reused in subsequent calls
|
|
|
|
* so copy the result.
|
|
|
|
*/
|
|
|
|
base = strdup(basename(lname));
|
|
|
|
|
|
|
|
free(lname);
|
|
|
|
|
|
|
|
if (!base)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dso__set_short_name(dso, base, true);
|
|
|
|
}
|
|
|
|
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
struct dso *dso = dso__new_id(name, id);
|
2019-08-30 11:11:01 -03:00
|
|
|
|
|
|
|
if (dso != NULL) {
|
2024-05-04 14:37:57 -07:00
|
|
|
/*
|
|
|
|
* The dsos lock is held on entry, so rename the dso before
|
|
|
|
* adding it to avoid needing to take the dsos lock again to say
|
|
|
|
* the array isn't sorted.
|
|
|
|
*/
|
2019-08-30 11:11:01 -03:00
|
|
|
dso__set_basename(dso);
|
2024-05-04 14:37:57 -07:00
|
|
|
__dsos__add(dsos, dso);
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
|
|
|
|
{
|
2024-05-04 14:37:57 -07:00
|
|
|
struct dso *dso = __dsos__find_id(dsos, name, id, false, /*write_locked=*/true);
|
2020-03-24 09:54:24 +05:30
|
|
|
|
2024-05-04 14:38:01 -07:00
|
|
|
if (dso && dso_id__empty(dso__id(dso)) && !dso_id__empty(id))
|
2024-05-04 14:37:57 -07:00
|
|
|
__dso__inject_id(dso, id);
|
2020-03-24 09:54:24 +05:30
|
|
|
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
return dso ? dso : __dsos__addnew_id(dsos, name, id);
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
perf dso: Move dso_id from 'struct map' to 'struct dso'
And take it into account when looking up DSOs when we have the dso_id
fields obtained from somewhere, like from PERF_RECORD_MMAP2 records.
Instances of struct map pointing to the same DSO pathname but with
anything in dso_id different are in fact different DSOs, so better have
different 'struct dso' instances to reflect that. At some point we may
want to get copies of the contents of the different objects if we want
to do correct annotation or other analysis.
With this we get 'struct map' 24 bytes leaner:
$ pahole -C map ~/bin/perf
struct map {
union {
struct rb_node rb_node __attribute__((__aligned__(8))); /* 0 24 */
struct list_head node; /* 0 16 */
} __attribute__((__aligned__(8))); /* 0 24 */
u64 start; /* 24 8 */
u64 end; /* 32 8 */
_Bool erange_warned:1; /* 40: 0 1 */
_Bool priv:1; /* 40: 1 1 */
/* XXX 6 bits hole, try to pack */
/* XXX 3 bytes hole, try to pack */
u32 prot; /* 44 4 */
u64 pgoff; /* 48 8 */
u64 reloc; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
u64 (*map_ip)(struct map *, u64); /* 64 8 */
u64 (*unmap_ip)(struct map *, u64); /* 72 8 */
struct dso * dso; /* 80 8 */
refcount_t refcnt; /* 88 4 */
u32 flags; /* 92 4 */
/* size: 96, cachelines: 2, members: 13 */
/* sum members: 92, holes: 1, sum holes: 3 */
/* sum bitfield members: 2 bits, bit holes: 1, sum bit holes: 6 bits */
/* forced alignments: 1 */
/* last cacheline: 32 bytes */
} __attribute__((__aligned__(8)));
$
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-g4hxxmraplo7wfjmk384mfsb@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-19 18:44:22 -03:00
|
|
|
struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
|
|
|
struct dso *dso;
|
|
|
|
down_write(&dsos->lock);
|
2024-04-09 23:42:04 -07:00
|
|
|
dso = __dsos__findnew_id(dsos, name, id);
|
2019-08-30 11:11:01 -03:00
|
|
|
up_write(&dsos->lock);
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__fprintf_buildid_cb_args {
|
|
|
|
FILE *fp;
|
|
|
|
bool (*skip)(struct dso *dso, int parm);
|
|
|
|
int parm;
|
|
|
|
size_t ret;
|
|
|
|
};
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
static int dsos__fprintf_buildid_cb(struct dso *dso, void *data)
|
|
|
|
{
|
|
|
|
struct dsos__fprintf_buildid_cb_args *args = data;
|
|
|
|
char sbuild_id[SBUILD_ID_SIZE];
|
2020-10-13 21:24:40 +02:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
if (args->skip && args->skip(dso, args->parm))
|
|
|
|
return 0;
|
2024-05-04 14:38:01 -07:00
|
|
|
build_id__sprintf(dso__bid(dso), sbuild_id);
|
|
|
|
args->ret += fprintf(args->fp, "%-40s %s\n", sbuild_id, dso__long_name(dso));
|
2024-04-09 23:42:07 -07:00
|
|
|
return 0;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
size_t dsos__fprintf_buildid(struct dsos *dsos, FILE *fp,
|
|
|
|
bool (*skip)(struct dso *dso, int parm), int parm)
|
2019-08-30 11:11:01 -03:00
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__fprintf_buildid_cb_args args = {
|
|
|
|
.fp = fp,
|
|
|
|
.skip = skip,
|
|
|
|
.parm = parm,
|
|
|
|
.ret = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
dsos__for_each_dso(dsos, dsos__fprintf_buildid_cb, &args);
|
|
|
|
return args.ret;
|
|
|
|
}
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__fprintf_cb_args {
|
|
|
|
FILE *fp;
|
|
|
|
size_t ret;
|
|
|
|
};
|
2019-08-30 11:11:01 -03:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
static int dsos__fprintf_cb(struct dso *dso, void *data)
|
|
|
|
{
|
|
|
|
struct dsos__fprintf_cb_args *args = data;
|
|
|
|
|
|
|
|
args->ret += dso__fprintf(dso, args->fp);
|
|
|
|
return 0;
|
2019-08-30 11:11:01 -03:00
|
|
|
}
|
2024-04-09 23:42:03 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
size_t dsos__fprintf(struct dsos *dsos, FILE *fp)
|
2024-04-09 23:42:03 -07:00
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dsos__fprintf_cb_args args = {
|
|
|
|
.fp = fp,
|
|
|
|
.ret = 0,
|
|
|
|
};
|
2024-04-09 23:42:03 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
dsos__for_each_dso(dsos, dsos__fprintf_cb, &args);
|
|
|
|
return args.ret;
|
|
|
|
}
|
2024-04-09 23:42:03 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
static int dsos__hit_all_cb(struct dso *dso, void *data __maybe_unused)
|
|
|
|
{
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_hit(dso);
|
2024-04-09 23:42:03 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2024-04-09 23:42:04 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
int dsos__hit_all(struct dsos *dsos)
|
|
|
|
{
|
|
|
|
return dsos__for_each_dso(dsos, dsos__hit_all_cb, NULL);
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:04 -07:00
|
|
|
struct dso *dsos__findnew_module_dso(struct dsos *dsos,
|
|
|
|
struct machine *machine,
|
|
|
|
struct kmod_path *m,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
struct dso *dso;
|
|
|
|
|
|
|
|
down_write(&dsos->lock);
|
|
|
|
|
2024-05-04 14:37:57 -07:00
|
|
|
dso = __dsos__find_id(dsos, m->name, NULL, /*cmp_short=*/true, /*write_locked=*/true);
|
|
|
|
if (dso) {
|
|
|
|
up_write(&dsos->lock);
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Failed to find the dso so create it. Change the name before adding it
|
|
|
|
* to the array, to avoid unnecessary sorts and potential locking
|
|
|
|
* issues.
|
|
|
|
*/
|
|
|
|
dso = dso__new_id(m->name, /*id=*/NULL);
|
2024-04-09 23:42:04 -07:00
|
|
|
if (!dso) {
|
2024-05-04 14:37:57 -07:00
|
|
|
up_write(&dsos->lock);
|
|
|
|
return NULL;
|
2024-04-09 23:42:04 -07:00
|
|
|
}
|
2024-05-04 14:37:57 -07:00
|
|
|
dso__set_basename(dso);
|
|
|
|
dso__set_module_info(dso, m, machine);
|
|
|
|
dso__set_long_name(dso, strdup(filename), true);
|
2024-05-04 14:38:01 -07:00
|
|
|
dso__set_kernel(dso, DSO_SPACE__KERNEL);
|
2024-05-04 14:37:57 -07:00
|
|
|
__dsos__add(dsos, dso);
|
2024-04-09 23:42:04 -07:00
|
|
|
|
|
|
|
up_write(&dsos->lock);
|
|
|
|
return dso;
|
|
|
|
}
|
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
static int dsos__find_kernel_dso_cb(struct dso *dso, void *data)
|
2024-04-09 23:42:04 -07:00
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dso **res = data;
|
|
|
|
/*
|
|
|
|
* The cpumode passed to is_kernel_module is not the cpumode of *this*
|
|
|
|
* event. If we insist on passing correct cpumode to is_kernel_module,
|
|
|
|
* we should record the cpumode when we adding this dso to the linked
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
* However we don't really need passing correct cpumode. We know the
|
|
|
|
* correct cpumode must be kernel mode (if not, we should not link it
|
|
|
|
* onto kernel_dsos list).
|
|
|
|
*
|
|
|
|
* Therefore, we pass PERF_RECORD_MISC_CPUMODE_UNKNOWN.
|
|
|
|
* is_kernel_module() treats it as a kernel cpumode.
|
|
|
|
*/
|
2024-05-04 14:38:01 -07:00
|
|
|
if (!dso__kernel(dso) ||
|
|
|
|
is_kernel_module(dso__long_name(dso), PERF_RECORD_MISC_CPUMODE_UNKNOWN))
|
2024-04-09 23:42:07 -07:00
|
|
|
return 0;
|
2024-04-09 23:42:04 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
*res = dso__get(dso);
|
|
|
|
return 1;
|
|
|
|
}
|
2024-04-09 23:42:04 -07:00
|
|
|
|
2024-04-09 23:42:07 -07:00
|
|
|
struct dso *dsos__find_kernel_dso(struct dsos *dsos)
|
|
|
|
{
|
|
|
|
struct dso *res = NULL;
|
|
|
|
|
|
|
|
dsos__for_each_dso(dsos, dsos__find_kernel_dso_cb, &res);
|
2024-04-09 23:42:04 -07:00
|
|
|
return res;
|
|
|
|
}
|
2024-04-09 23:42:05 -07:00
|
|
|
|
|
|
|
int dsos__for_each_dso(struct dsos *dsos, int (*cb)(struct dso *dso, void *data), void *data)
|
|
|
|
{
|
2024-04-09 23:42:07 -07:00
|
|
|
int err;
|
2024-04-09 23:42:05 -07:00
|
|
|
|
|
|
|
down_read(&dsos->lock);
|
2024-04-09 23:42:07 -07:00
|
|
|
err = __dsos__for_each_dso(dsos, cb, data);
|
2024-04-09 23:42:05 -07:00
|
|
|
up_read(&dsos->lock);
|
2024-04-09 23:42:07 -07:00
|
|
|
return err;
|
2024-04-09 23:42:05 -07:00
|
|
|
}
|