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=-17.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 5231EC432BE for ; Mon, 23 Aug 2021 12:23:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36F3961078 for ; Mon, 23 Aug 2021 12:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237265AbhHWMYb (ORCPT ); Mon, 23 Aug 2021 08:24:31 -0400 Received: from foss.arm.com ([217.140.110.172]:52734 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236754AbhHWMYa (ORCPT ); Mon, 23 Aug 2021 08:24:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D044101E; Mon, 23 Aug 2021 05:23:47 -0700 (PDT) Received: from [10.57.43.155] (unknown [10.57.43.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F3863F766; Mon, 23 Aug 2021 05:23:44 -0700 (PDT) Subject: Re: [PATCH v1 3/3] perf auxtrace arm: Support compat_auxtrace_mmap__{read_head|write_tail} To: Leo Yan References: <20210809112727.596876-1-leo.yan@linaro.org> <20210809112727.596876-4-leo.yan@linaro.org> Cc: Arnaldo Carvalho de Melo , Mike Leach , Will Deacon , Peter Zijlstra , Adrian Hunter , Andi Kleen , Mark Rutland , Catalin Marinas , Russell King , linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Li Huafei , Jin Yao , Riccardo Mancini , Ingo Molnar , Namhyung Kim , Suzuki K Poulose , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , John Garry , coresight@lists.linaro.org, linux-kernel@vger.kernel.org From: James Clark Message-ID: <6ce4057a-57cf-501d-6449-2069cd00ba57@arm.com> Date: Mon, 23 Aug 2021 13:23:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210809112727.596876-4-leo.yan@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/08/2021 12:27, Leo Yan wrote: > When the tool runs with compat mode on Arm platform, the kernel is in > 64-bit mode and user space is in 32-bit mode; the user space can use > instructions "ldrd" and "strd" for 64-bit value atomicity. > > This patch adds compat_auxtrace_mmap__{read_head|write_tail} for arm > building, it uses "ldrd" and "strd" instructions to ensure accessing > atomicity for aux head and tail. The file arch/arm/util/auxtrace.c is > built for arm and arm64 building, these two functions are not needed for > arm64, so check the compiler macro "__arm__" to only include them for > arm building. > > Signed-off-by: Leo Yan > --- > tools/perf/arch/arm/util/auxtrace.c | 32 +++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util/auxtrace.c > index b187bddbd01a..c7c7ec0812d5 100644 > --- a/tools/perf/arch/arm/util/auxtrace.c > +++ b/tools/perf/arch/arm/util/auxtrace.c > @@ -107,3 +107,35 @@ struct auxtrace_record > *err = 0; > return NULL; > } > + > +#if defined(__arm__) > +u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm) > +{ > + struct perf_event_mmap_page *pc = mm->userpg; > + u64 result; > + > + __asm__ __volatile__( > +" ldrd %0, %H0, [%1]" > + : "=&r" (result) > + : "r" (&pc->aux_head), "Qo" (pc->aux_head) > + ); > + > + return result; > +} Hi Leo, I see that this is a duplicate of the atomic read in arch/arm/include/asm/atomic.h For x86, it's possible to include tools/include/asm/atomic.h, but that doesn't include arch/arm/include/asm/atomic.h and there are some other #ifdefs that might make it not so easy for Arm. Just wondering if you considered trying to include the existing one? Or decided that it was easier to duplicate it? Other than that, I have tested that the change works with a 32bit build with snapshot and normal mode. Reviewed by: James Clark Tested by: James Clark > + > +int compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) > +{ > + struct perf_event_mmap_page *pc = mm->userpg; > + > + /* Ensure all reads are done before we write the tail out */ > + smp_mb(); > + > + __asm__ __volatile__( > +" strd %2, %H2, [%1]" > + : "=Qo" (pc->aux_tail) > + : "r" (&pc->aux_tail), "r" (tail) > + ); > + > + return 0; > +} > +#endif > 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=-18.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 33440C4338F for ; Mon, 23 Aug 2021 12:25:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 F20F46138E for ; Mon, 23 Aug 2021 12:25:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F20F46138E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:Cc:References:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xMOxsgt4FFf+boPnjJsgUE1kDBJh3NLgLVK/PS/9Sic=; b=hkz+CVVplgtTE3q0A66cHpy3pp e8yGWDs0msYuQ0crELCqi7IClBJYt7J9xvda8oqqEds0VpZAI2CKPcyJ6nAvPHqdQ55I2C9drWvlk zHAu0Sh9Gwes2jiTZVJNt5xFKFiDszHux4j0RRGIx7Sbm/P11nJamE/Fo4NH/k2j9fON8Ib097TAZ zFjoGnrFIiZvMbzgarsFEcq3x9qhYxmdDJcIJkotyOMos30GgD2Ja429fPJ2i1GYpQnMsiRln4xZb vp3BtS7fzhXlWp+7BlYHm0hlTb7c/lxnAEcafpZNi0XF4uMyz7yoZD1SPNHxfoYX7H8oWZlavYkIU x9VCDI1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI8zk-00GlKo-Cp; Mon, 23 Aug 2021 12:24:04 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI8zg-00GlGb-9x for linux-arm-kernel@lists.infradead.org; Mon, 23 Aug 2021 12:24:01 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D044101E; Mon, 23 Aug 2021 05:23:47 -0700 (PDT) Received: from [10.57.43.155] (unknown [10.57.43.155]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F3863F766; Mon, 23 Aug 2021 05:23:44 -0700 (PDT) Subject: Re: [PATCH v1 3/3] perf auxtrace arm: Support compat_auxtrace_mmap__{read_head|write_tail} To: Leo Yan References: <20210809112727.596876-1-leo.yan@linaro.org> <20210809112727.596876-4-leo.yan@linaro.org> Cc: Arnaldo Carvalho de Melo , Mike Leach , Will Deacon , Peter Zijlstra , Adrian Hunter , Andi Kleen , Mark Rutland , Catalin Marinas , Russell King , linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Li Huafei , Jin Yao , Riccardo Mancini , Ingo Molnar , Namhyung Kim , Suzuki K Poulose , Mathieu Poirier , Alexander Shishkin , Jiri Olsa , John Garry , coresight@lists.linaro.org, linux-kernel@vger.kernel.org From: James Clark Message-ID: <6ce4057a-57cf-501d-6449-2069cd00ba57@arm.com> Date: Mon, 23 Aug 2021 13:23:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210809112727.596876-4-leo.yan@linaro.org> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210823_052400_504227_061454B1 X-CRM114-Status: GOOD ( 28.13 ) 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 09/08/2021 12:27, Leo Yan wrote: > When the tool runs with compat mode on Arm platform, the kernel is in > 64-bit mode and user space is in 32-bit mode; the user space can use > instructions "ldrd" and "strd" for 64-bit value atomicity. > > This patch adds compat_auxtrace_mmap__{read_head|write_tail} for arm > building, it uses "ldrd" and "strd" instructions to ensure accessing > atomicity for aux head and tail. The file arch/arm/util/auxtrace.c is > built for arm and arm64 building, these two functions are not needed for > arm64, so check the compiler macro "__arm__" to only include them for > arm building. > > Signed-off-by: Leo Yan > --- > tools/perf/arch/arm/util/auxtrace.c | 32 +++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util/auxtrace.c > index b187bddbd01a..c7c7ec0812d5 100644 > --- a/tools/perf/arch/arm/util/auxtrace.c > +++ b/tools/perf/arch/arm/util/auxtrace.c > @@ -107,3 +107,35 @@ struct auxtrace_record > *err = 0; > return NULL; > } > + > +#if defined(__arm__) > +u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm) > +{ > + struct perf_event_mmap_page *pc = mm->userpg; > + u64 result; > + > + __asm__ __volatile__( > +" ldrd %0, %H0, [%1]" > + : "=&r" (result) > + : "r" (&pc->aux_head), "Qo" (pc->aux_head) > + ); > + > + return result; > +} Hi Leo, I see that this is a duplicate of the atomic read in arch/arm/include/asm/atomic.h For x86, it's possible to include tools/include/asm/atomic.h, but that doesn't include arch/arm/include/asm/atomic.h and there are some other #ifdefs that might make it not so easy for Arm. Just wondering if you considered trying to include the existing one? Or decided that it was easier to duplicate it? Other than that, I have tested that the change works with a 32bit build with snapshot and normal mode. Reviewed by: James Clark Tested by: James Clark > + > +int compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) > +{ > + struct perf_event_mmap_page *pc = mm->userpg; > + > + /* Ensure all reads are done before we write the tail out */ > + smp_mb(); > + > + __asm__ __volatile__( > +" strd %2, %H2, [%1]" > + : "=Qo" (pc->aux_tail) > + : "r" (&pc->aux_tail), "r" (tail) > + ); > + > + return 0; > +} > +#endif > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel