1 /*****************************************************************************\
2  *  powercapping.h - Definitions for power capping logic in the controller
3  *****************************************************************************
4  *  Copyright (C) 2013 CEA/DAM/DIF
5  *  Written by Matthieu Hautreux <matthieu.hautreux@cea.fr>
6  *
7  *  This file is part of Slurm, a resource management program.
8  *  For details, see <https://slurm.schedmd.com/>.
9  *  Please also read the included file: DISCLAIMER.
10  *
11  *  Slurm is free software; you can redistribute it and/or modify it under
12  *  the terms of the GNU General Public License as published by the Free
13  *  Software Foundation; either version 2 of the License, or (at your option)
14  *  any later version.
15  *
16  *  In addition, as a special exception, the copyright holders give permission
17  *  to link the code of portions of this program with the OpenSSL library under
18  *  certain conditions as described in each individual source file, and
19  *  distribute linked combinations including the two. You must obey the GNU
20  *  General Public License in all respects for all of the code used other than
21  *  OpenSSL. If you modify file(s) with this exception, you may extend this
22  *  exception to your version of the file(s), but you are not obligated to do
23  *  so. If you do not wish to do so, delete this exception statement from your
24  *  version.  If you delete this exception statement from all source files in
25  *  the program, then also delete it here.
26  *
27  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
28  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
29  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
30  *  details.
31  *
32  *  You should have received a copy of the GNU General Public License along
33  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
34  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
35 \*****************************************************************************/
36 
37 #ifndef _POWERCAPPING_H
38 #define _POWERCAPPING_H
39 
40 #include <stdint.h>
41 #include <time.h>
42 #include "src/slurmctld/slurmctld.h"
43 
44 /**
45  * powercap_get_cluster_max_watts
46  * return the max power consumption of the cluster
47  * RET uint32_t - the max consumption in watts
48  */
49 uint32_t powercap_get_cluster_max_watts(void);
50 
51 /**
52  * powercap_get_cluster_min_watts
53  * return the min power consumption of the cluster
54  * RET uint32_t - the min consumption in watts
55  */
56 uint32_t powercap_get_cluster_min_watts(void);
57 
58 /**
59  * powercap_get_cluster_current_cap
60  * return the current powercap value
61  * RET uint32_t - powercap
62  */
63 uint32_t powercap_get_cluster_current_cap(void);
64 
65 /**
66  * powercap_set_cluster_cap
67  * set a new powercap value
68  * IN uint32_t - new_cap
69  * RET int - 0 or error code
70  */
71 int powercap_set_cluster_cap(uint32_t new_cap);
72 
73 /**
74  * powercap_get_cluster_adjusted_max_watts
75  * return max power consumption of the cluster,
76  * taking into consideration the nodes which are POWERED DOWN
77  * RET uint32_t - the max consumption in watts
78  */
79 uint32_t powercap_get_cluster_adjusted_max_watts(void);
80 
81 /**
82  * powercap_get_cluster_current_max_watts
83  * return current max power consumption of the cluster,
84  * taking into consideration the nodes which are POWERED DOWN
85  * and the nodes which are idle
86  * RET uint32_t - the max consumption in watts
87  */
88 uint32_t powercap_get_cluster_current_max_watts(void);
89 
90 /**
91  * powercap_get_node_bitmap_maxwatt
92  * return current max consumption value of the cluster,
93  * taking into consideration the nodes which are POWERED DOWN
94  * and the nodes which are idle using the input bitmap to identify
95  * them.
96  * A null argument means, use the controller idle_node_bitmap instead.
97  * IN bitstr_t* idle_bitmap
98  * RET uint32_t - the max consumption in watts
99  */
100 uint32_t powercap_get_node_bitmap_maxwatts(bitstr_t* select_bitmap);
101 
102 /**
103  * powercap_get_job_cap
104  * return the cap value of a job taking into account the current cap
105  * as well as the power reservations defined on the interval
106  *
107  * IN job_ptr - job under consideration
108  * IN when - time of job start
109  * IN reboot - node reboot required
110  * RET - The power cap this job is restricted to
111  */
112 uint32_t powercap_get_job_cap(job_record_t *job_ptr, time_t when, bool reboot);
113 
114 /**
115  * power_layout_ready
116  * check if the layout has at least the minimum available attributes
117  * per node declared and possible to be retrieved
118  *
119  * RET bool - whether the layout is ready for usage
120  */
121 bool power_layout_ready(void);
122 
123 /**
124  * which_power_layout
125  * return which power layout is activated to be used for powercapping
126  *
127  * RET int - 0 both or none, 1 power layout, 2 power_cpufreq layout
128  */
129 int which_power_layout(void);
130 
131 /**
132  * powercap_get_job_nodes_numfreq
133  * return the number of allowed frequencies as long as in which positions
134  * they are in the layouts
135  * IN bitstr_t* select_bitmap related to the nodes that the job could allocate
136  * IN uint32_t cpu_freq_min for the job as given in the command
137  * IN uint32_t cpu_freq_max for the job as given in the command
138  * RET int* - an array of allowed frequency positions
139  *            and in 0 the number of total allowed frequencies
140  */
141 int* powercap_get_job_nodes_numfreq(bitstr_t *select_bitmap,
142 			uint32_t cpu_freq_min, uint32_t cpu_freq_max);
143 
144 /**
145  * powercap_get_node_bitmap_maxwatts_dvfs
146  * similar with powercap_get_node_bitmap_maxwatt with the difference that
147  * there is a return on the max_watts_dvfs array of possible max_watts in case
148  * the cores get different allowed cpu frequencies
149  * IN bitstr_t* idle_bitmap
150  * IN bitstr_t* select_bitmap
151  * IN/OUT uint32_t *max_watts_dvfs for the job as given in the command
152  * IN int* allowed_freqs for the job as given in the command
153  * IN uint32_t num_cpus par job par node
154  * RET uint32_t - the max consumption in watts
155  */
156 uint32_t powercap_get_node_bitmap_maxwatts_dvfs(bitstr_t *idle_bitmap,
157 			bitstr_t *select_bitmap, uint32_t *max_watts_dvfs,
158 			int* allowed_freqs, uint32_t num_cpus);
159 /**
160  * powercap_get_job_optimal_cpufreq
161  * return the position upon the allowed_freqs array that gives us the optimal
162  * cpu frequency for the job to be run based on the power budget available
163  * and the usage of the already executing jobs
164  * IN uint32_t powercap
165  * IN int* allowed_freqs
166  * RET int - the position on the allowed_freqs array for the optimal cpufreq
167  */
168 int powercap_get_job_optimal_cpufreq(uint32_t powercap, int* allowed_freqs);
169 
170 /**
171  * powercap_get_cpufreq
172  * return the cpu frequency related to a particular position on the layouts
173  * IN bitstr_t* select_bitmap
174  * IN int k
175  * RET uint32_t - the cpu frequency
176  */
177 uint32_t powercap_get_cpufreq(bitstr_t *select_bitmap, int k);
178 
179 #endif /* !_POWERCAPPING_H */
180