| 119 | } |
| 120 | |
| 121 | void |
| 122 | setup_test_case_1(const int64_t n) |
| 123 | { |
| 124 | ink_thread list[n]; |
| 125 | |
| 126 | #if TS_USE_HWLOC |
| 127 | // ThreadAffinityInitializer::set_affinity mimics |
| 128 | const hwloc_obj_type_t obj_type = thread_affinity(); |
| 129 | const int obj_count = hwloc_get_nbobjs_by_type(ink_get_topology(), obj_type); |
| 130 | |
| 131 | assert(obj_count > 0); |
| 132 | |
| 133 | for (int i = 0; i < n; i++) { |
| 134 | ink_thread_create(&list[i], test_case_1, (void *)(static_cast<intptr_t>(i)), 0, 0, nullptr); |
| 135 | |
| 136 | int dst = i; |
| 137 | if (thread_assiging_order == 1) { |
| 138 | // Assign threads one side of siblings first |
| 139 | dst = i * 2; |
| 140 | if (dst >= obj_count) { |
| 141 | dst = (i * 2 - obj_count) + 1; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | hwloc_obj_t obj = hwloc_get_obj_by_type(ink_get_topology(), obj_type, dst % obj_count); |
| 146 | hwloc_set_thread_cpubind(ink_get_topology(), list[i], obj->cpuset, HWLOC_CPUBIND_STRICT); |
| 147 | |
| 148 | if (debug_enabled) { |
| 149 | int cpu_mask_len = hwloc_bitmap_snprintf(nullptr, 0, obj->cpuset) + 1; |
| 150 | char *cpu_mask = static_cast<char *>(alloca(cpu_mask_len)); |
| 151 | hwloc_bitmap_snprintf(cpu_mask, cpu_mask_len, obj->cpuset); |
| 152 | |
| 153 | std::cout << "tid=" << list[i] << " obj->logical_index=" << obj->logical_index << " cpu_mask=" << cpu_mask << std::endl; |
| 154 | } |
| 155 | } |
| 156 | #else |
| 157 | for (int i = 0; i < n; i++) { |
| 158 | ink_thread_create(&list[i], test_case_1, (void *)((intptr_t)i), 0, 0, nullptr); |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | for (int i = 0; i < n; i++) { |
| 163 | ink_thread_join(list[i]); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | TEST_CASE("simple new and free", "") |
| 168 | { |
no test coverage detected