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