BBlack has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/372544 )

Change subject: numa.rb: add nodes and inverted cpumask
......................................................................


numa.rb: add nodes and inverted cpumask

Change-Id: Icb1c5f63ca966ff8c51d40d2603bd8108ff09243
---
M modules/base/lib/facter/numa.rb
1 file changed, 40 insertions(+), 6 deletions(-)

Approvals:
  BBlack: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/base/lib/facter/numa.rb b/modules/base/lib/facter/numa.rb
index 7084bd6..b1131f1 100644
--- a/modules/base/lib/facter/numa.rb
+++ b/modules/base/lib/facter/numa.rb
@@ -12,11 +12,19 @@
 # attached to a single specific node is assigned to all nodes in the output
 # here, as shown for "lo" in the first example below.
 #
+# device_to_cpumask_invert gives a sysfs "cpumask" form which specifies all
+# CPUs which are not part of the NUMA node of the adapter.  In the case of
+# non-NUMA adapaters like "lo", it will be all-cpus instead of no-cpus, to
+# avoid common silly failure modes when applying this data in non-NUMA cases.
+# The intent is to use this cpumask to move low-priority (or at least,
+# non-network) work away from the NUMA node of the adapter.
+#
 # Example with 2x numa nodes as 2x cpu dies.  Each die has 4 physical (8 
logical
 # HT) cpu cores, system would show "16 cpus" in the simple view.  eth0 and eth1
 # are each attached to a distinct node:
 #
 # numa = {
+#    "nodes" => [0,1]
 #    "device_to_node" => {
 #        "eth0" => [0]
 #        "eth1" => [1]
@@ -28,12 +36,18 @@
 #        "lo"   => [[0, 8], [1, 9], [2, 10], [3, 11],
 #                   [4, 12], [5, 13], [6, 14], [7, 15]],
 #    }
+#    device_to_cpumask_invert => {
+#        "eth0" => "aaaa", # node1's cpus
+#        "eth1" => "5555", # node0's cpus
+#        "lo"   => "ffff", # all cpus
+#    }
 # }
 #
 # Minimal example, how things might look on a small or virtual node with 1
 # single-core CPU lacking HT:
 #
 # numa = {
+#    "nodes" => [0]
 #    "device_to_node" => {
 #        "eth0" => [0],
 #        "lo"   => [0],
@@ -41,6 +55,10 @@
 #    "device_to_htset" => {
 #        "eth0" => [[0]],
 #        "lo"   => [[0]],
+#    }
+#    device_to_cpumask_invert => {
+#        "eth0" => "1",
+#        "lo"   => "1",
 #    }
 # }
 #
@@ -66,23 +84,39 @@
   node_to_htset
 end
 
+def get_cpumask(nodes)
+  nodes.map do |n|
+    File.open("/sys/devices/system/node/node#{n}/cpumap")
+        .read.tr(',', '').to_i(16)
+  end.reduce(:|).to_s(16).reverse.scan(/.{8}|.+/).join(',').reverse
+end
+
 Facter.add('numa') do
   setcode do
     nodes = nodes_list
     node_to_htset = nodes_to_htsets(nodes)
     device_to_node = {}
     device_to_htset = {}
+    device_to_cpumask_invert = {}
     Pathname.glob('/sys/class/net/*').sort.each do |d|
       dev = d.to_s.split('/')[4]
       nodefile = "#{d}/device/numa_node"
       raw_node = File.exist?(nodefile) ? File.open(nodefile, 'r').read.to_i : 
-1
-      device_to_node[dev] = raw_node >= 0 ? [raw_node] : nodes
-      device_to_htset[dev] = []
-      device_to_node[dev].each do |dn|
-        device_to_htset[dev].concat(node_to_htset[dn])
+      if raw_node >= 0 && nodes.length > 1
+        device_to_node[dev] = [raw_node]
+        device_to_htset[dev] = node_to_htset[raw_node]
+        device_to_cpumask_invert[dev] = get_cpumask(nodes - [raw_node])
+      else
+        device_to_node[dev] = nodes
+        device_to_htset[dev] = node_to_htset.values.flatten(1).sort
+        device_to_cpumask_invert[dev] = get_cpumask(nodes)
       end
-      device_to_htset[dev].sort!
     end
-    { 'device_to_node' => device_to_node, 'device_to_htset' => device_to_htset 
}
+    {
+      'nodes' => nodes,
+      'device_to_node' => device_to_node,
+      'device_to_htset' => device_to_htset,
+      'device_to_cpumask_invert' => device_to_cpumask_invert,
+    }
   end
 end

-- 
To view, visit https://gerrit.wikimedia.org/r/372544
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icb1c5f63ca966ff8c51d40d2603bd8108ff09243
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BBlack <[email protected]>
Gerrit-Reviewer: BBlack <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to