Lines Matching full:gs

1030 static struct guest_vcpu *guest_session__vcpu(struct guest_session *gs, u32 vcpu)  in guest_session__vcpu()  argument
1032 if (realloc_array_as_needed(gs->vcpu, gs->vcpu_cnt, vcpu, NULL)) in guest_session__vcpu()
1034 return &gs->vcpu[vcpu]; in guest_session__vcpu()
1037 static int guest_session__output_bytes(struct guest_session *gs, void *buf, size_t sz) in guest_session__output_bytes() argument
1039 ssize_t ret = writen(gs->tmp_fd, buf, sz); in guest_session__output_bytes()
1049 struct guest_session *gs = container_of(tool, struct guest_session, tool); in guest_session__repipe() local
1051 return guest_session__output_bytes(gs, event, event->header.size); in guest_session__repipe()
1054 static int guest_session__map_tid(struct guest_session *gs, u32 tid, u32 vcpu) in guest_session__map_tid() argument
1065 hlist_add_head(&guest_tid->node, &gs->tids[hash]); in guest_session__map_tid()
1074 struct guest_session *gs = data; in host_peek_vm_comms_cb() local
1080 event->comm.pid != gs->machine_pid) in host_peek_vm_comms_cb()
1097 guest_vcpu = guest_session__vcpu(gs, vcpu); in host_peek_vm_comms_cb()
1106 return guest_session__map_tid(gs, event->comm.tid, vcpu); in host_peek_vm_comms_cb()
1109 static int host_peek_vm_comms(struct perf_session *session, struct guest_session *gs) in host_peek_vm_comms() argument
1113 host_peek_vm_comms_cb, gs); in host_peek_vm_comms()
1121 static u64 guest_session__allocate_new_id(struct guest_session *gs, struct evlist *host_evlist) in guest_session__allocate_new_id() argument
1124 gs->highest_id += 1; in guest_session__allocate_new_id()
1125 } while (!gs->highest_id || evlist__is_id_used(host_evlist, gs->highest_id)); in guest_session__allocate_new_id()
1127 return gs->highest_id; in guest_session__allocate_new_id()
1130 static int guest_session__map_id(struct guest_session *gs, u64 id, u64 host_id, u32 vcpu) in guest_session__map_id() argument
1142 hlist_add_head(&guest_id->node, &gs->heads[hash]); in guest_session__map_id()
1166 static int guest_session__map_ids(struct guest_session *gs, struct evlist *host_evlist) in guest_session__map_ids() argument
1168 struct evlist *evlist = gs->session->evlist; in guest_session__map_ids()
1184 host_id = guest_session__allocate_new_id(gs, host_evlist); in guest_session__map_ids()
1185 ret = guest_session__map_id(gs, id, host_id, sid->cpu.cpu); in guest_session__map_ids()
1194 static struct guest_id *guest_session__lookup_id(struct guest_session *gs, u64 id) in guest_session__lookup_id() argument
1201 head = &gs->heads[hash]; in guest_session__lookup_id()
1219 static int guest_session__add_attr(struct guest_session *gs, struct evsel *evsel) in guest_session__add_attr() argument
1221 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__add_attr()
1238 struct guest_id *guest_id = guest_session__lookup_id(gs, id); in guest_session__add_attr()
1265 sid->tid = gs->vcpu[vcpu].tid; in guest_session__add_attr()
1266 sid->machine_pid = gs->machine_pid; in guest_session__add_attr()
1275 static int guest_session__add_attrs(struct guest_session *gs) in guest_session__add_attrs() argument
1277 struct evlist *evlist = gs->session->evlist; in guest_session__add_attrs()
1282 ret = guest_session__add_attr(gs, evsel); in guest_session__add_attrs()
1301 static struct guest_tid *guest_session__lookup_tid(struct guest_session *gs, u32 tid) in guest_session__lookup_tid() argument
1308 head = &gs->tids[hash]; in guest_session__lookup_tid()
1376 struct guest_session *gs = data; in guest_session__add_build_ids_cb() local
1377 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__add_build_ids_cb()
1382 return synthesize_build_id(inject, dso, gs->machine_pid); in guest_session__add_build_ids_cb()
1386 static int guest_session__add_build_ids(struct guest_session *gs) in guest_session__add_build_ids() argument
1388 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__add_build_ids()
1393 return dsos__for_each_dso(&gs->session->machines.host.dsos, in guest_session__add_build_ids()
1395 gs); in guest_session__add_build_ids()
1403 struct guest_session *gs = container_of(tool, struct guest_session, tool); in guest_session__ksymbol_event() local
1409 return guest_session__output_bytes(gs, event, event->header.size); in guest_session__ksymbol_event()
1412 static int guest_session__start(struct guest_session *gs, const char *name, bool force) in guest_session__start() argument
1419 gs->tool.mmap = guest_session__repipe; in guest_session__start()
1420 gs->tool.mmap2 = guest_session__repipe; in guest_session__start()
1421 gs->tool.comm = guest_session__repipe; in guest_session__start()
1422 gs->tool.fork = guest_session__repipe; in guest_session__start()
1423 gs->tool.exit = guest_session__repipe; in guest_session__start()
1424 gs->tool.lost = guest_session__repipe; in guest_session__start()
1425 gs->tool.context_switch = guest_session__repipe; in guest_session__start()
1426 gs->tool.ksymbol = guest_session__ksymbol_event; in guest_session__start()
1427 gs->tool.text_poke = guest_session__repipe; in guest_session__start()
1434 gs->tool.build_id = perf_event__process_build_id; in guest_session__start()
1436 gs->tool.id_index = perf_event__process_id_index; in guest_session__start()
1438 gs->tool.ordered_events = true; in guest_session__start()
1439 gs->tool.ordering_requires_timestamps = true; in guest_session__start()
1441 gs->data.path = name; in guest_session__start()
1442 gs->data.force = force; in guest_session__start()
1443 gs->data.mode = PERF_DATA_MODE_READ; in guest_session__start()
1445 session = perf_session__new(&gs->data, &gs->tool); in guest_session__start()
1448 gs->session = session; in guest_session__start()
1454 gs->dflt_id_hdr_size = session->machines.host.id_hdr_size; in guest_session__start()
1456 gs->dflt_id = evlist__first_id(session->evlist); in guest_session__start()
1457 if (!gs->dflt_id) { in guest_session__start()
1463 gs->tmp_file_name = strdup(tmp_file_name); in guest_session__start()
1464 if (!gs->tmp_file_name) in guest_session__start()
1466 gs->tmp_fd = mkstemp(gs->tmp_file_name); in guest_session__start()
1467 if (gs->tmp_fd < 0) in guest_session__start()
1470 if (zstd_init(&gs->session->zstd_data, 0) < 0) in guest_session__start()
1477 ret = perf_session__process_events(gs->session); in guest_session__start()
1481 if (lseek(gs->tmp_fd, 0, SEEK_SET)) in guest_session__start()
1501 static void guest_session__exit(struct guest_session *gs) in guest_session__exit() argument
1503 if (gs->session) { in guest_session__exit()
1504 perf_session__delete(gs->session); in guest_session__exit()
1505 free_hlist(gs->heads, PERF_EVLIST__HLIST_SIZE); in guest_session__exit()
1506 free_hlist(gs->tids, PERF_EVLIST__HLIST_SIZE); in guest_session__exit()
1508 if (gs->tmp_file_name) { in guest_session__exit()
1509 if (gs->tmp_fd >= 0) in guest_session__exit()
1510 close(gs->tmp_fd); in guest_session__exit()
1511 unlink(gs->tmp_file_name); in guest_session__exit()
1512 zfree(&gs->tmp_file_name); in guest_session__exit()
1514 zfree(&gs->vcpu); in guest_session__exit()
1515 zfree(&gs->perf_data_file); in guest_session__exit()
1529 static void guest_session__get_tc(struct guest_session *gs) in guest_session__get_tc() argument
1531 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__get_tc()
1533 get_tsc_conv(&gs->host_tc, &inject->session->time_conv); in guest_session__get_tc()
1534 get_tsc_conv(&gs->guest_tc, &gs->session->time_conv); in guest_session__get_tc()
1537 static void guest_session__convert_time(struct guest_session *gs, u64 guest_time, u64 *host_time) in guest_session__convert_time() argument
1546 if (gs->guest_tc.cap_user_time_zero) in guest_session__convert_time()
1547 tsc = perf_time_to_tsc(guest_time, &gs->guest_tc); in guest_session__convert_time()
1555 tsc -= gs->time_offset; in guest_session__convert_time()
1556 tsc /= gs->time_scale; in guest_session__convert_time()
1558 if (gs->host_tc.cap_user_time_zero) in guest_session__convert_time()
1559 *host_time = tsc_to_perf_time(tsc, &gs->host_tc); in guest_session__convert_time()
1564 static int guest_session__fetch(struct guest_session *gs) in guest_session__fetch() argument
1571 buf = gs->ev.event_buf; in guest_session__fetch()
1576 gs->ev.event_buf = buf; in guest_session__fetch()
1579 ret = readn(gs->tmp_fd, buf, hdr_sz); in guest_session__fetch()
1591 ret = readn(gs->tmp_fd, buf, hdr->size - hdr_sz); in guest_session__fetch()
1595 gs->ev.event = (union perf_event *)gs->ev.event_buf; in guest_session__fetch()
1596 gs->ev.sample.time = 0; in guest_session__fetch()
1603 ret = evlist__parse_sample(gs->session->evlist, gs->ev.event, &gs->ev.sample); in guest_session__fetch()
1609 if (!gs->have_tc) { in guest_session__fetch()
1610 guest_session__get_tc(gs); in guest_session__fetch()
1611 gs->have_tc = true; in guest_session__fetch()
1614 guest_session__convert_time(gs, gs->ev.sample.time, &gs->ev.sample.time); in guest_session__fetch()
1649 static int guest_session__inject_events(struct guest_session *gs, u64 timestamp) in guest_session__inject_events() argument
1651 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__inject_events()
1654 if (!gs->ready) in guest_session__inject_events()
1665 if (!gs->fetched) { in guest_session__inject_events()
1666 ret = guest_session__fetch(gs); in guest_session__inject_events()
1669 gs->fetched = true; in guest_session__inject_events()
1672 ev = gs->ev.event; in guest_session__inject_events()
1673 sample = &gs->ev.sample; in guest_session__inject_events()
1692 id = gs->dflt_id; in guest_session__inject_events()
1693 id_hdr_size = gs->dflt_id_hdr_size; in guest_session__inject_events()
1695 struct evsel *evsel = evlist__id2evsel(gs->session->evlist, id); in guest_session__inject_events()
1718 guest_id = guest_session__lookup_id(gs, id); in guest_session__inject_events()
1730 if (sample->cpu >= gs->vcpu_cnt) { in guest_session__inject_events()
1736 sample->cpu = gs->vcpu[sample->cpu].cpu; in guest_session__inject_events()
1749 gs->fetched = false; in guest_session__inject_events()
1757 static int guest_session__flush_events(struct guest_session *gs) in guest_session__flush_events() argument
1759 return guest_session__inject_events(gs, -1); in guest_session__flush_events()
1780 struct guest_session *gs = &inject->guest_session; in host__finished_init() local
1787 ret = host_peek_vm_comms(session, gs); in host__finished_init()
1791 if (!gs->vcpu_cnt) { in host__finished_init()
1792 pr_err("No VCPU threads found for pid %u\n", gs->machine_pid); in host__finished_init()
1799 gs->highest_id = evlist__find_highest_id(session->evlist); in host__finished_init()
1800 ret = guest_session__map_ids(gs, session->evlist); in host__finished_init()
1804 ret = guest_session__add_attrs(gs); in host__finished_init()
1808 ret = synthesize_id_index(inject, gs->session->evlist->core.nr_entries); in host__finished_init()
1814 ret = guest_session__add_build_ids(gs); in host__finished_init()
1820 gs->ready = true; in host__finished_init()
1822 ret = guest_session__inject_events(gs, 0); in host__finished_init()
1860 struct guest_session *gs = &inject->guest_session; in host__context_switch() local
1866 if (out || pid != gs->machine_pid) in host__context_switch()
1869 guest_tid = guest_session__lookup_tid(gs, tid); in host__context_switch()
1879 if (vcpu >= gs->vcpu_cnt) in host__context_switch()
1883 gs->vcpu[vcpu].cpu = sample->cpu; in host__context_switch()
1960 struct guest_session *gs = &inject->guest_session; in parse_guest_data() local
1974 gs->perf_data_file = strsep(&s, ","); in parse_guest_data()
1975 if (!gs->perf_data_file) in parse_guest_data()
1978 gs->copy_kcore_dir = has_kcore_dir(gs->perf_data_file); in parse_guest_data()
1979 if (gs->copy_kcore_dir) in parse_guest_data()
1985 gs->machine_pid = strtoul(tok, NULL, 0); in parse_guest_data()
1989 gs->time_scale = 1; in parse_guest_data()
1994 gs->time_offset = strtoull(tok, NULL, 0); in parse_guest_data()
1999 gs->time_scale = strtod(tok, NULL); in parse_guest_data()
2000 if (!gs->time_scale) in parse_guest_data()
2141 static int guest_session__copy_kcore_dir(struct guest_session *gs) in guest_session__copy_kcore_dir() argument
2143 struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session); in guest_session__copy_kcore_dir()
2148 gs->perf_data_file, inject->output.path, gs->machine_pid); in guest_session__copy_kcore_dir()
2165 struct guest_session *gs = &inject->guest_session; in __cmd_inject() local
2236 } else if (gs->perf_data_file) { in __cmd_inject()
2237 char *name = gs->perf_data_file; in __cmd_inject()
2269 ret = guest_session__start(gs, name, session->data->force); in __cmd_inject()
2275 output_data_offset += gs->session->header.data_offset; in __cmd_inject()
2289 if (gs->session) { in __cmd_inject()
2294 ret = guest_session__flush_events(gs); in __cmd_inject()
2341 if (gs->copy_kcore_dir) { in __cmd_inject()
2342 ret = guest_session__copy_kcore_dir(gs); in __cmd_inject()