Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp264444pxf; Thu, 25 Mar 2021 03:40:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWWiWJMcQa8iFlAwUGkrzs4aeiJCKU7lZrSyNFGEI2BojlUz5bxzfMl/Hcw+9AaZ+Z8o82 X-Received: by 2002:a17:906:3d62:: with SMTP id r2mr8474303ejf.488.1616668814730; Thu, 25 Mar 2021 03:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616668814; cv=none; d=google.com; s=arc-20160816; b=HSFW0UZZrCImakmjKrKovI+FxNWE87yOq9BgQy74cgWXzUaRkBMpqJ/jK3jmxb18X5 RmEuf1OAcCkBIhyq8cLtwptPoIFjiYuAYHwkJYbvLPEClNZ7XZ8cbsUk6Mkzegzy4IN+ uYBkeMNF2veYssKb5K3KTHbhbUB+jajyKOiNQETGHIrCxuHzuq3RXCJVDXefew0yjmFq 540cEl58h1e09QbEJk7LdYrj8ZR9l1QBktBaLMyUWGzXOosbJVswS/gcCk5Fmazwfi67 wLZpHQAFu5nz/Xcbr8lRkC9iDTX7kGTP/kS0IP0Qjwuv3OtojFjo2yyRQt7BtEtNR6z2 p53g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=cLhenI0UI0Z6fo+6un3xxnl18eyKLBr48G4SOln3kRQ=; b=cp/iLpuVgdywCPQ28ebasC5+7nTDFz/NQOSd6fSkNSAaB4lNd0mOFsXrQuNgQ6bafz eg2H19/s3QFaWrYKSS9mzCRbzF8Y4op+qWqUIJxWL8K+FiY+T3S1O3hv9jKFQBEoZZCG UDnXP2+7Gx0btMnhB689CCqemWia1hBTs211oyntC9TlosYUX13Sc7hiTmOye+rgUAcW jz2wqqSNr3k8ucBgqSMsoAnjzeW4cDK/miYjeQY2VM/ed3Y3wTomryhmd87fWgFxHcCL r4AuBS3HAA/afBjdqj+zQNVDGIGXpYGnGUPUt0/dt4j94RsV0ZzWz6Le5xsHhj1yEiLg 1dBA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r27si3778535edw.299.2021.03.25.03.39.50; Thu, 25 Mar 2021 03:40:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230266AbhCYKi5 (ORCPT + 99 others); Thu, 25 Mar 2021 06:38:57 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:14900 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230139AbhCYKiT (ORCPT ); Thu, 25 Mar 2021 06:38:19 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4F5hNk02YtzkfWX; Thu, 25 Mar 2021 18:36:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Thu, 25 Mar 2021 18:38:07 +0800 From: John Garry To: , , , , , , , , , , CC: , , , , , , , John Garry Subject: [PATCH v2 2/6] perf test: Handle metric reuse in pmu-events parsing test Date: Thu, 25 Mar 2021 18:33:14 +0800 Message-ID: <1616668398-144648-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1616668398-144648-1-git-send-email-john.garry@huawei.com> References: <1616668398-144648-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pmu-events parsing test does not handle metric reuse at all. Introduce some simple handling to resolve metrics who reference other metrics. Signed-off-by: John Garry --- tools/perf/tests/pmu-events.c | 80 +++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 0ca6a5a53523..20b6bf14f7f7 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -12,6 +12,7 @@ #include "util/evlist.h" #include "util/expr.h" #include "util/parse-events.h" +#include "metricgroup.h" struct perf_pmu_test_event { /* used for matching against events from generated pmu-events.c */ @@ -471,6 +472,70 @@ static void expr_failure(const char *msg, pr_debug("On expression %s\n", pe->metric_expr); } +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); + 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; + +} + static int test_parsing(void) { struct pmu_events_map *cpus_map = perf_pmu__find_map(NULL); @@ -488,7 +553,9 @@ static int test_parsing(void) break; j = 0; for (;;) { + struct metric *metric, *tmp; struct hashmap_entry *cur; + LIST_HEAD(compound_list); size_t bkt; pe = &map->table[j++]; @@ -504,6 +571,13 @@ static int test_parsing(void) continue; } + if (resolve_metric_simple(&ctx, &compound_list, map, + pe->metric_name)) { + expr_failure("Could not resolve metrics", map, pe); + ret++; + goto exit; /* Don't tolerate errors due to severity */ + } + /* * Add all ids with a made up value. The value may * trigger divide by zero when subtracted and so try to @@ -519,6 +593,11 @@ static int test_parsing(void) ret++; } + list_for_each_entry_safe(metric, tmp, &compound_list, list) { + expr__add_ref(&ctx, &metric->metric_ref); + free(metric); + } + if (expr__parse(&result, &ctx, pe->metric_expr, 0)) { expr_failure("Parse failed", map, pe); ret++; @@ -527,6 +606,7 @@ static int test_parsing(void) } } /* TODO: fail when not ok */ +exit: return ret == 0 ? TEST_OK : TEST_SKIP; } -- 2.26.2