-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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 onoff service #24334
drivers: clock_control: nrf: Use onoff service #24334
Conversation
All checks are passing now. Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
fce8975
to
c234836
Compare
@cvinayak thanks for checking this. I will take a look what is the onoff overhead and what can be done about it. |
3b1552e
to
bcc244b
Compare
@cvinayak can you take one more look? I've added @anangl can you take another look at the driver implementation as i had to add some hacks&flags to support out of band hf clock requesting. I've also added a test suite where i tried to mix ble and onoff API and stress test it. Overall, that didn't make clock control driver prettier so I hope that this backdoor was opened for only one guest. |
bcc244b
to
8e3ce05
Compare
LOG_INF("setup done"); | ||
} | ||
|
||
static void tear_down_instance(const char *dev_name, | ||
clock_control_subsys_t subsys) | ||
{ | ||
struct device *dev = device_get_binding(dev_name); | ||
#if DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf_clock), okay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if DT_NODE_HAS_STATUS(DT_INST(0, nordic_nrf_clock), okay) | |
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_clock) |
err = clock_control_off(dev, subsys); | ||
zassert_equal(0, err, "%s: Unexpected err (%d)", dev_name, err); | ||
zassert_equal(-EBUSY, err, "%s: Unexpected err (%d)", dev_name, err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error code is not specified by the clock_control API, so this check should be performed only for nRF clocks. Same applies to double start/stop test cases.
/* Used only by HF clock */ | ||
#define HF_BT_ACTIVE BIT(8) | ||
#define HF_GENERIC_ACTIVE BIT(9) | ||
#define HF_USER_MASK (HF_BT_ACTIVE | HF_GENERIC_ACTIVE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only for HFCLK, why not use a dedicated variable for it? Something like:
static atomic_t hfclk_users;
You would then avoid the need of this weird masking of flags
with HF_USER_MASK
in set_off_state()
:
https://github.com/zephyrproject-rtos/zephyr/blob/a7fbf5e80f3f702024c261dd63899f368f39028d/drivers/clock_control/nrf_power_clock.c#L158
and in set_starting_state()
:
https://github.com/zephyrproject-rtos/zephyr/blob/a7fbf5e80f3f702024c261dd63899f368f39028d/drivers/clock_control/nrf_power_clock.c#L173-L175
Also accesses to such variable should be faster than to flags
for which you need to get the pointer via get_hf_flags()
.
* ensure that every z_nrf_clock_bt_ctrl_hf_request matches | ||
* z_nrf_clock_bt_ctrl_hf_release call. | ||
*/ | ||
void z_nrf_clock_bt_ctrl_hf_request(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should rather use *_bt_ctlr_*
, for consistency with other related stuff.
|
||
*flags |= HF_GENERIC_ACTIVE; | ||
if (*flags & HF_BT_ACTIVE) { | ||
nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, &type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value returned by nrf_clock_is_running()
is ignored here, so (void)
could help make it clear (and perhaps also avoid warnings from some linters).
8e3ce05
to
f263f18
Compare
/* Used only by HF clock */ | ||
#define HF_USER_BT BIT(0) | ||
#define HF_USER_GENERIC BIT(1) | ||
#define HF_USER_MASK (HF_USER_BT | HF_USER_GENERIC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
@cvinayak can you check bluetooth part? |
Master 98bcc51: The performance is now comparable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved for BLE controller changes by analyzing performance changes.
Updated nrf clock control driver to use onoff service for managing multiple users. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added shell command to clock driver to get clock status. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added suite to test clock control with onoff. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Nordic platforms exposes API for controlling HF clock along onoff API. This API is dedicated to be used by the bluetooth controller and must not be used elsewhere. Test suite is validating stability of HF clock control using onoff API and specialized API. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Adapted driver to use onoff service for clock control. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Adapted driver to clock_control changes (usage of onoff manager). Since timer is permanenty requesting the clock, it is using API dedicated for that: z_nrf_clock_control_lf_on(). Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Adapted nrfx_rtc counter to request clock through onoff API. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Adapt link layer to use onoff service when controlling clock. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Change to use onoff service when controlling HFXO. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Removed HFXO request. It is a qemu target thus HF clock source should not matter. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Adapted to use onoff service for clock control Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
nrf_hw_models require extension to support nrf_clock_is_running call. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
f263f18
to
3d5aaea
Compare
Ported nRF clock control driver to use onoff service.
Clock_control API no longer tracks number of users but only enables or disables clock. It should not be used directly for clocks which have multiple user.
Clock control driver implements onoff service which can be used to track clock users. Clock control driver implements error detection mechanism which detects cases when direct API and onoff API is used for the same clock subsystem.
Nordic specific API (
nrf_clock_control.h
) provides function for getting onoff manager associated with given clock subsystem:z_nrf_clock_control_get_onoff()
.Since low frequency clock is typically used in enable once mode, nordic specific API provides a function for enabling LF clock without a need to maintain onoff client (
z_nrf_clock_control_lf_on()
). This is currently used by components which uses LF clock: system timer, bluetooth or counter driver.PR contains port to use onoff service whenever HF clock is used.
PR is based on #23898 thus DNM.
Fixes #20712