Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3540764ybz; Mon, 20 Apr 2020 04:59:29 -0700 (PDT) X-Google-Smtp-Source: APiQypLHOvyXMeD2xZMWbvFsA1m80aThhP6Xf7wHJNv3mZiid3+c3ZOvmIqZlKKjPetpsUXzpFhO X-Received: by 2002:aa7:c90d:: with SMTP id b13mr13805311edt.14.1587383969449; Mon, 20 Apr 2020 04:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587383969; cv=none; d=google.com; s=arc-20160816; b=agoThLER/TN6enFw6eFSmWkrorx23yQm10uO6Fkg4sJmoN89xvuBFzOnb0S4bLcWM/ 7kfnay4Gb5m6otmfjmZaWxk5gFzK4QnlbK7iyD1LS/0H4Vu6FJz+58akJS5Fg8cXOer9 AC0tznAIeSgcawhAXPG5CWJrgSmRFRigxbFWq34pwb1LiXwZrHqCAd2ehAFvI4gkdc1h ynk6YvP7EIrjfd+Mr3NSiYgdDACyYoCHX+Lbq4cScmxP+HQlMMcPt6O2oPp2t7SB/INK enOKgTd2QV9/ALuAViP8fbvYksznSFFuu0dAktE+4C0TVCz6TlkeF2tIen8MT4CAgcxT h9Dg== 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=hEz7MH7luoH65KaYEJ4Uq2oKaGYaIzzEjc8399+4nqA=; b=lEfjTTAVNUwIsNyMFD9e5lQpJUlCZbdCYGVEBM5k9HtvYqPiVIkzWorFRMeN0RfhgB 8IBzHnnxsn9w7irLaC8YHRlWFUhiOeEjUxXP9Ef6rqSUlKsgZjMyi7q4913SbtrLsVKj z6cXH3lnhjk+GztVFOYsyzW4myqxFJQgE0aAWp5mBX5/bNucCbozzg8NR1wh6g2dGvsJ orSkcUSHErr9y96dpehsFerHopIMue4vWzm/0YHHOSvxNaFmpQuImzicuAj1K08i/U5+ wRtAnAlXKHnKmgAEukmjM0+76LbqrZDg9KVb8NH2SmbI7TdNwpPx1dz/qutXkK685Emi DGWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZbmCNCEq; 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 gj20si397171ejb.48.2020.04.20.04.59.06; Mon, 20 Apr 2020 04:59:29 -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=ZbmCNCEq; 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 S1726762AbgDTL5L (ORCPT + 99 others); Mon, 20 Apr 2020 07:57:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726453AbgDTL5J (ORCPT ); Mon, 20 Apr 2020 07:57:09 -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 06FDD21927; Mon, 20 Apr 2020 11:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383828; bh=oJKe5r3enYIHI/9JXAP7ILpEmBjxMZdI1Za4GyV6cIU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZbmCNCEqUmUvm7AtbV814CgOsYbAF24CIXqbOZsobDzzt7s0ZdoozIfdYRvr/JPB/ ArqnUATGkVHAW5JtwoGHWp0VrEdUxCVmRCEcUsRms3giGEIH1MuRw/a8bo0u2y3aAs h3VZdj5++4woR+9xvvEWWNHBiTN55FoH1Rzbl/L8= 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 50/60] perf machine: Factor out lbr_callchain_add_kernel_ip() Date: Mon, 20 Apr 2020 08:53:06 -0300 Message-Id: <20200420115316.18781-51-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 kernel ip to callchain. Factor out lbr_callchain_add_kernel_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-8-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/machine.c | 67 ++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 0da540e6f803..a7f75fd43b0f 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2190,6 +2190,40 @@ static int remove_loops(struct branch_entry *l, int nr, return nr; } +static int lbr_callchain_add_kernel_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, int end) +{ + struct ip_callchain *chain = sample->callchain; + u8 cpumode = PERF_RECORD_MISC_USER; + int err, i; + + if (callee) { + for (i = 0; i < end + 1; i++) { + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, chain->ips[i], + false, NULL, NULL, branch_from); + if (err) + return err; + } + return 0; + } + + for (i = end; i >= 0; i--) { + err = add_callchain_ip(thread, cursor, parent, + root_al, &cpumode, chain->ips[i], + false, NULL, NULL, branch_from); + if (err) + return err; + } + + return 0; +} + /* * Recolve LBR callstack chain sample * Return: @@ -2242,17 +2276,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread, if (callchain_param.order == ORDER_CALLEE) { /* Add kernel ip */ - for (j = 0; j < i + 1; j++) { - ip = chain->ips[j]; - branch = false; - flags = NULL; - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); - if (err) - goto error; - } + err = lbr_callchain_add_kernel_ip(thread, cursor, sample, + parent, root_al, branch_from, + true, i); + if (err) + goto error; + /* Add LBR ip from first entries.to */ ip = entries[0].to; branch = true; @@ -2308,17 +2337,11 @@ static int resolve_lbr_callchain_sample(struct thread *thread, goto error; /* Add kernel ip */ - for (j = lbr_nr + 1; j < mix_chain_nr; j++) { - ip = chain->ips[i + 1 - (j - lbr_nr)]; - branch = false; - flags = NULL; - err = add_callchain_ip(thread, cursor, parent, - root_al, &cpumode, ip, - branch, flags, NULL, - branch_from); - if (err) - goto error; - } + err = lbr_callchain_add_kernel_ip(thread, cursor, sample, + parent, root_al, branch_from, + false, i); + if (err) + goto error; } return 1; -- 2.21.1