Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: clock_control: nrf: Use synthesized LF clock source in tests #24972

Conversation

nordic-krch
Copy link
Contributor

In tests k_busy_wait is used extensively. It measures delay using
cpu clock source (HF RC). It is less accurate than LF default clock
source (LF XTAL) which leads to tests failure where it is expected
that k_busy_wait(n) will give same (with microseconds accuracy) to
k_sleep(K_MSEC(1000*n)). By chosing LF SYNTH as the source for LF
clock (system clock), it is ensured that HF (cpu) and LF (system)
clocks have the same accuracy and k_sleep and k_busy_wait results
are aligned.

Fixes #24784 for testing.

Signed-off-by: Krzysztof Chruscinski krzysztof.chruscinski@nordicsemi.no

In tests k_busy_wait is used extensively. It  measures delay using
cpu clock source (HF RC). It is less accurate than LF default clock
source (LF XTAL) which leads to tests failure where it is expected
that k_busy_wait(n) will give same (with microseconds accuracy) to
k_sleep(K_MSEC(1000*n)). By chosing LF SYNTH as the source for LF
clock (system clock), it is ensured that HF (cpu) and LF (system)
clocks have the same accuracy and k_sleep and k_busy_wait results
are aligned.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Copy link
Collaborator

@pabigot pabigot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should solve the problem, but it does it by selecting a test configuration that does not represent what applications do. I'm less sure that's a good idea as it hides the fact that there is, and will always be, a potential difference between these clock domains.

@@ -23,7 +23,8 @@ if CLOCK_CONTROL_NRF

choice CLOCK_CONTROL_NRF_SOURCE
prompt "32KHz clock source"
default CLOCK_CONTROL_NRF_K32SRC_XTAL
default CLOCK_CONTROL_NRF_K32SRC_XTAL if !ZTEST
default CLOCK_CONTROL_NRF_K32SRC_SYNTH if ZTEST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pabigot @andyross @nordic-krch

Since the assumption that k_busy_wait() and k_sleep() are driven by the same clock is just not valid for Nordic platfroms (and likely for others as well, present or future), would it be better to introduce a new FREQUENCY_TOLERANCE variable that the test uses to extend its tolerance and that can be set to 0 for platforms that use the same clock.
Then you can have something like: check_timeout_drift() that uses FREQUENCY_TOLERANCE in all tests that combine busy waits with sleep.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyross could you please weigh in here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments in #24784 (comment) -- I'd be personally happy with this patch, or its converse.

To nitpick: I guess stylewise I'd prefer a choice of name that conveys the implication and not just the details. The important thing to an app isn't what whether the source is "SYNTH" or "XTAL", it's that the "synth" choice is subject to temperature and semiconductor process skew where the crystal is tuned to more conventional tolerances.

As far as adding code to the test framework, that would work, but it doesn't seem much different than just adding a fudge factor for individual cases. These kind of long busy waits are pretty rare even in the tests.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to be clear: I'd be fine with this as-is.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, thinking on this a little more. I'm not quite fine with it as-is. The effect of the actual logic in this patch is to change the default value of a kconfig depending on whether or not ZTEST is set, which means that the test suite isn't going to be testing Zephyr as it is built by applications.

Now, this particular situation is a tiny edge case and not likely to be a problem. But design-wise that's sort of a no-no. We should define the kconfig, what it does, how it's used, and have the tests that need it use it just like apps would.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nRF: Busy wait clock is skewed vs. timer clock
4 participants