| 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 | #include "unique_shmem.h" | ||
| 21 | |||
| 22 | #include "LB_comm/shmem.h" | ||
| 23 | #include "LB_comm/shmem_cpuinfo.h" | ||
| 24 | #include "LB_core/spd.h" | ||
| 25 | #include "apis/dlb_errors.h" | ||
| 26 | #include "support/mask_utils.h" | ||
| 27 | #include "support/options.h" | ||
| 28 | |||
| 29 | #include <sched.h> | ||
| 30 | #include <sys/types.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include <stdio.h> | ||
| 33 | #include <string.h> | ||
| 34 | #include <assert.h> | ||
| 35 | |||
| 36 | /* array_cpuid_t */ | ||
| 37 | #define ARRAY_T cpuid_t | ||
| 38 | #include "support/array_template.h" | ||
| 39 | |||
| 40 | /* array_cpuinfo_task_t */ | ||
| 41 | #define ARRAY_T cpuinfo_task_t | ||
| 42 | #define ARRAY_KEY_T pid_t | ||
| 43 | #include "support/array_template.h" | ||
| 44 | |||
| 45 | // Basic checks with 2 sub-processes with masks | ||
| 46 | |||
| 47 | 2 | int main( int argc, char **argv ) { | |
| 48 | // This test needs at least room for 4 CPUs | ||
| 49 | enum { SYS_SIZE = 4 }; | ||
| 50 | 2 | mu_init(); | |
| 51 | 2 | mu_testing_set_sys_size(SYS_SIZE); | |
| 52 | |||
| 53 | // Initialize local masks to [1100] and [0011] | ||
| 54 | 2 | pid_t p1_pid = 111; | |
| 55 | cpu_set_t p1_mask; | ||
| 56 | 2 | CPU_ZERO(&p1_mask); | |
| 57 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(0, &p1_mask); |
| 58 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(1, &p1_mask); |
| 59 | 2 | pid_t p2_pid = 222; | |
| 60 | cpu_set_t p2_mask; | ||
| 61 | 2 | CPU_ZERO(&p2_mask); | |
| 62 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(2, &p2_mask); |
| 63 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(3, &p2_mask); |
| 64 | array_cpuinfo_task_t tasks; | ||
| 65 | 2 | array_cpuinfo_task_t_init(&tasks, SYS_SIZE); | |
| 66 | |||
| 67 | // Construct some CPU priority arrays | ||
| 68 | array_cpuid_t cpus_0_1; | ||
| 69 | 2 | array_cpuid_t_init(&cpus_0_1, SYS_SIZE); | |
| 70 | 2 | array_cpuid_t_push(&cpus_0_1, 0); | |
| 71 | 2 | array_cpuid_t_push(&cpus_0_1, 1); | |
| 72 | |||
| 73 | array_cpuid_t cpus_2_3; | ||
| 74 | 2 | array_cpuid_t_init(&cpus_2_3, SYS_SIZE); | |
| 75 | 2 | array_cpuid_t_push(&cpus_2_3, 2); | |
| 76 | 2 | array_cpuid_t_push(&cpus_2_3, 3); | |
| 77 | |||
| 78 | array_cpuid_t cpus_2_3_0; | ||
| 79 | 2 | array_cpuid_t_init(&cpus_2_3_0, SYS_SIZE); | |
| 80 | 2 | array_cpuid_t_push(&cpus_2_3_0, 2); | |
| 81 | 2 | array_cpuid_t_push(&cpus_2_3_0, 3); | |
| 82 | 2 | array_cpuid_t_push(&cpus_2_3_0, 0); | |
| 83 | |||
| 84 | array_cpuid_t cpus_2_3_0_1; | ||
| 85 | 2 | array_cpuid_t_init(&cpus_2_3_0_1, SYS_SIZE); | |
| 86 | 2 | array_cpuid_t_push(&cpus_2_3_0_1, 2); | |
| 87 | 2 | array_cpuid_t_push(&cpus_2_3_0_1, 3); | |
| 88 | 2 | array_cpuid_t_push(&cpus_2_3_0_1, 0); | |
| 89 | 2 | array_cpuid_t_push(&cpus_2_3_0_1, 1); | |
| 90 | |||
| 91 | 2 | int64_t last_borrow = 0; | |
| 92 | int requested_ncpus; | ||
| 93 | |||
| 94 | // Init | ||
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p2_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_ERR_PERM ); |
| 97 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p2_pid, 0, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 98 | |||
| 99 | // Get pointers to the shmem auxiliary cpu sets | ||
| 100 | 2 | const cpu_set_t *free_cpus = shmem_cpuinfo_testing__get_free_cpu_set(); | |
| 101 | 2 | const cpu_set_t *occupied_cores = shmem_cpuinfo_testing__get_occupied_core_set(); | |
| 102 | |||
| 103 | // Initialize options and enable queues if needed | ||
| 104 | options_t options; | ||
| 105 | 2 | options_init(&options, NULL); | |
| 106 | 2 | bool async = options.mode == MODE_ASYNC; | |
| 107 | 2 | bool polling = options.mode == MODE_POLLING; | |
| 108 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { |
| 109 | 1 | shmem_cpuinfo__enable_request_queues(); | |
| 110 | } | ||
| 111 | |||
| 112 | int err; | ||
| 113 | |||
| 114 | /*** Successful ping-pong ***/ | ||
| 115 | { | ||
| 116 | // Process 1 wants CPUs 2 & 3 | ||
| 117 | 2 | requested_ncpus = 2; | |
| 118 | 2 | err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus, | |
| 119 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks); | ||
| 120 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( async ? err == DLB_NOTED : err == DLB_NOUPDT ); |
| 121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 122 | |||
| 123 | // Process 2 releases CPUs 2 & 3 | ||
| 124 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 125 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { |
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 127 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 128 | && tasks.items[0].cpuid == 2 | ||
| 129 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 130 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 131 | && tasks.items[1].cpuid == 3 | ||
| 132 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 133 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 134 | } else { | ||
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 136 | } | ||
| 137 | |||
| 138 | // If polling, process 1 needs to ask again for CPUs 2 & 3 | ||
| 139 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 140 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, NULL /* requested_ncpus */, |
| 141 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 142 | == DLB_SUCCESS ); | ||
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 144 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 145 | && tasks.items[0].cpuid == 2 | ||
| 146 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 147 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 148 | && tasks.items[1].cpuid == 3 | ||
| 149 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 150 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 151 | } | ||
| 152 | |||
| 153 | // Process 1 cannot reclaim CPUs 2 & 3 | ||
| 154 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_ERR_PERM ); |
| 155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 156 | |||
| 157 | // Process 2 reclaims CPUs 2 & 3 | ||
| 158 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_NOTED ); |
| 159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 160 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 161 | && tasks.items[0].cpuid == 2 | ||
| 162 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 163 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 164 | && tasks.items[1].cpuid == 2 | ||
| 165 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 166 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p1_pid |
| 167 | && tasks.items[2].cpuid == 3 | ||
| 168 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 169 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p2_pid |
| 170 | && tasks.items[3].cpuid == 3 | ||
| 171 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 172 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 173 | |||
| 174 | // Process 1 returns CPUs 2 & 3 | ||
| 175 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 176 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 178 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 179 | && tasks.items[0].cpuid == 2 | ||
| 180 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 181 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 182 | && tasks.items[1].cpuid == 3 | ||
| 183 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 184 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 185 | } else { | ||
| 186 | 1 | shmem_cpuinfo__return_async_cpu_mask(p1_pid, &p2_mask); | |
| 187 | } | ||
| 188 | |||
| 189 | // Process 2 releases CPUs 2 & 3 again | ||
| 190 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 191 |
10/18✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
|
2 | assert( async ? tasks.count == 2 |
| 192 | && tasks.items[0].pid == p1_pid && tasks.items[0].cpuid == 2 | ||
| 193 | && tasks.items[0].action == ENABLE_CPU | ||
| 194 | && tasks.items[1].pid == p1_pid && tasks.items[1].cpuid == 3 | ||
| 195 | && tasks.items[1].action == ENABLE_CPU | ||
| 196 | : tasks.count == 0 ); | ||
| 197 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 198 | |||
| 199 | // If polling, process 1 needs to ask again for CPUs 2 & 3 | ||
| 200 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 201 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, NULL /* requested_ncpus */, |
| 202 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 203 | == DLB_SUCCESS ); | ||
| 204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 205 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 206 | && tasks.items[0].cpuid == 2 | ||
| 207 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 208 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 209 | && tasks.items[1].cpuid == 3 | ||
| 210 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 211 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 212 | } | ||
| 213 | |||
| 214 | // Process 2 reclaims CPUs 2 & 3 again | ||
| 215 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_NOTED ); |
| 216 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 217 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 218 | && tasks.items[0].cpuid == 2 | ||
| 219 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 220 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 221 | && tasks.items[1].cpuid == 2 | ||
| 222 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 223 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p1_pid |
| 224 | && tasks.items[2].cpuid == 3 | ||
| 225 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 226 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p2_pid |
| 227 | && tasks.items[3].cpuid == 3 | ||
| 228 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 229 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 230 | |||
| 231 | // Process 1 returns CPUs 2 & 3 and removes petition | ||
| 232 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 233 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 234 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 235 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 236 | && tasks.items[0].cpuid == 2 | ||
| 237 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 238 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 239 | && tasks.items[1].cpuid == 3 | ||
| 240 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 241 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 242 | } else { | ||
| 243 | 1 | shmem_cpuinfo__return_async_cpu_mask(p1_pid, &p2_mask); | |
| 244 | } | ||
| 245 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 247 | |||
| 248 | // Process 2 releases CPUs 2 & 3, checks no victim and reclaims | ||
| 249 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 250 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 251 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 253 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 254 | && tasks.items[0].cpuid == 2 | ||
| 255 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 256 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 257 | && tasks.items[1].cpuid == 3 | ||
| 258 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 259 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 260 | |||
| 261 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( CPU_COUNT(free_cpus) == 0 ); |
| 262 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( CPU_COUNT(occupied_cores) == 0 ); |
| 263 | } | ||
| 264 | |||
| 265 | /*** Successful ping-pong, but using reclaim_all and return_all ***/ | ||
| 266 | { | ||
| 267 | // Process 2 releases CPUs 2 & 3 | ||
| 268 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 270 | |||
| 271 | // Process 1 wants CPUs 2 & 3 | ||
| 272 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, NULL /* requested_ncpus */, |
| 273 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 274 | == DLB_SUCCESS ); | ||
| 275 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 276 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 277 | && tasks.items[0].cpuid == 2 | ||
| 278 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 279 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p1_pid |
| 280 | && tasks.items[1].cpuid == 3 | ||
| 281 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 282 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 283 | |||
| 284 | // Process 2 reclaims all | ||
| 285 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED ); |
| 286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 287 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 288 | && tasks.items[0].cpuid == 2 | ||
| 289 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 290 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 291 | && tasks.items[1].cpuid == 2 | ||
| 292 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 293 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p1_pid |
| 294 | && tasks.items[2].cpuid == 3 | ||
| 295 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 296 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p2_pid |
| 297 | && tasks.items[3].cpuid == 3 | ||
| 298 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 299 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 300 | |||
| 301 | // Process 1 returns all | ||
| 302 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 303 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_all(p1_pid, &tasks) == DLB_SUCCESS ); |
| 304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 305 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 306 | && tasks.items[0].cpuid == 2 | ||
| 307 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 308 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 309 | && tasks.items[1].cpuid == 3 | ||
| 310 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 311 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 312 | } else { | ||
| 313 | 1 | shmem_cpuinfo__return_async_cpu_mask(p1_pid, &p2_mask); | |
| 314 | } | ||
| 315 | |||
| 316 | // Process 2 releases CPUs 2 & 3 again | ||
| 317 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 318 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { |
| 319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 320 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 321 | && tasks.items[0].cpuid == 2 | ||
| 322 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 323 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 324 | && tasks.items[1].cpuid == 3 | ||
| 325 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 326 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 327 | } else { | ||
| 328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 329 | } | ||
| 330 | |||
| 331 | // If polling, process 1 needs to ask again for CPUs 2 & 3 | ||
| 332 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 333 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, NULL /* requested_ncpus */, |
| 334 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 335 | == DLB_SUCCESS ); | ||
| 336 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 337 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 338 | && tasks.items[0].cpuid == 2 | ||
| 339 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 340 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 341 | && tasks.items[1].cpuid == 3 | ||
| 342 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 343 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 344 | } | ||
| 345 | |||
| 346 | // Process 2 reclaims all again | ||
| 347 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED ); |
| 348 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 349 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 350 | && tasks.items[0].cpuid == 2 | ||
| 351 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 352 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 353 | && tasks.items[1].cpuid == 2 | ||
| 354 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 355 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p1_pid |
| 356 | && tasks.items[2].cpuid == 3 | ||
| 357 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 358 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p2_pid |
| 359 | && tasks.items[3].cpuid == 3 | ||
| 360 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 361 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 362 | |||
| 363 | // Process 1 returns all and removes petition | ||
| 364 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 365 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_all(p1_pid, &tasks) == DLB_SUCCESS ); |
| 366 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 367 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 368 | && tasks.items[0].cpuid == 2 | ||
| 369 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 370 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p1_pid |
| 371 | && tasks.items[1].cpuid == 3 | ||
| 372 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 373 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 374 | } else { | ||
| 375 | 1 | shmem_cpuinfo__return_async_cpu_mask(p1_pid, &p2_mask); | |
| 376 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__lend_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 378 | } | ||
| 379 | |||
| 380 | // Process 2 releases CPUs 2 & 3, checks no new guests and reclaims | ||
| 381 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 382 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 383 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_SUCCESS ); |
| 384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 385 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 386 | && tasks.items[0].cpuid == 2 | ||
| 387 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 388 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 389 | && tasks.items[1].cpuid == 3 | ||
| 390 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 391 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 392 | } | ||
| 393 | |||
| 394 | /*** Late reply ***/ | ||
| 395 | { | ||
| 396 | // Process 1 wants CPUs 2 & 3 | ||
| 397 | 2 | requested_ncpus = 2; | |
| 398 | 2 | err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus, | |
| 399 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks); | ||
| 400 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( async ? err == DLB_NOTED : err == DLB_NOUPDT ); |
| 401 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 402 | |||
| 403 | // Process 1 no longer wants CPUs 2 & 3 | ||
| 404 | 2 | shmem_cpuinfo__remove_requests(p1_pid); | |
| 405 | |||
| 406 | // Process 2 releases CPUs 2 & 3 | ||
| 407 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 409 | |||
| 410 | // Process 2 reclaims CPUs 2 & 3 | ||
| 411 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 412 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 413 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 414 | && tasks.items[0].cpuid == 2 | ||
| 415 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 416 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 417 | && tasks.items[1].cpuid == 3 | ||
| 418 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 419 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 420 | } | ||
| 421 | |||
| 422 | /*** MaxParallelism ***/ | ||
| 423 | { | ||
| 424 | // Process 1 lends CPU 0 | ||
| 425 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS ); |
| 426 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 427 | |||
| 428 | // TEST 1: process 2 is guesting 0,2-3 and sets max_parellelism to 1 | ||
| 429 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 430 | &cpus_2_3_0, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 431 | == DLB_SUCCESS ); | ||
| 432 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 433 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 434 | && tasks.items[0].cpuid == 0 | ||
| 435 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 436 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 437 | |||
| 438 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 1, &tasks) == DLB_SUCCESS ); |
| 439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 440 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 441 | && tasks.items[0].cpuid == 3 | ||
| 442 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 443 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 444 | && tasks.items[1].cpuid == 0 | ||
| 445 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 446 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 447 | |||
| 448 | // TEST 2: process 2 is guesting 0,2-3 and sets max_parellelism to 2 | ||
| 449 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 450 | &cpus_2_3_0, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 451 | == DLB_SUCCESS ); | ||
| 452 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 453 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 454 | && tasks.items[0].cpuid == 3 | ||
| 455 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 456 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 457 | && tasks.items[1].cpuid == 0 | ||
| 458 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 459 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 460 | |||
| 461 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 2, &tasks) == DLB_SUCCESS ); |
| 462 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 463 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 464 | && tasks.items[0].cpuid == 0 | ||
| 465 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 466 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 467 | |||
| 468 | // TEST 3: process 2 is guesting 0,2-3 and sets max_parellelism to 3 | ||
| 469 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 470 | &cpus_2_3_0, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 471 | == DLB_SUCCESS ); | ||
| 472 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 473 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 474 | && tasks.items[0].cpuid == 0 | ||
| 475 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 476 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 477 | |||
| 478 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 3, &tasks) == DLB_SUCCESS ); |
| 479 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 480 | |||
| 481 | // Process 1 lends CPU 1 | ||
| 482 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p1_pid, 1, &tasks) == DLB_SUCCESS ); |
| 483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 484 | |||
| 485 | // TEST 4: process 2 is guesting 0-3 and sets max_parellelism to 1 | ||
| 486 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 487 | &cpus_2_3_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 488 | == DLB_SUCCESS ); | ||
| 489 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 490 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 491 | && tasks.items[0].cpuid == 1 | ||
| 492 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 493 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 494 | |||
| 495 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 1, &tasks) == DLB_SUCCESS ); |
| 496 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 3 ); |
| 497 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 498 | && tasks.items[0].cpuid == 3 | ||
| 499 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 500 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 501 | && tasks.items[1].cpuid == 0 | ||
| 502 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 503 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p2_pid |
| 504 | && tasks.items[2].cpuid == 1 | ||
| 505 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 506 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 507 | |||
| 508 | // TEST 5: process 2 is guesting 0-3 and sets max_parellelism to 2 | ||
| 509 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 510 | &cpus_2_3_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 511 | == DLB_SUCCESS ); | ||
| 512 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 3 ); |
| 513 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 514 | && tasks.items[0].cpuid == 3 | ||
| 515 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 516 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 517 | && tasks.items[1].cpuid == 0 | ||
| 518 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 519 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p2_pid |
| 520 | && tasks.items[2].cpuid == 1 | ||
| 521 | && tasks.items[2].action == ENABLE_CPU ); | ||
| 522 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 523 | |||
| 524 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 2, &tasks) == DLB_SUCCESS ); |
| 525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 526 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 527 | && tasks.items[0].cpuid == 0 | ||
| 528 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 529 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 530 | && tasks.items[1].cpuid == 1 | ||
| 531 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 532 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 533 | |||
| 534 | // TEST 6: process 2 is guesting 0-3 and sets max_parellelism to 3, P1 reclaims | ||
| 535 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 536 | &cpus_2_3_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 537 | == DLB_SUCCESS ); | ||
| 538 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 539 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 540 | && tasks.items[0].cpuid == 0 | ||
| 541 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 542 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 543 | && tasks.items[1].cpuid == 1 | ||
| 544 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 545 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 546 | |||
| 547 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_all(p1_pid, &tasks) == DLB_NOTED ); |
| 548 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 549 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 550 | && tasks.items[0].cpuid == 0 | ||
| 551 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 552 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p1_pid |
| 553 | && tasks.items[1].cpuid == 0 | ||
| 554 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 555 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p2_pid |
| 556 | && tasks.items[2].cpuid == 1 | ||
| 557 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 558 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p1_pid |
| 559 | && tasks.items[3].cpuid == 1 | ||
| 560 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 561 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 562 | |||
| 563 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 3, &tasks) == DLB_SUCCESS ); |
| 564 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 565 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 566 | && tasks.items[0].cpuid == 1 | ||
| 567 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 568 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 569 | && tasks.items[1].cpuid == 1 | ||
| 570 | && tasks.items[1].action == DISABLE_CPU ); | ||
| 571 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 572 | |||
| 573 | // Process 2 lends CPU 0 | ||
| 574 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS ); |
| 575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 576 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 577 | && tasks.items[0].cpuid == 0 | ||
| 578 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 579 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 580 | } | ||
| 581 | |||
| 582 | /*** Test CPU ownership changes ***/ | ||
| 583 | { | ||
| 584 | cpu_set_t mask; | ||
| 585 | |||
| 586 | // Remove CPU 3 ownership from Process 2 | ||
| 587 | 2 | mu_parse_mask("2", &mask); | |
| 588 | 2 | shmem_cpuinfo__update_ownership(p2_pid, &mask, &tasks); | |
| 589 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 590 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 591 | && tasks.items[0].cpuid == 3 | ||
| 592 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 593 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 594 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 3) == DLB_ERR_PERM ); |
| 595 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_ERR_PERM ); |
| 596 | // Recover | ||
| 597 | 2 | mu_parse_mask("2-3", &mask); | |
| 598 | 2 | shmem_cpuinfo__update_ownership(p2_pid, &mask, &tasks); | |
| 599 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 600 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 601 | && tasks.items[0].cpuid == 3 | ||
| 602 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 603 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 604 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 3) == DLB_ERR_PERM ); |
| 605 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_SUCCESS ); |
| 606 | |||
| 607 | // Remove CPU 3 ownership from Process 2 while in LENT state | ||
| 608 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS ); |
| 609 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 610 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS ); |
| 611 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 612 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 613 | && tasks.items[0].cpuid == 3 | ||
| 614 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 615 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 616 | 2 | mu_parse_mask("2", &mask); | |
| 617 | 2 | shmem_cpuinfo__update_ownership(p2_pid, &mask, &tasks); | |
| 618 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 619 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 620 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS ); |
| 621 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 1 ); |
| 622 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p1_pid |
| 623 | && tasks.items[0].cpuid == 3 | ||
| 624 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 625 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 626 | } else { | ||
| 627 | 1 | shmem_cpuinfo__return_async_cpu(p1_pid, 3); | |
| 628 | } | ||
| 629 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_ERR_PERM ); |
| 630 | // Recover | ||
| 631 | 2 | mu_parse_mask("2-3", &mask); | |
| 632 | 2 | shmem_cpuinfo__update_ownership(p2_pid, &mask, &tasks); | |
| 633 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 634 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 635 | && tasks.items[0].cpuid == 3 | ||
| 636 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 637 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 638 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 3) == DLB_ERR_PERM ); |
| 639 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_SUCCESS ); |
| 640 | |||
| 641 | // Steal ownership of CPU 3 from Process 2 to Process 1, while CPU 0 is LENT | ||
| 642 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS ); |
| 643 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 644 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS ); |
| 645 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 646 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 647 | && tasks.items[0].cpuid == 0 | ||
| 648 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 649 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 650 | 2 | mu_parse_mask("0-1,3", &mask); | |
| 651 | 2 | shmem_cpuinfo__update_ownership(p1_pid, &mask, &tasks); | |
| 652 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 653 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 654 | && tasks.items[0].cpuid == 3 | ||
| 655 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 656 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p1_pid |
| 657 | && tasks.items[1].cpuid == 3 | ||
| 658 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 659 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 660 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 661 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__return_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS ); |
| 662 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 1 ); |
| 663 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p2_pid |
| 664 | && tasks.items[0].cpuid == 3 | ||
| 665 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 666 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 667 | } else { | ||
| 668 | 1 | shmem_cpuinfo__return_async_cpu(p2_pid, 3); | |
| 669 | } | ||
| 670 | // CPU 0 is still guested by Process2 | ||
| 671 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 0) == DLB_SUCCESS ); |
| 672 | // CPU 3 is available to Process1 | ||
| 673 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 3) == DLB_SUCCESS ); |
| 674 | // Recover | ||
| 675 | 2 | mu_parse_mask("0-1", &mask); | |
| 676 | 2 | shmem_cpuinfo__update_ownership(p1_pid, &mask, &tasks); | |
| 677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 678 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 679 | && tasks.items[0].cpuid == 3 | ||
| 680 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 681 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 682 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p1_pid, 3) == DLB_ERR_PERM ); |
| 683 | 2 | mu_parse_mask("2-3", &mask); | |
| 684 | 2 | shmem_cpuinfo__update_ownership(p2_pid, &mask, &tasks); | |
| 685 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 686 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 687 | && tasks.items[0].cpuid == 3 | ||
| 688 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 689 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 690 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_SUCCESS ); |
| 691 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS ); |
| 692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 693 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS ); |
| 694 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 1 ); |
| 695 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 696 | && tasks.items[0].cpuid == 0 | ||
| 697 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 698 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 699 | } | ||
| 700 | |||
| 701 | // Finalize | ||
| 702 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 703 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 704 | |||
| 705 | /* Test lend post mortem feature */ | ||
| 706 | { | ||
| 707 | // Set up fake spd to set post-mortem option | ||
| 708 | subprocess_descriptor_t spd; | ||
| 709 | 2 | spd.options.debug_opts = DBG_LPOSTMORTEM; | |
| 710 | 2 | spd_enter_dlb(&spd); | |
| 711 | |||
| 712 | // Initialize | ||
| 713 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 714 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p2_pid, 0, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 715 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { shmem_cpuinfo__enable_request_queues(); } |
| 716 | |||
| 717 | // P1 finalizes | ||
| 718 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 719 | |||
| 720 | // P2 borrows P1 CPUs | ||
| 721 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 722 | &cpus_2_3_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 723 | == DLB_SUCCESS ); | ||
| 724 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 725 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p2_pid |
| 726 | && tasks.items[0].cpuid == 0 | ||
| 727 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 728 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 729 | && tasks.items[1].cpuid == 1 | ||
| 730 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 731 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 732 | |||
| 733 | // P2 finalizes | ||
| 734 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 735 | } | ||
| 736 | |||
| 737 | /* Test early finalization with pending actions */ | ||
| 738 | { | ||
| 739 | // Set up fake spd to set post-mortem option | ||
| 740 | subprocess_descriptor_t spd; | ||
| 741 | 2 | spd.options.debug_opts = DBG_LPOSTMORTEM; | |
| 742 | 2 | spd_enter_dlb(&spd); | |
| 743 | |||
| 744 | // Initialize | ||
| 745 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 746 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__init(p2_pid, 0, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 747 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { shmem_cpuinfo__enable_request_queues(); } |
| 748 | |||
| 749 | // P2 lends CPUs 2 & 3 | ||
| 750 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__lend_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_SUCCESS ); |
| 751 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 752 | |||
| 753 | // P1 acquires CPU 2 & 3 | ||
| 754 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, NULL /* requested_ncpus */, |
| 755 | &cpus_2_3, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks) | ||
| 756 | == DLB_SUCCESS ); | ||
| 757 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 2 ); |
| 758 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 759 | && tasks.items[0].cpuid == 2 | ||
| 760 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 761 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p1_pid |
| 762 | && tasks.items[1].cpuid == 3 | ||
| 763 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 764 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 765 | |||
| 766 | // P2 reclaims its CPU and requests the rest | ||
| 767 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__reclaim_cpu_mask(p2_pid, &p2_mask, &tasks) == DLB_NOTED ); |
| 768 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 4 ); |
| 769 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[0].pid == p1_pid |
| 770 | && tasks.items[0].cpuid == 2 | ||
| 771 | && tasks.items[0].action == DISABLE_CPU ); | ||
| 772 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[1].pid == p2_pid |
| 773 | && tasks.items[1].cpuid == 2 | ||
| 774 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 775 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[2].pid == p1_pid |
| 776 | && tasks.items[2].cpuid == 3 | ||
| 777 | && tasks.items[2].action == DISABLE_CPU ); | ||
| 778 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[3].pid == p2_pid |
| 779 | && tasks.items[3].cpuid == 3 | ||
| 780 | && tasks.items[3].action == ENABLE_CPU ); | ||
| 781 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 782 | 2 | requested_ncpus = 2; | |
| 783 | 2 | err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus, | |
| 784 | &cpus_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, &tasks); | ||
| 785 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( async ? err == DLB_NOTED : err == DLB_NOUPDT ); |
| 786 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 787 | |||
| 788 | // P1 finalizes | ||
| 789 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS ); |
| 790 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (async) { |
| 791 | // P2 gets CPUs 0-3 | ||
| 792 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 4 ); |
| 793 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (int i = 0; i < 4; ++i) { |
| 794 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | assert( tasks.items[i].pid == p2_pid |
| 795 | && tasks.items[i].cpuid == i | ||
| 796 | && tasks.items[i].action == ENABLE_CPU ); | ||
| 797 | } | ||
| 798 | } else { | ||
| 799 | // P2 gets CPU 2-3 | ||
| 800 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 801 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (int i = 0; i < 2; ++i) { |
| 802 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | assert( tasks.items[i].pid == p2_pid |
| 803 | && tasks.items[i].cpuid == i+2 | ||
| 804 | && tasks.items[i].action == ENABLE_CPU ); | ||
| 805 | } | ||
| 806 | } | ||
| 807 | 2 | array_cpuinfo_task_t_clear(&tasks); | |
| 808 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 809 | |||
| 810 | // If polling, P2 needs to ask again for CPUs 0-3 | ||
| 811 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (polling) { |
| 812 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 2) == DLB_SUCCESS ); |
| 813 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 3) == DLB_SUCCESS ); |
| 814 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */, |
| 815 | &cpus_2_3_0_1, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, &last_borrow, | ||
| 816 | &tasks) == DLB_SUCCESS ); | ||
| 817 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 2 ); |
| 818 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[0].pid == p2_pid |
| 819 | && tasks.items[0].cpuid == 0 | ||
| 820 | && tasks.items[0].action == ENABLE_CPU ); | ||
| 821 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | assert( tasks.items[1].pid == p2_pid |
| 822 | && tasks.items[1].cpuid == 1 | ||
| 823 | && tasks.items[1].action == ENABLE_CPU ); | ||
| 824 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 825 | } | ||
| 826 | |||
| 827 | // P2 finalizes | ||
| 828 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS ); |
| 829 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( tasks.count == 0 ); |
| 830 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 831 | } | ||
| 832 | |||
| 833 | 2 | mu_finalize(); | |
| 834 | |||
| 835 | 2 | return 0; | |
| 836 | } | ||
| 837 |