| 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 | #include "unique_shmem.h" | ||
| 21 | |||
| 22 | #include "LB_comm/shmem.h" | ||
| 23 | #include "LB_comm/shmem_procinfo.h" | ||
| 24 | #include "LB_comm/shmem_cpuinfo.h" | ||
| 25 | #include "LB_comm/shmem_barrier.h" | ||
| 26 | #include "LB_comm/shmem_talp.h" | ||
| 27 | #include "support/mask_utils.h" | ||
| 28 | #include "support/types.h" | ||
| 29 | #include "apis/dlb_errors.h" | ||
| 30 | |||
| 31 | #include <sched.h> | ||
| 32 | #include <sys/types.h> | ||
| 33 | #include <stdint.h> | ||
| 34 | #include <assert.h> | ||
| 35 | |||
| 36 | /* array_cpuid_t */ | ||
| 37 | #define ARRAY_T cpuid_t | ||
| 38 | #include "support/array_template.h" | ||
| 39 | |||
| 40 | /* array_cpuinfo_task_t */ | ||
| 41 | #define ARRAY_T cpuinfo_task_t | ||
| 42 | #define ARRAY_KEY_T pid_t | ||
| 43 | #include "support/array_template.h" | ||
| 44 | |||
| 45 | 1 | int main(int argc, char *argv[]) { | |
| 46 | |||
| 47 | enum { SHMEM_SIZE_MULTIPLIER = 1 }; | ||
| 48 | enum { SHMEM_TALP_SIZE_MULTIPLIER = 10 }; | ||
| 49 | |||
| 50 | /* System size */ | ||
| 51 | enum { SYS_SIZE = 64 }; | ||
| 52 | 1 | mu_init(); | |
| 53 | 1 | mu_testing_set_sys_size(SYS_SIZE); | |
| 54 | array_cpuinfo_task_t tasks; | ||
| 55 | 1 | array_cpuinfo_task_t_init(&tasks, SYS_SIZE); | |
| 56 | |||
| 57 | /* Initialize local masks */ | ||
| 58 | 1 | pid_t p1_pid = 11111; | |
| 59 | cpu_set_t p1_mask; | ||
| 60 | 1 | mu_parse_mask("0-15,32-39,48,49", &p1_mask); | |
| 61 | 1 | pid_t p2_pid = 22222; | |
| 62 | cpu_set_t p2_mask; | ||
| 63 | 1 | mu_parse_mask("16-31,40-47,50,51", &p2_mask); | |
| 64 | |||
| 65 | /* check masks correctness */ | ||
| 66 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p1_mask) == 26 ); |
| 67 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p2_mask) == 26 ); |
| 68 | cpu_set_t p1_p2_mask; | ||
| 69 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
|
17 | CPU_OR(&p1_p2_mask, &p1_mask, &p2_mask); |
| 70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p1_p2_mask) == 52 ); |
| 71 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
|
17 | CPU_AND(&p1_p2_mask, &p1_mask, &p2_mask); |
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( CPU_COUNT(&p1_p2_mask) == 0 ); |
| 73 | |||
| 74 | /* Other shmem parameters */ | ||
| 75 | array_cpuid_t cpus_priority_array; | ||
| 76 | 1 | array_cpuid_t_init(&cpus_priority_array, SYS_SIZE); | |
| 77 | 1 | int64_t last_borrow_value = 0; | |
| 78 | 1 | int64_t *last_borrow = &last_borrow_value; | |
| 79 | int requested_ncpus; | ||
| 80 | |||
| 81 | /* Initialize shared memories */ | ||
| 82 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__init(p1_pid, 0, &p1_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 83 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__init(p2_pid, 0, &p2_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 84 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p1_pid, 0, &p1_mask, NULL, SHMEM_KEY, |
| 85 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p2_pid, 0, &p2_mask, NULL, SHMEM_KEY, |
| 87 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 88 | 1 | shmem_barrier__init(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 89 | 1 | barrier_t *default_barrier = shmem_barrier__register("Barrier 0", 0); | |
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( default_barrier != NULL ); |
| 91 | 1 | barrier_t *barrier1 = shmem_barrier__register("Barrier 1", DLB_BARRIER_LEWI_OFF); | |
| 92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( barrier1 != NULL ); |
| 93 | /* p1_pid and p2_pid */ | ||
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__init(SHMEM_KEY, SHMEM_TALP_SIZE_MULTIPLIER) == DLB_SUCCESS ); |
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__init(SHMEM_KEY, SHMEM_TALP_SIZE_MULTIPLIER) == DLB_SUCCESS ); |
| 96 | |||
| 97 | /* Enable request queues */ | ||
| 98 | 1 | shmem_cpuinfo__enable_request_queues(); | |
| 99 | |||
| 100 | /* P2 requests 12 CPUs in the subset [4-15] */ | ||
| 101 | 1 | requested_ncpus = 12; | |
| 102 | 1 | array_cpuid_t_clear(&cpus_priority_array); | |
| 103 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1 times.
|
13 | for (int i=4; i<4+requested_ncpus; ++i) array_cpuid_t_push(&cpus_priority_array, i); |
| 104 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p2_pid, &requested_ncpus, |
| 105 | &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, | ||
| 106 | last_borrow, &tasks) == DLB_NOTED ); | ||
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 108 | |||
| 109 | /* CPUs 0-3 are lent (they remain idle) */ | ||
| 110 | 1 | cpu_set_t cpus_to_lend = { .__bits = {0xf} }; | |
| 111 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__lend_cpu_mask(p1_pid, &cpus_to_lend, &tasks) == DLB_SUCCESS ); |
| 112 | |||
| 113 | /* CPUs 8-11 are lent and guested by P2 */ | ||
| 114 | 1 | cpu_set_t cpus_for_p2 = { .__bits = {0xf00} }; | |
| 115 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__lend_cpu_mask(p1_pid, &cpus_for_p2, &tasks) == DLB_SUCCESS ); |
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 4 ); |
| 117 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (int i=0; i<4; ++i) { |
| 118 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | assert( tasks.items[i].pid == p2_pid && tasks.items[i].cpuid == i+8 |
| 119 | && tasks.items[i].action == ENABLE_CPU ); | ||
| 120 | } | ||
| 121 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 122 | |||
| 123 | /* CPUs 12-15 are lent, guested by P2 and reclaimed */ | ||
| 124 | 1 | cpu_set_t cpus_to_reclaim = { .__bits = {0xf000} }; | |
| 125 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__lend_cpu_mask(p1_pid, &cpus_to_reclaim, &tasks) == DLB_SUCCESS ); |
| 126 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 4 ); |
| 127 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (int i=0; i<4; ++i) { |
| 128 |
3/6✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 | assert( tasks.items[i].pid == p2_pid && tasks.items[i].cpuid == i+12 |
| 129 | && tasks.items[i].action == ENABLE_CPU ); | ||
| 130 | } | ||
| 131 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 132 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__reclaim_cpu_mask(p1_pid, &cpus_to_reclaim, &tasks) == DLB_NOTED ); |
| 133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 8 ); /* 4 enable for p1_pid, 4 disable for p2_pid */ |
| 134 | 1 | array_cpuinfo_task_t_clear(&tasks); | |
| 135 | |||
| 136 | /* P1 requests 4 CPUs in the subset [16-19] */ | ||
| 137 | 1 | requested_ncpus = 4; | |
| 138 | 1 | array_cpuid_t_clear(&cpus_priority_array); | |
| 139 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | for (int i=16; i<16+requested_ncpus; ++i) array_cpuid_t_push(&cpus_priority_array, i); |
| 140 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_ncpus_from_cpu_subset(p1_pid, &requested_ncpus, |
| 141 | &cpus_priority_array, LEWI_AFFINITY_AUTO, 0 /* max_parallelism */, | ||
| 142 | last_borrow, &tasks) == DLB_NOTED ); | ||
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 144 | |||
| 145 | /* P3 registers one CPU and requests CPU 19 also */ | ||
| 146 | 1 | pid_t p3_pid = 33333; | |
| 147 | cpu_set_t p3_mask; | ||
| 148 | 1 | mu_parse_mask("63", &p3_mask); | |
| 149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__init(p3_pid, 0, &p3_mask, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__init(p3_pid, 0, &p3_mask, NULL, SHMEM_KEY, |
| 151 | SHMEM_SIZE_MULTIPLIER) == DLB_SUCCESS ); | ||
| 152 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__acquire_cpu(p3_pid, 19, &tasks) == DLB_NOTED ); |
| 153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( tasks.count == 0 ); |
| 154 | |||
| 155 | /* Register some TALP regions */ | ||
| 156 | 1 | int region_id1 = -1; | |
| 157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__register(p1_pid, 1, "Custom region 1", ®ion_id1) == DLB_SUCCESS ); |
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region_id1 == 0 ); |
| 159 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__set_times(region_id1, 111111, 111111) == DLB_SUCCESS ); |
| 160 | 1 | int region_id2 = -1 ; | |
| 161 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__register(p1_pid, 1, "Region 2", ®ion_id2) == DLB_SUCCESS ); |
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region_id2 == 1 ); |
| 163 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__set_times(region_id2, INT64_MAX, 42) == DLB_SUCCESS ); |
| 164 | 1 | int region_id3 = -1; | |
| 165 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__register(p2_pid, 1, "Custom region 1", ®ion_id3) == DLB_SUCCESS ); |
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | assert( region_id3 == 2 ); |
| 167 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__set_times(region_id3, 0, 4242) == DLB_SUCCESS ); |
| 168 | |||
| 169 | /* Print */ | ||
| 170 | 1 | shmem_cpuinfo__print_info(NULL, 0, 0, DLB_COLOR_AUTO); | |
| 171 | 1 | shmem_procinfo__print_info(NULL, SHMEM_SIZE_MULTIPLIER); | |
| 172 | 1 | shmem_barrier__print_info(NULL, SHMEM_SIZE_MULTIPLIER); | |
| 173 | 1 | shmem_talp__print_info(NULL, SHMEM_TALP_SIZE_MULTIPLIER); | |
| 174 | |||
| 175 | /* Finalize shared memories */ | ||
| 176 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__finalize(p1_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 177 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__finalize(p2_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 178 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_cpuinfo__finalize(p3_pid, SHMEM_KEY, 0) == DLB_SUCCESS ); |
| 179 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p1_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 180 | == DLB_SUCCESS ); | ||
| 181 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p2_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 182 | == DLB_SUCCESS ); | ||
| 183 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_procinfo__finalize(p3_pid, false, SHMEM_KEY, SHMEM_SIZE_MULTIPLIER) |
| 184 | == DLB_SUCCESS ); | ||
| 185 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_barrier__detach(default_barrier) == 0 ); |
| 186 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_barrier__detach(barrier1) == 0 ); |
| 187 | 1 | shmem_barrier__finalize(SHMEM_KEY, SHMEM_SIZE_MULTIPLIER); | |
| 188 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__finalize(p1_pid) == DLB_SUCCESS ); |
| 189 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | assert( shmem_talp__finalize(p2_pid) == DLB_SUCCESS ); |
| 190 | |||
| 191 | 1 | mu_finalize(); | |
| 192 | |||
| 193 | 1 | return 0; | |
| 194 | } | ||
| 195 |