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 | */ |
| 15 | |
| 16 | #ifndef included_clib_cpu_h |
| 17 | #define included_clib_cpu_h |
| 18 | |
Damjan Marion | 0a78fa1 | 2019-01-19 23:45:36 +0100 | [diff] [blame] | 19 | #include <sys/syscall.h> |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 20 | #include <vppinfra/format.h> |
| 21 | |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 22 | #if defined(__x86_64__) |
| 23 | #define foreach_march_variant \ |
Damjan Marion | 98f7f0a | 2023-04-17 09:38:11 +0000 | [diff] [blame] | 24 | _ (scalar, "Generic (SIMD disabled)") \ |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 25 | _ (hsw, "Intel Haswell") \ |
| 26 | _ (trm, "Intel Tremont") \ |
| 27 | _ (skx, "Intel Skylake (server) / Cascade Lake") \ |
Damjan Marion | 1ca6818 | 2023-03-15 11:08:53 +0000 | [diff] [blame] | 28 | _ (icl, "Intel Ice Lake") \ |
| 29 | _ (adl, "Intel Alder Lake") \ |
| 30 | _ (spr, "Intel Sapphire Rapids") |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 31 | #elif defined(__aarch64__) |
| 32 | #define foreach_march_variant \ |
| 33 | _ (octeontx2, "Marvell Octeon TX2") \ |
| 34 | _ (thunderx2t99, "Marvell ThunderX2 T99") \ |
| 35 | _ (qdf24xx, "Qualcomm CentriqTM 2400") \ |
| 36 | _ (cortexa72, "ARM Cortex-A72") \ |
| 37 | _ (neoversen1, "ARM Neoverse N1") |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 38 | #else |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 39 | #define foreach_march_variant |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 40 | #endif |
| 41 | |
Sivaprasad Tummala | 6a1a832 | 2023-04-17 05:16:11 -0700 | [diff] [blame^] | 42 | #define amd_vendor(t1, t2, t3) \ |
| 43 | ((t1 == 0x68747541) && /* htuA */ \ |
| 44 | (t2 == 0x444d4163) && /* DMAc */ \ |
| 45 | (t3 == 0x69746e65)) /* itne */ |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 46 | typedef enum |
| 47 | { |
| 48 | CLIB_MARCH_VARIANT_TYPE = 0, |
| 49 | #define _(s, n) CLIB_MARCH_VARIANT_TYPE_##s, |
| 50 | foreach_march_variant |
| 51 | #undef _ |
| 52 | CLIB_MARCH_TYPE_N_VARIANTS |
| 53 | } clib_march_variant_type_t; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 54 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 55 | #ifdef CLIB_MARCH_VARIANT |
Damjan Marion | 04f3db3 | 2017-11-10 21:55:45 +0100 | [diff] [blame] | 56 | #define __CLIB_MULTIARCH_FN(a,b) a##_##b |
| 57 | #define _CLIB_MULTIARCH_FN(a,b) __CLIB_MULTIARCH_FN(a,b) |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 58 | #define CLIB_MULTIARCH_FN(fn) _CLIB_MULTIARCH_FN(fn,CLIB_MARCH_VARIANT) |
Damjan Marion | 04f3db3 | 2017-11-10 21:55:45 +0100 | [diff] [blame] | 59 | #else |
| 60 | #define CLIB_MULTIARCH_FN(fn) fn |
| 61 | #endif |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 62 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 63 | #define CLIB_MARCH_SFX CLIB_MULTIARCH_FN |
| 64 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 65 | typedef struct _clib_march_fn_registration |
| 66 | { |
| 67 | void *function; |
| 68 | int priority; |
| 69 | struct _clib_march_fn_registration *next; |
| 70 | char *name; |
| 71 | } clib_march_fn_registration; |
| 72 | |
| 73 | static_always_inline void * |
| 74 | clib_march_select_fn_ptr (clib_march_fn_registration * r) |
| 75 | { |
| 76 | void *rv = 0; |
| 77 | int last_prio = -1; |
| 78 | |
| 79 | while (r) |
| 80 | { |
| 81 | if (last_prio < r->priority) |
| 82 | { |
| 83 | last_prio = r->priority; |
| 84 | rv = r->function; |
| 85 | } |
| 86 | r = r->next; |
| 87 | } |
| 88 | return rv; |
| 89 | } |
| 90 | |
Damjan Marion | 11e0d75 | 2021-05-05 20:06:39 +0200 | [diff] [blame] | 91 | #define CLIB_MARCH_FN_POINTER(fn) \ |
| 92 | (__typeof__ (fn) *) clib_march_select_fn_ptr (fn##_march_fn_registrations); |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 93 | |
Mohammed Hawari | e714926 | 2022-05-18 10:08:47 +0200 | [diff] [blame] | 94 | #define CLIB_MARCH_FN_VOID_POINTER(fn) \ |
| 95 | clib_march_select_fn_ptr (fn##_march_fn_registrations); |
| 96 | |
Damjan Marion | 910d369 | 2019-01-21 11:48:34 +0100 | [diff] [blame] | 97 | #define _CLIB_MARCH_FN_REGISTRATION(fn) \ |
| 98 | static clib_march_fn_registration \ |
| 99 | CLIB_MARCH_SFX(fn##_march_fn_registration) = \ |
| 100 | { \ |
| 101 | .name = CLIB_MARCH_VARIANT_STR \ |
| 102 | }; \ |
| 103 | \ |
| 104 | static void __clib_constructor \ |
| 105 | fn##_march_register () \ |
| 106 | { \ |
| 107 | clib_march_fn_registration *r; \ |
| 108 | r = & CLIB_MARCH_SFX (fn##_march_fn_registration); \ |
| 109 | r->priority = CLIB_MARCH_FN_PRIORITY(); \ |
| 110 | r->next = fn##_march_fn_registrations; \ |
| 111 | r->function = CLIB_MARCH_SFX (fn); \ |
| 112 | fn##_march_fn_registrations = r; \ |
| 113 | } |
| 114 | |
| 115 | #ifdef CLIB_MARCH_VARIANT |
| 116 | #define CLIB_MARCH_FN_REGISTRATION(fn) \ |
| 117 | extern clib_march_fn_registration *fn##_march_fn_registrations; \ |
| 118 | _CLIB_MARCH_FN_REGISTRATION(fn) |
| 119 | #else |
| 120 | #define CLIB_MARCH_FN_REGISTRATION(fn) \ |
| 121 | clib_march_fn_registration *fn##_march_fn_registrations = 0; \ |
| 122 | _CLIB_MARCH_FN_REGISTRATION(fn) |
| 123 | #endif |
Radu Nicolau | e1480a2 | 2021-01-14 10:25:02 +0000 | [diff] [blame] | 124 | #define foreach_x86_64_flags \ |
| 125 | _ (sse3, 1, ecx, 0) \ |
| 126 | _ (pclmulqdq, 1, ecx, 1) \ |
| 127 | _ (ssse3, 1, ecx, 9) \ |
| 128 | _ (sse41, 1, ecx, 19) \ |
| 129 | _ (sse42, 1, ecx, 20) \ |
| 130 | _ (avx, 1, ecx, 28) \ |
| 131 | _ (rdrand, 1, ecx, 30) \ |
| 132 | _ (avx2, 7, ebx, 5) \ |
Maros Ondrejicka | 568ef46 | 2022-11-10 14:11:40 +0100 | [diff] [blame] | 133 | _ (bmi2, 7, ebx, 8) \ |
Radu Nicolau | e1480a2 | 2021-01-14 10:25:02 +0000 | [diff] [blame] | 134 | _ (rtm, 7, ebx, 11) \ |
| 135 | _ (pqm, 7, ebx, 12) \ |
| 136 | _ (pqe, 7, ebx, 15) \ |
| 137 | _ (avx512f, 7, ebx, 16) \ |
| 138 | _ (rdseed, 7, ebx, 18) \ |
| 139 | _ (x86_aes, 1, ecx, 25) \ |
| 140 | _ (sha, 7, ebx, 29) \ |
| 141 | _ (vaes, 7, ecx, 9) \ |
| 142 | _ (vpclmulqdq, 7, ecx, 10) \ |
| 143 | _ (avx512_vnni, 7, ecx, 11) \ |
| 144 | _ (avx512_bitalg, 7, ecx, 12) \ |
| 145 | _ (avx512_vpopcntdq, 7, ecx, 14) \ |
| 146 | _ (movdiri, 7, ecx, 27) \ |
| 147 | _ (movdir64b, 7, ecx, 28) \ |
Damjan Marion | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 148 | _ (enqcmd, 7, ecx, 29) \ |
Ray Kinsella | 0d27e3e | 2021-10-15 12:48:31 +0100 | [diff] [blame] | 149 | _ (avx512_fp16, 7, edx, 23) \ |
Radu Nicolau | e1480a2 | 2021-01-14 10:25:02 +0000 | [diff] [blame] | 150 | _ (invariant_tsc, 0x80000007, edx, 8) |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 151 | |
| 152 | #define foreach_aarch64_flags \ |
| 153 | _ (fp, 0) \ |
| 154 | _ (asimd, 1) \ |
| 155 | _ (evtstrm, 2) \ |
| 156 | _ (aarch64_aes, 3) \ |
| 157 | _ (pmull, 4) \ |
| 158 | _ (sha1, 5) \ |
| 159 | _ (sha2, 6) \ |
| 160 | _ (crc32, 7) \ |
| 161 | _ (atomics, 8) \ |
| 162 | _ (fphp, 9) \ |
| 163 | _ (asimdhp, 10) \ |
| 164 | _ (cpuid, 11) \ |
| 165 | _ (asimdrdm, 12) \ |
| 166 | _ (jscvt, 13) \ |
| 167 | _ (fcma, 14) \ |
| 168 | _ (lrcpc, 15) \ |
| 169 | _ (dcpop, 16) \ |
| 170 | _ (sha3, 17) \ |
| 171 | _ (sm3, 18) \ |
| 172 | _ (sm4, 19) \ |
| 173 | _ (asimddp, 20) \ |
| 174 | _ (sha512, 21) \ |
| 175 | _ (sve, 22) |
| 176 | |
Dave Barach | 6c89a35 | 2022-12-26 14:01:36 -0500 | [diff] [blame] | 177 | u32 clib_get_current_cpu_id (void); |
| 178 | u32 clib_get_current_numa_node (void); |
Damjan Marion | 0a78fa1 | 2019-01-19 23:45:36 +0100 | [diff] [blame] | 179 | |
Dave Barach | 6c89a35 | 2022-12-26 14:01:36 -0500 | [diff] [blame] | 180 | typedef int (*clib_cpu_supports_func_t) (void); |
Zachary Leaf | 268d7be | 2022-05-12 02:26:00 -0500 | [diff] [blame] | 181 | |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 182 | #if defined(__x86_64__) |
| 183 | #include "cpuid.h" |
| 184 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 185 | static inline int |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 186 | clib_get_cpuid (const u32 lev, u32 * eax, u32 * ebx, u32 * ecx, u32 * edx) |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 187 | { |
| 188 | if ((u32) __get_cpuid_max (0x80000000 & lev, 0) < lev) |
| 189 | return 0; |
| 190 | if (lev == 7) |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 191 | __cpuid_count (lev, 0, *eax, *ebx, *ecx, *edx); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 192 | else |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 193 | __cpuid (lev, *eax, *ebx, *ecx, *edx); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 194 | return 1; |
| 195 | } |
| 196 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 197 | #define _(flag, func, reg, bit) \ |
| 198 | static inline int \ |
| 199 | clib_cpu_supports_ ## flag() \ |
| 200 | { \ |
| 201 | u32 __attribute__((unused)) eax, ebx = 0, ecx = 0, edx = 0; \ |
| 202 | clib_get_cpuid (func, &eax, &ebx, &ecx, &edx); \ |
| 203 | \ |
| 204 | return ((reg & (1 << bit)) != 0); \ |
| 205 | } |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 206 | foreach_x86_64_flags |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 207 | #undef _ |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 208 | #else /* __x86_64__ */ |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 209 | |
| 210 | #define _(flag, func, reg, bit) \ |
| 211 | static inline int clib_cpu_supports_ ## flag() { return 0; } |
| 212 | foreach_x86_64_flags |
| 213 | #undef _ |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 214 | #endif /* __x86_64__ */ |
| 215 | #if defined(__aarch64__) |
| 216 | #include <sys/auxv.h> |
| 217 | #define _(flag, bit) \ |
| 218 | static inline int \ |
| 219 | clib_cpu_supports_ ## flag() \ |
| 220 | { \ |
| 221 | unsigned long hwcap = getauxval(AT_HWCAP); \ |
| 222 | return (hwcap & (1 << bit)); \ |
| 223 | } |
| 224 | foreach_aarch64_flags |
| 225 | #undef _ |
| 226 | #else /* ! __x86_64__ && !__aarch64__ */ |
| 227 | #define _(flag, bit) \ |
| 228 | static inline int clib_cpu_supports_ ## flag() { return 0; } |
| 229 | foreach_aarch64_flags |
| 230 | #undef _ |
| 231 | #endif /* __x86_64__, __aarch64__ */ |
| 232 | /* |
| 233 | * aes is the only feature with the same name in both flag lists |
| 234 | * handle this by prefixing it with the arch name, and handling it |
| 235 | * with the custom function below |
| 236 | */ |
| 237 | static inline int |
| 238 | clib_cpu_supports_aes () |
| 239 | { |
Zhiyong Yang | 7f4fd22 | 2019-04-19 03:04:41 -0400 | [diff] [blame] | 240 | #if defined(__x86_64__) |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 241 | return clib_cpu_supports_x86_aes (); |
| 242 | #elif defined (__aarch64__) |
| 243 | return clib_cpu_supports_aarch64_aes (); |
| 244 | #else |
| 245 | return 0; |
Christophe Fontaine | 33e8195 | 2016-12-19 14:41:52 +0100 | [diff] [blame] | 246 | #endif |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 249 | static inline int |
Damjan Marion | 98f7f0a | 2023-04-17 09:38:11 +0000 | [diff] [blame] | 250 | clib_cpu_march_priority_scalar () |
| 251 | { |
| 252 | return 1; |
| 253 | } |
| 254 | |
| 255 | static inline int |
Damjan Marion | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 256 | clib_cpu_march_priority_spr () |
| 257 | { |
| 258 | if (clib_cpu_supports_enqcmd ()) |
| 259 | return 300; |
| 260 | return -1; |
| 261 | } |
| 262 | |
| 263 | static inline int |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 264 | clib_cpu_march_priority_icl () |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 265 | { |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 266 | if (clib_cpu_supports_avx512_bitalg ()) |
| 267 | return 200; |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | static inline int |
Damjan Marion | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 272 | clib_cpu_march_priority_adl () |
| 273 | { |
| 274 | if (clib_cpu_supports_movdiri () && clib_cpu_supports_avx2 ()) |
| 275 | return 150; |
| 276 | return -1; |
| 277 | } |
| 278 | |
| 279 | static inline int |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 280 | clib_cpu_march_priority_skx () |
| 281 | { |
| 282 | if (clib_cpu_supports_avx512f ()) |
| 283 | return 100; |
| 284 | return -1; |
| 285 | } |
| 286 | |
| 287 | static inline int |
Radu Nicolau | e1480a2 | 2021-01-14 10:25:02 +0000 | [diff] [blame] | 288 | clib_cpu_march_priority_trm () |
| 289 | { |
| 290 | if (clib_cpu_supports_movdiri ()) |
Damjan Marion | 1552228 | 2023-03-14 13:34:59 +0100 | [diff] [blame] | 291 | return 40; |
Radu Nicolau | e1480a2 | 2021-01-14 10:25:02 +0000 | [diff] [blame] | 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | static inline int |
Damjan Marion | 162330f | 2020-04-29 21:28:15 +0200 | [diff] [blame] | 296 | clib_cpu_march_priority_hsw () |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 297 | { |
| 298 | if (clib_cpu_supports_avx2 ()) |
Damjan Marion | 6459315 | 2019-03-12 19:59:22 +0100 | [diff] [blame] | 299 | return 50; |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 300 | return -1; |
| 301 | } |
| 302 | |
Ray Kinsella | 0024e53 | 2021-11-26 14:57:35 +0000 | [diff] [blame] | 303 | #define X86_CPU_ARCH_PERF_FUNC 0xA |
| 304 | |
| 305 | static inline int |
| 306 | clib_get_pmu_counter_count (u8 *fixed, u8 *general) |
| 307 | { |
| 308 | #if defined(__x86_64__) |
| 309 | u32 __clib_unused eax = 0, ebx = 0, ecx = 0, edx = 0; |
| 310 | clib_get_cpuid (X86_CPU_ARCH_PERF_FUNC, &eax, &ebx, &ecx, &edx); |
| 311 | |
| 312 | *general = (eax & 0xFF00) >> 8; |
| 313 | *fixed = (edx & 0xF); |
| 314 | |
| 315 | return 1; |
| 316 | #else |
| 317 | return 0; |
| 318 | #endif |
| 319 | } |
| 320 | |
Lijian Zhang | 2e23721 | 2018-09-10 17:13:56 +0800 | [diff] [blame] | 321 | static inline u32 |
| 322 | clib_cpu_implementer () |
| 323 | { |
| 324 | char buf[128]; |
| 325 | static u32 implementer = -1; |
| 326 | |
| 327 | if (-1 != implementer) |
| 328 | return implementer; |
| 329 | |
| 330 | FILE *fp = fopen ("/proc/cpuinfo", "r"); |
| 331 | if (!fp) |
| 332 | return implementer; |
| 333 | |
| 334 | while (!feof (fp)) |
| 335 | { |
| 336 | if (!fgets (buf, sizeof (buf), fp)) |
| 337 | break; |
| 338 | buf[127] = '\0'; |
| 339 | if (strstr (buf, "CPU implementer")) |
| 340 | implementer = (u32) strtol (memchr (buf, ':', 128) + 2, NULL, 0); |
| 341 | if (-1 != implementer) |
| 342 | break; |
| 343 | } |
| 344 | fclose (fp); |
| 345 | |
| 346 | return implementer; |
| 347 | } |
| 348 | |
| 349 | static inline u32 |
| 350 | clib_cpu_part () |
| 351 | { |
| 352 | char buf[128]; |
| 353 | static u32 part = -1; |
| 354 | |
| 355 | if (-1 != part) |
| 356 | return part; |
| 357 | |
| 358 | FILE *fp = fopen ("/proc/cpuinfo", "r"); |
| 359 | if (!fp) |
| 360 | return part; |
| 361 | |
| 362 | while (!feof (fp)) |
| 363 | { |
| 364 | if (!fgets (buf, sizeof (buf), fp)) |
| 365 | break; |
| 366 | buf[127] = '\0'; |
| 367 | if (strstr (buf, "CPU part")) |
| 368 | part = (u32) strtol (memchr (buf, ':', 128) + 2, NULL, 0); |
| 369 | if (-1 != part) |
| 370 | break; |
| 371 | } |
| 372 | fclose (fp); |
| 373 | |
| 374 | return part; |
| 375 | } |
| 376 | |
Nitin Saxena | e2f5236 | 2020-08-25 19:58:37 +0530 | [diff] [blame] | 377 | #define AARCH64_CPU_IMPLEMENTER_CAVIUM 0x43 |
| 378 | #define AARCH64_CPU_PART_THUNDERX2 0x0af |
| 379 | #define AARCH64_CPU_PART_OCTEONTX2T96 0x0b2 |
| 380 | #define AARCH64_CPU_PART_OCTEONTX2T98 0x0b1 |
Lijian Zhang | 2e23721 | 2018-09-10 17:13:56 +0800 | [diff] [blame] | 381 | #define AARCH64_CPU_IMPLEMENTER_QDF24XX 0x51 |
| 382 | #define AARCH64_CPU_PART_QDF24XX 0xc00 |
| 383 | #define AARCH64_CPU_IMPLEMENTER_CORTEXA72 0x41 |
| 384 | #define AARCH64_CPU_PART_CORTEXA72 0xd08 |
Lijian.Zhang | 690ce86 | 2020-02-18 19:58:19 +0800 | [diff] [blame] | 385 | #define AARCH64_CPU_IMPLEMENTER_NEOVERSEN1 0x41 |
| 386 | #define AARCH64_CPU_PART_NEOVERSEN1 0xd0c |
Lijian Zhang | 2e23721 | 2018-09-10 17:13:56 +0800 | [diff] [blame] | 387 | |
| 388 | static inline int |
Nitin Saxena | e2f5236 | 2020-08-25 19:58:37 +0530 | [diff] [blame] | 389 | clib_cpu_march_priority_octeontx2 () |
| 390 | { |
| 391 | if ((AARCH64_CPU_IMPLEMENTER_CAVIUM == clib_cpu_implementer ()) && |
| 392 | ((AARCH64_CPU_PART_OCTEONTX2T96 == clib_cpu_part ()) |
| 393 | || AARCH64_CPU_PART_OCTEONTX2T98 == clib_cpu_part ())) |
| 394 | return 20; |
| 395 | return -1; |
| 396 | } |
| 397 | |
| 398 | static inline int |
Lijian Zhang | 2e23721 | 2018-09-10 17:13:56 +0800 | [diff] [blame] | 399 | clib_cpu_march_priority_thunderx2t99 () |
| 400 | { |
Nitin Saxena | e2f5236 | 2020-08-25 19:58:37 +0530 | [diff] [blame] | 401 | if ((AARCH64_CPU_IMPLEMENTER_CAVIUM == clib_cpu_implementer ()) && |
| 402 | (AARCH64_CPU_PART_THUNDERX2 == clib_cpu_part ())) |
Lijian Zhang | 2e23721 | 2018-09-10 17:13:56 +0800 | [diff] [blame] | 403 | return 20; |
| 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | static inline int |
| 408 | clib_cpu_march_priority_qdf24xx () |
| 409 | { |
| 410 | if ((AARCH64_CPU_IMPLEMENTER_QDF24XX == clib_cpu_implementer ()) && |
| 411 | (AARCH64_CPU_PART_QDF24XX == clib_cpu_part ())) |
| 412 | return 20; |
| 413 | return -1; |
| 414 | } |
| 415 | |
| 416 | static inline int |
| 417 | clib_cpu_march_priority_cortexa72 () |
| 418 | { |
| 419 | if ((AARCH64_CPU_IMPLEMENTER_CORTEXA72 == clib_cpu_implementer ()) && |
| 420 | (AARCH64_CPU_PART_CORTEXA72 == clib_cpu_part ())) |
| 421 | return 10; |
| 422 | return -1; |
| 423 | } |
| 424 | |
Lijian.Zhang | 690ce86 | 2020-02-18 19:58:19 +0800 | [diff] [blame] | 425 | static inline int |
| 426 | clib_cpu_march_priority_neoversen1 () |
| 427 | { |
| 428 | if ((AARCH64_CPU_IMPLEMENTER_NEOVERSEN1 == clib_cpu_implementer ()) && |
| 429 | (AARCH64_CPU_PART_NEOVERSEN1 == clib_cpu_part ())) |
| 430 | return 10; |
| 431 | return -1; |
| 432 | } |
| 433 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 434 | #ifdef CLIB_MARCH_VARIANT |
| 435 | #define CLIB_MARCH_FN_PRIORITY() CLIB_MARCH_SFX(clib_cpu_march_priority)() |
| 436 | #else |
| 437 | #define CLIB_MARCH_FN_PRIORITY() 0 |
| 438 | #endif |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 439 | #endif /* included_clib_cpu_h */ |
| 440 | |
Florin Coras | 983cc7d | 2018-09-18 23:11:55 -0700 | [diff] [blame] | 441 | #define CLIB_MARCH_FN_CONSTRUCTOR(fn) \ |
| 442 | static void __clib_constructor \ |
| 443 | CLIB_MARCH_SFX(fn ## _march_constructor) (void) \ |
| 444 | { \ |
| 445 | if (CLIB_MARCH_FN_PRIORITY() > fn ## _selected_priority) \ |
| 446 | { \ |
| 447 | fn ## _selected = & CLIB_MARCH_SFX (fn ## _ma); \ |
| 448 | fn ## _selected_priority = CLIB_MARCH_FN_PRIORITY(); \ |
| 449 | } \ |
| 450 | } \ |
| 451 | |
| 452 | #ifndef CLIB_MARCH_VARIANT |
Damjan Marion | 1bb67ab | 2021-04-30 11:11:08 +0200 | [diff] [blame] | 453 | #define CLIB_MARCH_FN(fn, rtype, _args...) \ |
| 454 | static rtype CLIB_MARCH_SFX (fn##_ma) (_args); \ |
| 455 | rtype (*fn##_selected) (_args) = &CLIB_MARCH_SFX (fn##_ma); \ |
| 456 | int fn##_selected_priority = 0; \ |
| 457 | static inline rtype CLIB_MARCH_SFX (fn##_ma) (_args) |
Florin Coras | 983cc7d | 2018-09-18 23:11:55 -0700 | [diff] [blame] | 458 | #else |
Damjan Marion | 1bb67ab | 2021-04-30 11:11:08 +0200 | [diff] [blame] | 459 | #define CLIB_MARCH_FN(fn, rtype, _args...) \ |
| 460 | static rtype CLIB_MARCH_SFX (fn##_ma) (_args); \ |
| 461 | extern rtype (*fn##_selected) (_args); \ |
| 462 | extern int fn##_selected_priority; \ |
| 463 | CLIB_MARCH_FN_CONSTRUCTOR (fn) \ |
| 464 | static rtype CLIB_MARCH_SFX (fn##_ma) (_args) |
Florin Coras | 983cc7d | 2018-09-18 23:11:55 -0700 | [diff] [blame] | 465 | #endif |
| 466 | |
| 467 | #define CLIB_MARCH_FN_SELECT(fn) (* fn ## _selected) |
| 468 | |
Gabriel Ganne | 73cb006 | 2017-12-05 14:26:33 +0100 | [diff] [blame] | 469 | format_function_t format_cpu_uarch; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 470 | format_function_t format_cpu_model_name; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 471 | format_function_t format_cpu_flags; |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 472 | format_function_t format_march_variant; |
Damjan Marion | 522e486 | 2016-03-04 12:44:14 +0100 | [diff] [blame] | 473 | |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 474 | /* |
| 475 | * fd.io coding-style-patch-verification: ON |
| 476 | * |
| 477 | * Local Variables: |
| 478 | * eval: (c-set-style "gnu") |
| 479 | * End: |
| 480 | */ |