GCC Code Coverage Report


Directory: ./
File: tests/unit/02_shmem/cpuinfo_01.c
Date: 2026-12-01 10:07:21
Exec Total Coverage
Lines: 320 320 100.0%
Functions: 1 1 100.0%
Branches: 429 816 52.6%

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
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
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 mu_parse_mask("0-1", &p1_mask);
57 2 pid_t p2_pid = 222;
58 cpu_set_t p2_mask;
59 2 mu_parse_mask("2-3", &p2_mask);
60 array_cpuinfo_task_t tasks;
61 2 array_cpuinfo_task_t_init(&tasks, SYS_SIZE);
62
63 // Init
64
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 );
65
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 );
66
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 );
67
68 // Get pointers to the shmem auxiliary cpu sets
69 2 const cpu_set_t *free_cpus = shmem_cpuinfo_testing__get_free_cpu_set();
70 2 const cpu_set_t *occupied_cores = shmem_cpuinfo_testing__get_occupied_core_set();
71
72 // Initialize options and enable queues if needed
73 options_t options;
74 2 options_init(&options, NULL);
75 2 bool async = options.mode == MODE_ASYNC;
76 2 bool polling = options.mode == MODE_POLLING;
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
81 int err;
82
83 /*** Successful ping-pong ***/
84 {
85 // Process 1 wants CPU 3
86 2 err = shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks);
87
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 );
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
90
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
91
92 // Process 2 releases CPU 3
93
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
94
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
96
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
97 && tasks.items[0].cpuid == 3
98 && tasks.items[0].action == ENABLE_CPU );
99 1 array_cpuinfo_task_t_clear(&tasks);
100
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
101
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
102 } else {
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
104
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(free_cpus) == 1 && CPU_ISSET(3, free_cpus) );
105
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
106 }
107
108 // If polling, process 1 needs to ask again for CPU 3
109
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
110
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
112
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
113 && tasks.items[0].cpuid == 3
114 && tasks.items[0].action == ENABLE_CPU );
115 1 array_cpuinfo_task_t_clear(&tasks);
116
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
117
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
118 }
119
120 // Process 1 cannot reclaim CPU 3
121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_cpu(p1_pid, 3, &tasks) == DLB_ERR_PERM );
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
123
124 // Process 2 reclaims CPU 3
125
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_cpu(p2_pid, 3, &tasks) == DLB_NOTED );
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
127
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
128 && tasks.items[0].cpuid == 3
129 && tasks.items[0].action == DISABLE_CPU );
130
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
131 && tasks.items[1].cpuid == 3
132 && tasks.items[1].action == ENABLE_CPU );
133 2 array_cpuinfo_task_t_clear(&tasks);
134
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
135
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(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
136
137 // Process 1 returns CPU 3
138
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
139
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
141
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
142 && tasks.items[0].cpuid == 3
143 && tasks.items[0].action == DISABLE_CPU );
144 1 array_cpuinfo_task_t_clear(&tasks);
145 } else {
146 1 shmem_cpuinfo__return_async_cpu(p1_pid, 3);
147 }
148
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
150
151 // Process 2 releases CPU 3 again
152
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
153
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
155
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
156 && tasks.items[0].cpuid == 3
157 && tasks.items[0].action == ENABLE_CPU );
158 1 array_cpuinfo_task_t_clear(&tasks);
159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
160
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
161 } else {
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
163
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(free_cpus) == 1 && CPU_ISSET(3, free_cpus) );
164
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
165 }
166
167 // If polling, process 1 needs to ask again for CPU 3
168
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
169
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
171
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
172 && tasks.items[0].cpuid == 3
173 && tasks.items[0].action == ENABLE_CPU );
174 1 array_cpuinfo_task_t_clear(&tasks);
175
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
176
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
177 }
178
179 // Process 2 reclaims CPU 3 again
180
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_cpu(p2_pid, 3, &tasks) == DLB_NOTED );
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
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[0].pid == p1_pid
183 && tasks.items[0].cpuid == 3
184 && tasks.items[0].action == DISABLE_CPU );
185
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
186 && tasks.items[1].cpuid == 3
187 && tasks.items[1].action == ENABLE_CPU );
188 2 array_cpuinfo_task_t_clear(&tasks);
189
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
190
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(occupied_cores) == 1 && CPU_ISSET(3, occupied_cores) );
191
192 // Process 1 returns CPU 3
193
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
194
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
196
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
197 && tasks.items[0].cpuid == 3
198 && tasks.items[0].action == DISABLE_CPU );
199 1 array_cpuinfo_task_t_clear(&tasks);
200 } else {
201 1 shmem_cpuinfo__return_async_cpu(p1_pid, 3);
202 }
203
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
204
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
205
206 // Process removes petition of CPU 3
207
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
209
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
210
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
211
212 // Process 2 releases CPU 3, checks no victim and reclaims
213
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
215
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(free_cpus) == 1 && CPU_ISSET(3, free_cpus) );
216
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
217
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_all(p2_pid, &tasks) == DLB_SUCCESS );
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
219
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
220 && tasks.items[0].cpuid == 3
221 && tasks.items[0].action == ENABLE_CPU );
222 2 array_cpuinfo_task_t_clear(&tasks);
223
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
224
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
225 }
226
227
228 /*** Late reply ***/
229 {
230 // Process 1 wants CPU 3
231 2 err = shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks);
232
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 );
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
234
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
235
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
236
237 // Process 1 no longer wants CPU 3
238
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
240
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
241
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
242
243 // Process 2 releases CPU 3
244
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
246
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(free_cpus) == 1 && CPU_ISSET(3, free_cpus) );
247
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
248
249 // Process 2 reclaims CPU 3
250
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
251
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
252
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
253 && tasks.items[0].cpuid == 3
254 && tasks.items[0].action == ENABLE_CPU );
255 2 array_cpuinfo_task_t_clear(&tasks);
256
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
257
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
258 }
259
260 /*** MaxParallelism ***/
261 {
262 // Process 1 lends CPU 0
263
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 0, &tasks) == DLB_SUCCESS );
264
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
265
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(free_cpus) == 1 && CPU_ISSET(0, free_cpus) );
266
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
267
268 // Process 2 acquires CPU 0
269
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS );
270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
271
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
272 && tasks.items[0].cpuid == 0
273 && tasks.items[0].action == ENABLE_CPU );
274 2 array_cpuinfo_task_t_clear(&tasks);
275
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
276
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(occupied_cores) == 1 && CPU_ISSET(0, occupied_cores) );
277
278 // Process 2 sets max_parallelism to 1 (CPUs 0 and 3 should be removed)
279
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 1, &tasks) == DLB_SUCCESS );
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
281
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
282 && tasks.items[0].cpuid == 3
283 && tasks.items[0].action == DISABLE_CPU );
284
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
285 && tasks.items[1].cpuid == 0
286 && tasks.items[1].action == DISABLE_CPU );
287 2 array_cpuinfo_task_t_clear(&tasks);
288
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(free_cpus) == 2
289 && CPU_ISSET(0, free_cpus)
290 && CPU_ISSET(3, free_cpus) );
291
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
292
293 // Process 2 acquires CPU 3
294
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
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[0].pid == p2_pid
297 && tasks.items[0].cpuid == 3
298 && tasks.items[0].action == ENABLE_CPU );
299 2 array_cpuinfo_task_t_clear(&tasks);
300
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(free_cpus) == 1 && CPU_ISSET(0, free_cpus) );
301
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
302
303 // Process 2 sets max_parallelism to 2 (no CPU should be removed)
304
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__update_max_parallelism(p2_pid, 2, &tasks) == DLB_SUCCESS );
305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
306
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(free_cpus) == 1 && CPU_ISSET(0, free_cpus) );
307
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
308 }
309
310 /*** Errors ***/
311
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__return_cpu(p1_pid, 3, &tasks) == DLB_ERR_PERM );
312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
313
314 // Finalize
315
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
316
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
317
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_ERR_NOSHMEM );
318
319 /* Test lend post mortem feature */
320 {
321 // Set up fake spd to set post-mortem option
322 subprocess_descriptor_t spd;
323 2 spd.options.debug_opts = DBG_LPOSTMORTEM;
324 2 spd_enter_dlb(&spd);
325
326 // Initialize
327
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 );
328
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 );
329
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) { shmem_cpuinfo__enable_request_queues(); }
330
331 // Update pointers of the new shmem
332 2 free_cpus = shmem_cpuinfo_testing__get_free_cpu_set();
333 2 occupied_cores = shmem_cpuinfo_testing__get_occupied_core_set();
334
335 // P1 finalizes
336
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( CPU_EQUAL(free_cpus, &p1_mask) );
338
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
339
340 // P2 acquires P1 CPUs
341
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS );
342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
343
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
344 && tasks.items[0].cpuid == 0
345 && tasks.items[0].action == ENABLE_CPU );
346 2 array_cpuinfo_task_t_clear(&tasks);
347
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 1, &tasks) == DLB_SUCCESS );
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
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 == p2_pid
350 && tasks.items[0].cpuid == 1
351 && tasks.items[0].action == ENABLE_CPU );
352 2 array_cpuinfo_task_t_clear(&tasks);
353
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
354
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
355
356 // P2 may poll for reclaimed resources, no action for public CPUs
357
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
358
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_all(p2_pid, &tasks) == DLB_NOUPDT );
359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
360
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu_mask(p2_pid, &p1_mask, &tasks) == DLB_NOUPDT );
361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
362
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu(p2_pid, 0, &tasks) == DLB_NOUPDT );
363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
364 }
365
366 // P2 finalizes
367
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
368 }
369
370 /* Test respect-cpuset=no feature */
371 {
372 // Set up fake spd to set respect-cpuset option
373 subprocess_descriptor_t spd;
374 2 spd.options.lewi_respect_cpuset = false;
375 2 spd_enter_dlb(&spd);
376
377 // Initialize
378 cpu_set_t reduced_p1_mask;
379 2 mu_parse_mask("0", &reduced_p1_mask);
380
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__init(p1_pid, 0, &reduced_p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
381 cpu_set_t reduced_p2_mask;
382 2 mu_parse_mask("2", &reduced_p2_mask);
383
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__init(p2_pid, 0, &reduced_p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS );
384
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) { shmem_cpuinfo__enable_request_queues(); }
385
386 // Update pointers of the new shmem
387 2 free_cpus = shmem_cpuinfo_testing__get_free_cpu_set();
388 2 occupied_cores = shmem_cpuinfo_testing__get_occupied_core_set();
389
390 // Not yet registered CPUs count as free CPUs
391
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(free_cpus) == 2
392 && CPU_ISSET(1, free_cpus)
393 && CPU_ISSET(3, free_cpus) );
394
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
395
396 // P1 borrows CPU 3
397
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__borrow_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
399
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
400 && tasks.items[0].cpuid == 3
401 && tasks.items[0].action == ENABLE_CPU );
402 2 array_cpuinfo_task_t_clear(&tasks);
403
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(free_cpus) == 1 && CPU_ISSET(1, free_cpus) );
404
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
405
406 // P1 may poll for reclaimed resources, no action for public CPUs
407
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
408
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_all(p1_pid, &tasks) == DLB_NOUPDT );
409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu_mask(p1_pid, &p2_mask, &tasks) == DLB_NOUPDT );
411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
412
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__return_cpu(p1_pid, 3, &tasks) == DLB_NOUPDT );
413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
414 }
415
416 // P1 lends CPU 3
417
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
419
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(free_cpus) == 2
420 && CPU_ISSET(1, free_cpus)
421 && CPU_ISSET(3, free_cpus) );
422
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
423
424 // P1 borrows CPU 3 from cpuset
425 2 int requested_ncpus = 1;
426 array_cpuid_t cpus_priority_array;
427 2 array_cpuid_t_init(&cpus_priority_array, SYS_SIZE);
428 2 array_cpuid_t_push(&cpus_priority_array, 3);
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__borrow_ncpus_from_cpu_subset(p1_pid, &requested_ncpus,
430 &cpus_priority_array, LEWI_AFFINITY_AUTO,
431 /* max_parallelism */ 0, /* last_borrow */ NULL, &tasks)
432 == DLB_SUCCESS );
433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
434
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
435 && tasks.items[0].cpuid == 3
436 && tasks.items[0].action == ENABLE_CPU );
437 2 array_cpuinfo_task_t_clear(&tasks);
438
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(free_cpus) == 1 && CPU_ISSET(1, free_cpus) );
439
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
440
441 // P1 lends CPU 3
442
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
444
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(free_cpus) == 2
445 && CPU_ISSET(1, free_cpus)
446 && CPU_ISSET(3, free_cpus) );
447
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
448
449 // P1 aquires CPU 3
450
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
452
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
453 && tasks.items[0].cpuid == 3
454 && tasks.items[0].action == ENABLE_CPU );
455 2 array_cpuinfo_task_t_clear(&tasks);
456
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(free_cpus) == 1 && CPU_ISSET(1, free_cpus) );
457
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
458
459 // P2 wants to aquire full mask, acquires [1], [2-3] are pending
460 2 int requested_cpus = 3;
461 2 array_cpuid_t_clear(&cpus_priority_array);
462 2 array_cpuid_t_push(&cpus_priority_array, 2);
463 2 array_cpuid_t_push(&cpus_priority_array, 3);
464 2 array_cpuid_t_push(&cpus_priority_array, 0);
465 2 array_cpuid_t_push(&cpus_priority_array, 1);
466
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_cpus,
467 &cpus_priority_array, LEWI_AFFINITY_AUTO,
468 /* max_parallelism */ 0, /* last_borrow */ NULL, &tasks)
469 == async ? DLB_NOTED : DLB_SUCCESS );
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
471
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
472 && tasks.items[0].cpuid == 1
473 && tasks.items[0].action == ENABLE_CPU );
474 2 array_cpuinfo_task_t_clear(&tasks);
475
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
476
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
477
478 // P1 lends CPU 3
479
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p1_pid, 3, &tasks) == DLB_SUCCESS );
480
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
482
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
483 && tasks.items[0].cpuid == 3
484 && tasks.items[0].action == ENABLE_CPU );
485 1 array_cpuinfo_task_t_clear(&tasks);
486
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
487
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
488 } else {
489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 0 );
490
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 assert( CPU_COUNT(free_cpus) == 1 && CPU_ISSET(3, free_cpus) );
491
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
492 }
493
494 // If polling, process 2 needs to ask again for CPU 3
495
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
496
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 3, &tasks) == DLB_SUCCESS );
497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
498
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
499 && tasks.items[0].cpuid == 3
500 && tasks.items[0].action == ENABLE_CPU );
501 1 array_cpuinfo_task_t_clear(&tasks);
502
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
503
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
504 }
505
506 // Finalize
507
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
508
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
509 }
510
511
512 /* Test early finalization with pending actions */
513 {
514 // Set up fake spd to set post-mortem option
515 subprocess_descriptor_t spd;
516 2 spd.options.debug_opts = DBG_LPOSTMORTEM;
517 2 spd_enter_dlb(&spd);
518
519 // Initialize
520
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 );
521
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 );
522
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) { shmem_cpuinfo__enable_request_queues(); }
523
524 // Update pointers of the new shmem
525 2 free_cpus = shmem_cpuinfo_testing__get_free_cpu_set();
526 2 occupied_cores = shmem_cpuinfo_testing__get_occupied_core_set();
527
528 // P2 lends CPU 2
529
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__lend_cpu(p2_pid, 2, &tasks) == DLB_SUCCESS );
530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
531
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(free_cpus) == 1 && CPU_ISSET(2, free_cpus) );
532
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(occupied_cores) == 0 );
533
534 // P1 acquires CPU 2
535
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__acquire_cpu(p1_pid, 2, &tasks) == DLB_SUCCESS );
536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 1 );
537
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
538 && tasks.items[0].cpuid == 2
539 && tasks.items[0].action == ENABLE_CPU );
540 2 array_cpuinfo_task_t_clear(&tasks);
541
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
542
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(occupied_cores) == 1 && CPU_ISSET(2, occupied_cores) );
543
544 // P2 reclaims CPU 2 and requests CPUs 0 and 1
545
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__reclaim_cpu(p2_pid, 2, &tasks) == DLB_NOTED );
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 2 );
547
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
548 && tasks.items[0].cpuid == 2
549 && tasks.items[0].action == DISABLE_CPU );
550
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
551 && tasks.items[1].cpuid == 2
552 && tasks.items[1].action == ENABLE_CPU );
553 2 array_cpuinfo_task_t_clear(&tasks);
554 2 err = shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks);
555
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 );
556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
557 2 err = shmem_cpuinfo__acquire_cpu(p2_pid, 1, &tasks);
558
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 );
559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
560
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( CPU_COUNT(free_cpus) == 0 );
561
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(occupied_cores) == 1 && CPU_ISSET(2, occupied_cores) );
562
563 // P1 finalizes
564
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS );
565
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (async) {
566 // P2 gets CPUs 0-2
567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 3 );
568
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; ++i) {
569
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 assert( tasks.items[i].pid == p2_pid
570 && tasks.items[i].cpuid == i
571 && tasks.items[i].action == ENABLE_CPU );
572 }
573
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
574
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
575 } else {
576 // P2 gets CPU 2
577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
578
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
579 && tasks.items[0].cpuid == 2
580 && tasks.items[0].action == ENABLE_CPU );
581
7/14
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
1 assert( CPU_COUNT(free_cpus) == 2
582 && CPU_ISSET(0, free_cpus)
583 && CPU_ISSET(1, free_cpus) );
584
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
585 }
586 2 array_cpuinfo_task_t_clear(&tasks);
587
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
588
589 // If polling, P2 needs to ask again for CPUs 0-2
590
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (polling) {
591
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__check_cpu_availability(p2_pid, 2) == DLB_SUCCESS );
592
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 0, &tasks) == DLB_SUCCESS );
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
594
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
595 && tasks.items[0].cpuid == 0
596 && tasks.items[0].action == ENABLE_CPU );
597 1 array_cpuinfo_task_t_clear(&tasks);
598
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( shmem_cpuinfo__acquire_cpu(p2_pid, 1, &tasks) == DLB_SUCCESS );
599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert( tasks.count == 1 );
600
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
601 && tasks.items[0].cpuid == 1
602 && tasks.items[0].action == ENABLE_CPU );
603 1 array_cpuinfo_task_t_clear(&tasks);
604
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(free_cpus) == 0 );
605
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 assert( CPU_COUNT(occupied_cores) == 0 );
606 }
607
608 // P2 finalizes
609
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__deregister(p1_pid, &tasks) == DLB_SUCCESS );
610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 assert( tasks.count == 0 );
611
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS );
612 }
613
614 2 mu_finalize();
615
616 2 return 0;
617 }
618