Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3540936ybz; Mon, 20 Apr 2020 04:59:42 -0700 (PDT) X-Google-Smtp-Source: APiQypKA1bSfs5aUR4j9OKc+jmNyeBYnt1MRCU5zHnhmEHw4PxDVIYyMbqjbqCXK6cWjvsY98McG X-Received: by 2002:a17:906:74c:: with SMTP id z12mr7438815ejb.87.1587383982447; Mon, 20 Apr 2020 04:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383982; cv=none; d=google.com; s=arc-20160816; b=cXKcBUroAJaiwb+Xga5BLkShtJwksmsDWmArEYaqhsbAY+Fjh/8DyFi6S3Yz9sKl7M juh8sHP0qsOA0gd2yJS/gtK5hOSuLHP445Yi/6gCb6qG1xGY3ZILCATlGVwD3zNWTXVA XJdTgQyeH5KHINblzNLITnlDsYHFOkPpkl+SIJ6wfAqKJexXWqpS1KxmgZGbiOmninCL BLVc7+0E17b14Kq/w7v9QZ6ZTiaoYpJ7sXpB6xjW+Z0mh60mx96MeRMWWXYycIrPBB1B /whMQ9HT+BlYjq2KC0BK7ftQVPfFf+jggMDTY7httHMZkg0VyOixErU+nOhgccAj4U/X 5iPA== 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=f+t0cVyOhqEJi/SL2MzCtNcKXfnmxOQVcHzbd+awahw=; b=IYEOCB+y19BApAvFQDMWb5HjXWJ8O/NCymXZf9ootwVziXcAe8A9/yxm0VQ/jCvG/Q IDIeypsKG3i0/3hHWrPtjLhmcOml8OwT2X0AtdW4r9f2hbJOx0o7Drf9dQxJkYPgzUYL snTyxAz3M1ASzLcDzIHmgfFJCeAuAy/aiP4NyiTdcz2GRAyO/YhCioxGVsL9v6sWXqUg l7/iU9cC/rxyoCQGlov/qjHVS/W7joE0kEAeH4+XOhdGU031j2dFi5/Iw20isfxruXgc Nd+3L7+7wuYPCuZV1+9uxHtdyf++VL613LUDq+O8WPzhZ/dNky7S5cXuml5FalmtZUal znPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b3qOL2LE; 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 u4si404213ejb.432.2020.04.20.04.59.19; Mon, 20 Apr 2020 04:59:42 -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=b3qOL2LE; 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 S1727785AbgDTL5R (ORCPT + 99 others); Mon, 20 Apr 2020 07:57:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:41774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726717AbgDTL5O (ORCPT ); Mon, 20 Apr 2020 07:57:14 -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 00BA0218AC; Mon, 20 Apr 2020 11:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383833; bh=LzTpe3nRXWzu7leUSs8VdFuPvTxItUjuILYM/9xUqZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b3qOL2LE73dmD/UROVpo3jL3BAnKMa918iFrIvktwf4a0ykh018y0P3MVnQZY99PJ jEIG2219ku6UMLwyrorF0RptzkD/NQs91RBDUpYowQ9gsgwXO13/wZ3G2dKzv4qIaj +pgYrl3dGePDzS5gTNgTVqJMRXfWwiravgRKIxPM= 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 51/60] perf machine: Factor out lbr_callchain_add_lbr_ip() Date: Mon, 20 Apr 2020 08:53:07 -0300 Message-Id: <20200420115316.18781-52-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 Both caller and callee needs to add ip from LBR to callchain. Factor out lbr_callchain_add_lbr_ip() to improve code readability. 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-9-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 143 +++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 70 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index a7f75fd43b0f..f9d69fce584a 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2224,6 +2224,74 @@ static int lbr_callchain_add_kernel_ip(struct thread *thread, return 0; } +static int lbr_callchain_add_lbr_ip(struct thread *thread, + struct callchain_cursor *cursor, + struct perf_sample *sample, + struct symbol **parent, + struct addr_location *root_al, + u64 *branch_from, + bool callee) +{ + struct branch_stack *lbr_stack = sample->branch_stack; + struct branch_entry *entries = perf_sample__branch_entries(sample); + u8 cpumode = PERF_RECORD_MISC_USER; + int lbr_nr = lbr_stack->nr; + struct branch_flags *flags; + int err, i; + u64 ip; + + if (callee) { + /* Add LBR ip from first entries.to */ + ip = entries[0].to; + flags = &entries[0].flags; + *branch_from = entries[0].from; + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, ip, + true, flags, NULL, + *branch_from); + if (err) + return err; + + /* Add LBR ip from entries.from one by one. */ + for (i = 0; i < lbr_nr; i++) { + ip = entries[i].from; + flags = &entries[i].flags; + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, ip, + true, flags, NULL, + *branch_from); + if (err) + return err; + } + return 0; + } + + /* Add LBR ip from entries.from one by one. */ + for (i = lbr_nr - 1; i >= 0; i--) { + ip = entries[i].from; + flags = &entries[i].flags; + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, ip, + true, flags, NULL, + *branch_from); + if (err) + return err; + } + + /* Add LBR ip from first entries.to */ + ip = entries[0].to; + flags = &entries[0].flags; + *branch_from = entries[0].from; + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, ip, + true, flags, NULL, + *branch_from); + if (err) + return err; + + return 0; +} + /* * Recolve LBR callstack chain sample * Return: @@ -2240,14 +2308,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; - u8 cpumode = PERF_RECORD_MISC_USER; - u64 ip, branch_from = 0; - struct branch_stack *lbr_stack; - struct branch_entry *entries; - int lbr_nr, j, k; - bool branch; - struct branch_flags *flags; - int mix_chain_nr; + u64 branch_from = 0; int err; for (i = 0; i < chain_nr; i++) { @@ -2259,21 +2320,6 @@ static int resolve_lbr_callchain_sample(struct thread *thread, if (i == chain_nr) return 0; - lbr_stack = sample->branch_stack; - entries = perf_sample__branch_entries(sample); - lbr_nr = lbr_stack->nr; - /* - * LBR callstack can only get user call chain. - * The mix_chain_nr is kernel call chain - * number plus LBR user call chain number. - * i is kernel call chain number, - * 1 is PERF_CONTEXT_USER, - * lbr_nr + 1 is the user call chain number. - * For details, please refer to the comments - * in callchain__printf - */ - mix_chain_nr = i + 1 + lbr_nr + 1; - if (callchain_param.order == ORDER_CALLEE) { /* Add kernel ip */ err = lbr_callchain_add_kernel_ip(thread, cursor, sample, @@ -2282,57 +2328,14 @@ static int resolve_lbr_callchain_sample(struct thread *thread, if (err) goto error; - /* Add LBR ip from first entries.to */ - ip = entries[0].to; - branch = true; - flags = &entries[0].flags; - branch_from = entries[0].from; - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); + err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, + root_al, &branch_from, true); if (err) goto error; - /* Add LBR ip from entries.from one by one. */ - for (j = i + 2; j < mix_chain_nr; j++) { - k = j - i - 2; - ip = entries[k].from; - branch = true; - flags = &entries[k].flags; - - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); - if (err) - goto error; - } } else { - /* Add LBR ip from entries.from one by one. */ - for (j = 0; j < lbr_nr; j++) { - k = lbr_nr - j - 1; - ip = entries[k].from; - branch = true; - flags = &entries[k].flags; - - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); - if (err) - goto error; - } - - /* Add LBR ip from first entries.to */ - ip = entries[0].to; - branch = true; - flags = &entries[0].flags; - branch_from = entries[0].from; - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); + err = lbr_callchain_add_lbr_ip(thread, cursor, sample, parent, + root_al, &branch_from, false); if (err) goto error; -- 2.21.1