From patchwork Sat Oct 17 10:48:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 55155 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id EC7FE22FFA for ; Sat, 17 Oct 2015 10:50:13 +0000 (UTC) Received: by lbbor1 with SMTP id or1sf12944235lbb.2 for ; Sat, 17 Oct 2015 03:50:12 -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=DExVm1eE6ZUAwvtKMaEJ5+wh6qp8brTqejlZXmwvfJ8=; b=Ru1ZrQHg7W+5rcnT4c8juZwTardYxVsjlTYcsVYqapiSNZal+igBQ7xFdFc2UUcd5e Mk6UHCXkquM+Sr14MymdXs0Y3JTYmp0XIV/O4YY4AaQWmS29E4wpTeLOkv4u1SeDX79U kCsrzwOXTXm3kIEY5i6rdi7F/XoWALWRp1fjiEz1IyDPfjvUsu35FVUJKPF/6Q8CKUE0 jn4v0a/LZ1qvVT4qoNw/fVVo9fdZyo0H6fvBc3TdLPHaAv7Rt1yjHSW3THEluoWtoV7K NXyQgmLIKESQbTtAVPQRbXK2GATuXq4YiY4EYI0HtPpKSDd/Leg0jO+RTSWbxQ8FnEoM y32Q== X-Gm-Message-State: ALoCoQmnaZBP/sOn5E2yNHln5Qoo3qfFBgRG/uJDU1XMY2kwS26v6zn6Gk3mTiby9JLG38CaTvbr X-Received: by 10.195.18.100 with SMTP id gl4mr4798887wjd.4.1445079012529; Sat, 17 Oct 2015 03:50:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.26.140 with SMTP id a134ls434559lfa.30.gmail; Sat, 17 Oct 2015 03:50:12 -0700 (PDT) X-Received: by 10.112.130.225 with SMTP id oh1mr10365631lbb.69.1445079012200; Sat, 17 Oct 2015 03:50:12 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id r199si15785306lfe.160.2015.10.17.03.50.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Oct 2015 03:50:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbwb3 with SMTP id wb3so53742112lbb.1 for ; Sat, 17 Oct 2015 03:50:12 -0700 (PDT) X-Received: by 10.112.180.230 with SMTP id dr6mr10369977lbc.72.1445079012038; Sat, 17 Oct 2015 03:50:12 -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 w3csp436452lbq; Sat, 17 Oct 2015 03:50:11 -0700 (PDT) X-Received: by 10.68.237.225 with SMTP id vf1mr22623216pbc.82.1445079010941; Sat, 17 Oct 2015 03:50:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ms6si36091549pbb.247.2015.10.17.03.50.10; Sat, 17 Oct 2015 03:50:10 -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 S1752689AbbJQKty (ORCPT + 30 others); Sat, 17 Oct 2015 06:49:54 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7827 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751320AbbJQKtS (ORCPT ); Sat, 17 Oct 2015 06:49:18 -0400 Received: from 172.24.1.50 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.50]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWX99312; Sat, 17 Oct 2015 18:48:56 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Sat, 17 Oct 2015 18:48:45 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately Date: Sat, 17 Oct 2015 10:48:28 +0000 Message-ID: <1445078910-73699-6-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> References: <1445078910-73699-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.180 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: , This patch introduces basic facilities to support config different slots in a BPF map one by one. nr_indics and indics are introduced into 'struct parse_events_term', where indics is an array of indics which will be configured by this config term, nr_indics is the size of the array. The array is passed to 'struct bpf_map_priv'. To indicate the new type of configuration, BPF_MAP_PRIV_KEY_INDICS is added as a new key type. bpf_map_config_foreach_key() is extended to iterate over those indics instead of all possible keys. Signed-off-by: Wang Nan 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 --- tools/perf/util/bpf-loader.c | 68 +++++++++++++++++++++++++++++++++++++++++- tools/perf/util/parse-events.c | 4 ++- tools/perf/util/parse-events.h | 2 ++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 15cf27a..023fc12 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -638,6 +638,7 @@ int bpf__foreach_tev(struct bpf_object *obj, enum bpf_map_priv_key_type { BPF_MAP_PRIV_KEY_ALL, + BPF_MAP_PRIV_KEY_INDICS, }; enum bpf_map_priv_value_type { @@ -647,6 +648,12 @@ enum bpf_map_priv_value_type { struct bpf_map_priv { struct { enum bpf_map_priv_key_type type; + union { + struct { + size_t nr_indics; + u64 *indics; + } indics; + }; } key; struct { @@ -663,6 +670,8 @@ bpf_map_priv__clear(struct bpf_map *map __maybe_unused, { struct bpf_map_priv *priv = _priv; + if (priv->key.type == BPF_MAP_PRIV_KEY_INDICS) + zfree(&priv->key.indics.indics); free(priv); } @@ -718,6 +727,20 @@ bpf_map_config_foreach_key(struct bpf_map *map, } } return 0; + case BPF_MAP_PRIV_KEY_INDICS: + for (i = 0; i < priv->key.indics.nr_indics; i++) { + u64 _idx = priv->key.indics.indics[i]; + unsigned int idx = (unsigned int)(_idx); + + err = (*func)(name, map_fd, &def, + priv, &idx, arg); + if (err) { + pr_debug("ERROR: failed to insert value to %s[%u]\n", + name, idx); + return err; + } + } + return 0; default: pr_debug("ERROR: keytype for map '%s' invalid\n", name); return -EINVAL; @@ -728,6 +751,28 @@ bpf_map_config_foreach_key(struct bpf_map *map, } } +static int +bpf_map_priv_setkey(struct bpf_map_priv *priv, + struct parse_events_term *term, + const char *map_name) +{ + if (!term->nr_indics) + priv->key.type = BPF_MAP_PRIV_KEY_ALL; + else { + size_t memsz = term->nr_indics * sizeof(term->indics[0]); + + priv->key.indics.indics = malloc(memsz); + if (!priv->key.indics.indics) { + pr_debug("No enough memory to alloc indics for %s\n", + map_name); + return -ENOMEM; + } + memcpy(priv->key.indics.indics, term->indics, memsz); + priv->key.type = BPF_MAP_PRIV_KEY_INDICS; + priv->key.indics.nr_indics = term->nr_indics; + } + return 0; +} static int bpf__config_obj_map_array_value(struct bpf_map *map, @@ -773,7 +818,9 @@ bpf__config_obj_map_array_value(struct bpf_map *map, return -ENOMEM; } - priv->key.type = BPF_MAP_PRIV_KEY_ALL; + err = bpf_map_priv_setkey(priv, term, map_name); + if (err) + return err; priv->value.type = BPF_MAP_PRIV_VAL_VALUE; priv->value.val = term->val.num; return bpf_map__set_private(map, priv, bpf_map_priv__clear); @@ -834,6 +881,24 @@ bpf__config_obj_map(struct bpf_object *obj, goto out; } + if (term->nr_indics) { + struct bpf_map_def def; + + err = bpf_map__get_def(map, &def); + if (err) { + pr_debug("ERROR: Unable to get map definition from '%s'\n", + map_name); + goto out; + } + for (i = 0; i < term->nr_indics; i++) + if (term->indics[i] >= def.max_entries) { + pr_debug("ERROR: index %d too large\n", + (int)term->indics[i]); + err = -E2BIG; + goto out; + } + } + for (i = 0; i < ARRAY_SIZE(bpf_config_map_funcs); i++) { struct bpf_config_map_func *func = &bpf_config_map_funcs[i]; @@ -1004,6 +1069,7 @@ int bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused, { bpf__strerror_head(err, buf, size); bpf__strerror_entry(ENODEV, "Invalid config option: '%s'", term->config) + bpf__strerror_entry(E2BIG, "Index in '%s' too big", term->config) bpf__strerror_entry(ENOENT, "Config target in '%s' is invalid", term->config) bpf__strerror_entry(EBADF, "Map type mismatch in '%s'", term->config) bpf__strerror_entry(EINVAL, "Invalid config value") diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 9f081a1..42ac1cb 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2123,8 +2123,10 @@ void parse_events__free_terms(struct list_head *terms) { struct parse_events_term *term, *h; - list_for_each_entry_safe(term, h, terms, list) + list_for_each_entry_safe(term, h, terms, list) { + free(term->indics); free(term); + } } void parse_events_evlist_error(struct parse_events_evlist *data, diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index d4aa88e..5ba1d3e 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -71,6 +71,8 @@ enum { struct parse_events_term { char *config; + size_t nr_indics; + u64 *indics; union { char *str; u64 num;