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 "LB_core/lb_funcs.h" | ||
21 | #include "LB_policies/lewi.h" | ||
22 | #include "LB_policies/lewi_async.h" | ||
23 | #include "LB_policies/lewi_mask.h" | ||
24 | #include "apis/dlb_errors.h" | ||
25 | |||
26 | 6 | static int disabled() { return DLB_ERR_NOPOL; } | |
27 | 68 | static int dummy(struct SubProcessDescriptor *spd) { return DLB_SUCCESS; } | |
28 | |||
29 | typedef int (*lb_func_kind1)(const struct SubProcessDescriptor*); | ||
30 | typedef int (*lb_func_kind2)(const struct SubProcessDescriptor*, int); | ||
31 | typedef int (*lb_func_kind3)(const struct SubProcessDescriptor*, const cpu_set_t*); | ||
32 | typedef int (*lb_func_kind4)(const struct SubProcessDescriptor*, int, const cpu_set_t*); | ||
33 | |||
34 | 86 | void set_lb_funcs(balance_policy_t *lb_funcs, policy_t policy) { | |
35 | // Initialize all fields to a valid, but disabled, function | ||
36 | 86 | *lb_funcs = (balance_policy_t){ | |
37 | .init = dummy, | ||
38 | .finalize = dummy, | ||
39 | .enable = (lb_func_kind1)disabled, | ||
40 | .disable = (lb_func_kind1)disabled, | ||
41 | .set_max_parallelism = (lb_func_kind2)disabled, | ||
42 | .unset_max_parallelism = (lb_func_kind1)disabled, | ||
43 | .into_communication = (lb_func_kind1)disabled, | ||
44 | .out_of_communication = (lb_func_kind1)disabled, | ||
45 | .into_blocking_call = (lb_func_kind1)disabled, | ||
46 | .out_of_blocking_call = (lb_func_kind1)disabled, | ||
47 | .lend = (lb_func_kind1)disabled, | ||
48 | .lend_cpu = (lb_func_kind2)disabled, | ||
49 | .lend_cpus = (lb_func_kind2)disabled, | ||
50 | .lend_cpu_mask = (lb_func_kind3)disabled, | ||
51 | .reclaim = (lb_func_kind1)disabled, | ||
52 | .reclaim_cpu = (lb_func_kind2)disabled, | ||
53 | .reclaim_cpus = (lb_func_kind2)disabled, | ||
54 | .reclaim_cpu_mask = (lb_func_kind3)disabled, | ||
55 | .acquire_cpu = (lb_func_kind2)disabled, | ||
56 | .acquire_cpus = (lb_func_kind2)disabled, | ||
57 | .acquire_cpu_mask = (lb_func_kind3)disabled, | ||
58 | .acquire_cpus_in_mask = (lb_func_kind4)disabled, | ||
59 | .borrow = (lb_func_kind1)disabled, | ||
60 | .borrow_cpu = (lb_func_kind2)disabled, | ||
61 | .borrow_cpus = (lb_func_kind2)disabled, | ||
62 | .borrow_cpu_mask = (lb_func_kind3)disabled, | ||
63 | .borrow_cpus_in_mask = (lb_func_kind4)disabled, | ||
64 | .return_all = (lb_func_kind1)disabled, | ||
65 | .return_cpu = (lb_func_kind2)disabled, | ||
66 | .return_cpu_mask = (lb_func_kind3)disabled, | ||
67 | .check_cpu_availability = (lb_func_kind2)disabled, | ||
68 | .update_ownership = (lb_func_kind3)disabled, | ||
69 | }; | ||
70 | |||
71 | // Set according to policy | ||
72 |
4/5✓ Branch 0 taken 41 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
|
86 | switch(policy) { |
73 | 41 | case POLICY_NONE: | |
74 | 41 | break; | |
75 | 27 | case POLICY_LEWI: | |
76 | 27 | lb_funcs->init = lewi_Init; | |
77 | 27 | lb_funcs->finalize = lewi_Finalize; | |
78 | 27 | lb_funcs->enable = lewi_EnableDLB; | |
79 | 27 | lb_funcs->disable = lewi_DisableDLB; | |
80 | 27 | lb_funcs->set_max_parallelism = lewi_SetMaxParallelism; | |
81 | 27 | lb_funcs->unset_max_parallelism = lewi_UnsetMaxParallelism; | |
82 | 27 | lb_funcs->into_blocking_call = lewi_IntoBlockingCall; | |
83 | 27 | lb_funcs->out_of_blocking_call = lewi_OutOfBlockingCall; | |
84 | 27 | lb_funcs->lend = lewi_Lend; | |
85 | 27 | lb_funcs->reclaim = lewi_Reclaim; | |
86 | 27 | lb_funcs->borrow = lewi_Borrow; | |
87 | 27 | lb_funcs->borrow_cpus = lewi_BorrowCpus; | |
88 | 27 | break; | |
89 | 4 | case POLICY_LEWI_ASYNC: | |
90 | 4 | lb_funcs->init = lewi_async_Init; | |
91 | 4 | lb_funcs->finalize = lewi_async_Finalize; | |
92 | 4 | lb_funcs->enable = lewi_async_Enable; | |
93 | 4 | lb_funcs->disable = lewi_async_Disable; | |
94 | 4 | lb_funcs->into_blocking_call = lewi_async_IntoBlockingCall; | |
95 | 4 | lb_funcs->out_of_blocking_call = lewi_async_OutOfBlockingCall; | |
96 | 4 | lb_funcs->lend = lewi_async_Lend; | |
97 | 4 | lb_funcs->lend_cpus = lewi_async_LendCpus; | |
98 | 4 | lb_funcs->reclaim = lewi_async_Reclaim; | |
99 | 4 | lb_funcs->acquire_cpus = lewi_async_AcquireCpus; | |
100 | 4 | lb_funcs->borrow = lewi_async_Borrow; | |
101 | 4 | lb_funcs->borrow_cpus = lewi_async_BorrowCpus; | |
102 | 4 | break; | |
103 | 14 | case POLICY_LEWI_MASK: | |
104 | 14 | lb_funcs->init = lewi_mask_Init; | |
105 | 14 | lb_funcs->finalize = lewi_mask_Finalize; | |
106 | 14 | lb_funcs->enable = lewi_mask_EnableDLB; | |
107 | 14 | lb_funcs->disable = lewi_mask_DisableDLB; | |
108 | 14 | lb_funcs->set_max_parallelism = lewi_mask_SetMaxParallelism; | |
109 | 14 | lb_funcs->unset_max_parallelism = lewi_mask_UnsetMaxParallelism; | |
110 | 14 | lb_funcs->into_blocking_call = lewi_mask_IntoBlockingCall; | |
111 | 14 | lb_funcs->out_of_blocking_call = lewi_mask_OutOfBlockingCall; | |
112 | 14 | lb_funcs->lend = lewi_mask_Lend; | |
113 | 14 | lb_funcs->lend_cpu = lewi_mask_LendCpu; | |
114 | 14 | lb_funcs->lend_cpu_mask = lewi_mask_LendCpuMask; | |
115 | 14 | lb_funcs->reclaim = lewi_mask_Reclaim; | |
116 | 14 | lb_funcs->reclaim_cpu = lewi_mask_ReclaimCpu; | |
117 | 14 | lb_funcs->reclaim_cpus = lewi_mask_ReclaimCpus; | |
118 | 14 | lb_funcs->reclaim_cpu_mask = lewi_mask_ReclaimCpuMask; | |
119 | 14 | lb_funcs->acquire_cpu = lewi_mask_AcquireCpu; | |
120 | 14 | lb_funcs->acquire_cpus = lewi_mask_AcquireCpus; | |
121 | 14 | lb_funcs->acquire_cpu_mask = lewi_mask_AcquireCpuMask; | |
122 | 14 | lb_funcs->acquire_cpus_in_mask = lewi_mask_AcquireCpusInMask; | |
123 | 14 | lb_funcs->borrow = lewi_mask_Borrow; | |
124 | 14 | lb_funcs->borrow_cpu = lewi_mask_BorrowCpu; | |
125 | 14 | lb_funcs->borrow_cpus = lewi_mask_BorrowCpus; | |
126 | 14 | lb_funcs->borrow_cpu_mask = lewi_mask_BorrowCpuMask; | |
127 | 14 | lb_funcs->borrow_cpus_in_mask = lewi_mask_BorrowCpusInMask; | |
128 | 14 | lb_funcs->return_all = lewi_mask_Return; | |
129 | 14 | lb_funcs->return_cpu = lewi_mask_ReturnCpu; | |
130 | 14 | lb_funcs->return_cpu_mask = lewi_mask_ReturnCpuMask; | |
131 | 14 | lb_funcs->check_cpu_availability = lewi_mask_CheckCpuAvailability; | |
132 | 14 | lb_funcs->update_ownership = lewi_mask_UpdateOwnership; | |
133 | 14 | break; | |
134 | } | ||
135 | 86 | } | |
136 |