GCC Code Coverage Report


Directory: src/
File: src/apis/DLB_interface_sp.c
Date: 2025-11-21 10:34:40
Exec Total Coverage
Lines: 118 121 97.5%
Functions: 34 35 97.1%
Branches: 2 2 100.0%

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 "apis/dlb_sp.h"
21
22 #include "LB_core/spd.h"
23 #include "LB_core/DLB_kernel.h"
24 #include "support/atomic.h"
25 #include "support/dlb_common.h"
26
27 #include <stdlib.h>
28 #include <unistd.h>
29
30 32 static int get_atomic_spid(void) {
31 // pidmax is usually 32k, spid is concatenated in order to keep the pid in the first 5 digits
32 enum { SPID_INCREMENT = 100000 };
33 static atomic_int spid_seed = 0;
34 32 return DLB_ATOMIC_ADD_FETCH_RLX(&spid_seed, SPID_INCREMENT) + getpid();
35 }
36
37
38 /* Status */
39
40 DLB_EXPORT_SYMBOL
41 32 dlb_handler_t DLB_Init_sp(int ncpus, const_dlb_cpu_set_t mask, const char *dlb_args) {
42 32 subprocess_descriptor_t *spd = malloc(sizeof(subprocess_descriptor_t));
43 32 spd->dlb_initialized = true;
44 32 spd_register(spd);
45 32 spd_enter_dlb(spd);
46 32 int error = Initialize(spd, get_atomic_spid(), ncpus, mask, dlb_args);
47
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 30 times.
32 if (error != DLB_SUCCESS) {
48 2 spd_unregister(spd);
49 2 free(spd);
50 2 return NULL;
51 }
52 30 return spd;
53 }
54
55 DLB_EXPORT_SYMBOL
56 30 int DLB_Finalize_sp(dlb_handler_t handler) {
57 30 spd_enter_dlb(handler);
58 30 int error = Finish(handler);
59 30 spd_unregister(handler);
60 30 free(handler);
61 30 return error;
62 }
63
64 DLB_EXPORT_SYMBOL
65 3 int DLB_Enable_sp(dlb_handler_t handler) {
66 3 spd_enter_dlb(handler);
67 3 return set_lewi_enabled(handler, true);
68 }
69
70 DLB_EXPORT_SYMBOL
71 3 int DLB_Disable_sp(dlb_handler_t handler) {
72 3 spd_enter_dlb(handler);
73 3 return set_lewi_enabled(handler, false);
74 }
75
76 DLB_EXPORT_SYMBOL
77 3 int DLB_SetMaxParallelism_sp(dlb_handler_t handler, int max) {
78 3 spd_enter_dlb(handler);
79 3 return set_max_parallelism(handler, max);
80 }
81
82 DLB_EXPORT_SYMBOL
83 2 int DLB_UnsetMaxParallelism_sp(dlb_handler_t handler) {
84 2 spd_enter_dlb(handler);
85 2 return unset_max_parallelism(handler);
86 }
87
88
89 /* Callbacks */
90
91 DLB_EXPORT_SYMBOL
92 22 int DLB_CallbackSet_sp(dlb_handler_t handler, dlb_callbacks_t which,
93 dlb_callback_t callback, void *arg) {
94 22 spd_enter_dlb(handler);
95 22 pm_interface_t *pm = &((subprocess_descriptor_t*)handler)->pm;
96 22 return pm_callback_set(pm, which, callback, arg);
97 }
98
99 DLB_EXPORT_SYMBOL
100 1 int DLB_CallbackGet_sp(dlb_handler_t handler, dlb_callbacks_t which,
101 dlb_callback_t *callback, void **arg) {
102 1 spd_enter_dlb(handler);
103 1 const pm_interface_t *pm = &((subprocess_descriptor_t*)handler)->pm;
104 1 return pm_callback_get(pm, which, callback, arg);
105 }
106
107
108 /* Lend */
109
110 DLB_EXPORT_SYMBOL
111 2 int DLB_Lend_sp(dlb_handler_t handler) {
112 2 spd_enter_dlb(handler);
113 2 return lend(handler);
114 }
115
116 DLB_EXPORT_SYMBOL
117 34 int DLB_LendCpu_sp(dlb_handler_t handler, int cpuid) {
118 34 spd_enter_dlb(handler);
119 34 return lend_cpu(handler, cpuid);
120 }
121
122 DLB_EXPORT_SYMBOL
123 4 int DLB_LendCpus_sp(dlb_handler_t handler, int ncpus) {
124 4 spd_enter_dlb(handler);
125 4 return lend_cpus(handler, ncpus);
126 }
127
128 DLB_EXPORT_SYMBOL
129 14 int DLB_LendCpuMask_sp(dlb_handler_t handler, const_dlb_cpu_set_t mask) {
130 14 spd_enter_dlb(handler);
131 14 return lend_cpu_mask(handler, mask);
132 }
133
134
135 /* Reclaim */
136
137 DLB_EXPORT_SYMBOL
138 3 int DLB_Reclaim_sp(dlb_handler_t handler) {
139 3 spd_enter_dlb(handler);
140 3 return reclaim(handler);
141 }
142
143 DLB_EXPORT_SYMBOL
144 3 int DLB_ReclaimCpu_sp(dlb_handler_t handler, int cpuid) {
145 3 spd_enter_dlb(handler);
146 3 return reclaim_cpu(handler, cpuid);
147 }
148
149 DLB_EXPORT_SYMBOL
150 1 int DLB_ReclaimCpus_sp(dlb_handler_t handler, int ncpus) {
151 1 spd_enter_dlb(handler);
152 1 return reclaim_cpus(handler, ncpus);
153 }
154
155 DLB_EXPORT_SYMBOL
156 5 int DLB_ReclaimCpuMask_sp(dlb_handler_t handler, const_dlb_cpu_set_t mask) {
157 5 spd_enter_dlb(handler);
158 5 return reclaim_cpu_mask(handler, mask);
159 }
160
161
162 /* Acquire */
163
164 DLB_EXPORT_SYMBOL
165 10 int DLB_AcquireCpu_sp(dlb_handler_t handler, int cpuid) {
166 10 spd_enter_dlb(handler);
167 10 return acquire_cpu(handler, cpuid);
168 }
169
170 DLB_EXPORT_SYMBOL
171 48 int DLB_AcquireCpus_sp(dlb_handler_t handler, int ncpus) {
172 48 spd_enter_dlb(handler);
173 48 return acquire_cpus(handler, ncpus);
174 }
175
176 DLB_EXPORT_SYMBOL
177 10 int DLB_AcquireCpuMask_sp(dlb_handler_t handler, const_dlb_cpu_set_t mask) {
178 10 spd_enter_dlb(handler);
179 10 return acquire_cpu_mask(handler, mask);
180 }
181
182 DLB_EXPORT_SYMBOL
183 5 int DLB_AcquireCpusInMask_sp(dlb_handler_t handler, int ncpus, const_dlb_cpu_set_t mask) {
184 5 spd_enter_dlb(handler);
185 5 return acquire_cpus_in_mask(handler, ncpus, mask);
186 }
187
188
189 /* Borrow */
190
191 DLB_EXPORT_SYMBOL
192 5 int DLB_Borrow_sp(dlb_handler_t handler) {
193 5 spd_enter_dlb(handler);
194 5 return borrow(handler);
195 }
196
197 DLB_EXPORT_SYMBOL
198 1 int DLB_BorrowCpu_sp(dlb_handler_t handler, int cpuid) {
199 1 spd_enter_dlb(handler);
200 1 return borrow_cpu(handler, cpuid);
201 }
202
203 DLB_EXPORT_SYMBOL
204 1 int DLB_BorrowCpus_sp(dlb_handler_t handler, int ncpus) {
205 1 spd_enter_dlb(handler);
206 1 return borrow_cpus(handler, ncpus);
207 }
208
209 DLB_EXPORT_SYMBOL
210 1 int DLB_BorrowCpuMask_sp(dlb_handler_t handler, const_dlb_cpu_set_t mask) {
211 1 spd_enter_dlb(handler);
212 1 return borrow_cpu_mask(handler, mask);
213 }
214
215 DLB_EXPORT_SYMBOL
216 5 int DLB_BorrowCpusInMask_sp(dlb_handler_t handler, int ncpus, const_dlb_cpu_set_t mask) {
217 5 spd_enter_dlb(handler);
218 5 return borrow_cpus_in_mask(handler, ncpus, mask);
219 }
220
221
222 /* Return */
223
224 DLB_EXPORT_SYMBOL
225 1 int DLB_Return_sp(dlb_handler_t handler) {
226 1 spd_enter_dlb(handler);
227 1 return return_all(handler);
228 }
229
230 DLB_EXPORT_SYMBOL
231 11 int DLB_ReturnCpu_sp(dlb_handler_t handler, int cpuid) {
232 11 spd_enter_dlb(handler);
233 11 return return_cpu(handler, cpuid);
234 }
235
236 DLB_EXPORT_SYMBOL
237 1 int DLB_ReturnCpuMask_sp(dlb_handler_t handler, const_dlb_cpu_set_t mask) {
238 1 spd_enter_dlb(handler);
239 1 return return_cpu_mask(handler, mask);
240 }
241
242
243 /* DROM Responsive */
244
245 DLB_EXPORT_SYMBOL
246 1 int DLB_PollDROM_sp(dlb_handler_t handler, int *ncpus, dlb_cpu_set_t mask) {
247 1 spd_enter_dlb(handler);
248 1 return poll_drom(handler, ncpus, mask);
249 }
250
251 DLB_EXPORT_SYMBOL
252 int DLB_PollDROM_Update_sp(dlb_handler_t handler) {
253 spd_enter_dlb(handler);
254 return poll_drom_update(handler);
255 }
256
257
258 /* Misc */
259
260 DLB_EXPORT_SYMBOL
261 7 int DLB_CheckCpuAvailability_sp(dlb_handler_t handler, int cpuid) {
262 7 spd_enter_dlb(handler);
263 7 return check_cpu_availability(handler, cpuid);
264 }
265
266 DLB_EXPORT_SYMBOL
267 2 int DLB_SetVariable_sp(dlb_handler_t handler, const char *variable, const char *value) {
268 2 spd_enter_dlb(handler);
269 2 options_t *options = &((subprocess_descriptor_t*)handler)->options;
270 2 return options_set_variable(options, variable, value);
271 }
272
273 DLB_EXPORT_SYMBOL
274 5 int DLB_GetVariable_sp(dlb_handler_t handler, const char *variable, char *value) {
275 5 spd_enter_dlb(handler);
276 5 const options_t *options = &((subprocess_descriptor_t*)handler)->options;
277 5 return options_get_variable(options, variable, value);
278 }
279
280 DLB_EXPORT_SYMBOL
281 1 int DLB_PrintVariables_sp(dlb_handler_t handler, int print_extended) {
282 1 spd_enter_dlb(handler);
283 1 const options_t *options = &((subprocess_descriptor_t*)handler)->options;
284 1 options_print_variables(options, print_extended);
285 1 return DLB_SUCCESS;
286 }
287