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.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SIGNED_OFF_BY,SPF_PASS,T_DKIMWL_WL_HIGH,UNWANTED_LANGUAGE_BODY 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 3C967C43219 for ; Fri, 3 May 2019 08:19:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A6622087F for ; Fri, 3 May 2019 08:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556871592; bh=hSEHK2Ch7TGJqCZBFpBLBTVPcTX+zZzugDwA9ak0TlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gRHM4Bj7MiahjxsPsgTCreeksj0a67DzRqYPvvDyrhnOA59BAkHiVcJMWKHAKvfWS kMimn6UZqJhe42tp+TpQg6QfaTjXuUJYM61/B+nGOV78qL1ba51y0N/7AA7kl8nZLG Inb0Hz4QxmfojAnfcpi2jECRtzKK4Ql6625DtbrQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727318AbfECITv (ORCPT ); Fri, 3 May 2019 04:19:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40832 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbfECIS7 (ORCPT ); Fri, 3 May 2019 04:18:59 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82C253092649; Fri, 3 May 2019 08:18:58 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61F26F6E6; Fri, 3 May 2019 08:18:56 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Stanislav Fomichev , Song Liu , Adrian Hunter , Andi Kleen Subject: [PATCH 04/12] perf tools: Add bpf dso read and size hooks Date: Fri, 3 May 2019 10:18:33 +0200 Message-Id: <20190503081841.1908-5-jolsa@kernel.org> In-Reply-To: <20190503081841.1908-1-jolsa@kernel.org> References: <20190503081841.1908-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 03 May 2019 08:18:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding bpf related code into dso reading paths to return size (bpf_size) and read the bpf code (bpf_read). Link: http://lkml.kernel.org/n/tip-ql6jpegvv5823yc87u0hlzfa@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/dso.c | 49 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 1e6a045adb8c..2c9289621efd 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include "bpf-event.h" #include "compress.h" #include "namespaces.h" #include "path.h" @@ -706,6 +708,44 @@ bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by) return false; } +static ssize_t bpf_read(struct dso *dso, u64 offset, char *data) +{ + struct bpf_prog_info_node *node; + ssize_t size = DSO__DATA_CACHE_SIZE; + u64 len; + u8 *buf; + + node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id); + if (!node || !node->info_linear) { + dso->data.status = DSO_DATA_STATUS_ERROR; + return -1; + } + + len = node->info_linear->info.jited_prog_len; + buf = (u8 *) node->info_linear->info.jited_prog_insns; + + if (offset >= len) + return -1; + + size = (ssize_t) min(len - offset, (u64) size); + memcpy(data, buf + offset, size); + return size; +} + +static int bpf_size(struct dso *dso) +{ + struct bpf_prog_info_node *node; + + node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id); + if (!node || !node->info_linear) { + dso->data.status = DSO_DATA_STATUS_ERROR; + return -1; + } + + dso->data.file_size = node->info_linear->info.jited_prog_len; + return 0; +} + static void dso_cache__free(struct dso *dso) { @@ -832,7 +872,11 @@ dso_cache__read(struct dso *dso, struct machine *machine, if (!cache) return -ENOMEM; - ret = file_read(dso, machine, cache_offset, cache->data); + if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) + ret = bpf_read(dso, cache_offset, cache->data); + else + ret = file_read(dso, machine, cache_offset, cache->data); + if (ret > 0) { cache->offset = cache_offset; cache->size = ret; @@ -941,6 +985,9 @@ int dso__data_file_size(struct dso *dso, struct machine *machine) if (dso->data.status == DSO_DATA_STATUS_ERROR) return -1; + if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) + return bpf_size(dso); + return file_size(dso, machine); } -- 2.20.1