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 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 3F9E9ECAAD3 for ; Thu, 1 Sep 2022 23:46:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E4BA83E13; Fri, 2 Sep 2022 01:46:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="RnIjbPiF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EA0F983FDE; Fri, 2 Sep 2022 01:46:25 +0200 (CEST) Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1EA0883E13 for ; Fri, 2 Sep 2022 01:46:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mibodhi@gmail.com Received: by mail-vs1-xe32.google.com with SMTP id 67so499763vsv.2 for ; Thu, 01 Sep 2022 16:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=cX+vvZkBnTFDqaLWTANSeede/py/mBoTUpJUhPloh1Y=; b=RnIjbPiFMkX8if4kfkaMuV/usqeRfSwByCOy4/Cwyn2HMsz3HjY3GnZpzM9SozsuCt MYyO/cpzTPsVyW1fiAkd/czQ++LSDlx55GlJI+GN2buTJ/vOMWMdL5a20MAz67l5Y0ck lzft4jrGc7CNW7HxuTM1WzE5i3APHuQBiiEsMVgD/Hw2xkQxXGw2EPW1/8vBVGiKIMPL EznTmv/aAYMmBalCDxk1ZDdxEzoRCwFTSeSj/48LQEE7xVr8RqX036JZ1+IwBR6z7Gh0 KecnV0Gbsew1YOaSJNiUcl/xQWutEnmg7bKWXlaPTxcNIvBqW3CDjKVuLa9LzkpUcs53 HhqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=cX+vvZkBnTFDqaLWTANSeede/py/mBoTUpJUhPloh1Y=; b=3xB3SsBfMn7O3+4KXA44QHpSXsgO3y/s878lROaRRzZpqJ9JhTRXQHLYQ7cuXKeeBv d739POt6wURQGOxFoWUo3+xLOE0uBvGC1co3vXACFeK+gIkuD7gNV3UnaPUUy56NMvUF JN+Z8RxnjeVFu5G+AzTz0gYTryIHcUCuo/tMhwjVOmjnBM8OeNt+SD8mibHVqOttVgan Z3IHXHITw+ixQBs6xlS12O4d5DlY17i9BrzflmRhdgm5kKzX9iyccZko5Nk8FBpiJS5W Dlwf7Unok838iNhI6Z4qZ1XQn8wkuPbjGn/0GOiWFq1Gqtvdk/Rc5P4OWC/3qPT3MDjD cnxQ== X-Gm-Message-State: ACgBeo0QoZs/Vye0pRFoOA8LXYJZz+Z54gP5NObXnnyI6tVbtEa6ZkRD uOTKXbfTe+FiSFzXtXFo5P7QNDa5EMw9gjbJOJ8= X-Google-Smtp-Source: AA6agR5Ft0Jas3u0Y6LbGtkgdYqAHsXeLsEjNiHyyM76ZzjcYZCMB2L993dLQvzksJT8PyB8l8tuhAeBQ0o4x691gWg= X-Received: by 2002:a67:d88b:0:b0:390:d9e9:190d with SMTP id f11-20020a67d88b000000b00390d9e9190dmr8019334vsj.72.1662075981730; Thu, 01 Sep 2022 16:46:21 -0700 (PDT) MIME-Version: 1.0 References: <20220830115317.410812-1-sr@denx.de> <282eefe1-58d4-89cd-f940-2428bdd42b59@denx.de> In-Reply-To: From: Tony Dinh Date: Thu, 1 Sep 2022 16:46:10 -0700 Message-ID: Subject: Re: [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards To: Simon Glass Cc: Stefan Roese , U-Boot Mailing List , =?UTF-8?Q?Pali_Roh=C3=A1r?= , Michael Walle , stefan.herbrechtsmeier-oss@weidmueller.com Content-Type: text/plain; charset="UTF-8" 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 Hi Stefan R, On Thu, Sep 1, 2022 at 7:35 AM Simon Glass wrote: > > Hi, > > On Thu, 1 Sept 2022 at 03:27, Stefan Roese wrote: > > > > Hi Tony, > > > > On 01.09.22 09:39, Tony Dinh wrote: > > > > > > > > >>> Some ideas. > > >>> > > >>> The get_timer() function looks wrong assigning an uint64_t to ulong. > > >>> > > >>> lib/time.c > > >>> > > >>> static uint64_t notrace tick_to_time(uint64_t tick) > > >>> uint64_t notrace get_ticks(void) > > >>> uint64_t __weak notrace get_ticks(void) > > >>> > > >>> ulong __weak get_timer(ulong base) > > >>> { > > >>> return tick_to_time(get_ticks()) - base; > > >>> } > > >>> > > >>> Most of the timer infrastructure is using uint64_t. I'm seeing this > > >>> __weak function get_timer was invoked in Kirkwood boards. Both in > > >>> sleep and timer commands. > > >> > > >> The get_ticks() thing can run at 1MHz but the timer is 1KHz, so that > > >> is why we don't need a u64 for the timer. > > This is wrong, I meant that get_tbclk() can run at 1MHZ (for example). > The tick is 1KHz. > > > > > > > Thanks for your explanation! However, would you agree that code is > > > problematic and needed some improvement ? IOW, depending what the > > > compiler does, it might return the 1st 32 bit of the 64-bit integer > > > result? > > Yes, we should really use ulong for the tick count as well. The use of > 64-bits seems wrong (on 32-bit machines). > > > > > It will return the lower 32 bits if the system is 32bit, yes. > > > > To check if we have a problem here, please add this (totally untested) > > code and extend it if it makes sense: > > > > diff --git a/lib/time.c b/lib/time.c > > index bbf191f67323..ef5252419f3b 100644 > > --- a/lib/time.c > > +++ b/lib/time.c > > @@ -146,7 +146,15 @@ int __weak timer_init(void) > > /* Returns time in milliseconds */ > > ulong __weak get_timer(ulong base) > > { > > - return tick_to_time(get_ticks()) - base; > > + u64 ticks = get_ticks(); > > + u64 time_ms = tick_to_time(ticks); > > + > > + if (time_ms & 0xffffffff00000000ULL) > > + printf("ticks=%lld time_ms=%lld\n", ticks, time_ms); > > + if ((time_ms - base) & 0xffffffff80000000ULL) > > + printf("ticks=%lld time_ms=%lld base=%ld ret=%lld\n", > > ticks, time_ms, base, time_ms - base); > > + > > + return time_ms - base; > > } With this patch, indeed it showed a wrap around. And the system was frozen during the next command. Below is the log (my annotated comment starts with ***). U-Boot 2022.10-rc3-00048-g66ccd87a9c-dirty (Sep 01 2022 - 15:44:22 -0700) Pogoplug V4 SoC: Kirkwood 88F6281_A1 Model: Cloud Engines PogoPlug Series 4 DRAM: 128 MiB orion_timer_probe Clock Rate 166000000 orion_timer_probe successful Core: 19 devices, 15 uclasses, devicetree: separate NAND: 128 MiB MMC: mvsdio@90000: 0 Loading Environment from NAND... OK In: serial Out: serial Err: serial pcie0.0: Link up Net: eth0: ethernet-controller@72000 Hit any key to stop autoboot: 0 Pogo_V4> sleep 5 do_sleep got a timer start = 14344 do_sleep delay = 5000 do_sleep delay = 5000 do_sleep sleeping... do_sleep start 14344 curent 100 do_sleep start 14344 curent 200 do_sleep start 14344 curent 4800 do_sleep start 14344 curent 4900 do_sleep end of sleep ... current = 5000 Pogo_V4> sleep 10 do_sleep got a timer start = 22370 do_sleep delay = 10000 do_sleep delay = 10000 do_sleep sleeping... do_sleep start 22370 curent 100 do_sleep start 22370 curent 200 do_sleep start 22370 curent 300 do_sleep start 22370 curent 400 do_sleep start 22370 curent 3300 do_sleep start 22370 curent 3400 do_sleep start 22370 curent 3500 ticks=188 time_ms=0 base=22370 ret=-22370 do_sleep end of sleep ... current = 4294944926 *** we are seeing wrap around here Pogo_V4> sleep 15 do_sleep got a timer start = 15733 do_sleep delay = 15000 do_sleep delay = 15000 do_sleep sleeping... do_sleep start 15733 curent 100 do_sleep start 15733 curent 200 do_sleep start 15733 curent 300 do_sleep start 15733 curent 400 do_sleep start 15733 curent 9900 do_sleep start 15733 curent 10000 do_sleep start 15733 curent 10100 *** And the system was frozen here Thanks, Tony > > > > At least here, you seem to have a wrap around with the 32bits AFAICT: > > > > > GoFlexHome> sleep 20.5 > > > do_sleep got a timer start = 15031 > > > do_sleep delay = 20000 > > > do_sleep delay = 20500 > > > do_sleep sleeping... > > > do_sleep start 15031 current 100 > > > > > > do_sleep start 15031 current 6400 > > > do_sleep end of sleep ... current = 4294952265 > > > > > > *** Something strange happened here. current should be 6500, but it > > > seems to have garbage. So the loop exits prematurely. > > > > 4294952265 = 0xFFFFC549! > > Yes this all needs a look, I think. > > Regards, > Simon