Skip to content

Conversation

@nordic-krch
Copy link
Contributor

@nordic-krch nordic-krch commented Jun 7, 2019

Proposal which extends API to allow asynchronous clock enabling.

Fixes #11107.
Fixes #12039.

Signed-off-by: Krzysztof Chruscinski [email protected]

@nordic-krch nordic-krch added RFC Request For Comments: want input from the community area: Clock Control labels Jun 7, 2019
@nordic-krch nordic-krch added the area: API Changes to public APIs label Jun 7, 2019
@nordic-krch
Copy link
Contributor Author

@pizi-nordic @cvinayak @carlescufi @tbursztyka @masz-nordic
I'm putting following proposal on a table regarding asynchronous enabling of clock. Regarding clock_control_get_status function. There was following proposal #11107 (comment) that i did not included but it may as well replace clock_control_get_status . More important is asynchronous enabling feature.

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 when parameter to the call since i think that it can be moved to the driver.

@nordic-krch
Copy link
Contributor Author

fyi @joerchan @thomasstenersen

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@tbursztyka tbursztyka Jun 7, 2019

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)

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch from 12c25f3 to c646678 Compare June 7, 2019 12:13
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch from c646678 to c51cb27 Compare June 10, 2019 06:18
@nordic-krch nordic-krch changed the title [RFC] drivers: clock_control: API extension proposal drivers: clock_control: API extension proposal Jun 10, 2019
@nordic-krch nordic-krch removed the RFC Request For Comments: want input from the community label Jun 10, 2019
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the description.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch from c51cb27 to d271132 Compare June 11, 2019 11:07
@zephyrbot
Copy link

zephyrbot commented Jun 11, 2019

All checks are passing now.

Review history of this comment for details about previous failed status.
Note that some checks might have not completed yet.

@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch 2 times, most recently from 8752585 to f295197 Compare June 11, 2019 12:04
@carlescufi
Copy link
Member

@erwango @MaureenHelm please take a look and give feedback

@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch 2 times, most recently from c0d3bc2 to 615e97f Compare June 12, 2019 10:47
@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch from 615e97f to a17cce3 Compare June 13, 2019 06:15
@nordic-krch
Copy link
Contributor Author

@cvinayak @pizi-nordic @tbursztyka could you check?
@MaureenHelm @erwango can you also take a look?

@cvinayak cvinayak self-requested a review June 17, 2019 11:33
@cvinayak cvinayak dismissed their stale review June 17, 2019 11:34

Wait for comments from others

Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Contributor Author

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]>
@nordic-krch nordic-krch force-pushed the clock_control_api_proposal branch from a17cce3 to d4aaffa Compare June 19, 2019 05:49
@nordic-krch
Copy link
Contributor Author

@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.

@nordic-krch
Copy link
Contributor Author

@cvinayak @tbursztyka ping

@carlescufi
Copy link
Member

This has now been opened and under review for more than two weeks, with no objections raised. Merging.

@carlescufi carlescufi merged commit e0943cf into zephyrproject-rtos:master Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: API Changes to public APIs area: Clock Control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clock_control: API should allow callback to be specified clock_control: API should support asynchronous and synchronous variants of turning on clocks

6 participants