Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include "dsos.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include "dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "vdso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "namespaces.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <libgen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <symbol.h> // filename__read_build_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) static int __dso_id__cmp(struct dso_id *a, struct dso_id *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	if (a->maj > b->maj) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	if (a->maj < b->maj) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	if (a->min > b->min) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	if (a->min < b->min) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	if (a->ino > b->ino) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	if (a->ino < b->ino) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	if (a->ino_generation > b->ino_generation) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (a->ino_generation < b->ino_generation) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static bool dso_id__empty(struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return !id->maj && !id->min && !id->ino && !id->ino_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void dso__inject_id(struct dso *dso, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	dso->id.maj = id->maj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	dso->id.min = id->min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	dso->id.ino = id->ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	dso->id.ino_generation = id->ino_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int dso_id__cmp(struct dso_id *a, struct dso_id *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 * The second is always dso->id, so zeroes if not set, assume passing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * NULL for a means a zeroed id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (dso_id__empty(a) || dso_id__empty(b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return __dso_id__cmp(a, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) int dso__cmp_id(struct dso *a, struct dso *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return __dso_id__cmp(&a->id, &b->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	bool have_build_id = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct dso *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct nscookie nsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	list_for_each_entry(pos, head, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (with_hits && !pos->hit && !dso__is_vdso(pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (pos->has_build_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			have_build_id = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		nsinfo__mountns_enter(pos->nsinfo, &nsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (filename__read_build_id(pos->long_name, &pos->bid) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			have_build_id	  = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			pos->has_build_id = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		nsinfo__mountns_exit(&nsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return have_build_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int __dso__cmp_long_name(const char *long_name, struct dso_id *id, struct dso *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int rc = strcmp(long_name, b->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	return rc ?: dso_id__cmp(id, &b->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static int __dso__cmp_short_name(const char *short_name, struct dso_id *id, struct dso *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	int rc = strcmp(short_name, b->short_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return rc ?: dso_id__cmp(id, &b->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int dso__cmp_short_name(struct dso *a, struct dso *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return __dso__cmp_short_name(a->short_name, &a->id, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * Find a matching entry and/or link current entry to RB tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * Either one of the dso or name parameter must be non-NULL or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * function will not work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, struct dso *dso,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 						const char *name, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct rb_node **p = &root->rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct rb_node  *parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		name = dso->long_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * Find node with the matching name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		struct dso *this = rb_entry(*p, struct dso, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		int rc = __dso__cmp_long_name(name, id, this);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		parent = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			 * In case the new DSO is a duplicate of an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			 * one, print a one-time warning & put the new entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			 * at the end of the list of duplicates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			if (!dso || (dso == this))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				return this;	/* Find matching dso */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			 * The core kernel DSOs may have duplicated long name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			 * In this case, the short name should be different.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			 * Comparing the short names to differentiate the DSOs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			rc = dso__cmp_short_name(dso, this);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				pr_err("Duplicated dso name: %s\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			p = &parent->rb_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			p = &parent->rb_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (dso) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		/* Add new node and rebalance tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		rb_link_node(&dso->rb_node, parent, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		rb_insert_color(&dso->rb_node, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		dso->root = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void __dsos__add(struct dsos *dsos, struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	list_add_tail(&dso->node, &dsos->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	__dsos__findnew_link_by_longname_id(&dsos->root, dso, NULL, &dso->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * It is now in the linked list, grab a reference, then garbage collect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * this when needing memory, by looking at LRU dso instances in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * list with atomic_read(&dso->refcnt) == 1, i.e. no references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * anywhere besides the one for the list, do, under a lock for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * list: remove it from the list, then a dso__put(), that probably will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 * be the last and will then call dso__delete(), end of life.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 * That, or at the end of the 'struct machine' lifetime, when all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 * 'struct dso' instances will be removed from the list, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 * dsos__exit(), if they have no other reference from some other data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 * structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * E.g.: after processing a 'perf.data' file and storing references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * to objects instantiated while processing events, we will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * references to the 'thread', 'map', 'dso' structs all from 'struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 * hist_entry' instances, but we may not need anything not referenced,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 * so we might as well call machines__exit()/machines__delete() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 * garbage collect it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	dso__get(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) void dsos__add(struct dsos *dsos, struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	down_write(&dsos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	__dsos__add(dsos, dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	up_write(&dsos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static struct dso *__dsos__findnew_by_longname_id(struct rb_root *root, const char *name, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return __dsos__findnew_link_by_longname_id(root, NULL, name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, struct dso_id *id, bool cmp_short)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct dso *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (cmp_short) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		list_for_each_entry(pos, &dsos->head, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			if (__dso__cmp_short_name(name, id, pos) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 				return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return __dsos__findnew_by_longname_id(&dsos->root, name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return __dsos__find_id(dsos, name, NULL, cmp_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void dso__set_basename(struct dso *dso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	char *base, *lname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (sscanf(dso->long_name, "/tmp/perf-%d.map", &tid) == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if (asprintf(&base, "[JIT] tid %d", tid) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	      /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	       * basename() may modify path buffer, so we must pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)                * a copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)                */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		lname = strdup(dso->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (!lname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		 * basename() may return a pointer to internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		 * storage which is reused in subsequent calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		 * so copy the result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		base = strdup(basename(lname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		free(lname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		if (!base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	dso__set_short_name(dso, base, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct dso *dso = dso__new_id(name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (dso != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		__dsos__add(dsos, dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dso__set_basename(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		/* Put dso here because __dsos_add already got it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		dso__put(dso);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct dso *__dsos__addnew(struct dsos *dsos, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	return __dsos__addnew_id(dsos, name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct dso *dso = __dsos__find_id(dsos, name, id, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (dso && dso_id__empty(&dso->id) && !dso_id__empty(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dso__inject_id(dso, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return dso ? dso : __dsos__addnew_id(dsos, name, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct dso *dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	down_write(&dsos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	dso = dso__get(__dsos__findnew_id(dsos, name, id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	up_write(&dsos->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return dso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			       bool (skip)(struct dso *dso, int parm), int parm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct dso *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	list_for_each_entry(pos, head, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		char sbuild_id[SBUILD_ID_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		if (skip && skip(pos, parm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		build_id__sprintf(&pos->bid, sbuild_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		ret += fprintf(fp, "%-40s %s\n", sbuild_id, pos->long_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) size_t __dsos__fprintf(struct list_head *head, FILE *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct dso *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	size_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	list_for_each_entry(pos, head, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		ret += dso__fprintf(pos, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }