Warning: That file was not part of the compilation database. It may have many parsing errors.
| 1 | /* @title: Topology generation */ |
|---|---|
| 2 | #pragma once |
| 3 | #include <smp/pertopo.h> |
| 4 | |
| 5 | struct topo_gen_descriptor { |
| 6 | struct pertopo_descriptor *descs[TOPOLOGY_LEVEL_MAX]; |
| 7 | }; |
| 8 | |
| 9 | #define TOPO_GEN_CTOR(type_, name_, level_, ctor_) \ |
| 10 | static inline void __topo_ctor_##level_##_##name_(typeof(type_) *inst, \ |
| 11 | size_t node_id) { \ |
| 12 | void (*const __typed_ctor)(typeof(type_) *, enum topology_level, \ |
| 13 | size_t) = (ctor_); \ |
| 14 | if (__typed_ctor != NULL) \ |
| 15 | __typed_ctor((typeof(type_) *) inst, level_, node_id); \ |
| 16 | } |
| 17 | |
| 18 | #define TOPO_DEFINE_3(type_, name_, ctor_) \ |
| 19 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_SMT, ctor_); \ |
| 20 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_CORE, ctor_); \ |
| 21 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_NUMA, ctor_); \ |
| 22 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_LLC, ctor_); \ |
| 23 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_PACKAGE, ctor_); \ |
| 24 | TOPO_GEN_CTOR(type_, name_, TOPOLOGY_LEVEL_MACHINE, ctor_); \ |
| 25 | PERTOPO_DEFINE(type_, name_##_SMT, TOPOLOGY_LEVEL_SMT, \ |
| 26 | __topo_ctor_TOPOLOGY_LEVEL_SMT_##name_); \ |
| 27 | PERTOPO_DEFINE(type_, name_##_CORE, TOPOLOGY_LEVEL_CORE, \ |
| 28 | __topo_ctor_TOPOLOGY_LEVEL_CORE_##name_); \ |
| 29 | PERTOPO_DEFINE(type_, name_##_NUMA, TOPOLOGY_LEVEL_NUMA, \ |
| 30 | __topo_ctor_TOPOLOGY_LEVEL_NUMA_##name_); \ |
| 31 | PERTOPO_DEFINE(type_, name_##_LLC, TOPOLOGY_LEVEL_LLC, \ |
| 32 | __topo_ctor_TOPOLOGY_LEVEL_LLC_##name_); \ |
| 33 | PERTOPO_DEFINE(type_, name_##_PACKAGE, TOPOLOGY_LEVEL_PACKAGE, \ |
| 34 | __topo_ctor_TOPOLOGY_LEVEL_PACKAGE_##name_); \ |
| 35 | PERTOPO_DEFINE(type_, name_##_MACHINE, TOPOLOGY_LEVEL_MACHINE, \ |
| 36 | __topo_ctor_TOPOLOGY_LEVEL_MACHINE_##name_); \ |
| 37 | static typeof(type_) __topo_gen_##name_ cc_unused; \ |
| 38 | static struct topo_gen_descriptor __topo_gen_desc_##name_ cc_unused = { \ |
| 39 | .descs = { \ |
| 40 | [TOPOLOGY_LEVEL_SMT] = &__pertopo_desc_##name_##_SMT, \ |
| 41 | [TOPOLOGY_LEVEL_CORE] = &__pertopo_desc_##name_##_CORE, \ |
| 42 | [TOPOLOGY_LEVEL_NUMA] = &__pertopo_desc_##name_##_NUMA, \ |
| 43 | [TOPOLOGY_LEVEL_LLC] = &__pertopo_desc_##name_##_LLC, \ |
| 44 | [TOPOLOGY_LEVEL_PACKAGE] = &__pertopo_desc_##name_##_PACKAGE, \ |
| 45 | [TOPOLOGY_LEVEL_MACHINE] = &__pertopo_desc_##name_##_MACHINE, \ |
| 46 | }}; |
| 47 | |
| 48 | #define TOPO_DEFINE_2(type_, name_) TOPO_DEFINE_3(type_, name_, NULL) |
| 49 | #define TOPO_DEFINE(...) PP_CALL(TOPO_DEFINE, __VA_ARGS__) |
| 50 | |
| 51 | #define topo_gen_for_each_internal_2(var, name) \ |
| 52 | for (enum topology_level __topo_gen_level = 0; \ |
| 53 | __topo_gen_level < TOPOLOGY_LEVEL_MAX; __topo_gen_level++) \ |
| 54 | for (size_t __topo_gen_idx = 0; \ |
| 55 | __topo_gen_idx < global.topology.count[__topo_gen_level]; \ |
| 56 | __topo_gen_idx++) \ |
| 57 | for (var = (typeof(var)) __topo_gen_desc_##name \ |
| 58 | .descs[__topo_gen_level] \ |
| 59 | ->pertopo_ptrs[__topo_gen_idx]; \ |
| 60 | var != NULL; var = NULL) |
| 61 | |
| 62 | #define topo_gen_for_each_internal_3(var, level, name) \ |
| 63 | for (level = 0; level < TOPOLOGY_LEVEL_MAX; level++) \ |
| 64 | for (size_t __topo_gen_idx = 0; \ |
| 65 | __topo_gen_idx < global.topology.count[level]; __topo_gen_idx++) \ |
| 66 | for (var = (typeof(var)) __topo_gen_desc_##name.descs[level] \ |
| 67 | ->pertopo_ptrs[__topo_gen_idx]; \ |
| 68 | var != NULL; var = NULL) |
| 69 | |
| 70 | #define topo_gen_for_each_internal_4(var, level, node_id, name) \ |
| 71 | for (level = 0; level < TOPOLOGY_LEVEL_MAX; level++) \ |
| 72 | for (node_id = 0; node_id < global.topology.count[level]; node_id++) \ |
| 73 | for (var = (typeof(var)) __topo_gen_desc_##name.descs[level] \ |
| 74 | ->pertopo_ptrs[node_id]; \ |
| 75 | var != NULL; var = NULL) |
| 76 | |
| 77 | #define topo_gen_for_each(...) PP_CALL(topo_gen_for_each_internal, __VA_ARGS__) |
| 78 | |
| 79 | #define topo_gen_for_each_at_3(var, name, level) \ |
| 80 | for (size_t __topo_gen_idx = 0; \ |
| 81 | __topo_gen_idx < global.topology.count[level]; __topo_gen_idx++) \ |
| 82 | for (var = (typeof(var)) __topo_gen_desc_##name.descs[level] \ |
| 83 | ->pertopo_ptrs[__topo_gen_idx]; \ |
| 84 | var != NULL; var = NULL) |
| 85 | |
| 86 | #define topo_gen_for_each_at_4(var, node_id, name, level) \ |
| 87 | for (node_id = 0; node_id < global.topology.count[level]; node_id++) \ |
| 88 | for (var = (typeof(var)) __topo_gen_desc_##name.descs[level] \ |
| 89 | ->pertopo_ptrs[node_id]; \ |
| 90 | var != NULL; var = NULL) |
| 91 | |
| 92 | #define topo_gen_for_each_at(...) \ |
| 93 | PP_CALL(topo_gen_for_each_at_internal, __VA_ARGS__) |
| 94 |
Warning: That file was not part of the compilation database. It may have many parsing errors.