Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp696435pxf; Thu, 1 Apr 2021 11:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4GGKc9ShDkDaR2lQdS5uw8dVsm6iyt1lil2+PNfdNvSXfZZynzNgKTaBKTBH6ml5tAh0f X-Received: by 2002:a17:906:2b46:: with SMTP id b6mr10273677ejg.521.1617300497855; Thu, 01 Apr 2021 11:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617300497; cv=none; d=google.com; s=arc-20160816; b=tNZJYr8FaL7OR0Lnlonh9JAApowfIWBLqPymGcBXgdqEAbDMQiFLKu6OW1xHeeMc61 zo6inDtn7hSQL1rHe6EvHU9CSMN5N0vyKNOHwbfZ4540PxNi5JLu8RnRnISqVorim5zI SatwEter5yTEq3E2GKWdrwYuTVnJgbsvEUkHPdJlFREclEt+5VCwZsvlSpnQBX09I4jW tvf1mYbxKxfoj44k3x6vTSdMcB6cTvVEsd164S95NDu9LvSrwENnYaHsn5x4BcuETTT3 sYD33XM/1wUve6jE09KbQhrOr/M4p5tlHADPOujXyrbkL9KoM2dvgHb285nNyZBXjQCg H2wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=J59mviOinQtGL5knvSCm5IlcQ3vnWMamNF8NZHi8YX8=; b=xUdqwB4NSARbHRVc1/R73Yy+P6GUnA50UD+fafP196Jd8VCqsjxJLjxyngb3MoxXvE u/yJPctgTc4QvZ0PH4iW1NRYYG3RGF3PQjOjX1OfdX398cbSOAtcnATzNIkci2GEB/vz U3KRJo3aSAHT7xgqE5eh2gwnt7EiIICq+Z2B8Je10cYClbzjn0Kfi9pc33/MQHRV1h9m x6qlnJIcMJ8PJjl9Vj5PUhWqhldtGZ2RpnAQ1Zly476fsRew1AhhtpKOX67soJxHvbL2 U+fGxn8fz5woBNDauaFtLRzC0yj7mW4qbS0vkLqaGnADv1k9TPZKB3/F0wWsbUTBx0/i 9eFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fZfXPLpb; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx19si4663298edb.512.2021.04.01.11.07.55; Thu, 01 Apr 2021 11:08:17 -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=@redhat.com header.s=mimecast20190719 header.b=fZfXPLpb; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235027AbhDASGy (ORCPT + 99 others); Thu, 1 Apr 2021 14:06:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22542 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234724AbhDARwT (ORCPT ); Thu, 1 Apr 2021 13:52:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617299539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J59mviOinQtGL5knvSCm5IlcQ3vnWMamNF8NZHi8YX8=; b=fZfXPLpbm8pCVZs85AGWkDFp7+IKLrVvw2MyQg/3Td62LPZWXIbquRwe0+QEr8ddJHbkcH KNT2N3T+GpLR/jkug3yYVEA8GqT5VCYVGz1SDQYPOSJ0jPUGbrLuaFEyyZ7hM/r3MeN70/ IZIRMH9w70Ik/VTwV3sdBmRWAOAncDo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-271-1HT9BmJQP1SZUDCW7XGgkw-1; Thu, 01 Apr 2021 09:49:48 -0400 X-MC-Unique: 1HT9BmJQP1SZUDCW7XGgkw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4348C1009E29; Thu, 1 Apr 2021 13:49:45 +0000 (UTC) Received: from krava (unknown [10.40.193.98]) by smtp.corp.redhat.com (Postfix) with SMTP id 3A6B35C237; Thu, 1 Apr 2021 13:49:40 +0000 (UTC) Date: Thu, 1 Apr 2021 15:49:40 +0200 From: Jiri Olsa To: John Garry Cc: will@kernel.org, mathieu.poirier@linaro.org, leo.yan@linaro.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, irogers@google.com, linuxarm@huawei.com, kjain@linux.ibm.com, kan.liang@linux.intel.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, zhangshaokun@hisilicon.com, pc@us.ibm.com Subject: Re: [PATCH v2 2/6] perf test: Handle metric reuse in pmu-events parsing test Message-ID: References: <1616668398-144648-1-git-send-email-john.garry@huawei.com> <1616668398-144648-3-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1616668398-144648-3-git-send-email-john.garry@huawei.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 06:33:14PM +0800, John Garry wrote: SNIP > +struct metric { > + struct list_head list; > + struct metric_ref metric_ref; > +}; > + > +static int resolve_metric_simple(struct expr_parse_ctx *pctx, > + struct list_head *compound_list, > + struct pmu_events_map *map, > + const char *metric_name) > +{ > + struct hashmap_entry *cur, *cur_tmp; > + struct metric *metric, *tmp; > + size_t bkt; > + bool all; > + int rc; > + > + do { > + all = true; > + hashmap__for_each_entry_safe((&pctx->ids), cur, cur_tmp, bkt) { > + struct metric_ref *ref; > + struct pmu_event *pe; > + > + pe = metrcgroup_find_metric(cur->key, map); > + if (!pe) > + continue; > + > + if (!strcmp(metric_name, (char *)cur->key)) { > + pr_warning("Recursion detected for metric %s\n", metric_name); > + rc = -1; > + goto out_err; > + } > + > + all = false; > + > + /* The metric key itself needs to go out.. */ > + expr__del_id(pctx, cur->key); > + > + metric = malloc(sizeof(*metric)); > + if (!metric) { > + rc = -ENOMEM; > + goto out_err; > + } > + > + ref = &metric->metric_ref; > + ref->metric_name = pe->metric_name; > + ref->metric_expr = pe->metric_expr; > + list_add_tail(&metric->list, compound_list); > + > + rc = expr__find_other(pe->metric_expr, NULL, pctx, 0); so this might add new items to pctx->ids, I think you need to restart the iteration as we do it in __resolve_metric otherwise you could miss some new keys jirka > + if (rc) > + goto out_err; > + } > + } while (!all); > + > + return 0; > + > +out_err: > + list_for_each_entry_safe(metric, tmp, compound_list, list) > + free(metric); > + > + return rc; > + > +} SNIP