| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************/ | ||
| 2 | /* Copyright 2009-2026 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 | #ifdef HAVE_CONFIG_H | ||
| 21 | #include <config.h> | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include "LB_core/DLB_kernel.h" | ||
| 25 | |||
| 26 | #include "LB_core/node_barrier.h" | ||
| 27 | #include "LB_core/spd.h" | ||
| 28 | #include "LB_numThreads/numThreads.h" | ||
| 29 | #include "LB_numThreads/omptool.h" | ||
| 30 | #include "LB_comm/shmem_async.h" | ||
| 31 | #include "LB_comm/shmem_barrier.h" | ||
| 32 | #include "LB_comm/shmem_cpuinfo.h" | ||
| 33 | #include "LB_comm/shmem_procinfo.h" | ||
| 34 | #include "LB_comm/shmem_talp.h" | ||
| 35 | #include "apis/dlb_errors.h" | ||
| 36 | #include "apis/dlb_talp.h" | ||
| 37 | #include "support/debug.h" | ||
| 38 | #include "support/mytime.h" | ||
| 39 | #include "support/tracing.h" | ||
| 40 | #include "support/options.h" | ||
| 41 | #include "support/mask_utils.h" | ||
| 42 | #include "talp/backend_manager.h" | ||
| 43 | #include "talp/talp.h" | ||
| 44 | #include "talp/talp_mpi.h" | ||
| 45 | #ifdef MPI_LIB | ||
| 46 | #include "mpi/mpi_core.h" | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #include <limits.h> | ||
| 50 | #include <sched.h> | ||
| 51 | #include <string.h> | ||
| 52 | |||
| 53 | |||
| 54 | /* By default all threads are participants. | ||
| 55 | * A thread may change this value to avoid participating in LeWI and TALP metrics. */ | ||
| 56 | __thread bool thread_is_observer = false; | ||
| 57 | |||
| 58 | |||
| 59 | /* Status */ | ||
| 60 | |||
| 61 | 101 | int Initialize(subprocess_descriptor_t *spd, pid_t id, int ncpus, | |
| 62 | const cpu_set_t *mask, const char *lb_args) { | ||
| 63 | |||
| 64 | 101 | int error = DLB_SUCCESS; | |
| 65 | |||
| 66 | // Set it to false in case one thread is an observer but then Initializes DLB | ||
| 67 | 101 | thread_is_observer = false; | |
| 68 | |||
| 69 | // Initialize common modules (spd->id and instrumentation module ASAP) | ||
| 70 | 101 | *spd = (const subprocess_descriptor_t) { | |
| 71 | .id = id, | ||
| 72 | 101 | .pid = getpid(), | |
| 73 | 101 | .dlb_initialized = spd->dlb_initialized, | |
| 74 | 101 | .dlb_preinitialized = spd->dlb_preinitialized, | |
| 75 | 101 | .dlb_initialized_via_ompt = spd->dlb_initialized_via_ompt, | |
| 76 | }; | ||
| 77 | 101 | options_init(&spd->options, lb_args); | |
| 78 | 101 | debug_init(&spd->options); | |
| 79 | init_tracing(&spd->options); | ||
| 80 | instrument_event(RUNTIME_EVENT, EVENT_INIT, EVENT_BEGIN); | ||
| 81 | 101 | mu_init(); | |
| 82 | 101 | timer_init(); | |
| 83 | |||
| 84 | // Infer LeWI mode | ||
| 85 | 101 | spd->lb_policy = | |
| 86 |
4/4✓ Branch 0 taken 43 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 3 times.
|
159 | !spd->options.lewi ? POLICY_NONE : |
| 87 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 30 times.
|
58 | spd->options.lewi_affinity == LEWI_AFFINITY_NONE ? POLICY_LEWI : |
| 88 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | spd->options.lewi_affinity != LEWI_AFFINITY_AUTO ? POLICY_LEWI_MASK : |
| 89 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 10 times.
|
28 | spd->dlb_initialized_via_ompt ? POLICY_LEWI_MASK : |
| 90 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
|
10 | spd->options.preinit_pid ? POLICY_LEWI_MASK : |
| 91 | mask ? POLICY_LEWI_MASK : | ||
| 92 | POLICY_LEWI; | ||
| 93 | |||
| 94 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 68 times.
|
101 | if (spd->lb_policy == POLICY_LEWI |
| 95 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 28 times.
|
33 | && spd->options.mode == MODE_ASYNC) { |
| 96 | 5 | spd->lb_policy = POLICY_LEWI_ASYNC; | |
| 97 | } | ||
| 98 | |||
| 99 | // Check if real process mask is needed and possible incompatibilities | ||
| 100 | // (Basically, always except if classic LeWI) | ||
| 101 | 101 | bool mask_is_needed = ( | |
| 102 | 101 | spd->lb_policy == POLICY_LEWI_MASK | |
| 103 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 17 times.
|
76 | || spd->options.drom |
| 104 |
4/4✓ Branch 0 taken 76 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 54 times.
|
177 | || spd->options.preinit_pid); |
| 105 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 54 times.
|
101 | if (mask_is_needed && |
| 106 |
2/4✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 47 times.
|
47 | (spd->lb_policy == POLICY_LEWI || spd->lb_policy == POLICY_LEWI_ASYNC)) { |
| 107 | ✗ | warning("Classic LeWI support with no cpuset binding is not compatible" | |
| 108 | " with newer DLB modules. DLB_Init cannot continue."); | ||
| 109 | ✗ | return DLB_ERR_NOCOMP; | |
| 110 | } | ||
| 111 | |||
| 112 | // Initialize the rest of the subprocess descriptor | ||
| 113 | 101 | pm_init(&spd->pm); | |
| 114 | 101 | set_lb_funcs(&spd->lb_funcs, spd->lb_policy); | |
| 115 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 46 times.
|
101 | if (mask) { |
| 116 | // Preferred case, mask is provided by the user | ||
| 117 | 55 | memcpy(&spd->process_mask, mask, sizeof(cpu_set_t)); | |
| 118 | } else { | ||
| 119 | // Best effort querying the system | ||
| 120 | // (it may be late if DLB_Init is called after other RT sets this thread's affinity) | ||
| 121 | 46 | sched_getaffinity(0, sizeof(cpu_set_t), &spd->process_mask); | |
| 122 | } | ||
| 123 | |||
| 124 | // ncpus is only used for classic LeWI | ||
| 125 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 28 times.
|
101 | if (spd->lb_policy == POLICY_LEWI |
| 126 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 68 times.
|
73 | || spd->lb_policy == POLICY_LEWI_ASYNC) { |
| 127 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 4 times.
|
33 | spd->lewi_ncpus = ncpus > 0 ? ncpus : pm_get_num_threads(); |
| 128 | } | ||
| 129 | |||
| 130 | // Initialize shared memories | ||
| 131 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 54 times.
|
101 | if (mask_is_needed) { |
| 132 | // Initialize procinfo | ||
| 133 |
1/2✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
|
47 | if (spd->options.lewi_color == 0) { |
| 134 | cpu_set_t new_process_mask; | ||
| 135 | 47 | error = shmem_procinfo__init(spd->id, spd->options.preinit_pid, | |
| 136 | 47 | &spd->process_mask, &new_process_mask, spd->options.shm_key, | |
| 137 | spd->options.shm_size_multiplier); | ||
| 138 | |||
| 139 | // If the process has been pre-initialized (error=DLB_NOTED), | ||
| 140 | // the mask provided by shmem_procinfo__init must overwrite the process mask | ||
| 141 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 31 times.
|
47 | if (error == DLB_NOTED) { |
| 142 | 16 | set_process_mask(&spd->pm, &new_process_mask); | |
| 143 | 16 | memcpy(&spd->process_mask, &new_process_mask, sizeof(cpu_set_t)); | |
| 144 | 16 | error = DLB_SUCCESS; | |
| 145 | } | ||
| 146 | } else { | ||
| 147 | // If using --lewi-color, we also need to initialize procinfo with cpu sharing | ||
| 148 | ✗ | error = shmem_procinfo__init_with_cpu_sharing(spd->id, spd->options.preinit_pid, | |
| 149 | ✗ | &spd->process_mask, spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 150 | } | ||
| 151 | |||
| 152 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 45 times.
|
47 | if (error != DLB_SUCCESS) return error; |
| 153 | |||
| 154 | // Initialize cpuinfo | ||
| 155 | 45 | error = shmem_cpuinfo__init(spd->id, spd->options.preinit_pid, | |
| 156 | 45 | &spd->process_mask, spd->options.shm_key, spd->options.lewi_color); | |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (error != DLB_SUCCESS) return error; |
| 158 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 43 times.
|
54 | } else if (spd->options.talp) { |
| 159 | // If mask is not needed but TALP is enabled, we still need to | ||
| 160 | // initialize shmem_procinfo but allowing CPU sharing | ||
| 161 | 11 | error = shmem_procinfo__init_with_cpu_sharing(spd->id, spd->options.preinit_pid, | |
| 162 | 11 | &spd->process_mask, spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 163 | } | ||
| 164 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 3 times.
|
99 | if (spd->options.barrier) { |
| 165 | 96 | shmem_barrier__init(spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 166 | 96 | node_barrier_init(spd); | |
| 167 | } | ||
| 168 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 88 times.
|
99 | if (spd->options.mode == MODE_ASYNC) { |
| 169 | 11 | error = shmem_async_init(spd->id, &spd->pm, &spd->process_mask, | |
| 170 | 11 | spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (error != DLB_SUCCESS) return error; |
| 172 | } | ||
| 173 | |||
| 174 | // Initialise LeWI | ||
| 175 | 99 | error = spd->lb_funcs.init(spd); | |
| 176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | if (error != DLB_SUCCESS) return error; |
| 177 | |||
| 178 | // Initialize TALP | ||
| 179 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 86 times.
|
99 | if (spd->options.talp) { |
| 180 | 13 | talp_init(spd); | |
| 181 | } else { | ||
| 182 | 86 | spd->talp_info = NULL; | |
| 183 | } | ||
| 184 | |||
| 185 | // Print initialization summary | ||
| 186 | 99 | info0("%s %s", PACKAGE, VERSION); | |
| 187 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 41 times.
|
99 | if (spd->lb_policy != POLICY_NONE) { |
| 188 | 58 | info0("Balancing policy: %s", policy_tostr(spd->lb_policy)); | |
| 189 | 58 | options_print_lewi_flags(&spd->options); | |
| 190 | } | ||
| 191 | instrument_print_flags(); | ||
| 192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_API, "Enabled verbose mode for DLB API"); |
| 193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_MPI_API, "Enabled verbose mode for MPI API"); |
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_MPI_INT, "Enabled verbose mode for MPI Interception"); |
| 195 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_SHMEM, "Enabled verbose mode for Shared Memory"); |
| 196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_DROM, "Enabled verbose mode for DROM"); |
| 197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_STATS, "Enabled verbose mode for STATS"); |
| 198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_MICROLB, "Enabled verbose mode for microLB policies"); |
| 199 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_ASYNC, "Enabled verbose mode for Asynchronous thread"); |
| 200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | verbose0(VB_OMPT, "Enabled verbose mode for OMPT experimental features"); |
| 201 | |||
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99 times.
|
99 | if (spd->options.verbose & VB_AFFINITY) { |
| 203 | print_buffer_t buffer; | ||
| 204 | ✗ | mu_get_system_description(&buffer); | |
| 205 | ✗ | verbose0(VB_AFFINITY, "System affinity\n%s", buffer.addr); | |
| 206 | ✗ | printbuffer_destroy(&buffer); | |
| 207 | } | ||
| 208 | |||
| 209 | // Print number of cpus or mask | ||
| 210 |
2/2✓ Branch 0 taken 45 times.
✓ Branch 1 taken 54 times.
|
99 | if (mask_is_needed) { |
| 211 | 45 | info("Process CPU affinity mask: %s", mu_to_str(&spd->process_mask)); | |
| 212 | } | ||
| 213 | |||
| 214 | 99 | spd->lewi_enabled = true; | |
| 215 | instrument_event(RUNTIME_EVENT, EVENT_INIT, EVENT_END); | ||
| 216 | instrument_event(DLB_MODE_EVENT, EVENT_ENABLED, EVENT_BEGIN); | ||
| 217 | |||
| 218 | 99 | return error; | |
| 219 | } | ||
| 220 | |||
| 221 | 99 | int Finish(subprocess_descriptor_t *spd) { | |
| 222 | |||
| 223 | /* Protect finalization if spd does not match with current process */ | ||
| 224 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
|
99 | if (spd->pid != getpid()) { |
| 225 | ✗ | return DLB_NOUPDT; | |
| 226 | } | ||
| 227 | |||
| 228 | 99 | int error = DLB_SUCCESS; | |
| 229 | instrument_event(RUNTIME_EVENT, EVENT_FINALIZE, EVENT_BEGIN); | ||
| 230 | |||
| 231 | #if MPI_LIB | ||
| 232 | /* If DLB_Finalize is called preemptively, we need to finalize also the MPI | ||
| 233 | * module */ | ||
| 234 | finalize_mpi_core(); | ||
| 235 | #endif | ||
| 236 | |||
| 237 | 99 | spd->lewi_enabled = false; | |
| 238 | |||
| 239 | 99 | pm_finalize(&spd->pm); | |
| 240 | |||
| 241 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 86 times.
|
99 | if (spd->options.talp) { |
| 242 | 13 | talp_finalize(spd); | |
| 243 | } | ||
| 244 |
1/2✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
|
99 | if (spd->lb_funcs.finalize) { |
| 245 | 99 | spd->lb_funcs.finalize(spd); | |
| 246 | 99 | spd->lb_funcs.finalize = NULL; | |
| 247 | } | ||
| 248 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 3 times.
|
99 | if (spd->options.barrier) { |
| 249 | 96 | node_barrier_finalize(spd); | |
| 250 | 96 | shmem_barrier__finalize(spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 251 | } | ||
| 252 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 25 times.
|
99 | if (spd->lb_policy == POLICY_LEWI_MASK |
| 253 |
2/2✓ Branch 0 taken 59 times.
✓ Branch 1 taken 15 times.
|
74 | || spd->options.drom |
| 254 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 11 times.
|
59 | || spd->options.talp |
| 255 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | || spd->options.ompt |
| 256 | ✗ | || spd->options.preinit_pid) { | |
| 257 | 99 | shmem_cpuinfo__finalize(spd->id, spd->options.shm_key, spd->options.lewi_color); | |
| 258 | 99 | shmem_procinfo__finalize(spd->id, spd->options.debug_opts & DBG_RETURNSTOLEN, | |
| 259 | 99 | spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 260 | } | ||
| 261 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 88 times.
|
99 | if (spd->options.mode == MODE_ASYNC) { |
| 262 | 11 | shmem_async_finalize(spd->id); | |
| 263 | } | ||
| 264 | 99 | timer_finalize(); | |
| 265 | instrument_event(RUNTIME_EVENT, EVENT_FINALIZE, EVENT_END); | ||
| 266 | instrument_finalize(); | ||
| 267 | 99 | options_finalize(&spd->options); | |
| 268 | 99 | return error; | |
| 269 | } | ||
| 270 | |||
| 271 | 7 | int PreInitialize(subprocess_descriptor_t *spd, const cpu_set_t *mask, | |
| 272 | const char *lb_args) { | ||
| 273 | // Initialize options | ||
| 274 | 7 | options_init(&spd->options, lb_args); | |
| 275 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (spd->options.preinit_pid == 0) return DLB_ERR_INIT; |
| 276 | |||
| 277 | 7 | debug_init(&spd->options); | |
| 278 | |||
| 279 | // Initialize subprocess descriptor | ||
| 280 | 7 | spd->lb_policy = POLICY_NONE; | |
| 281 | 7 | pm_init(&spd->pm); | |
| 282 | 7 | set_lb_funcs(&spd->lb_funcs, spd->lb_policy); | |
| 283 | 7 | spd->id = spd->options.preinit_pid; | |
| 284 | 7 | memcpy(&spd->process_mask, mask, sizeof(cpu_set_t)); | |
| 285 | |||
| 286 | // Initialize modules | ||
| 287 | 7 | int error = DLB_SUCCESS; | |
| 288 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | error = error ? error : shmem_cpuinfo_ext__init(spd->options.shm_key, spd->options.lewi_color); |
| 289 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | error = error ? error : shmem_procinfo_ext__init(spd->options.shm_key, |
| 290 | spd->options.shm_size_multiplier); | ||
| 291 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | error = error ? error : shmem_procinfo_ext__preinit(spd->id, mask, DLB_DROM_FLAGS_NONE); |
| 292 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | error = error ? error : shmem_cpuinfo_ext__preinit(spd->id, mask, DLB_DROM_FLAGS_NONE); |
| 293 | // Close shmems even if there was an error | ||
| 294 | 7 | int cpuinfo_finalize_err = shmem_cpuinfo_ext__finalize(); | |
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | error = error ? error : cpuinfo_finalize_err; |
| 296 | 7 | int procinfo_finalize_err = shmem_procinfo_ext__finalize(); | |
| 297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | error = error ? error : procinfo_finalize_err; |
| 298 | 7 | return error; | |
| 299 | } | ||
| 300 | |||
| 301 | 18 | int set_lewi_enabled(subprocess_descriptor_t *spd, bool enabled) { | |
| 302 | 18 | int error = DLB_SUCCESS; | |
| 303 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 4 times.
|
18 | if (__sync_bool_compare_and_swap(&spd->lewi_enabled, !enabled, enabled)) { |
| 304 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | if (enabled) { |
| 305 | 7 | spd->lb_funcs.enable(spd); | |
| 306 | instrument_event(DLB_MODE_EVENT, EVENT_ENABLED, EVENT_BEGIN); | ||
| 307 | } else { | ||
| 308 | 7 | spd->lb_funcs.disable(spd); | |
| 309 | instrument_event(DLB_MODE_EVENT, EVENT_DISABLED, EVENT_BEGIN); | ||
| 310 | } | ||
| 311 | } else { | ||
| 312 | 4 | error = DLB_NOUPDT; | |
| 313 | } | ||
| 314 | 18 | return error; | |
| 315 | } | ||
| 316 | |||
| 317 | 5 | int set_max_parallelism(subprocess_descriptor_t *spd, int max) { | |
| 318 | int error; | ||
| 319 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (!spd->options.lewi) { |
| 320 | 3 | error = DLB_ERR_NOLEWI; | |
| 321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } else if (!spd->lewi_enabled) { |
| 322 | ✗ | error = DLB_ERR_DISBLD; | |
| 323 | } else { | ||
| 324 | instrument_event(RUNTIME_EVENT, EVENT_MAX_PARALLELISM, EVENT_BEGIN); | ||
| 325 | instrument_event(MAX_PAR_EVENT, 0, EVENT_END); | ||
| 326 | instrument_event(MAX_PAR_EVENT, max, EVENT_BEGIN); | ||
| 327 | 2 | error = spd->lb_funcs.set_max_parallelism(spd, max); | |
| 328 | instrument_event(RUNTIME_EVENT, EVENT_MAX_PARALLELISM, EVENT_END); | ||
| 329 | } | ||
| 330 | 5 | return error; | |
| 331 | } | ||
| 332 | |||
| 333 | 3 | int unset_max_parallelism(subprocess_descriptor_t *spd) { | |
| 334 | int error; | ||
| 335 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (!spd->options.lewi) { |
| 336 | 1 | error = DLB_ERR_NOLEWI; | |
| 337 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } else if (!spd->lewi_enabled) { |
| 338 | ✗ | error = DLB_ERR_DISBLD; | |
| 339 | } else { | ||
| 340 | instrument_event(RUNTIME_EVENT, EVENT_MAX_PARALLELISM, EVENT_BEGIN); | ||
| 341 | instrument_event(MAX_PAR_EVENT, 0, EVENT_END); | ||
| 342 | 2 | error = spd->lb_funcs.unset_max_parallelism(spd); | |
| 343 | instrument_event(RUNTIME_EVENT, EVENT_MAX_PARALLELISM, EVENT_END); | ||
| 344 | } | ||
| 345 | 3 | return error; | |
| 346 | } | ||
| 347 | |||
| 348 | |||
| 349 | /* Sync-call specific (MPI, DLB_Barrier, etc.) */ | ||
| 350 | |||
| 351 | 18 | void into_sync_call(sync_call_flags_t flags) { | |
| 352 | /* Observer threads do not trigger LeWI nor TALP on sync calls */ | ||
| 353 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
|
18 | if (unlikely(thread_is_observer)) return; |
| 354 | |||
| 355 | 16 | const subprocess_descriptor_t *spd = thread_spd; | |
| 356 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (unlikely(spd == NULL)) return; |
| 357 | |||
| 358 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | if (spd->options.lewi && spd->lewi_enabled && flags.do_lewi) { |
| 359 | 16 | spd->lb_funcs.into_blocking_call(spd); | |
| 360 | 16 | omptool__into_blocking_call(); | |
| 361 | } | ||
| 362 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if(spd->options.talp) { |
| 363 | ✗ | talp_into_sync_call(spd, flags.is_blocking && flags.is_collective); | |
| 364 | } | ||
| 365 | } | ||
| 366 | |||
| 367 | 18 | void out_of_sync_call(sync_call_flags_t flags) { | |
| 368 | /* Observer threads do not trigger LeWI nor TALP on MPI calls */ | ||
| 369 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
|
18 | if (unlikely(thread_is_observer)) return; |
| 370 | |||
| 371 | 16 | const subprocess_descriptor_t *spd = thread_spd; | |
| 372 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (unlikely(spd == NULL)) return; |
| 373 | |||
| 374 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | if (spd->options.lewi && spd->lewi_enabled && flags.do_lewi) { |
| 375 | 16 | spd->lb_funcs.out_of_blocking_call(spd); | |
| 376 | 16 | omptool__outof_blocking_call(); | |
| 377 | } | ||
| 378 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if(spd->options.talp) { |
| 379 | ✗ | talp_out_of_sync_call(spd, flags.is_blocking && flags.is_collective); | |
| 380 | } | ||
| 381 | } | ||
| 382 | |||
| 383 | |||
| 384 | /* Lend */ | ||
| 385 | |||
| 386 | 8 | int lend(const subprocess_descriptor_t *spd) { | |
| 387 | int error; | ||
| 388 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
|
8 | if (!spd->options.lewi) { |
| 389 | 6 | error = DLB_ERR_NOLEWI; | |
| 390 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | } else if (!spd->lewi_enabled) { |
| 391 | 2 | error = DLB_ERR_DISBLD; | |
| 392 | } else { | ||
| 393 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_BEGIN); | ||
| 394 | instrument_event(GIVE_CPUS_EVENT, CPU_SETSIZE, EVENT_BEGIN); | ||
| 395 | ✗ | omptool__lend_from_api(); | |
| 396 | ✗ | error = spd->lb_funcs.lend(spd); | |
| 397 | instrument_event(GIVE_CPUS_EVENT, 0, EVENT_END); | ||
| 398 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_END); | ||
| 399 | } | ||
| 400 | 8 | return error; | |
| 401 | } | ||
| 402 | |||
| 403 | 40 | int lend_cpu(const subprocess_descriptor_t *spd, int cpuid) { | |
| 404 | int error; | ||
| 405 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 37 times.
|
40 | if (!spd->options.lewi) { |
| 406 | 3 | error = DLB_ERR_NOLEWI; | |
| 407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | } else if (!spd->lewi_enabled) { |
| 408 | ✗ | error = DLB_ERR_DISBLD; | |
| 409 | } else { | ||
| 410 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_BEGIN); | ||
| 411 | instrument_event(GIVE_CPUS_EVENT, 1, EVENT_BEGIN); | ||
| 412 | 37 | error = spd->lb_funcs.lend_cpu(spd, cpuid); | |
| 413 | instrument_event(GIVE_CPUS_EVENT, 0, EVENT_END); | ||
| 414 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_END); | ||
| 415 | } | ||
| 416 | 40 | return error; | |
| 417 | } | ||
| 418 | |||
| 419 | 6 | int lend_cpus(const subprocess_descriptor_t *spd, int ncpus) { | |
| 420 | int error; | ||
| 421 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (!spd->options.lewi) { |
| 422 | 3 | error = DLB_ERR_NOLEWI; | |
| 423 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } else if (!spd->lewi_enabled) { |
| 424 | ✗ | error = DLB_ERR_DISBLD; | |
| 425 | } else { | ||
| 426 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_BEGIN); | ||
| 427 | instrument_event(GIVE_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 428 | 3 | error = spd->lb_funcs.lend_cpus(spd, ncpus); | |
| 429 | instrument_event(GIVE_CPUS_EVENT, 0, EVENT_END); | ||
| 430 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_END); | ||
| 431 | } | ||
| 432 | 6 | return error; | |
| 433 | } | ||
| 434 | |||
| 435 | 18 | int lend_cpu_mask(const subprocess_descriptor_t *spd, const cpu_set_t *mask) { | |
| 436 | int error; | ||
| 437 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 15 times.
|
18 | if (!spd->options.lewi) { |
| 438 | 3 | error = DLB_ERR_NOLEWI; | |
| 439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | } else if (!spd->lewi_enabled) { |
| 440 | ✗ | error = DLB_ERR_DISBLD; | |
| 441 | } else { | ||
| 442 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_BEGIN); | ||
| 443 | instrument_event(GIVE_CPUS_EVENT, CPU_COUNT(mask), EVENT_BEGIN); | ||
| 444 | 15 | error = spd->lb_funcs.lend_cpu_mask(spd, mask); | |
| 445 | instrument_event(GIVE_CPUS_EVENT, 0, EVENT_END); | ||
| 446 | instrument_event(RUNTIME_EVENT, EVENT_LEND, EVENT_END); | ||
| 447 | } | ||
| 448 | 18 | return error; | |
| 449 | } | ||
| 450 | |||
| 451 | |||
| 452 | /* Reclaim */ | ||
| 453 | |||
| 454 | 6 | int reclaim(const subprocess_descriptor_t *spd) { | |
| 455 | int error; | ||
| 456 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (!spd->options.lewi) { |
| 457 | 3 | error = DLB_ERR_NOLEWI; | |
| 458 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } else if (!spd->lewi_enabled) { |
| 459 | ✗ | error = DLB_ERR_DISBLD; | |
| 460 | } else { | ||
| 461 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_BEGIN); | ||
| 462 | instrument_event(WANT_CPUS_EVENT, CPU_SETSIZE, EVENT_BEGIN); | ||
| 463 | 3 | error = spd->lb_funcs.reclaim(spd); | |
| 464 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 465 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_END); | ||
| 466 | } | ||
| 467 | 6 | return error; | |
| 468 | } | ||
| 469 | |||
| 470 | 5 | int reclaim_cpu(const subprocess_descriptor_t *spd, int cpuid) { | |
| 471 | int error; | ||
| 472 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (!spd->options.lewi) { |
| 473 | 3 | error = DLB_ERR_NOLEWI; | |
| 474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } else if (!spd->lewi_enabled) { |
| 475 | ✗ | error = DLB_ERR_DISBLD; | |
| 476 | } else { | ||
| 477 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_BEGIN); | ||
| 478 | instrument_event(WANT_CPUS_EVENT, 1, EVENT_BEGIN); | ||
| 479 | 2 | error = spd->lb_funcs.reclaim_cpu(spd, cpuid); | |
| 480 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 481 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_END); | ||
| 482 | } | ||
| 483 | 5 | return error; | |
| 484 | } | ||
| 485 | |||
| 486 | 3 | int reclaim_cpus(const subprocess_descriptor_t *spd, int ncpus) { | |
| 487 | int error; | ||
| 488 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 489 | 3 | error = DLB_ERR_NOLEWI; | |
| 490 | ✗ | } else if (!spd->lewi_enabled) { | |
| 491 | ✗ | error = DLB_ERR_DISBLD; | |
| 492 | } else { | ||
| 493 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_BEGIN); | ||
| 494 | instrument_event(WANT_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 495 | ✗ | error = spd->lb_funcs.reclaim_cpus(spd, ncpus); | |
| 496 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 497 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_END); | ||
| 498 | } | ||
| 499 | 3 | return error; | |
| 500 | } | ||
| 501 | |||
| 502 | 8 | int reclaim_cpu_mask(const subprocess_descriptor_t *spd, const cpu_set_t *mask) { | |
| 503 | int error; | ||
| 504 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
|
8 | if (!spd->options.lewi) { |
| 505 | 3 | error = DLB_ERR_NOLEWI; | |
| 506 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | } else if (!spd->lewi_enabled) { |
| 507 | ✗ | error = DLB_ERR_DISBLD; | |
| 508 | } else { | ||
| 509 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_BEGIN); | ||
| 510 | instrument_event(WANT_CPUS_EVENT, CPU_COUNT(mask), EVENT_BEGIN); | ||
| 511 | 5 | error = spd->lb_funcs.reclaim_cpu_mask(spd, mask); | |
| 512 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 513 | instrument_event(RUNTIME_EVENT, EVENT_RECLAIM, EVENT_END); | ||
| 514 | } | ||
| 515 | 8 | return error; | |
| 516 | } | ||
| 517 | |||
| 518 | |||
| 519 | /* Acquire */ | ||
| 520 | |||
| 521 | 13 | int acquire_cpu(const subprocess_descriptor_t *spd, int cpuid) { | |
| 522 | int error; | ||
| 523 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
|
13 | if (!spd->options.lewi) { |
| 524 | 3 | error = DLB_ERR_NOLEWI; | |
| 525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | } else if (!spd->lewi_enabled) { |
| 526 | ✗ | error = DLB_ERR_DISBLD; | |
| 527 | } else { | ||
| 528 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_BEGIN); | ||
| 529 | instrument_event(WANT_CPUS_EVENT, 1, EVENT_BEGIN); | ||
| 530 | 10 | error = spd->lb_funcs.acquire_cpu(spd, cpuid); | |
| 531 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 532 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_END); | ||
| 533 | } | ||
| 534 | 13 | return error; | |
| 535 | } | ||
| 536 | |||
| 537 | 61 | int acquire_cpus(const subprocess_descriptor_t *spd, int ncpus) { | |
| 538 | int error; | ||
| 539 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 58 times.
|
61 | if (!spd->options.lewi) { |
| 540 | 3 | error = DLB_ERR_NOLEWI; | |
| 541 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | } else if (!spd->lewi_enabled) { |
| 542 | ✗ | error = DLB_ERR_DISBLD; | |
| 543 | } else { | ||
| 544 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_BEGIN); | ||
| 545 | instrument_event(WANT_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 546 | 58 | error = spd->lb_funcs.acquire_cpus(spd, ncpus); | |
| 547 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 548 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_END); | ||
| 549 | } | ||
| 550 | 61 | return error; | |
| 551 | } | ||
| 552 | |||
| 553 | 12 | int acquire_cpu_mask(const subprocess_descriptor_t *spd, const cpu_set_t *mask) { | |
| 554 | int error; | ||
| 555 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
|
12 | if (!spd->options.lewi) { |
| 556 | 3 | error = DLB_ERR_NOLEWI; | |
| 557 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | } else if (!spd->lewi_enabled) { |
| 558 | ✗ | error = DLB_ERR_DISBLD; | |
| 559 | } else { | ||
| 560 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_BEGIN); | ||
| 561 | instrument_event(WANT_CPUS_EVENT, CPU_COUNT(mask), EVENT_BEGIN); | ||
| 562 | 9 | error = spd->lb_funcs.acquire_cpu_mask(spd, mask); | |
| 563 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 564 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_END); | ||
| 565 | } | ||
| 566 | 12 | return error; | |
| 567 | } | ||
| 568 | |||
| 569 | 14 | int acquire_cpus_in_mask(const subprocess_descriptor_t *spd, int ncpus, const cpu_set_t *mask) { | |
| 570 | int error; | ||
| 571 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11 times.
|
14 | if (!spd->options.lewi) { |
| 572 | 3 | error = DLB_ERR_NOLEWI; | |
| 573 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | } else if (!spd->lewi_enabled) { |
| 574 | ✗ | error = DLB_ERR_DISBLD; | |
| 575 | } else { | ||
| 576 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_BEGIN); | ||
| 577 | instrument_event(WANT_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 578 | 11 | error = spd->lb_funcs.acquire_cpus_in_mask(spd, ncpus, mask); | |
| 579 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 580 | instrument_event(RUNTIME_EVENT, EVENT_ACQUIRE, EVENT_END); | ||
| 581 | } | ||
| 582 | 14 | return error; | |
| 583 | } | ||
| 584 | |||
| 585 | |||
| 586 | /* Borrow */ | ||
| 587 | |||
| 588 | 7 | int borrow(const subprocess_descriptor_t *spd) { | |
| 589 | int error; | ||
| 590 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (!spd->options.lewi) { |
| 591 | 3 | error = DLB_ERR_NOLEWI; | |
| 592 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (!spd->lewi_enabled) { |
| 593 | ✗ | error = DLB_ERR_DISBLD; | |
| 594 | } else { | ||
| 595 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_BEGIN); | ||
| 596 | instrument_event(WANT_CPUS_EVENT, CPU_SETSIZE, EVENT_BEGIN); | ||
| 597 | 4 | error = spd->lb_funcs.borrow(spd); | |
| 598 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 599 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_END); | ||
| 600 | } | ||
| 601 | 7 | return error; | |
| 602 | } | ||
| 603 | |||
| 604 | 3 | int borrow_cpu(const subprocess_descriptor_t *spd, int cpuid) { | |
| 605 | int error; | ||
| 606 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 607 | 3 | error = DLB_ERR_NOLEWI; | |
| 608 | ✗ | } else if (!spd->lewi_enabled) { | |
| 609 | ✗ | error = DLB_ERR_DISBLD; | |
| 610 | } else { | ||
| 611 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_BEGIN); | ||
| 612 | instrument_event(WANT_CPUS_EVENT, 1, EVENT_BEGIN); | ||
| 613 | ✗ | error = spd->lb_funcs.borrow_cpu(spd, cpuid); | |
| 614 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 615 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_END); | ||
| 616 | } | ||
| 617 | 3 | return error; | |
| 618 | } | ||
| 619 | |||
| 620 | 3 | int borrow_cpus(const subprocess_descriptor_t *spd, int ncpus) { | |
| 621 | int error; | ||
| 622 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 623 | 3 | error = DLB_ERR_NOLEWI; | |
| 624 | ✗ | } else if (!spd->lewi_enabled) { | |
| 625 | ✗ | error = DLB_ERR_DISBLD; | |
| 626 | } else { | ||
| 627 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_BEGIN); | ||
| 628 | instrument_event(WANT_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 629 | ✗ | error = spd->lb_funcs.borrow_cpus(spd, ncpus); | |
| 630 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 631 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_END); | ||
| 632 | } | ||
| 633 | 3 | return error; | |
| 634 | } | ||
| 635 | |||
| 636 | 3 | int borrow_cpu_mask(const subprocess_descriptor_t *spd, const cpu_set_t *mask) { | |
| 637 | int error; | ||
| 638 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 639 | 3 | error = DLB_ERR_NOLEWI; | |
| 640 | ✗ | } else if (!spd->lewi_enabled) { | |
| 641 | ✗ | error = DLB_ERR_DISBLD; | |
| 642 | } else { | ||
| 643 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_BEGIN); | ||
| 644 | instrument_event(WANT_CPUS_EVENT, CPU_COUNT(mask), EVENT_BEGIN); | ||
| 645 | ✗ | error = spd->lb_funcs.borrow_cpu_mask(spd, mask); | |
| 646 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 647 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_END); | ||
| 648 | } | ||
| 649 | 3 | return error; | |
| 650 | } | ||
| 651 | |||
| 652 | 7 | int borrow_cpus_in_mask(const subprocess_descriptor_t *spd, int ncpus, const cpu_set_t *mask) { | |
| 653 | int error; | ||
| 654 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (!spd->options.lewi) { |
| 655 | 3 | error = DLB_ERR_NOLEWI; | |
| 656 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (!spd->lewi_enabled) { |
| 657 | ✗ | error = DLB_ERR_DISBLD; | |
| 658 | } else { | ||
| 659 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_BEGIN); | ||
| 660 | instrument_event(WANT_CPUS_EVENT, ncpus, EVENT_BEGIN); | ||
| 661 | 4 | error = spd->lb_funcs.borrow_cpus_in_mask(spd, ncpus, mask); | |
| 662 | instrument_event(WANT_CPUS_EVENT, 0, EVENT_END); | ||
| 663 | instrument_event(RUNTIME_EVENT, EVENT_BORROW, EVENT_END); | ||
| 664 | } | ||
| 665 | 7 | return error; | |
| 666 | } | ||
| 667 | |||
| 668 | /* Return */ | ||
| 669 | |||
| 670 | 3 | int return_all(const subprocess_descriptor_t *spd) { | |
| 671 | int error; | ||
| 672 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 673 | 3 | error = DLB_ERR_NOLEWI; | |
| 674 | ✗ | } else if (!spd->lewi_enabled) { | |
| 675 | ✗ | error = DLB_ERR_DISBLD; | |
| 676 | } else { | ||
| 677 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_BEGIN); | ||
| 678 | ✗ | error = spd->lb_funcs.return_all(spd); | |
| 679 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_END); | ||
| 680 | } | ||
| 681 | 3 | return error; | |
| 682 | } | ||
| 683 | |||
| 684 | 19 | int return_cpu(const subprocess_descriptor_t *spd, int cpuid) { | |
| 685 | int error; | ||
| 686 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 16 times.
|
19 | if (!spd->options.lewi) { |
| 687 | 3 | error = DLB_ERR_NOLEWI; | |
| 688 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (!spd->lewi_enabled) { |
| 689 | ✗ | error = DLB_ERR_DISBLD; | |
| 690 | } else { | ||
| 691 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_BEGIN); | ||
| 692 | 16 | error = spd->lb_funcs.return_cpu(spd, cpuid); | |
| 693 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_END); | ||
| 694 | } | ||
| 695 | 19 | return error; | |
| 696 | } | ||
| 697 | |||
| 698 | 3 | int return_cpu_mask(const subprocess_descriptor_t *spd, const cpu_set_t *mask) { | |
| 699 | int error; | ||
| 700 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (!spd->options.lewi) { |
| 701 | 3 | error = DLB_ERR_NOLEWI; | |
| 702 | ✗ | } else if (!spd->lewi_enabled) { | |
| 703 | ✗ | error = DLB_ERR_DISBLD; | |
| 704 | } else { | ||
| 705 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_BEGIN); | ||
| 706 | ✗ | error = spd->lb_funcs.return_cpu_mask(spd, mask); | |
| 707 | instrument_event(RUNTIME_EVENT, EVENT_RETURN, EVENT_END); | ||
| 708 | } | ||
| 709 | 3 | return error; | |
| 710 | } | ||
| 711 | |||
| 712 | |||
| 713 | /* Drom Responsive */ | ||
| 714 | |||
| 715 | 8 | int poll_drom(const subprocess_descriptor_t *spd, int *new_cpus, cpu_set_t *new_mask) { | |
| 716 | int error; | ||
| 717 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 | if (!spd->options.drom) { |
| 718 | 2 | error = DLB_ERR_NOCOMP; | |
| 719 | } else { | ||
| 720 | instrument_event(RUNTIME_EVENT, EVENT_POLLDROM, EVENT_BEGIN); | ||
| 721 | // Use a local mask if new_mask was not provided | ||
| 722 | cpu_set_t local_mask; | ||
| 723 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | cpu_set_t *mask = new_mask ? new_mask : &local_mask; |
| 724 | |||
| 725 | 6 | error = shmem_procinfo__polldrom(spd->id, new_cpus, mask); | |
| 726 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (error == DLB_SUCCESS) { |
| 727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (spd->options.lewi) { |
| 728 | /* If LeWI, resolve reclaimed CPUs */ | ||
| 729 | ✗ | spd->lb_funcs.update_ownership(spd, mask); | |
| 730 | } else { | ||
| 731 | /* Otherwise, udate owner and guest data */ | ||
| 732 | 3 | shmem_cpuinfo__update_ownership(spd->id, mask, NULL); | |
| 733 | } | ||
| 734 | } | ||
| 735 | instrument_event(RUNTIME_EVENT, EVENT_POLLDROM, EVENT_END); | ||
| 736 | } | ||
| 737 | 8 | return error; | |
| 738 | } | ||
| 739 | |||
| 740 | 3 | int poll_drom_update(const subprocess_descriptor_t *spd) { | |
| 741 | cpu_set_t new_mask; | ||
| 742 | 3 | int error = poll_drom(spd, NULL, &new_mask); | |
| 743 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (error == DLB_SUCCESS) { |
| 744 | 2 | set_process_mask(&spd->pm, &new_mask); | |
| 745 | } | ||
| 746 | 3 | return error; | |
| 747 | } | ||
| 748 | |||
| 749 | 14 | int drom_setprocessmask(int pid, const_dlb_cpu_set_t mask, dlb_drom_flags_t flags) { | |
| 750 | cpu_set_t free_cpu_mask; | ||
| 751 | 14 | int error = shmem_procinfo__setprocessmask(pid, mask, flags, &free_cpu_mask); | |
| 752 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
|
14 | if (error == DLB_SUCCESS |
| 753 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | && thread_spd->dlb_initialized |
| 754 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 | && (pid == 0 || pid == thread_spd->id) |
| 755 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | && !(flags & DLB_NO_SYNC)) { |
| 756 | /* Mask has been successfully set by own process, do like a poll_drom_update */ | ||
| 757 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (thread_spd->options.lewi) { |
| 758 | /* If LeWI, resolve reclaimed CPUs */ | ||
| 759 | ✗ | thread_spd->lb_funcs.update_ownership(thread_spd, mask); | |
| 760 | } else { | ||
| 761 | /* Otherwise, udate owner and guest data */ | ||
| 762 | 2 | shmem_cpuinfo__update_ownership(thread_spd->id, mask, NULL); | |
| 763 | } | ||
| 764 | 2 | set_process_mask(&thread_spd->pm, mask); | |
| 765 | } | ||
| 766 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
14 | if (error == DLB_SUCCESS && (flags & DLB_FREE_CPUS_SLURM)) { |
| 767 | // Slurm freeing | ||
| 768 | ✗ | char *mask_str = mu_parse_to_slurm_format(&free_cpu_mask); | |
| 769 | ✗ | if (mask_str == NULL) { | |
| 770 | ✗ | warning("error parsing mask %s to Slurm format", mu_to_str(&free_cpu_mask)); | |
| 771 | ✗ | return DLB_ERR_UNKNOWN; | |
| 772 | } | ||
| 773 | ✗ | if (!secure_getenv("SLURM_JOBID")) { | |
| 774 | ✗ | warning("SLURM_JOBID is mandatory"); | |
| 775 | ✗ | return DLB_ERR_UNKNOWN; | |
| 776 | } | ||
| 777 | char hostname[HOST_NAME_MAX]; | ||
| 778 | ✗ | gethostname(hostname, HOST_NAME_MAX); | |
| 779 | char *args[5]; | ||
| 780 | ✗ | asprintf(&args[0], "scontrol"); | |
| 781 | ✗ | asprintf(&args[1], "update"); | |
| 782 | ✗ | asprintf(&args[2], "jobid=%s", secure_getenv("SLURM_JOBID")); | |
| 783 | ✗ | asprintf(&args[3], "dealloc=%s:%s", hostname, mask_str); | |
| 784 | ✗ | args[4] = NULL; | |
| 785 | |||
| 786 | ✗ | int res_pid = fork(); | |
| 787 | ✗ | if (res_pid < 0) { | |
| 788 | ✗ | warning("fork error while invoking scontrol"); | |
| 789 | ✗ | return DLB_ERR_UNKNOWN; | |
| 790 | ✗ | } else if (res_pid == 0) { | |
| 791 | ✗ | verbose(VB_DROM, "%s %s %s %s", args[0], args[1], args[2], args[3]); | |
| 792 | ✗ | execvp("scontrol", args); | |
| 793 | } | ||
| 794 | |||
| 795 | ✗ | for (int i = 0; i < 5; ++i) { | |
| 796 | ✗ | free(args[i]); | |
| 797 | } | ||
| 798 | ✗ | free(mask_str); | |
| 799 | } | ||
| 800 | |||
| 801 | 14 | return error; | |
| 802 | } | ||
| 803 | |||
| 804 | |||
| 805 | /* Misc */ | ||
| 806 | |||
| 807 | 24 | int check_cpu_availability(const subprocess_descriptor_t *spd, int cpuid) { | |
| 808 | 24 | int error = DLB_SUCCESS; | |
| 809 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 23 times.
|
24 | if (!spd->options.lewi) { |
| 810 | 1 | error = DLB_ERR_NOLEWI; | |
| 811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | } else if (!spd->lewi_enabled) { |
| 812 | ✗ | error = DLB_ERR_DISBLD; | |
| 813 | } else { | ||
| 814 | 23 | error = spd->lb_funcs.check_cpu_availability(spd, cpuid); | |
| 815 | } | ||
| 816 | 24 | return error; | |
| 817 | } | ||
| 818 | |||
| 819 | 5 | int print_shmem(subprocess_descriptor_t *spd, int num_columns, | |
| 820 | dlb_printshmem_flags_t print_flags) { | ||
| 821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!spd->dlb_initialized) { |
| 822 | ✗ | options_init(&spd->options, NULL); | |
| 823 | ✗ | debug_init(&spd->options); | |
| 824 | } | ||
| 825 | |||
| 826 | 5 | shmem_cpuinfo__print_info(spd->options.shm_key, spd->options.lewi_color, | |
| 827 | num_columns, print_flags); | ||
| 828 | 5 | shmem_procinfo__print_info(spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 829 | 5 | shmem_barrier__print_info(spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 830 | 5 | shmem_talp__print_info(spd->options.shm_key, spd->options.shm_size_multiplier); | |
| 831 | |||
| 832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!spd->dlb_initialized) { |
| 833 | ✗ | options_finalize(&spd->options); | |
| 834 | } | ||
| 835 | |||
| 836 | 5 | return DLB_SUCCESS; | |
| 837 | } | ||
| 838 | |||
| 839 | 11 | int set_observer_role(bool is_observer) { | |
| 840 | 11 | thread_is_observer = is_observer; | |
| 841 | 11 | return DLB_SUCCESS; | |
| 842 | } | ||
| 843 | |||
| 844 | ✗ | int get_gpu_affinity(char *buffer, size_t buffer_size, bool full_uuid) { | |
| 845 | ✗ | return talp_backend_manager_get_gpu_affinity(buffer, buffer_size, full_uuid); | |
| 846 | } | ||
| 847 | |||
| 848 | ✗ | void print_dlb_variables(subprocess_descriptor_t *spd, bool print_extended) { | |
| 849 | |||
| 850 | options_t options; | ||
| 851 | ✗ | options_init(&options, NULL); | |
| 852 | |||
| 853 | /* dlb is not intialized, this step is needed to print the correct host:pid */ | ||
| 854 | ✗ | if (spd->id == 0) { | |
| 855 | ✗ | spd->id = getpid(); | |
| 856 | } | ||
| 857 | ✗ | debug_init(&options); | |
| 858 | |||
| 859 | ✗ | options_print_variables(&options, print_extended); | |
| 860 | |||
| 861 | ✗ | options_finalize(&options); | |
| 862 | } | ||
| 863 |