Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
byeonggiljun committed Aug 15, 2024
1 parent a2ab5bc commit 5d52945
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
46 changes: 24 additions & 22 deletions core/federated/RTI/rti_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ void update_scheduling_node_next_event_tag_locked(scheduling_node_t* e, tag_t ne
if (target_upstream_id == e->id) {
continue;
}
downstream_next_event_tag_if_needed(rti_common->scheduling_nodes[target_upstream_id], e->id);
scheduling_node_t* node = rti_common->scheduling_nodes[target_upstream_id];
tag_t dnet = downstream_next_event_tag(node, e->id);
if (lf_tag_compare(node->last_DNET, dnet) != 0 && lf_tag_compare(node->next_event, dnet) <= 0) {
notify_downstream_next_event_tag(node, dnet);
}
}
}
}
Expand Down Expand Up @@ -458,7 +462,7 @@ void update_all_downstreams(scheduling_node_t* node) {
}
}

tag_t get_DNET_candidate(tag_t received_tag, tag_t minimum_delay) {
tag_t get_dnet_candidate(tag_t received_tag, tag_t minimum_delay) {
// (A.t, A.m) - (B.t - B.m)
// B cannot be NEVER_TAG as (0, 0) denotes no delay.
// Also, we assume B is not FOREVER_TAG because FOREVER_TAG delay means that there is no connection.
Expand Down Expand Up @@ -490,49 +494,47 @@ tag_t get_DNET_candidate(tag_t received_tag, tag_t minimum_delay) {
return result;
}

void downstream_next_event_tag_if_needed(scheduling_node_t* node, uint16_t new_NET_source_federate_id) {
tag_t downstream_next_event_tag(scheduling_node_t* node, uint16_t node_sending_new_net_id) {
if (is_in_zero_delay_cycle(node)) {
return;
return NEVER_TAG;
}

tag_t DNET = FOREVER_TAG;
scheduling_node_t* new_NET_source_federate = rti_common->scheduling_nodes[new_NET_source_federate_id];
if (is_in_zero_delay_cycle(new_NET_source_federate)) {
return;
tag_t result = FOREVER_TAG;
scheduling_node_t* node_sending_new_net = rti_common->scheduling_nodes[node_sending_new_net_id];
if (is_in_zero_delay_cycle(node_sending_new_net)) {
return NEVER_TAG;
}

int index = node->id * rti_common->number_of_scheduling_nodes + new_NET_source_federate_id;
tag_t DNET_candidate = get_DNET_candidate(new_NET_source_federate->next_event, rti_common->min_delays[index]);
int index = node->id * rti_common->number_of_scheduling_nodes + node_sending_new_net_id;
tag_t candidate = get_dnet_candidate(node_sending_new_net->next_event, rti_common->min_delays[index]);

if (lf_tag_compare(node->last_DNET, DNET_candidate) >= 0) {
DNET = DNET_candidate;
if (lf_tag_compare(node->last_DNET, candidate) >= 0) {
result = candidate;
} else {
for (int i = 0; i < node->num_all_downstreams; i++) {
uint16_t target_downstream_id = node->all_downstreams[i];
scheduling_node_t* target_dowstream = rti_common->scheduling_nodes[target_downstream_id];

if (is_in_zero_delay_cycle(target_dowstream)) {
// This node is an upstream of ZDC. Do not send DNET to this node.
return;
return NEVER_TAG;
}

index = node->id * rti_common->number_of_scheduling_nodes + target_downstream_id;
DNET_candidate = get_DNET_candidate(target_dowstream->next_event, rti_common->min_delays[index]);
candidate = get_dnet_candidate(target_dowstream->next_event, rti_common->min_delays[index]);

if (lf_tag_compare(DNET, DNET_candidate) > 0) {
DNET = DNET_candidate;
if (lf_tag_compare(result, candidate) > 0) {
result = candidate;
}
}
}
if (DNET.time < start_time) {
if (result.time < start_time) {
// DNET with the time smaller than the start time acts as the same as DNET of the NEVER tag.
// Thus, set DNET as NEVER_TAG to prevent sending unnecessary DNETs.
DNET = NEVER_TAG;
// Thus, set the result as NEVER_TAG to prevent sending unnecessary DNETs.
result = NEVER_TAG;
}

if (lf_tag_compare(node->last_DNET, DNET) != 0 && lf_tag_compare(node->next_event, DNET) <= 0) {
notify_downstream_next_event_tag(node, DNET);
}
return result;
}

bool is_in_zero_delay_cycle(scheduling_node_t* node) {
Expand Down
8 changes: 4 additions & 4 deletions core/federated/RTI/rti_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void update_all_downstreams(scheduling_node_t* node);
* @param received_tag
* @param minimum_delay
*/
tag_t get_DNET_candidate(tag_t received_tag, tag_t minimum_delay);
tag_t get_dnet_candidate(tag_t received_tag, tag_t minimum_delay);

/**
* @param e The target node.
Expand All @@ -302,11 +302,11 @@ void notify_downstream_next_event_tag(scheduling_node_t* e, tag_t tag);

/**
* @param node The target node that may receive a new DNET.
* @param new_NET_source_federate_id The ID of the federate that sends a new NET. If this federate's new NET does not
* change the DNET value, we can exit this function immediately. If it does, we have to look up the target federate's
* @param node_sending_new_net_id The ID of the node that sends a new NET. If this node's new NET does not
* change the DNET value, we can exit this function immediately. If it does, we have to look up the target node's
* downstream federates to compute the exact new DNET value.
*/
void downstream_next_event_tag_if_needed(scheduling_node_t* node, uint16_t new_NET_source_federate_id);
tag_t downstream_next_event_tag(scheduling_node_t* node, uint16_t node_sending_new_net_id);

/**
* For the given scheduling node (enclave or federate), invalidate the `min_delays`,
Expand Down
2 changes: 1 addition & 1 deletion core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ tag_t lf_send_next_event_tag(environment_t* env, tag_t tag, bool wait_for_reply)
_fed.last_skipped_NET = NEVER_TAG;
LF_PRINT_LOG("Sent the last skipped next event tag (NET) " PRINTF_TAG
" to RTI based on the last DNET " PRINTF_TAG ".",
_fed.last_DNET - start_time, _fed.last_DNET.microstep, tag.time - start_time, tag.microstep);
_fed.last_DNET.time - start_time, _fed.last_DNET.microstep, tag.time - start_time, tag.microstep);
}
return _fed.last_TAG;
}
Expand Down

0 comments on commit 5d52945

Please sign in to comment.