Line data Source code
1 0 : /*
2 : * Copyright (c) 2025 Analog Devices, Inc.
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_SUBSYS_CPU_FREQ_POLICY_H_
8 : #define ZEPHYR_SUBSYS_CPU_FREQ_POLICY_H_
9 :
10 : #ifdef __cplusplus
11 : extern "C" {
12 : #endif
13 :
14 : /*
15 : * CPU Frequency Policy Interface - to be implemented by each policy.
16 : */
17 :
18 : #include <zephyr/types.h>
19 : #include <zephyr/cpu_freq/pstate.h>
20 :
21 :
22 : /**
23 : * @brief CPU Frequency Scaling Policy
24 : * @defgroup subsys_cpu_freq_policy CPU Frequency Policy
25 : * @since 4.3
26 : * @version 0.1.0
27 : * @ingroup subsys_cpu_freq
28 : * @{
29 : */
30 :
31 : /**
32 : * @brief Get the next P-state from CPU frequency scaling policy
33 : *
34 : * This function is implemented by a CPU frequency scaling policy selected via
35 : * Kconfig. The caller must ensure that the current CPU does not change. If
36 : * called from an ISR or a single CPU system, this restriction is automatically
37 : * met. If called from a thread on an SMP system, either interrupts or the
38 : * scheduler must be disabled to ensure the current CPU does not change.
39 : *
40 : * @param pstate_out Pointer to the P-state struct where the next P-state is returned.
41 : *
42 : * @retval 0 in case of success, nonzero in case of failure.
43 : */
44 1 : int cpu_freq_policy_select_pstate(const struct pstate **pstate_out);
45 :
46 : /**
47 : * @brief Reset data structures used by CPU frequency scaling policy
48 : *
49 : * This function is implemented by a CPU frequency scaling policy selected via
50 : * Kconfig. It resets any data structured needed by the policy. It is
51 : * automatically invoked by the CPU frequency scaling subsystem and should not
52 : * be called directly by application code.
53 : */
54 1 : void cpu_freq_policy_reset(void);
55 :
56 : /**
57 : * @brief Set the CPU frequency scaling P-state according to policy
58 : *
59 : * This function is implemented by a CPU frequency scaling policy selected via
60 : * Kconfig. It accepts a P-state previously obtained by a call to
61 : * :c:func:`cpu_freq_policy_select_pstate` and attempts to apply it according
62 : * to the policy. The policy may choose to apply the selected P-state, or
63 : * apply a different P-state, or ignore the request altogether. This function
64 : * is automatically invoked by the CPU frequency scaling subsystem and should
65 : * not be called directly by application code.
66 : *
67 : * @param state Pointer to a P-state
68 : *
69 : * @return Pointer to the applied P-state, or NULL if nothing applied
70 : */
71 1 : const struct pstate *cpu_freq_policy_pstate_set(const struct pstate *state);
72 :
73 : /**
74 : * @}
75 : */
76 :
77 : #ifdef __cplusplus
78 : }
79 : #endif
80 :
81 : #endif /* ZEPHYR_SUBSYS_CPU_FREQ_POLICY_H_ */
|