Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 60724C433FE for ; Sun, 16 Oct 2022 14:50:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3A48A84DF8; Sun, 16 Oct 2022 16:50:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="Pge4OvGm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0413984EAA; Sun, 16 Oct 2022 16:50:45 +0200 (CEST) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E566384DE4 for ; Sun, 16 Oct 2022 16:50:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id EB46B3F116 for ; Sun, 16 Oct 2022 14:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1665931840; bh=nZseMRpNoqeL9/GmFn160ucHRT+nrdA9DC2hS1j7M1A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Pge4OvGmLx0U786hbrFk6wpsXtboOMUmheT9hkArO3X4uvEtqkwUH5umA6e/sMcA+ jfvSaJpqsP3ZlBR50tMqXUI0GoVEfco/MB1mOIq7t6fHOFnJlWFOPf0+5ivxV+jxSo t1yfOTjmy00c5aDrzY5IpZYxQ65J9nGDpGF5HokPGp14/TrMB4i+BjtqTIj9nSjP3O K/YpbjnV43XLXMfDKyvsM/fjAT9ss6yZEK4SbUIJc6MnHq2vPAHxQLawQS2hGrgOIu isC/2SS3tHFGkPP10FpeiqpEgb11XiUXOVFpn9mPiVSpdS57HynWyl4NiTH0zFh/AG 3zsd9AbX1EB5w== Received: by mail-wm1-f72.google.com with SMTP id 3-20020a05600c020300b003c5eefe54adso4417091wmi.9 for ; Sun, 16 Oct 2022 07:50:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nZseMRpNoqeL9/GmFn160ucHRT+nrdA9DC2hS1j7M1A=; b=MLdqGDC8fH3B9qW1ALp4P7++EvMHk/T8y1F4bWiul28YL0wTcQfNzfFxILX8Jr8ke0 QKcKul0mrRCBwLp/Tm6Bd3NMwAsNgwJatncXMwTjXBGtAvBSSJFiYCpwukvOUwVPZu7c q9nduL1OqfA+mw757tbQCJwrSa/qQVZQ+1JS9ka5JkTC/yejcRB7zXTbLJYrQxjkKnxj RThnVtMM5KSv9B6I2uTAAH5E8/Zr7+pl93qSHGUWfs/jjXEB8BmTg75LqK1S3/MjIow9 gWDofvRaEWud7J2GwEd5zXf0g7ahRdRZZXMhKa7YxsUsYSSwXQXp0dSCbyZ8zfanJuh6 SGzA== X-Gm-Message-State: ACrzQf2A8BmILXxdAl+2733vn4GVAqqs/4Sy9QIK7R5ocej7KQYhR4fs XAT7OQx0mpt7TyXmdQpwC8zrLj+Tx+LzjJGkiyK62W+nHLxfGzRh6B17IaLi7wzhKY45Pw98Gri xNDQVl8nqx9Jckd7L0ve/fe73ZqKfNEM= X-Received: by 2002:a05:600c:4f06:b0:3b4:b67c:68bb with SMTP id l6-20020a05600c4f0600b003b4b67c68bbmr16773819wmq.36.1665931840567; Sun, 16 Oct 2022 07:50:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+QE0hvRzek2ce9vrsY9L6yDWeIG1XYh0/cs3a6FB7OhFPI9ajwKvVuljXBNsSasGw3eRxDg== X-Received: by 2002:a05:600c:4f06:b0:3b4:b67c:68bb with SMTP id l6-20020a05600c4f0600b003b4b67c68bbmr16773804wmq.36.1665931840214; Sun, 16 Oct 2022 07:50:40 -0700 (PDT) Received: from [192.168.123.94] (ip-084-118-157-002.um23.pools.vodafone-ip.de. [84.118.157.2]) by smtp.gmail.com with ESMTPSA id n2-20020a5d4c42000000b0022a2bacabbasm6363320wrt.31.2022.10.16.07.50.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 16 Oct 2022 07:50:39 -0700 (PDT) Message-ID: <4c8ae88a-01be-33ad-3089-4befb2d586fa@canonical.com> Date: Sun, 16 Oct 2022 16:50:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH] clk: k210: Fix error calculation on 32bit Content-Language: en-US To: Sean Anderson Cc: Lukasz Majewski , Simon Glass , u-boot@lists.denx.de, =?UTF-8?Q?Michal_Such=c3=a1nek?= References: <20221013203429.15200-1-msuchanek@suse.de> <20221016075142.GO28810@kitsune.suse.cz> <31257dd6-2658-ae48-be43-9da7cfbeb6f6@canonical.com> <187c7eb8-2497-8723-4ead-d4e255ace1e8@canonical.com> <0f410376-e06e-a58a-357e-8bf5aa3a66f1@gmail.com> From: Heinrich Schuchardt In-Reply-To: <0f410376-e06e-a58a-357e-8bf5aa3a66f1@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean On 10/16/22 16:48, Sean Anderson wrote: > On 10/16/22 10:40, Heinrich Schuchardt wrote: >> >> >> On 10/16/22 16:19, Sean Anderson wrote: >>> On 10/16/22 07:46, Heinrich Schuchardt wrote: >>>> >>>> >>>> On 10/16/22 09:51, Michal Suchánek wrote: >>>>> On Thu, Oct 13, 2022 at 10:34:29PM +0200, Michal Suchanek wrote: >>>>>> k210 is 64bit but the driver and tests are also built in sandbox, and >>>>>> that can be built 32bit. >>>>>> >>>>>> BIT(32) does not work on 32bit, shift before subtraction to fit into >>>>>> 32bit integer with BIT values. >>>>> >>>>> >>>>> Also see >>>>> https://patchwork.ozlabs.org/project/uboot/patch/20221016071035.461454-1-heinrich.schuchardt@canonical.com/ >>>>>> >>>>>> Signed-off-by: Michal Suchanek >>>>>> --- >>>>>> >>>>>>   drivers/clk/clk_k210.c | 2 +- >>>>>>   test/dm/k210_pll.c     | 2 +- >>>>>>   2 files changed, 2 insertions(+), 2 deletions(-) >>>>>> >>>>>> diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c >>>>>> index 1961efaa5e..e85f8ae14a 100644 >>>>>> --- a/drivers/clk/clk_k210.c >>>>>> +++ b/drivers/clk/clk_k210.c >>>>>> @@ -846,7 +846,7 @@ again: >>>>>>           error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); >>>>>>           /* The lower 16 bits are spurious */ >>>>>> -        error = abs((error - BIT(32))) >> 16; >>>>>> +        error = abs((error >> 16) - BIT(32 - 16)); >>>> >>>> >>>> Your patch changes the results. Replacing BIT() by BIT_ULL() does >>>> not change the result: >>>> >>>> error = -1 = 0xffffffffffffffff >>>> before >>>> error - BIT(32) = -4294967297 = 0xfffffffeffffffff >>>> abs(error - BIT(32)) = 4294967297 = 0x100000001 >>>> abs(error - BIT(32)) >> 16 = 65536 = 0x10000 >>>> after >>>> error >> 16 = -1 = 0xffffffffffffffff >>>> (error >> 16) - BIT(32 - 16) = -65537 = 0xfffffffffffeffff >>>> abs((error >> 16) - BIT(32 - 16)) = 65537 = 0x10001 >>>> using BIT_ULL >>>> abs(error - BIT_ULL(32)) >> 16 = 65536 = 0x10000 >>>> >>>> error = 70000 = 0x11170 >>>> before >>>> error - BIT(32) = -4294897296 = 0xffffffff00011170 >>>> abs(error - BIT(32)) = 4294897296 = 0xfffeee90 >>>> abs(error - BIT(32)) >> 16 = 65534 = 0xfffe >>>> after >>>> error >> 16 = 1 = 0x1 >>>> (error >> 16) - BIT(32 - 16) = -65535 = 0xffffffffffff0001 >>>> abs((error >> 16) - BIT(32 - 16)) = 65535 = 0xffff >>>> using BIT_ULL >>>> abs(error - BIT_ULL(32)) >> 16 = 65534 = 0xfffe >>>> >>>> I assume this change of results is unintended. >>>> >>>> We also replace abs() by abs64() to get correct results on a 32bit >>>> system: >>>> >>>> error = -1 = 0xffffffffffffffff >>>> abs(error - BIT_ULL(32)) >> 16 = 0 = 0x0 >>>> abs64(error - BIT_ULL(32)) >> 16 = 65536 = 0x10000 >>>> error = 70000 = 0x11170 >>>> abs(error - BIT_ULL(32)) >> 16 = 1 = 0x1 >>>> abs64(error - BIT_ULL(32)) >> 16 = 65534 = 0xfffe >>>> >>>> Best regards >>>> >>>> Heinrich >>>> >>>>>>           if (error < best_error) { >>>>>>               best->r = r; >>>>>> diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c >>>>>> index a0cc84c396..622b1c9bef 100644 >>>>>> --- a/test/dm/k210_pll.c >>>>>> +++ b/test/dm/k210_pll.c >>>>>> @@ -33,7 +33,7 @@ static int dm_test_k210_pll_calc_config(u32 >>>>>> rate, u32 rate_in, >>>>>>                   error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, >>>>>>                                     r * od); >>>>>>                   /* The lower 16 bits are spurious */ >>>>>> -                error = abs((error - BIT(32))) >> 16; >>>>>> +                error = abs((error >> 16) - BIT(32 - 16)); >>>>>>                   if (error < best_error) { >>>>>>                       best->r = r; >>>>>>                       best->f = f; >>>>>> -- >>>>>> 2.37.3 >>>>>> >>> >>> IMO the driver should just be changed to depend on 64-bit. The k210 >>> is 64-bit, >>> and I didn't write anything with 32-bit in mind. >> >> Michal, Simon, and I are striving to get the sandbox working on ilp32 >> systems. >> >> Do you suggest to remove  the driver from sandbox_defconfig? >> >> This would imply that the unit test is not executed on Gitlab CI. You >> will still be able to execute it on the actual hardware. > > It's still enabled for sandbox64, so it should still be executed there. No, the sandbox64 is also to be compiled on ilp32. It models physical address extension (PAE). Best regards Heinrich