Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf session: Create guest machines from id_index

Now that id_index has machine_pid, use it to create guest machines.
Create the guest machines with an idle thread because guest events
for "swapper" will be possible.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: kvm@vger.kernel.org
Link: https://lore.kernel.org/r/20220711093218.10967-12-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
ff7a78c2 b47bb186

+31
+31
tools/perf/util/session.c
··· 2751 2751 fprintf(fp, "# ========\n#\n"); 2752 2752 } 2753 2753 2754 + static int perf_session__register_guest(struct perf_session *session, pid_t machine_pid) 2755 + { 2756 + struct machine *machine = machines__findnew(&session->machines, machine_pid); 2757 + struct thread *thread; 2758 + 2759 + if (!machine) 2760 + return -ENOMEM; 2761 + 2762 + machine->single_address_space = session->machines.host.single_address_space; 2763 + 2764 + thread = machine__idle_thread(machine); 2765 + if (!thread) 2766 + return -ENOMEM; 2767 + thread__put(thread); 2768 + 2769 + return 0; 2770 + } 2771 + 2754 2772 int perf_event__process_id_index(struct perf_session *session, 2755 2773 union perf_event *event) 2756 2774 { ··· 2780 2762 size_t e2_sz = sizeof(struct id_index_entry_2); 2781 2763 size_t etot_sz = e1_sz + e2_sz; 2782 2764 struct id_index_entry_2 *e2; 2765 + pid_t last_pid = 0; 2783 2766 2784 2767 max_nr = sz / e1_sz; 2785 2768 nr = ie->nr; ··· 2806 2787 for (i = 0; i < nr; i++, (e2 ? e2++ : 0)) { 2807 2788 struct id_index_entry *e = &ie->entries[i]; 2808 2789 struct perf_sample_id *sid; 2790 + int ret; 2809 2791 2810 2792 if (dump_trace) { 2811 2793 fprintf(stdout, " ... id: %"PRI_lu64, e->id); ··· 2834 2814 2835 2815 sid->machine_pid = e2->machine_pid; 2836 2816 sid->vcpu.cpu = e2->vcpu; 2817 + 2818 + if (!sid->machine_pid) 2819 + continue; 2820 + 2821 + if (sid->machine_pid != last_pid) { 2822 + ret = perf_session__register_guest(session, sid->machine_pid); 2823 + if (ret) 2824 + return ret; 2825 + last_pid = sid->machine_pid; 2826 + perf_guest = true; 2827 + } 2837 2828 } 2838 2829 return 0; 2839 2830 }