Revert "docs: Release Notes: Add Label"
[armband.git] / patches / fuel-nailgun-agent / 0003-AArch64-Add-CPU-details-detection.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Sun, 15 Jan 2017 08:09:10 +0100
3 Subject: [PATCH] AArch64: Add CPU details detection
4
5 [ Alexandru Avadanii ]
6 Based on Stan's previous patch for ohai, extend fuel-nailgun-agent
7 to properly support AArch64 CPUs.
8
9 [ Stanislaw Kardach ]
10 There is currently little human readable detail in /proc/cpuinfo on
11 arm64 so this patch tries to enchance this information by parsing the
12 DMI data (using `dmidecode`) and fail gracefully to empty strings
13 if no information could not be read from there. By no means this
14 parsing is to be taken as a standardised way of discovering an
15 arm64 CPU, it is just a suggestion.
16
17 Signed-off-by: Stanislaw Kardach <stanislaw.kardach@cavium.com>
18 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
19 ---
20  agent | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21  1 file changed, 90 insertions(+)
22
23 diff --git a/agent b/agent
24 index 0c56264..eeb4d26 100755
25 --- a/agent
26 +++ b/agent
27 @@ -340,6 +340,15 @@ class NodeAgent
28    end
29
30    def _get_detailed_cpuinfo
31 +    case `uname -m`
32 +      when /aarch64.*/
33 +        _get_detailed_cpuinfo_for_arm64
34 +      else # default to x86
35 +        _get_detailed_cpuinfo_for_x86
36 +    end
37 +  end
38 +
39 +  def _get_detailed_cpuinfo_for_x86
40      real = {}
41      info = {}
42      info[:total] = 0
43 @@ -371,6 +380,87 @@ class NodeAgent
44      info
45    end
46
47 +  def _get_detailed_cpuinfo_for_arm64
48 +    cpu_implementers = {
49 +      "0x41" => "ARM",
50 +      "0x53" => "Samsung",
51 +      "0x51" => "Qualcom",
52 +      "0x43" => "Cavium",
53 +      "0x50" => "APM"
54 +    }
55 +    core_models = {
56 +      "0xd04" => "cortex-a35",
57 +      "0xd03" => "cortex-a53",
58 +      "0xd07" => "cortex-a57",
59 +      "0xd08" => "cortex-a72",
60 +      "0x001" => "exynos-m1",
61 +      "0x800" => "qdf24xx",
62 +      "0x0a1" => "thunderx",
63 +      "0x000" => "xgene1",
64 +      "0xd07.0xd03" => "cortex-a57.cortex-a53",
65 +      "0xd08.0xd03" => "cortex-a72.cortex-a53"
66 +    }
67 +    cpuinfo = {}
68 +    real_cpus = {}
69 +    cpu_number = -1
70 +    current_cpu = nil
71 +    `dmidecode -t 4 -q`.each_line do |line|
72 +      case line
73 +        when /Processor Information/
74 +          cpu_number +=1
75 +          real_cpus[cpu_number] = {}
76 +        when /\s*Manufacturer:\s(.+)/
77 +          real_cpus[cpu_number][:vendor_id] = $1
78 +        when /\s*Family:\s(.+)/
79 +          real_cpus[cpu_number][:family] = $1
80 +        when /\s*Max Speed:\s(.+)\s*MHz/
81 +          real_cpus[cpu_number][:mhz] = $1.strip
82 +        when /\s*Core Enabled:\s(.+)/
83 +          real_cpus[cpu_number][:cores] = $1
84 +      end
85 +    end
86 +
87 +    cpu_number = 0
88 +    File.open("/proc/cpuinfo").each do |line|
89 +      case line
90 +      when /processor\s+:\s(.+)/
91 +        cpuinfo[$1] = {}
92 +        current_cpu = $1
93 +        cpu_number += 1
94 +        phys_id = File.read(
95 +          "/sys/devices/system/cpu/cpu%d/topology/physical_package_id" %
96 +            $1).strip
97 +        i = phys_id.to_i
98 +        cpuinfo[$1][:core_id] =
99 +          File.read("/sys/devices/system/cpu/cpu%d/topology/core_id" %
100 +            $1).strip rescue ""
101 +        cpuinfo[$1][:physical_id] = phys_id if not phys_id.empty?
102 +        if real_cpus[i].nil?
103 +          i = 0
104 +        end
105 +        if not real_cpus[i].nil?
106 +          cpuinfo[$1][:family] = real_cpus[i][:family] rescue ""
107 +          cpuinfo[$1][:cores] = real_cpus[i][:cores] rescue ""
108 +          cpuinfo[$1][:mhz] = real_cpus[i][:mhz] rescue ""
109 +        end
110 +      when /CPU implementer\s+:\s(.+)/
111 +        cpuinfo[current_cpu][:vendor_id] = cpu_implementers[$1]
112 +        cpuinfo[current_cpu][:vendor_id] ||= real_cpus[cpuinfo[current_cpu][:physical_id].to_i][:vendor_id] rescue nil
113 +        cpuinfo[current_cpu][:vendor_id] ||= real_cpus[0][:vendor_id] rescue nil
114 +        cpuinfo[current_cpu][:vendor_id] ||= $1
115 +      when /CPU part\s+:\s(.+)/
116 +        cpuinfo[current_cpu][:model] = $1
117 +        cpuinfo[current_cpu][:model_name] = core_models[$1]
118 +        cpuinfo[current_cpu][:model_name] ||= ""
119 +      when /Features\s+:\s(.+)/
120 +        cpuinfo[current_cpu][:flags] = $1.split(' ')
121 +      end
122 +    end
123 +    cpuinfo[:total] = cpu_number
124 +    cpuinfo[:real] = real_cpus.keys.length
125 +    cpuinfo
126 +  end
127 +
128    def _get_blkdev_info
129      info = {}
130      if File.directory?('/sys/block/')