From 4886952ee53106521c6548da5ff206c31974b64e Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 6 Oct 2010 14:57:27 +0200
Subject: [PATCH] Add a hack for normalized CPU values in hspace
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, the key metrics/tiered spec computations show the virtual cpu
count. However, since we do have a maximum ration Vcpu/Pcpu, we can also
show the β€œnormalized” cpu count, i.e. the equivalent physical cpu count
corresponding to the virtual ones.
---
 hspace.1  | 10 ++++++----
 hspace.hs | 17 +++++++++--------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/hspace.1 b/hspace.1
index 34d147ed6..23bd296ae 100644
--- a/hspace.1
+++ b/hspace.1
@@ -144,18 +144,20 @@ complete value for this variable could be: \fB4096,102400,2=225
 2560,102400,2=20 512,102400,2=21\fR.
 
 .TP
-.I KM_USED_CPU, KM_USED_MEM, KM_USED_DSK
+.I KM_USED_CPU, KM_USED_NPU, KM_USED_MEM, KM_USED_DSK
 These represents the metrics of used resources at the start of the
-computation (only for tiered allocation mode).
+computation (only for tiered allocation mode). The NPU value is
+"normalized" CPU count, i.e. the number of virtual CPUs divided by the
+maximum ratio of the virtual to physical CPUs.
 
 .TP
-.I KM_POOL_CPU, KM_POOL_MEM, KM_POOL_DSK
+.I KM_POOL_CPU, KM_POOL_NPU, KM_POOL_MEM, KM_POOL_DSK
 These represents the total resources allocated during the tiered
 allocation process. In effect, they represent how much is readily
 available for allocation.
 
 .TP
-.I KM_UNAV_CPU, KM_UNAV_MEM, KM_UNAV_DSK
+.I KM_UNAV_CPU, KM_POOL_NPU, KM_UNAV_MEM, KM_UNAV_DSK
 These represents the resources left over (either free as in
 unallocable or allocable on their own) after the tiered allocation has
 been completed. They represent better the actual unallocable
diff --git a/hspace.hs b/hspace.hs
index 8b8405c76..90986d950 100644
--- a/hspace.hs
+++ b/hspace.hs
@@ -154,21 +154,22 @@ printResults fin_nl num_instances allocs sreason = do
   -- this should be the final entry
   printKeys [("OK", "1")]
 
-formatRSpec :: String -> RSpec -> [(String, String)]
-formatRSpec s r =
+formatRSpec :: Double -> String -> RSpec -> [(String, String)]
+formatRSpec m_cpu s r =
     [ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r)
+    , ("KM_" ++ s ++ "_NPU", show $ fromIntegral (rspecCpu r) / m_cpu)
     , ("KM_" ++ s ++ "_MEM", show $ rspecMem r)
     , ("KM_" ++ s ++ "_DSK", show $ rspecDsk r)
     ]
 
-printAllocationStats :: Node.List -> Node.List -> IO ()
-printAllocationStats ini_nl fin_nl = do
+printAllocationStats :: Double -> Node.List -> Node.List -> IO ()
+printAllocationStats m_cpu ini_nl fin_nl = do
   let ini_stats = Cluster.totalResources ini_nl
       fin_stats = Cluster.totalResources fin_nl
       (rini, ralo, runa) = Cluster.computeAllocationDelta ini_stats fin_stats
-  printKeys $ formatRSpec "USED" rini
-  printKeys $ formatRSpec "POOL" ralo
-  printKeys $ formatRSpec "UNAV" runa
+  printKeys $ formatRSpec m_cpu  "USED" rini
+  printKeys $ formatRSpec m_cpu "POOL"ralo
+  printKeys $ formatRSpec m_cpu "UNAV" runa
 
 -- | Ensure a value is quoted if needed
 ensureQuoted :: String -> String
@@ -318,7 +319,7 @@ main = do
                              out_path
        printKeys $ printStats PTiered (Cluster.totalResources trl_nl)
        printKeys [("TSPEC", intercalate " " spec_map')]
-       printAllocationStats nl trl_nl)
+       printAllocationStats m_cpu nl trl_nl)
 
   -- Run the standard (avg-mode) allocation
 
-- 
GitLab