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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/util/dsos.c (Version linux-6.12-rc7) and /tools/perf/util/dsos.c (Version linux-6.10.14)


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

~ [ 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