~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/util/dsos.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/util/dsos.c (Version linux-6.11.5) and /tools/perf/util/dsos.c (Version linux-5.11.22)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 #include "debug.h"                                  2 #include "debug.h"
  3 #include "dsos.h"                                   3 #include "dsos.h"
  4 #include "dso.h"                                    4 #include "dso.h"
  5 #include "util.h"                              << 
  6 #include "vdso.h"                                   5 #include "vdso.h"
  7 #include "namespaces.h"                             6 #include "namespaces.h"
  8 #include <errno.h>                             << 
  9 #include <libgen.h>                                 7 #include <libgen.h>
 10 #include <stdlib.h>                                 8 #include <stdlib.h>
 11 #include <string.h>                                 9 #include <string.h>
 12 #include <symbol.h> // filename__read_build_id     10 #include <symbol.h> // filename__read_build_id
 13 #include <unistd.h>                            << 
 14                                                    11 
 15 void dsos__init(struct dsos *dsos)             !!  12 static int __dso_id__cmp(struct dso_id *a, struct dso_id *b)
 16 {                                                  13 {
 17         init_rwsem(&dsos->lock);               !!  14         if (a->maj > b->maj) return -1;
                                                   >>  15         if (a->maj < b->maj) return 1;
 18                                                    16 
 19         dsos->cnt = 0;                         !!  17         if (a->min > b->min) return -1;
 20         dsos->allocated = 0;                   !!  18         if (a->min < b->min) return 1;
 21         dsos->dsos = NULL;                     << 
 22         dsos->sorted = true;                   << 
 23 }                                              << 
 24                                                    19 
 25 static void dsos__purge(struct dsos *dsos)     !!  20         if (a->ino > b->ino) return -1;
 26 {                                              !!  21         if (a->ino < b->ino) return 1;
 27         down_write(&dsos->lock);               << 
 28                                                    22 
 29         for (unsigned int i = 0; i < dsos->cnt !!  23         if (a->ino_generation > b->ino_generation) return -1;
 30                 struct dso *dso = dsos->dsos[i !!  24         if (a->ino_generation < b->ino_generation) return 1;
 31                                                    25 
 32                 dso__set_dsos(dso, NULL);      !!  26         return 0;
 33                 dso__put(dso);                 !!  27 }
 34         }                                      << 
 35                                                    28 
 36         zfree(&dsos->dsos);                    !!  29 static bool dso_id__empty(struct dso_id *id)
 37         dsos->cnt = 0;                         !!  30 {
 38         dsos->allocated = 0;                   !!  31         if (!id)
 39         dsos->sorted = true;                   !!  32                 return true;
 40                                                    33 
 41         up_write(&dsos->lock);                 !!  34         return !id->maj && !id->min && !id->ino && !id->ino_generation;
 42 }                                                  35 }
 43                                                    36 
 44 void dsos__exit(struct dsos *dsos)             !!  37 static void dso__inject_id(struct dso *dso, struct dso_id *id)
 45 {                                                  38 {
 46         dsos__purge(dsos);                     !!  39         dso->id.maj = id->maj;
 47         exit_rwsem(&dsos->lock);               !!  40         dso->id.min = id->min;
                                                   >>  41         dso->id.ino = id->ino;
                                                   >>  42         dso->id.ino_generation = id->ino_generation;
 48 }                                                  43 }
 49                                                    44 
 50                                                !!  45 static int dso_id__cmp(struct dso_id *a, struct dso_id *b)
 51 static int __dsos__for_each_dso(struct dsos *d << 
 52                                 int (*cb)(stru << 
 53                                 void *data)    << 
 54 {                                                  46 {
 55         for (unsigned int i = 0; i < dsos->cnt !!  47         /*
 56                 struct dso *dso = dsos->dsos[i !!  48          * The second is always dso->id, so zeroes if not set, assume passing
 57                 int err;                       !!  49          * NULL for a means a zeroed id
                                                   >>  50          */
                                                   >>  51         if (dso_id__empty(a) || dso_id__empty(b))
                                                   >>  52                 return 0;
 58                                                    53 
 59                 err = cb(dso, data);           !!  54         return __dso_id__cmp(a, b);
 60                 if (err)                       << 
 61                         return err;            << 
 62         }                                      << 
 63         return 0;                              << 
 64 }                                                  55 }
 65                                                    56 
 66 struct dsos__read_build_ids_cb_args {          !!  57 int dso__cmp_id(struct dso *a, struct dso *b)
 67         bool with_hits;                        !!  58 {
 68         bool have_build_id;                    !!  59         return __dso_id__cmp(&a->id, &b->id);
 69 };                                             !!  60 }
 70                                                    61 
 71 static int dsos__read_build_ids_cb(struct dso  !!  62 bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
 72 {                                                  63 {
 73         struct dsos__read_build_ids_cb_args *a !!  64         bool have_build_id = false;
                                                   >>  65         struct dso *pos;
 74         struct nscookie nsc;                       66         struct nscookie nsc;
 75                                                    67 
 76         if (args->with_hits && !dso__hit(dso)  !!  68         list_for_each_entry(pos, head, node) {
 77                 return 0;                      !!  69                 if (with_hits && !pos->hit && !dso__is_vdso(pos))
 78         if (dso__has_build_id(dso)) {          !!  70                         continue;
 79                 args->have_build_id = true;    !!  71                 if (pos->has_build_id) {
 80                 return 0;                      !!  72                         have_build_id = true;
 81         }                                      !!  73                         continue;
 82         nsinfo__mountns_enter(dso__nsinfo(dso) << 
 83         if (filename__read_build_id(dso__long_ << 
 84                 args->have_build_id = true;    << 
 85                 dso__set_has_build_id(dso);    << 
 86         } else if (errno == ENOENT && dso__nsi << 
 87                 char *new_name = dso__filename << 
 88                                                << 
 89                 if (new_name && filename__read << 
 90                         args->have_build_id =  << 
 91                         dso__set_has_build_id( << 
 92                 }                                  74                 }
 93                 free(new_name);                !!  75                 nsinfo__mountns_enter(pos->nsinfo, &nsc);
                                                   >>  76                 if (filename__read_build_id(pos->long_name, &pos->bid) > 0) {
                                                   >>  77                         have_build_id     = true;
                                                   >>  78                         pos->has_build_id = true;
                                                   >>  79                 }
                                                   >>  80                 nsinfo__mountns_exit(&nsc);
 94         }                                          81         }
 95         nsinfo__mountns_exit(&nsc);            << 
 96         return 0;                              << 
 97 }                                              << 
 98                                                << 
 99 bool dsos__read_build_ids(struct dsos *dsos, b << 
100 {                                              << 
101         struct dsos__read_build_ids_cb_args ar << 
102                 .with_hits = with_hits,        << 
103                 .have_build_id = false,        << 
104         };                                     << 
105                                                << 
106         dsos__for_each_dso(dsos, dsos__read_bu << 
107         return args.have_build_id;             << 
108 }                                              << 
109                                                    82 
110 static int __dso__cmp_long_name(const char *lo !!  83         return have_build_id;
111                                 const struct d << 
112 {                                              << 
113         int rc = strcmp(long_name, dso__long_n << 
114         return rc ?: dso_id__cmp(id, dso__id_c << 
115 }                                                  84 }
116                                                    85 
117 static int __dso__cmp_short_name(const char *s !!  86 static int __dso__cmp_long_name(const char *long_name, struct dso_id *id, struct dso *b)
118                                  const struct  << 
119 {                                                  87 {
120         int rc = strcmp(short_name, dso__short !!  88         int rc = strcmp(long_name, b->long_name);
121         return rc ?: dso_id__cmp(id, dso__id_c !!  89         return rc ?: dso_id__cmp(id, &b->id);
122 }                                                  90 }
123                                                    91 
124 static int dsos__cmp_long_name_id_short_name(c !!  92 static int __dso__cmp_short_name(const char *short_name, struct dso_id *id, struct dso *b)
125 {                                                  93 {
126         const struct dso *a = *((const struct  !!  94         int rc = strcmp(short_name, b->short_name);
127         const struct dso *b = *((const struct  !!  95         return rc ?: dso_id__cmp(id, &b->id);
128         int rc = strcmp(dso__long_name(a), dso << 
129                                                << 
130         if (!rc) {                             << 
131                 rc = dso_id__cmp(dso__id_const << 
132                 if (!rc)                       << 
133                         rc = strcmp(dso__short << 
134         }                                      << 
135         return rc;                             << 
136 }                                                  96 }
137                                                    97 
138 struct dsos__key {                             !!  98 static int dso__cmp_short_name(struct dso *a, struct dso *b)
139         const char *long_name;                 << 
140         const struct dso_id *id;               << 
141 };                                             << 
142                                                << 
143 static int dsos__cmp_key_long_name_id(const vo << 
144 {                                                  99 {
145         const struct dsos__key *key = vkey;    !! 100         return __dso__cmp_short_name(a->short_name, &a->id, b);
146         const struct dso *dso = *((const struc << 
147                                                << 
148         return __dso__cmp_long_name(key->long_ << 
149 }                                                 101 }
150                                                   102 
151 /*                                                103 /*
152  * Find a matching entry and/or link current e    104  * Find a matching entry and/or link current entry to RB tree.
153  * Either one of the dso or name parameter mus    105  * Either one of the dso or name parameter must be non-NULL or the
154  * function will not work.                        106  * function will not work.
155  */                                               107  */
156 static struct dso *__dsos__find_by_longname_id !! 108 struct dso *__dsos__findnew_link_by_longname_id(struct rb_root *root, struct dso *dso,
157                                                !! 109                                                 const char *name, struct dso_id *id)
158                                                << 
159                                                << 
160 {                                              << 
161         struct dsos__key key = {               << 
162                 .long_name = name,             << 
163                 .id = id,                      << 
164         };                                     << 
165         struct dso **res;                      << 
166                                                << 
167         if (dsos->dsos == NULL)                << 
168                 return NULL;                   << 
169                                                << 
170         if (!dsos->sorted) {                   << 
171                 if (!write_locked) {           << 
172                         struct dso *dso;       << 
173                                                << 
174                         up_read(&dsos->lock);  << 
175                         down_write(&dsos->lock << 
176                         dso = __dsos__find_by_ << 
177                                                << 
178                         up_write(&dsos->lock); << 
179                         down_read(&dsos->lock) << 
180                         return dso;            << 
181                 }                              << 
182                 qsort(dsos->dsos, dsos->cnt, s << 
183                       dsos__cmp_long_name_id_s << 
184                 dsos->sorted = true;           << 
185         }                                      << 
186                                                << 
187         res = bsearch(&key, dsos->dsos, dsos-> << 
188                       dsos__cmp_key_long_name_ << 
189         if (!res)                              << 
190                 return NULL;                   << 
191                                                << 
192         return dso__get(*res);                 << 
193 }                                              << 
194                                                << 
195 int __dsos__add(struct dsos *dsos, struct dso  << 
196 {                                                 110 {
197         if (dsos->cnt == dsos->allocated) {    !! 111         struct rb_node **p = &root->rb_node;
198                 unsigned int to_allocate = 2;  !! 112         struct rb_node  *parent = NULL;
199                 struct dso **temp;             << 
200                                                << 
201                 if (dsos->allocated > 0)       << 
202                         to_allocate = dsos->al << 
203                 temp = realloc(dsos->dsos, siz << 
204                 if (!temp)                     << 
205                         return -ENOMEM;        << 
206                 dsos->dsos = temp;             << 
207                 dsos->allocated = to_allocate; << 
208         }                                      << 
209         if (!dsos->sorted) {                   << 
210                 dsos->dsos[dsos->cnt++] = dso_ << 
211         } else {                               << 
212                 int low = 0, high = dsos->cnt  << 
213                 int insert = dsos->cnt; /* Def << 
214                                                   113 
215                 while (low <= high) {          !! 114         if (!name)
216                         int mid = low + (high  !! 115                 name = dso->long_name;
217                         int cmp = dsos__cmp_lo !! 116         /*
218                                                !! 117          * Find node with the matching name
219                         if (cmp < 0) {         !! 118          */
220                                 low = mid + 1; !! 119         while (*p) {
221                         } else {               !! 120                 struct dso *this = rb_entry(*p, struct dso, rb_node);
222                                 high = mid - 1 !! 121                 int rc = __dso__cmp_long_name(name, id, this);
223                                 insert = mid;  !! 122 
                                                   >> 123                 parent = *p;
                                                   >> 124                 if (rc == 0) {
                                                   >> 125                         /*
                                                   >> 126                          * In case the new DSO is a duplicate of an existing
                                                   >> 127                          * one, print a one-time warning & put the new entry
                                                   >> 128                          * at the end of the list of duplicates.
                                                   >> 129                          */
                                                   >> 130                         if (!dso || (dso == this))
                                                   >> 131                                 return this;    /* Find matching dso */
                                                   >> 132                         /*
                                                   >> 133                          * The core kernel DSOs may have duplicated long name.
                                                   >> 134                          * In this case, the short name should be different.
                                                   >> 135                          * Comparing the short names to differentiate the DSOs.
                                                   >> 136                          */
                                                   >> 137                         rc = dso__cmp_short_name(dso, this);
                                                   >> 138                         if (rc == 0) {
                                                   >> 139                                 pr_err("Duplicated dso name: %s\n", name);
                                                   >> 140                                 return NULL;
224                         }                         141                         }
225                 }                                 142                 }
226                 memmove(&dsos->dsos[insert + 1 !! 143                 if (rc < 0)
227                         (dsos->cnt - insert) * !! 144                         p = &parent->rb_left;
228                 dsos->cnt++;                   !! 145                 else
229                 dsos->dsos[insert] = dso__get( !! 146                         p = &parent->rb_right;
230         }                                         147         }
231         dso__set_dsos(dso, dsos);              !! 148         if (dso) {
232         return 0;                              !! 149                 /* Add new node and rebalance tree */
                                                   >> 150                 rb_link_node(&dso->rb_node, parent, p);
                                                   >> 151                 rb_insert_color(&dso->rb_node, root);
                                                   >> 152                 dso->root = root;
                                                   >> 153         }
                                                   >> 154         return NULL;
233 }                                                 155 }
234                                                   156 
235 int dsos__add(struct dsos *dsos, struct dso *d !! 157 void __dsos__add(struct dsos *dsos, struct dso *dso)
236 {                                                 158 {
237         int ret;                               !! 159         list_add_tail(&dso->node, &dsos->head);
                                                   >> 160         __dsos__findnew_link_by_longname_id(&dsos->root, dso, NULL, &dso->id);
                                                   >> 161         /*
                                                   >> 162          * It is now in the linked list, grab a reference, then garbage collect
                                                   >> 163          * this when needing memory, by looking at LRU dso instances in the
                                                   >> 164          * list with atomic_read(&dso->refcnt) == 1, i.e. no references
                                                   >> 165          * anywhere besides the one for the list, do, under a lock for the
                                                   >> 166          * list: remove it from the list, then a dso__put(), that probably will
                                                   >> 167          * be the last and will then call dso__delete(), end of life.
                                                   >> 168          *
                                                   >> 169          * That, or at the end of the 'struct machine' lifetime, when all
                                                   >> 170          * 'struct dso' instances will be removed from the list, in
                                                   >> 171          * dsos__exit(), if they have no other reference from some other data
                                                   >> 172          * structure.
                                                   >> 173          *
                                                   >> 174          * E.g.: after processing a 'perf.data' file and storing references
                                                   >> 175          * to objects instantiated while processing events, we will have
                                                   >> 176          * references to the 'thread', 'map', 'dso' structs all from 'struct
                                                   >> 177          * hist_entry' instances, but we may not need anything not referenced,
                                                   >> 178          * so we might as well call machines__exit()/machines__delete() and
                                                   >> 179          * garbage collect it.
                                                   >> 180          */
                                                   >> 181         dso__get(dso);
                                                   >> 182 }
238                                                   183 
                                                   >> 184 void dsos__add(struct dsos *dsos, struct dso *dso)
                                                   >> 185 {
239         down_write(&dsos->lock);                  186         down_write(&dsos->lock);
240         ret = __dsos__add(dsos, dso);          !! 187         __dsos__add(dsos, dso);
241         up_write(&dsos->lock);                    188         up_write(&dsos->lock);
242         return ret;                            << 
243 }                                                 189 }
244                                                   190 
245 struct dsos__find_id_cb_args {                 !! 191 static struct dso *__dsos__findnew_by_longname_id(struct rb_root *root, const char *name, struct dso_id *id)
246         const char *name;                      !! 192 {
247         struct dso_id *id;                     !! 193         return __dsos__findnew_link_by_longname_id(root, NULL, name, id);
248         struct dso *res;                       << 
249 };                                             << 
250                                                << 
251 static int dsos__find_id_cb(struct dso *dso, v << 
252 {                                              << 
253         struct dsos__find_id_cb_args *args = d << 
254                                                << 
255         if (__dso__cmp_short_name(args->name,  << 
256                 args->res = dso__get(dso);     << 
257                 return 1;                      << 
258         }                                      << 
259         return 0;                              << 
260                                                << 
261 }                                                 194 }
262                                                   195 
263 static struct dso *__dsos__find_id(struct dsos !! 196 static struct dso *__dsos__find_id(struct dsos *dsos, const char *name, struct dso_id *id, bool cmp_short)
264                                    bool cmp_sh << 
265 {                                                 197 {
266         struct dso *res;                       !! 198         struct dso *pos;
267                                                   199 
268         if (cmp_short) {                          200         if (cmp_short) {
269                 struct dsos__find_id_cb_args a !! 201                 list_for_each_entry(pos, &dsos->head, node)
270                         .name = name,          !! 202                         if (__dso__cmp_short_name(name, id, pos) == 0)
271                         .id = id,              !! 203                                 return pos;
272                         .res = NULL,           !! 204                 return NULL;
273                 };                             << 
274                                                << 
275                 __dsos__for_each_dso(dsos, dso << 
276                 return args.res;               << 
277         }                                         205         }
278         res = __dsos__find_by_longname_id(dsos !! 206         return __dsos__findnew_by_longname_id(&dsos->root, name, id);
279         return res;                            << 
280 }                                                 207 }
281                                                   208 
282 struct dso *dsos__find(struct dsos *dsos, cons !! 209 struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
283 {                                                 210 {
284         struct dso *res;                       !! 211         return __dsos__find_id(dsos, name, NULL, cmp_short);
285                                                << 
286         down_read(&dsos->lock);                << 
287         res = __dsos__find_id(dsos, name, NULL << 
288         up_read(&dsos->lock);                  << 
289         return res;                            << 
290 }                                                 212 }
291                                                   213 
292 static void dso__set_basename(struct dso *dso)    214 static void dso__set_basename(struct dso *dso)
293 {                                                 215 {
294         char *base, *lname;                       216         char *base, *lname;
295         int tid;                                  217         int tid;
296                                                   218 
297         if (perf_pid_map_tid(dso__long_name(ds !! 219         if (sscanf(dso->long_name, "/tmp/perf-%d.map", &tid) == 1) {
298                 if (asprintf(&base, "[JIT] tid    220                 if (asprintf(&base, "[JIT] tid %d", tid) < 0)
299                         return;                   221                         return;
300         } else {                                  222         } else {
301               /*                                  223               /*
302                * basename() may modify path bu    224                * basename() may modify path buffer, so we must pass
303                * a copy.                          225                * a copy.
304                */                                 226                */
305                 lname = strdup(dso__long_name( !! 227                 lname = strdup(dso->long_name);
306                 if (!lname)                       228                 if (!lname)
307                         return;                   229                         return;
308                                                   230 
309                 /*                                231                 /*
310                  * basename() may return a poi    232                  * basename() may return a pointer to internal
311                  * storage which is reused in     233                  * storage which is reused in subsequent calls
312                  * so copy the result.            234                  * so copy the result.
313                  */                               235                  */
314                 base = strdup(basename(lname))    236                 base = strdup(basename(lname));
315                                                   237 
316                 free(lname);                      238                 free(lname);
317                                                   239 
318                 if (!base)                        240                 if (!base)
319                         return;                   241                         return;
320         }                                         242         }
321         dso__set_short_name(dso, base, true);     243         dso__set_short_name(dso, base, true);
322 }                                                 244 }
323                                                   245 
324 static struct dso *__dsos__addnew_id(struct ds    246 static struct dso *__dsos__addnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
325 {                                                 247 {
326         struct dso *dso = dso__new_id(name, id    248         struct dso *dso = dso__new_id(name, id);
327                                                   249 
328         if (dso != NULL) {                        250         if (dso != NULL) {
329                 /*                             << 
330                  * The dsos lock is held on en << 
331                  * adding it to avoid needing  << 
332                  * the array isn't sorted.     << 
333                  */                            << 
334                 dso__set_basename(dso);        << 
335                 __dsos__add(dsos, dso);           251                 __dsos__add(dsos, dso);
                                                   >> 252                 dso__set_basename(dso);
                                                   >> 253                 /* Put dso here because __dsos_add already got it */
                                                   >> 254                 dso__put(dso);
336         }                                         255         }
337         return dso;                               256         return dso;
338 }                                                 257 }
339                                                   258 
                                                   >> 259 struct dso *__dsos__addnew(struct dsos *dsos, const char *name)
                                                   >> 260 {
                                                   >> 261         return __dsos__addnew_id(dsos, name, NULL);
                                                   >> 262 }
                                                   >> 263 
340 static struct dso *__dsos__findnew_id(struct d    264 static struct dso *__dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
341 {                                                 265 {
342         struct dso *dso = __dsos__find_id(dsos !! 266         struct dso *dso = __dsos__find_id(dsos, name, id, false);
343                                                   267 
344         if (dso && dso_id__empty(dso__id(dso)) !! 268         if (dso && dso_id__empty(&dso->id) && !dso_id__empty(id))
345                 __dso__inject_id(dso, id);     !! 269                 dso__inject_id(dso, id);
346                                                   270 
347         return dso ? dso : __dsos__addnew_id(d    271         return dso ? dso : __dsos__addnew_id(dsos, name, id);
348 }                                                 272 }
349                                                   273 
350 struct dso *dsos__findnew_id(struct dsos *dsos    274 struct dso *dsos__findnew_id(struct dsos *dsos, const char *name, struct dso_id *id)
351 {                                                 275 {
352         struct dso *dso;                          276         struct dso *dso;
353         down_write(&dsos->lock);                  277         down_write(&dsos->lock);
354         dso = __dsos__findnew_id(dsos, name, i !! 278         dso = dso__get(__dsos__findnew_id(dsos, name, id));
355         up_write(&dsos->lock);                    279         up_write(&dsos->lock);
356         return dso;                               280         return dso;
357 }                                                 281 }
358                                                   282 
359 struct dsos__fprintf_buildid_cb_args {         !! 283 size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
360         FILE *fp;                              !! 284                                bool (skip)(struct dso *dso, int parm), int parm)
361         bool (*skip)(struct dso *dso, int parm << 
362         int parm;                              << 
363         size_t ret;                            << 
364 };                                             << 
365                                                << 
366 static int dsos__fprintf_buildid_cb(struct dso << 
367 {                                              << 
368         struct dsos__fprintf_buildid_cb_args * << 
369         char sbuild_id[SBUILD_ID_SIZE];        << 
370                                                << 
371         if (args->skip && args->skip(dso, args << 
372                 return 0;                      << 
373         build_id__sprintf(dso__bid(dso), sbuil << 
374         args->ret += fprintf(args->fp, "%-40s  << 
375         return 0;                              << 
376 }                                              << 
377                                                << 
378 size_t dsos__fprintf_buildid(struct dsos *dsos << 
379                                bool (*skip)(st << 
380 {                                                 285 {
381         struct dsos__fprintf_buildid_cb_args a !! 286         struct dso *pos;
382                 .fp = fp,                      !! 287         size_t ret = 0;
383                 .skip = skip,                  << 
384                 .parm = parm,                  << 
385                 .ret = 0,                      << 
386         };                                     << 
387                                                   288 
388         dsos__for_each_dso(dsos, dsos__fprintf !! 289         list_for_each_entry(pos, head, node) {
389         return args.ret;                       !! 290                 char sbuild_id[SBUILD_ID_SIZE];
390 }                                              << 
391                                                << 
392 struct dsos__fprintf_cb_args {                 << 
393         FILE *fp;                              << 
394         size_t ret;                            << 
395 };                                             << 
396                                                << 
397 static int dsos__fprintf_cb(struct dso *dso, v << 
398 {                                              << 
399         struct dsos__fprintf_cb_args *args = d << 
400                                                << 
401         args->ret += dso__fprintf(dso, args->f << 
402         return 0;                              << 
403 }                                              << 
404                                                << 
405 size_t dsos__fprintf(struct dsos *dsos, FILE * << 
406 {                                              << 
407         struct dsos__fprintf_cb_args args = {  << 
408                 .fp = fp,                      << 
409                 .ret = 0,                      << 
410         };                                     << 
411                                                << 
412         dsos__for_each_dso(dsos, dsos__fprintf << 
413         return args.ret;                       << 
414 }                                              << 
415                                                << 
416 static int dsos__hit_all_cb(struct dso *dso, v << 
417 {                                              << 
418         dso__set_hit(dso);                     << 
419         return 0;                              << 
420 }                                              << 
421                                                   291 
422 int dsos__hit_all(struct dsos *dsos)           !! 292                 if (skip && skip(pos, parm))
423 {                                              !! 293                         continue;
424         return dsos__for_each_dso(dsos, dsos__ !! 294                 build_id__sprintf(&pos->bid, sbuild_id);
425 }                                              !! 295                 ret += fprintf(fp, "%-40s %s\n", sbuild_id, pos->long_name);
426                                                << 
427 struct dso *dsos__findnew_module_dso(struct ds << 
428                                      struct ma << 
429                                      struct km << 
430                                      const cha << 
431 {                                              << 
432         struct dso *dso;                       << 
433                                                << 
434         down_write(&dsos->lock);               << 
435                                                << 
436         dso = __dsos__find_id(dsos, m->name, N << 
437         if (dso) {                             << 
438                 up_write(&dsos->lock);         << 
439                 return dso;                    << 
440         }                                         296         }
441         /*                                     !! 297         return ret;
442          * Failed to find the dso so create it << 
443          * to the array, to avoid unnecessary  << 
444          * issues.                             << 
445          */                                    << 
446         dso = dso__new_id(m->name, /*id=*/NULL << 
447         if (!dso) {                            << 
448                 up_write(&dsos->lock);         << 
449                 return NULL;                   << 
450         }                                      << 
451         dso__set_basename(dso);                << 
452         dso__set_module_info(dso, m, machine); << 
453         dso__set_long_name(dso, strdup(filenam << 
454         dso__set_kernel(dso, DSO_SPACE__KERNEL << 
455         __dsos__add(dsos, dso);                << 
456                                                << 
457         up_write(&dsos->lock);                 << 
458         return dso;                            << 
459 }                                              << 
460                                                << 
461 static int dsos__find_kernel_dso_cb(struct dso << 
462 {                                              << 
463         struct dso **res = data;               << 
464         /*                                     << 
465          * The cpumode passed to is_kernel_mod << 
466          * event. If we insist on passing corr << 
467          * we should record the cpumode when w << 
468          * list.                               << 
469          *                                     << 
470          * However we don't really need passin << 
471          * correct cpumode must be kernel mode << 
472          * onto kernel_dsos list).             << 
473          *                                     << 
474          * Therefore, we pass PERF_RECORD_MISC << 
475          * is_kernel_module() treats it as a k << 
476          */                                    << 
477         if (!dso__kernel(dso) ||               << 
478             is_kernel_module(dso__long_name(ds << 
479                 return 0;                      << 
480                                                << 
481         *res = dso__get(dso);                  << 
482         return 1;                              << 
483 }                                                 298 }
484                                                   299 
485 struct dso *dsos__find_kernel_dso(struct dsos  !! 300 size_t __dsos__fprintf(struct list_head *head, FILE *fp)
486 {                                                 301 {
487         struct dso *res = NULL;                !! 302         struct dso *pos;
488                                                !! 303         size_t ret = 0;
489         dsos__for_each_dso(dsos, dsos__find_ke << 
490         return res;                            << 
491 }                                              << 
492                                                   304 
493 int dsos__for_each_dso(struct dsos *dsos, int  !! 305         list_for_each_entry(pos, head, node) {
494 {                                              !! 306                 ret += dso__fprintf(pos, fp);
495         int err;                               !! 307         }
496                                                   308 
497         down_read(&dsos->lock);                !! 309         return ret;
498         err = __dsos__for_each_dso(dsos, cb, d << 
499         up_read(&dsos->lock);                  << 
500         return err;                            << 
501 }                                                 310 }
502                                                   311 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php