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=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 B74BAC433B4 for ; Thu, 1 Apr 2021 18:07:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9932560FE6 for ; Thu, 1 Apr 2021 18:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236132AbhDASG6 (ORCPT ); Thu, 1 Apr 2021 14:06:58 -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 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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 6D74FC433ED for ; Thu, 1 Apr 2021 13:51:22 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E21856124A for ; Thu, 1 Apr 2021 13:51:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E21856124A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cYETr+yeoMbkMsI7CKDEZ/XdrN/SK2WsC6+XEbH4Kmg=; b=HDiz94nzLGu0e504JGMv/OfC2 Bo1LqIMWzajBjzFUTuBcoIsKp02v6kDiOj7/tX8yYhxNzdcneNR9fPx/m+ZzTjaVu6VA1JNLYHDPV PEwHuY6WGrA6TT0+H5bZvyFq3FkV2n5z5uZGNZbiRa9lbxdXbf2fmzMXXM3DoWCqnHtVGXDTTXVkv YDiq9lmVl3YdoEUttPsi7L/20wdjGkXsB33aIzIYrjkN/YV/OxTcaMIJ6M/xGd2IuBbM9xXLo1+wU rlWfRF2phJvEJN6tgF0HWRbEi+pU47WQw5R1roAZ70122xt3xyTTPUt/dv0+fmfD+EUejZ23JWX3+ hsz27dAlA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lRxhw-009jXK-PY; Thu, 01 Apr 2021 13:50:00 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lRxht-009jWg-QA for linux-arm-kernel@lists.infradead.org; Thu, 01 Apr 2021 13:49:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617284991; 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=au6Pvpn/0yuXLUHRt88+8XS3xxN9kzJ47d8p00O57wlSoDYA1u2cqsKdx3jZW8p0G8xujn hqdRixo/EUEQDPsb+qiIVMCAL662x9PIY/lbAuQlAH9rfN72QuGFKTsjYXXCOwjleamT53 np6pANmFzuMRyrjxyCen6+tL+vJwJBg= 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-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210401_144958_022841_3683945F X-CRM114-Status: GOOD ( 16.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel