Received: by 10.192.165.156 with SMTP id m28csp565389imm; Fri, 13 Apr 2018 04:11:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+fKoGxbaJW20amxWMaIwVrtlj9cixMlM80ZJxWWf8zYXBh9vp+hfZ0u3y1vqX4xa3edxSP X-Received: by 10.99.117.80 with SMTP id f16mr3738233pgn.439.1523617871838; Fri, 13 Apr 2018 04:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523617871; cv=none; d=google.com; s=arc-20160816; b=h5O+7NXYqLv1CgajGMHM1vIUpn5XP/DuyPsc+Ntcp+AnO3yKf5qEXxwYGs4DtqTi7X s4z4uE124qKZqGe5sDQtOkuU/GDPOJCTxoHvwMdhWKxK9jkAhPQeSStfonAo8RtoIBCV jzr5lsHKNqwoYzlDheZXlf/45owJ3Oa27sJLqePGmqrn/zsCwHgd6hISWEh/HiPTG6sN uNF5ElUQ1pQhD0Jb8Sqj0czTzmgTjfYTBKK80JAlTfa3sn41Ta9tSMpoY9ejgBSZKodx 1ZL2NqOacgajEsMFvyNzLICKjy9XY429GN80ildHdRCWksC+RsMlLSiDzYg2Ax6/hcdu M3Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=vrwz453oWkyZqk8nAFYQSKygEBpKjhfuH8aKuNO6l1k=; b=PaUTKacq1d2ZEwVcnX+RQcFCb/bt/8f5Im27dCQ3WRDZtcC13fFzEgQpF5c7c+S2XT oH4eipSub52ASFSHfEAE8n91PQB4q0xUj8cXlGIgDMa7zCi8D+CssXwH+iTYr5BDXKkP ZCAw0bFk6uTqufcs6lRqh2wQNik4qAmq7oMTO51fGew/WQIgGFJMH3a1NBrsGm2sQYEY YdC1NvE/QFSCORmJdhCjQwmU7hnP5Fm8XaibBuHHUp/Bkixsd13UQUEVSx/wJAMb6TfX x5oBX5OrPsDMjgcQPhmOiwin+aTuDU4kvwKXreRuiUrlnRCMwrbNzydl7rhskD1xFBeZ Vfjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si5211263plb.349.2018.04.13.04.10.57; Fri, 13 Apr 2018 04:11:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754289AbeDMLJk (ORCPT + 99 others); Fri, 13 Apr 2018 07:09:40 -0400 Received: from foss.arm.com ([217.140.101.70]:41372 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753919AbeDMLJj (ORCPT ); Fri, 13 Apr 2018 07:09:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 115C71435; Fri, 13 Apr 2018 04:09:39 -0700 (PDT) Received: from [10.1.210.88] (e110467-lin.cambridge.arm.com [10.1.210.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 80DF03F24A; Fri, 13 Apr 2018 04:09:37 -0700 (PDT) Subject: Re: [PATCH v2 1/2] dmaengine: stm32-mdma: align TLEN and buffer length on burst To: Pierre Yves MORDRET , Vinod Koul , Maxime Coquelin , Alexandre Torgue , Dan Williams , M'boumba Cedric Madianga , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <1523457879-9869-1-git-send-email-pierre-yves.mordret@st.com> <1523457879-9869-2-git-send-email-pierre-yves.mordret@st.com> <9a2a267c-2b0b-0d6a-c762-47e7d37f84ea@arm.com> <22bd0af7-9820-57c5-9215-8185839d7d27@st.com> From: Robin Murphy Message-ID: <7ab2cfcd-07ed-e380-727a-727e78cc0336@arm.com> Date: Fri, 13 Apr 2018 12:09:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <22bd0af7-9820-57c5-9215-8185839d7d27@st.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/04/18 10:45, Pierre Yves MORDRET wrote: > Hi Robin > > On 04/11/2018 05:14 PM, Robin Murphy wrote: >> On 11/04/18 15:44, Pierre-Yves MORDRET wrote: >>> Both buffer Transfer Length (TLEN if any) and transfer size have to be >>> aligned on burst size (burst beats*bus width). >>> >>> Signed-off-by: Pierre-Yves MORDRET >>> --- >>> Version history: >>> v1: >>> * Initial >>> v2: >>> --- >>> --- >>> drivers/dma/stm32-mdma.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c >>> index daa1602..fbcffa2 100644 >>> --- a/drivers/dma/stm32-mdma.c >>> +++ b/drivers/dma/stm32-mdma.c >>> @@ -413,7 +413,7 @@ static u32 stm32_mdma_get_best_burst(u32 buf_len, u32 tlen, u32 max_burst, >>> u32 best_burst = max_burst; >>> u32 burst_len = best_burst * width; >>> >>> - while ((burst_len > 0) && (tlen % burst_len)) { >>> + while ((burst_len > 0) && (((tlen | buf_len) & (burst_len - 1)) != 0)) { >>> best_burst = best_burst >> 1; >>> burst_len = best_burst * width; >>> } >> >> FWIW, doesn't that whole loop come down to just: >> >> burst_len = min(ffs(tlen | buf_len), max_burst * width); > > No sure it ends as expected. or I miss something or don't understand this statement > I tried with "relevant value" : i.e. best_burst = 32, Tlen=128(default) and > buf_len = 64, width= 4. This statements gets me something wrong output => 7 > instead of 16 * 4. > I doubt :) Heh, seems I confused myself halfway through and started thinking max_burst and width were the exponents x rather than the values 2^x... A more representative guess should be: min(1 << __ffs(tlen | buf_len), max_burst * width); but the general point I was trying to make is that a loop checking whether the bottom n bits of something are zero for different values of n is unnecessary when n can simply be calculated directly*. Robin. * in the case of this "just the lowest set bit" idiom there's also the shift-free ((x & (x - 1)) ^ x), but as well as being unreadable it's generally less efficient than (1 << __ffs(x)) for most modern ISAs.