Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp756874ybk; Fri, 15 May 2020 12:41:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpv0J7G8xUsnx7ctPiUlG61ipozuP2fw3CXs2wbjNLjwt9VC0pwyib4mFFgihhzpX498L4 X-Received: by 2002:a17:906:ad4:: with SMTP id z20mr4448471ejf.82.1589571703998; Fri, 15 May 2020 12:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589571703; cv=none; d=google.com; s=arc-20160816; b=mXbRtk1+JP6dfErMUgcf3r8FSgNzEDI8tVinB8sWOIjxN1IJK+T4T08HpnzaaUdog3 D/zIQwEpLvZ3pcjDxH5hvGa+Z39xg/5xewfl/KCvV8J4t6TlU2MSmNXXOlwE9AHdtMLG DYEzX8Irj/iOWar5B/tpZsW5pGAx+8r730SMN8aSRfxJBrMqMDEmpcAU6DWpoQuioPsp ZF/BsyrG3zHs3Ld1pt8k73v01K1ngPVBYmhsAznhxV9zEz85EoYYWKwPfUWpFpdlqljE 91Yxu1/SIrnZqMEtfstmv7wA2ZFDbwj0tnsEJKTJZ60l7aEIfZvrwTtnUJdWtGuFpmBk Pz6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4BQMLiV7/BzZ4YarNv+2ABNpKJB9d3AIj9UHyBIXc0M=; b=W3NRO4b3tQCITE0yf4jrjqMDf7F+ugH2NKy7LDp4rgmAfa8RpYJw/BQOUwSLgNfU61 w4iDJlapUGhJnNZW+tyltpIBdFQ5kzAbomAjiLkytxWZqFUN/xlRiBWekcVgbk8Mhm7o QPqCKdDxHu6YKurlfGF8LiTdbLLxY+Tfqj/3RfwpT6tWhv5JreMT3wXk34f6aC8cD3kG 6vGK1dpsrY1/fCJzF8Wn/+IMRdjDDQOn2+NYsD9USFQ7HWgxMgHJqSNPmmBlwYB59rTq UGfOrZEIFMTSWvRLT1oDwfYCXFwRQKSLN5ga/kp6ZpONmIdkaURZvKVQb5pJdcsnb3VT v3fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CO76H2fP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si1862709edm.144.2020.05.15.12.41.20; Fri, 15 May 2020 12:41:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CO76H2fP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726367AbgEOTjq (ORCPT + 99 others); Fri, 15 May 2020 15:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726168AbgEOTjq (ORCPT ); Fri, 15 May 2020 15:39:46 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED38C061A0C; Fri, 15 May 2020 12:39:45 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id d7so2972737qtn.11; Fri, 15 May 2020 12:39:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4BQMLiV7/BzZ4YarNv+2ABNpKJB9d3AIj9UHyBIXc0M=; b=CO76H2fPe/gmTLc9vA/Uw8T86Xg+X8HMd1/oZ+N6jGgzKfFJnhkyEa0nCAgaB1mhOO DS7bHDWmBfMxfgn08jVH+Ir45lUztMhcQsKK6BIas2HN5uB2bXHFSvRCAPJTiQGOQpff 8o1iiDoziuQ4jhCJOf+TFMrADges9ONOoEZt9BciOzw2MEqpOjL0ZykeC8mK0ncvI02r zR/bHvcZVqlGOJhphjK5Uc2jl/D0QC2yq+8aa5hP2L3mXrivKoyb6Tvg2UrM3Iziugk7 bpB2fbKaW4SnaN/5w3V0tEBkwP4xVvkY8lPghTePTtbTZE4OcvYtJbpUmSRUjdbJ9Imy EU3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4BQMLiV7/BzZ4YarNv+2ABNpKJB9d3AIj9UHyBIXc0M=; b=WlLEPQTydNCDS+kVwktSixGKBH0WGSzJgAF43p9bvAkP2Az5JS8y7R+cfaYG7YcBwa JL4YubRiovq2rLk/XLcCQqbeqeGtmqngGOVVVKHcYgA+Sow6JCyvMHxUx72Mf1fO60IP fR9I562UxOkmAr+3aim8lHR5DC5YoT+KnO01ISGZZw4PrPjE4Bxd0fwNT4TvOKc89cx7 ebrjB1czNV7F/1FUaptWPymWmive8JAqj//N2DpEu//OO6wuP7g08DVt75KuePICNuxe Pu7l0F8lfotKCZZybYvWHLCM19s3GX3ZDs/4MCSOOQ5Z1n+Qv3aX3IYawzEK1X6r+kWs MKwg== X-Gm-Message-State: AOAM533HP9nFS/6GlmSFtRwPXixp7potRstIPGk5wMRmor9P3uYL0HKs GRvz1yBYGTm2WxYxu7UekslB9m51Nq5n1ueZR8s= X-Received: by 2002:aed:2f02:: with SMTP id l2mr5209605qtd.117.1589571585047; Fri, 15 May 2020 12:39:45 -0700 (PDT) MIME-Version: 1.0 References: <20200515165007.217120-1-irogers@google.com> <20200515165007.217120-8-irogers@google.com> In-Reply-To: <20200515165007.217120-8-irogers@google.com> From: Andrii Nakryiko Date: Fri, 15 May 2020 12:39:34 -0700 Message-ID: Subject: Re: [PATCH v2 7/7] perf expr: Migrate expr ids table to a hashmap To: Ian Rogers Cc: 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 , Adrian Hunter , Leo Yan , open list , Networking , bpf , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 15, 2020 at 9:51 AM Ian Rogers wrote: > > Use a hashmap between a char* string and a double* value. While bpf's > hashmap entries are size_t in size, we can't guarantee sizeof(size_t) >= > sizeof(double). Avoid a memory allocation when gathering ids by making 0.0 > a special value encoded as NULL. > > Original map suggestion by Andi Kleen: > https://lore.kernel.org/lkml/20200224210308.GQ160988@tassilo.jf.intel.com/ > and seconded by Jiri Olsa: > https://lore.kernel.org/lkml/20200423112915.GH1136647@krava/ > > Signed-off-by: Ian Rogers > --- > tools/perf/tests/expr.c | 40 ++++++----- > tools/perf/tests/pmu-events.c | 25 +++---- > tools/perf/util/expr.c | 129 +++++++++++++++++++--------------- > tools/perf/util/expr.h | 26 +++---- > tools/perf/util/expr.y | 22 +----- > tools/perf/util/metricgroup.c | 87 +++++++++++------------ > tools/perf/util/stat-shadow.c | 49 ++++++++----- > 7 files changed, 197 insertions(+), 181 deletions(-) > > diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c > index 3f742612776a..5e606fd5a2c6 100644 > --- a/tools/perf/tests/expr.c > +++ b/tools/perf/tests/expr.c > @@ -19,11 +19,9 @@ static int test(struct expr_parse_ctx *ctx, const char *e, double val2) > int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) > { > const char *p; > - const char **other; > - double val; > - int i, ret; > + double val, *val_ptr; > + int ret; > struct expr_parse_ctx ctx; > - int num_other; > > expr__ctx_init(&ctx); > expr__add_id(&ctx, "FOO", 1); > @@ -52,25 +50,29 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) > ret = expr__parse(&val, &ctx, p, 1); > TEST_ASSERT_VAL("missing operand", ret == -1); > > + hashmap__clear(&ctx.ids); hashmap__clear() will free up memory allocated for hashmap itself and hash entries, but not keys/values. Unless it's happening somewhere else, you'll need to do something similar to expr__ctx_clear() below? Same below for another "lone" hashmap_clear() call. > TEST_ASSERT_VAL("find other", > - expr__find_other("FOO + BAR + BAZ + BOZO", "FOO", &other, &num_other, 1) == 0); [...]