u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier-oss@weidmueller.com>
To: Stefan Roese <sr@denx.de>, Tony Dinh <mibodhi@gmail.com>,
	Simon Glass <sjg@chromium.org>
Cc: "U-Boot Mailing List" <u-boot@lists.denx.de>,
	"Pali Rohár" <pali@kernel.org>,
	"Michael Walle" <michael@walle.cc>
Subject: Re: [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards
Date: Thu, 1 Sep 2022 13:52:38 +0200	[thread overview]
Message-ID: <11acb481-bc4a-0d75-910b-e3e2f3228645@weidmueller.com> (raw)
In-Reply-To: <f94dd6e8-98f5-85d5-6e14-f3dbcd9d69f3@denx.de>

Hi,

Am 01.09.2022 um 11:27 schrieb Stefan Roese:
> Hi Tony,
> 
> On 01.09.22 09:39, Tony Dinh wrote:
> 
> <snip>
> 
>>>> 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.
>>
>> 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?
> 
> 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;
>   }
> 
> 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
>> <snip>
>> 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!
> 

Does the driver use a 32 bit counter without the timer_conv_64 function 
inside the get_count function?

Regards
   Stefan

  reply	other threads:[~2022-09-01 11:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 11:53 [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards Stefan Roese
2022-08-30 11:53 ` [PATCH 1/6] timer: orion-timer: Add support for other Armada SoC's Stefan Roese
2022-08-30 11:53 ` [PATCH 2/6] timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support Stefan Roese
2022-08-30 12:00   ` Michael Walle
2022-08-30 12:08     ` Stefan Roese
2022-08-30 15:56       ` Simon Glass
2022-08-31  5:57         ` Stefan Roese
2022-08-31 17:44           ` Simon Glass
2022-09-01  5:33             ` Stefan Roese
2022-08-30 11:53 ` [PATCH 3/6] arm: mvebu: Use CONFIG_TIMER on all MVEBU & KIRKWOOD platforms Stefan Roese
2022-08-30 12:04   ` Michael Walle
2022-08-30 12:11     ` Stefan Roese
2022-08-30 11:53 ` [PATCH 4/6] arm: mvebu: dts: Makefile: Compile Armada 375 dtb in a separate step Stefan Roese
2022-08-30 11:53 ` [PATCH 5/6] arm: mvebu: dts: armada-375.dtsi: Add timer0 & timer1 Stefan Roese
2022-08-30 11:53 ` [PATCH 6/6] arm: mvebu: dts: mvebu-u-boot.dtsi: Add "u-boot, dm-pre-reloc" to timer DT node Stefan Roese
2022-08-30 22:15 ` [PATCH 0/6] Enable CONFIG_TIMER for all Kirwood / MVEBU boards Tony Dinh
2022-08-31  5:02   ` Stefan Roese
2022-08-31  5:08     ` Stefan Roese
2022-08-31  6:12       ` Stefan Roese
2022-08-31  6:45         ` Tony Dinh
2022-08-31  6:30       ` Tony Dinh
2022-08-31  7:22         ` Stefan Roese
2022-08-31 15:08           ` Tony Dinh
2022-08-31 21:53             ` Tony Dinh
2022-09-01  1:38               ` Tony Dinh
2022-09-01  2:27                 ` Simon Glass
2022-09-01  7:39                   ` Tony Dinh
2022-09-01  9:27                     ` Stefan Roese
2022-09-01 11:52                       ` Stefan Herbrechtsmeier [this message]
2022-09-02  5:38                         ` Stefan Roese
2022-09-01 14:34                       ` Simon Glass
2022-09-01 23:46                         ` Tony Dinh
2022-09-02  2:51                           ` Tony Dinh
2022-09-02  3:49                             ` Tony Dinh
2022-09-16  4:34 Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11acb481-bc4a-0d75-910b-e3e2f3228645@weidmueller.com \
    --to=stefan.herbrechtsmeier-oss@weidmueller.com \
    --cc=mibodhi@gmail.com \
    --cc=michael@walle.cc \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).