machine.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. #include "callchain.h"
  2. #include "debug.h"
  3. #include "event.h"
  4. #include "evsel.h"
  5. #include "hist.h"
  6. #include "machine.h"
  7. #include "map.h"
  8. #include "sort.h"
  9. #include "strlist.h"
  10. #include "thread.h"
  11. #include <stdbool.h>
  12. #include <symbol/kallsyms.h>
  13. #include "unwind.h"
  14. int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
  15. {
  16. map_groups__init(&machine->kmaps);
  17. RB_CLEAR_NODE(&machine->rb_node);
  18. INIT_LIST_HEAD(&machine->user_dsos);
  19. INIT_LIST_HEAD(&machine->kernel_dsos);
  20. machine->threads = RB_ROOT;
  21. INIT_LIST_HEAD(&machine->dead_threads);
  22. machine->last_match = NULL;
  23. machine->kmaps.machine = machine;
  24. machine->pid = pid;
  25. machine->symbol_filter = NULL;
  26. machine->id_hdr_size = 0;
  27. machine->root_dir = strdup(root_dir);
  28. if (machine->root_dir == NULL)
  29. return -ENOMEM;
  30. if (pid != HOST_KERNEL_ID) {
  31. struct thread *thread = machine__findnew_thread(machine, 0,
  32. pid);
  33. char comm[64];
  34. if (thread == NULL)
  35. return -ENOMEM;
  36. snprintf(comm, sizeof(comm), "[guest/%d]", pid);
  37. thread__set_comm(thread, comm, 0);
  38. }
  39. return 0;
  40. }
  41. struct machine *machine__new_host(void)
  42. {
  43. struct machine *machine = malloc(sizeof(*machine));
  44. if (machine != NULL) {
  45. machine__init(machine, "", HOST_KERNEL_ID);
  46. if (machine__create_kernel_maps(machine) < 0)
  47. goto out_delete;
  48. }
  49. return machine;
  50. out_delete:
  51. free(machine);
  52. return NULL;
  53. }
  54. static void dsos__delete(struct list_head *dsos)
  55. {
  56. struct dso *pos, *n;
  57. list_for_each_entry_safe(pos, n, dsos, node) {
  58. list_del(&pos->node);
  59. dso__delete(pos);
  60. }
  61. }
  62. void machine__delete_dead_threads(struct machine *machine)
  63. {
  64. struct thread *n, *t;
  65. list_for_each_entry_safe(t, n, &machine->dead_threads, node) {
  66. list_del(&t->node);
  67. thread__delete(t);
  68. }
  69. }
  70. void machine__delete_threads(struct machine *machine)
  71. {
  72. struct rb_node *nd = rb_first(&machine->threads);
  73. while (nd) {
  74. struct thread *t = rb_entry(nd, struct thread, rb_node);
  75. rb_erase(&t->rb_node, &machine->threads);
  76. nd = rb_next(nd);
  77. thread__delete(t);
  78. }
  79. }
  80. void machine__exit(struct machine *machine)
  81. {
  82. map_groups__exit(&machine->kmaps);
  83. dsos__delete(&machine->user_dsos);
  84. dsos__delete(&machine->kernel_dsos);
  85. zfree(&machine->root_dir);
  86. }
  87. void machine__delete(struct machine *machine)
  88. {
  89. machine__exit(machine);
  90. free(machine);
  91. }
  92. void machines__init(struct machines *machines)
  93. {
  94. machine__init(&machines->host, "", HOST_KERNEL_ID);
  95. machines->guests = RB_ROOT;
  96. machines->symbol_filter = NULL;
  97. }
  98. void machines__exit(struct machines *machines)
  99. {
  100. machine__exit(&machines->host);
  101. /* XXX exit guest */
  102. }
  103. struct machine *machines__add(struct machines *machines, pid_t pid,
  104. const char *root_dir)
  105. {
  106. struct rb_node **p = &machines->guests.rb_node;
  107. struct rb_node *parent = NULL;
  108. struct machine *pos, *machine = malloc(sizeof(*machine));
  109. if (machine == NULL)
  110. return NULL;
  111. if (machine__init(machine, root_dir, pid) != 0) {
  112. free(machine);
  113. return NULL;
  114. }
  115. machine->symbol_filter = machines->symbol_filter;
  116. while (*p != NULL) {
  117. parent = *p;
  118. pos = rb_entry(parent, struct machine, rb_node);
  119. if (pid < pos->pid)
  120. p = &(*p)->rb_left;
  121. else
  122. p = &(*p)->rb_right;
  123. }
  124. rb_link_node(&machine->rb_node, parent, p);
  125. rb_insert_color(&machine->rb_node, &machines->guests);
  126. return machine;
  127. }
  128. void machines__set_symbol_filter(struct machines *machines,
  129. symbol_filter_t symbol_filter)
  130. {
  131. struct rb_node *nd;
  132. machines->symbol_filter = symbol_filter;
  133. machines->host.symbol_filter = symbol_filter;
  134. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  135. struct machine *machine = rb_entry(nd, struct machine, rb_node);
  136. machine->symbol_filter = symbol_filter;
  137. }
  138. }
  139. struct machine *machines__find(struct machines *machines, pid_t pid)
  140. {
  141. struct rb_node **p = &machines->guests.rb_node;
  142. struct rb_node *parent = NULL;
  143. struct machine *machine;
  144. struct machine *default_machine = NULL;
  145. if (pid == HOST_KERNEL_ID)
  146. return &machines->host;
  147. while (*p != NULL) {
  148. parent = *p;
  149. machine = rb_entry(parent, struct machine, rb_node);
  150. if (pid < machine->pid)
  151. p = &(*p)->rb_left;
  152. else if (pid > machine->pid)
  153. p = &(*p)->rb_right;
  154. else
  155. return machine;
  156. if (!machine->pid)
  157. default_machine = machine;
  158. }
  159. return default_machine;
  160. }
  161. struct machine *machines__findnew(struct machines *machines, pid_t pid)
  162. {
  163. char path[PATH_MAX];
  164. const char *root_dir = "";
  165. struct machine *machine = machines__find(machines, pid);
  166. if (machine && (machine->pid == pid))
  167. goto out;
  168. if ((pid != HOST_KERNEL_ID) &&
  169. (pid != DEFAULT_GUEST_KERNEL_ID) &&
  170. (symbol_conf.guestmount)) {
  171. sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
  172. if (access(path, R_OK)) {
  173. static struct strlist *seen;
  174. if (!seen)
  175. seen = strlist__new(true, NULL);
  176. if (!strlist__has_entry(seen, path)) {
  177. pr_err("Can't access file %s\n", path);
  178. strlist__add(seen, path);
  179. }
  180. machine = NULL;
  181. goto out;
  182. }
  183. root_dir = path;
  184. }
  185. machine = machines__add(machines, pid, root_dir);
  186. out:
  187. return machine;
  188. }
  189. void machines__process_guests(struct machines *machines,
  190. machine__process_t process, void *data)
  191. {
  192. struct rb_node *nd;
  193. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  194. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  195. process(pos, data);
  196. }
  197. }
  198. char *machine__mmap_name(struct machine *machine, char *bf, size_t size)
  199. {
  200. if (machine__is_host(machine))
  201. snprintf(bf, size, "[%s]", "kernel.kallsyms");
  202. else if (machine__is_default_guest(machine))
  203. snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
  204. else {
  205. snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms",
  206. machine->pid);
  207. }
  208. return bf;
  209. }
  210. void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size)
  211. {
  212. struct rb_node *node;
  213. struct machine *machine;
  214. machines->host.id_hdr_size = id_hdr_size;
  215. for (node = rb_first(&machines->guests); node; node = rb_next(node)) {
  216. machine = rb_entry(node, struct machine, rb_node);
  217. machine->id_hdr_size = id_hdr_size;
  218. }
  219. return;
  220. }
  221. static struct thread *__machine__findnew_thread(struct machine *machine,
  222. pid_t pid, pid_t tid,
  223. bool create)
  224. {
  225. struct rb_node **p = &machine->threads.rb_node;
  226. struct rb_node *parent = NULL;
  227. struct thread *th;
  228. /*
  229. * Front-end cache - TID lookups come in blocks,
  230. * so most of the time we dont have to look up
  231. * the full rbtree:
  232. */
  233. if (machine->last_match && machine->last_match->tid == tid) {
  234. if (pid && pid != machine->last_match->pid_)
  235. machine->last_match->pid_ = pid;
  236. return machine->last_match;
  237. }
  238. while (*p != NULL) {
  239. parent = *p;
  240. th = rb_entry(parent, struct thread, rb_node);
  241. if (th->tid == tid) {
  242. machine->last_match = th;
  243. if (pid && pid != th->pid_)
  244. th->pid_ = pid;
  245. return th;
  246. }
  247. if (tid < th->tid)
  248. p = &(*p)->rb_left;
  249. else
  250. p = &(*p)->rb_right;
  251. }
  252. if (!create)
  253. return NULL;
  254. th = thread__new(pid, tid);
  255. if (th != NULL) {
  256. rb_link_node(&th->rb_node, parent, p);
  257. rb_insert_color(&th->rb_node, &machine->threads);
  258. machine->last_match = th;
  259. }
  260. return th;
  261. }
  262. struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
  263. pid_t tid)
  264. {
  265. return __machine__findnew_thread(machine, pid, tid, true);
  266. }
  267. struct thread *machine__find_thread(struct machine *machine, pid_t pid,
  268. pid_t tid)
  269. {
  270. return __machine__findnew_thread(machine, pid, tid, false);
  271. }
  272. int machine__process_comm_event(struct machine *machine, union perf_event *event,
  273. struct perf_sample *sample)
  274. {
  275. struct thread *thread = machine__findnew_thread(machine,
  276. event->comm.pid,
  277. event->comm.tid);
  278. if (dump_trace)
  279. perf_event__fprintf_comm(event, stdout);
  280. if (thread == NULL || thread__set_comm(thread, event->comm.comm, sample->time)) {
  281. dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
  282. return -1;
  283. }
  284. return 0;
  285. }
  286. int machine__process_lost_event(struct machine *machine __maybe_unused,
  287. union perf_event *event, struct perf_sample *sample __maybe_unused)
  288. {
  289. dump_printf(": id:%" PRIu64 ": lost:%" PRIu64 "\n",
  290. event->lost.id, event->lost.lost);
  291. return 0;
  292. }
  293. struct map *machine__new_module(struct machine *machine, u64 start,
  294. const char *filename)
  295. {
  296. struct map *map;
  297. struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename);
  298. if (dso == NULL)
  299. return NULL;
  300. map = map__new2(start, dso, MAP__FUNCTION);
  301. if (map == NULL)
  302. return NULL;
  303. if (machine__is_host(machine))
  304. dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
  305. else
  306. dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
  307. map_groups__insert(&machine->kmaps, map);
  308. return map;
  309. }
  310. size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
  311. {
  312. struct rb_node *nd;
  313. size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) +
  314. __dsos__fprintf(&machines->host.user_dsos, fp);
  315. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  316. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  317. ret += __dsos__fprintf(&pos->kernel_dsos, fp);
  318. ret += __dsos__fprintf(&pos->user_dsos, fp);
  319. }
  320. return ret;
  321. }
  322. size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
  323. bool (skip)(struct dso *dso, int parm), int parm)
  324. {
  325. return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) +
  326. __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
  327. }
  328. size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
  329. bool (skip)(struct dso *dso, int parm), int parm)
  330. {
  331. struct rb_node *nd;
  332. size_t ret = machine__fprintf_dsos_buildid(&machines->host, fp, skip, parm);
  333. for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
  334. struct machine *pos = rb_entry(nd, struct machine, rb_node);
  335. ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm);
  336. }
  337. return ret;
  338. }
  339. size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp)
  340. {
  341. int i;
  342. size_t printed = 0;
  343. struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;
  344. if (kdso->has_build_id) {
  345. char filename[PATH_MAX];
  346. if (dso__build_id_filename(kdso, filename, sizeof(filename)))
  347. printed += fprintf(fp, "[0] %s\n", filename);
  348. }
  349. for (i = 0; i < vmlinux_path__nr_entries; ++i)
  350. printed += fprintf(fp, "[%d] %s\n",
  351. i + kdso->has_build_id, vmlinux_path[i]);
  352. return printed;
  353. }
  354. size_t machine__fprintf(struct machine *machine, FILE *fp)
  355. {
  356. size_t ret = 0;
  357. struct rb_node *nd;
  358. for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
  359. struct thread *pos = rb_entry(nd, struct thread, rb_node);
  360. ret += thread__fprintf(pos, fp);
  361. }
  362. return ret;
  363. }
  364. static struct dso *machine__get_kernel(struct machine *machine)
  365. {
  366. const char *vmlinux_name = NULL;
  367. struct dso *kernel;
  368. if (machine__is_host(machine)) {
  369. vmlinux_name = symbol_conf.vmlinux_name;
  370. if (!vmlinux_name)
  371. vmlinux_name = "[kernel.kallsyms]";
  372. kernel = dso__kernel_findnew(machine, vmlinux_name,
  373. "[kernel]",
  374. DSO_TYPE_KERNEL);
  375. } else {
  376. char bf[PATH_MAX];
  377. if (machine__is_default_guest(machine))
  378. vmlinux_name = symbol_conf.default_guest_vmlinux_name;
  379. if (!vmlinux_name)
  380. vmlinux_name = machine__mmap_name(machine, bf,
  381. sizeof(bf));
  382. kernel = dso__kernel_findnew(machine, vmlinux_name,
  383. "[guest.kernel]",
  384. DSO_TYPE_GUEST_KERNEL);
  385. }
  386. if (kernel != NULL && (!kernel->has_build_id))
  387. dso__read_running_kernel_build_id(kernel, machine);
  388. return kernel;
  389. }
  390. struct process_args {
  391. u64 start;
  392. };
  393. static int symbol__in_kernel(void *arg, const char *name,
  394. char type __maybe_unused, u64 start)
  395. {
  396. struct process_args *args = arg;
  397. if (strchr(name, '['))
  398. return 0;
  399. args->start = start;
  400. return 1;
  401. }
  402. static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
  403. size_t bufsz)
  404. {
  405. if (machine__is_default_guest(machine))
  406. scnprintf(buf, bufsz, "%s", symbol_conf.default_guest_kallsyms);
  407. else
  408. scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
  409. }
  410. /* Figure out the start address of kernel map from /proc/kallsyms */
  411. static u64 machine__get_kernel_start_addr(struct machine *machine)
  412. {
  413. char filename[PATH_MAX];
  414. struct process_args args;
  415. machine__get_kallsyms_filename(machine, filename, PATH_MAX);
  416. if (symbol__restricted_filename(filename, "/proc/kallsyms"))
  417. return 0;
  418. if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
  419. return 0;
  420. return args.start;
  421. }
  422. int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
  423. {
  424. enum map_type type;
  425. u64 start = machine__get_kernel_start_addr(machine);
  426. for (type = 0; type < MAP__NR_TYPES; ++type) {
  427. struct kmap *kmap;
  428. machine->vmlinux_maps[type] = map__new2(start, kernel, type);
  429. if (machine->vmlinux_maps[type] == NULL)
  430. return -1;
  431. machine->vmlinux_maps[type]->map_ip =
  432. machine->vmlinux_maps[type]->unmap_ip =
  433. identity__map_ip;
  434. kmap = map__kmap(machine->vmlinux_maps[type]);
  435. kmap->kmaps = &machine->kmaps;
  436. map_groups__insert(&machine->kmaps,
  437. machine->vmlinux_maps[type]);
  438. }
  439. return 0;
  440. }
  441. void machine__destroy_kernel_maps(struct machine *machine)
  442. {
  443. enum map_type type;
  444. for (type = 0; type < MAP__NR_TYPES; ++type) {
  445. struct kmap *kmap;
  446. if (machine->vmlinux_maps[type] == NULL)
  447. continue;
  448. kmap = map__kmap(machine->vmlinux_maps[type]);
  449. map_groups__remove(&machine->kmaps,
  450. machine->vmlinux_maps[type]);
  451. if (kmap->ref_reloc_sym) {
  452. /*
  453. * ref_reloc_sym is shared among all maps, so free just
  454. * on one of them.
  455. */
  456. if (type == MAP__FUNCTION) {
  457. zfree((char **)&kmap->ref_reloc_sym->name);
  458. zfree(&kmap->ref_reloc_sym);
  459. } else
  460. kmap->ref_reloc_sym = NULL;
  461. }
  462. map__delete(machine->vmlinux_maps[type]);
  463. machine->vmlinux_maps[type] = NULL;
  464. }
  465. }
  466. int machines__create_guest_kernel_maps(struct machines *machines)
  467. {
  468. int ret = 0;
  469. struct dirent **namelist = NULL;
  470. int i, items = 0;
  471. char path[PATH_MAX];
  472. pid_t pid;
  473. char *endp;
  474. if (symbol_conf.default_guest_vmlinux_name ||
  475. symbol_conf.default_guest_modules ||
  476. symbol_conf.default_guest_kallsyms) {
  477. machines__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
  478. }
  479. if (symbol_conf.guestmount) {
  480. items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
  481. if (items <= 0)
  482. return -ENOENT;
  483. for (i = 0; i < items; i++) {
  484. if (!isdigit(namelist[i]->d_name[0])) {
  485. /* Filter out . and .. */
  486. continue;
  487. }
  488. pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
  489. if ((*endp != '\0') ||
  490. (endp == namelist[i]->d_name) ||
  491. (errno == ERANGE)) {
  492. pr_debug("invalid directory (%s). Skipping.\n",
  493. namelist[i]->d_name);
  494. continue;
  495. }
  496. sprintf(path, "%s/%s/proc/kallsyms",
  497. symbol_conf.guestmount,
  498. namelist[i]->d_name);
  499. ret = access(path, R_OK);
  500. if (ret) {
  501. pr_debug("Can't access file %s\n", path);
  502. goto failure;
  503. }
  504. machines__create_kernel_maps(machines, pid);
  505. }
  506. failure:
  507. free(namelist);
  508. }
  509. return ret;
  510. }
  511. void machines__destroy_kernel_maps(struct machines *machines)
  512. {
  513. struct rb_node *next = rb_first(&machines->guests);
  514. machine__destroy_kernel_maps(&machines->host);
  515. while (next) {
  516. struct machine *pos = rb_entry(next, struct machine, rb_node);
  517. next = rb_next(&pos->rb_node);
  518. rb_erase(&pos->rb_node, &machines->guests);
  519. machine__delete(pos);
  520. }
  521. }
  522. int machines__create_kernel_maps(struct machines *machines, pid_t pid)
  523. {
  524. struct machine *machine = machines__findnew(machines, pid);
  525. if (machine == NULL)
  526. return -1;
  527. return machine__create_kernel_maps(machine);
  528. }
  529. int machine__load_kallsyms(struct machine *machine, const char *filename,
  530. enum map_type type, symbol_filter_t filter)
  531. {
  532. struct map *map = machine->vmlinux_maps[type];
  533. int ret = dso__load_kallsyms(map->dso, filename, map, filter);
  534. if (ret > 0) {
  535. dso__set_loaded(map->dso, type);
  536. /*
  537. * Since /proc/kallsyms will have multiple sessions for the
  538. * kernel, with modules between them, fixup the end of all
  539. * sections.
  540. */
  541. __map_groups__fixup_end(&machine->kmaps, type);
  542. }
  543. return ret;
  544. }
  545. int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
  546. symbol_filter_t filter)
  547. {
  548. struct map *map = machine->vmlinux_maps[type];
  549. int ret = dso__load_vmlinux_path(map->dso, map, filter);
  550. if (ret > 0)
  551. dso__set_loaded(map->dso, type);
  552. return ret;
  553. }
  554. static void map_groups__fixup_end(struct map_groups *mg)
  555. {
  556. int i;
  557. for (i = 0; i < MAP__NR_TYPES; ++i)
  558. __map_groups__fixup_end(mg, i);
  559. }
  560. static char *get_kernel_version(const char *root_dir)
  561. {
  562. char version[PATH_MAX];
  563. FILE *file;
  564. char *name, *tmp;
  565. const char *prefix = "Linux version ";
  566. sprintf(version, "%s/proc/version", root_dir);
  567. file = fopen(version, "r");
  568. if (!file)
  569. return NULL;
  570. version[0] = '\0';
  571. tmp = fgets(version, sizeof(version), file);
  572. fclose(file);
  573. name = strstr(version, prefix);
  574. if (!name)
  575. return NULL;
  576. name += strlen(prefix);
  577. tmp = strchr(name, ' ');
  578. if (tmp)
  579. *tmp = '\0';
  580. return strdup(name);
  581. }
  582. static int map_groups__set_modules_path_dir(struct map_groups *mg,
  583. const char *dir_name, int depth)
  584. {
  585. struct dirent *dent;
  586. DIR *dir = opendir(dir_name);
  587. int ret = 0;
  588. if (!dir) {
  589. pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
  590. return -1;
  591. }
  592. while ((dent = readdir(dir)) != NULL) {
  593. char path[PATH_MAX];
  594. struct stat st;
  595. /*sshfs might return bad dent->d_type, so we have to stat*/
  596. snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
  597. if (stat(path, &st))
  598. continue;
  599. if (S_ISDIR(st.st_mode)) {
  600. if (!strcmp(dent->d_name, ".") ||
  601. !strcmp(dent->d_name, ".."))
  602. continue;
  603. /* Do not follow top-level source and build symlinks */
  604. if (depth == 0) {
  605. if (!strcmp(dent->d_name, "source") ||
  606. !strcmp(dent->d_name, "build"))
  607. continue;
  608. }
  609. ret = map_groups__set_modules_path_dir(mg, path,
  610. depth + 1);
  611. if (ret < 0)
  612. goto out;
  613. } else {
  614. char *dot = strrchr(dent->d_name, '.'),
  615. dso_name[PATH_MAX];
  616. struct map *map;
  617. char *long_name;
  618. if (dot == NULL || strcmp(dot, ".ko"))
  619. continue;
  620. snprintf(dso_name, sizeof(dso_name), "[%.*s]",
  621. (int)(dot - dent->d_name), dent->d_name);
  622. strxfrchar(dso_name, '-', '_');
  623. map = map_groups__find_by_name(mg, MAP__FUNCTION,
  624. dso_name);
  625. if (map == NULL)
  626. continue;
  627. long_name = strdup(path);
  628. if (long_name == NULL) {
  629. ret = -1;
  630. goto out;
  631. }
  632. dso__set_long_name(map->dso, long_name, true);
  633. dso__kernel_module_get_build_id(map->dso, "");
  634. }
  635. }
  636. out:
  637. closedir(dir);
  638. return ret;
  639. }
  640. static int machine__set_modules_path(struct machine *machine)
  641. {
  642. char *version;
  643. char modules_path[PATH_MAX];
  644. version = get_kernel_version(machine->root_dir);
  645. if (!version)
  646. return -1;
  647. snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s",
  648. machine->root_dir, version);
  649. free(version);
  650. return map_groups__set_modules_path_dir(&machine->kmaps, modules_path, 0);
  651. }
  652. static int machine__create_module(void *arg, const char *name, u64 start)
  653. {
  654. struct machine *machine = arg;
  655. struct map *map;
  656. map = machine__new_module(machine, start, name);
  657. if (map == NULL)
  658. return -1;
  659. dso__kernel_module_get_build_id(map->dso, machine->root_dir);
  660. return 0;
  661. }
  662. static int machine__create_modules(struct machine *machine)
  663. {
  664. const char *modules;
  665. char path[PATH_MAX];
  666. if (machine__is_default_guest(machine)) {
  667. modules = symbol_conf.default_guest_modules;
  668. } else {
  669. snprintf(path, PATH_MAX, "%s/proc/modules", machine->root_dir);
  670. modules = path;
  671. }
  672. if (symbol__restricted_filename(modules, "/proc/modules"))
  673. return -1;
  674. if (modules__parse(modules, machine, machine__create_module))
  675. return -1;
  676. if (!machine__set_modules_path(machine))
  677. return 0;
  678. pr_debug("Problems setting modules path maps, continuing anyway...\n");
  679. return 0;
  680. }
  681. const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
  682. int machine__create_kernel_maps(struct machine *machine)
  683. {
  684. struct dso *kernel = machine__get_kernel(machine);
  685. char filename[PATH_MAX];
  686. const char *name;
  687. u64 addr = 0;
  688. int i;
  689. machine__get_kallsyms_filename(machine, filename, PATH_MAX);
  690. for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
  691. addr = kallsyms__get_function_start(filename, name);
  692. if (addr)
  693. break;
  694. }
  695. if (!addr)
  696. return -1;
  697. if (kernel == NULL ||
  698. __machine__create_kernel_maps(machine, kernel) < 0)
  699. return -1;
  700. if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
  701. if (machine__is_host(machine))
  702. pr_debug("Problems creating module maps, "
  703. "continuing anyway...\n");
  704. else
  705. pr_debug("Problems creating module maps for guest %d, "
  706. "continuing anyway...\n", machine->pid);
  707. }
  708. /*
  709. * Now that we have all the maps created, just set the ->end of them:
  710. */
  711. map_groups__fixup_end(&machine->kmaps);
  712. if (maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, name,
  713. addr)) {
  714. machine__destroy_kernel_maps(machine);
  715. return -1;
  716. }
  717. return 0;
  718. }
  719. static void machine__set_kernel_mmap_len(struct machine *machine,
  720. union perf_event *event)
  721. {
  722. int i;
  723. for (i = 0; i < MAP__NR_TYPES; i++) {
  724. machine->vmlinux_maps[i]->start = event->mmap.start;
  725. machine->vmlinux_maps[i]->end = (event->mmap.start +
  726. event->mmap.len);
  727. /*
  728. * Be a bit paranoid here, some perf.data file came with
  729. * a zero sized synthesized MMAP event for the kernel.
  730. */
  731. if (machine->vmlinux_maps[i]->end == 0)
  732. machine->vmlinux_maps[i]->end = ~0ULL;
  733. }
  734. }
  735. static bool machine__uses_kcore(struct machine *machine)
  736. {
  737. struct dso *dso;
  738. list_for_each_entry(dso, &machine->kernel_dsos, node) {
  739. if (dso__is_kcore(dso))
  740. return true;
  741. }
  742. return false;
  743. }
  744. static int machine__process_kernel_mmap_event(struct machine *machine,
  745. union perf_event *event)
  746. {
  747. struct map *map;
  748. char kmmap_prefix[PATH_MAX];
  749. enum dso_kernel_type kernel_type;
  750. bool is_kernel_mmap;
  751. /* If we have maps from kcore then we do not need or want any others */
  752. if (machine__uses_kcore(machine))
  753. return 0;
  754. machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
  755. if (machine__is_host(machine))
  756. kernel_type = DSO_TYPE_KERNEL;
  757. else
  758. kernel_type = DSO_TYPE_GUEST_KERNEL;
  759. is_kernel_mmap = memcmp(event->mmap.filename,
  760. kmmap_prefix,
  761. strlen(kmmap_prefix) - 1) == 0;
  762. if (event->mmap.filename[0] == '/' ||
  763. (!is_kernel_mmap && event->mmap.filename[0] == '[')) {
  764. char short_module_name[1024];
  765. char *name, *dot;
  766. if (event->mmap.filename[0] == '/') {
  767. name = strrchr(event->mmap.filename, '/');
  768. if (name == NULL)
  769. goto out_problem;
  770. ++name; /* skip / */
  771. dot = strrchr(name, '.');
  772. if (dot == NULL)
  773. goto out_problem;
  774. snprintf(short_module_name, sizeof(short_module_name),
  775. "[%.*s]", (int)(dot - name), name);
  776. strxfrchar(short_module_name, '-', '_');
  777. } else
  778. strcpy(short_module_name, event->mmap.filename);
  779. map = machine__new_module(machine, event->mmap.start,
  780. event->mmap.filename);
  781. if (map == NULL)
  782. goto out_problem;
  783. name = strdup(short_module_name);
  784. if (name == NULL)
  785. goto out_problem;
  786. dso__set_short_name(map->dso, name, true);
  787. map->end = map->start + event->mmap.len;
  788. } else if (is_kernel_mmap) {
  789. const char *symbol_name = (event->mmap.filename +
  790. strlen(kmmap_prefix));
  791. /*
  792. * Should be there already, from the build-id table in
  793. * the header.
  794. */
  795. struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
  796. kmmap_prefix);
  797. if (kernel == NULL)
  798. goto out_problem;
  799. kernel->kernel = kernel_type;
  800. if (__machine__create_kernel_maps(machine, kernel) < 0)
  801. goto out_problem;
  802. machine__set_kernel_mmap_len(machine, event);
  803. /*
  804. * Avoid using a zero address (kptr_restrict) for the ref reloc
  805. * symbol. Effectively having zero here means that at record
  806. * time /proc/sys/kernel/kptr_restrict was non zero.
  807. */
  808. if (event->mmap.pgoff != 0) {
  809. maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
  810. symbol_name,
  811. event->mmap.pgoff);
  812. }
  813. if (machine__is_default_guest(machine)) {
  814. /*
  815. * preload dso of guest kernel and modules
  816. */
  817. dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
  818. NULL);
  819. }
  820. }
  821. return 0;
  822. out_problem:
  823. return -1;
  824. }
  825. int machine__process_mmap2_event(struct machine *machine,
  826. union perf_event *event,
  827. struct perf_sample *sample __maybe_unused)
  828. {
  829. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  830. struct thread *thread;
  831. struct map *map;
  832. enum map_type type;
  833. int ret = 0;
  834. if (dump_trace)
  835. perf_event__fprintf_mmap2(event, stdout);
  836. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  837. cpumode == PERF_RECORD_MISC_KERNEL) {
  838. ret = machine__process_kernel_mmap_event(machine, event);
  839. if (ret < 0)
  840. goto out_problem;
  841. return 0;
  842. }
  843. thread = machine__findnew_thread(machine, event->mmap2.pid,
  844. event->mmap2.tid);
  845. if (thread == NULL)
  846. goto out_problem;
  847. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  848. type = MAP__VARIABLE;
  849. else
  850. type = MAP__FUNCTION;
  851. map = map__new(&machine->user_dsos, event->mmap2.start,
  852. event->mmap2.len, event->mmap2.pgoff,
  853. event->mmap2.pid, event->mmap2.maj,
  854. event->mmap2.min, event->mmap2.ino,
  855. event->mmap2.ino_generation,
  856. event->mmap2.filename, type);
  857. if (map == NULL)
  858. goto out_problem;
  859. thread__insert_map(thread, map);
  860. return 0;
  861. out_problem:
  862. dump_printf("problem processing PERF_RECORD_MMAP2, skipping event.\n");
  863. return 0;
  864. }
  865. int machine__process_mmap_event(struct machine *machine, union perf_event *event,
  866. struct perf_sample *sample __maybe_unused)
  867. {
  868. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  869. struct thread *thread;
  870. struct map *map;
  871. enum map_type type;
  872. int ret = 0;
  873. if (dump_trace)
  874. perf_event__fprintf_mmap(event, stdout);
  875. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  876. cpumode == PERF_RECORD_MISC_KERNEL) {
  877. ret = machine__process_kernel_mmap_event(machine, event);
  878. if (ret < 0)
  879. goto out_problem;
  880. return 0;
  881. }
  882. thread = machine__findnew_thread(machine, event->mmap.pid,
  883. event->mmap.tid);
  884. if (thread == NULL)
  885. goto out_problem;
  886. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  887. type = MAP__VARIABLE;
  888. else
  889. type = MAP__FUNCTION;
  890. map = map__new(&machine->user_dsos, event->mmap.start,
  891. event->mmap.len, event->mmap.pgoff,
  892. event->mmap.pid, 0, 0, 0, 0,
  893. event->mmap.filename,
  894. type);
  895. if (map == NULL)
  896. goto out_problem;
  897. thread__insert_map(thread, map);
  898. return 0;
  899. out_problem:
  900. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  901. return 0;
  902. }
  903. static void machine__remove_thread(struct machine *machine, struct thread *th)
  904. {
  905. machine->last_match = NULL;
  906. rb_erase(&th->rb_node, &machine->threads);
  907. /*
  908. * We may have references to this thread, for instance in some hist_entry
  909. * instances, so just move them to a separate list.
  910. */
  911. list_add_tail(&th->node, &machine->dead_threads);
  912. }
  913. int machine__process_fork_event(struct machine *machine, union perf_event *event,
  914. struct perf_sample *sample)
  915. {
  916. struct thread *thread = machine__find_thread(machine,
  917. event->fork.pid,
  918. event->fork.tid);
  919. struct thread *parent = machine__findnew_thread(machine,
  920. event->fork.ppid,
  921. event->fork.ptid);
  922. /* if a thread currently exists for the thread id remove it */
  923. if (thread != NULL)
  924. machine__remove_thread(machine, thread);
  925. thread = machine__findnew_thread(machine, event->fork.pid,
  926. event->fork.tid);
  927. if (dump_trace)
  928. perf_event__fprintf_task(event, stdout);
  929. if (thread == NULL || parent == NULL ||
  930. thread__fork(thread, parent, sample->time) < 0) {
  931. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  932. return -1;
  933. }
  934. return 0;
  935. }
  936. int machine__process_exit_event(struct machine *machine, union perf_event *event,
  937. struct perf_sample *sample __maybe_unused)
  938. {
  939. struct thread *thread = machine__find_thread(machine,
  940. event->fork.pid,
  941. event->fork.tid);
  942. if (dump_trace)
  943. perf_event__fprintf_task(event, stdout);
  944. if (thread != NULL)
  945. thread__exited(thread);
  946. return 0;
  947. }
  948. int machine__process_event(struct machine *machine, union perf_event *event,
  949. struct perf_sample *sample)
  950. {
  951. int ret;
  952. switch (event->header.type) {
  953. case PERF_RECORD_COMM:
  954. ret = machine__process_comm_event(machine, event, sample); break;
  955. case PERF_RECORD_MMAP:
  956. ret = machine__process_mmap_event(machine, event, sample); break;
  957. case PERF_RECORD_MMAP2:
  958. ret = machine__process_mmap2_event(machine, event, sample); break;
  959. case PERF_RECORD_FORK:
  960. ret = machine__process_fork_event(machine, event, sample); break;
  961. case PERF_RECORD_EXIT:
  962. ret = machine__process_exit_event(machine, event, sample); break;
  963. case PERF_RECORD_LOST:
  964. ret = machine__process_lost_event(machine, event, sample); break;
  965. default:
  966. ret = -1;
  967. break;
  968. }
  969. return ret;
  970. }
  971. static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
  972. {
  973. if (sym->name && !regexec(regex, sym->name, 0, NULL, 0))
  974. return 1;
  975. return 0;
  976. }
  977. static void ip__resolve_ams(struct machine *machine, struct thread *thread,
  978. struct addr_map_symbol *ams,
  979. u64 ip)
  980. {
  981. struct addr_location al;
  982. memset(&al, 0, sizeof(al));
  983. /*
  984. * We cannot use the header.misc hint to determine whether a
  985. * branch stack address is user, kernel, guest, hypervisor.
  986. * Branches may straddle the kernel/user/hypervisor boundaries.
  987. * Thus, we have to try consecutively until we find a match
  988. * or else, the symbol is unknown
  989. */
  990. thread__find_cpumode_addr_location(thread, machine, MAP__FUNCTION, ip, &al);
  991. ams->addr = ip;
  992. ams->al_addr = al.addr;
  993. ams->sym = al.sym;
  994. ams->map = al.map;
  995. }
  996. static void ip__resolve_data(struct machine *machine, struct thread *thread,
  997. u8 m, struct addr_map_symbol *ams, u64 addr)
  998. {
  999. struct addr_location al;
  1000. memset(&al, 0, sizeof(al));
  1001. thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr,
  1002. &al);
  1003. ams->addr = addr;
  1004. ams->al_addr = al.addr;
  1005. ams->sym = al.sym;
  1006. ams->map = al.map;
  1007. }
  1008. struct mem_info *sample__resolve_mem(struct perf_sample *sample,
  1009. struct addr_location *al)
  1010. {
  1011. struct mem_info *mi = zalloc(sizeof(*mi));
  1012. if (!mi)
  1013. return NULL;
  1014. ip__resolve_ams(al->machine, al->thread, &mi->iaddr, sample->ip);
  1015. ip__resolve_data(al->machine, al->thread, al->cpumode,
  1016. &mi->daddr, sample->addr);
  1017. mi->data_src.val = sample->data_src;
  1018. return mi;
  1019. }
  1020. struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
  1021. struct addr_location *al)
  1022. {
  1023. unsigned int i;
  1024. const struct branch_stack *bs = sample->branch_stack;
  1025. struct branch_info *bi = calloc(bs->nr, sizeof(struct branch_info));
  1026. if (!bi)
  1027. return NULL;
  1028. for (i = 0; i < bs->nr; i++) {
  1029. ip__resolve_ams(al->machine, al->thread, &bi[i].to, bs->entries[i].to);
  1030. ip__resolve_ams(al->machine, al->thread, &bi[i].from, bs->entries[i].from);
  1031. bi[i].flags = bs->entries[i].flags;
  1032. }
  1033. return bi;
  1034. }
  1035. static int machine__resolve_callchain_sample(struct machine *machine,
  1036. struct thread *thread,
  1037. struct ip_callchain *chain,
  1038. struct symbol **parent,
  1039. struct addr_location *root_al,
  1040. int max_stack)
  1041. {
  1042. u8 cpumode = PERF_RECORD_MISC_USER;
  1043. int chain_nr = min(max_stack, (int)chain->nr);
  1044. int i;
  1045. int err;
  1046. callchain_cursor_reset(&callchain_cursor);
  1047. if (chain->nr > PERF_MAX_STACK_DEPTH) {
  1048. pr_warning("corrupted callchain. skipping...\n");
  1049. return 0;
  1050. }
  1051. for (i = 0; i < chain_nr; i++) {
  1052. u64 ip;
  1053. struct addr_location al;
  1054. if (callchain_param.order == ORDER_CALLEE)
  1055. ip = chain->ips[i];
  1056. else
  1057. ip = chain->ips[chain->nr - i - 1];
  1058. if (ip >= PERF_CONTEXT_MAX) {
  1059. switch (ip) {
  1060. case PERF_CONTEXT_HV:
  1061. cpumode = PERF_RECORD_MISC_HYPERVISOR;
  1062. break;
  1063. case PERF_CONTEXT_KERNEL:
  1064. cpumode = PERF_RECORD_MISC_KERNEL;
  1065. break;
  1066. case PERF_CONTEXT_USER:
  1067. cpumode = PERF_RECORD_MISC_USER;
  1068. break;
  1069. default:
  1070. pr_debug("invalid callchain context: "
  1071. "%"PRId64"\n", (s64) ip);
  1072. /*
  1073. * It seems the callchain is corrupted.
  1074. * Discard all.
  1075. */
  1076. callchain_cursor_reset(&callchain_cursor);
  1077. return 0;
  1078. }
  1079. continue;
  1080. }
  1081. al.filtered = 0;
  1082. thread__find_addr_location(thread, machine, cpumode,
  1083. MAP__FUNCTION, ip, &al);
  1084. if (al.sym != NULL) {
  1085. if (sort__has_parent && !*parent &&
  1086. symbol__match_regex(al.sym, &parent_regex))
  1087. *parent = al.sym;
  1088. else if (have_ignore_callees && root_al &&
  1089. symbol__match_regex(al.sym, &ignore_callees_regex)) {
  1090. /* Treat this symbol as the root,
  1091. forgetting its callees. */
  1092. *root_al = al;
  1093. callchain_cursor_reset(&callchain_cursor);
  1094. }
  1095. }
  1096. err = callchain_cursor_append(&callchain_cursor,
  1097. ip, al.map, al.sym);
  1098. if (err)
  1099. return err;
  1100. }
  1101. return 0;
  1102. }
  1103. static int unwind_entry(struct unwind_entry *entry, void *arg)
  1104. {
  1105. struct callchain_cursor *cursor = arg;
  1106. return callchain_cursor_append(cursor, entry->ip,
  1107. entry->map, entry->sym);
  1108. }
  1109. int machine__resolve_callchain(struct machine *machine,
  1110. struct perf_evsel *evsel,
  1111. struct thread *thread,
  1112. struct perf_sample *sample,
  1113. struct symbol **parent,
  1114. struct addr_location *root_al,
  1115. int max_stack)
  1116. {
  1117. int ret;
  1118. ret = machine__resolve_callchain_sample(machine, thread,
  1119. sample->callchain, parent,
  1120. root_al, max_stack);
  1121. if (ret)
  1122. return ret;
  1123. /* Can we do dwarf post unwind? */
  1124. if (!((evsel->attr.sample_type & PERF_SAMPLE_REGS_USER) &&
  1125. (evsel->attr.sample_type & PERF_SAMPLE_STACK_USER)))
  1126. return 0;
  1127. /* Bail out if nothing was captured. */
  1128. if ((!sample->user_regs.regs) ||
  1129. (!sample->user_stack.size))
  1130. return 0;
  1131. return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
  1132. thread, sample, max_stack);
  1133. }
  1134. int machine__for_each_thread(struct machine *machine,
  1135. int (*fn)(struct thread *thread, void *p),
  1136. void *priv)
  1137. {
  1138. struct rb_node *nd;
  1139. struct thread *thread;
  1140. int rc = 0;
  1141. for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
  1142. thread = rb_entry(nd, struct thread, rb_node);
  1143. rc = fn(thread, priv);
  1144. if (rc != 0)
  1145. return rc;
  1146. }
  1147. list_for_each_entry(thread, &machine->dead_threads, node) {
  1148. rc = fn(thread, priv);
  1149. if (rc != 0)
  1150. return rc;
  1151. }
  1152. return rc;
  1153. }
  1154. int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
  1155. struct target *target, struct thread_map *threads,
  1156. perf_event__handler_t process, bool data_mmap)
  1157. {
  1158. if (target__has_task(target))
  1159. return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap);
  1160. else if (target__has_cpu(target))
  1161. return perf_event__synthesize_threads(tool, process, machine, data_mmap);
  1162. /* command specified */
  1163. return 0;
  1164. }