Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp646424ybz; Wed, 22 Apr 2020 05:25:14 -0700 (PDT) X-Google-Smtp-Source: APiQypIDVuqd6lP37EDaSXFf7xZRb1Qa+sdtPY/rBIBk72bgroF5Co6fHkNkaFh18qNr4ksyuFj2 X-Received: by 2002:a05:6402:4:: with SMTP id d4mr22515070edu.344.1587558314505; Wed, 22 Apr 2020 05:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587558314; cv=none; d=google.com; s=arc-20160816; b=U7HArJUXjLkXcWPiLNZT7NpefLeENgpRmndH7g+flh6zKuuIceHGJgzppl70adjAZS 1nva6iqeqxcpfbr1GVKxT+arGOCW+MlEnWk+wLPomuvW9EoufFTpWPLN2bUHcRl+GmTW D7XalUt2NbES+n+/RUPOGkOe9Vm3sTebY2R7IZPREnnJf3dCwpjG8UFFhq93DbFC9t9v n92JdAg1dTVcVHE27d9QE5wWYb/s/kyy/hqRYm4Xx1UD4qIxJYjA5j8dJVbg+TZLUP1r hOCqr2wadX/hwKlKwez+QM0OXoEGnYS5qtzUQCB1p/E8blhj3eIzHQTmgNQNDeMsDf4F a/HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=B6X6vbtrDacDL4mt5N/2etf9/kLH23qH5BeOUcRQEa4=; b=MyTYnLkoeXodh5nBraJaydvc6bunDqYPwk/+ums9U+/FUTIbwxq27FiiQxfC8lEI1k 9y5gRr+36XWOfsibM/kcv+ddf5oMlByEdFz8X2vlb7gxSNxbwQEoyS7EDGxPLo5MLuLL MPvSsLrbcwnLthvEWMd203PibrIdsC8e2SAl/Mr8j3YJO0B3uADRtuZcC27yv/LgyNeN m1VS6z1Qsp25592GJjcZ8w4axGNlRp0Z/SuLf31PSq6bLXkWHDu9VIqzZPsACsW/ct9z I9/JHEO+IJ4UoAFG27Mbf0V0FeRtNAgOLx6nNKKciGGuOkR8SB9A88b01bxG5dzqkYqK Bw4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ld23si3343370ejb.242.2020.04.22.05.24.51; Wed, 22 Apr 2020 05:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728995AbgDVMSE (ORCPT + 99 others); Wed, 22 Apr 2020 08:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728716AbgDVMRk (ORCPT ); Wed, 22 Apr 2020 08:17:40 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3CDBC03C1A9; Wed, 22 Apr 2020 05:17:39 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jREJo-0007nH-6v; Wed, 22 Apr 2020 14:17:32 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 6804F1C0483; Wed, 22 Apr 2020 14:17:23 +0200 (CEST) Date: Wed, 22 Apr 2020 12:17:22 -0000 From: "tip-bot2 for Adrian Hunter" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf thread-stack: Add thread_stack__sample_late() Cc: Adrian Hunter , Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo , x86 , LKML In-Reply-To: <20200401101613.6201-10-adrian.hunter@intel.com> References: <20200401101613.6201-10-adrian.hunter@intel.com> MIME-Version: 1.0 Message-ID: <158755784297.28353.7627391855107279620.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 4fef41bfb1d8d2ada4a18eb3ab80c2682bcbae12 Gitweb: https://git.kernel.org/tip/4fef41bfb1d8d2ada4a18eb3ab80c2682bcbae12 Author: Adrian Hunter AuthorDate: Wed, 01 Apr 2020 13:16:06 +03:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Thu, 16 Apr 2020 12:19:15 -03:00 perf thread-stack: Add thread_stack__sample_late() Add a thread stack function to create a call chain for hardware events where the sample records get created some time after the event occurred. Signed-off-by: Adrian Hunter Cc: Andi Kleen Cc: Jiri Olsa Link: http://lore.kernel.org/lkml/20200401101613.6201-10-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread-stack.c | 57 +++++++++++++++++++++++++++++++++- tools/perf/util/thread-stack.h | 3 ++- 2 files changed, 60 insertions(+) diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c index 0885967..83f6c83 100644 --- a/tools/perf/util/thread-stack.c +++ b/tools/perf/util/thread-stack.c @@ -497,6 +497,63 @@ void thread_stack__sample(struct thread *thread, int cpu, chain->nr = i; } +/* + * Hardware sample records, created some time after the event occurred, need to + * have subsequent addresses removed from the call chain. + */ +void thread_stack__sample_late(struct thread *thread, int cpu, + struct ip_callchain *chain, size_t sz, + u64 sample_ip, u64 kernel_start) +{ + struct thread_stack *ts = thread__stack(thread, cpu); + u64 sample_context = callchain_context(sample_ip, kernel_start); + u64 last_context, context, ip; + size_t nr = 0, j; + + if (sz < 2) { + chain->nr = 0; + return; + } + + if (!ts) + goto out; + + /* + * When tracing kernel space, kernel addresses occur at the top of the + * call chain after the event occurred but before tracing stopped. + * Skip them. + */ + for (j = 1; j <= ts->cnt; j++) { + ip = ts->stack[ts->cnt - j].ret_addr; + context = callchain_context(ip, kernel_start); + if (context == PERF_CONTEXT_USER || + (context == sample_context && ip == sample_ip)) + break; + } + + last_context = sample_ip; /* Use sample_ip as an invalid context */ + + for (; nr < sz && j <= ts->cnt; nr++, j++) { + ip = ts->stack[ts->cnt - j].ret_addr; + context = callchain_context(ip, kernel_start); + if (context != last_context) { + if (nr >= sz - 1) + break; + chain->ips[nr++] = context; + last_context = context; + } + chain->ips[nr] = ip; + } +out: + if (nr) { + chain->nr = nr; + } else { + chain->ips[0] = sample_context; + chain->ips[1] = sample_ip; + chain->nr = 2; + } +} + struct call_return_processor * call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data), void *data) diff --git a/tools/perf/util/thread-stack.h b/tools/perf/util/thread-stack.h index e1ec5a5..8962ddc 100644 --- a/tools/perf/util/thread-stack.h +++ b/tools/perf/util/thread-stack.h @@ -85,6 +85,9 @@ int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip, void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr); void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain, size_t sz, u64 ip, u64 kernel_start); +void thread_stack__sample_late(struct thread *thread, int cpu, + struct ip_callchain *chain, size_t sz, u64 ip, + u64 kernel_start); int thread_stack__flush(struct thread *thread); void thread_stack__free(struct thread *thread); size_t thread_stack__depth(struct thread *thread, int cpu);