-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: clock_control: API extension proposal #16675
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: API extension proposal #16675
Conversation
|
@pizi-nordic @cvinayak @carlescufi @tbursztyka @masz-nordic Only enabling clock is asynchronous. I don't see a need for asynchronous disabling as user usually don't care when clock is disabled (and in many cases it won't be as there might be other users). Currently Bluetooth implements it's own mechanism to start the HF XTAL clock before radio activity. I've added |
include/clock_control.h
Outdated
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.
why not use errno values?
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.
There is no error status here so far.
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.
changed to return:
0 - running
-EALREADY - starting
-ESHUTDOWN - off
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.
I would have kept the original enum. errno are describing errors on calls, not a generic non-erroneous status.
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.
what about clock_control_async_on should that return 0 when running and -EALREADY or -EINPROGRESS when scheduled? It would also be good to clarify error code returned by clock_control_on. Currently it does not specify error codes and nordic driver returns -EINPROGRESS or 0. Others usually return 0 always.
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.
Indeed codes are missing.
In case of clock_control_on it is straightforward:
- 0, even if it is already on. It's simpler, no need to let the user handling an error which anyway means what he requested was a success (he wanted it on, it is on anyway).
- EINVAL if subsystem is bogus
In case of clock_control_async_on, since there is a callback you'll need to verify it (on the same subsystem):
- 0 if it went fine
- -EINPROGRESS if given cb/user_data are the same as running one
- -EBUSY is cb/user_data are different
- -ENOTSUP some clock controller are immediate, so such function won't be implemented for them. Am I doing the right assumption here? ([edit] seems I did yes)
- -EINVAL if cb is not provided (seems mandatory to have one)
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.
0 if it went fine
do you mean that it's up and running or started? I'm still not sure if we should distinguish between started and starting state here. I see following use cases for distinction:
- User can use that information is to determine from which context callback was called.
- user can start clock in blocking manner
while (clock_control_async_on(dev, NULL, now)==-EINPROGRESS));
-EBUSY i would rather return that if provided user_data is already in the list which is rather application error.
-EINVAL if cb is not provided (seems mandatory to have one)
I don't think it has to be mandatory. This could be supported and once driver implements it then counter_clock_on() can be simply counter_clock_async_on(dev, NULL, now).
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.
Good point about -EINPROGRESS, let's not distinguish started/running.
As well as for the -EINVAL removal, I did not see that possibility of clock_on pointing to async_on.
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.
enum is brought back. It contains unknown status which means lack of support for checking status.
12c25f3 to
c646678
Compare
include/clock_control.h
Outdated
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.
I really preferred the enum in case get_status is implemented. -ENOTSUP is fine as an error, rest are just non erroneous status code.
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.
is it ok to return positive values as enum values and negative as error? I would prefer to keep function returning through value. It can be that enum will have status unknown which will mean that getting status is not supported.
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.
it is solved as described in #16675 (comment)
c646678 to
c51cb27
Compare
include/clock_control.h
Outdated
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.
Usually we have XXX_DEFINE() and XXX_INITIALIZER() macro for such structures.
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.
added
include/clock_control.h
Outdated
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.
Must not be on stack or must be in persistent memory? How long the pointer must point to valid memory?
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.
Fixed the description.
include/clock_control.h
Outdated
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.
Would use different name than timeout, which suggests giving up after the timeout.
BTW. In which half?
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.
i mentioned once deadline instead of timeout (#16675 (comment)). @tbursztyka what do you think? To me deadline sounds better since as a user i want clock to be running at latest at that moment.
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.
In which half?
I've clarified it. Please take another look.
c51cb27 to
d271132
Compare
|
All checks are passing now. Review history of this comment for details about previous failed status. |
8752585 to
f295197
Compare
|
@erwango @MaureenHelm please take a look and give feedback |
c0d3bc2 to
615e97f
Compare
615e97f to
a17cce3
Compare
|
@cvinayak @pizi-nordic @tbursztyka could you check? |
include/clock_control.h
Outdated
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.
How you are going to implement "deadline" feature for Nordic?
Also, if this is mandatory feature, how other platforms are supposed to handle this?
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.
On Nordic I plan to use PPI and RTC1 channel (system clock source).
The simplest way for handling that on any platform is to start clock immediately. That covers functionality since deadline is met. It's only about low power. Platforms focused on lower power will find the way. One way is to use system timer adjusted to system latency (e.g. starting clock N ms earlier than requested).
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.
So Clock Control will be bound to system clock.
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.
yes
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.
I have withdrawn deadline argument from async on. In offline discussions we agreed with @pizi-nordic and @carlescufi that it will be difficult to implement it on other platforms than nordic. It would be in fact public api which would be nordic specific for now.
Ideally, we should have kernel API like k_uptime_us_get_32. Absolute, monotonic microseconds counter which could be used for deadline.
Proposal which extends api to allow asynchronous clock enabling. Signed-off-by: Krzysztof Chruscinski <[email protected]>
a17cce3 to
d4aaffa
Compare
|
@pizi-nordic @tbursztyka @cvinayak can you take another look. I think that current patch is quite straightforward as i removed the only thing that was considered controversial - delayed asynchronous request. |
|
@cvinayak @tbursztyka ping |
|
This has now been opened and under review for more than two weeks, with no objections raised. Merging. |
Proposal which extends API to allow asynchronous clock enabling.
Fixes #11107.
Fixes #12039.
Signed-off-by: Krzysztof Chruscinski [email protected]