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