GCC Code Coverage Report


Directory: src/
File: src/apis/DLB_interface_drom.c
Date: 2025-11-21 10:34:40
Exec Total Coverage
Lines: 48 52 92.3%
Functions: 8 10 80.0%
Branches: 12 18 66.7%

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 /* Dynamic Resource Ownership Manager API */
21
22 #include "apis/dlb_drom.h"
23
24 #include "LB_comm/shmem_cpuinfo.h"
25 #include "LB_comm/shmem_procinfo.h"
26 #include "LB_core/spd.h"
27 #include "LB_core/DLB_kernel.h"
28 #include "apis/dlb_errors.h"
29 #include "support/debug.h"
30 #include "support/dlb_common.h"
31 #include "support/env.h"
32 #include "support/mask_utils.h"
33 #include "support/options.h"
34
35 #include <sched.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40
41 DLB_EXPORT_SYMBOL
42 19 int DLB_DROM_Attach(void) {
43 char shm_key[MAX_OPTION_LENGTH];
44 19 options_parse_entry("--shm-key", &shm_key);
45 int shm_size_multiplier;
46 19 options_parse_entry("--shm-size-multiplier", &shm_size_multiplier);
47 int shmem_color;
48 19 options_parse_entry("--lewi-color", &shmem_color);
49 19 shmem_cpuinfo_ext__init(shm_key, shmem_color);
50 19 shmem_procinfo_ext__init(shm_key, shm_size_multiplier);
51 19 return DLB_SUCCESS;
52 }
53
54 DLB_EXPORT_SYMBOL
55 19 int DLB_DROM_Detach(void) {
56 19 int error = shmem_cpuinfo_ext__finalize();
57
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 error = error ? error : shmem_procinfo_ext__finalize();
58 19 return error;
59 }
60
61 DLB_EXPORT_SYMBOL
62 1 int DLB_DROM_GetNumCpus(int *ncpus) {
63 1 *ncpus = mu_get_system_size();
64 1 return DLB_SUCCESS;
65 }
66
67 DLB_EXPORT_SYMBOL
68 int DLB_DROM_GetPidList(int *pidlist, int *nelems, int max_len) {
69 return shmem_procinfo__getpidlist(pidlist, nelems, max_len);
70 }
71
72 DLB_EXPORT_SYMBOL
73 11 int DLB_DROM_GetProcessMask(int pid, dlb_cpu_set_t mask, dlb_drom_flags_t flags) {
74 11 int error = shmem_procinfo__getprocessmask(pid, mask, flags);
75
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
11 if (error == DLB_ERR_NOSHMEM) {
76 2 DLB_DROM_Attach();
77 2 error = shmem_procinfo__getprocessmask(pid, mask, flags);
78 2 DLB_DROM_Detach();
79 }
80 11 return error;
81 }
82
83 DLB_EXPORT_SYMBOL
84 9 int DLB_DROM_SetProcessMask(int pid, const_dlb_cpu_set_t mask, dlb_drom_flags_t flags) {
85 9 spd_enter_dlb(thread_spd);
86 9 int error = drom_setprocessmask(pid, mask, flags);
87
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if (error == DLB_ERR_NOSHMEM) {
88 5 DLB_DROM_Attach();
89 5 error = drom_setprocessmask(pid, mask, flags);
90 5 DLB_DROM_Detach();
91 }
92 9 return error;
93 }
94
95 DLB_EXPORT_SYMBOL
96 1 int DLB_DROM_SetProcessMaskStr(int pid, const char *mask, dlb_drom_flags_t flags) {
97 cpu_set_t _mask;
98 1 mu_parse_mask(mask, &_mask);
99 1 return DLB_DROM_SetProcessMask(pid, &_mask, flags);
100 }
101
102 DLB_EXPORT_SYMBOL
103 6 int DLB_DROM_PreInit(int pid, const_dlb_cpu_set_t mask, dlb_drom_flags_t flags,
104 char ***next_environ) {
105 /* Set up DROM args */
106 char drom_args[64];
107 6 int __attribute__((unused)) n = snprintf(drom_args, 64, "--drom=1 --preinit-pid=%d %s",
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 pid, flags & DLB_RETURN_STOLEN ? "--debug-opts=return-stolen" : "");
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 ensure(n<64, "snprintf overflow");
110 6 dlb_setenv("DLB_ARGS", drom_args, next_environ, ENV_APPEND);
111
112 /* Set up OMP_NUM_THREADS new value, only if mask is valid and variable is already set */
113
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int new_num_threads = mask ? CPU_COUNT(mask) : 0;
114 char omp_value[8];
115 6 snprintf(omp_value, 8, "%d", new_num_threads);
116
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (new_num_threads > 0) {
117 5 dlb_setenv("OMP_NUM_THREADS", omp_value, next_environ, ENV_UPDATE_IF_EXISTS);
118 }
119
120 6 int error = shmem_procinfo_ext__preinit(pid, mask, flags);
121
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 error = error ? error : shmem_cpuinfo_ext__preinit(pid, mask, flags);
122 6 return error;
123 }
124
125 DLB_EXPORT_SYMBOL
126 4 int DLB_DROM_PostFinalize(int pid, dlb_drom_flags_t flags) {
127 4 int error = shmem_procinfo_ext__postfinalize(pid, flags & DLB_RETURN_STOLEN);
128
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 error = error ? error : shmem_cpuinfo_ext__postfinalize(pid);
129 4 return error;
130 }
131
132 DLB_EXPORT_SYMBOL
133 int DLB_DROM_RecoverStolenCpus(int pid) {
134 return shmem_procinfo_ext__recover_stolen_cpus(pid);
135 }
136