GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/cpuinfo_03.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 262 262 100.0%
Functions: 1 1 100.0%
Branches: 291 538 54.1%

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 #include "support/types.h"
29
30 #include <sched.h>
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include <stdio.h>
34 #include <assert.h>
35 #include <string.h>
36
37 /* array_cpuid_t */
38 #define ARRAY_T cpuid_t
39 #include "support/array_template.h"
40
41 /* array_cpuinfo_task_t */
42 #define ARRAY_T cpuinfo_task_t
43 #define ARRAY_KEY_T pid_t
44 #include "support/array_template.h"
45
46 // Basic checks for checking Borrow and Acquire features
47
48 2 int main( int argc, char **argv ) {
49 // This test needs at least room for 4 CPUs
50 enum { SYS_SIZE = 4 };
51 2 mu_init();
52 2 mu_testing_set_sys_size(SYS_SIZE);
53
54 // Initialize local masks to [1100] and [0011]
55 2 pid_t p1_pid = 111;
56 cpu_set_t p1_mask;
57 2 CPU_ZERO(&p1_mask);
58
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 CPU_SET(0, &p1_mask);
59
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 CPU_SET(1, &p1_mask);
60 2 pid_t p2_pid = 222;
61 cpu_set_t p2_mask;
62 2 CPU_ZERO(&p2_mask);
63
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 CPU_SET(2, &p2_mask);
64
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 CPU_SET(3, &p2_mask);
65 array_cpuinfo_task_t tasks;
66 2 array_cpuinfo_task_t_init(&tasks, SYS_SIZE);
67
68 // Init
69
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 );
70
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 );
71
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 );
72
73 // Initialize options and enable queues if needed
74 options_t options;
75 2 options_init(&options, NULL);
76 2 bool async = options.mode == MODE_ASYNC;
77
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
78 1 shmem_cpuinfo__enable_request_queues();
79 }
80 2 int64_t last_borrow_value = 0;
81
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 int64_t *last_borrow = async ? NULL : &last_borrow_value;
82 int requested_ncpus;
83
84 // Setup dummy priority CPUs
85 array_cpuid_t cpus_priority_array;
86 2 array_cpuid_t_init(&cpus_priority_array, SYS_SIZE);
87
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
10 for (int i=0; i<SYS_SIZE; ++i) array_cpuid_t_push(&cpus_priority_array, i);
88
89 int err;
90
91 /*** BorrowCpus test ***/
92 {
93 // Process 2 releases CPU 3
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
96
97 // Process 1 wants to BORROW up to 2 CPUs
98 2 requested_ncpus = 2;
99
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__borrow_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
100 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
101 last_borrow, &tasks) == DLB_SUCCESS );
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
103
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
104 && tasks.items[0].cpuid == 3
105 && tasks.items[0].action == ENABLE_CPU );
106 2 array_cpuinfo_task_t_clear(&tasks);
107
108 // Process 2 releases CPU 2
109
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 2, &tasks) == DLB_SUCCESS );
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
111
112 // Process 2 reclaims all
113
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED );
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 3 );
115
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
116 && tasks.items[0].cpuid == 2
117 && tasks.items[0].action == ENABLE_CPU );
118
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
119 && tasks.items[1].cpuid == 3
120 && tasks.items[1].action == DISABLE_CPU );
121
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
122 && tasks.items[2].cpuid == 3
123 && tasks.items[2].action == ENABLE_CPU );
124 2 array_cpuinfo_task_t_clear(&tasks);
125
126 // Process 1 releases CPU 3
127
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
128
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 6 taken 2 times.
✗ Branch 7 not taken.
2 assert( tasks.count == 1 && tasks.items[0].pid == p2_pid
129 && tasks.items[0].cpuid == 3 && tasks.items[0].action == ENABLE_CPU );
130 2 array_cpuinfo_task_t_clear(&tasks);
131 }
132
133 /*** AcquireCpus test ***/
134 {
135 // Process 2 releases CPU 3
136
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
138
139 // Process 1 wants to ACQUIRE 2 CPUs
140 2 requested_ncpus = 2;
141 2 err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
142 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
143 last_borrow, &tasks);
144
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_SUCCESS );
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
146
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
147 && tasks.items[0].cpuid == 3
148 && tasks.items[0].action == ENABLE_CPU );
149 2 array_cpuinfo_task_t_clear(&tasks);
150
151 // Process 2 releases CPU 2
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 2, &tasks) == DLB_SUCCESS );
153
7/12
✓ 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 not taken.
✓ Branch 11 taken 2 times.
2 assert( async ? tasks.count == 1 && tasks.items[0].pid == p1_pid
154 && tasks.items[0].cpuid == 2 && tasks.items[0].action == ENABLE_CPU
155 : tasks.count == 0 );
156 2 array_cpuinfo_task_t_clear(&tasks);
157
158 // If polling, process 1 needs to ask again for the last CPU
159
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (!async) {
160
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
161 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
162 last_borrow, &tasks) == DLB_SUCCESS );
163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
164
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
165 && tasks.items[0].cpuid == 2
166 && tasks.items[0].action == ENABLE_CPU );
167 1 array_cpuinfo_task_t_clear(&tasks);
168 }
169
170 // Process 2 reclaims all
171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED );
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 4 );
173
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
174 && tasks.items[0].cpuid == 2
175 && tasks.items[0].action == DISABLE_CPU );
176
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
177 && tasks.items[1].cpuid == 2
178 && tasks.items[1].action == ENABLE_CPU );
179
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
180 && tasks.items[2].cpuid == 3
181 && tasks.items[2].action == DISABLE_CPU );
182
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
183 && tasks.items[3].cpuid == 3
184 && tasks.items[3].action == ENABLE_CPU );
185 2 array_cpuinfo_task_t_clear(&tasks);
186
187 // Process 1 releases CPU 2 and 3
188
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 2, &tasks) == DLB_SUCCESS );
189
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 6 taken 2 times.
✗ Branch 7 not taken.
2 assert( tasks.count == 1 && tasks.items[0].pid == p2_pid
190 && tasks.items[0].cpuid == 2 && tasks.items[0].action == ENABLE_CPU );
191 2 array_cpuinfo_task_t_clear(&tasks);
192
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
193
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 6 taken 2 times.
✗ Branch 7 not taken.
2 assert( tasks.count == 1 && tasks.items[0].pid == p2_pid
194 && tasks.items[0].cpuid == 3 && tasks.items[0].action == ENABLE_CPU );
195 2 array_cpuinfo_task_t_clear(&tasks);
196 }
197
198 /*** AcquireCpus with late reply ***/
199 {
200 // Process 2 releases CPU 3
201
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
203
204 // Process 1 wants to ACQUIRE 2 CPUs
205 2 requested_ncpus = 2;
206 2 err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
207 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
208 last_borrow, &tasks);
209
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_SUCCESS );
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
211
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
212 && tasks.items[0].cpuid == 3
213 && tasks.items[0].action == ENABLE_CPU );
214 2 array_cpuinfo_task_t_clear(&tasks);
215
216 // Process 1 wants to cancel previous request
217 2 shmem_cpuinfo__remove_requests(p1_pid);
218
219 // Process 1 releases CPU 3
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
222
223 // Process 2 reclaims all
224
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_SUCCESS );
225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
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[0].pid == p2_pid
227 && tasks.items[0].cpuid == 3
228 && tasks.items[0].action == ENABLE_CPU );
229 2 array_cpuinfo_task_t_clear(&tasks);
230 }
231
232 /*** AcquireCpus one by one with some CPUs already reclaimed ***/
233 {
234 // Process 1 releases CPUs 0 and 1
235
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS );
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
237
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 1, &tasks) == DLB_SUCCESS );
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
239
240 // Process 2 acquires CPU 0
241
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS );
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
243
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
244 && tasks.items[0].cpuid == 0
245 && tasks.items[0].action == ENABLE_CPU );
246 2 array_cpuinfo_task_t_clear(&tasks);
247
248 // Process 1 acquires 1 CPU (acquires CPU 1 first, currently idle)
249 2 requested_ncpus = 1;
250
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
251 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
252 last_borrow, &tasks) == DLB_SUCCESS );
253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
254
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
255 && tasks.items[0].cpuid == 1
256 && tasks.items[0].action == ENABLE_CPU );
257 2 array_cpuinfo_task_t_clear(&tasks);
258
259 // Process 1 acquires 1 CPU (reclaims CPU 0)
260 2 requested_ncpus = 1;
261
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
262 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
263 last_borrow, &tasks) == DLB_NOTED );
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
265
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
266 && tasks.items[0].cpuid == 0
267 && tasks.items[0].action == DISABLE_CPU );
268
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
269 && tasks.items[1].cpuid == 0
270 && tasks.items[1].action == ENABLE_CPU );
271 2 array_cpuinfo_task_t_clear(&tasks);
272
273 // Process 2 returns CPU 0
274
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS );
275
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 6 taken 2 times.
✗ Branch 7 not taken.
2 assert( tasks.count == 1 && tasks.items[0].pid == p1_pid
276 && tasks.items[0].cpuid == 0 && tasks.items[0].action == ENABLE_CPU );
277 2 array_cpuinfo_task_t_clear(&tasks);
278 }
279
280 /*** AcquireCpus of CPUs not in the priority array ***/
281 {
282 // Process 2 acquires 1 CPU, but only allowing CPUs [2, 3, 1]
283 2 array_cpuid_t_clear(&cpus_priority_array);
284 2 array_cpuid_t_push(&cpus_priority_array, 2);
285 2 array_cpuid_t_push(&cpus_priority_array, 3);
286 2 array_cpuid_t_push(&cpus_priority_array, 1);
287 2 requested_ncpus = 1;
288 2 err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus,
289 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
290 last_borrow, &tasks);
291
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 );
292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
293
294 // Process 1 releases CPU 0
295
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS );
296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
297
298 // If polling, process 2 needs to ask again (no update because CPU 0 is not eligible)
299
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (!async) {
300 1 requested_ncpus = 1;
301
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus,
302 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
303 last_borrow, &tasks) == DLB_NOUPDT );
304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
305 }
306
307 // Process 1 acquires CPU 0 (currently idle)
308
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS );
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
310
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
311 && tasks.items[0].cpuid == 0
312 && tasks.items[0].action == ENABLE_CPU );
313 2 array_cpuinfo_task_t_clear(&tasks);
314
315 // Process 1 releases CPU 1
316
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 1, &tasks) == DLB_SUCCESS );
317
7/12
✓ 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 not taken.
✓ Branch 11 taken 2 times.
2 assert( async ? tasks.count == 1 && tasks.items[0].pid == p2_pid
318 && tasks.items[0].cpuid == 1 && tasks.items[0].action == ENABLE_CPU
319 : tasks.count == 0 );
320 2 array_cpuinfo_task_t_clear(&tasks);
321
322 // If polling, process 2 needs to ask again
323
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (!async) {
324 1 requested_ncpus = 1;
325
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus,
326 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
327 last_borrow, &tasks) == DLB_SUCCESS );
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
329
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
330 && tasks.items[0].cpuid == 1
331 && tasks.items[0].action == ENABLE_CPU );
332 1 array_cpuinfo_task_t_clear(&tasks);
333 }
334
335 // Process 2 releases CPU 1
336
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 1, &tasks) == DLB_SUCCESS );
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
338
339 // 1 acquires CPU 1 (currently idle)
340
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 1, &tasks) == DLB_SUCCESS );
341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
342
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
343 && tasks.items[0].cpuid == 1
344 && tasks.items[0].action == ENABLE_CPU );
345 2 array_cpuinfo_task_t_clear(&tasks);
346 }
347
348 // Finalize
349
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
350
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
351
352 /* Test lend post mortem feature */
353 {
354 // Reset cpu priority
355 2 array_cpuid_t_clear(&cpus_priority_array);
356
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
10 for (int i=0; i<SYS_SIZE; ++i) array_cpuid_t_push(&cpus_priority_array, i);
357
358 // Set up fake spd to set post-mortem option
359 subprocess_descriptor_t spd;
360 2 spd.options.debug_opts = DBG_LPOSTMORTEM;
361 2 spd_enter_dlb(&spd);
362
363 // Initialize
364
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 );
365
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 );
366
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) { shmem_cpuinfo__enable_request_queues(); }
367
368 // P1 finalizes
369
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
370
371 // P2 borrows P1 CPUs
372
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__borrow_ncpus_from_cpu_subset(p2_pid, NULL /* requested_ncpus */,
373 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
374 last_borrow, &tasks) == DLB_SUCCESS );
375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
376
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
377 && tasks.items[0].cpuid == 0
378 && tasks.items[0].action == ENABLE_CPU );
379
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
380 && tasks.items[1].cpuid == 1
381 && tasks.items[1].action == ENABLE_CPU );
382 2 array_cpuinfo_task_t_clear(&tasks);
383
384 // P2 finalizes
385
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
386 }
387
388 /* Test early finalization with pending actions */
389 {
390 // Reset cpu priority
391 2 array_cpuid_t_clear(&cpus_priority_array);
392
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
10 for (int i=0; i<SYS_SIZE; ++i) array_cpuid_t_push(&cpus_priority_array, i);
393
394 // Set up fake spd to set post-mortem option
395 subprocess_descriptor_t spd;
396 2 spd.options.debug_opts = DBG_LPOSTMORTEM;
397 2 spd_enter_dlb(&spd);
398
399 // Initialize
400
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 );
401
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 );
402
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) { shmem_cpuinfo__enable_request_queues(); }
403
404 // P2 asks for as many CPUs as SYS_SIZE
405 2 requested_ncpus = SYS_SIZE;
406 2 err = shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus,
407 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
408 last_borrow, &tasks);
409
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 );
410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
411
412 // P1 finalizes
413
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS );
414
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 2 );
416
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
417 && tasks.items[0].cpuid == 0
418 && tasks.items[0].action == ENABLE_CPU );
419
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
420 && tasks.items[1].cpuid == 1
421 && tasks.items[1].action == ENABLE_CPU );
422 1 array_cpuinfo_task_t_clear(&tasks);
423 } else {
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
425 }
426
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
427
428 // If polling, P2 needs to ask again for SYS_SIZE CPUs
429
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (!async) {
430 1 requested_ncpus = SYS_SIZE;
431
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus,
432 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
433 last_borrow, &tasks) == DLB_SUCCESS );
434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 2 );
435
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
436 && tasks.items[0].cpuid == 0
437 && tasks.items[0].action == ENABLE_CPU );
438
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
439 && tasks.items[1].cpuid == 1
440 && tasks.items[1].action == ENABLE_CPU );
441 1 array_cpuinfo_task_t_clear(&tasks);
442 }
443
444 // P2 finalizes
445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__deregister(p2_pid, &tasks) == DLB_SUCCESS );
446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
447
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
448 }
449
450 /* Test asynchronous acquire ncpus with disabled CPUs */
451
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
452
453 // Reset cpu priority
454 1 array_cpuid_t_clear(&cpus_priority_array);
455
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
5 for (int i=0; i<SYS_SIZE; ++i) array_cpuid_t_push(&cpus_priority_array, i);
456
457 // Set up fake spd with default options
458 1 subprocess_descriptor_t spd = {};
459 1 spd.options.lewi_respect_cpuset = true;
460 1 spd.options.debug_opts = DBG_CLEAR;
461 1 spd_enter_dlb(&spd);
462
463 // Initialize P1 with an empty mask
464 cpu_set_t p1_empty_mask;
465 1 CPU_ZERO(&p1_empty_mask);
466
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p1_pid, 0, &p1_empty_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
467 1 shmem_cpuinfo__enable_request_queues();
468
469 // P1 asks for all CPUs
470 1 requested_ncpus = DLB_MAX_CPUS;
471
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
472 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
473 last_borrow, &tasks) == DLB_NOTED );
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( requested_ncpus == DLB_MAX_CPUS );
476
477 // P2 initializes
478 cpu_set_t p2_full_mask;
479 1 mu_get_system_mask(&p2_full_mask);
480
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p2_pid, 0, &p2_full_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
481
482 // P2 lends CPU 3
483
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
485
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
486 && tasks.items[0].cpuid == 3
487 && tasks.items[0].action == ENABLE_CPU );
488 1 array_cpuinfo_task_t_clear(&tasks);
489
490 // P2 reclaims CPU 3
491
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED );
492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 2 );
493
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
494 && tasks.items[0].cpuid == 3
495 && tasks.items[0].action == DISABLE_CPU );
496
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
497 && tasks.items[1].cpuid == 3
498 && tasks.items[1].action == ENABLE_CPU );
499 1 array_cpuinfo_task_t_clear(&tasks);
500
501 // P1 returns
502 1 shmem_cpuinfo__return_async_cpu(p1_pid, 3);
503
504 // P2 lends again CPU 3
505
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
507
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
508 && tasks.items[0].cpuid == 3
509 && tasks.items[0].action == ENABLE_CPU );
510 1 array_cpuinfo_task_t_clear(&tasks);
511
512 // Finalize
513
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS );
514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
515
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
516
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__deregister(p2_pid, &tasks) == DLB_SUCCESS );
517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
518
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
519 && tasks.items[0].cpuid == 3
520 && tasks.items[0].action == ENABLE_CPU );
521 1 array_cpuinfo_task_t_clear(&tasks);
522
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
523 }
524
525 /* Test asynchronous acquire mask with disabled CPUs */
526
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
527
528 // Reset cpu priority
529 1 array_cpuid_t_clear(&cpus_priority_array);
530
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
5 for (int i=0; i<SYS_SIZE; ++i) array_cpuid_t_push(&cpus_priority_array, i);
531
532 // Set up fake spd with default options
533 1 subprocess_descriptor_t spd = {};
534 1 spd.options.lewi_respect_cpuset = true;
535 1 spd.options.debug_opts = DBG_CLEAR;
536 1 spd_enter_dlb(&spd);
537
538 // Initialize P1 with an empty mask
539 cpu_set_t p1_empty_mask;
540 1 CPU_ZERO(&p1_empty_mask);
541
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p1_pid, 0, &p1_empty_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
542 1 shmem_cpuinfo__enable_request_queues();
543
544 // P1 asks for all CPUs (passing NULL as requested_ncpus and having all CPUs in
545 // cpus_priority_array is equivalent for asking for a full mask)
546
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 */,
547 &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */,
548 last_borrow, &tasks) == DLB_NOTED );
549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( requested_ncpus == DLB_MAX_CPUS );
551
552 // P2 initializes
553 cpu_set_t p2_full_mask;
554 1 mu_get_system_mask(&p2_full_mask);
555
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__init(p2_pid, 0, &p2_full_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
556
557 // P2 lends CPU 3
558
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
560
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
561 && tasks.items[0].cpuid == 3
562 && tasks.items[0].action == ENABLE_CPU );
563 1 array_cpuinfo_task_t_clear(&tasks);
564
565 // P2 reclaims CPU 3
566
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_NOTED );
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 2 );
568
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
569 && tasks.items[0].cpuid == 3
570 && tasks.items[0].action == DISABLE_CPU );
571
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
572 && tasks.items[1].cpuid == 3
573 && tasks.items[1].action == ENABLE_CPU );
574 1 array_cpuinfo_task_t_clear(&tasks);
575
576 // P1 returns
577 1 shmem_cpuinfo__return_async_cpu(p1_pid, 3);
578
579 // P2 lends again CPU 3
580
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
582
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
583 && tasks.items[0].cpuid == 3
584 && tasks.items[0].action == ENABLE_CPU );
585 1 array_cpuinfo_task_t_clear(&tasks);
586
587 // Finalize
588
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS );
589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
590
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
591
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__deregister(p2_pid, &tasks) == DLB_SUCCESS );
592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
593
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
594 && tasks.items[0].cpuid == 3
595 && tasks.items[0].action == ENABLE_CPU );
596 1 array_cpuinfo_task_t_clear(&tasks);
597
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
598 }
599
600 2 mu_finalize();
601
602 2 return 0;
603 }
604