/* * Verify slurm.conf CpuFreqGovernors list * * Input: - arg - string list of governors * - govs - pointer to composite of enum for each governor in list * Returns - -1 on error, else 0 */ extern int cpu_freq_verify_govlist(const char *arg, uint32_t *govs) { char *list, *gov, *savestr; uint32_t agov; *govs = 0; if (arg == NULL) { error("cpu_freq_verify_govlist: governor list is empty"); return -1; } list = xstrdup(arg); if ( (gov = strtok_r(list, ",", &savestr) ) == NULL) { error("cpu_freq_verify_govlist: governor list '%s' invalid", arg); return -1; } do { debug3("cpu_freq_verify_govlist: gov = %s", gov); agov = _cpu_freq_check_gov(gov, 0); if (agov == 0) { error("cpu_freq_verify_govlist: governor '%s' invalid", gov); return -1; } *govs |= agov; } while ( (gov = strtok_r(NULL, ",", &savestr) ) != NULL); xfree(list); return 0; }
/* * Verify slurm.conf CpuFreqDef option * * Input: - arg - frequency value to check * valid governor, low, medium, highm1, high, * or numeric frequency * - freq - pointer to corresponging enum or numberic value * Returns - -1 on error, else 0 */ extern int cpu_freq_verify_def(const char *arg, uint32_t *freq) { uint32_t cpufreq = 0; cpufreq = _cpu_freq_check_gov(arg, CPU_FREQ_USERSPACE); if (cpufreq) { debug3("cpu_freq_verify_def: %s set", arg); *freq = cpufreq; return 0; } error("%s: CpuFreqDef=%s invalid", __func__, arg); return -1; }
/* * Verify cpu_freq command line option * * --cpu-freq=arg * where arg is p1{-p2{:p3}} * * - p1 can be [#### | low | medium | high | highm1] * which will set the current frequency, and set the governor to * UserSpace. * - p1 can be [Conservative | OnDemand | Performance | PowerSave | UserSpace] * which will set the governor to the corresponding value. * - When p2 is present, p1 will be the minimum frequency and p2 will be * the maximum. The governor will not be changed. * - p2 can be [#### | medium | high | highm1] p2 must be greater than p1. * - If the current frequency is < min, it will be set to min. * Likewise, if the current frequency is > max, it will be set to max. * - p3 can be [Conservative | OnDemand | Performance | PowerSave | UserSpace] * which will set the governor to the corresponding value. * When p3 is UserSpace, the current frequency is set to p2. * p2 will have been set by PowerCapping. * * returns -1 on error, 0 otherwise */ extern int cpu_freq_verify_cmdline(const char *arg, uint32_t *cpu_freq_min, uint32_t *cpu_freq_max, uint32_t *cpu_freq_gov) { char *poscolon, *posdash; char *p1=NULL, *p2=NULL, *p3=NULL; uint32_t frequency; int rc = 0; if (cpu_freq_govs == 0) cpu_freq_govs = slurm_get_cpu_freq_govs(); if (arg == NULL || cpu_freq_min == NULL || cpu_freq_max == NULL || cpu_freq_gov == NULL) { return -1; } *cpu_freq_min = NO_VAL; *cpu_freq_max = NO_VAL; *cpu_freq_gov = NO_VAL; poscolon = strchr(arg,':'); if (poscolon) { p3 = xstrdup((poscolon+1)); } posdash = strchr(arg,'-'); if (posdash) { p1 = xstrndup(arg, (posdash-arg)); if (poscolon) { p2 = xstrndup((posdash+1), ((poscolon-posdash)-1)); } else { p2 = xstrdup((posdash+1)); } } else { if (poscolon) { p1 = xstrndup(arg, (poscolon-arg)); } else { p1 = xstrdup(arg); } } frequency = _cpu_freq_check_gov(p1, 0); if (frequency != 0) { if (p3) { error("governor cannot be specified twice " "%s{-}:%s in --cpu-freq", p1, p3); rc = -1; goto clean; } *cpu_freq_gov = frequency; } else { frequency = _cpu_freq_check_freq(p1); if (frequency == 0) { rc = -1; goto clean; } *cpu_freq_max = frequency; } if (p2) { frequency = _cpu_freq_check_freq(p2); if (frequency == 0) { rc = -1; goto clean; } *cpu_freq_min = *cpu_freq_max; *cpu_freq_max = frequency; if (*cpu_freq_max < *cpu_freq_min) { error("min cpu-frec (%s) must be < max cpu-freq (%s)", p1, p2); rc = -1; goto clean; } } if (p3) { if (!p2) { error("gov on cpu-frec (%s) illegal without max", p3); rc = -1; goto clean; } frequency = _cpu_freq_check_gov(p3, 0); if (frequency == 0) { error("illegal governor: %s on --cpu-freq", p3); rc = -1; goto clean; } *cpu_freq_gov = frequency; } clean: if (*cpu_freq_gov != NO_VAL) { if (((*cpu_freq_gov & cpu_freq_govs) & ~CPU_FREQ_RANGE_FLAG) == 0) { error("governor on %s is not allowed in slurm.conf", arg); *cpu_freq_gov = NO_VAL; rc = -1; } } if (debug_flags & DEBUG_FLAG_CPU_FREQ) { cpu_freq_debug("command", "NO_VAL", NULL, 0, *cpu_freq_gov, *cpu_freq_min, *cpu_freq_max, NO_VAL); } xfree(p1); xfree(p2); xfree(p3); return rc; }