From nobody Wed Dec 31 12:29:11 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 983A3C4332F for ; Thu, 2 Nov 2023 23:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjKBXkV (ORCPT ); Thu, 2 Nov 2023 19:40:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjKBXkS (ORCPT ); Thu, 2 Nov 2023 19:40:18 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5F4191; Thu, 2 Nov 2023 16:40:15 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6b1e46ca282so1612356b3a.2; Thu, 02 Nov 2023 16:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698968415; x=1699573215; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=nwx33ziTZV4oUTDb3pCxYB5gse6/L8kFAcjyGJ3wPjU=; b=ardE/e/OFV1WVFlgbsyEk9GhQwbAaJNkEvpDjOTNdlItw7+NYESIYN3Vn17Cloj2k4 cPmFj8wN9jveXutC5MFUtmUyJSFm8JvoEfoCaD+6pDN7YT8GWsysXFvlKzDCCGdPhCSl tfrTiODYbaSi3Ro6R9AX/xmmRshyH8PZJl2NrDkDzEP44YLkvaE2yt1JBeX+ogX4Wk/Y rjYSCJdLKrcPJHSNEEw/PUi7QxiLqkHaS++nSbkeojENcXzdOoXduw3Jtq8AAcqtEBfe fwNV0eNdpbvklD7pEojClnt5DsB6plw3VdsAGNB8m7ikCiQkYVT8ujczEqD0yZvPmK6v LTAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698968415; x=1699573215; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nwx33ziTZV4oUTDb3pCxYB5gse6/L8kFAcjyGJ3wPjU=; b=OPEl1va01NKi7Lj1xTYUeU0BH4r7G9eXiuH9/gWioXvceab81gA8FNYjSK4hi4+h97 bGEtozcf3YibqW/3EK0Oh+sKWq9eCHN7IVgbTzEGBwZyv6iCyQT7Bsg434o/snUrZaIM zre31VgRmXa3mC6L6g3gs7qgHAyOu8gJs+jW15650cKrVRiOIjNADjPpmmfzLNLCxKwA GByUQDs3axuNhLUJ+eXQxMGzIAqvfYEGsPinuR5XsGXnKbGZQhTgez5QPb6POVJDEn5v wxZDL4bOG0PfQ/nICzTAXDUA3VZCFhcydLg5T34C2MtSwHsxjEjyirxOi6DhA2hGRMFo FR0A== X-Gm-Message-State: AOJu0YznBYFQBZ0cfM0AfvZq7wVZvEu12jAOTj4kpbe/UYc5t4E76K0s Av9uKz+gX4hSTz4stdKNLAg= X-Google-Smtp-Source: AGHT+IFRS21vfiNTeBTx4JqrE7f8vfAvs3pKAEuVgNnJ8sC6kaivycMOu4gEyZ/kviWnLj7RWvebeg== X-Received: by 2002:a05:6a21:35c2:b0:181:219f:4a76 with SMTP id ba2-20020a056a2135c200b00181219f4a76mr8749304pzc.38.1698968414935; Thu, 02 Nov 2023 16:40:14 -0700 (PDT) Received: from bangji.corp.google.com ([2620:15c:2c0:5:ea22:bed1:d67b:af04]) by smtp.gmail.com with ESMTPSA id 184-20020a6308c1000000b005bd2b3a03eesm266410pgi.6.2023.11.02.16.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 16:40:14 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Thomas Richter Subject: [PATCH] perf test: Simplify object code reading test Date: Thu, 2 Nov 2023 16:40:13 -0700 Message-ID: <20231102234013.4188687-1-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It tries cycles (or cpu-clock on s390) event with exclude_kernel bit to open. But other arch on a VM can fail with the hardware event and need to fallback to the software event in the same way. So let's get rid of the cpuid check and use generic fallback mechanism using an array of event candidates. Now event in the odd index excludes the kernel so use that for the return value. Cc: Thomas Richter Signed-off-by: Namhyung Kim Tested-by: James Clark --- tools/perf/tests/code-reading.c | 76 ++++++++++----------------------- 1 file changed, 23 insertions(+), 53 deletions(-) diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-readin= g.c index 3af81012014e..047ba297c6fa 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -511,38 +511,6 @@ static void fs_something(void) } } =20 -#ifdef __s390x__ -#include "header.h" // for get_cpuid() -#endif - -static const char *do_determine_event(bool excl_kernel) -{ - const char *event =3D excl_kernel ? "cycles:u" : "cycles"; - -#ifdef __s390x__ - char cpuid[128], model[16], model_c[16], cpum_cf_v[16]; - unsigned int family; - int ret, cpum_cf_a; - - if (get_cpuid(cpuid, sizeof(cpuid))) - goto out_clocks; - ret =3D sscanf(cpuid, "%*[^,],%u,%[^,],%[^,],%[^,],%x", &family, model_c, - model, cpum_cf_v, &cpum_cf_a); - if (ret !=3D 5) /* Not available */ - goto out_clocks; - if (excl_kernel && (cpum_cf_a & 4)) - return event; - if (!excl_kernel && (cpum_cf_a & 2)) - return event; - - /* Fall through: missing authorization */ -out_clocks: - event =3D excl_kernel ? "cpu-clock:u" : "cpu-clock"; - -#endif - return event; -} - static void do_something(void) { fs_something(); @@ -583,8 +551,10 @@ static int do_test_code_reading(bool try_kcore) int err =3D -1, ret; pid_t pid; struct map *map; - bool have_vmlinux, have_kcore, excl_kernel =3D false; + bool have_vmlinux, have_kcore; struct dso *dso; + const char *events[] =3D { "cycles", "cycles:u", "cpu-clock", "cpu-clock:= u", NULL }; + int evidx =3D 0; =20 pid =3D getpid(); =20 @@ -618,7 +588,7 @@ static int do_test_code_reading(bool try_kcore) =20 /* No point getting kernel events if there is no kernel object */ if (!have_vmlinux && !have_kcore) - excl_kernel =3D true; + evidx++; =20 threads =3D thread_map__new_by_tid(pid); if (!threads) { @@ -646,7 +616,7 @@ static int do_test_code_reading(bool try_kcore) goto out_put; } =20 - while (1) { + while (events[evidx]) { const char *str; =20 evlist =3D evlist__new(); @@ -657,7 +627,7 @@ static int do_test_code_reading(bool try_kcore) =20 perf_evlist__set_maps(&evlist->core, cpus, threads); =20 - str =3D do_determine_event(excl_kernel); + str =3D events[evidx]; pr_debug("Parsing event '%s'\n", str); ret =3D parse_event(evlist, str); if (ret < 0) { @@ -675,32 +645,32 @@ static int do_test_code_reading(bool try_kcore) =20 ret =3D evlist__open(evlist); if (ret < 0) { - if (!excl_kernel) { - excl_kernel =3D true; - /* - * Both cpus and threads are now owned by evlist - * and will be freed by following perf_evlist__set_maps - * call. Getting reference to keep them alive. - */ - perf_cpu_map__get(cpus); - perf_thread_map__get(threads); - perf_evlist__set_maps(&evlist->core, NULL, NULL); - evlist__delete(evlist); - evlist =3D NULL; - continue; - } + evidx++; =20 - if (verbose > 0) { + if (events[evidx] =3D=3D NULL && verbose > 0) { char errbuf[512]; evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); pr_debug("perf_evlist__open() failed!\n%s\n", errbuf); } =20 - goto out_put; + /* + * Both cpus and threads are now owned by evlist + * and will be freed by following perf_evlist__set_maps + * call. Getting reference to keep them alive. + */ + perf_cpu_map__get(cpus); + perf_thread_map__get(threads); + perf_evlist__set_maps(&evlist->core, NULL, NULL); + evlist__delete(evlist); + evlist =3D NULL; + continue; } break; } =20 + if (events[evidx] =3D=3D NULL) + goto out_put; + ret =3D evlist__mmap(evlist, UINT_MAX); if (ret < 0) { pr_debug("evlist__mmap failed\n"); @@ -721,7 +691,7 @@ static int do_test_code_reading(bool try_kcore) err =3D TEST_CODE_READING_NO_KERNEL_OBJ; else if (!have_vmlinux && !try_kcore) err =3D TEST_CODE_READING_NO_VMLINUX; - else if (excl_kernel) + else if (evidx % 2) err =3D TEST_CODE_READING_NO_ACCESS; else err =3D TEST_CODE_READING_OK; --=20 2.42.0.869.gea05f2083d-goog