Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3501301imu; Mon, 7 Jan 2019 04:39:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN4noXDHMitsMT9ZTXZa86B+n/YRBPcZsOzy+BG1iZ46jOH/HfLYk5quvsfFa1M+ruTVx/dt X-Received: by 2002:a17:902:6909:: with SMTP id j9mr59189087plk.196.1546864786344; Mon, 07 Jan 2019 04:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546864786; cv=none; d=google.com; s=arc-20160816; b=y8timSSeuPy4HChSPQDWlaeQWnBrR3a4Ncr41KVFUNzlQuZfTuwRVQxrtdIvJWsVpo sHnRsZCeOxPerhgGN3w5AN2RSfOnxkkJKqmRQpR3l7yoX/M0/stgA6VOAYBXC9WTDAlF 8AhTmBCrk4U1XSw6HDZhpHZ6vnMEzBjuKacLf2E5f4susEyiNomM5lqd+HYR2hkVJ31k 7inMNou95yam2jM556ER38Ab7igIsqjVtmTWjyXv7dPyrWYgx84YYrboEdvtB1SZvlR0 ScsqpzEgCfQZ+i4LsWzJlEcZB/Yuq8Kzj9dlg5h1tyn+rKUYeVg8u8LBCfFWBK5wseJ7 HJNg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fngF/xAUbr+CXoEqPOCsm8zv5ajbVY0F/igU6jk7lqE=; b=xCr62gScA52oi7C+BArdT1yThda7UJDDK8c0XFTtE5fzEriNWG3JksXdMNWADn+cWE INgGIFwbFZOzjn7owhIb+2BP11YtC2qXYIs3p5G/vlBTFvGsr+slIRU5NWDT3A5Jo1uv K1SNBWEkJqr4XzsYU+IjqDtxs3FDwGwUCdvgcZ9JBzWsBn/zUN4rMaW0WGokcXHs/pYO 0oddmQcnWUQVSOcQfzuM+7ps/nBpBuiUoDzEjp07bCUMX4xNr23yHAzQtVGNXPogM0Xd lSJhYYl2AHPsPeMgW8wJzxyGUVSf0yrRMwsIghpuXxT7PIIUCKVybV2+CHkUsz6u5vXV iQnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vHjewgFh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si8860432pfb.190.2019.01.07.04.39.31; Mon, 07 Jan 2019 04:39:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vHjewgFh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727853AbfAGMhu (ORCPT + 99 others); Mon, 7 Jan 2019 07:37:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:52818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727616AbfAGMht (ORCPT ); Mon, 7 Jan 2019 07:37:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 6721620859; Mon, 7 Jan 2019 12:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864668; bh=+41pSvgGQgaIYvV7pqXSn7LFiyNgXDWZ5sgfdNfM7RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vHjewgFh03zQRhhFvJCUHKHgaV2YHDGcd8OPNyV3BQmGIvQO9V/kxoSD3n88MzDaX ej0BsouwYG2qyNw5jgDBidV/xX5aCkwQ7eOMky7JB4ZY1CmKlEofkeskhMqvm257DN 9NatKcX1H/O/DMafDLdPUjDEZZbOl1Ao2Ek4x2Xw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Andi Kleen , "David S. Miller" , Jiri Olsa , Leo Yan , Mathieu Poirier , Arnaldo Carvalho de Melo Subject: [PATCH 4.20 065/145] perf thread: Add fallback functions for cases where cpumode is insufficient Date: Mon, 7 Jan 2019 13:31:42 +0100 Message-Id: <20190107104445.776857948@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter commit 8e80ad9983caeee09c3a0a1a37e05bff93becce4 upstream. For branch stacks or branch samples, the sample cpumode might not be correct because it applies only to the sample 'ip' and not necessary to 'addr' or branch stack addresses. Add fallback functions that can be used to deal with those cases Signed-off-by: Adrian Hunter Cc: Andi Kleen Cc: David S. Miller Cc: Jiri Olsa Cc: Leo Yan Cc: Mathieu Poirier Cc: stable@vger.kernel.org # 4.19 Link: http://lkml.kernel.org/r/20181106210712.12098-2-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/event.c | 27 +++++++++++++++++++++++++++ tools/perf/util/machine.c | 27 +++++++++++++++++++++++++++ tools/perf/util/machine.h | 2 ++ tools/perf/util/thread.h | 4 ++++ 4 files changed, 60 insertions(+) --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -1577,6 +1577,24 @@ struct map *thread__find_map(struct thre return al->map; } +/* + * For branch stacks or branch samples, the sample cpumode might not be correct + * because it applies only to the sample 'ip' and not necessary to 'addr' or + * branch stack addresses. If possible, use a fallback to deal with those cases. + */ +struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, + struct addr_location *al) +{ + struct map *map = thread__find_map(thread, cpumode, addr, al); + struct machine *machine = thread->mg->machine; + u8 addr_cpumode = machine__addr_cpumode(machine, cpumode, addr); + + if (map || addr_cpumode == cpumode) + return map; + + return thread__find_map(thread, addr_cpumode, addr, al); +} + struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al) { @@ -1585,6 +1603,15 @@ struct symbol *thread__find_symbol(struc al->sym = map__find_symbol(al->map, al->addr); return al->sym; } + +struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, + u64 addr, struct addr_location *al) +{ + al->sym = NULL; + if (thread__find_map_fb(thread, cpumode, addr, al)) + al->sym = map__find_symbol(al->map, al->addr); + return al->sym; +} /* * Callers need to drop the reference to al->thread, obtained in --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2592,6 +2592,33 @@ int machine__get_kernel_start(struct mac return err; } +u8 machine__addr_cpumode(struct machine *machine, u8 cpumode, u64 addr) +{ + u8 addr_cpumode = cpumode; + bool kernel_ip; + + if (!machine->single_address_space) + goto out; + + kernel_ip = machine__kernel_ip(machine, addr); + switch (cpumode) { + case PERF_RECORD_MISC_KERNEL: + case PERF_RECORD_MISC_USER: + addr_cpumode = kernel_ip ? PERF_RECORD_MISC_KERNEL : + PERF_RECORD_MISC_USER; + break; + case PERF_RECORD_MISC_GUEST_KERNEL: + case PERF_RECORD_MISC_GUEST_USER: + addr_cpumode = kernel_ip ? PERF_RECORD_MISC_GUEST_KERNEL : + PERF_RECORD_MISC_GUEST_USER; + break; + default: + break; + } +out: + return addr_cpumode; +} + struct dso *machine__findnew_dso(struct machine *machine, const char *filename) { return dsos__findnew(&machine->dsos, filename); --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -100,6 +100,8 @@ static inline bool machine__kernel_ip(st return ip >= kernel_start; } +u8 machine__addr_cpumode(struct machine *machine, u8 cpumode, u64 addr); + struct thread *machine__find_thread(struct machine *machine, pid_t pid, pid_t tid); struct comm *machine__thread_exec_comm(struct machine *machine, --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -96,9 +96,13 @@ struct thread *thread__main_thread(struc struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al); +struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr, + struct addr_location *al); struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode, u64 addr, struct addr_location *al); +struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, + u64 addr, struct addr_location *al); void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, struct addr_location *al);