diff --git a/src/common/read_config.c b/src/common/read_config.c index 7836a9d3c0bda762cb9529a5d59129af28df1194..0c66df0265ef21df3472ba14d53a8eba5ec550b2 100644 --- a/src/common/read_config.c +++ b/src/common/read_config.c @@ -4009,19 +4009,32 @@ extern char *get_extra_conf_path(char *conf_name) extern bool run_in_daemon(char *daemons) { - char *start_char = daemons, *end_char = NULL; + char *full, *start_char, *end_char; xassert(slurm_prog_name); if (!strcmp(daemons, slurm_prog_name)) return true; + full = xstrdup(daemons); + start_char = full; + while (start_char && (end_char = strstr(start_char, ","))) { *end_char = 0; - if (!strcmp(start_char, slurm_prog_name)) + if (!strcmp(start_char, slurm_prog_name)) { + xfree(full); return true; + } + start_char = end_char + 1; } + if (start_char && !strcmp(start_char, slurm_prog_name)) { + xfree(full); + return true; + } + + xfree(full); + return false; } diff --git a/src/plugins/acct_gather_energy/ipmi/acct_gather_energy_ipmi.c b/src/plugins/acct_gather_energy/ipmi/acct_gather_energy_ipmi.c index 576f013ab9e3d939744ebab826c37d10b74347bf..f8d4c03f0717a27113f2739dacc65b6a551051a3 100644 --- a/src/plugins/acct_gather_energy/ipmi/acct_gather_energy_ipmi.c +++ b/src/plugins/acct_gather_energy/ipmi/acct_gather_energy_ipmi.c @@ -160,6 +160,19 @@ static bool _is_thread_launcher(void) return run; } +static bool _run_in_daemon(void) +{ + static bool set = false; + static bool run = false; + + if (!set) { + set = 1; + run = run_in_daemon("slurmd,slurmstepd"); + } + + return run; +} + static void _task_sleep(int rem) { while (rem) @@ -816,29 +829,23 @@ static int _first_update_task_energy(void) */ extern int init(void) { - int rc = SLURM_SUCCESS; debug_flags = slurm_get_debug_flags(); - local_energy = acct_gather_energy_alloc(); - local_energy->consumed_energy=0; - local_energy->base_consumed_energy=0; - local_energy->base_watts=0; - /* put anything that requires the .conf being read in acct_gather_energy_p_conf_parse */ - if (rc == SLURM_SUCCESS) - verbose("%s loaded", plugin_name); - else - flag_energy_accounting_shutdown = true; - - return rc; + return SLURM_SUCCESS; } extern int fini(void) { + time_t begin_fini; + + if (!_run_in_daemon()) + return SLURM_SUCCESS; + flag_energy_accounting_shutdown = true; - time_t begin_fini = time(NULL); + begin_fini = time(NULL); while (flag_thread_run_running || flag_thread_write_running) { if ((time(NULL) - begin_fini) > (slurm_ipmi_conf.freq + 1)) { @@ -865,6 +872,7 @@ extern int fini(void) extern int acct_gather_energy_p_update_node_energy(void) { int rc = SLURM_SUCCESS; + xassert(_run_in_daemon()); return rc; } @@ -874,6 +882,8 @@ extern int acct_gather_energy_p_get_data(enum acct_energy_type data_type, { int rc = SLURM_SUCCESS; + xassert(_run_in_daemon()); + switch (data_type) { case ENERGY_DATA_JOULES_TASK: slurm_mutex_lock(&ipmi_mutex); @@ -904,6 +914,8 @@ extern int acct_gather_energy_p_set_data(enum acct_energy_type data_type, { int rc = SLURM_SUCCESS; + xassert(_run_in_daemon()); + switch (data_type) { case ENERGY_DATA_RECONFIG: debug_flags = slurm_get_debug_flags(); @@ -1047,6 +1059,14 @@ extern void acct_gather_energy_p_conf_set(s_p_hashtbl_t *tbl) "EnergyIPMIPowerSensor", tbl); } + if (!_run_in_daemon()) + return; + + local_energy = acct_gather_energy_alloc(); + local_energy->consumed_energy=0; + local_energy->base_consumed_energy=0; + local_energy->base_watts=0; + if (_is_thread_launcher()) { if (!flag_init) { flag_init = true; @@ -1064,4 +1084,6 @@ extern void acct_gather_energy_p_conf_set(s_p_hashtbl_t *tbl) } } else _first_update_task_energy(); + + verbose("%s loaded", plugin_name); } diff --git a/src/plugins/acct_gather_energy/rapl/acct_gather_energy_rapl.c b/src/plugins/acct_gather_energy/rapl/acct_gather_energy_rapl.c index 997682ee5f1697a02bd039d0e1b59166e456f5ce..9e555cab0526f261fcf159c3c63aac13243e9c1f 100644 --- a/src/plugins/acct_gather_energy/rapl/acct_gather_energy_rapl.c +++ b/src/plugins/acct_gather_energy/rapl/acct_gather_energy_rapl.c @@ -261,7 +261,7 @@ static bool _run_in_daemon(void) if (!set) { set = 1; - run = run_in_daemon("slurmd"); + run = run_in_daemon("slurmd,slurmstepd"); } return run; @@ -399,24 +399,11 @@ static void _get_joules_task(acct_gather_energy_t *energy) */ extern int init(void) { - int i; - uint64_t result; - - if (!_run_in_daemon()) - return SLURM_SUCCESS; - - _hardware(); - for (i = 0; i < nb_pkg; i++) - pkg_fd[i] = _open_msr(pkg2cpu[i]); - - local_energy = acct_gather_energy_alloc(); - - result = _read_msr(pkg_fd[0], MSR_RAPL_POWER_UNIT); - if (result == 0) - local_energy->current_watts = NO_VAL; - debug_flags = slurm_get_debug_flags(); - verbose("%s loaded", plugin_name); + + /* put anything that requires the .conf being read in + acct_gather_energy_p_conf_parse + */ return SLURM_SUCCESS; } @@ -494,5 +481,23 @@ extern void acct_gather_energy_p_conf_options(s_p_options_t **full_options, extern void acct_gather_energy_p_conf_set(s_p_hashtbl_t *tbl) { + int i; + uint64_t result; + + if (!_run_in_daemon()) + return; + + _hardware(); + for (i = 0; i < nb_pkg; i++) + pkg_fd[i] = _open_msr(pkg2cpu[i]); + + local_energy = acct_gather_energy_alloc(); + + result = _read_msr(pkg_fd[0], MSR_RAPL_POWER_UNIT); + if (result == 0) + local_energy->current_watts = NO_VAL; + + verbose("%s loaded", plugin_name); + return; }