machine.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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)
  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. ret = map_groups__set_modules_path_dir(mg, path);
  604. if (ret < 0)
  605. goto out;
  606. } else {
  607. char *dot = strrchr(dent->d_name, '.'),
  608. dso_name[PATH_MAX];
  609. struct map *map;
  610. char *long_name;
  611. if (dot == NULL || strcmp(dot, ".ko"))
  612. continue;
  613. snprintf(dso_name, sizeof(dso_name), "[%.*s]",
  614. (int)(dot - dent->d_name), dent->d_name);
  615. strxfrchar(dso_name, '-', '_');
  616. map = map_groups__find_by_name(mg, MAP__FUNCTION,
  617. dso_name);
  618. if (map == NULL)
  619. continue;
  620. long_name = strdup(path);
  621. if (long_name == NULL) {
  622. ret = -1;
  623. goto out;
  624. }
  625. dso__set_long_name(map->dso, long_name, true);
  626. dso__kernel_module_get_build_id(map->dso, "");
  627. }
  628. }
  629. out:
  630. closedir(dir);
  631. return ret;
  632. }
  633. static int machine__set_modules_path(struct machine *machine)
  634. {
  635. char *version;
  636. char modules_path[PATH_MAX];
  637. version = get_kernel_version(machine->root_dir);
  638. if (!version)
  639. return -1;
  640. snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
  641. machine->root_dir, version);
  642. free(version);
  643. return map_groups__set_modules_path_dir(&machine->kmaps, modules_path);
  644. }
  645. static int machine__create_module(void *arg, const char *name, u64 start)
  646. {
  647. struct machine *machine = arg;
  648. struct map *map;
  649. map = machine__new_module(machine, start, name);
  650. if (map == NULL)
  651. return -1;
  652. dso__kernel_module_get_build_id(map->dso, machine->root_dir);
  653. return 0;
  654. }
  655. static int machine__create_modules(struct machine *machine)
  656. {
  657. const char *modules;
  658. char path[PATH_MAX];
  659. if (machine__is_default_guest(machine)) {
  660. modules = symbol_conf.default_guest_modules;
  661. } else {
  662. snprintf(path, PATH_MAX, "%s/proc/modules", machine->root_dir);
  663. modules = path;
  664. }
  665. if (symbol__restricted_filename(modules, "/proc/modules"))
  666. return -1;
  667. if (modules__parse(modules, machine, machine__create_module))
  668. return -1;
  669. if (!machine__set_modules_path(machine))
  670. return 0;
  671. pr_debug("Problems setting modules path maps, continuing anyway...\n");
  672. return 0;
  673. }
  674. const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
  675. int machine__create_kernel_maps(struct machine *machine)
  676. {
  677. struct dso *kernel = machine__get_kernel(machine);
  678. char filename[PATH_MAX];
  679. const char *name;
  680. u64 addr = 0;
  681. int i;
  682. machine__get_kallsyms_filename(machine, filename, PATH_MAX);
  683. for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
  684. addr = kallsyms__get_function_start(filename, name);
  685. if (addr)
  686. break;
  687. }
  688. if (!addr)
  689. return -1;
  690. if (kernel == NULL ||
  691. __machine__create_kernel_maps(machine, kernel) < 0)
  692. return -1;
  693. if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
  694. if (machine__is_host(machine))
  695. pr_debug("Problems creating module maps, "
  696. "continuing anyway...\n");
  697. else
  698. pr_debug("Problems creating module maps for guest %d, "
  699. "continuing anyway...\n", machine->pid);
  700. }
  701. /*
  702. * Now that we have all the maps created, just set the ->end of them:
  703. */
  704. map_groups__fixup_end(&machine->kmaps);
  705. if (maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, name,
  706. addr)) {
  707. machine__destroy_kernel_maps(machine);
  708. return -1;
  709. }
  710. return 0;
  711. }
  712. static void machine__set_kernel_mmap_len(struct machine *machine,
  713. union perf_event *event)
  714. {
  715. int i;
  716. for (i = 0; i < MAP__NR_TYPES; i++) {
  717. machine->vmlinux_maps[i]->start = event->mmap.start;
  718. machine->vmlinux_maps[i]->end = (event->mmap.start +
  719. event->mmap.len);
  720. /*
  721. * Be a bit paranoid here, some perf.data file came with
  722. * a zero sized synthesized MMAP event for the kernel.
  723. */
  724. if (machine->vmlinux_maps[i]->end == 0)
  725. machine->vmlinux_maps[i]->end = ~0ULL;
  726. }
  727. }
  728. static bool machine__uses_kcore(struct machine *machine)
  729. {
  730. struct dso *dso;
  731. list_for_each_entry(dso, &machine->kernel_dsos, node) {
  732. if (dso__is_kcore(dso))
  733. return true;
  734. }
  735. return false;
  736. }
  737. static int machine__process_kernel_mmap_event(struct machine *machine,
  738. union perf_event *event)
  739. {
  740. struct map *map;
  741. char kmmap_prefix[PATH_MAX];
  742. enum dso_kernel_type kernel_type;
  743. bool is_kernel_mmap;
  744. /* If we have maps from kcore then we do not need or want any others */
  745. if (machine__uses_kcore(machine))
  746. return 0;
  747. machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
  748. if (machine__is_host(machine))
  749. kernel_type = DSO_TYPE_KERNEL;
  750. else
  751. kernel_type = DSO_TYPE_GUEST_KERNEL;
  752. is_kernel_mmap = memcmp(event->mmap.filename,
  753. kmmap_prefix,
  754. strlen(kmmap_prefix) - 1) == 0;
  755. if (event->mmap.filename[0] == '/' ||
  756. (!is_kernel_mmap && event->mmap.filename[0] == '[')) {
  757. char short_module_name[1024];
  758. char *name, *dot;
  759. if (event->mmap.filename[0] == '/') {
  760. name = strrchr(event->mmap.filename, '/');
  761. if (name == NULL)
  762. goto out_problem;
  763. ++name; /* skip / */
  764. dot = strrchr(name, '.');
  765. if (dot == NULL)
  766. goto out_problem;
  767. snprintf(short_module_name, sizeof(short_module_name),
  768. "[%.*s]", (int)(dot - name), name);
  769. strxfrchar(short_module_name, '-', '_');
  770. } else
  771. strcpy(short_module_name, event->mmap.filename);
  772. map = machine__new_module(machine, event->mmap.start,
  773. event->mmap.filename);
  774. if (map == NULL)
  775. goto out_problem;
  776. name = strdup(short_module_name);
  777. if (name == NULL)
  778. goto out_problem;
  779. dso__set_short_name(map->dso, name, true);
  780. map->end = map->start + event->mmap.len;
  781. } else if (is_kernel_mmap) {
  782. const char *symbol_name = (event->mmap.filename +
  783. strlen(kmmap_prefix));
  784. /*
  785. * Should be there already, from the build-id table in
  786. * the header.
  787. */
  788. struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
  789. kmmap_prefix);
  790. if (kernel == NULL)
  791. goto out_problem;
  792. kernel->kernel = kernel_type;
  793. if (__machine__create_kernel_maps(machine, kernel) < 0)
  794. goto out_problem;
  795. machine__set_kernel_mmap_len(machine, event);
  796. /*
  797. * Avoid using a zero address (kptr_restrict) for the ref reloc
  798. * symbol. Effectively having zero here means that at record
  799. * time /proc/sys/kernel/kptr_restrict was non zero.
  800. */
  801. if (event->mmap.pgoff != 0) {
  802. maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
  803. symbol_name,
  804. event->mmap.pgoff);
  805. }
  806. if (machine__is_default_guest(machine)) {
  807. /*
  808. * preload dso of guest kernel and modules
  809. */
  810. dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
  811. NULL);
  812. }
  813. }
  814. return 0;
  815. out_problem:
  816. return -1;
  817. }
  818. int machine__process_mmap2_event(struct machine *machine,
  819. union perf_event *event,
  820. struct perf_sample *sample __maybe_unused)
  821. {
  822. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  823. struct thread *thread;
  824. struct map *map;
  825. enum map_type type;
  826. int ret = 0;
  827. if (dump_trace)
  828. perf_event__fprintf_mmap2(event, stdout);
  829. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  830. cpumode == PERF_RECORD_MISC_KERNEL) {
  831. ret = machine__process_kernel_mmap_event(machine, event);
  832. if (ret < 0)
  833. goto out_problem;
  834. return 0;
  835. }
  836. thread = machine__findnew_thread(machine, event->mmap2.pid,
  837. event->mmap2.tid);
  838. if (thread == NULL)
  839. goto out_problem;
  840. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  841. type = MAP__VARIABLE;
  842. else
  843. type = MAP__FUNCTION;
  844. map = map__new(&machine->user_dsos, event->mmap2.start,
  845. event->mmap2.len, event->mmap2.pgoff,
  846. event->mmap2.pid, event->mmap2.maj,
  847. event->mmap2.min, event->mmap2.ino,
  848. event->mmap2.ino_generation,
  849. event->mmap2.filename, type);
  850. if (map == NULL)
  851. goto out_problem;
  852. thread__insert_map(thread, map);
  853. return 0;
  854. out_problem:
  855. dump_printf("problem processing PERF_RECORD_MMAP2, skipping event.\n");
  856. return 0;
  857. }
  858. int machine__process_mmap_event(struct machine *machine, union perf_event *event,
  859. struct perf_sample *sample __maybe_unused)
  860. {
  861. u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  862. struct thread *thread;
  863. struct map *map;
  864. enum map_type type;
  865. int ret = 0;
  866. if (dump_trace)
  867. perf_event__fprintf_mmap(event, stdout);
  868. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  869. cpumode == PERF_RECORD_MISC_KERNEL) {
  870. ret = machine__process_kernel_mmap_event(machine, event);
  871. if (ret < 0)
  872. goto out_problem;
  873. return 0;
  874. }
  875. thread = machine__findnew_thread(machine, event->mmap.pid,
  876. event->mmap.tid);
  877. if (thread == NULL)
  878. goto out_problem;
  879. if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
  880. type = MAP__VARIABLE;
  881. else
  882. type = MAP__FUNCTION;
  883. map = map__new(&machine->user_dsos, event->mmap.start,
  884. event->mmap.len, event->mmap.pgoff,
  885. event->mmap.pid, 0, 0, 0, 0,
  886. event->mmap.filename,
  887. type);
  888. if (map == NULL)
  889. goto out_problem;
  890. thread__insert_map(thread, map);
  891. return 0;
  892. out_problem:
  893. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  894. return 0;
  895. }
  896. static void machine__remove_thread(struct machine *machine, struct thread *th)
  897. {
  898. machine->last_match = NULL;
  899. rb_erase(&th->rb_node, &machine->threads);
  900. /*
  901. * We may have references to this thread, for instance in some hist_entry
  902. * instances, so just move them to a separate list.
  903. */
  904. list_add_tail(&th->node, &machine->dead_threads);
  905. }
  906. int machine__process_fork_event(struct machine *machine, union perf_event *event,
  907. struct perf_sample *sample)
  908. {
  909. struct thread *thread = machine__find_thread(machine,
  910. event->fork.pid,
  911. event->fork.tid);
  912. struct thread *parent = machine__findnew_thread(machine,
  913. event->fork.ppid,
  914. event->fork.ptid);
  915. /* if a thread currently exists for the thread id remove it */
  916. if (thread != NULL)
  917. machine__remove_thread(machine, thread);
  918. thread = machine__findnew_thread(machine, event->fork.pid,
  919. event->fork.tid);
  920. if (dump_trace)
  921. perf_event__fprintf_task(event, stdout);
  922. if (thread == NULL || parent == NULL ||
  923. thread__fork(thread, parent, sample->time) < 0) {
  924. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  925. return -1;
  926. }
  927. return 0;
  928. }
  929. int machine__process_exit_event(struct machine *machine, union perf_event *event,
  930. struct perf_sample *sample __maybe_unused)
  931. {
  932. struct thread *thread = machine__find_thread(machine,
  933. event->fork.pid,
  934. event->fork.tid);
  935. if (dump_trace)
  936. perf_event__fprintf_task(event, stdout);
  937. if (thread != NULL)
  938. thread__exited(thread);
  939. return 0;
  940. }
  941. int machine__process_event(struct machine *machine, union perf_event *event,
  942. struct perf_sample *sample)
  943. {
  944. int ret;
  945. switch (event->header.type) {
  946. case PERF_RECORD_COMM:
  947. ret = machine__process_comm_event(machine, event, sample); break;
  948. case PERF_RECORD_MMAP:
  949. ret = machine__process_mmap_event(machine, event, sample); break;
  950. case PERF_RECORD_MMAP2:
  951. ret = machine__process_mmap2_event(machine, event, sample); break;
  952. case PERF_RECORD_FORK:
  953. ret = machine__process_fork_event(machine, event, sample); break;
  954. case PERF_RECORD_EXIT:
  955. ret = machine__process_exit_event(machine, event, sample); break;
  956. case PERF_RECORD_LOST:
  957. ret = machine__process_lost_event(machine, event, sample); break;
  958. default:
  959. ret = -1;
  960. break;
  961. }
  962. return ret;
  963. }
  964. static bool symbol__match_regex(struct symbol *sym, regex_t *regex)
  965. {
  966. if (sym->name && !regexec(regex, sym->name, 0, NULL, 0))
  967. return 1;
  968. return 0;
  969. }
  970. static void ip__resolve_ams(struct machine *machine, struct thread *thread,
  971. struct addr_map_symbol *ams,
  972. u64 ip)
  973. {
  974. struct addr_location al;
  975. memset(&al, 0, sizeof(al));
  976. /*
  977. * We cannot use the header.misc hint to determine whether a
  978. * branch stack address is user, kernel, guest, hypervisor.
  979. * Branches may straddle the kernel/user/hypervisor boundaries.
  980. * Thus, we have to try consecutively until we find a match
  981. * or else, the symbol is unknown
  982. */
  983. thread__find_cpumode_addr_location(thread, machine, MAP__FUNCTION, ip, &al);
  984. ams->addr = ip;
  985. ams->al_addr = al.addr;
  986. ams->sym = al.sym;
  987. ams->map = al.map;
  988. }
  989. static void ip__resolve_data(struct machine *machine, struct thread *thread,
  990. u8 m, struct addr_map_symbol *ams, u64 addr)
  991. {
  992. struct addr_location al;
  993. memset(&al, 0, sizeof(al));
  994. thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr,
  995. &al);
  996. ams->addr = addr;
  997. ams->al_addr = al.addr;
  998. ams->sym = al.sym;
  999. ams->map = al.map;
  1000. }
  1001. struct mem_info *sample__resolve_mem(struct perf_sample *sample,
  1002. struct addr_location *al)
  1003. {
  1004. struct mem_info *mi = zalloc(sizeof(*mi));
  1005. if (!mi)
  1006. return NULL;
  1007. ip__resolve_ams(al->machine, al->thread, &mi->iaddr, sample->ip);
  1008. ip__resolve_data(al->machine, al->thread, al->cpumode,
  1009. &mi->daddr, sample->addr);
  1010. mi->data_src.val = sample->data_src;
  1011. return mi;
  1012. }
  1013. struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
  1014. struct addr_location *al)
  1015. {
  1016. unsigned int i;
  1017. const struct branch_stack *bs = sample->branch_stack;
  1018. struct branch_info *bi = calloc(bs->nr, sizeof(struct branch_info));
  1019. if (!bi)
  1020. return NULL;
  1021. for (i = 0; i < bs->nr; i++) {
  1022. ip__resolve_ams(al->machine, al->thread, &bi[i].to, bs->entries[i].to);
  1023. ip__resolve_ams(al->machine, al->thread, &bi[i].from, bs->entries[i].from);
  1024. bi[i].flags = bs->entries[i].flags;
  1025. }
  1026. return bi;
  1027. }
  1028. static int machine__resolve_callchain_sample(struct machine *machine,
  1029. struct thread *thread,
  1030. struct ip_callchain *chain,
  1031. struct symbol **parent,
  1032. struct addr_location *root_al,
  1033. int max_stack)
  1034. {
  1035. u8 cpumode = PERF_RECORD_MISC_USER;
  1036. int chain_nr = min(max_stack, (int)chain->nr);
  1037. int i;
  1038. int err;
  1039. callchain_cursor_reset(&callchain_cursor);
  1040. if (chain->nr > PERF_MAX_STACK_DEPTH) {
  1041. pr_warning("corrupted callchain. skipping...\n");
  1042. return 0;
  1043. }
  1044. for (i = 0; i < chain_nr; i++) {
  1045. u64 ip;
  1046. struct addr_location al;
  1047. if (callchain_param.order == ORDER_CALLEE)
  1048. ip = chain->ips[i];
  1049. else
  1050. ip = chain->ips[chain->nr - i - 1];
  1051. if (ip >= PERF_CONTEXT_MAX) {
  1052. switch (ip) {
  1053. case PERF_CONTEXT_HV:
  1054. cpumode = PERF_RECORD_MISC_HYPERVISOR;
  1055. break;
  1056. case PERF_CONTEXT_KERNEL:
  1057. cpumode = PERF_RECORD_MISC_KERNEL;
  1058. break;
  1059. case PERF_CONTEXT_USER:
  1060. cpumode = PERF_RECORD_MISC_USER;
  1061. break;
  1062. default:
  1063. pr_debug("invalid callchain context: "
  1064. "%"PRId64"\n", (s64) ip);
  1065. /*
  1066. * It seems the callchain is corrupted.
  1067. * Discard all.
  1068. */
  1069. callchain_cursor_reset(&callchain_cursor);
  1070. return 0;
  1071. }
  1072. continue;
  1073. }
  1074. al.filtered = 0;
  1075. thread__find_addr_location(thread, machine, cpumode,
  1076. MAP__FUNCTION, ip, &al);
  1077. if (al.sym != NULL) {
  1078. if (sort__has_parent && !*parent &&
  1079. symbol__match_regex(al.sym, &parent_regex))
  1080. *parent = al.sym;
  1081. else if (have_ignore_callees && root_al &&
  1082. symbol__match_regex(al.sym, &ignore_callees_regex)) {
  1083. /* Treat this symbol as the root,
  1084. forgetting its callees. */
  1085. *root_al = al;
  1086. callchain_cursor_reset(&callchain_cursor);
  1087. }
  1088. }
  1089. err = callchain_cursor_append(&callchain_cursor,
  1090. ip, al.map, al.sym);
  1091. if (err)
  1092. return err;
  1093. }
  1094. return 0;
  1095. }
  1096. static int unwind_entry(struct unwind_entry *entry, void *arg)
  1097. {
  1098. struct callchain_cursor *cursor = arg;
  1099. return callchain_cursor_append(cursor, entry->ip,
  1100. entry->map, entry->sym);
  1101. }
  1102. int machine__resolve_callchain(struct machine *machine,
  1103. struct perf_evsel *evsel,
  1104. struct thread *thread,
  1105. struct perf_sample *sample,
  1106. struct symbol **parent,
  1107. struct addr_location *root_al,
  1108. int max_stack)
  1109. {
  1110. int ret;
  1111. ret = machine__resolve_callchain_sample(machine, thread,
  1112. sample->callchain, parent,
  1113. root_al, max_stack);
  1114. if (ret)
  1115. return ret;
  1116. /* Can we do dwarf post unwind? */
  1117. if (!((evsel->attr.sample_type & PERF_SAMPLE_REGS_USER) &&
  1118. (evsel->attr.sample_type & PERF_SAMPLE_STACK_USER)))
  1119. return 0;
  1120. /* Bail out if nothing was captured. */
  1121. if ((!sample->user_regs.regs) ||
  1122. (!sample->user_stack.size))
  1123. return 0;
  1124. return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
  1125. thread, sample, max_stack);
  1126. }
  1127. int machine__for_each_thread(struct machine *machine,
  1128. int (*fn)(struct thread *thread, void *p),
  1129. void *priv)
  1130. {
  1131. struct rb_node *nd;
  1132. struct thread *thread;
  1133. int rc = 0;
  1134. for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) {
  1135. thread = rb_entry(nd, struct thread, rb_node);
  1136. rc = fn(thread, priv);
  1137. if (rc != 0)
  1138. return rc;
  1139. }
  1140. list_for_each_entry(thread, &machine->dead_threads, node) {
  1141. rc = fn(thread, priv);
  1142. if (rc != 0)
  1143. return rc;
  1144. }
  1145. return rc;
  1146. }
  1147. int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
  1148. struct target *target, struct thread_map *threads,
  1149. perf_event__handler_t process, bool data_mmap)
  1150. {
  1151. if (target__has_task(target))
  1152. return perf_event__synthesize_thread_map(tool, threads, process, machine, data_mmap);
  1153. else if (target__has_cpu(target))
  1154. return perf_event__synthesize_threads(tool, process, machine, data_mmap);
  1155. /* command specified */
  1156. return 0;
  1157. }