From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752677AbdJKPyF (ORCPT ); Wed, 11 Oct 2017 11:54:05 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:58864 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbdJKPyC (ORCPT ); Wed, 11 Oct 2017 11:54:02 -0400 Subject: Re: [PATCH] dmaengine: stm32-mdma: avoid 64-bit division To: Arnd Bergmann , Benjamin Gaignard CC: Vinod Koul , Maxime Coquelin , Alexandre Torgue , Linux Kernel Mailing List , , "M'boumba Cedric Madianga" , Dan Williams , Linux ARM References: <20171011140144.3746128-1-arnd@arndb.de> From: Pierre Yves MORDRET Message-ID: <6e0215da-40f7-128e-5781-00b7d2acbd94@st.com> Date: Wed, 11 Oct 2017 17:53:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG5NODE2.st.com (10.75.127.14) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-11_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/11/2017 05:13 PM, Arnd Bergmann wrote: > On Wed, Oct 11, 2017 at 4:46 PM, Benjamin Gaignard > wrote: >> 2017-10-11 16:39 GMT+02:00 Arnd Bergmann : >>> On Wed, Oct 11, 2017 at 4:27 PM, Benjamin Gaignard >>> wrote: >>>> 2017-10-11 16:01 GMT+02:00 Arnd Bergmann : >>>> >>>>> @@ -398,6 +400,9 @@ static enum dma_slave_buswidth stm32_mdma_get_max_width(u32 buf_len, u32 tlen) >>>>> break; >>>>> } >>>>> >>>>> + if (addr % max_width) >>>>> + max_width = DMA_SLAVE_BUSWIDTH_1_BYTE; >>>>> + >>>> >>>> I'm only half-convince by the implicite 32 bits cast done into >>>> function prototype. >>>> If we keep using dma_addr_t and use do_div() instead of % >>>> does compiler can still optimize the code ? >>>> >>> >>> I wouldn't want to add a do_div() here, since it's guaranteed >>> not to be needed. Would you prefer an explicit cast here >>> and leave the argument as dma_addr_t? >>> >>> We could also use a bit mask here like >>> >>> if (addr & (max_width-1)) >> >> That sound better for me since it doesn't limit the code to 32 bits architecture > > FWIW, I used the u32 type here because that's the limit of the > dma driver, the dma_addr_t gets converted to that anyway > later. > >>> >>> or we could combined it with the check above: >>> >>> if ((((buf_len | addr) & (max_width - 1)) == 0) && >>> (tlen >= max_width)) >> >> No it is more simple to read with two checks > > I should have mentioned that this variant would also change > behavior: the current code falls back to byte access when > the address alignment is less than the length alignment. > The change I suggested here would change that to use > the maximum possible address width that fits the alignment > of either size or address. Both alignment are required on address and length. The main advantage result is maximized in term of width. As for now I don't see any drawback except a short explanation. Nonetheless I need to think a little bit more about this change. > > I don't know what behavior we actually want though, or > if that change would be correct. > > Arnd > Regards Py