From patchwork Wed Oct 14 12:41:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54923 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 4565F23087 for ; Wed, 14 Oct 2015 12:43:34 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf25973466wic.3 for ; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=mubc+v3gpo858ZdF4ko8VSuBqRm7eedNyvNK78XGQ4M=; b=Kvz6uq/a7qLB4wsfW06qEzStndVb1jdUXQkCcAkDfeo7dG+EL3ychKdLnqDde05iXD 3zcGWPRH639A5PgUYBZW7m8AAsdthPmH/faJmDLYtMy3cl0ToCcvZuCfkMmernGZSwT+ TesWu3FXE0HMobZ7OopOILBcEzGlKkflSjR920umlK42HuICEmgo3PgJaMiTHKp/oHJ/ EE+shOR31/eBtxfKwbfmwnCA+7fgJzAUyy0jP663AMjBr5psB/2FUt0BHe86vBGdJa6k zQYVcjRvsnCIGHeYC17wTxO9Cx+/yOpZZIPP0sf/XoLlRv+XcOypdbSEW1+tJsw902GP zLRQ== X-Gm-Message-State: ALoCoQk3AYxX8UfqGnr+d9HZxvBj3dJ6G10H5vYypwPEQGlarF2QHT+Wk6B+SLK90MKfMT2jwQLB X-Received: by 10.180.208.7 with SMTP id ma7mr821344wic.5.1444826613471; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.165.199 with SMTP id o190ls35381lfe.60.gmail; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) X-Received: by 10.112.151.106 with SMTP id up10mr1517357lbb.106.1444826613286; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id rj9si5444753lbb.26.2015.10.14.05.43.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:43:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbck17 with SMTP id ck17so45416683lbb.1 for ; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) X-Received: by 10.112.161.168 with SMTP id xt8mr493660lbb.88.1444826613111; Wed, 14 Oct 2015 05:43:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2710054lbq; Wed, 14 Oct 2015 05:43:32 -0700 (PDT) X-Received: by 10.66.252.2 with SMTP id zo2mr3575372pac.89.1444826611304; Wed, 14 Oct 2015 05:43:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ph4si13027707pbb.177.2015.10.14.05.43.30; Wed, 14 Oct 2015 05:43:31 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753719AbbJNMn0 (ORCPT + 30 others); Wed, 14 Oct 2015 08:43:26 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:50488 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753682AbbJNMnI (ORCPT ); Wed, 14 Oct 2015 08:43:08 -0400 Received: from 172.24.1.49 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.49]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWT05980; Wed, 14 Oct 2015 20:42:48 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Wed, 14 Oct 2015 20:42:38 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 29/31] perf tools: Add API to apply config to BPF map Date: Wed, 14 Oct 2015 12:41:40 +0000 Message-ID: <1444826502-49291-30-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> References: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , bpf__apply_config() is introduced as the core CPI to apply config options to all BPF objects. This patch also does the real work for setting maps events for BPF_MAP_TYPE_PERF_EVENT_ARRAY maps by inserting file descriptions of a evsel into the BPF map. This patch is required because we are unable to set all BPF config during parsing. Events in BPF_MAP_TYPE_PERF_EVENT_ARRAY maps is an example: during parsing, fds of events is not ready yet. Signed-off-by: Wang Nan Signed-off-by: He Kuang Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-tmg65cm1zaf1zxs7zmvxmxp4@git.kernel.org --- tools/perf/util/bpf-loader.c | 109 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 15 ++++++ 2 files changed, 124 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index b92c2f7..9d661c0 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -7,6 +7,7 @@ #include #include +#include #include #include "perf.h" #include "debug.h" @@ -767,6 +768,107 @@ int bpf__config_obj(struct bpf_object *obj, return -ENODEV; } +static int +bpf__apply_config_map(struct bpf_map *map) +{ + struct bpf_map_priv *priv; + struct bpf_map_def def; + const char *name; + int err, map_fd; + + name = bpf_map__get_name(map); + err = bpf_map__get_private(map, (void **)&priv); + if (err) { + pr_debug("ERROR: failed to get private field from map %s\n", + name); + return err; + } + if (!priv) { + pr_debug("INFO: nothing to config for map %s\n", name); + return 0; + } + + map_fd = bpf_map__get_fd(map); + if (map_fd < 0) { + pr_debug("ERROR: failed to get fd from map %s\n", name); + return map_fd; + } + + err = bpf_map__get_def(map, &def); + if (err) { + pr_debug("ERROR: failed to retrive map def from map %s\n", + name); + return err; + } + + if (priv->evsel) { + struct xyarray *xy = priv->evsel->fd; + unsigned int cpus, i; + + if (!xy) { + pr_debug("ERROR: event is not ready for map %s\n", name); + return -EINVAL; + } + + if (xy->row_size / xy->entry_size != 1) { + pr_debug("ERROR: Dimension of target event is incorrect for map %s\n", + name); + return -EINVAL; + } + + cpus = xy->entries / (xy->row_size / xy->entry_size); + if (cpus > def.max_entries) { + pr_debug("ERROR: map %s needs to be enlarge to %d for its event\n", + name, cpus); + return -EINVAL; + } else if (cpus < def.max_entries) + pr_debug("WARNING: map %s has more entries than required\n", + name); + + for (i = 0; i < cpus; i++) { + int *evt_fd = xyarray__entry(xy, i, 0); + + err = bpf_map_update_elem(map_fd, &i, evt_fd, + BPF_ANY); + + if (err) { + pr_debug("ERROR: failed to insert fd %d to %s[%d]\n", + *evt_fd, name, i); + return -errno; + } + } + } + return 0; +} + +static int +bpf__apply_config_object(struct bpf_object *obj) +{ + struct bpf_map *map; + int err; + + bpf_map__for_each(map, obj) { + err = bpf__apply_config_map(map); + if (err) + return err; + } + return 0; +} + +int bpf__apply_config(void) +{ + struct bpf_object *obj, *tmp; + int err; + + bpf_object__for_each_safe(obj, tmp) { + err = bpf__apply_config_object(obj); + if (err) + return err; + } + + return 0; +} + #define bpf__strerror_head(err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\ @@ -822,3 +924,10 @@ int bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused, bpf__strerror_end(buf, size); return 0; } + +int bpf__strerror_apply_config(int err, char *buf, size_t size) +{ + bpf__strerror_head(err, buf, size); + bpf__strerror_end(buf, size); + return 0; +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h index 4c99b21..3a93ba3 100644 --- a/tools/perf/util/bpf-loader.h +++ b/tools/perf/util/bpf-loader.h @@ -53,6 +53,8 @@ int bpf__strerror_config_obj(struct bpf_object *obj, const char *key, struct bpf_config_val *val, struct perf_evlist *evlist, int err, char *buf, size_t size); +int bpf__apply_config(void); +int bpf__strerror_apply_config(int err, char *buf, size_t size); #else static inline struct bpf_object * bpf__prepare_load(const char *filename __maybe_unused, @@ -93,6 +95,12 @@ bpf__config_obj(struct bpf_object *obj __maybe_unused, } static inline int +bpf__apply_config(void) +{ + return 0; +} + +static inline int __bpf_strerror(char *buf, size_t size) { if (!size) @@ -129,5 +137,12 @@ bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused, { return __bpf_strerror(buf, size); } + +static inline int +bpf__strerror_apply_config(int err __maybe_unused, + char *buf, size_t size) +{ + return __bpf_strerror(buf, size); +} #endif #endif