xref: /dpdk/lib/power/rte_power_pmd_mgmt.h (revision f30a1bbd63f494f5ba623582d7e9166c817794a4)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4 
5 #ifndef _RTE_POWER_PMD_MGMT_H
6 #define _RTE_POWER_PMD_MGMT_H
7 
8 /**
9  * @file
10  * RTE PMD Power Management
11  */
12 
13 #include <stdint.h>
14 
15 #include <rte_log.h>
16 #include <rte_power_cpufreq.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * PMD Power Management Type
24  */
25 enum rte_power_pmd_mgmt_type {
26 	/** Use power-optimized monitoring to wait for incoming traffic */
27 	RTE_POWER_MGMT_TYPE_MONITOR = 1,
28 	/** Use power-optimized sleep to avoid busy polling */
29 	RTE_POWER_MGMT_TYPE_PAUSE,
30 	/** Use frequency scaling when traffic is low */
31 	RTE_POWER_MGMT_TYPE_SCALE,
32 };
33 
34 /**
35  * Enable power management on a specified Ethernet device Rx queue and lcore.
36  *
37  * @note This function is not thread-safe.
38  *
39  * @warning This function must be called when all affected Ethernet queues are
40  *   stopped and no Rx/Tx is in progress!
41  *
42  * @param lcore_id
43  *   The lcore the Rx queue will be polled from.
44  * @param port_id
45  *   The port identifier of the Ethernet device.
46  * @param queue_id
47  *   The queue identifier of the Ethernet device.
48  * @param mode
49  *   The power management scheme to use for specified Rx queue.
50  * @return
51  *   0 on success
52  *   <0 on error
53  */
54 int
55 rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id,
56 		uint16_t port_id, uint16_t queue_id,
57 		enum rte_power_pmd_mgmt_type mode);
58 
59 /**
60  * Disable power management on a specified Ethernet device Rx queue and lcore.
61  *
62  * @note This function is not thread-safe.
63  *
64  * @warning This function must be called when all affected Ethernet queues are
65  *   stopped and no Rx/Tx is in progress!
66  *
67  * @param lcore_id
68  *   The lcore the Rx queue is polled from.
69  * @param port_id
70  *   The port identifier of the Ethernet device.
71  * @param queue_id
72  *   The queue identifier of the Ethernet device.
73  * @return
74  *   0 on success
75  *   <0 on error
76  */
77 int
78 rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id,
79 		uint16_t port_id, uint16_t queue_id);
80 
81 /**
82  * Set a emptypoll_max to specified value. Used to specify the number of empty
83  * polls to wait before entering sleep state.
84  *
85  * @param max
86  *   The value to set emptypoll_max to.
87  */
88 void
89 rte_power_pmd_mgmt_set_emptypoll_max(unsigned int max);
90 
91 /**
92  * Get the current value of emptypoll_max.
93  *
94  * @return
95  *   The current emptypoll_max value
96  */
97 unsigned int
98 rte_power_pmd_mgmt_get_emptypoll_max(void);
99 
100 /**
101  * Set the pause_duration. Used to adjust the pause mode callback duration.
102  *
103  * @note Duration must be greater than zero.
104  *
105  * @param duration
106  *   The value to set pause_duration to.
107  * @return
108  *   0 on success
109  *   <0 on error
110  */
111 int
112 rte_power_pmd_mgmt_set_pause_duration(unsigned int duration);
113 
114 /**
115  * Get the current value of pause_duration.
116  *
117  * @return
118  *   The current pause_duration value.
119  */
120 unsigned int
121 rte_power_pmd_mgmt_get_pause_duration(void);
122 
123 /**
124  * Set the min frequency to be used for frequency scaling or zero to use defaults.
125  *
126  * @note Supported by: Pstate mode.
127  *
128  * @param lcore
129  *   The ID of the lcore to set the min frequency for.
130  * @param min
131  *   The value, in KiloHertz, to set the minimum frequency to.
132  * @return
133  *   0 on success
134  *   <0 on error
135  */
136 int
137 rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min);
138 
139 /**
140  * Set the max frequency to be used for frequency scaling or zero to use defaults.
141  *
142  * @note Supported by: Pstate mode.
143  *
144  * @param lcore
145  *   The ID of the lcore to set the max frequency for.
146  * @param max
147  *   The value, in KiloHertz, to set the maximum frequency to.
148  *   If 'max' is 0, it is considered 'not set'.
149  * @return
150  *   0 on success
151  *   <0 on error
152  */
153 int
154 rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max);
155 
156 /**
157  * Get the current configured min frequency used for frequency scaling.
158  *
159  * @note Supported by: Pstate mode.
160  *
161  * @param lcore
162  *   The ID of the lcore to get the min frequency for.
163  * @return
164  *   0 if no value has been configured via the 'set' API.
165  *   >0 if a minimum frequency has been configured. Value is the minimum frequency
166  *   , in KiloHertz, used for frequency scaling.
167  *   <0 on error
168  */
169 int
170 rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore);
171 
172 /**
173  * Get the current configured max frequency used for frequency scaling.
174  *
175  * @note Supported by: Pstate mode.
176  *
177  * @param lcore
178  *   The ID of the lcore to get the max frequency for.
179  * @return
180  *   0 if no value has been configured via the 'set' API.
181  *   >0 if a maximum frequency has been configured. Value is the maximum frequency
182  *   , in KiloHertz, used for frequency scaling.
183  *   <0 on error
184  */
185 int
186 rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore);
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #endif
193