From patchwork Thu May 7 08:14:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 219716 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=-17.4 required=3.0 tests=DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL 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 6D3F4C38A24 for ; Thu, 7 May 2020 08:14:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3945120753 for ; Thu, 7 May 2020 08:14:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="U7wRbdfz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726907AbgEGIOy (ORCPT ); Thu, 7 May 2020 04:14:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726701AbgEGIOw (ORCPT ); Thu, 7 May 2020 04:14:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57FFBC061A41 for ; Thu, 7 May 2020 01:14:52 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id h129so6031387ybc.3 for ; Thu, 07 May 2020 01:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4jAiujVPIH0XWZpTZgSL+DGkUTq2TxINaqAiEYunye0=; b=U7wRbdfzR+TPabVXRkSFeJE9tthG2dbucEQJlAe7mIkrJqQjNyRHem0kHXtghq8bnr D5W15KCkFJS8JPclkWuahr8m2Or7W3s1CRJK6fwG+ha+JsvVJK6oHhAhhaQ+53kgckBX jo0+hIoMrvB++vfIC/LRimiKx41T5K6kdLlQi0AWa4ykCIJCFJGXa2NhsIC7LoB8wikT jx/5iUJ6bIJ/75C1HiSa2uzwXOvqkOW/tLz/fSHRtA0uk/PJ/11XwFNOGH3bgv3gXs3n B+2rSOwVUo+gQoTo/Rh8zPvAp6P9EVr9PTU9s/+KCG4AAgfUVIvxV30NhAkerMPUB5+/ 02Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4jAiujVPIH0XWZpTZgSL+DGkUTq2TxINaqAiEYunye0=; b=I9MdsMGLSGYiZ6zTvCM4ANhcZwClAsaTBl1N4fYguoCxZF4dtpMAAMyXqO9GL9wvmE t6pdwaUCZPtwfhkDlC8dyJ8cMyuwfzKpwOrN1RtZTbaQewFxMLDkZ6/4k8YWeAvVA/TB RcEuHcbEhLdkqcOKiflhqiK1bshPBKQwRC+izMvxrW9pSw74fjmcl6DzzC29WTRVGLZj cj2S8RRlNovAMYr9dLVIm4HnFoqi7U81ra/L9C4wiJXvAvOwpNRJgnswSYxyFK9+jO7p 4W/vHtrclcZy7JK6PZ5IqyReHHjXTb+WCDipWiWqA4hONQhXvF6HnXenWgaiIi8ri10z fBVQ== X-Gm-Message-State: AGi0PuY8FTV7/LssqC/8xaoSUPv+FR/5hmzfMTdiJP4Qe/+R930c80y8 q24LXBn2KGqnr+HndIPMUZTf87w9QzvL X-Google-Smtp-Source: APiQypKwLkD+uB2It9ZWT/f91/xVIyTeXDlbilbCRc/Jf9xhtrEOmeGyY8IG713wAfAF70bC8hWyMwFCX2YI X-Received: by 2002:a25:6f56:: with SMTP id k83mr20697937ybc.248.1588839291471; Thu, 07 May 2020 01:14:51 -0700 (PDT) Date: Thu, 7 May 2020 01:14:31 -0700 In-Reply-To: <20200507081436.49071-1-irogers@google.com> Message-Id: <20200507081436.49071-3-irogers@google.com> Mime-Version: 1.0 References: <20200507081436.49071-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [RFC PATCH 2/7] perf metricgroup: change evlist_used to a bitmap From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian , Ian Rogers Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use a bitmap rather than an array of bools. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 2f92dbc05226..dcd175c05872 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -95,7 +95,7 @@ struct egroup { static struct evsel *find_evsel_group(struct evlist *perf_evlist, struct expr_parse_ctx *pctx, struct evsel **metric_events, - bool *evlist_used) + unsigned long *evlist_used) { struct evsel *ev; bool leader_found; @@ -105,7 +105,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, double *val_ptr; evlist__for_each_entry (perf_evlist, ev) { - if (evlist_used[j++]) + if (test_bit(j++, evlist_used)) continue; if (hashmap__find(&pctx->ids, ev->name, (void**)&val_ptr)) { if (!metric_events[i]) @@ -149,7 +149,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, j++; } ev = metric_events[i]; - evlist_used[ev->idx] = true; + set_bit(ev->idx, evlist_used); } return metric_events[0]; @@ -165,13 +165,11 @@ static int metricgroup__setup_events(struct list_head *groups, int ret = 0; struct egroup *eg; struct evsel *evsel; - bool *evlist_used; + unsigned long *evlist_used; - evlist_used = calloc(perf_evlist->core.nr_entries, sizeof(bool)); - if (!evlist_used) { - ret = -ENOMEM; - return ret; - } + evlist_used = bitmap_alloc(perf_evlist->core.nr_entries); + if (!evlist_used) + return -ENOMEM; list_for_each_entry (eg, groups, nd) { struct evsel **metric_events; @@ -209,7 +207,7 @@ static int metricgroup__setup_events(struct list_head *groups, list_add(&expr->nd, &me->head); } - free(evlist_used); + bitmap_free(evlist_used); return ret; }