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

PM: allow custom policy to use default policy code without duplication #62550

Closed
wants to merge 2 commits into from

Conversation

nashif
Copy link
Member

@nashif nashif commented Sep 12, 2023

  • pm: split default policy so custom code can call it
  • doc: pm: do not hide pm_policy_next_state

When implementing a custom PM policy, you might want to use the default
behaviour in addition to other customization. So instead of reimplenting
the code from the default policy, just call the function in the custom
policy code. example:

const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
{

       /* custom policy code here */
       ....
       ....
       ....
       /* end custom policy */
       return pm_policy_default_next_state(cpu, ticks);
}

Signed-off-by: Anas Nashif <[email protected]>
This is a public API that can be implemented by the application to
provide a custom policy.

Signed-off-by: Anas Nashif <[email protected]>
@ceolin
Copy link
Member

ceolin commented Sep 12, 2023

Hmm mixed feelings about it, this can be helpful but it is one more indirection, one more api and possibly can cause confusion ... I would just make the API public and let the application completely define their policy, which can probably be the default with slightly changes.

@nashif
Copy link
Member Author

nashif commented Sep 12, 2023

I would just make the API public and let the application completely define their policy, which can probably be the default with slightly changes.

what API? It is already public.

the idea here is that you might end up duplicating the code of the default policy in your app, why not just call the implementation directly and not having to reimplement it?

const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
{

       /* custom policy code here */
       ....
       ....
       ....
       /* end custom policy */
       return pm_policy_default_next_state(cpu, ticks);
}

@ceolin
Copy link
Member

ceolin commented Sep 12, 2023

I would just make the API public and let the application completely define their policy, which can probably be the default with slightly changes.

what API? It is already public.

I mean't not hidden this API.

the idea here is that you might end up duplicating the code of the default policy in your app, why not just call the implementation directly and not having to reimplement it?

I see the reason, I just don't now if that is common case and consequently worth having one more function and this indirection. That's useful in #61726 the way it was proposed, but if they are defining their own policy they may remove things like power state constraints and latency constraints if they are not using and making it faster / simpler ...

Not a blocker though.

I would just make the API public and let the application completely define their policy, which can probably be the default with slightly changes.

const struct pm_state_info *pm_policy_next_state(uint8_t cpu, int32_t ticks)
{

       /* custom policy code here */
       ....
       ....
       ....
       /* end custom policy */
       return pm_policy_default_next_state(cpu, ticks);
}

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

Successfully merging this pull request may close these issues.

2 participants