From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87413C43381 for ; Sat, 9 Mar 2019 05:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 558E52081B for ; Sat, 9 Mar 2019 05:56:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbfCIF4o (ORCPT ); Sat, 9 Mar 2019 00:56:44 -0500 Received: from mga12.intel.com ([192.55.52.136]:63276 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfCIF4m (ORCPT ); Sat, 9 Mar 2019 00:56:42 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2019 21:56:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,458,1544515200"; d="scan'208";a="132845008" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by fmsmga007.fm.intel.com with ESMTP; 08 Mar 2019 21:56:41 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 763813001F2; Fri, 8 Mar 2019 21:56:41 -0800 (PST) From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH v5 01/15] perf tools: Add utility function to fetch executable Date: Fri, 8 Mar 2019 21:56:14 -0800 Message-Id: <20190309055628.21617-2-andi@firstfloor.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190309055628.21617-1-andi@firstfloor.org> References: <20190309055628.21617-1-andi@firstfloor.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: Andi Kleen Add a utility function to fetch executable code. Convert one user over to it. There are more places doing that, but they do significantly different actions, so they are not easy to fit into a single library function. Signed-off-by: Andi Kleen --- tools/perf/util/Build | 1 + tools/perf/util/fetch.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/fetch.h | 7 +++++++ tools/perf/util/intel-bts.c | 21 +++------------------ 4 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 tools/perf/util/fetch.c create mode 100644 tools/perf/util/fetch.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 8dd3102301ea..649321fc3fb9 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -65,6 +65,7 @@ perf-y += trace-event-scripting.o perf-y += trace-event.o perf-y += svghelper.o perf-y += sort.o +perf-y += fetch.o perf-y += hist.o perf-y += util.o perf-y += xyarray.o diff --git a/tools/perf/util/fetch.c b/tools/perf/util/fetch.c new file mode 100644 index 000000000000..1430083e7eca --- /dev/null +++ b/tools/perf/util/fetch.c @@ -0,0 +1,28 @@ +#include "perf.h" +#include "machine.h" +#include "thread.h" +#include "symbol.h" +#include "map.h" +#include "fetch.h" + +int fetch_exe(u64 ip, struct thread *thread, struct machine *machine, + char *buf, int len, bool *is64bit) +{ + struct addr_location al; + u8 cpumode; + long offset; + + if (machine__kernel_ip(machine, ip)) + cpumode = PERF_RECORD_MISC_KERNEL; + else + cpumode = PERF_RECORD_MISC_USER; + if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) + return -1; + if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR) + return -1; + map__load(al.map); + offset = al.map->map_ip(al.map, ip); + if (is64bit) + *is64bit = al.map->dso->is_64_bit; + return dso__data_read_offset(al.map->dso, machine, offset, (u8 *)buf, len); +} diff --git a/tools/perf/util/fetch.h b/tools/perf/util/fetch.h new file mode 100644 index 000000000000..7b77b8cee55a --- /dev/null +++ b/tools/perf/util/fetch.h @@ -0,0 +1,7 @@ +#ifndef FETCH_H +#define FETCH_H 1 + +int fetch_exe(u64 ip, struct thread *thread, struct machine *machine, + char *buf, int len, bool *is64bit); + +#endif diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 0c0180c67574..915f4662e52e 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -38,6 +38,7 @@ #include "auxtrace.h" #include "intel-pt-decoder/intel-pt-insn-decoder.h" #include "intel-bts.h" +#include "fetch.h" #define MAX_TIMESTAMP (~0ULL) @@ -328,35 +329,19 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip) { struct machine *machine = btsq->bts->machine; struct thread *thread; - struct addr_location al; unsigned char buf[INTEL_PT_INSN_BUF_SZ]; ssize_t len; - int x86_64; - uint8_t cpumode; + bool x86_64; int err = -1; - if (machine__kernel_ip(machine, ip)) - cpumode = PERF_RECORD_MISC_KERNEL; - else - cpumode = PERF_RECORD_MISC_USER; - thread = machine__find_thread(machine, -1, btsq->tid); if (!thread) return -1; - if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) - goto out_put; - - len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, - INTEL_PT_INSN_BUF_SZ); + len = fetch_exe(ip, thread, machine, (char*)buf, INTEL_PT_INSN_BUF_SZ, &x86_64); if (len <= 0) goto out_put; - /* Load maps to ensure dso->is_64_bit has been updated */ - map__load(al.map); - - x86_64 = al.map->dso->is_64_bit; - if (intel_pt_get_insn(buf, len, x86_64, &btsq->intel_pt_insn)) goto out_put; -- 2.20.1