-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_allocation.rb
48 lines (42 loc) · 1.21 KB
/
cpu_allocation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/ruby -w
require 'facter'
numa_list=Facter::Util::Resolution.exec("lscpu | grep 'NUMA .* CPU'")
numa_lines=numa_list.split("\n")
numa_nodes_core_info=Array.new
numa_nodes_pci_address=Array.new
numa_lines.each_with_index do |line,index|
numa_nodes_core_info[index] = Hash.new
cpu_range = line.split(':').last.strip()
if cpu_range.include? "-"
cpu_range_list=cpu_range.split('-')
if cpu_range_list.length==2
numa_nodes_core_info[index] = (cpu_range_list[0]..cpu_range_list[1]).to_a
end
else
numa_nodes[index][0]=cpu_range
end
end
Dir["/sys/bus/pci/devices/*"].each do |pci_address_dir|
file_name = File.join(pci_address_dir,"numa_node")
if File.file?(file_name)
pci_numa_node = Facter::Util::Resolution.exec("cat #{file_name}").to_i
if pci_numa_node!=-1
if numa_nodes_pci_address[pci_numa_node].nil?
numa_nodes_pci_address[pci_numa_node]=Array.new
end
numa_nodes_pci_address[pci_numa_node]<< File.basename(pci_address_dir)
end
end
end
Facter.add(:numa_core_info) do
confine :kernel => :linux
setcode do
numa_nodes_core_info
end
end
Facter.add(:numa_pci_address) do
confine :kernel => :linux
setcode do
numa_nodes_pci_address
end
end