Skip to content

Commit

Permalink
Warn when DNET is enabling and there is a physical action
Browse files Browse the repository at this point in the history
  • Loading branch information
byeonggiljun committed Jan 17, 2025
1 parent 79d9851 commit 0d772cd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
18 changes: 18 additions & 0 deletions core/src/main/java/org/lflang/federated/extensions/CExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.lflang.federated.generator.FederationFileConfig;
import org.lflang.federated.launcher.RtiConfig;
import org.lflang.federated.serialization.FedROS2CPPSerialization;
import org.lflang.generator.ActionInstance;
import org.lflang.generator.CodeBuilder;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.generator.ReactorInstance;
Expand All @@ -60,6 +61,7 @@
import org.lflang.target.property.ClockSyncOptionsProperty;
import org.lflang.target.property.CoordinationOptionsProperty;
import org.lflang.target.property.CoordinationProperty;
import org.lflang.target.property.DNETProperty;
import org.lflang.target.property.FedSetupProperty;
import org.lflang.target.property.KeepaliveProperty;
import org.lflang.target.property.SingleThreadedProperty;
Expand Down Expand Up @@ -833,6 +835,22 @@ private String generateCodeForPhysicalActions(
outputFound = output;
}
}
if (federate.targetConfig.getOrDefault(DNETProperty.INSTANCE)) {
ActionInstance found = federate.findPhysicalAction(instance);
if (found != null) {
String warning =
String.join(
"\n",
"Found a physical action inside the federate "
+ addDoubleQuotes(instance.getName()),
"and a signal downstream next event tag (DNET) will be used.",
"The signal DNET may increase the lag, the time difference between ",
"the time this physical action is scheduled and the time it is executed, ",
"specifically when this federate has multiple upstream reactors.",
"Consider disabling the signal DNET with a property {DNET: false}.");
messageReporter.at(found.getDefinition()).warning(warning);
}
}
if (minDelay != TimeValue.MAX_VALUE) {
// Unless silenced, issue a warning.
if (coordinationOptions.advanceMessageInterval == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,27 @@ private boolean containsAllVarRefs(Iterable<VarRef> varRefs) {
return inFederate;
}

/**
* Return the first found physical action or null if there is no physical action in this federate.
*
* @param instance The reactor instance to check whether there is a physical action.
*/
public ActionInstance findPhysicalAction(ReactorInstance instance) {
for (ActionInstance action : instance.actions) {
if (action.isPhysical()) {
return action;
}
}
for (ReactorInstance child : instance.children) {
for (ActionInstance action : child.actions) {
if (action.isPhysical()) {
return action;
}
}
}
return null;
}

/**
* Find output ports that are connected to a physical action trigger upstream in the same reactor.
* Return a list of such outputs paired with the minimum delay from the nearest physical action.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/c/reactor-c

0 comments on commit 0d772cd

Please sign in to comment.