Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3543612ybz; Mon, 20 Apr 2020 05:02:09 -0700 (PDT) X-Google-Smtp-Source: APiQypKt1nfPIh/MgW2zF2HxpRHtey2daXlwPpwlTA68vuqTqlgwjsFHStT7wpWd+QIy0MF4AFvN X-Received: by 2002:a17:906:b2c2:: with SMTP id cf2mr15219837ejb.262.1587384128859; Mon, 20 Apr 2020 05:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587384128; cv=none; d=google.com; s=arc-20160816; b=Y89fWsMf+mAkRi49RValrPyhQ3Og85lGkMBM5MDQ4e0s4RAupHUZ9Uur3KjNlzZG8i IGyCKR9M/P1Ce/6zqIqbEYkINyGAMuj68beNkP9bxlPKIy4+9j8bRxLmEzQ+aZ5eTQ1b Z1crY/Cjt3cv6SET/2RFVjZgyysnvJAePL1UOo7DGWlQxVDRwYqRHb1X7bdUuEQvRl9i 1IW/0kWWzqkoY0ql+FjRXgDFUCFp0ArlQaYis0dW8txjK0uiKXkPTI1V7ytsw/EBWhPr 5bzMqRZVUsTlfHkUgqQpG16HcgLDEB8C/ERySU9fV2Xee5cCK1l2H9ns2nsR7LiF2+bs GaTQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+WoXpTqjJ9Cj1BKnX3l3RYZgmakBQKmEhepwGiwsad4=; b=ODYG9qJAAKCUNf5SGldzm5NoHNyzXkqfUscwQElkpG4BvuML4gJyc+/br0775Qevdw MqV0bW2MRZwVu0V2NJJjWbg7iHPltN+CIZ6G+Xkik3A0+lX+K+jmBWvQ9fFeF9r2I9KF a4WGYjQtvZpEITLWfBVftbXf0NjaLPb/6SscswSuNNbaEZT1+U3twKW4Lt8eKI1GMdF4 UKNbEpqGl/CMySAjTV73xRscyJmjG3Zkrn7efhbQIIzjNDvBMWCu67pzCUSm2H4fd6z0 hZLB02gXZUrrCEBIIxfsiHim0+zZdnuSOD5CfhizwEjhSGAcM78PV7FBQCfaLsjF8p5E ZCOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lVyFCjCZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce16si400167ejc.526.2020.04.20.05.01.45; Mon, 20 Apr 2020 05:02:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=lVyFCjCZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727801AbgDTL5Z (ORCPT + 99 others); Mon, 20 Apr 2020 07:57:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:41994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbgDTL5Y (ORCPT ); Mon, 20 Apr 2020 07:57:24 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E40CD21927; Mon, 20 Apr 2020 11:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383843; bh=Bs7MyTBHg4KpMB3N/TJ3QoCulD6TDLZr6+xspbm2Rxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lVyFCjCZapNmfLv35zhjUiFUeJ6ZzPt5q9nUk4OlViBoA17MkQhrB6pXlOVTHw8iA OY5xIK0oUPsU+zuYkj4no/FQ16+EigT/KAJaNlqcYfRjG7V8Tnw1aULM8oEWFXp2L6 u8b/EXngPwhiBqWcl1VqC4zZ+ifvGJ55m1U3P+g0= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Kan Liang , Andi Kleen , Jiri Olsa , Adrian Hunter , Alexey Budankov , Mathieu Poirier , Michael Ellerman , Pavel Gerasimov , Peter Zijlstra , Ravi Bangoria , Stephane Eranian , Vitaly Slobodskoy , Arnaldo Carvalho de Melo Subject: [PATCH 53/60] perf thread: Save previous sample for LBR stitching approach Date: Mon, 20 Apr 2020 08:53:09 -0300 Message-Id: <20200420115316.18781-54-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang To retrieve the overwritten LBRs from previous sample for LBR stitching approach, perf has to save the previous sample. Only allocate the struct lbr_stitch once, when LBR stitching approach is enabled and kernel supports hw_idx. Signed-off-by: Kan Liang Reviewed-by: Andi Kleen Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexey Budankov Cc: Mathieu Poirier Cc: Michael Ellerman Cc: Namhyung Kim Cc: Pavel Gerasimov Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Stephane Eranian Cc: Vitaly Slobodskoy Link: http://lore.kernel.org/lkml/20200319202517.23423-11-kan.liang@linux.intel.com [ Use zalloc()/zfree() for thread->lbr_stitch ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 23 +++++++++++++++++++++++ tools/perf/util/thread.c | 1 + tools/perf/util/thread.h | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index f9d69fce584a..a54ca09a1d00 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2292,6 +2292,21 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread, return 0; } +static bool alloc_lbr_stitch(struct thread *thread) +{ + if (thread->lbr_stitch) + return true; + + thread->lbr_stitch = zalloc(sizeof(*thread->lbr_stitch)); + if (!thread->lbr_stitch) + goto err; + +err: + pr_warning("Failed to allocate space for stitched LBRs. Disable LBR stitch\n"); + thread->lbr_stitch_enable = false; + return false; +} + /* * Recolve LBR callstack chain sample * Return: @@ -2308,6 +2323,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread, { struct ip_callchain *chain = sample->callchain; int chain_nr = min(max_stack, (int)chain->nr), i; + struct lbr_stitch *lbr_stitch; u64 branch_from = 0; int err; @@ -2320,6 +2336,13 @@ static int resolve_lbr_callchain_sample(struct thread *thread, if (i == chain_nr) return 0; + if (thread->lbr_stitch_enable && !sample->no_hw_idx && + alloc_lbr_stitch(thread)) { + lbr_stitch = thread->lbr_stitch; + + memcpy(&lbr_stitch->prev_sample, sample, sizeof(*sample)); + } + if (callchain_param.order == ORDER_CALLEE) { /* Add kernel ip */ err = lbr_callchain_add_kernel_ip(thread, cursor, sample, diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1f080db23615..8d0da260c84c 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -111,6 +111,7 @@ void thread__delete(struct thread *thread) exit_rwsem(&thread->namespaces_lock); exit_rwsem(&thread->comm_lock); + thread__free_stitch_list(thread); free(thread); } diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 95294050cff2..34eb61cee6a4 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include "rwsem.h" +#include "event.h" struct addr_location; struct map; @@ -20,6 +22,10 @@ struct perf_record_namespaces; struct thread_stack; struct unwind_libunwind_ops; +struct lbr_stitch { + struct perf_sample prev_sample; +}; + struct thread { union { struct rb_node rb_node; @@ -49,6 +55,7 @@ struct thread { /* LBR call stack stitch */ bool lbr_stitch_enable; + struct lbr_stitch *lbr_stitch; }; struct machine; @@ -145,4 +152,9 @@ static inline bool thread__is_filtered(struct thread *thread) return false; } +static inline void thread__free_stitch_list(struct thread *thread) +{ + zfree(&thread->lbr_stitch); +} + #endif /* __PERF_THREAD_H */ -- 2.21.1