xref: /dpdk/lib/power/rte_power_uncore.h (revision ebe99d351a3f79acf305b882052f286c65cd9b25)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Intel Corporation
3  * Copyright(c) 2024 Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef RTE_POWER_UNCORE_H
7 #define RTE_POWER_UNCORE_H
8 
9 /**
10  * @file
11  * Uncore Frequency Management
12  */
13 
14 #include "power_uncore_ops.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* Uncore Power Management Environment */
21 enum rte_uncore_power_mgmt_env {
22 	RTE_UNCORE_PM_ENV_NOT_SET,
23 	RTE_UNCORE_PM_ENV_AUTO_DETECT,
24 	RTE_UNCORE_PM_ENV_INTEL_UNCORE,
25 	RTE_UNCORE_PM_ENV_AMD_HSMP
26 };
27 
28 /**
29  * Set the default uncore power management implementation.
30  * This has to be called prior to calling any other rte_power_uncore_*() API.
31  * It is thread safe. New env can be set only in uninitialized state.
32  * rte_power_unset_uncore_env must be called if different env was already set.
33  *
34  * @param env
35  *  env. The environment in which to initialise Uncore Power Management for.
36  *
37  * @return
38  *  - 0 on success.
39  *  - Negative on error.
40  */
41 __rte_experimental
42 int rte_power_set_uncore_env(enum rte_uncore_power_mgmt_env env);
43 
44 /**
45  * Unset the global uncore environment configuration.
46  * This can only be called after all threads have completed.
47  */
48 __rte_experimental
49 void rte_power_unset_uncore_env(void);
50 
51 /**
52  * Get the default uncore power management implementation.
53  *
54  * @return
55  *  power_management_env The configured environment.
56  */
57 __rte_experimental
58 enum rte_uncore_power_mgmt_env rte_power_get_uncore_env(void);
59 
60 /**
61  * Initialize uncore frequency management for specific die on a package.
62  * It will get the available frequencies and prepare to set new die frequencies.
63  *
64  * This function should NOT be called in the fast path.
65  *
66  * @param pkg
67  *  Package number.
68  *  Each physical CPU in a system is referred to as a package.
69  * @param die
70  *  Die number.
71  *  Each package can have several dies connected together via the uncore mesh.
72  *
73  * @return
74  *  - 0 on success.
75  *  - Negative on error.
76  */
77 int
78 rte_power_uncore_init(unsigned int pkg, unsigned int die);
79 
80 /**
81  * Exit uncore frequency management on a specific die on a package.
82  * It will restore uncore min and* max values to previous values
83  * before initialization of API.
84  *
85  * This function should NOT be called in the fast path.
86  *
87  * @param pkg
88  *  Package number.
89  *  Each physical CPU in a system is referred to as a package.
90  * @param die
91  *  Die number.
92  *  Each package can have several dies connected together via the uncore mesh.
93  *
94  * @return
95  *  - 0 on success.
96  *  - Negative on error.
97  */
98 int
99 rte_power_uncore_exit(unsigned int pkg, unsigned int die);
100 
101 /**
102  * Return the current index of available frequencies of a specific die on a package.
103  * It should be protected outside of this function for threadsafe.
104  *
105  * This function should NOT be called in the fast path.
106  *
107  * @param pkg
108  *  Package number.
109  *  Each physical CPU in a system is referred to as a package.
110  * @param die
111  *  Die number.
112  *  Each package can have several dies connected together via the uncore mesh.
113  *
114  * @return
115  *  The current index of available frequencies.
116  *  If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'.
117  */
118 uint32_t rte_power_get_uncore_freq(unsigned int pkg, unsigned int die);
119 
120 /**
121  * Set minimum and maximum uncore frequency for specified die on a package
122  * to specified index value.
123  * It should be protected outside of this function for threadsafe.
124  *
125  * This function should NOT be called in the fast path.
126  *
127  * @param pkg
128  *  Package number.
129  *  Each physical CPU in a system is referred to as a package.
130  * @param die
131  *  Die number.
132  *  Each package can have several dies connected together via the uncore mesh.
133  * @param index
134  *  The index of available frequencies.
135  *
136  * @return
137  *  - 1 on success with frequency changed.
138  *  - 0 on success without frequency changed.
139  *  - Negative on error.
140  */
141 int rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index);
142 
143 /**
144  * Set minimum and maximum uncore frequency for specified die on a package
145  * to maximum value according to the available frequencies.
146  * It should be protected outside of this function for threadsafe.
147  *
148  * This function should NOT be called in the fast path.
149  *
150  * @param pkg
151  *  Package number.
152  *  Each physical CPU in a system is referred to as a package.
153  * @param die
154  *  Die number.
155  *  Each package can have several dies connected together via the uncore mesh.
156  *
157  * @return
158  *  - 1 on success with frequency changed.
159  *  - 0 on success without frequency changed.
160  *  - Negative on error.
161  */
162 int rte_power_uncore_freq_max(unsigned int pkg, unsigned int die);
163 
164 /**
165  * Set minimum and maximum uncore frequency for specified die on a package
166  * to minimum value according to the available frequencies.
167  * It should be protected outside of this function for threadsafe.
168  *
169  * This function should NOT be called in the fast path.
170  *
171  * @param pkg
172  *  Package number.
173  *  Each physical CPU in a system is referred to as a package.
174  * @param die
175  *  Die number.
176  *  Each package can have several dies connected together via the uncore mesh.
177  *
178  * @return
179  *  - 1 on success with frequency changed.
180  *  - 0 on success without frequency changed.
181  *  - Negative on error.
182  */
183 int rte_power_uncore_freq_min(unsigned int pkg, unsigned int die);
184 
185 /**
186  * Return the list of available frequencies in the index array.
187  *
188  * This function should NOT be called in the fast path.
189  *
190  * @param pkg
191  *  Package number.
192  *  Each physical CPU in a system is referred to as a package.
193  * @param die
194  *  Die number.
195  *  Each package can have several dies connected together via the uncore mesh.
196  * @param freqs
197  *  The buffer array to save the frequencies.
198  * @param num
199  *  The number of frequencies to get.
200  *
201  * @return
202  *  - The number of available index's in frequency array.
203  *  - Negative on error.
204  */
205 __rte_experimental
206 int rte_power_uncore_freqs(unsigned int pkg, unsigned int die,
207 		uint32_t *freqs, uint32_t num);
208 
209 /**
210  * Return the list length of available frequencies in the index array.
211  *
212  * This function should NOT be called in the fast path.
213  *
214  * @param pkg
215  *  Package number.
216  *  Each physical CPU in a system is referred to as a package.
217  * @param die
218  *  Die number.
219  *  Each package can have several dies connected together via the uncore mesh.
220  *
221  * @return
222  *  - The number of available index's in frequency array.
223  *  - Negative on error.
224  */
225 int rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die);
226 
227 /**
228  * Return the number of packages (CPUs) on a system
229  * by parsing the uncore sysfs directory.
230  *
231  * This function should NOT be called in the fast path.
232  *
233  * @return
234  *  - Zero on error.
235  *  - Number of package on system on success.
236  */
237 unsigned int rte_power_uncore_get_num_pkgs(void);
238 
239 /**
240  * Return the number of dies for pakckages (CPUs) specified
241  * from parsing the uncore sysfs directory.
242  *
243  * This function should NOT be called in the fast path.
244  *
245  * @param pkg
246  *  Package number.
247  *  Each physical CPU in a system is referred to as a package.
248  *
249  * @return
250  *  - Zero on error.
251  *  - Number of dies for package on sucecss.
252  */
253 unsigned int rte_power_uncore_get_num_dies(unsigned int pkg);
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* RTE_POWER_UNCORE_H */
260