Merge "NUMA topology discovering"

This commit is contained in:
Jenkins 2016-02-25 12:16:51 +00:00 committed by Gerrit Code Review
commit 6ae1bb9c64
1 changed files with 50 additions and 0 deletions

50
agent
View File

@ -31,6 +31,8 @@ require 'timeout'
require 'uri'
# TODO(vsharshov): replace below lines by this string after excluding Ruby 1.8
require 'pathname'
require 'rexml/document'
include REXML
unless Process.euid == 0
puts "You must be root"
@ -147,6 +149,7 @@ class NodeAgent
@api_url = "#{scheme}://#{@api_ip}:#{api_port}/api"
@logger.info("API URL is #{@api_url}")
@os = ohai_system_info
@numa_topology = get_numa_topology
end
def get_scheme_and_port
@ -276,6 +279,7 @@ class NodeAgent
:disks => [],
:memory => (_dmi_memory or _ohai_memory),
:pci_devices => _get_pci_dev_list,
:numa_topology => @numa_topology,
}
admin_mac = (_master_ip_and_mac[:mac] or @os[:macaddress]) rescue nil
@ -808,6 +812,52 @@ class NodeAgent
@logger.warn("Can't get data from lshw. Reason: #{e.message}")
end
def get_numa_topology
# Output EXAMPLE:
# <distances nbobjs="2" relative_depth="1" latency_base="10.000000">
# <latency value="1.000000"/>
# <latency value="2.100000"/>
# <latency value="2.100000"/>
# <latency value="1.000000"/>
# </distances>
# <object type="NUMANode" os_index="0" cpuset="0x3ff003ff" complete_cpuset="0x3ff003ff" online_cpuset="0x3ff003ff" allowed_cpuset="0x3ff003ff" nodeset="0x00000001" complete_nodeset="0x00000001" allowed_nodeset="0x00000001" local_memory="67452473344">
# <page_type size="4096" count="14370737"/>
# <page_type size="1073741824" count="8"/>
doc = Document.new `lstopo --no-caches --of xml`
topology = {:numa_nodes => [], :supported_hugepages => supported_hugepages, :distances => nil}
doc.elements.each('/topology/object/distances/') do |dist|
topology[:distances] = dist.elements.collect{|v| v.attributes['value']}
.each_slice(dist.attributes['nbobjs'].to_i).to_a
end
numa_node = "/topology/object/object[@type='NUMANode']"
element = doc.elements[numa_node] ? numa_node : "/topology/object[@type='Machine']"
doc.elements.each(element) do |numa|
struct = {:id=> nil, :cpus => [], :memory => nil}
struct[:id] = numa.attributes['os_index'].to_i
struct[:memory] = numa.attributes['local_memory'].to_i
numa.elements.each("object/object/object[@type='PU']") do |pu|
struct[:cpus] << pu.attributes['os_index'].to_i
end
topology[:numa_nodes] << struct
end
topology
rescue e
logger.error "Something went wrong with parsing lstopo: #{e.backtrace}"
nil
end
def supported_hugepages
return [2048, 1048576] if @os[:cpu]['0']['flags'].include?('pdpe1gb')
return [2048] if @os[:cpu]['0']['flags'].include?('pse')
[]
end
def update_state
@node_state = nil
if File.exist?("/etc/nailgun_systemtype")