From b25abb3a9f700276d4f012d6e72e0d11f41e7ea3 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Fri, 17 Jul 2015 11:39:20 -0700
Subject: [PATCH] Convert burst buffer base unit from GB to MB

This will make using the Cray test environemt easier
---
 doc/html/burst_buffer.shtml                   |  4 +--
 doc/man/man5/burst_buffer.conf.5              |  8 ++---
 src/api/burst_buffer_info.c                   | 10 +++---
 .../burst_buffer/common/burst_buffer_common.c | 11 +++---
 .../burst_buffer/cray/burst_buffer_cray.c     | 35 ++++++-------------
 5 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/doc/html/burst_buffer.shtml b/doc/html/burst_buffer.shtml
index b5c7c4ff47e..5e70bb50dbc 100644
--- a/doc/html/burst_buffer.shtml
+++ b/doc/html/burst_buffer.shtml
@@ -169,7 +169,7 @@ buffer plugins.<br>
 <i>type</i> specifies a Cray generic burst buffer resource, for example "nodes".<br>
 if "type" is not specified, the number is a measure of storage space.<br>
 <i>units</i> may be "N" (nodes), "GB" (gigabytes), "TB" (terabytes),
-"PB" (petabytes), etc. with the default units being gigabyes for reservations
+"PB" (petabytes), etc. with the default units being megabyes for reservations
 of storage space.<br>
 
 Jobs using this reservation are not restricted to these burst buffer resources,
@@ -186,6 +186,6 @@ $ scontrol create reservation StartTime=noon duration=60 \
   BurstBuffer=cray:nodes:2,generic:20GB
 </pre>
 
-<p style="text-align:center;">Last modified 25 March 2015</p>
+<p style="text-align:center;">Last modified 17 July 2015</p>
 
 <!--#include virtual="footer.txt"-->
diff --git a/doc/man/man5/burst_buffer.conf.5 b/doc/man/man5/burst_buffer.conf.5
index 7d2eaee939e..24dddb3e61b 100644
--- a/doc/man/man5/burst_buffer.conf.5
+++ b/doc/man/man5/burst_buffer.conf.5
@@ -50,8 +50,8 @@ and it's default value is /opt/cray/dw_wlm/default/bin/dw_wlm_cli.
 
 .TP
 \fBGranularity\fR
-Granularity of job space allocations in units of gigabytes.
-The default value is 1 gigabyte.
+Granularity of job space allocations in units of megabytes.
+The default value is 1 megabyte.
 This option is not used by the burst_buffer/cray plugin.
 
 .\ Possible future enhancement
@@ -72,7 +72,7 @@ This option is not used by the burst_buffer/cray plugin.
 Maximum burst buffer allocation size for any single job.
 The numeric value may have a suffix of "m" (megabytes), "g" (gigabytes),
 "t" (terabytes), "p" (petabytes), or "n" (nodes).
-Gigabytes is assumed if no suffix is supplied.
+Megabytes is assumed if no suffix is supplied.
 By default there is no job allocation size limit.
 
 .TP
@@ -144,7 +144,7 @@ The size is calculated by adding the burst buffer allocations for all jobs
 plus any persistent buffers belonging to the user.
 The numeric value may have a suffix of "m" (megabytes), "g" (gigabytes),
 "t" (terabytes), "p" (petabytes), or "n" (nodes).
-Gigabytes is assumed if no suffix is supplied.
+Megabytes is assumed if no suffix is supplied.
 By default there is no job allocation size limit.
 
 .SH "EXAMPLE"
diff --git a/src/api/burst_buffer_info.c b/src/api/burst_buffer_info.c
index 1c469a743ce..aac032c9741 100644
--- a/src/api/burst_buffer_info.c
+++ b/src/api/burst_buffer_info.c
@@ -60,7 +60,7 @@
 #include "src/common/xstring.h"
 
 /* Reformat a numeric value with an appropriate suffix.
- * The units are GB */
+ * The units are MB */
 static void _get_size_str(char *buf, size_t buf_size, uint64_t num)
 {
 	uint64_t tmp64;
@@ -68,16 +68,16 @@ static void _get_size_str(char *buf, size_t buf_size, uint64_t num)
 	if ((num == NO_VAL64) || (num == INFINITE64)) {
 		snprintf(buf, buf_size, "INFINITE");
 	} else if (num == 0) {
-		snprintf(buf, buf_size, "0GB");
+		snprintf(buf, buf_size, "0MB");
 	} else if ((num % (1024 * 1024)) == 0) {
 		tmp64 = num / (1024 * 1024);
-		snprintf(buf, buf_size, "%"PRIu64"PB", tmp64);
+		snprintf(buf, buf_size, "%"PRIu64"TB", tmp64);
 	} else if ((num % 1024) == 0) {
 		tmp64 = num / 1024;
-		snprintf(buf, buf_size, "%"PRIu64"TB", tmp64);
+		snprintf(buf, buf_size, "%"PRIu64"GB", tmp64);
 	} else {
 		tmp64 = num;
-		snprintf(buf, buf_size, "%"PRIu64"GB", tmp64);
+		snprintf(buf, buf_size, "%"PRIu64"MB", tmp64);
 	}
 }
 
diff --git a/src/plugins/burst_buffer/common/burst_buffer_common.c b/src/plugins/burst_buffer/common/burst_buffer_common.c
index 718684f23dc..ef4fe670ec5 100644
--- a/src/plugins/burst_buffer/common/burst_buffer_common.c
+++ b/src/plugins/burst_buffer/common/burst_buffer_common.c
@@ -620,7 +620,8 @@ extern void bb_pack_state(bb_state_t *state_ptr, Buf buffer,
 }
 
 /* Translate a burst buffer size specification in string form to numeric form,
- * recognizing various sufficies (MB, GB, TB, PB, and Nodes). */
+ * recognizing various sufficies (MB, GB, TB, PB, and Nodes). Default units
+ * are MB. */
 extern uint64_t bb_get_size_num(char *tok, uint64_t granularity)
 {
 	char *end_ptr = NULL;
@@ -631,13 +632,13 @@ extern uint64_t bb_get_size_num(char *tok, uint64_t granularity)
 	if (bb_size_i > 0) {
 		bb_size_u = (uint64_t) bb_size_i;
 		if ((end_ptr[0] == 'm') || (end_ptr[0] == 'M')) {
-			bb_size_u = (bb_size_u + 1023) / 1024;
-		} else if ((end_ptr[0] == 'g') || (end_ptr[0] == 'G')) {
 			;
-		} else if ((end_ptr[0] == 't') || (end_ptr[0] == 'T')) {
+		} else if ((end_ptr[0] == 'g') || (end_ptr[0] == 'G')) {
 			bb_size_u *= 1024;
-		} else if ((end_ptr[0] == 'p') || (end_ptr[0] == 'P')) {
+		} else if ((end_ptr[0] == 't') || (end_ptr[0] == 'T')) {
 			bb_size_u *= (1024 * 1024);
+		} else if ((end_ptr[0] == 'p') || (end_ptr[0] == 'P')) {
+			bb_size_u *= (1024 * 1024 * 1024);
 		}
 	}
 
diff --git a/src/plugins/burst_buffer/cray/burst_buffer_cray.c b/src/plugins/burst_buffer/cray/burst_buffer_cray.c
index 1983cf22831..55461882ad5 100644
--- a/src/plugins/burst_buffer/cray/burst_buffer_cray.c
+++ b/src/plugins/burst_buffer/cray/burst_buffer_cray.c
@@ -108,9 +108,6 @@ typedef struct bb_entry {
 	uint64_t granularity;
 	uint64_t quantity;
 	uint64_t free;
-	uint64_t gb_granularity;
-	uint64_t gb_quantity;
-	uint64_t gb_free;
 } bb_entry_t;
 
 typedef struct {
@@ -481,8 +478,6 @@ static bool _test_bb_spec(struct job_record *job_ptr)
 
 /*
  * Determine the current actual burst buffer state.
- * Run the program "get_sys_state" and parse stdout for details.
- * job_id IN - specific job to get information about, or 0 for all jobs
  */
 static void _load_state(void)
 {
@@ -505,13 +500,15 @@ first_load = false;
 
 	for (i = 0; i < num_ents; i++) {
 		/* ID: "bytes" */
-		if (strcmp(ents[i].id, "bytes") == 0) {
+//		if (strcmp(ents[i].id, "bytes") == 0) {
+		if (strcmp(ents[i].id, "dwcache") == 0) {
 			bb_state.bb_config.granularity
-				= ents[i].gb_granularity;
+				= ents[i].granularity;
 			bb_state.total_space
-				= ents[i].gb_quantity;
+				= ents[i].quantity * ents[i].granularity;
 			bb_state.used_space
-				= ents[i].gb_quantity - ents[i].gb_free;
+				= (ents[i].quantity - ents[i].free) *
+				  ents[i].granularity;
 			xassert(bb_state.used_space >= 0);
 
 			/* Everything else is a burst buffer
@@ -529,9 +526,9 @@ first_load = false;
 			   bb_state.bb_config.gres_cnt;
 		bb_state.bb_config.gres_cnt++;
 		gres_ptr->avail_cnt = ents[i].quantity;
-		gres_ptr->granularity = ents[i].gb_granularity;
+		gres_ptr->granularity = ents[i].granularity;
 		gres_ptr->name = xstrdup(ents[i].id);
-		gres_ptr->used_cnt = ents[i].gb_quantity - ents[i].gb_free;
+		gres_ptr->used_cnt = ents[i].quantity - ents[i].free;
 	}
 	_bb_free_entry(ents, num_ents);
 }
@@ -2492,22 +2489,10 @@ _json_parse_array(json_object *jobj, char *key, int *num)
 	for (i = 0; i < *num; i++) {
 		jvalue = json_object_array_get_idx(jarray, i);
 		_json_parse_object(jvalue, &ents[i]);
-		/* Convert to GB
+		/* Convert to Bytes to MB
 		 */
 		if (strcmp(ents[i].units, "bytes") == 0) {
-			ents[i].gb_granularity
-				= ents[i].granularity/(1024*1024*1024);
-			ents[i].gb_quantity
-				= ents[i].quantity * ents[i].gb_granularity;
-			ents[i].gb_free
-				= ents[i].free * ents[i].gb_granularity;
-		} else {
-			/* So the caller can use all the entries
-			 * in a loop.
-			 */
-			ents[i].gb_granularity = ents[i].granularity;
-			ents[i].gb_quantity = ents[i].quantity;
-			ents[i].gb_free = ents[i].free;
+			ents[i].granularity /= (1024 * 1024);
 		}
 	}
 
-- 
GitLab