From mboxrd@z Thu Jan 1 00:00:00 1970 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=-14.3 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,URIBL_BLOCKED, 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 2D4B7CA9EA0 for ; Fri, 25 Oct 2019 16:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA97721872 for ; Fri, 25 Oct 2019 16:08:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TX3fDtsk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504588AbfJYQIt (ORCPT ); Fri, 25 Oct 2019 12:08:49 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51470 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729004AbfJYQIs (ORCPT ); Fri, 25 Oct 2019 12:08:48 -0400 Received: by mail-wm1-f65.google.com with SMTP id q70so2740096wme.1 for ; Fri, 25 Oct 2019 09:08:47 -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=pUAd15LRZOGwcYUMNoWJDAN25LcrehG7DRhTjZLaCUQ=; b=TX3fDtskQmARxaduJ9lW2PYUO1GrW/aaoetTvbCvWaK7Y6aiSmPid5yYypW/7fPr3S pTzYMe+iwvF8daPxny21YlbO3e25Jvl1JvaJitNVo4nuI3+/Y7OyCh+R7vTHG3kqoofX wjCQUO47OFRuIZkvZ2y1VJArRHsZODtnmnay4fne3iIlZR8JZJRFj2fvJLVqKwvk/zko bWiSWJZGL95li5wQSGofbVYJgioN1O9PVXwrDPm7fDK39g7hfCLzMjBnPcgzXh5is9qw GMXE/6DbCobNqz7yWibJaox8AUyumylmLg9TZ9QrObNXyNlUI8to+hEACV5igUw9BiIN sIUQ== 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=pUAd15LRZOGwcYUMNoWJDAN25LcrehG7DRhTjZLaCUQ=; b=aw8ZybJC1rP37UGmxlF00X7q2HTTPJrOSUukUJHR9oIpYvJgoAik8V1UV69zCJxxf6 53s+UdClMEPAyEp4RVJB1s8FdKA+dnNhwmR9VLQxVs+TarAOG8yyKyzkpE8fMaEz7kHf AVwbPB6631epZJ00unt9UM9YApEGK6t9emxkH6c01CbB2QYfZh12g/Zv+gd2B+XHpla7 A70wUciZMoJaQrIQsWM+YzvTOl/VwysVj6pOOrsR/7V64TbTDZOO8djXCDGMhsMWPw9t gqEYqnHrwcOOHL8UDxdnWPRes/c5+qrq/NL6fJgVYhFZfM7g/SI6GxudBalBgpWysC2b OSFQ== X-Gm-Message-State: APjAAAWJiE20f6oxUiotrzBcwYhnf0HoX+/n91KhDSNCrBTtuPHUQtRn QmuMmomU5yk5mnksUv2J+talq0Kre0IZxvc1NsiQJw== X-Google-Smtp-Source: APXvYqxgEKH4JI31XMApFgp97WIl0mpGTv/DJYlY9rEO7toLsBkrC/1TRbAdMMaeG/BVltRL3FzSpAjcCsP0I2qd/rQ= X-Received: by 2002:a1c:a791:: with SMTP id q139mr4111694wme.155.1572019725853; Fri, 25 Oct 2019 09:08:45 -0700 (PDT) MIME-Version: 1.0 References: <20191023005337.196160-1-irogers@google.com> <20191024190202.109403-1-irogers@google.com> <20191024190202.109403-7-irogers@google.com> <20191025082714.GH31679@krava> In-Reply-To: <20191025082714.GH31679@krava> From: Ian Rogers Date: Fri, 25 Oct 2019 09:08:34 -0700 Message-ID: Subject: Re: [PATCH v3 6/9] perf tools: add destructors for parse event terms To: Jiri Olsa Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andi Kleen , Jin Yao , Adrian Hunter , Kan Liang , John Garry , LKML , netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux , Stephane Eranian Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, Oct 25, 2019 at 1:27 AM Jiri Olsa wrote: > > On Thu, Oct 24, 2019 at 12:01:59PM -0700, Ian Rogers wrote: > > If parsing fails then destructors are ran to clean the up the stack. > > Rename the head union member to make the term and evlist use cases more > > distinct, this simplifies matching the correct destructor. > > nice did not know about this.. looks like it's been in bison for some time, right? Looks like it wasn't in Bison 1 but in Bison 2, we're at Bison 3 and Bison 2 is > 14 years old: https://web.archive.org/web/20050924004158/http://www.gnu.org/software/bison/manual/html_mono/bison.html#Destructor-Decl > > > > Signed-off-by: Ian Rogers > > --- > > tools/perf/util/parse-events.y | 69 +++++++++++++++++++++++----------- > > 1 file changed, 48 insertions(+), 21 deletions(-) > > > > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y > > index 545ab7cefc20..4725b14b9db4 100644 > > --- a/tools/perf/util/parse-events.y > > +++ b/tools/perf/util/parse-events.y > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > #include "pmu.h" > > #include "evsel.h" > > #include "parse-events.h" > > @@ -37,6 +38,25 @@ static struct list_head* alloc_list() > > return list; > > } > > > > +static void free_list_evsel(struct list_head* list_evsel) > > +{ > > + struct perf_evsel *pos, *tmp; > > + > > + list_for_each_entry_safe(pos, tmp, list_evsel, node) { > > + list_del_init(&pos->node); > > + perf_evsel__delete(pos); > > + } > > + free(list_evsel); > > I think you need to iterate 'struct evsel' in here, not 'struct perf_evsel' > > should be: > > struct evsel *evsel, *tmp; > > list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) { > list_del_init(&evsel->core.node); > evsel__delete(evsel); > } Thanks, I'll address this. Ian > thanks, > jirka > > > +} > > + > > +static void free_term(struct parse_events_term *term) > > +{ > > + if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) > > + free(term->val.str); > > + zfree(&term->array.ranges); > > + free(term); > > +} > > + > > static void inc_group_count(struct list_head *list, > > struct parse_events_state *parse_state) > > { > > @@ -66,6 +86,7 @@ static void inc_group_count(struct list_head *list, > > %type PE_VALUE_SYM_TOOL > > %type PE_RAW > > %type PE_TERM > > +%type value_sym > > %type PE_NAME > > %type PE_BPF_OBJECT > > %type PE_BPF_SOURCE > > @@ -76,37 +97,43 @@ static void inc_group_count(struct list_head *list, > > %type PE_EVENT_NAME > > %type PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT > > %type PE_DRV_CFG_TERM > > -%type value_sym > > -%type event_config > > -%type opt_event_config > > -%type opt_pmu_config > > +%destructor { free ($$); } > > %type event_term > > -%type event_pmu > > -%type event_legacy_symbol > > -%type event_legacy_cache > > -%type event_legacy_mem > > -%type event_legacy_tracepoint > > +%destructor { free_term ($$); } > > +%type event_config > > +%type opt_event_config > > +%type opt_pmu_config > > +%destructor { parse_events_terms__delete ($$); } > > +%type event_pmu > > +%type event_legacy_symbol > > +%type event_legacy_cache > > +%type event_legacy_mem > > +%type event_legacy_tracepoint > > +%type event_legacy_numeric > > +%type event_legacy_raw > > +%type event_bpf_file > > +%type event_def > > +%type event_mod > > +%type event_name > > +%type event > > +%type events > > +%type group_def > > +%type group > > +%type groups > > +%destructor { free_list_evsel ($$); } > > %type tracepoint_name > > -%type event_legacy_numeric > > -%type event_legacy_raw > > -%type event_bpf_file > > -%type event_def > > -%type event_mod > > -%type event_name > > -%type event > > -%type events > > -%type group_def > > -%type group > > -%type groups > > +%destructor { free ($$.sys); free ($$.event); } > > %type array > > %type array_term > > %type array_terms > > +%destructor { free ($$.ranges); } > > > > %union > > { > > char *str; > > u64 num; > > - struct list_head *head; > > + struct list_head *list_evsel; > > + struct list_head *list_terms; > > struct parse_events_term *term; > > struct tracepoint_name { > > char *sys; > > -- > > 2.23.0.866.gb869b98d4c-goog > > >