Line data Source code
1 1 : /** 2 : * @file gvt/fossil.c 3 : * 4 : * @brief Housekeeping operations 5 : * 6 : * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com> 7 : * SPDX-License-Identifier: GPL-3.0-only 8 : */ 9 : 10 : #include <gvt/fossil.h> 11 : 12 : #include <datatypes/remote_msg_map.h> 13 : #include <gvt/gvt.h> 14 : #include <lp/lp.h> 15 : #include <lp/process.h> 16 : #include <mm/model_allocator.h> 17 : #include <mm/msg_allocator.h> 18 : 19 : #include <memory.h> 20 : 21 0 : #define cant_discard_ref_i(ref_i) \ 22 : array_get_at(proc_p->past_msgs, ref_i)->dest_t >= current_gvt 23 : 24 0 : static inline array_count_t first_discardable_ref(simtime_t current_gvt, 25 : struct process_data *proc_p) 26 : { 27 : array_count_t j = array_count(proc_p->past_msgs) - 1; 28 : while(cant_discard_ref_i(j)){ 29 : --j; 30 : } 31 : return j; 32 : } 33 : 34 0 : static inline void fossil_lp_collect(simtime_t current_gvt) 35 : { 36 : struct process_data *proc_p = ¤t_lp->p; 37 : array_count_t past_i = first_discardable_ref(current_gvt, proc_p); 38 : past_i = model_allocator_fossil_lp_collect(past_i); 39 : array_count_t sent_i = array_count(proc_p->sent_msgs); 40 : array_count_t j = array_count(proc_p->past_msgs); 41 : do{ 42 : --sent_i; 43 : j -= (array_get_at(proc_p->sent_msgs, sent_i) == NULL); 44 : } while(j > past_i); 45 : array_truncate_first(proc_p->sent_msgs, sent_i); 46 : 47 : while(j--){ 48 : msg_allocator_free(array_get_at(proc_p->past_msgs, j)); 49 : } 50 : array_truncate_first(proc_p->past_msgs, past_i); 51 : } 52 : 53 0 : void fossil_collect(simtime_t current_gvt) 54 : { 55 : #ifdef ROOTSIM_MPI 56 : remote_msg_map_fossil_collect(current_gvt); 57 : msg_allocator_fossil_collect(current_gvt); 58 : #endif 59 : 60 : for (uint64_t i = lp_id_first; i < lp_id_end; ++i) { 61 : current_lp = &lps[i]; 62 : fossil_lp_collect(current_gvt); 63 : } 64 : }