| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2021 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 "apis/dlb_sp.h" | ||
| 23 | #include "support/mask_utils.h" | ||
| 24 | #include "LB_comm/shmem_async.h" | ||
| 25 | #include "LB_core/spd.h" | ||
| 26 | |||
| 27 | #include <sched.h> | ||
| 28 | #include <unistd.h> | ||
| 29 | #include <string.h> | ||
| 30 | #include <assert.h> | ||
| 31 | |||
| 32 | /* Same test as 03_policies/lewi_mask_01.c but using the API (sp) */ | ||
| 33 | |||
| 34 | static dlb_handler_t handler1; | ||
| 35 | static dlb_handler_t handler2; | ||
| 36 | static cpu_set_t sp1_mask; | ||
| 37 | static cpu_set_t sp2_mask; | ||
| 38 | static bool sp1_enabled = true; | ||
| 39 | static bool sp2_enabled = true; | ||
| 40 | static interaction_mode_t mode; | ||
| 41 | |||
| 42 | /* Subprocess 1 callbacks */ | ||
| 43 | 28 | static void sp1_cb_enable_cpu(int cpuid, void *arg) { | |
| 44 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | CPU_SET(cpuid, &sp1_mask); |
| 45 | 28 | } | |
| 46 | |||
| 47 | 4 | static void sp1_cb_disable_cpu(int cpuid, void *arg) { | |
| 48 |
4/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
4 | if (mode == MODE_ASYNC && sp1_enabled) { |
| 49 | 1 | DLB_ReturnCpu_sp(handler1, cpuid); | |
| 50 | } | ||
| 51 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | CPU_CLR(cpuid, &sp1_mask); |
| 52 | 4 | } | |
| 53 | |||
| 54 | /* Subprocess 2 callbacks */ | ||
| 55 | 27 | static void sp2_cb_enable_cpu(int cpuid, void *arg) { | |
| 56 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | CPU_SET(cpuid, &sp2_mask); |
| 57 | 27 | } | |
| 58 | |||
| 59 | 10 | static void sp2_cb_disable_cpu(int cpuid, void *arg) { | |
| 60 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
10 | if (mode == MODE_ASYNC && sp2_enabled) { |
| 61 | 6 | DLB_ReturnCpu_sp(handler2, cpuid); | |
| 62 | } | ||
| 63 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | CPU_CLR(cpuid, &sp2_mask); |
| 64 | 10 | } | |
| 65 | |||
| 66 | 8 | static void wait_for_async_completion(void) { | |
| 67 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | if (mode == MODE_ASYNC) { |
| 68 | 7 | pid_t pid1 = ((const subprocess_descriptor_t*)handler1)->id; | |
| 69 | 7 | pid_t pid2 = ((const subprocess_descriptor_t*)handler2)->id; | |
| 70 | 7 | shmem_async_wait_for_completion(pid1); | |
| 71 | 7 | shmem_async_wait_for_completion(pid2); | |
| 72 | 7 | __sync_synchronize(); | |
| 73 | } | ||
| 74 | 8 | } | |
| 75 | |||
| 76 | 2 | int main( int argc, char **argv ) { | |
| 77 | // This test needs at least room for 4 CPUs | ||
| 78 | enum { SYS_SIZE = 4 }; | ||
| 79 | 2 | mu_init(); | |
| 80 | 2 | mu_testing_set_sys_size(SYS_SIZE); | |
| 81 | |||
| 82 | // Initialize local masks to [1100] and [0011] | ||
| 83 | 2 | CPU_ZERO(&sp1_mask); | |
| 84 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(0, &sp1_mask); |
| 85 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(1, &sp1_mask); |
| 86 | 2 | CPU_ZERO(&sp2_mask); | |
| 87 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(2, &sp2_mask); |
| 88 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(3, &sp2_mask); |
| 89 | |||
| 90 | // Initialize constant masks for fast reference | ||
| 91 | 2 | const cpu_set_t sys_mask = { .__bits = {0xf} }; /* [1111] */ | |
| 92 | 2 | const cpu_set_t sp1_process_mask = {.__bits={0x3}}; /* [0011] */ | |
| 93 | 2 | const cpu_set_t sp2_process_mask = {.__bits={0xc}}; /* [1100] */ | |
| 94 | |||
| 95 | // Options | ||
| 96 | 2 | char options[64] = "--lewi --shm-key="; | |
| 97 | 2 | strcat(options, SHMEM_KEY); | |
| 98 | |||
| 99 | // Subprocess 1 init | ||
| 100 | 2 | handler1 = DLB_Init_sp(0, &sp1_mask, options); | |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( handler1 != NULL ); |
| 102 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_CallbackSet_sp(handler1, dlb_callback_enable_cpu, |
| 103 | (dlb_callback_t)sp1_cb_enable_cpu, NULL) == DLB_SUCCESS); | ||
| 104 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_CallbackSet_sp(handler1, dlb_callback_disable_cpu, |
| 105 | (dlb_callback_t)sp1_cb_disable_cpu, NULL) == DLB_SUCCESS); | ||
| 106 | |||
| 107 | // Subprocess 2 init | ||
| 108 | 2 | handler2 = DLB_Init_sp(0, &sp2_mask, options); | |
| 109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( handler2 != NULL ); |
| 110 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_CallbackSet_sp(handler2, dlb_callback_enable_cpu, |
| 111 | (dlb_callback_t)sp2_cb_enable_cpu, NULL) == DLB_SUCCESS ); | ||
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_CallbackSet_sp(handler2, dlb_callback_disable_cpu, |
| 113 | (dlb_callback_t)sp2_cb_disable_cpu, NULL) == DLB_SUCCESS ); | ||
| 114 | |||
| 115 | // Get interaction mode (this test is called twice, using mode={polling,async}) | ||
| 116 | char value[16]; | ||
| 117 | 2 | DLB_GetVariable_sp(handler1, "--mode", value); | |
| 118 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (strcmp(value, "polling") == 0) { |
| 119 | 1 | mode = MODE_POLLING; | |
| 120 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | } else if (strcmp(value, "async") == 0) { |
| 121 | 1 | mode = MODE_ASYNC; | |
| 122 | } else { | ||
| 123 | // Unknown value | ||
| 124 | ✗ | return -1; | |
| 125 | } | ||
| 126 | |||
| 127 | int err; | ||
| 128 | |||
| 129 | /* Cpu tests */ | ||
| 130 | { | ||
| 131 | // Subprocess 1 wants to acquire CPU 3 | ||
| 132 | 2 | err = DLB_AcquireCpu_sp(handler1, 3); | |
| 133 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( mode == MODE_ASYNC ? err == DLB_NOTED : err == DLB_NOUPDT ); |
| 134 | |||
| 135 | // Subprocess 2 no longer needs CPU 3 | ||
| 136 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(3, &sp2_mask); |
| 137 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 3) == DLB_SUCCESS ); |
| 138 | |||
| 139 | // Subprocess 1 receives CPU 3 | ||
| 140 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 141 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpu_sp(handler1, 3) == DLB_SUCCESS ); |
| 142 | } else { | ||
| 143 | 1 | wait_for_async_completion(); | |
| 144 | } | ||
| 145 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(3, &sp1_mask) ); |
| 146 | |||
| 147 | // Subprocess 2 needs again CPU 3 | ||
| 148 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpu_sp(handler2, 3) == DLB_NOTED ); |
| 149 | |||
| 150 | // Resolve that Subprocess 2 contains CPU 3, and Subprocess 1 doesn't | ||
| 151 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 152 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler2, 3) == DLB_NOTED ); |
| 153 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReturnCpu_sp(handler1, 3) == DLB_SUCCESS ); |
| 154 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler2, 3) == DLB_SUCCESS ); |
| 155 | } else { | ||
| 156 | 1 | wait_for_async_completion(); | |
| 157 | } | ||
| 158 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(3, &sp2_mask) ); |
| 159 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( !CPU_ISSET(3, &sp1_mask) ); |
| 160 | |||
| 161 | // Subprocess 1 no longer needs CPU 1 | ||
| 162 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(1, &sp1_mask); |
| 163 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler1, 1) == DLB_SUCCESS ); |
| 164 | |||
| 165 | // Subprocess 2 needs CPU 1 | ||
| 166 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpu_sp(handler2, 1) == DLB_SUCCESS ); |
| 167 | |||
| 168 | // Subprocess 1 reclaims | ||
| 169 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_ReclaimCpu_sp(handler1, 1) == DLB_NOTED ); |
| 170 | |||
| 171 | // Resolve that Subprocess 1 contains CPU 1, and Subprocess 2 doesn't | ||
| 172 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 173 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler1, 1) == DLB_NOTED ); |
| 174 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReturnCpu_sp(handler2, 1) == DLB_SUCCESS ); |
| 175 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler1, 1) == DLB_SUCCESS ); |
| 176 | } else { | ||
| 177 | 1 | wait_for_async_completion(); | |
| 178 | } | ||
| 179 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(1, &sp1_mask) ); |
| 180 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( !CPU_ISSET(1, &sp2_mask) ); |
| 181 | |||
| 182 | // Test that SP2 receives CPU 1 again if SP1 lends it again | ||
| 183 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_ASYNC) { |
| 184 | // Subprocess 1 lends everything | ||
| 185 | 1 | CPU_ZERO(&sp1_mask); | |
| 186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_LendCpuMask_sp(handler1, &sys_mask) == DLB_SUCCESS ); |
| 187 | |||
| 188 | // CPU 1 was still requested by Subprocess 2 | ||
| 189 | 1 | wait_for_async_completion(); | |
| 190 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert( CPU_ISSET(1, &sp2_mask) ); |
| 191 | |||
| 192 | // Subprocess 2 lends CPU 1 | ||
| 193 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_CLR(1, &sp2_mask); |
| 194 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_LendCpu_sp(handler2, 1) == DLB_SUCCESS ); |
| 195 | |||
| 196 | // Subprocess 1 acquires its mask | ||
| 197 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpuMask_sp(handler1, &sp1_process_mask) == DLB_SUCCESS ); |
| 198 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert( CPU_ISSET(0, &sp1_mask) ); |
| 199 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert( CPU_ISSET(1, &sp1_mask) ); |
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | /* CpuMask tests */ | ||
| 204 | { | ||
| 205 | // Subprocess 1 lends everything | ||
| 206 | 2 | CPU_ZERO(&sp1_mask); | |
| 207 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler1, &sys_mask) == DLB_SUCCESS ); |
| 208 | |||
| 209 | // Subprocess 2 acquires everything | ||
| 210 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpuMask_sp(handler2, &sys_mask) == DLB_SUCCESS ); |
| 211 | |||
| 212 | // Subprocess 1 reclaims its CPUs | ||
| 213 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_ReclaimCpuMask_sp(handler1, &sp1_process_mask) == DLB_NOTED ); |
| 214 | |||
| 215 | // Subprocess 1 reclaims everything | ||
| 216 | 2 | err = DLB_ReclaimCpuMask_sp(handler1, &sys_mask); | |
| 217 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( mode == MODE_ASYNC ? err == DLB_NOUPDT : err == DLB_NOTED ); |
| 218 | |||
| 219 | // Subprocess 2 lends external CPUs | ||
| 220 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(0, &sp2_mask); |
| 221 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(1, &sp2_mask); |
| 222 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler2, &sp1_process_mask) == DLB_SUCCESS ); |
| 223 | |||
| 224 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 225 | // Subprocess 1 needs to poll to set guest field | ||
| 226 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler1, 0) == DLB_SUCCESS ); |
| 227 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler1, 1) == DLB_SUCCESS ); |
| 228 | } else { | ||
| 229 | 1 | wait_for_async_completion(); | |
| 230 | } | ||
| 231 | |||
| 232 | // Check everyone has their CPUs | ||
| 233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( CPU_EQUAL(&sp1_process_mask, &sp1_mask) ); |
| 234 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | assert( CPU_EQUAL(&sp2_process_mask, &sp2_mask) ); |
| 235 | } | ||
| 236 | |||
| 237 | /* Cpus tests */ | ||
| 238 | { | ||
| 239 | // Subprocess 1 lends CPU 1 | ||
| 240 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(1, &sp1_mask); |
| 241 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler1, 1) == DLB_SUCCESS ); |
| 242 | |||
| 243 | // Subprocess 2 acquires one CPU | ||
| 244 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpus_sp(handler2, 1) == DLB_SUCCESS ); |
| 245 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(1, &sp2_mask) ); |
| 246 | |||
| 247 | // Subprocess 2 acquires one CPU again | ||
| 248 | 2 | err = DLB_AcquireCpus_sp(handler2, 1); | |
| 249 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( mode == MODE_ASYNC ? err == DLB_NOTED : err == DLB_NOUPDT ); |
| 250 | |||
| 251 | // Subprocess 1 acquires 1 CPU, it should reclaim CPU 1 | ||
| 252 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpus_sp(handler1, 1) == DLB_NOTED ); |
| 253 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(1, &sp1_mask) ); |
| 254 | |||
| 255 | // Subprocess 2 returns CPU 1 (async returns by callback) | ||
| 256 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 257 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | assert( CPU_ISSET(1, &sp2_mask) ); |
| 258 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | CPU_CLR(1, &sp2_mask); |
| 259 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_ReturnCpu_sp(handler2, 1) == DLB_SUCCESS ); |
| 260 | } | ||
| 261 | |||
| 262 | // Subprocess 1 needs to poll to set guest field | ||
| 263 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_POLLING) { |
| 264 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_CheckCpuAvailability_sp(handler1, 1) == DLB_SUCCESS ); |
| 265 | } | ||
| 266 | |||
| 267 | // Subprocess 2 no longer wants external CPUs | ||
| 268 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpus_sp(handler2, 0) == DLB_SUCCESS ); /* general queue */ |
| 269 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 1) == DLB_SUCCESS ); /* CPU queue */ |
| 270 | |||
| 271 | 2 | wait_for_async_completion(); | |
| 272 | } | ||
| 273 | |||
| 274 | /* Reset test */ | ||
| 275 | { | ||
| 276 | // Subprocess 2 lends CPU 3 | ||
| 277 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(3, &sp2_mask); |
| 278 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 3) == DLB_SUCCESS ); |
| 279 | |||
| 280 | // Subprocess 1 acquires one CPU | ||
| 281 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpus_sp(handler1, 1) == DLB_SUCCESS ); |
| 282 |
4/8✓ 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.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | assert( CPU_ISSET(3, &sp1_mask) && CPU_COUNT(&sp1_mask) == 3 ); |
| 283 | |||
| 284 | // Subprocess 1 decides to shut down CPU 1 without notifying DLB | ||
| 285 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(1, &sp1_mask); |
| 286 | |||
| 287 | // Subprocess 1 resets. CPU 1 should not be re-enabled | ||
| 288 | 2 | sp1_enabled = false; | |
| 289 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Disable_sp(handler1) == DLB_SUCCESS ); |
| 290 |
4/8✓ 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.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | assert( CPU_ISSET(0, &sp1_mask) && CPU_COUNT(&sp1_mask) == 1 ); |
| 291 | |||
| 292 | // Subprocess 2 recovers CPU 3 | ||
| 293 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpu_sp(handler2, 3) == DLB_SUCCESS ); |
| 294 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | assert( CPU_ISSET(3, &sp2_mask) ); |
| 295 | |||
| 296 | // Subprocess 1 enables DLB and CPU 1 | ||
| 297 | 2 | sp1_enabled = true; | |
| 298 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Enable_sp(handler1) == DLB_SUCCESS ); |
| 299 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(1, &sp1_mask); |
| 300 | } | ||
| 301 | |||
| 302 | /* MaxParallelism */ | ||
| 303 | { | ||
| 304 | // Subprocess 1 lends everything | ||
| 305 | 2 | CPU_ZERO(&sp1_mask); | |
| 306 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler1, &sys_mask) == DLB_SUCCESS ); |
| 307 | |||
| 308 | // Subprocess 2 borrows everything | ||
| 309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Borrow_sp(handler2) == DLB_SUCCESS ); |
| 310 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 4 |
| 311 | && CPU_ISSET(0, &sp2_mask) && CPU_ISSET(1, &sp2_mask) ); | ||
| 312 | |||
| 313 | // Subprocess 1 acquires its CPUs | ||
| 314 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpuMask_sp(handler1, &sp1_process_mask) == DLB_NOTED ); |
| 315 | |||
| 316 | // Subprocess 2 sets max_parallelism to 2 | ||
| 317 | 2 | DLB_SetMaxParallelism_sp(handler2, 2); | |
| 318 | |||
| 319 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_ASYNC) { |
| 320 | 1 | wait_for_async_completion(); | |
| 321 | } | ||
| 322 | |||
| 323 | // Both SPs should have their own CPUs | ||
| 324 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp1_mask) == 2 |
| 325 | && CPU_ISSET(0, &sp1_mask) && CPU_ISSET(1, &sp1_mask) ); | ||
| 326 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 327 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask) ); | ||
| 328 | |||
| 329 | // Subprocess 2 removes any previous requests | ||
| 330 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_ASYNC) { |
| 331 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpus_sp(handler2, 0) == DLB_SUCCESS ); |
| 332 | } | ||
| 333 | |||
| 334 | // Subprocess 1 lends everything | ||
| 335 | 2 | CPU_ZERO(&sp1_mask); | |
| 336 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler1, &sys_mask) == DLB_SUCCESS ); |
| 337 | |||
| 338 | // check that the previous lend did not change subprocess 2 mask | ||
| 339 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 340 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask) ); | ||
| 341 | |||
| 342 | // Subprocess 2 borrows everything (can't, max_parallelism still 2) | ||
| 343 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Borrow_sp(handler2) == DLB_NOUPDT ); |
| 344 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 345 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask) ); | ||
| 346 | |||
| 347 | // Subprocess 1 acquire its CPUs | ||
| 348 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpuMask_sp(handler1, &sp1_process_mask) == DLB_SUCCESS ); |
| 349 | |||
| 350 | // Subprocess 2 resets max_parallelism | ||
| 351 | 2 | DLB_UnsetMaxParallelism_sp(handler2); | |
| 352 | } | ||
| 353 | |||
| 354 | /* Test CpusInMask */ | ||
| 355 | { | ||
| 356 | // Construct a mask of only 1 CPU from subprocess 1, and all from subprocess 2 | ||
| 357 | cpu_set_t mask; | ||
| 358 | 2 | CPU_ZERO(&mask); | |
| 359 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_SET(0, &mask); |
| 360 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 2 times.
|
34 | CPU_OR(&mask, &mask, &sp2_mask); |
| 361 | |||
| 362 | // Subprocess 1 lends everything | ||
| 363 | 2 | CPU_ZERO(&sp1_mask); | |
| 364 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler1, &sys_mask) == DLB_SUCCESS ); |
| 365 | |||
| 366 | // Subprocess 2 lends 1 CPU | ||
| 367 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(2, &sp2_mask); |
| 368 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 2) == DLB_SUCCESS ); |
| 369 | |||
| 370 | // Subprocess 2 tries to acquire 1 CPU from the auxiliar mask [0,2,3] (it should prioritize [2,3]) | ||
| 371 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpusInMask_sp(handler2, 1, &mask) == DLB_SUCCESS ); |
| 372 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 373 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask)); | ||
| 374 | |||
| 375 | // Subprocess 2 lends 1 CPU, again | ||
| 376 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | CPU_CLR(2, &sp2_mask); |
| 377 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 2) == DLB_SUCCESS ); |
| 378 | |||
| 379 | // Subprocess 2 tries to acquire 4 CPUs from the auxiliar mask [0,2,3] | ||
| 380 | 2 | err = DLB_AcquireCpusInMask_sp(handler2, 4, &mask); | |
| 381 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | assert( mode == MODE_ASYNC ? err == DLB_NOTED : err == DLB_SUCCESS ); |
| 382 |
10/20✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 3 |
| 383 | && CPU_ISSET(0, &sp2_mask) && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask)); | ||
| 384 | |||
| 385 | // Subprocess 2 removes any previous requests | ||
| 386 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (mode == MODE_ASYNC) { |
| 387 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( DLB_AcquireCpus_sp(handler2, 0) == DLB_SUCCESS ); |
| 388 | } | ||
| 389 | |||
| 390 | // Subprocess 2 lends everything (0 first, and 2-3 later) | ||
| 391 | 2 | CPU_ZERO(&sp2_mask); | |
| 392 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpu_sp(handler2, 0) == DLB_SUCCESS ); |
| 393 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_LendCpuMask_sp(handler2, &sp2_process_mask) == DLB_SUCCESS ); |
| 394 | |||
| 395 | // Subprocess 2 borrows 1 CPU (twice) from the auxiliar mask [0,2,3] (it should prioritize [2,3]) | ||
| 396 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_BorrowCpusInMask_sp(handler2, 1, &mask) == DLB_SUCCESS ); |
| 397 |
4/8✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 1 && CPU_ISSET(2, &sp2_mask)); |
| 398 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_BorrowCpusInMask_sp(handler2, 1, &mask) == DLB_SUCCESS ); |
| 399 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 400 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask)); | ||
| 401 | |||
| 402 | // Subprocess 1 acquire its CPUs | ||
| 403 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_AcquireCpuMask_sp(handler1, &sp1_process_mask) == DLB_SUCCESS ); |
| 404 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp1_mask) == 2 |
| 405 | && CPU_ISSET(0, &sp1_mask) && CPU_ISSET(1, &sp1_mask)); | ||
| 406 | |||
| 407 | // Both SPs should have their own CPUs | ||
| 408 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp1_mask) == 2 |
| 409 | && CPU_ISSET(0, &sp1_mask) && CPU_ISSET(1, &sp1_mask) ); | ||
| 410 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
|
2 | assert( CPU_COUNT(&sp2_mask) == 2 |
| 411 | && CPU_ISSET(2, &sp2_mask) && CPU_ISSET(3, &sp2_mask) ); | ||
| 412 | } | ||
| 413 | |||
| 414 | // Finalize | ||
| 415 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Finalize_sp(handler1) == DLB_SUCCESS ); |
| 416 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | assert( DLB_Finalize_sp(handler2) == DLB_SUCCESS ); |
| 417 | |||
| 418 | 2 | mu_finalize(); | |
| 419 | |||
| 420 | 2 | return 0; | |
| 421 | } | ||
| 422 |