Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3322726yba; Tue, 16 Apr 2019 09:03:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2Szsl8AXnS6TviiHRx5Iv0Cb2ETZ2Qs6k/NwdFK/JMfev6BDipURmwwaw+KwQgTtkZDB4 X-Received: by 2002:a63:6a43:: with SMTP id f64mr44676501pgc.366.1555430589987; Tue, 16 Apr 2019 09:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555430589; cv=none; d=google.com; s=arc-20160816; b=nzdx3qB8E09o0uKmoMrzH9b3G5Fa3XV9IntJa5Tc/DUGpYIwYU9jo8qSYqTns+ngxT E1Ek4MjgfwXyckgN06qxJ54LDhGI5QqE6jgOP7QegMmV3jWf2P1hWURUr3OHnK1lkQ7x kHTTtbpyaMK6x46V9GXnggGcSor3LlwM5VHRfM4vM0fc36oAlOUxxsTQ2gtjKRijB+fD NdrciWLjx+qMIykMzeIb1K7XcYflovYsaMawC+BxKnaxxn5RIjkvXmj3yGK+grPTyWd6 W6QHetKSSjJ9+YewjB9Co3Um6YSn5eX5cQrvuE8CidVCsHIAHyRGxnxbezbqb4Yqj97j 4wow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=T7TD2POZCiyGRaCRYSxHFd+DLXkYywwHCNG2nYgjcEs=; b=Xlc2YscheRuE2ZMfH1l3jgPn+qF9bK1FXbmRzbD7/SNq04IEWM3OfVN0QiS40ByFsT ym13w/3vCDmMNtkO7+YgUt8v1dXfK9Vm2VMrVDQtu1//HlWZnmWoJSFeGg1aWn425AO8 M68gQUzrp4TpoovD5BbA/gOCuz9kOCWfSoQ3qHfiGzxHX5829e6AtAeJ6wwn/SxSxKaL GsXBgRIdSSoj1Tcklc84ID4/bnfVPTg0BjkcEdqdNOB9yQu1TAo3Lvh+9Bn+iFJp6HcC hOsmUGAjzN31Xgyf19rkeAVH8nSOwcRlFsoblA0OxkkssOp4ZymwRhl2fLfkvww/wyI1 +sOQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q86si20779346pfi.197.2019.04.16.09.02.53; Tue, 16 Apr 2019 09:03:09 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729960AbfDPQBt (ORCPT + 99 others); Tue, 16 Apr 2019 12:01:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41192 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729934AbfDPQBr (ORCPT ); Tue, 16 Apr 2019 12:01:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55CD08666F; Tue, 16 Apr 2019 16:01:47 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E04A5D71A; Tue, 16 Apr 2019 16:01:44 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Adrian Hunter , Song Liu , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH 04/12] perf tools: Add bpf dso read and size hooks Date: Tue, 16 Apr 2019 18:01:19 +0200 Message-Id: <20190416160127.30203-5-jolsa@kernel.org> In-Reply-To: <20190416160127.30203-1-jolsa@kernel.org> References: <20190416160127.30203-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 16 Apr 2019 16:01:47 +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. 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 6fdff723e55a..0cc6702c6442 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) { @@ -831,7 +871,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; @@ -940,6 +984,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.17.2