Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp374820rwr; Wed, 26 Apr 2023 00:04:58 -0700 (PDT) X-Google-Smtp-Source: AKy350am+KSU/bvW8IML9YK+/6bRvnVVtJn0isnYFsD+/kudQkUu2d5s2a9HfwaHDc0MedGoQHj4 X-Received: by 2002:a05:6a21:789e:b0:f5:c6d5:adf5 with SMTP id bf30-20020a056a21789e00b000f5c6d5adf5mr9525687pzc.40.1682492698144; Wed, 26 Apr 2023 00:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682492698; cv=none; d=google.com; s=arc-20160816; b=QkN/ts7pQwuv3CewSuSS5GKPlEAzWPsP2zkwJIMjy/FHbVs7Pxo4PnmeYPFwA9Mn64 UK+68Bf6VyxF8wIFdPbbWY4lmHc24CvssV2d8W2XXQaxV0G9H/rANeGvPwxF4XW7KoLa vNISW2PLqpRvTEVpw5qoaOtj3hBvWF5csHFZYo8oSAUgGkD5ZRzBBQx4gCxThd83EYCZ kz6sTpyXpQ0xQirBkfmXhDUUDW2W84/i9jWOv4GksaN20/WchdLIRKz0bh4eW+v5BP8z y33GNdYzCiTjMs8TnHHqKpVGL7yJzgStXTE8hCyxUnU6bcliZBuvfx9HSvPxzV7bvL+p t56A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=pGMhDh/Xxfc/617r/znj1e9S4uhjiiI/jhf4ibmGn/I=; b=jhLxQBVSjrMkHouMmJFVafBUgjcWRYU3b2xXBaKxlu4l/EZrJA24aocr0EGWAhwl3u tLqQTVO6JGt1/PoKdyJmn/DmYESxAsBasNQrYIy7fGF+GSb8Ku38YfGuL/dF01/eokxn AGLvqi+JSV0Vyrp5HIv9QlY4w9EG+siytryuEF3kx89CfyLr13FMZX4RNtRb/TSHXrQS oGyn/be9NiufwPRKcl73mD3RlWyj5J8Xkt29O9NaP1iaV8JXU1XVXvtJZPwiPlyJcNcH csTRJI7/5m2/65p2jBFJtTX+O3kDBLP3lzd5L5HxmdS18l29HuzPjvBgH/gQDdF/p4Yc 2DNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=FhKZ0DbW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k21-20020a6568d5000000b00518c8895ebfsi15695993pgt.139.2023.04.26.00.04.44; Wed, 26 Apr 2023 00:04:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=FhKZ0DbW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239838AbjDZHEO (ORCPT + 99 others); Wed, 26 Apr 2023 03:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239769AbjDZHDe (ORCPT ); Wed, 26 Apr 2023 03:03:34 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E23EC3581 for ; Wed, 26 Apr 2023 00:02:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5529a6f9f28so101470707b3.2 for ; Wed, 26 Apr 2023 00:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682492557; x=1685084557; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pGMhDh/Xxfc/617r/znj1e9S4uhjiiI/jhf4ibmGn/I=; b=FhKZ0DbW98MwDW0YYRBsJErMz6DD3KZB3q5XqWRRfggSzXjVsDbhf1nBN17cgMT4bj cpMm9pfQsbCSWHdFa+1SzDjDuMaiWZjrYLDHpkDJNeRaTdnF2HB9S956VcP/iEJ8+o3R KA23U2jsY/mZlYdg4AJhxyF/2zOAzV9vUUAVoK2QzhcjPT+qhhofQh0DxcJsePhv5bcx MMtqxDVJIwhctmaofnNPxZMOJOOOl0o0gP7fsKw2nUXXW8jseH05+zKAKWXGeX433JpL 0L3MydqE9IAuyp4Muf6R+jq/OuuTqmNjy3IIjKrC9UCHWfiNTgl8gYbOK4yjB4NMWuX4 FIKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682492557; x=1685084557; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pGMhDh/Xxfc/617r/znj1e9S4uhjiiI/jhf4ibmGn/I=; b=DuA+3GztQOrscXsTUMrP2Gfxoewv8G3/qvXtQLfi3QrNXTR25oGX4d7NmToLVD8hMb OmvCQwq136DiGhvW0yTjaK0Te0qh7xchObgbYITOl/U9ICwKDnw/SpcRVewp8xTDuHy+ bN+f/EgVKMt1OJh9VOv48G9LUeDQZDa+IMZUHVKeu311fOygjAoQTJL4+s39VMuRl74Q pX2EHqIzirce7WkcPB7QVHJ37CWgp81QlujwMhDfEm92kPaqcUcIpagSApRZXGYAntCt V4uVRt3+60ptwpYN67UfuvsFBxKVtGrNTOr6Fb8lW/mRzmcOx3WUXyJzLOPvot42m0iS 4v3Q== X-Gm-Message-State: AAQBX9dg6wu2aFGfMGnqSSikwsdDW1n2wTimqG1vUtpbsERo4mp3mueJ 74Llqpiu5n2o7dg7Jn0/YZ4WxgYKPuPj X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:144f:e890:2b29:48d9]) (user=irogers job=sendgmr) by 2002:a81:4425:0:b0:552:d924:a304 with SMTP id r37-20020a814425000000b00552d924a304mr9106383ywa.4.1682492557276; Wed, 26 Apr 2023 00:02:37 -0700 (PDT) Date: Wed, 26 Apr 2023 00:00:22 -0700 In-Reply-To: <20230426070050.1315519-1-irogers@google.com> Message-Id: <20230426070050.1315519-13-irogers@google.com> Mime-Version: 1.0 References: <20230426070050.1315519-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v1 12/40] perf test: Roundtrip name, don't assume 1 event per name From: Ian Rogers To: Arnaldo Carvalho de Melo , Kan Liang , Ahmad Yasin , Peter Zijlstra , Ingo Molnar , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Florian Fischer , Rob Herring , Zhengjun Xing , John Garry , Kajol Jain , Sumanth Korikkar , Thomas Richter , Tiezhu Yang , Ravi Bangoria , Leo Yan , Yang Jihong , James Clark , Suzuki Poulouse , Kang Minchul , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Opening hardware names and a legacy cache event on a hybrid PMU opens it on each PMU. Parsing and checking indexes fails, as the parsed index is double the expected. Avoid checking the index by just comparing the names immediately after the parse. This change removes hard coded hybrid logic and removes assumptions about the expansion of an event. On hybrid the PMUs may or may not support an event and so using a distance isn't a consistent solution. Signed-off-by: Ian Rogers --- tools/perf/tests/evsel-roundtrip-name.c | 119 ++++++++++-------------- 1 file changed, 49 insertions(+), 70 deletions(-) diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c index e94fed901992..15ff86f9da0b 100644 --- a/tools/perf/tests/evsel-roundtrip-name.c +++ b/tools/perf/tests/evsel-roundtrip-name.c @@ -4,114 +4,93 @@ #include "parse-events.h" #include "tests.h" #include "debug.h" -#include "pmu.h" -#include "pmu-hybrid.h" -#include #include static int perf_evsel__roundtrip_cache_name_test(void) { - char name[128]; - int type, op, err = 0, ret = 0, i, idx; - struct evsel *evsel; - struct evlist *evlist = evlist__new(); + int ret = TEST_OK; - if (evlist == NULL) - return -ENOMEM; - - for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { - for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { + for (int type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { + for (int op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { /* skip invalid cache type */ if (!evsel__is_cache_op_valid(type, op)) continue; - for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { - __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name)); - err = parse_event(evlist, name); - if (err) - ret = err; - } - } - } - - idx = 0; - evsel = evlist__first(evlist); + for (int res = 0; res < PERF_COUNT_HW_CACHE_RESULT_MAX; res++) { + char name[128]; + struct evlist *evlist = evlist__new(); + struct evsel *evsel; + int err; - for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { - for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { - /* skip invalid cache type */ - if (!evsel__is_cache_op_valid(type, op)) - continue; + if (evlist == NULL) { + pr_debug("Failed to alloc evlist"); + return TEST_FAIL; + } + __evsel__hw_cache_type_op_res_name(type, op, res, + name, sizeof(name)); - for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { - __evsel__hw_cache_type_op_res_name(type, op, i, name, sizeof(name)); - if (evsel->core.idx != idx) + err = parse_event(evlist, name); + if (err) { + pr_debug("Failure to parse cache event '%s' possibly as PMUs don't support it", + name); + evlist__delete(evlist); continue; - - ++idx; - - if (strcmp(evsel__name(evsel), name)) { - pr_debug("%s != %s\n", evsel__name(evsel), name); - ret = -1; } - - evsel = evsel__next(evsel); + evlist__for_each_entry(evlist, evsel) { + if (strcmp(evsel__name(evsel), name)) { + pr_debug("%s != %s\n", evsel__name(evsel), name); + ret = TEST_FAIL; + } + } + evlist__delete(evlist); } } } - - evlist__delete(evlist); return ret; } -static int __perf_evsel__name_array_test(const char *const names[], int nr_names, - int distance) +static int perf_evsel__name_array_test(const char *const names[], int nr_names) { - int i, err; - struct evsel *evsel; - struct evlist *evlist = evlist__new(); + int ret = TEST_OK; - if (evlist == NULL) - return -ENOMEM; + for (int i = 0; i < nr_names; ++i) { + struct evlist *evlist = evlist__new(); + struct evsel *evsel; + int err; - for (i = 0; i < nr_names; ++i) { + if (evlist == NULL) { + pr_debug("Failed to alloc evlist"); + return TEST_FAIL; + } err = parse_event(evlist, names[i]); if (err) { pr_debug("failed to parse event '%s', err %d\n", names[i], err); - goto out_delete_evlist; + evlist__delete(evlist); + ret = TEST_FAIL; + continue; } - } - - err = 0; - evlist__for_each_entry(evlist, evsel) { - if (strcmp(evsel__name(evsel), names[evsel->core.idx / distance])) { - --err; - pr_debug("%s != %s\n", evsel__name(evsel), names[evsel->core.idx / distance]); + evlist__for_each_entry(evlist, evsel) { + if (strcmp(evsel__name(evsel), names[i])) { + pr_debug("%s != %s\n", evsel__name(evsel), names[i]); + ret = TEST_FAIL; + } } + evlist__delete(evlist); } - -out_delete_evlist: - evlist__delete(evlist); - return err; + return ret; } -#define perf_evsel__name_array_test(names, distance) \ - __perf_evsel__name_array_test(names, ARRAY_SIZE(names), distance) - static int test__perf_evsel__roundtrip_name_test(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - int err = 0, ret = 0; - - if (perf_pmu__has_hybrid() && perf_pmu__hybrid_mounted("cpu_atom")) - return perf_evsel__name_array_test(evsel__hw_names, 2); + int err = 0, ret = TEST_OK; - err = perf_evsel__name_array_test(evsel__hw_names, 1); + err = perf_evsel__name_array_test(evsel__hw_names, PERF_COUNT_HW_MAX); if (err) ret = err; - err = __perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1, 1); + err = perf_evsel__name_array_test(evsel__sw_names, PERF_COUNT_SW_DUMMY + 1); if (err) ret = err; -- 2.40.1.495.gc816e09b53d-goog