From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36788C43334 for ; Wed, 20 Jul 2022 01:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241443AbiGTBV3 (ORCPT ); Tue, 19 Jul 2022 21:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240962AbiGTBUv (ORCPT ); Tue, 19 Jul 2022 21:20:51 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B24B6559F for ; Tue, 19 Jul 2022 18:16:06 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z13so4443190wro.13 for ; Tue, 19 Jul 2022 18:16:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bW+JKCRkrraL1G5WWSlYo9qIrZupPzOKLmThC+fgGao=; b=eavKJoLYp39eJ+OuLSSa1CvQnHWU83szgReL2+yzBxcOrUywcl3h9xNSztKN1YTc2J DuKheVv6jMqkdsu0iRSZi8nop2iOZcz27X3YuO8o6CxKmTw9TEuqxvE9yJ+pJNie9sFu SZx1wgnKG5c6ZULFGPBqzJxpOj7El+Fh679ZiAnawNJ472eEuXjETaa6zI4h80qUGmnL YXlFPzq3r6eg2WO8AHe/vI6FlyN2wrWHiNlleF2hEd8ZbcYCV9IHaA3ah9sSdpc98wt5 TenaDC8QOoRuTLpJnPus2WKtb2DhsPVWTDfJZgfg4meBlkGFdcR3xrW9w4oZyKwD0sGy z9Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bW+JKCRkrraL1G5WWSlYo9qIrZupPzOKLmThC+fgGao=; b=k0jqIoX0bs8+I/+FuSH6CnOGgNGhvNpJihYJ0RtKuYXMYzRTzTLtj3dK/BUihL9Hrl bArA+XX30hzqMsgYtypz3HEylvQhTAEOi/zwS8d2vao6a4MBPVf3Fi+ZowkS6HqgvGvG 5eesAOFEuFKwYOpUEwG0s1wS3Q2Yn3fBPHWCpOHeNuIM3To5dvgjKxGHjggfpfqukyNG cUUpbt1RBx2EFuYVQYPShdlzSLhgZiva9qXNNK1dp7Cis51WmzwDvbPVSgwIOuiciDkG th5KAqUy1j67kripFcIEpvmPUAhNdi1B3ZUKxk7gZt4pYC5RS1n/4sfSrCmOX4j3GxpO aCmw== X-Gm-Message-State: AJIora+BXE8ivFiLPFWSXBaFS8twMyd/sxg1EPZONohRKWKN/9pXNCw2 TzHz3RCFml/Fj9WsX4dZuNosuhvshJ9ISy3Y8G3Dbg== X-Google-Smtp-Source: AGRyM1vT8gdog19dsLbf908GQkADJf3t9ZiSnp1ex3lEChjSSJCdKA8Da8yefYrfZkwRdvoLOl3IgFVQA6Zw1hKgctw= X-Received: by 2002:a5d:4d92:0:b0:21d:6f02:d971 with SMTP id b18-20020a5d4d92000000b0021d6f02d971mr27852330wru.300.1658279764042; Tue, 19 Jul 2022 18:16:04 -0700 (PDT) MIME-Version: 1.0 References: <20220711093218.10967-1-adrian.hunter@intel.com> <20220711093218.10967-33-adrian.hunter@intel.com> In-Reply-To: <20220711093218.10967-33-adrian.hunter@intel.com> From: Ian Rogers Date: Tue, 19 Jul 2022 18:15:52 -0700 Message-ID: Subject: Re: [PATCH 32/35] perf intel-pt: Determine guest thread from guest sideband To: Adrian Hunter Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 11, 2022 at 2:34 AM Adrian Hunter wrote: > > Prior to decoding, determine what guest thread, if any, is running. > > Signed-off-by: Adrian Hunter Acked-by: Ian Rogers Thanks, Ian > --- > tools/perf/util/intel-pt.c | 69 ++++++++++++++++++++++++++++++++++++-- > 1 file changed, 67 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c > index dc2af64f9e31..a08c2f059d5a 100644 > --- a/tools/perf/util/intel-pt.c > +++ b/tools/perf/util/intel-pt.c > @@ -196,6 +196,10 @@ struct intel_pt_queue { > struct machine *guest_machine; > struct thread *guest_thread; > struct thread *unknown_guest_thread; > + pid_t guest_machine_pid; > + pid_t guest_pid; > + pid_t guest_tid; > + int vcpu; > bool exclude_kernel; > bool have_sample; > u64 time; > @@ -759,8 +763,13 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn, > cpumode = intel_pt_nr_cpumode(ptq, *ip, nr); > > if (nr) { > - if ((!symbol_conf.guest_code && cpumode != PERF_RECORD_MISC_GUEST_KERNEL) || > - intel_pt_get_guest(ptq)) { > + if (ptq->pt->have_guest_sideband) { > + if (!ptq->guest_machine || ptq->guest_machine_pid != ptq->pid) { > + intel_pt_log("ERROR: guest sideband but no guest machine\n"); > + return -EINVAL; > + } > + } else if ((!symbol_conf.guest_code && cpumode != PERF_RECORD_MISC_GUEST_KERNEL) || > + intel_pt_get_guest(ptq)) { > intel_pt_log("ERROR: no guest machine\n"); > return -EINVAL; > } > @@ -1385,6 +1394,55 @@ static void intel_pt_first_timestamp(struct intel_pt *pt, u64 timestamp) > } > } > > +static int intel_pt_get_guest_from_sideband(struct intel_pt_queue *ptq) > +{ > + struct machines *machines = &ptq->pt->session->machines; > + struct machine *machine; > + pid_t machine_pid = ptq->pid; > + pid_t tid; > + int vcpu; > + > + if (machine_pid <= 0) > + return 0; /* Not a guest machine */ > + > + machine = machines__find(machines, machine_pid); > + if (!machine) > + return 0; /* Not a guest machine */ > + > + if (ptq->guest_machine != machine) { > + ptq->guest_machine = NULL; > + thread__zput(ptq->guest_thread); > + thread__zput(ptq->unknown_guest_thread); > + > + ptq->unknown_guest_thread = machine__find_thread(machine, 0, 0); > + if (!ptq->unknown_guest_thread) > + return -1; > + ptq->guest_machine = machine; > + } > + > + vcpu = ptq->thread ? ptq->thread->guest_cpu : -1; > + if (vcpu < 0) > + return -1; > + > + tid = machine__get_current_tid(machine, vcpu); > + > + if (ptq->guest_thread && ptq->guest_thread->tid != tid) > + thread__zput(ptq->guest_thread); > + > + if (!ptq->guest_thread) { > + ptq->guest_thread = machine__find_thread(machine, -1, tid); > + if (!ptq->guest_thread) > + return -1; > + } > + > + ptq->guest_machine_pid = machine_pid; > + ptq->guest_pid = ptq->guest_thread->pid_; > + ptq->guest_tid = tid; > + ptq->vcpu = vcpu; > + > + return 0; > +} > + > static void intel_pt_set_pid_tid_cpu(struct intel_pt *pt, > struct auxtrace_queue *queue) > { > @@ -1405,6 +1463,13 @@ static void intel_pt_set_pid_tid_cpu(struct intel_pt *pt, > if (queue->cpu == -1) > ptq->cpu = ptq->thread->cpu; > } > + > + if (pt->have_guest_sideband && intel_pt_get_guest_from_sideband(ptq)) { > + ptq->guest_machine_pid = 0; > + ptq->guest_pid = -1; > + ptq->guest_tid = -1; > + ptq->vcpu = -1; > + } > } > > static void intel_pt_sample_flags(struct intel_pt_queue *ptq) > -- > 2.25.1 >