mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: Chuan Liu <chuan.liu@amlogic.com>
To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] soc: amlogic: clk-measure: Optimize measurement accuracy
Date: Fri, 18 Jul 2025 14:13:54 +0800	[thread overview]
Message-ID: <7fbd3743-cfda-4877-888d-bdeb28d4972f@amlogic.com> (raw)
In-Reply-To: <CAFBinCDyjf7MOE6f_AGEEwqV8z68qRv6JAUxn7zt5ZZqwFLkPg@mail.gmail.com>

hi Marti:


On 7/17/2025 11:43 PM, Martin Blumenstingl wrote:
> [ EXTERNAL EMAIL ]
>
> Hello,
>
> thank you for this patch!
>
> On Thu, Jul 17, 2025 at 5:08 AM Chuan Liu via B4 Relay
> <devnull+chuan.liu.amlogic.com@kernel.org> wrote:
>> From: Chuan Liu <chuan.liu@amlogic.com>
>>
>> The cycle count register has a 20-bit effective width, but the driver
>> only utilizes 16 bits. This reduces the sampling window when measuring
>> high-frequency clocks, resulting in (slightly) degraded measurement
>> accuracy.
> I checked the Meson8 downstream code [0] and it uses 0x000FFFFF to
> mask the register value -> this means that old SoCs also have a 20-bit
> wide width.
>
> [...]
>> Here are the test comparisons based on C3:
> [...]
>> Here are the test comparisons based on C3:
> I have tested this patch with Meson8b based Odroid-C1:
> pre-optimization:
> # time cat /sys/kernel/debug/meson-clk-msr/measure_summary | grep -v "  0  "
>    clock                     rate    precision
> ---------------------------------------------
>   clk81                 159372396    +/-5208Hz
>   a9_clk_div16           24000000    +/-3125Hz
>   rtc_osc_clk_out           31250    +/-3125Hz
>   hdmi_ch0_tmds         146399038    +/-4807Hz
>   sar_adc                 1140625    +/-3125Hz
>   sdhc_rx                94443750    +/-3125Hz
>   sdhc_sd                94443750    +/-3125Hz
>   pwm_d                 849921875    +/-31250Hz
>   pwm_c                 849921875    +/-31250Hz
>
> real    0m0.102s
> user    0m0.005s
> sys     0m0.069s
>
>
> post-optimization:
> # time cat /sys/kernel/debug/meson-clk-msr/measure_summary | grep -v "  0  "
>    clock                     rate    precision
> ---------------------------------------------
>   clk81                 159373438    +/-1562Hz
>   a9_clk_div16           12000000    +/-1562Hz
>   rtc_osc_clk_out           32813    +/-1562Hz
>   hdmi_ch0_tmds         146398438    +/-1562Hz
>   sar_adc                 1143750    +/-1562Hz
>   sdhc_rx                94443750    +/-1562Hz
>   sdhc_sd                94443750    +/-1562Hz
>   pwm_d                 849992188    +/-1562Hz
>   pwm_c                 849992188    +/-1562Hz
>
> real    0m0.173s
> user    0m0.008s
> sys     0m0.109s
>
> So there's also an improvement in accuracy. The only downside I'm
> seeing is that it takes 75% extra time for the measurement. For me
> this is irrelevant since we use this for debugging.
>
> [...]
>> +       /*
>> +        * HACK: The input clock signal path from gate (Controlled by MSR_RUN)
>> +        * to internal sampling circuit in clk-measure has a propagation delay
>> +        * requirement: 24 clock cycles must elapse after mux selection before
>> +        * sampling.
>> +        *
>> +        * For a 30kHz measurement clock, this translates to an 800μs delay:
>> +        * 800us = 24 / 30000Hz.
>> +        */
>> +       fsleep(800);
> What is needed to make this not a HACK anymore? Is there a register
> that we can poll for the number of clock cycles that have passed?


The required delay duration is frequency-dependent on the measurement
clock source. The current 800μs delay is calculated based on a
minimum input clock frequency of 30kHz. At higher input frequencies,
this delay could be proportionally reduced. Applying a uniform 800μs
delay therefore appears overly conservative for general use cases.


The IP currently lacks a status register to detect whether the input
clock signal has successfully propagated to the internal measurement
circuitry.


The design of this IP has been maintained for many years. From a
hardware design perspective, there is room for optimization in this
signal propagation delay. Future IP updates may not require such a
long delay.


>
> Best regards,
> Martin

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2025-07-18  6:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17  3:08 Chuan Liu via B4 Relay
2025-07-17 15:43 ` Martin Blumenstingl
2025-07-18  6:13   ` Chuan Liu [this message]
2025-07-21 20:16     ` Martin Blumenstingl
2025-07-22  2:32       ` Chuan Liu

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=7fbd3743-cfda-4877-888d-bdeb28d4972f@amlogic.com \
    --to=chuan.liu@amlogic.com \
    --cc=jbrunet@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=neil.armstrong@linaro.org \
    /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

all inboxes | Powered by JetHome®