1 /*****************************************************************************\ 2 * cpu_frequency.h - Define cpu frequency control functions 3 ***************************************************************************** 4 * Copyright (C) 2012 Bull 5 * Written by Don Albert, <don.albert@bull.com> 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 _CPU_FREQUENCY_H_ 38 #define _CPU_FREQUENCY_H_ 39 40 #include "src/slurmd/slurmd/slurmd.h" 41 #include "src/slurmd/slurmstepd/slurmstepd_job.h" 42 43 /* 44 * check if cpu frequency setting is allowed on this node 45 * if so, create and initialize the cpu frequency table entry for each cpu 46 */ 47 extern void 48 cpu_freq_init(slurmd_conf_t *conf); 49 50 /* 51 * free memory from cpu frequency table 52 */ 53 extern void 54 cpu_freq_fini(void); 55 56 /* 57 * reset debug flag (slurmd) 58 */ 59 extern void 60 cpu_freq_reconfig(void); 61 62 /* 63 * Send the cpu_frequency table info to slurmstepd 64 */ 65 extern void 66 cpu_freq_send_info(int fd); 67 68 /* 69 * Receive the cpu_frequency table info from slurmd 70 */ 71 extern void 72 cpu_freq_recv_info(int fd); 73 74 /* 75 * Validate the cpus and select the frequency to set 76 * Called from task cpuset code with job record containing 77 * a pointer to a hex map of the cpus to be used by this step 78 */ 79 extern void 80 cpu_freq_cpuset_validate(stepd_step_rec_t *job); 81 82 /* 83 * Validate the cpus and select the frequency to set 84 * Called from task cgroup cpuset code with string containing 85 * the list of cpus to be used by this step 86 */ 87 extern void 88 cpu_freq_cgroup_validate(stepd_step_rec_t *job, char *step_alloc_cores); 89 90 /* 91 * Verify slurm.conf CpuFreqGovernors list 92 * 93 * Input: - arg - string list of governors 94 * - govs - pointer to composite of enum for each governor in list 95 * Returns - -1 on error, else 0 96 */ 97 extern int 98 cpu_freq_verify_govlist(const char *arg, uint32_t *govs); 99 100 /* 101 * Verify slurm.conf CpuFreqDef option 102 * 103 * Input: - arg - frequency value to check 104 * valid governor, low, medium, highm1, high, 105 * or numeric frequency 106 * - freq - pointer to corresponging enum or numberic value 107 * Returns - -1 on error, else 0 108 */ 109 extern int 110 cpu_freq_verify_def(const char *arg, uint32_t *freq); 111 112 /* 113 * Verify cpu_freq command line option 114 * 115 * --cpu-freq=arg 116 * where arg is p1{-p2}{:p3} 117 * 118 * - p1 can be [#### | low | medium | high | highm1] 119 * which will set the current and max cpu frequency, but not the governor. 120 * - p1 can be [Conservative | OnDemand | Performance | PowerSave] 121 * which will set the governor to the corresponding value. 122 * - If p1 is the first case and is preceded with <, then the value of p1 123 * becomes the max frequency and min is set to "low". 124 * Similarly, if p1 is followed by > then p1 becomes the minimum frequency 125 * and max is set to "high". 126 * - When p2 is present, p1 will be the minimum frequency and p2 will be 127 * the maximum. 128 * - p2 can be [#### | medium | high | highm1] p2 must be greater than p1. 129 * - If the current frequency is < min, it will be set to min. 130 * Likewise, if the current frequency is > max, it will be set to max. 131 * - p3 can be [Conservative | OnDemand | Performance | PowerSave] 132 * which will set the governor to the corresponding value. 133 * 134 * returns -1 on error, 0 otherwise 135 */ 136 extern int 137 cpu_freq_verify_cmdline(const char *arg, 138 uint32_t *cpu_freq_min, 139 uint32_t *cpu_freq_max, 140 uint32_t *cpu_freq_gov); 141 142 /* Convert a composite cpu governor enum to its equivalent string 143 * 144 * Input: - buf - buffer to contain string 145 * - bufsz - size of buffer 146 * - gpvs - composite enum of governors 147 */ 148 extern void 149 cpu_freq_govlist_to_string(char* buf, uint16_t bufsz, uint32_t govs); 150 151 /* 152 * Return an xmalloc()'d string representing the original input to --cpu-freq. 153 */ 154 extern char *cpu_freq_to_cmdline(uint32_t min, uint32_t max, uint32_t gov); 155 156 /* 157 * Set environment variables associated with the frequency variables. 158 */ 159 extern int 160 cpu_freq_set_env(char* var, uint32_t min, uint32_t max, uint32_t gov); 161 162 /* Convert a cpu_freq number to its equivalent string */ 163 extern void 164 cpu_freq_to_string(char *buf, int buf_size, uint32_t cpu_freq); 165 166 167 /* 168 * set the userspace governor and the new frequency value 169 */ 170 extern void 171 cpu_freq_set(stepd_step_rec_t *job); 172 173 /* 174 * reset the governor and cpu frequency to the configured values 175 */ 176 extern void 177 cpu_freq_reset(stepd_step_rec_t *job); 178 179 /* 180 * Convert frequency parameters to strings 181 * Typically called to produce string for a log or reporting utility. 182 * 183 * 184 * When label!=NULL, info message is put to log. This is convienient for 185 * inserting debug calls to verify values in structures or messages. 186 * noval_str==NULL allows missing parameters not to be reported. 187 * freq_str is a buffer to hold the composite string for all input values. 188 * freq_len is length of freq_str 189 * 190 * Returns 0 if all parameters are NO_VAL (or 0) 191 */ 192 extern int 193 cpu_freq_debug(char* label, char* noval_str, char* freq_str, int freq_len, 194 uint32_t gov, uint32_t min, uint32_t max, uint32_t freq); 195 196 #endif /* _CPU_FREQUENCY_H_ */ 197