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=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 39CB9C433DB for ; Mon, 15 Mar 2021 16:11:34 +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 85A0864E0C for ; Mon, 15 Mar 2021 16:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85A0864E0C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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=Z+VPGWDtWDmbqACgKPS6cVVvmTw9fVEysfd+i69rcsw=; b=bQa4Y/op2znn4aox41LSoL1cp hSOCfIOHYPERwEIqy9d/pSExeFH7BgBhGN0/pjad7XM4JcX5RKpnkjKjQM62sSdbVd9zIk/MyxoMj quM6u27W7TEkFHmrmgXKTZ1UHpp9HaeAc58JmCwpXylQ3/M38vS7Fmyu7yEwzURyzyYFMf4zU02Mx PnU2RNpgy7YFqp3MGLiTUbB3y8fhpsPyL/1fDY45KXoL5sU+kNsrfMTFyxyIw4s7Y3exWI9M5Dkm8 kwiboMIoNrmU+TBjOgxwBW8JgYvmdBOHTs6BKfUdJ/hm65vliS7EEy5Oe9DcJ+wgBqRPdCVFWMgsP a9MlC8lfg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLpn8-00GK7Z-Kt; Mon, 15 Mar 2021 16:10:02 +0000 Received: from mail-qk1-x72d.google.com ([2607:f8b0:4864:20::72d]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lLpn0-00GK6O-7N for linux-arm-kernel@lists.infradead.org; Mon, 15 Mar 2021 16:09:57 +0000 Received: by mail-qk1-x72d.google.com with SMTP id l132so32176502qke.7 for ; Mon, 15 Mar 2021 09:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dn/BYdPmPgpvcXruqRlax0DqbdC/XbjJpw3iTQ9fPJs=; b=JCGTGkeIH3bXXwKj5NEZMJj68zxYSDeRq84Frf+K2wUc5D1C+igHbEK1yKZnPGpGKb YqYuyWj3CkXKI00iIA5LSSidrZzDbNSxuDumModgqSHYQi4EdajujbWyHKNbCLcNZVnT ISiLWD2lZeo0QMDGELKlRBFpc3BQywfpG1OkbDGKuHiT/4NxdxX5R1R77SshR50KIM8Y s/+d7t/6tV8Bom6C1F0hNvtBP81v/f5QwistYualIopP5YiGK+ZE9atdVmHBrxE1CSVJ lknsdEZTeV9D6vmqz1IFt0P480EUTB6MrePLta5zepTDLBPjSJpeXO/6Gc79daPAhHte b8dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dn/BYdPmPgpvcXruqRlax0DqbdC/XbjJpw3iTQ9fPJs=; b=U6UC2jHZNni+Vyd0dJ/wDxMpRhY9o7CWe0gmGknAbC5r3A246NIRbhgqKsuWQoYD+B oYhB6v6SRRcg4aLi2dgByOnxMqccXnW/WfxrTUsbdSDo6MgzU2dOKxnSrj5ooc9cxMzL GMXcMSPKc1z+xUMBYj5YXHKcBWoaLBUDsV2WXm2QgNdmcgXdoXgTBixoaikoo5WvtzCD Gv9W81WqA0+TKQPuHJ/O+mEyv6f5Ellade1LXk6nyZ7SPASgA9tA93Bxsj7/wszoxrEP HAgP/fMyX1aKQ+XEqDLveAhe1scO4uVIXBRaBEsRLSBFO+VbYmVfMU/x9BIkRk9wxQtP xPLw== X-Gm-Message-State: AOAM530mD4wAdLhuQU0BIzSYpCyTemdq6X6cSaVLT9NjIrLJjSCGl4Rv jmkFxNI1vytwUjDOuK/Ohw== X-Google-Smtp-Source: ABdhPJzhTS+wIL85cPmmVJCrnVbLEw2+1k4TqV13oxzV2fECiaKQ7BxpFlKwR7l2bHxz2ObUJwb2GQ== X-Received: by 2002:a05:620a:2206:: with SMTP id m6mr25563559qkh.176.1615824589604; Mon, 15 Mar 2021 09:09:49 -0700 (PDT) Received: from gabell (209-6-122-159.s2973.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [209.6.122.159]) by smtp.gmail.com with ESMTPSA id r17sm11015224qtx.62.2021.03.15.09.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 09:09:48 -0700 (PDT) Date: Mon, 15 Mar 2021 12:09:46 -0400 From: Masayoshi Mizuma To: Rob Herring Cc: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Ian Rogers , Alexander Shishkin , honnappa.nagarahalli@arm.com, Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 08/10] perf: arm64: Add test for userspace counter access on heterogeneous systems Message-ID: <20210315160946.k7l5dwlgsbaeytd6@gabell> References: <20210311000837.3630499-1-robh@kernel.org> <20210311000837.3630499-9-robh@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210311000837.3630499-9-robh@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210315_160954_699548_BACA0DB2 X-CRM114-Status: GOOD ( 40.26 ) 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 Wed, Mar 10, 2021 at 05:08:35PM -0700, Rob Herring wrote: > Userspace counter access only works on heterogeneous systems with some > restrictions. The userspace process must be pinned to a homogeneous > subset of CPUs and must open the corresponding PMU for those CPUs. This > commit adds a test implementing these requirements. > > Signed-off-by: Rob Herring > --- > v6: > - Add a check on cap_user_rdpmc > v5: > - Adapt to libperf mmap API changes > v4: > - Update perf_evsel__mmap params > v2: > - Drop all but heterogeneous test as others covered by libperf tests > - Rework to use libperf > --- > tools/perf/arch/arm64/include/arch-tests.h | 7 + > tools/perf/arch/arm64/tests/Build | 1 + > tools/perf/arch/arm64/tests/arch-tests.c | 4 + > tools/perf/arch/arm64/tests/user-events.c | 177 +++++++++++++++++++++ > 4 files changed, 189 insertions(+) > create mode 100644 tools/perf/arch/arm64/tests/user-events.c > > diff --git a/tools/perf/arch/arm64/include/arch-tests.h b/tools/perf/arch/arm64/include/arch-tests.h > index 90ec4c8cb880..380ad34a3f09 100644 > --- a/tools/perf/arch/arm64/include/arch-tests.h > +++ b/tools/perf/arch/arm64/include/arch-tests.h > @@ -2,11 +2,18 @@ > #ifndef ARCH_TESTS_H > #define ARCH_TESTS_H > > +#include > + > #ifdef HAVE_DWARF_UNWIND_SUPPORT > struct thread; > struct perf_sample; > +int test__arch_unwind_sample(struct perf_sample *sample, > + struct thread *thread); > #endif I got the following compile error with aarch64: # make tools/perf ... GEN /root/linux/tools/perf/python/perf.so CC /root/linux/tools/perf/arch/arm64/tests/user-events.o CC /root/linux/tools/perf/arch/arm64/tests/arch-tests.o In file included from arch/arm64/tests/arch-tests.c:4: /root/linux/tools/perf/arch/arm64/include/arch-tests.h:10:5: error: redundant redeclaration of 'test__arch_unwind_sample' [-Werror=redundant-decls] int test__arch_unwind_sample(struct perf_sample *sample, ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from arch/arm64/tests/arch-tests.c:3: /root/linux/tools/perf/tests/tests.h:140:5: note: previous declaration of 'test__arch_unwind_sample' was here int test__arch_unwind_sample(struct perf_sample *sample, ^~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[8]: *** [/root/linux/tools/build/Makefile.build:97: /root/linux/tools/perf/arch/arm64/tests/arch-tests.o] Error 1 That's because test__arch_unwind_sample() is in tools/perf/tests/tests.h as well. tools/perf/tests/tests.h: ... #if defined(__arm__) || defined(__aarch64__) #ifdef HAVE_DWARF_UNWIND_SUPPORT struct thread; struct perf_sample; int test__arch_unwind_sample(struct perf_sample *sample, struct thread *thread); #endif #endif I'm not sure the best way to resolve the error, but the error is gone with the following additional patch. Could you take a look it? diff --git a/tools/perf/arch/arm64/include/arch-tests.h b/tools/perf/arch/arm64/include/arch-tests.h index ddfa7460e1e1..7ff2e29bdc1c 100644 --- a/tools/perf/arch/arm64/include/arch-tests.h +++ b/tools/perf/arch/arm64/include/arch-tests.h @@ -4,13 +4,6 @@ #include -#ifdef HAVE_DWARF_UNWIND_SUPPORT -struct thread; -struct perf_sample; -int test__arch_unwind_sample(struct perf_sample *sample, - struct thread *thread); -#endif - extern struct test arch_tests[]; int test__rd_pinned(struct test __maybe_unused *test, int __maybe_unused subtest); Thanks! Masa > > extern struct test arch_tests[]; > +int test__rd_pinned(struct test __maybe_unused *test, > + int __maybe_unused subtest); > + > > #endif > diff --git a/tools/perf/arch/arm64/tests/Build b/tools/perf/arch/arm64/tests/Build > index a61c06bdb757..3f9a20c17fc6 100644 > --- a/tools/perf/arch/arm64/tests/Build > +++ b/tools/perf/arch/arm64/tests/Build > @@ -1,4 +1,5 @@ > perf-y += regs_load.o > perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o > > +perf-y += user-events.o > perf-y += arch-tests.o > diff --git a/tools/perf/arch/arm64/tests/arch-tests.c b/tools/perf/arch/arm64/tests/arch-tests.c > index 5b1543c98022..80ce7bd3c16d 100644 > --- a/tools/perf/arch/arm64/tests/arch-tests.c > +++ b/tools/perf/arch/arm64/tests/arch-tests.c > @@ -10,6 +10,10 @@ struct test arch_tests[] = { > .func = test__dwarf_unwind, > }, > #endif > + { > + .desc = "Pinned CPU user counter access", > + .func = test__rd_pinned, > + }, > { > .func = NULL, > }, > diff --git a/tools/perf/arch/arm64/tests/user-events.c b/tools/perf/arch/arm64/tests/user-events.c > new file mode 100644 > index 000000000000..c8efc6b369e6 > --- /dev/null > +++ b/tools/perf/arch/arm64/tests/user-events.c > @@ -0,0 +1,177 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "pmu.h" > +#include "debug.h" > +#include "tests/tests.h" > +#include "arch-tests.h" > + > +static int run_test(struct perf_evsel *evsel) > +{ > + int n; > + volatile int tmp = 0; > + u64 delta, i, loops = 1000; > + struct perf_counts_values counts = { .val = 0 }; > + > + for (n = 0; n < 6; n++) { > + u64 stamp, now; > + > + perf_evsel__read(evsel, 0, 0, &counts); > + stamp = counts.val; > + > + for (i = 0; i < loops; i++) > + tmp++; > + > + perf_evsel__read(evsel, 0, 0, &counts); > + now = counts.val; > + loops *= 10; > + > + delta = now - stamp; > + pr_debug("%14d: %14llu\n", n, (long long)delta); > + > + if (!delta) > + break; > + } > + return delta ? 0 : -1; > +} > + > +static struct perf_pmu *pmu_for_cpu(int cpu) > +{ > + int acpu, idx; > + struct perf_pmu *pmu = NULL; > + > + while ((pmu = perf_pmu__scan(pmu)) != NULL) { > + if (pmu->is_uncore) > + continue; > + perf_cpu_map__for_each_cpu(acpu, idx, pmu->cpus) > + if (acpu == cpu) > + return pmu; > + } > + return NULL; > +} > + > +static bool pmu_is_homogeneous(void) > +{ > + int core_cnt = 0; > + struct perf_pmu *pmu = NULL; > + > + while ((pmu = perf_pmu__scan(pmu)) != NULL) { > + if (!pmu->is_uncore && !perf_cpu_map__empty(pmu->cpus)) > + core_cnt++; > + } > + return core_cnt == 1; > +} > + > +static int libperf_print(enum libperf_print_level level, > + const char *fmt, va_list ap) > +{ > + (void)level; > + return vfprintf(stderr, fmt, ap); > +} > + > +static struct perf_evsel *perf_init(struct perf_event_attr *attr) > +{ > + int err; > + struct perf_thread_map *threads; > + struct perf_evsel *evsel; > + struct perf_event_mmap_page *pc; > + > + libperf_init(libperf_print); > + > + threads = perf_thread_map__new_dummy(); > + if (!threads) { > + pr_err("failed to create threads\n"); > + return NULL; > + } > + > + perf_thread_map__set_pid(threads, 0, 0); > + > + evsel = perf_evsel__new(attr); > + if (!evsel) { > + pr_err("failed to create evsel\n"); > + goto out_thread; > + } > + > + err = perf_evsel__open(evsel, NULL, threads); > + if (err) { > + pr_err("failed to open evsel\n"); > + goto out_open; > + } > + > + if (perf_evsel__mmap(evsel, 0)) { > + pr_err("failed to mmap evsel\n"); > + goto out_mmap; > + } > + > + pc = perf_evsel__mmap_base(evsel, 0, 0); > + if (!pc->cap_user_rdpmc) { > + pr_err("userspace access not enabled\n"); > + goto out_mmap; > + } > + > + return evsel; > + > +out_mmap: > + perf_evsel__close(evsel); > +out_open: > + perf_evsel__delete(evsel); > +out_thread: > + perf_thread_map__put(threads); > + return NULL; > +} > + > +int test__rd_pinned(struct test __maybe_unused *test, > + int __maybe_unused subtest) > +{ > + int cpu, cputmp, ret = -1; > + struct perf_evsel *evsel; > + struct perf_event_attr attr = { > + .config = 0x8, /* Instruction count */ > + .config1 = 0, /* 32-bit counter */ > + .exclude_kernel = 1, > + }; > + cpu_set_t cpu_set; > + struct perf_pmu *pmu; > + > + if (pmu_is_homogeneous()) > + return TEST_SKIP; > + > + cpu = sched_getcpu(); > + pmu = pmu_for_cpu(cpu); > + if (!pmu) > + return -1; > + attr.type = pmu->type; > + > + CPU_ZERO(&cpu_set); > + perf_cpu_map__for_each_cpu(cpu, cputmp, pmu->cpus) > + CPU_SET(cpu, &cpu_set); > + if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) > + pr_err("Could not set affinity\n"); > + > + evsel = perf_init(&attr); > + if (!evsel) > + return -1; > + > + perf_cpu_map__for_each_cpu(cpu, cputmp, pmu->cpus) { > + CPU_ZERO(&cpu_set); > + CPU_SET(cpu, &cpu_set); > + if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) > + pr_err("Could not set affinity\n"); > + > + pr_debug("Running on CPU %d\n", cpu); > + > + ret = run_test(evsel); > + if (ret) > + break; > + } > + > + perf_evsel__close(evsel); > + perf_evsel__delete(evsel); > + return ret; > +} > -- > 2.27.0 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel