Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp850680ybt; Fri, 26 Jun 2020 13:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzms5qXMoeRt55c10xEtLxjJYOefxBZjlYL2bTDFA+MJqpKIX0i8lrOUtSr5s+xuYhVRFBK X-Received: by 2002:a17:906:a892:: with SMTP id ha18mr4200856ejb.462.1593202065255; Fri, 26 Jun 2020 13:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593202065; cv=none; d=google.com; s=arc-20160816; b=a1cvqgbdsOM7vNrSvoxO35HfQ4ERXWp6qyrrV4DHKqhMMyq4hiQgITdo6p4yxan4oL Mz72uFLG6EjCjIJYT7pAywqNA7taGDk9eYsnZBD5lSW72BkPubWIRladh/bHDQIpg8Wt gTQTeg7Z9VDJDxqtKSadnipymUzOSgJk8PQCglpiB136RfeGO9Jf42RI4hT7cZBtSIQH 74FgiSNeKMDjRew9+aP+wXi8HLLbeJEqFlyn4yc/lJyNVzYv+CWuSnm121cl95qKtCMa foJBrsW2XOKRKZrcenrt+o7e/+vMxGaQsRKHODtMzFmAc/UpI+sRogk1cJ7hkqk83d50 XGVw== 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=h9iScij+INx6Ii2zxgR7WLn6FdOxcA8dMusmQA4u5sY=; b=dTs8pYZW7rxtRhL+2gVqelv58LlqElQ4PMEzYrBp6sYRCfRwrPRItfczh2u09o0ZrL KsEp9LyZaZ6HqCua0nP4bGvVyegXr9HNnx8siw6eqM2DO2S3dK2MHaV6ATpjdTd83Qv+ rKu9fpm7Zbx/Z9/MCqW32vgHG8D9bclGVFP/dblbu1w39hp+m8y3D6qyMhWHsMQZ9dEE +SI4BQLBAwjACIP+roQnBcvmgkKYwgA0zCzkYQqPykIuD/e0nju95WiElePKep3PhQJi mZ5KOf86Zv+HeoGuMnulgmSAUIr2LocIWuyaVetUfDdEiWg78g0x1Hc8cVI5to/S2uAI py2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tvUBVP6P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si7956254ejx.659.2020.06.26.13.07.21; Fri, 26 Jun 2020 13:07:45 -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=@google.com header.s=20161025 header.b=tvUBVP6P; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726028AbgFZUE6 (ORCPT + 99 others); Fri, 26 Jun 2020 16:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbgFZUEy (ORCPT ); Fri, 26 Jun 2020 16:04:54 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 486EBC03E979 for ; Fri, 26 Jun 2020 13:04:54 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id b6so10584679wrs.11 for ; Fri, 26 Jun 2020 13:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h9iScij+INx6Ii2zxgR7WLn6FdOxcA8dMusmQA4u5sY=; b=tvUBVP6PjUWl2uLBtAteWs3IWlbQDnwNilBs3dQXP+1lqrHxkD2lWaaujiQT5GZH4j zAtTK982aiVxeuauy2bEb8jQdCp+8asaSvTwDml4dcVMEcgqe4zHBp9WyrwSM1BuBMwV Y+edcZxacethaLifNJWB5dzd6UTU70zvd9jEdj6c7T7ZmChPCFDAihhonloAGfYmJ0r6 jdz4nXnwGQbS1H3porL7kVhAI0UxDSBpVh8xrlYCPG4R7v4/vcT60dcYvmfJcgnD1L/R VFfoX7yZBf/CJzpupnr+8TPEotfvlIq4PKXY1diZquRDphcAH04MdXloX4iKK73hP5IW jU8w== 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=h9iScij+INx6Ii2zxgR7WLn6FdOxcA8dMusmQA4u5sY=; b=XrLw2iJ9eWqhS3dI7RKDJk70JS1sG4mbyDiG4yE06xapsFWvZ7fgTcGv3HwYtpWoSK v7L2fpZAoGgcyVbLp6jNy68fld16TjwccjWUyuxH3MIu/eV2xmQ6si9gachp/eITrInv AVF9ha36EGskoa6DBpA4k/o9sEWcHPA45ZFPyeslMkq+UMYoj9zojwkjPiY1JDcZHoHa Uy89Klj7+FjFuDcE/2fKs37y2OTEoLb+3T8Epm9pBlhJ+8UM1mUaxjuAZPCyxeroPZRt /zwdmm7UxjWgz7WRH7oMhSNKXX0V4Z324TF/VvI51yta+K2VPhaq541QyRQDGjBZHrUG ADUw== X-Gm-Message-State: AOAM530ZHep+GXnsiFX8FzFWhitqF1GoXaASUlQBv+p1WBvkltpoHnkh AphRpz6S06daX0hTEP+7owZwmvk70fJgFSALupQ/wA== X-Received: by 2002:adf:e5d0:: with SMTP id a16mr5240030wrn.48.1593201892707; Fri, 26 Jun 2020 13:04:52 -0700 (PDT) MIME-Version: 1.0 References: <20200626194720.2915044-1-jolsa@kernel.org> <20200626194720.2915044-3-jolsa@kernel.org> In-Reply-To: <20200626194720.2915044-3-jolsa@kernel.org> From: Ian Rogers Date: Fri, 26 Jun 2020 13:04:41 -0700 Message-ID: Subject: Re: [PATCH 02/10] perf tools: Add struct expr_parse_data to keep expr value To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Andi Kleen , Kajol Jain , John Garry , "Paul A. Clarke" , 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, Jun 26, 2020 at 12:47 PM Jiri Olsa wrote: > > Adding struct expr_parse_data to keep expr value > instead of just simple double pointer, so we can > store more data for ID in following changes. Nit, expr_parse_data sounds a bit like data that is created just at parse time. Perhaps id_data, for data associated with an id? Thanks, Ian > Signed-off-by: Jiri Olsa > --- > tools/perf/tests/expr.c | 3 ++- > tools/perf/util/expr.c | 20 ++++++++++---------- > tools/perf/util/expr.h | 4 ++++ > tools/perf/util/metricgroup.c | 2 +- > 4 files changed, 17 insertions(+), 12 deletions(-) > > diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c > index 82aa32fcab64..e64461f1a24c 100644 > --- a/tools/perf/tests/expr.c > +++ b/tools/perf/tests/expr.c > @@ -18,8 +18,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) > { > + struct expr_parse_data *val_ptr; > const char *p; > - double val, *val_ptr; > + double val; > int ret; > struct expr_parse_ctx ctx; > > diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c > index a02937e5f3ac..7573b21e73df 100644 > --- a/tools/perf/util/expr.c > +++ b/tools/perf/util/expr.c > @@ -35,30 +35,30 @@ static bool key_equal(const void *key1, const void *key2, > /* Caller must make sure id is allocated */ > int expr__add_val(struct expr_parse_ctx *ctx, const char *name, double val) > { > - double *val_ptr = NULL, *old_val = NULL; > + struct expr_parse_data *data_ptr = NULL, *old_data = NULL; > char *old_key = NULL; > int ret; > > if (val != 0.0) { > - val_ptr = malloc(sizeof(double)); > - if (!val_ptr) > + data_ptr = malloc(sizeof(*data_ptr)); > + if (!data_ptr) > return -ENOMEM; > - *val_ptr = val; > + data_ptr->val = val; > } > - ret = hashmap__set(&ctx->ids, name, val_ptr, > - (const void **)&old_key, (void **)&old_val); > + ret = hashmap__set(&ctx->ids, name, data_ptr, > + (const void **)&old_key, (void **)&old_data); > free(old_key); > - free(old_val); > + free(old_data); > return ret; > } > > int expr__get_id(struct expr_parse_ctx *ctx, const char *id, double *val_ptr) > { > - double *data; > + struct expr_parse_data *data; > > if (!hashmap__find(&ctx->ids, id, (void **)&data)) > return -1; > - *val_ptr = (data == NULL) ? 0.0 : *data; > + *val_ptr = (data == NULL) ? 0.0 : data->val; > return 0; > } > > @@ -119,7 +119,7 @@ int expr__parse(double *final_val, struct expr_parse_ctx *ctx, > int expr__find_other(const char *expr, const char *one, > struct expr_parse_ctx *ctx, int runtime) > { > - double *old_val = NULL; > + struct expr_parse_data *old_val = NULL; > char *old_key = NULL; > int ret = __expr__parse(NULL, ctx, expr, EXPR_OTHER, runtime); > > diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h > index 35bdc609cf55..f9f16efe76bc 100644 > --- a/tools/perf/util/expr.h > +++ b/tools/perf/util/expr.h > @@ -15,6 +15,10 @@ struct expr_parse_ctx { > struct hashmap ids; > }; > > +struct expr_parse_data { > + double val; > +}; > + > struct expr_scanner_ctx { > int start_token; > int runtime; > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > index 82fecb5a302d..85e7fa2e2707 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -138,7 +138,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, > unsigned long *evlist_used) > { > struct evsel *ev, *current_leader = NULL; > - double *val_ptr; > + struct expr_parse_data *val_ptr; > int i = 0, matched_events = 0, events_to_match; > const int idnum = (int)hashmap__size(&pctx->ids); > > -- > 2.25.4 >