GCC Code Coverage Report


Directory: src/
File: src/apis/DLB_interface_drom.c
Date: 2024-11-22 17:07:10
Exec Total Coverage
Lines: 41 48 85.4%
Functions: 6 9 66.7%
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/options.h"
30 #include "support/debug.h"
31 #include "support/env.h"
32 #include "support/mask_utils.h"
33
34 #include <sched.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39
40 #pragma GCC visibility push(default)
41
42 18 int DLB_DROM_Attach(void) {
43 char shm_key[MAX_OPTION_LENGTH];
44 18 options_parse_entry("--shm-key", &shm_key);
45 int shmem_color;
46 18 options_parse_entry("--lewi-color", &shmem_color);
47 18 shmem_cpuinfo_ext__init(shm_key, shmem_color);
48 18 shmem_procinfo_ext__init(shm_key);
49 18 return DLB_SUCCESS;
50 }
51
52 18 int DLB_DROM_Detach(void) {
53 18 int error = shmem_cpuinfo_ext__finalize();
54
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 error = error ? error : shmem_procinfo_ext__finalize();
55 18 return error;
56 }
57
58 int DLB_DROM_GetNumCpus(int *ncpus) {
59 *ncpus = mu_get_system_size();
60 return DLB_SUCCESS;
61 }
62
63 int DLB_DROM_GetPidList(int *pidlist, int *nelems, int max_len) {
64 return shmem_procinfo__getpidlist(pidlist, nelems, max_len);
65 }
66
67 11 int DLB_DROM_GetProcessMask(int pid, dlb_cpu_set_t mask, dlb_drom_flags_t flags) {
68 11 int error = shmem_procinfo__getprocessmask(pid, mask, flags);
69
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
11 if (error == DLB_ERR_NOSHMEM) {
70 2 DLB_DROM_Attach();
71 2 error = shmem_procinfo__getprocessmask(pid, mask, flags);
72 2 DLB_DROM_Detach();
73 }
74 11 return error;
75 }
76
77 8 int DLB_DROM_SetProcessMask(int pid, const_dlb_cpu_set_t mask, dlb_drom_flags_t flags) {
78 8 spd_enter_dlb(thread_spd);
79 8 int error = drom_setprocessmask(pid, mask, flags);
80
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
8 if (error == DLB_ERR_NOSHMEM) {
81 5 DLB_DROM_Attach();
82 5 error = drom_setprocessmask(pid, mask, flags);
83 5 DLB_DROM_Detach();
84 }
85 8 return error;
86 }
87
88 6 int DLB_DROM_PreInit(int pid, const_dlb_cpu_set_t mask, dlb_drom_flags_t flags,
89 char ***next_environ) {
90 /* Set up DROM args */
91 char drom_args[64];
92 6 int __attribute__((unused)) n = snprintf(drom_args, 64, "--drom=1 --preinit-pid=%d %s",
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 pid, flags & DLB_RETURN_STOLEN ? "--debug-opts=return-stolen" : "");
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 ensure(n<64, "snprintf overflow");
95 6 dlb_setenv("DLB_ARGS", drom_args, next_environ, ENV_APPEND);
96
97 /* Set up OMP_NUM_THREADS new value, only if mask is valid and variable is already set */
98
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int new_num_threads = mask ? CPU_COUNT(mask) : 0;
99 char omp_value[8];
100 6 snprintf(omp_value, 8, "%d", new_num_threads);
101
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (new_num_threads > 0) {
102 5 dlb_setenv("OMP_NUM_THREADS", omp_value, next_environ, ENV_UPDATE_IF_EXISTS);
103 }
104
105 6 int error = shmem_procinfo_ext__preinit(pid, mask, flags);
106
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 error = error ? error : shmem_cpuinfo_ext__preinit(pid, mask, flags);
107 6 return error;
108 }
109
110 4 int DLB_DROM_PostFinalize(int pid, dlb_drom_flags_t flags) {
111 4 int error = shmem_procinfo_ext__postfinalize(pid, flags & DLB_RETURN_STOLEN);
112
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 error = error ? error : shmem_cpuinfo_ext__postfinalize(pid);
113 4 return error;
114 }
115
116 int DLB_DROM_RecoverStolenCpus(int pid) {
117 return shmem_procinfo_ext__recover_stolen_cpus(pid);
118 }
119
120 #pragma GCC visibility pop
121