Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 15 | #include <fcntl.h> |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 16 | #include <vppinfra/clib.h> |
| 17 | #include <vppinfra/format.h> |
| 18 | #include <vppinfra/cpu.h> |
| 19 | |
Damjan Marion | 6b69f94 | 2021-11-11 17:34:01 +0000 | [diff] [blame] | 20 | #define foreach_x86_cpu_uarch \ |
| 21 | _ (0x06, 0x9e, "Kaby Lake", "Kaby Lake DT/H/S/X") \ |
| 22 | _ (0x06, 0x9c, "Tremont", "Jasper Lake") \ |
| 23 | _ (0x06, 0x9a, "Alder Lake", "Alder Lake L") \ |
| 24 | _ (0x06, 0x97, "Alder Lake", "Alder Lake") \ |
| 25 | _ (0x06, 0x96, "Tremont", "Elkhart Lake") \ |
| 26 | _ (0x06, 0x8f, "Sapphire Rapids", "Sapphire Rapids X") \ |
| 27 | _ (0x06, 0x8e, "Kaby Lake", "Kaby Lake Y/U") \ |
| 28 | _ (0x06, 0x8c, "Tiger Lake", "Tiger Lake U") \ |
| 29 | _ (0x06, 0x86, "Tremont", "Jacobsville") \ |
| 30 | _ (0x06, 0x85, "Knights Mill", "Knights Mill") \ |
| 31 | _ (0x06, 0x7e, "Ice Lake", "Ice Lake U") \ |
| 32 | _ (0x06, 0x7d, "Ice Lake", "Ice Lake Y") \ |
| 33 | _ (0x06, 0x7a, "Goldmont Plus", "Gemini Lake") \ |
| 34 | _ (0x06, 0x6c, "Ice Lake", "Ice Lake SP") \ |
| 35 | _ (0x06, 0x6a, "Ice Lake", "Ice Lake DE") \ |
| 36 | _ (0x06, 0x66, "Cannon Lake", "Cannon Lake U") \ |
| 37 | _ (0x06, 0x5f, "Goldmont", "Denverton") \ |
| 38 | _ (0x06, 0x5e, "Skylake", "Skylake DT/H/S") \ |
| 39 | _ (0x06, 0x5c, "Goldmont", "Apollo Lake") \ |
| 40 | _ (0x06, 0x5a, "Silvermont", "Moorefield") \ |
| 41 | _ (0x06, 0x57, "Knights Landing", "Knights Landing") \ |
| 42 | _ (0x06, 0x56, "Broadwell", "Broadwell DE") \ |
| 43 | _ (0x06, 0x55, "Skylake", "Skylake X/SP") \ |
| 44 | _ (0x06, 0x4f, "Broadwell", "Broadwell EP/EX") \ |
| 45 | _ (0x06, 0x4e, "Skylake", "Skylake Y/U") \ |
| 46 | _ (0x06, 0x4d, "Silvermont", "Rangeley") \ |
| 47 | _ (0x06, 0x4c, "Airmont", "Braswell") \ |
| 48 | _ (0x06, 0x47, "Broadwell", "Broadwell H") \ |
| 49 | _ (0x06, 0x46, "Haswell", "Crystalwell") \ |
| 50 | _ (0x06, 0x45, "Haswell", "Haswell ULT") \ |
| 51 | _ (0x06, 0x3f, "Haswell", "Haswell E") \ |
| 52 | _ (0x06, 0x3e, "Ivy Bridge", "Ivy Bridge E/EN/EP") \ |
| 53 | _ (0x06, 0x3d, "Broadwell", "Broadwell U") \ |
| 54 | _ (0x06, 0x3c, "Haswell", "Haswell") \ |
| 55 | _ (0x06, 0x3a, "Ivy Bridge", "IvyBridge") \ |
| 56 | _ (0x06, 0x37, "Silvermont", "BayTrail") \ |
| 57 | _ (0x06, 0x36, "Saltwell", "Cedarview,Centerton") \ |
| 58 | _ (0x06, 0x35, "Saltwell", "Cloverview") \ |
| 59 | _ (0x06, 0x2f, "Westmere", "Westmere EX") \ |
| 60 | _ (0x06, 0x2e, "Nehalem", "Nehalem EX") \ |
| 61 | _ (0x06, 0x2d, "Sandy Bridge", "SandyBridge E/EN/EP") \ |
| 62 | _ (0x06, 0x2c, "Westmere", "Westmere EP/EX,Gulftown") \ |
| 63 | _ (0x06, 0x2a, "Sandy Bridge", "Sandy Bridge") \ |
| 64 | _ (0x06, 0x27, "Saltwell", "Medfield") \ |
| 65 | _ (0x06, 0x26, "Bonnell", "Tunnel Creek") \ |
| 66 | _ (0x06, 0x25, "Westmere", "Arrandale,Clarksdale") \ |
| 67 | _ (0x06, 0x1e, "Nehalem", "Clarksfield,Lynnfield,Jasper Forest") \ |
| 68 | _ (0x06, 0x1d, "Penryn", "Dunnington") \ |
| 69 | _ (0x06, 0x1c, "Bonnell", "Pineview,Silverthorne") \ |
| 70 | _ (0x06, 0x1a, "Nehalem", "Nehalem EP,Bloomfield)") \ |
| 71 | _ (0x06, 0x17, "Penryn", "Yorkfield,Wolfdale,Penryn,Harpertown") |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 72 | |
Nitin Saxena | c9122f9 | 2019-03-28 14:42:31 +0530 | [diff] [blame] | 73 | /* _(implementor-id, part-id, vendor-name, cpu-name, show CPU pass as string) */ |
Damjan Marion | 7bf8f5e | 2023-09-12 15:08:58 +0200 | [diff] [blame] | 74 | #define foreach_aarch64_cpu_uarch \ |
| 75 | _ (0x41, 0xd03, "ARM", "Cortex-A53", 0) \ |
| 76 | _ (0x41, 0xd07, "ARM", "Cortex-A57", 0) \ |
| 77 | _ (0x41, 0xd08, "ARM", "Cortex-A72", 0) \ |
| 78 | _ (0x41, 0xd09, "ARM", "Cortex-A73", 0) \ |
| 79 | _ (0x41, 0xd0a, "ARM", "Cortex-A75", 0) \ |
| 80 | _ (0x41, 0xd0b, "ARM", "Cortex-A76", 0) \ |
| 81 | _ (0x41, 0xd0c, "ARM", "Neoverse-N1", 0) \ |
| 82 | _ (0x41, 0xd49, "ARM", "Neoverse-N2", 0) \ |
| 83 | _ (0x41, 0xd4a, "ARM", "Neoverse-E1", 0) \ |
| 84 | _ (0x43, 0x0a1, "Marvell", "THUNDERX CN88XX", 0) \ |
| 85 | _ (0x43, 0x0a2, "Marvell", "OCTEON TX CN81XX", 0) \ |
| 86 | _ (0x43, 0x0a3, "Marvell", "OCTEON TX CN83XX", 0) \ |
| 87 | _ (0x43, 0x0af, "Marvell", "THUNDERX2 CN99XX", 1) \ |
| 88 | _ (0x43, 0x0b1, "Marvell", "OCTEON TX2 CN98XX", 1) \ |
| 89 | _ (0x43, 0x0b2, "Marvell", "OCTEON TX2 CN96XX", 1) |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 90 | |
Damjan Marion | dae1c7e | 2020-10-17 13:32:25 +0200 | [diff] [blame] | 91 | __clib_export u8 * |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 92 | format_cpu_uarch (u8 * s, va_list * args) |
| 93 | { |
| 94 | #if __x86_64__ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 95 | u32 __attribute__ ((unused)) eax, ebx, ecx, edx; |
Paul Vinciguerra | d6897c1 | 2018-12-30 11:07:36 -0800 | [diff] [blame] | 96 | u8 model, family, stepping; |
Sivaprasad Tummala | 6a1a832 | 2023-04-17 05:16:11 -0700 | [diff] [blame] | 97 | u8 amd_vendor = 0; |
| 98 | |
| 99 | if (__get_cpuid (0, &eax, &ebx, &ecx, &edx) == 0) |
| 100 | return format (s, "unknown (missing cpuid)"); |
| 101 | |
| 102 | if (amd_vendor (ebx, ecx, edx)) |
| 103 | amd_vendor = 1; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 104 | |
| 105 | if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0) |
| 106 | return format (s, "unknown (missing cpuid)"); |
| 107 | |
Paul Vinciguerra | d6897c1 | 2018-12-30 11:07:36 -0800 | [diff] [blame] | 108 | stepping = eax & 0x0f; |
Sivaprasad Tummala | 6a1a832 | 2023-04-17 05:16:11 -0700 | [diff] [blame] | 109 | if (amd_vendor) |
| 110 | { |
| 111 | family = ((eax >> 8) & 0x0f); |
| 112 | model = ((eax >> 4) & 0x0f); |
| 113 | if (family >= 0xf) |
| 114 | { |
| 115 | family = family + ((eax >> 20) & 0xf); |
| 116 | model = (model | ((eax >> 12) & 0xf0)); |
| 117 | } |
| 118 | return format (s, "Zen (family 0x%02x model 0x%02x)", family, model); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | model = ((eax >> 4) & 0x0f) | ((eax >> 12) & 0xf0); |
| 123 | family = (eax >> 8) & 0x0f; |
| 124 | } |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 125 | |
Paul Vinciguerra | d6897c1 | 2018-12-30 11:07:36 -0800 | [diff] [blame] | 126 | #define _(f,m,a,c) if ((model == m) && (family == f)) return \ |
| 127 | format(s, "[0x%x] %s ([0x%02x] %s) stepping 0x%x", f, a, m, c, stepping); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 128 | foreach_x86_cpu_uarch |
| 129 | #undef _ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 130 | return format (s, "unknown (family 0x%02x model 0x%02x)", family, model); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 131 | |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 132 | #elif __aarch64__ |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 133 | unformat_input_t input; |
| 134 | u32 implementer, primary_part_number, variant, revision; |
| 135 | |
Damjan Marion | 8d0c0c6 | 2023-08-06 20:39:38 +0200 | [diff] [blame] | 136 | if (unformat_init_file (&input, "/proc/cpuinfo")) |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 137 | { |
Damjan Marion | 8d0c0c6 | 2023-08-06 20:39:38 +0200 | [diff] [blame] | 138 | while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT) |
| 139 | { |
| 140 | if (unformat (&input, "CPU implementer%_: 0x%x", &implementer)) |
| 141 | ; |
| 142 | else if (unformat (&input, "CPU part%_: 0x%x", &primary_part_number)) |
| 143 | ; |
| 144 | else if (unformat (&input, "CPU variant%_: 0x%x", &variant)) |
| 145 | ; |
| 146 | else if (unformat (&input, "CPU revision%_: %u", &revision)) |
| 147 | ; |
| 148 | else |
| 149 | unformat_skip_line (&input); |
| 150 | } |
| 151 | unformat_free (&input); |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 152 | } |
Damjan Marion | 8d0c0c6 | 2023-08-06 20:39:38 +0200 | [diff] [blame] | 153 | else |
| 154 | return format (s, "unknown"); |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 155 | |
Nitin Saxena | c9122f9 | 2019-03-28 14:42:31 +0530 | [diff] [blame] | 156 | #define _(i,p,a,c,_format) if ((implementer == i) && (primary_part_number == p)){ \ |
| 157 | if (_format)\ |
| 158 | return format(s, "%s (%s PASS %c%u)", a, c, 'A'+variant, revision);\ |
| 159 | else {\ |
| 160 | if (implementer == 0x43)\ |
| 161 | variant++; \ |
| 162 | return format (s, "%s (%s PASS %u.%u)", a, c, variant, revision);}} |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 163 | |
Gabriel Ganne | ae66b0d | 2018-01-03 09:18:47 +0100 | [diff] [blame] | 164 | foreach_aarch64_cpu_uarch |
| 165 | #undef _ |
| 166 | return format (s, "unknown (implementer 0x%02x part 0x%03x PASS %u.%u)", |
| 167 | implementer, primary_part_number, variant, revision); |
| 168 | |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 169 | #else /* ! __x86_64__ */ |
| 170 | return format (s, "unknown"); |
| 171 | #endif |
| 172 | } |
| 173 | |
Damjan Marion | dae1c7e | 2020-10-17 13:32:25 +0200 | [diff] [blame] | 174 | __clib_export u8 * |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 175 | format_cpu_model_name (u8 * s, va_list * args) |
| 176 | { |
| 177 | #if __x86_64__ |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 178 | u32 __attribute__ ((unused)) eax, ebx, ecx, edx; |
| 179 | u8 *name = 0; |
| 180 | u32 *name_u32; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 181 | |
| 182 | if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) == 0) |
| 183 | return format (s, "unknown (missing cpuid)"); |
| 184 | |
| 185 | __get_cpuid (0x80000000, &eax, &ebx, &ecx, &edx); |
| 186 | if (eax < 0x80000004) |
| 187 | return format (s, "unknown (missing ext feature)"); |
| 188 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 189 | vec_validate (name, 48); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 190 | name_u32 = (u32 *) name; |
| 191 | |
| 192 | __get_cpuid (0x80000002, &eax, &ebx, &ecx, &edx); |
| 193 | name_u32[0] = eax; |
| 194 | name_u32[1] = ebx; |
| 195 | name_u32[2] = ecx; |
| 196 | name_u32[3] = edx; |
| 197 | |
| 198 | __get_cpuid (0x80000003, &eax, &ebx, &ecx, &edx); |
| 199 | name_u32[4] = eax; |
| 200 | name_u32[5] = ebx; |
| 201 | name_u32[6] = ecx; |
| 202 | name_u32[7] = edx; |
| 203 | |
| 204 | __get_cpuid (0x80000004, &eax, &ebx, &ecx, &edx); |
| 205 | name_u32[8] = eax; |
| 206 | name_u32[9] = ebx; |
| 207 | name_u32[10] = ecx; |
| 208 | name_u32[11] = edx; |
| 209 | |
| 210 | s = format (s, "%s", name); |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 211 | vec_free (name); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 212 | return s; |
| 213 | |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 214 | #elif defined(__aarch64__) |
| 215 | return format (s, "armv8"); |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 216 | #else /* ! __x86_64__ */ |
| 217 | return format (s, "unknown"); |
| 218 | #endif |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Damjan Marion | 63c31e0 | 2022-01-19 18:13:34 +0100 | [diff] [blame] | 221 | #if defined(__x86_64__) || defined(__aarch64__) |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 222 | static inline char const * |
Benoît Ganne | a7cb357 | 2019-12-16 16:00:14 +0100 | [diff] [blame] | 223 | flag_skip_prefix (char const *flag, const char *pfx, int len) |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 224 | { |
Benoît Ganne | a7cb357 | 2019-12-16 16:00:14 +0100 | [diff] [blame] | 225 | if (0 == strncmp (flag, pfx, len - 1)) |
| 226 | return flag + len - 1; |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 227 | return flag; |
| 228 | } |
Damjan Marion | 63c31e0 | 2022-01-19 18:13:34 +0100 | [diff] [blame] | 229 | #endif |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 230 | |
Damjan Marion | dae1c7e | 2020-10-17 13:32:25 +0200 | [diff] [blame] | 231 | __clib_export u8 * |
Damjan Marion | 63c31e0 | 2022-01-19 18:13:34 +0100 | [diff] [blame] | 232 | format_cpu_flags (u8 *s, va_list *args) |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 233 | { |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 234 | #if defined(__x86_64__) |
Damjan Marion | 63c31e0 | 2022-01-19 18:13:34 +0100 | [diff] [blame] | 235 | #define _(flag, func, reg, bit) \ |
| 236 | if (clib_cpu_supports_##flag ()) \ |
| 237 | s = format (s, "%s ", flag_skip_prefix (#flag, "x86_", sizeof ("x86_"))); |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 238 | foreach_x86_64_flags return s; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 239 | #undef _ |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 240 | #elif defined(__aarch64__) |
Damjan Marion | 63c31e0 | 2022-01-19 18:13:34 +0100 | [diff] [blame] | 241 | #define _(flag, bit) \ |
| 242 | if (clib_cpu_supports_##flag ()) \ |
| 243 | s = format (s, "%s ", \ |
| 244 | flag_skip_prefix (#flag, "aarch64_", sizeof ("aarch64_"))); |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 245 | foreach_aarch64_flags return s; |
| 246 | #undef _ |
| 247 | #else /* ! ! __x86_64__ && ! __aarch64__ */ |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 248 | return format (s, "unknown"); |
| 249 | #endif |
| 250 | } |
| 251 | |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 252 | __clib_export u32 |
| 253 | clib_get_current_cpu_id () |
| 254 | { |
Tom Jones | ac80b8b | 2024-01-26 13:48:49 +0000 | [diff] [blame] | 255 | #ifdef __linux__ |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 256 | unsigned cpu, node; |
| 257 | syscall (__NR_getcpu, &cpu, &node, 0); |
| 258 | return cpu; |
Tom Jones | ac80b8b | 2024-01-26 13:48:49 +0000 | [diff] [blame] | 259 | #else |
| 260 | return 0; |
| 261 | #endif /* __linux__ */ |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 262 | } |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 263 | |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 264 | __clib_export u32 |
| 265 | clib_get_current_numa_node () |
| 266 | { |
Tom Jones | ac80b8b | 2024-01-26 13:48:49 +0000 | [diff] [blame] | 267 | #ifdef __linux__ |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 268 | unsigned cpu, node; |
| 269 | syscall (__NR_getcpu, &cpu, &node, 0); |
| 270 | return node; |
Tom Jones | ac80b8b | 2024-01-26 13:48:49 +0000 | [diff] [blame] | 271 | #else |
| 272 | return 0; |
| 273 | #endif /* __linux__ */ |
Damjan Marion | f8cb701 | 2020-10-09 17:16:55 +0200 | [diff] [blame] | 274 | } |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 275 | |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 276 | __clib_export u8 * |
| 277 | format_march_variant (u8 *s, va_list *args) |
| 278 | { |
| 279 | clib_march_variant_type_t t = va_arg (*args, clib_march_variant_type_t); |
| 280 | char *variants[] = { [0] = "default", |
| 281 | #define _(s, n) [CLIB_MARCH_VARIANT_TYPE_##s] = n, |
| 282 | foreach_march_variant |
| 283 | #undef _ |
| 284 | }; |
| 285 | return format (s, "%s", variants[t]); |
| 286 | } |
| 287 | |
Damjan Marion | 7bf8f5e | 2023-09-12 15:08:58 +0200 | [diff] [blame] | 288 | #ifdef __aarch64__ |
| 289 | |
| 290 | __clib_export const clib_cpu_info_t * |
| 291 | clib_get_cpu_info () |
| 292 | { |
| 293 | static int first_run = 1; |
| 294 | static clib_cpu_info_t info = {}; |
| 295 | if (first_run) |
| 296 | { |
| 297 | FILE *fp = fopen ("/proc/cpuinfo", "r"); |
| 298 | char buf[128]; |
| 299 | |
| 300 | if (!fp) |
| 301 | return 0; |
| 302 | |
| 303 | while (!feof (fp)) |
| 304 | { |
| 305 | if (!fgets (buf, sizeof (buf), fp)) |
| 306 | break; |
| 307 | buf[127] = '\0'; |
| 308 | if (strstr (buf, "CPU part")) |
| 309 | info.aarch64.part_num = |
| 310 | strtol (memchr (buf, ':', 128) + 2, NULL, 0); |
| 311 | |
| 312 | if (strstr (buf, "CPU implementer")) |
| 313 | info.aarch64.implementer = |
| 314 | strtol (memchr (buf, ':', 128) + 2, NULL, 0); |
| 315 | } |
| 316 | fclose (fp); |
| 317 | |
| 318 | first_run = 0; |
| 319 | } |
| 320 | return &info; |
| 321 | } |
| 322 | |
| 323 | #endif |