diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c index 15df05b8c82244cb866b97d12098d247c1670620..4398b4f9df8613d5b921db85d49fea0f903b9548 100644 --- a/src/common/assoc_mgr.c +++ b/src/common/assoc_mgr.c @@ -44,6 +44,7 @@ #include "src/common/uid.h" #include "src/common/xstring.h" +#include "src/common/slurm_priority.h" #include "src/slurmdbd/read_config.h" #define ASSOC_USAGE_VERSION 1 @@ -1503,24 +1504,23 @@ extern List assoc_mgr_get_shares(void *db_conn, share->shares_norm = assoc->shares_norm; share->usage_raw = (uint64_t)assoc->usage_raw; - share->usage_norm = (double)assoc->usage_norm; + if(assoc->user) { /* We only calculate user effective usage when * we need it */ - long double usage_efctv = assoc->usage_norm + - ((assoc->parent_assoc_ptr->usage_efctv - - assoc->usage_norm) * - assoc->shares_raw / assoc->level_shares); - share->usage_efctv = (double)usage_efctv; + if(assoc->usage_efctv == (long double)NO_VAL) + priority_g_set_assoc_usage(assoc); + share->name = xstrdup(assoc->user); share->parent = xstrdup(assoc->acct); share->user = 1; } else { - share->usage_efctv = (double)assoc->usage_efctv; share->name = xstrdup(assoc->acct); share->parent = xstrdup(assoc->parent_acct); } + share->usage_norm = (double)assoc->usage_norm; + share->usage_efctv = (double)assoc->usage_efctv; } list_iterator_destroy(itr); slurm_mutex_unlock(&assoc_mgr_association_lock); diff --git a/src/common/slurm_priority.c b/src/common/slurm_priority.c index 45edb4d7e6c15ddc702271116afcaeb07a38f074..4430a2c7a0acd8af1e09620785b19249c8c6bdb1 100644 --- a/src/common/slurm_priority.c +++ b/src/common/slurm_priority.c @@ -46,6 +46,7 @@ typedef struct slurm_priority_ops { struct job_record *job_ptr); void (*reconfig) (); int (*set_max_usage) (uint32_t procs, uint32_t half_life); + void (*set_assoc_usage)(acct_association_rec_t *assoc); } slurm_priority_ops_t; typedef struct slurm_priority_context { @@ -83,6 +84,7 @@ static slurm_priority_ops_t * _priority_get_ops( "priority_p_set", "priority_p_reconfig", "priority_p_set_max_cluster_usage", + "priority_p_set_assoc_usage", }; int n_syms = sizeof( syms ) / sizeof( char * ); @@ -251,3 +253,12 @@ extern int priority_g_set_max_cluster_usage(uint32_t procs, uint32_t half_life) return (*(g_priority_context->ops.set_max_usage))(procs, half_life); } + +extern void priority_g_set_assoc_usage(acct_association_rec_t *assoc) +{ + if (slurm_priority_init() < 0) + return; + + (*(g_priority_context->ops.set_assoc_usage))(assoc); + return; +} diff --git a/src/common/slurm_priority.h b/src/common/slurm_priority.h index bf6b386146e1b25b4561e494f5f7840a2f5b09b4..b87a23a1589cf9a9b48c4c842c2a97c6afd2f793 100644 --- a/src/common/slurm_priority.h +++ b/src/common/slurm_priority.h @@ -50,6 +50,7 @@ #endif #include "src/slurmctld/slurmctld.h" +#include "src/common/slurm_accounting_storage.h" extern int slurm_priority_init(void); extern int slurm_priority_fini(void); @@ -65,4 +66,10 @@ extern void priority_g_reconfig(); */ extern int priority_g_set_max_cluster_usage(uint32_t procs, uint32_t half_life); +/* sets up the normalized usage and the effective usage of an + * association. + * IN/OUT: assoc - association to have usage set. + */ +extern void priority_g_set_assoc_usage(acct_association_rec_t *assoc); + #endif /*_SLURM_PRIORIY_H */ diff --git a/src/plugins/priority/basic/priority_basic.c b/src/plugins/priority/basic/priority_basic.c index d1a43d78d2c39c5bb3fc0ecf209e730af220ade0..f806d99749898ecc33f263fdc8f7ee80250c1e99 100644 --- a/src/plugins/priority/basic/priority_basic.c +++ b/src/plugins/priority/basic/priority_basic.c @@ -133,3 +133,8 @@ extern int priority_p_set_max_cluster_usage(uint32_t procs, uint32_t half_life) { return SLURM_SUCCESS; } + +extern void priority_p_set_assoc_usage(acct_association_rec_t *assoc) +{ + return; +} diff --git a/src/plugins/priority/multifactor/priority_multifactor.c b/src/plugins/priority/multifactor/priority_multifactor.c index ea0b77295c98a679048186208444ed45dec5fbfa..92eadc46b618543ae14bae4a011c8853e5fcb810 100644 --- a/src/plugins/priority/multifactor/priority_multifactor.c +++ b/src/plugins/priority/multifactor/priority_multifactor.c @@ -115,6 +115,7 @@ static long double small_usage; /* amount of usage to add if multiple * decay period for the same association */ extern int priority_p_set_max_cluster_usage(uint32_t procs, uint32_t half_life); +extern void priority_p_set_assoc_usage(acct_association_rec_t *assoc); /* * apply decay factor to all associations usage_raw @@ -149,53 +150,6 @@ static int _apply_decay(double decay_factor) return SLURM_SUCCESS; } -/* you should test for assoc == NULL before this function */ -static void _set_assoc_usage(acct_association_rec_t *assoc) -{ - char *child = "account"; - char *child_str = assoc->acct; - - if(assoc->user) { - child = "user"; - child_str = assoc->user; - } - - xassert(assoc_mgr_root_assoc); - xassert(assoc_mgr_root_assoc->usage_raw); - xassert(assoc->parent_assoc_ptr); - - assoc->usage_norm = assoc->usage_raw / assoc_mgr_root_assoc->usage_raw; - debug4("Normalized usage for %s %s off %s %Lf / %Lf = %Lf", - child, child_str, assoc->parent_assoc_ptr->acct, - assoc->usage_raw, assoc_mgr_root_assoc->usage_raw, - assoc->usage_norm); - /* This is needed in case someone changes the half-life on the - fly and now we have used more time than is available under - the new config */ - if (assoc->usage_norm > 1.0) - assoc->usage_norm = 1.0; - - if (assoc->parent_assoc_ptr == assoc_mgr_root_assoc) { - assoc->usage_efctv = assoc->usage_norm; - debug4("Effective usage for %s %s off %s %Lf %Lf", - child, child_str, assoc->parent_assoc_ptr->acct, - assoc->usage_efctv, assoc->usage_norm); - } else { - assoc->usage_efctv = assoc->usage_norm + - ((assoc->parent_assoc_ptr->usage_efctv - - assoc->usage_norm) * - assoc->shares_raw / - (long double)assoc->level_shares); - debug4("Effective usage for %s %s off %s " - "%Lf + ((%Lf - %Lf) * %d / %d) = %Lf", - child, child_str, assoc->parent_assoc_ptr->acct, - assoc->usage_norm, - assoc->parent_assoc_ptr->usage_efctv, - assoc->usage_norm, assoc->shares_raw, - assoc->level_shares, assoc->usage_efctv); - } -} - static time_t _read_last_decay_ran() { int data_allocated, data_read = 0; @@ -338,7 +292,7 @@ static int _set_children_usage_efctv(List childern_list) assoc->usage_efctv = (long double)NO_VAL; continue; } - _set_assoc_usage(assoc); + priority_p_set_assoc_usage(assoc); _set_children_usage_efctv(assoc->childern_list); } list_iterator_destroy(itr); @@ -365,7 +319,7 @@ static double _get_fairshare_priority( struct job_record *job_ptr ) slurm_mutex_lock(&assoc_mgr_association_lock); if(assoc->usage_efctv == (long double)NO_VAL) { - _set_assoc_usage(assoc); + priority_p_set_assoc_usage(assoc); } else { /* Add a tiny amount so the next job will get a lower priority than the previous jobs if they are @@ -797,3 +751,52 @@ extern int priority_p_set_max_cluster_usage(uint32_t procs, uint32_t half_life) return SLURM_SUCCESS; } + +extern void priority_p_set_assoc_usage(acct_association_rec_t *assoc) +{ + char *child = "account"; + char *child_str = assoc->acct; + + xassert(assoc); + + if(assoc->user) { + child = "user"; + child_str = assoc->user; + } + + xassert(assoc_mgr_root_assoc); + xassert(assoc_mgr_root_assoc->usage_raw); + xassert(assoc->parent_assoc_ptr); + + assoc->usage_norm = assoc->usage_raw / assoc_mgr_root_assoc->usage_raw; + debug4("Normalized usage for %s %s off %s %Lf / %Lf = %Lf", + child, child_str, assoc->parent_assoc_ptr->acct, + assoc->usage_raw, assoc_mgr_root_assoc->usage_raw, + assoc->usage_norm); + /* This is needed in case someone changes the half-life on the + fly and now we have used more time than is available under + the new config */ + if (assoc->usage_norm > 1.0) + assoc->usage_norm = 1.0; + + if (assoc->parent_assoc_ptr == assoc_mgr_root_assoc) { + assoc->usage_efctv = assoc->usage_norm; + debug4("Effective usage for %s %s off %s %Lf %Lf", + child, child_str, assoc->parent_assoc_ptr->acct, + assoc->usage_efctv, assoc->usage_norm); + } else { + assoc->usage_efctv = assoc->usage_norm + + ((assoc->parent_assoc_ptr->usage_efctv - + assoc->usage_norm) * + assoc->shares_raw / + (long double)assoc->level_shares); + debug4("Effective usage for %s %s off %s " + "%Lf + ((%Lf - %Lf) * %d / %d) = %Lf", + child, child_str, assoc->parent_assoc_ptr->acct, + assoc->usage_norm, + assoc->parent_assoc_ptr->usage_efctv, + assoc->usage_norm, assoc->shares_raw, + assoc->level_shares, assoc->usage_efctv); + } +} + diff --git a/src/sshare/process.c b/src/sshare/process.c index d3a2a9bb0d14167abf2eb9d6ff382268321c38c0..9412b81854bb94927807ff3ea684743e2ee067e4 100644 --- a/src/sshare/process.c +++ b/src/sshare/process.c @@ -120,7 +120,7 @@ extern int process(shares_response_msg_t *resp) format_list = list_create(slurm_destroy_char); slurm_addto_char_list(format_list, - "A,User,Id,RawShares,NormShares," + "A,User,RawShares,NormShares," "RawUsage,NormUsage,EffUsage"); print_fields_list = list_create(destroy_print_field);