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.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 1970DC4338F for ; Tue, 10 Aug 2021 09:27:51 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 352F960EBD for ; Tue, 10 Aug 2021 09:27:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 352F960EBD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=prevas.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E1D9482916; Tue, 10 Aug 2021 11:27:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="GMcSHAjQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E22182916; Tue, 10 Aug 2021 11:27:46 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on071e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::71e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 58BCB807F3 for ; Tue, 10 Aug 2021 11:27:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A/j1K1HyMJPW+nSO/x9UTuRho8XpFDDekNJX87xe4g9L3L4WGbhpTkA2eFUDkRCcva/9Avp5i6sIPCimHKQ/m/nPkTVmIyL3JmlITCRoUGdPiID/i+1/HT0rRa8g1s42YxMRPADtkuWqXwO7yFLwRxHW5+7gxGUF0bhKhEQA7aaQaSZx0zjngaAApVgksuhFkKzf8T36QCwfuY0les1ieKJWPh9IbWOe4sWgW1zLbZjgGSs55kltK6FeTQhqC5binGdxEOW898iQK2lWQQ2dOSryViex0KvE2rMzAsXhr/7WoC2bL7mgFQGrwWAt0/5JWz/epomVlTYlnSNhOszYAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aq4zU00uG649jVJgDRsTRXm7fkCrLjKFp2YqQRRuxy4=; b=Hc8U8UHSeDgmpxartlxYZEZhGMVKT6I6NogLsQmNFdNJoD1LZDPScTzKfi8f0/uwlJ2CZ/DfJVpHkHRgDtweEkFKmTCRVPjl8TuBa7pzhdO6mbyRSwoRmWSOjTFp16P/+KbuVJ2UOq2zWg8rwhvcVyDgrNJvpdNQtVlromqp3NgNobj4pWDpUN4JRuGi8RDj7apDQjVs4ykGd3KPZRcupMXx21qWECCqz611M5CypB00RSHSDHG6BUOJItWlclTvdnHDuOwIZRG0meirAh/wRNKM33+Pm2INsHPuPwDOQW+vALc290DH1ouV3dCPzriwlOh2sluVUkXPwGXufgfaPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aq4zU00uG649jVJgDRsTRXm7fkCrLjKFp2YqQRRuxy4=; b=GMcSHAjQeftPKd98xjctvU9Q3CQ4xfrcEu01UT3kdovERm500IR/tkuarpLpEhdsc9PyB71guPtAcdpYy10VRox3ZR/IzkVIFQHPpKScI3rrJfJPtx0seU3Ii2S12SWUrIse3xHs8b2/AcXglztNB1d4601GLr9W4BET5GTkyHc= Authentication-Results: konsulko.com; dkim=none (message not signed) header.d=none;konsulko.com; dmarc=none action=none header.from=prevas.dk; Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB2163.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:de::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.17; Tue, 10 Aug 2021 09:27:40 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::fc83:36a5:db02:3dbb]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::fc83:36a5:db02:3dbb%7]) with mapi id 15.20.4394.023; Tue, 10 Aug 2021 09:27:40 +0000 Subject: Re: [PATCH v2 2/3] arm64: memset-arm64: Use simple memset when cache is disabled To: Stefan Roese , u-boot@lists.denx.de Cc: Wolfgang Denk , sjg@chromium.org, trini@konsulko.com References: <20210810071358.1279581-1-sr@denx.de> <20210810071358.1279581-3-sr@denx.de> From: Rasmus Villemoes Message-ID: Date: Tue, 10 Aug 2021 11:27:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 In-Reply-To: <20210810071358.1279581-3-sr@denx.de> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: HE1PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:7:66::19) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [172.16.11.1] (81.216.59.226) by HE1PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:7:66::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.4 via Frontend Transport; Tue, 10 Aug 2021 09:27:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38252556-0479-43db-9be3-08d95be1194d X-MS-TrafficTypeDiagnostic: AM0PR10MB2163: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Jo/+0/Ey0IqKWy9trLxw2S99bwsKGwWdzzsByGACzSWSttrPQ3T3CaRfYo3a6diJG/uewTPakqUGJHoWXMDHjJh4C9m+brvzP5SWnip3bNgzd7zUA1eugoXZAanJU3ROOhP+c1vISytoyl23ugmSFGbq5p43apLgNj+4dSPK2dNwA/Ar865pMFOupQGd5Fan2+d+VT8pqqcPmqxh8nw0XHz2tmqmKslHKuE7r0qK16XD1Fs06mcLDNCmmigQUp1NoOHd1PBsWwDB06i0Ax0Jr5vkq4MQvWGzbXCKmkCh0kkN4qAo5loCSv0wYIvrSqb/Kr6kMHgNT43d4NL9yqXrn7ELcMCvV9cAgJgBQwsI/+jqcgt5WU8ialy9QDKVKRZ/JpVTPH+p6ifQHUQfMSAsN3Npp4ONj/rnSSjS3OMc1PxDQ3pDMzIp5ZpXPlgu8CpNQdtosdhk7xOWaMdbNj+SHGuIiDNoc1S4buJ4ppRo7lQrFZV/pkkI0XX8DzS2/mePLu7g52QTpN+Q/fCBYq42tv1Nr1QeLPO/ZdHMxbskfxlllAigP18BLlxTVxtEXANryIr8dnEqJliosY606R3SS9rsgGWYFDUmPwmiQSSpvT9KGmnXJPagxTG94+YeXg48FXt3A/0P20w3xKMn99o0QbFnq7eYD/RURIdURSZgdvfJhcpeuoHWUD6nDmra02d/crdp5mTQYkT9gpCt1uMh/FZPFyIjdy9Nw5z2shxSw4vES5IEyKQNWCSqd1QMr1WcDuFGJ8C1vtRMIUahpDIJbw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(366004)(66946007)(66476007)(31696002)(26005)(2906002)(8936002)(8976002)(66556008)(31686004)(6486002)(186003)(52116002)(44832011)(38350700002)(956004)(38100700002)(2616005)(508600001)(5660300002)(86362001)(36756003)(16576012)(316002)(4326008)(83380400001)(8676002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?Windows-1252?Q?qOOim/1ctsARz07QbKMU9ZnNDdUfPH5TrgpmwU8IfoBGsmb1q7blSZLM?= =?Windows-1252?Q?uymdzAyh5KFfKftwJyvuaTcGEHcTx2629v+MlP30Hd6M/0jCr1ObUDYL?= =?Windows-1252?Q?coo1cy+Rc7Rt8nIBHC1pvhouRf2c0rsuuCfyvvA+1nwPh/VbBZX8FFbm?= =?Windows-1252?Q?BP9spxoYYh2eWtu3ARtmSYH1LubkYwPIzwEcHpQBJYoINkV5/mO3rHxQ?= =?Windows-1252?Q?gyTAFCGlCDxgueWLgLdTrC3u1Ynjci0s/gDyYUG6RCaIoPxxpD1NegnB?= =?Windows-1252?Q?FtVTlFln9dOi66M+EhAPh+EAo5huVI44k869s9zMSwvwICkLpBC6drcP?= =?Windows-1252?Q?gL8hqdvUHUqPcBMw6xNDj9yxftCRQ46f2IoesW67FzVRYrOVt6aJdA3w?= =?Windows-1252?Q?9e/nyx036cbZgNfc8YXCN7YdeipTT2wfJUIxn+8+LTk5Dws+E/bK1KR4?= =?Windows-1252?Q?nItFzKI5VYNeDtaLX2qckiQH4nsaEJ05lmz0ZNQJbfkL/JKJXq5sjEQG?= =?Windows-1252?Q?20D66GpwkTxkD01JjF/dv+0KnD130DrU31ejpLsK6F51s6Alznnr/5he?= =?Windows-1252?Q?GZhqQbisLPXnGyFsoDQTkPpMoYrw/B7gVby5vhFg5FEMXlKy/xL5NNpJ?= =?Windows-1252?Q?z3oeEzgQMJVkcc+YlmMCLcyZJQrU6P9Us4kWX3tAuId9bHhiS4YYaz9l?= =?Windows-1252?Q?SA+CsYF6CxCtuHXCRBUhuzDCaweUWPZfqZYp2MioxlvP+xXRrYOx/scB?= =?Windows-1252?Q?k/K37aXRPs0VCO8ZvasGUCF1y7Yzh015XRMLCbAEtLxnkD92JSONUtKP?= =?Windows-1252?Q?rroVbWELPJsMWREU6siztX7mQM/8fDkBxypmVDXQyd/cOdc+YkY694Ig?= =?Windows-1252?Q?vqhm40JfcSM3480ugWtR/lD1vX3Mq9UL8EmEqs7gX3ZfRDQLTTvjfCyx?= =?Windows-1252?Q?7zk17aLfljMSAJFLSHrwi4pBCJGsX5bOvyooJL5JQx6PVgaZH+Ni0jT6?= =?Windows-1252?Q?KUIhCRttzjy7Xk3RZC+qP3QfageZOXfYQbGQd+HkOsESBG7RzpAZBGpi?= =?Windows-1252?Q?cCBLemhbw9qjj4jfsCRN80eunVNJ3It9S769h0O9M1Ut+BQmDBDcBnFC?= =?Windows-1252?Q?h7EEbNXozEbihBNtfvM+Ooq0NX4KpqazUUa50p89stdkHOxKNTx4D0rh?= =?Windows-1252?Q?oweh6q0uQ3wDfmnFKvRDxuhVlpV7fB5Lb0+U6Izi9x2OtjU6G8dbqOgm?= =?Windows-1252?Q?hMWEDfsD8Rsp1xvx/loMhltY1rOvx8cNU9XESfMXh4lo5aZbLPMFe4Bn?= =?Windows-1252?Q?qjT1WmOcKBTY4crZ5KLUDeUq8k+ahWnZEsoDLGuCgdiML6qzeaKMzCX2?= =?Windows-1252?Q?APSx5d03Vqi38vsJG14qfKXNTQdmOmo9EAUkuv8lzAnfm52o6PlcAuIR?= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 38252556-0479-43db-9be3-08d95be1194d X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 09:27:40.0901 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OVT+vKa/SOfu6C58/0jUWWdGBmolJMMqyzV31fZF4OVeGR+n3jYggXNZekq98ebeYFITbkZV5BtnM7HxRUE2RksLKTdjgDetX0oEohUPjnM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB2163 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 10/08/2021 09.13, Stefan Roese wrote: > The optimized memset uses the dc opcode, which causes problems when the > cache is disabled. This patch adds a check if the cache is disabled and > uses a very simple memset implementation in this case. Otherwise the > optimized version is used. > > Signed-off-by: Stefan Roese > > --- > > Changes in v2: > - New patch > > arch/arm/lib/memset-arm64.S | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/arch/arm/lib/memset-arm64.S b/arch/arm/lib/memset-arm64.S > index 710f6f582cad..a474dcb53c83 100644 > --- a/arch/arm/lib/memset-arm64.S > +++ b/arch/arm/lib/memset-arm64.S > @@ -11,6 +11,7 @@ > * > */ > > +#include > #include "asmdefs.h" > > #define dstin x0 > @@ -25,6 +26,35 @@ ENTRY (memset) > PTR_ARG (0) > SIZE_ARG (2) > > + /* > + * The optimized memset uses the dc opcode, which causes problems > + * when the cache is disabled. Let's check if the cache is disabled > + * and use a very simple memset implementation in this case. Otherwise > + * jump to the optimized version. > + */ > + switch_el x6, 3f, 2f, 1f > +3: mrs x6, sctlr_el3 > + b 0f > +2: mrs x6, sctlr_el2 > + b 0f > +1: mrs x6, sctlr_el1 > +0: > + tst x6, #CR_C > + bne 9f How costly is this switch_el and access to a control register? For a "big" memset of several 100s of bytes I'm sure it's a net win regardless. But smaller memsets are much more common, and no individual memset would show up in any boot time "profiling", but it is possible that the extra cost added to those smaller memsets adds up to some significant penalty. > + /* > + * A very "simple" memset implementation without the use of the > + * dc opcode. Can be run with caches disabled. > + */ > + mov x3, #0x0 > +4: strb w1, [x0, x3] > + add x3, x3, #0x1 > + cmp x2, x3 > + bne 4b > + ret > +9: > + So I can hardly claim to be fluent in aarch64, but AFAICT this does return the destination pointer as it must (because it leaves x0 untouched throughout). However, it fails (by writing over all of memory) when the size is 0, since it is essentially a do{}while and not a while{}. Rasmus