| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2024 Barcelona Supercomputing Center */ | ||
| 3 | /* */ | ||
| 4 | /* This file is part of the DLB library. */ | ||
| 5 | /* */ | ||
| 6 | /* DLB is free software: you can redistribute it and/or modify */ | ||
| 7 | /* it under the terms of the GNU Lesser General Public License as published by */ | ||
| 8 | /* the Free Software Foundation, either version 3 of the License, or */ | ||
| 9 | /* (at your option) any later version. */ | ||
| 10 | /* */ | ||
| 11 | /* DLB is distributed in the hope that it will be useful, */ | ||
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | ||
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | ||
| 14 | /* GNU Lesser General Public License for more details. */ | ||
| 15 | /* */ | ||
| 16 | /* You should have received a copy of the GNU Lesser General Public License */ | ||
| 17 | /* along with DLB. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | /*********************************************************************************/ | ||
| 19 | |||
| 20 | /* Test mask utils initialization and system functions */ | ||
| 21 | |||
| 22 | #include "support/mask_utils.h" | ||
| 23 | #include "support/debug.h" | ||
| 24 | #include "support/options.h" | ||
| 25 | |||
| 26 | #include <sched.h> | ||
| 27 | #include <stdio.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <assert.h> | ||
| 30 | |||
| 31 | |||
| 32 | 1 | int main(int argc, char *argv[]) { | |
| 33 | |||
| 34 | 1 | options_t options = { .verbose = VB_AFFINITY }; | |
| 35 | 1 | debug_init(&options); | |
| 36 | |||
| 37 | cpu_set_t system_mask; | ||
| 38 | cpu_set_t zero_mask; | ||
| 39 | 1 | CPU_ZERO(&zero_mask); | |
| 40 | |||
| 41 | print_buffer_t buffer; | ||
| 42 | |||
| 43 | /* Default, usually hwloc */ | ||
| 44 | { | ||
| 45 | 1 | warning("===== Default init ======"); | |
| 46 | |||
| 47 | // check it's safe to call init and finalize twice | ||
| 48 | 1 | mu_init(); | |
| 49 | 1 | mu_init(); | |
| 50 | |||
| 51 | 1 | mu_get_system_description(&buffer); | |
| 52 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 53 | 1 | printbuffer_destroy(&buffer); | |
| 54 | |||
| 55 | 1 | mu_finalize(); | |
| 56 | 1 | mu_finalize(); | |
| 57 | } | ||
| 58 | |||
| 59 | /* Force no hwloc */ | ||
| 60 | { | ||
| 61 | 1 | warning("===== No hwloc init ====="); | |
| 62 | |||
| 63 | 1 | mu_testing_init_nohwloc(); | |
| 64 | |||
| 65 | 1 | mu_get_system_description(&buffer); | |
| 66 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 67 | 1 | printbuffer_destroy(&buffer); | |
| 68 | |||
| 69 | 1 | mu_finalize(); | |
| 70 | } | ||
| 71 | |||
| 72 | /* Custom size */ | ||
| 73 | { | ||
| 74 | enum { SYS_SIZE = 70 }; | ||
| 75 | 1 | warning("===== Size %d ===== ", SYS_SIZE); | |
| 76 | |||
| 77 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 78 | |||
| 79 | 1 | mu_get_system_description(&buffer); | |
| 80 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 81 | 1 | printbuffer_destroy(&buffer); | |
| 82 | |||
| 83 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_size() == SYS_SIZE ); |
| 84 | 1 | mu_get_system_mask(&system_mask); | |
| 85 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&system_mask) == SYS_SIZE |
| 86 | && mu_get_first_cpu(&system_mask) == 0 | ||
| 87 | && mu_get_last_cpu(&system_mask) == SYS_SIZE - 1 ); | ||
| 88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_system_has_smt() == false ); |
| 89 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_hwthreads_per_core() == 1 ); |
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_num_nodes() == 1 ); |
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_cores_per_node() == SYS_SIZE ); |
| 92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, -2) == -1 ); |
| 93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, -1) == 0 ); |
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 0) == 1 ); |
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 68) == 69 ); |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 69) == -1 ); |
| 97 | |||
| 98 | 1 | mu_finalize(); | |
| 99 | } | ||
| 100 | |||
| 101 | /* Custom size and topology */ | ||
| 102 | { | ||
| 103 | enum { SYS_NCPUS = 32 }; | ||
| 104 | enum { SYS_NCORES = 16 }; | ||
| 105 | enum { SYS_NNODES = 4}; | ||
| 106 | 1 | warning("===== ncpus: %d, ncores: %d, nnodes: %d ===== ", | |
| 107 | SYS_NCPUS, SYS_NCORES, SYS_NNODES); | ||
| 108 | |||
| 109 | 1 | mu_testing_set_sys(SYS_NCPUS, SYS_NCORES, SYS_NNODES); | |
| 110 | |||
| 111 | 1 | mu_get_system_description(&buffer); | |
| 112 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 113 | 1 | printbuffer_destroy(&buffer); | |
| 114 | |||
| 115 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_size() == SYS_NCPUS ); |
| 116 | 1 | mu_get_system_mask(&system_mask); | |
| 117 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&system_mask) == SYS_NCPUS |
| 118 | && mu_get_first_cpu(&system_mask) == 0 | ||
| 119 | && mu_get_last_cpu(&system_mask) == SYS_NCPUS - 1 ); | ||
| 120 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_system_has_smt() == true ); |
| 121 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_hwthreads_per_core() == 2 ); |
| 122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_num_nodes() == SYS_NNODES ); |
| 123 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_cores_per_node() == SYS_NCORES / SYS_NNODES ); |
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 0) == 2 ); |
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 29) == 30 ); |
| 126 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 30) == -1 ); |
| 127 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 31) == -1 ); |
| 128 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_cpu_next_core(&system_mask, 32) == -1 ); |
| 129 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(-1) == -1 ); |
| 130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(0) == 0 ); |
| 131 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(31) == 15 ); |
| 132 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(32) == -1 ); |
| 133 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(0) != NULL); |
| 134 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(32) == NULL); |
| 135 | |||
| 136 | /* Test core mask functions */ | ||
| 137 | cpu_set_t mask; | ||
| 138 | 1 | mu_parse_mask("0-3", &mask); | |
| 139 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == 2 ); // [0,1] [2,3] are counted |
| 140 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == 2 ); |
| 141 | |||
| 142 | 1 | mu_parse_mask("0,1,5,6,10,11", &mask); | |
| 143 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == 2 ); // [0,1] [10,11] are counted |
| 144 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == 4 ); // [0,1] [4,5] [5,6] [10,11] |
| 145 | // are counted | ||
| 146 | |||
| 147 | 1 | mu_parse_mask("0-31", &mask); | |
| 148 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == SYS_NCORES ); // all are counted |
| 149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == SYS_NCORES ); // all are counted |
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_last_coreid(&mask) == SYS_NCORES-1 ); |
| 151 | |||
| 152 | int last_cpu; | ||
| 153 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 1 times.
|
17 | while ( -1 != (last_cpu = mu_take_last_coreid(&mask)) ) { |
| 154 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | assert( last_cpu == mu_count_cores(&mask) ); |
| 155 | } | ||
| 156 | |||
| 157 | 1 | mu_zero(&mask); | |
| 158 | |||
| 159 | cpu_set_t mask_correct; | ||
| 160 | 1 | mu_set_core(&mask, 0); | |
| 161 | 1 | mu_parse_mask("0,1", &mask_correct); | |
| 162 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_equal(&mask, &mask_correct) ); |
| 163 | |||
| 164 | 1 | mu_set_core(&mask, 3); | |
| 165 | 1 | mu_parse_mask("0,1,6,7", &mask_correct); | |
| 166 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_equal(&mask, &mask_correct) ); |
| 167 | |||
| 168 | 1 | mu_unset_core(&mask, 0); | |
| 169 | 1 | mu_parse_mask("6,7", &mask_correct); | |
| 170 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_equal(&mask, &mask_correct) ); |
| 171 | |||
| 172 | 1 | mu_unset_core(&mask, 3); | |
| 173 | 1 | mu_zero(&mask_correct); | |
| 174 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_equal(&mask, &mask_correct) ); |
| 175 | |||
| 176 | 1 | mu_finalize(); | |
| 177 | } | ||
| 178 | |||
| 179 | /* Heterogeneous with custom masks */ | ||
| 180 | { | ||
| 181 | enum { NUM_CORES = 4 }; | ||
| 182 | enum { NUM_NODES = 2 }; | ||
| 183 | cpu_set_t core_masks[NUM_CORES]; | ||
| 184 | cpu_set_t node_masks[NUM_NODES]; | ||
| 185 | 1 | mu_parse_mask("0-1,5-12", &system_mask); | |
| 186 | 1 | mu_parse_mask("5-6", &core_masks[0]); | |
| 187 | 1 | mu_parse_mask("7-8", &core_masks[1]); | |
| 188 | 1 | mu_parse_mask("9-10", &core_masks[2]); | |
| 189 | 1 | mu_parse_mask("11-12", &core_masks[3]); | |
| 190 | 1 | mu_parse_mask("5-10", &node_masks[0]); | |
| 191 | 1 | mu_parse_mask("11-12", &node_masks[1]); | |
| 192 | 1 | warning("===== Heterogeneous arch ===== "); | |
| 193 | |||
| 194 | 1 | mu_testing_set_sys_masks(&system_mask, core_masks, NUM_CORES, node_masks, NUM_NODES); | |
| 195 | |||
| 196 | 1 | mu_get_system_description(&buffer); | |
| 197 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 198 | 1 | printbuffer_destroy(&buffer); | |
| 199 | |||
| 200 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_size() == 13 ); |
| 201 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_system_has_smt() == true ); |
| 202 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_hwthreads_per_core() == 2 ); |
| 203 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_num_nodes() == NUM_NODES ); |
| 204 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_cores_per_node() == 3 ); // accounts for node 0 only ([5-10]) |
| 205 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(0) == -1 ); |
| 206 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(5) == 0 ); |
| 207 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(12) == 3 ); |
| 208 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_id(13) == -1 ); |
| 209 | |||
| 210 | /* Test functions that operate on NUMA nodes */ | ||
| 211 | cpu_set_t affinity_mask; | ||
| 212 | 1 | mu_get_nodes_intersecting_with_cpuset(&affinity_mask, &system_mask); | |
| 213 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&affinity_mask) == 8 |
| 214 | && mu_get_first_cpu(&affinity_mask) == 5 | ||
| 215 | && mu_get_last_cpu(&affinity_mask) == 12 ); | ||
| 216 | 1 | mu_get_nodes_subset_of_cpuset(&affinity_mask, &system_mask); | |
| 217 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&affinity_mask) == 8 |
| 218 | && mu_get_first_cpu(&affinity_mask) == 5 | ||
| 219 | && mu_get_last_cpu(&affinity_mask) == 12 ); | ||
| 220 | 1 | mu_get_nodes_intersecting_with_cpuset(&affinity_mask, &zero_mask); | |
| 221 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&affinity_mask) == 0 ); |
| 222 | 1 | mu_get_nodes_subset_of_cpuset(&affinity_mask, &zero_mask); | |
| 223 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&affinity_mask) == 0 ); |
| 224 | |||
| 225 | /* Test functions that operate on cores */ | ||
| 226 | cpu_set_t mask; | ||
| 227 | 1 | mu_parse_mask("6-11", &mask); | |
| 228 | cpu_set_t result; | ||
| 229 | 1 | mu_get_cores_intersecting_with_cpuset(&result, &mask); | |
| 230 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&result) == 8 |
| 231 | && mu_get_first_cpu(&result) == 5 | ||
| 232 | && mu_get_last_cpu(&result) == 12 ); | ||
| 233 | 1 | mu_get_cores_subset_of_cpuset(&result, &mask); | |
| 234 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | assert( CPU_COUNT(&result) == 4 |
| 235 | && mu_get_first_cpu(&result) == 7 | ||
| 236 | && mu_get_last_cpu(&result) == 10 ); | ||
| 237 | 1 | mu_get_cores_intersecting_with_cpuset(&result, &zero_mask); | |
| 238 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&result) == 0 ); |
| 239 | 1 | mu_get_cores_subset_of_cpuset(&result, &zero_mask); | |
| 240 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&result) == 0 ); |
| 241 | |||
| 242 | /* mu_get_core_mask */ | ||
| 243 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(42) == NULL ); |
| 244 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | assert( CPU_COUNT_S(8, mu_get_core_mask(12)->set) == 2 ); |
| 245 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(12)->count == 2 ); |
| 246 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(12)->first_cpuid == 11 ); |
| 247 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_core_mask(12)->last_cpuid == 12 ); |
| 248 | |||
| 249 | |||
| 250 | 1 | mu_finalize(); | |
| 251 | } | ||
| 252 | |||
| 253 | /* Core masks in a round-robin fashion */ | ||
| 254 | { | ||
| 255 | enum { SYS_SIZE = 8 }; | ||
| 256 | enum { NUM_CORES = 4 }; | ||
| 257 | enum { NUM_NODES = 1 }; | ||
| 258 | cpu_set_t core_masks[NUM_CORES]; | ||
| 259 | cpu_set_t node_masks[NUM_NODES]; | ||
| 260 | 1 | mu_parse_mask("0-7", &system_mask); | |
| 261 | 1 | mu_parse_mask("0-7", &node_masks[0]); | |
| 262 | 1 | mu_parse_mask("0,4", &core_masks[0]); | |
| 263 | 1 | mu_parse_mask("1,5", &core_masks[1]); | |
| 264 | 1 | mu_parse_mask("2,6", &core_masks[2]); | |
| 265 | 1 | mu_parse_mask("3,7", &core_masks[3]); | |
| 266 | 1 | warning("===== Round-robin arch ===== "); | |
| 267 | |||
| 268 | 1 | mu_testing_set_sys_masks(&system_mask, core_masks, NUM_CORES, node_masks, NUM_NODES); | |
| 269 | |||
| 270 | 1 | mu_get_system_description(&buffer); | |
| 271 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 272 | 1 | printbuffer_destroy(&buffer); | |
| 273 | |||
| 274 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_size() == SYS_SIZE ); |
| 275 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_system_has_smt() == true ); |
| 276 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_hwthreads_per_core() == 2 ); |
| 277 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_num_nodes() == NUM_NODES ); |
| 278 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_system_cores_per_node() == NUM_CORES / NUM_NODES ); |
| 279 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
|
9 | for (int i = 0; i < SYS_SIZE; ++i) { |
| 280 | 8 | int core_id = i % 4; | |
| 281 | 8 | const mu_cpuset_t *core_mask = mu_get_core_mask(i); | |
| 282 | 8 | const mu_cpuset_t *core_mask_ = mu_get_core_mask_by_coreid(core_id); | |
| 283 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | assert( core_mask_ == core_mask ); |
| 284 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | assert( mu_get_core_id(i) == core_id ); |
| 285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | assert( core_mask->count == 2 ); |
| 286 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | assert( i == ( i < 4 ? core_mask->first_cpuid : core_mask->last_cpuid ) ); |
| 287 |
3/4✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
|
8 | assert( mu_get_cpu_next_core(&system_mask, i) == ( core_id < 3 |
| 288 | ? i + 1 : -1 ) ); | ||
| 289 | } | ||
| 290 | |||
| 291 | cpu_set_t mask; | ||
| 292 | 1 | mu_parse_mask("0,1,4,5", &mask); | |
| 293 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == 2 ); // [0,4] [1,5] are counted |
| 294 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == 2 ); // [0,4] [1,5] are counted |
| 295 | |||
| 296 | 1 | mu_parse_mask("0,1,2,3,4,5", &mask); | |
| 297 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == 2 ); // [0,4] [1,5] are counted |
| 298 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == 4 ); // [0,4] [1,5] [2,6] [3,7] |
| 299 | // are counted | ||
| 300 | |||
| 301 | 1 | mu_parse_mask("0-7", &mask); | |
| 302 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores(&mask) == NUM_CORES ); // all are counted |
| 303 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_count_cores_intersecting_with_cpuset(&mask) == NUM_CORES ); // all are counted |
| 304 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( mu_get_last_coreid(&mask) == NUM_CORES-1 ); |
| 305 | |||
| 306 | int last_cpu; | ||
| 307 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | while ( -1 != (last_cpu = mu_take_last_coreid(&mask)) ) { |
| 308 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | assert( last_cpu == mu_count_cores(&mask) ); |
| 309 | } | ||
| 310 | } | ||
| 311 | |||
| 312 | /* Test operations when system is smaller than mask's setsize */ | ||
| 313 | { | ||
| 314 | 1 | warning("===== Other tests ===== "); | |
| 315 | |||
| 316 | enum { SYS_SIZE = 64 }; | ||
| 317 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 318 | |||
| 319 | /* Create a mask will garbage at the end */ | ||
| 320 | cpu_set_t mask; | ||
| 321 | 1 | mu_parse_mask("0-63", &mask); | |
| 322 | 1 | mask.__bits[15] = 1; | |
| 323 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&mask) > 64 ); |
| 324 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT_S(8, &mask) == 64 ); |
| 325 | |||
| 326 | /* Ensure that we only iterate valid CPUs */ | ||
| 327 | 1 | int sum = 0; | |
| 328 |
2/2✓ Branch 1 taken 64 times.
✓ Branch 2 taken 1 times.
|
65 | for (int cpuid = mu_get_first_cpu(&mask); cpuid >= 0; |
| 329 | 64 | cpuid = mu_get_next_cpu(&mask, cpuid)) { | |
| 330 | 64 | sum += cpuid; | |
| 331 | 64 | fprintf(stderr, "cpuid: %d\n", cpuid); | |
| 332 | } | ||
| 333 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( sum == 63*(63+1)/2 ); /* 0 + 1 .. + 63 */ |
| 334 | |||
| 335 | 1 | mu_finalize(); | |
| 336 | } | ||
| 337 | |||
| 338 | /* Empty node */ | ||
| 339 | { | ||
| 340 | 1 | warning("===== Empty node ===== "); | |
| 341 | |||
| 342 | enum { SYS_SIZE = 144 }; | ||
| 343 | enum { NUM_CORES = 4 }; | ||
| 344 | enum { NUM_NODES = 2 }; | ||
| 345 | cpu_set_t core_masks[NUM_CORES]; | ||
| 346 | cpu_set_t node_masks[NUM_NODES]; | ||
| 347 | 1 | mu_parse_mask("0-143", &system_mask); | |
| 348 | 1 | mu_parse_mask("28-31,140-143", &node_masks[0]); | |
| 349 | 1 | mu_parse_mask("", &node_masks[1]); | |
| 350 | 1 | mu_parse_mask("28,140", &core_masks[0]); | |
| 351 | 1 | mu_parse_mask("29,141", &core_masks[1]); | |
| 352 | 1 | mu_parse_mask("30,142", &core_masks[2]); | |
| 353 | 1 | mu_parse_mask("31,143", &core_masks[3]); | |
| 354 | |||
| 355 | 1 | mu_testing_set_sys_masks(&system_mask, core_masks, NUM_CORES, node_masks, NUM_NODES); | |
| 356 | |||
| 357 | 1 | mu_get_system_description(&buffer); | |
| 358 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 359 | 1 | printbuffer_destroy(&buffer); | |
| 360 | } | ||
| 361 | |||
| 362 | /* Exactly 256 CPUs */ | ||
| 363 | { | ||
| 364 | 1 | warning("===== 256 CPUs node ===== "); | |
| 365 | 1 | mu_testing_set_sys_size(256); | |
| 366 | |||
| 367 | 1 | mu_get_system_description(&buffer); | |
| 368 | 1 | warning("System affinity\n%s", buffer.addr); | |
| 369 | 1 | printbuffer_destroy(&buffer); | |
| 370 | } | ||
| 371 | |||
| 372 | 1 | return 0; | |
| 373 | } | ||
| 374 |