From 714b6e4d7d0e0ad20702b2fbfbe9b14dc2276bd2 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Sat, 21 Feb 2009 00:10:33 +0000
Subject: [PATCH] fix for sshare working correctly

---
 src/common/assoc_mgr.c                        |  14 +--
 src/common/slurm_priority.c                   |  11 ++
 src/common/slurm_priority.h                   |   7 ++
 src/plugins/priority/basic/priority_basic.c   |   5 +
 .../multifactor/priority_multifactor.c        | 101 +++++++++---------
 src/sshare/process.c                          |   2 +-
 6 files changed, 83 insertions(+), 57 deletions(-)

diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c
index 15df05b8c82..4398b4f9df8 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 45edb4d7e6c..4430a2c7a0a 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 bf6b386146e..b87a23a1589 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 d1a43d78d2c..f806d997498 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 ea0b77295c9..92eadc46b61 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 d3a2a9bb0d1..9412b81854b 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);
-- 
GitLab