Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary support for scheduling enclaves in the C target #2104

Open
wants to merge 140 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 121 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
011c763
Add enclaved reactor AST transformation and test files
erlingrj Jun 8, 2023
494c15f
Update tracing API
erlingrj Jun 8, 2023
4d78138
Merge branch 'enclaves' into enclaves2
erlingrj Jun 8, 2023
69f64ac
DelayedConnection should use enclaves
erlingrj Jun 8, 2023
50b4e4a
Bump reactor-C
erlingrj Jun 8, 2023
4141b40
Merge branch 'enclaves' into enclaves2
erlingrj Jun 8, 2023
3dc3919
Merge branch 'enclaves' into enclaves2
erlingrj Jun 10, 2023
80103d6
Use a reactor_mutex in the ConnectionReactor to enforce mutual exclu…
erlingrj Jun 10, 2023
b5b6632
Set LF_ENCLAVES compile def
erlingrj Jun 11, 2023
edd9952
Add a test for simple coordination of enclaves
erlingrj Jun 11, 2023
e5f2e89
Code auto-formatted with Spotless
erlingrj Jun 11, 2023
235483b
Initial work on code-generating the enclave topology
erlingrj Jun 13, 2023
bc89970
Code auto-formatted with Spotless
erlingrj Jun 13, 2023
c0ec4f6
Address Peter's comments
erlingrj Jun 14, 2023
b518935
Get SimpleCoordination working and add some failing tests
erlingrj Jun 16, 2023
240e973
Code auto-formatted with Spotless
erlingrj Jun 16, 2023
b16434e
Add validation checks and a bunch of tests
erlingrj Jun 24, 2023
48e8a1b
Handle enclaved connections with tokens
erlingrj Jun 26, 2023
d2ce286
bump reactor-C
erlingrj Jun 26, 2023
5051337
Handle enclaved connections with tokens
erlingrj Jun 26, 2023
7204d52
Dont initialize reactor_mutex unless we are in threaded moed
erlingrj Jun 26, 2023
d0dccc0
More fixes
erlingrj Jun 27, 2023
7cbb9c8
Update copying of reactor-c for Arduino
erlingrj Jun 29, 2023
76321d8
Move some tests
erlingrj Jun 29, 2023
2c9aa09
Rename enclave test to avoid collision
erlingrj Jun 29, 2023
0f26bdb
Dont generate 0-length arrays because MVSC
erlingrj Jun 29, 2023
be43717
Code auto-formatted with Spotless
erlingrj Jun 29, 2023
1d98b1a
time_t -> instant_t
erlingrj Jun 29, 2023
8f6d89a
Update enclave tests to include platform.h if using lf_sleep
erlingrj Jun 29, 2023
62258c7
Merge remote-tracking branch 'origin/master' into enclaves2
erlingrj Jun 29, 2023
9c7ea0d
Move from errorReporter to messageReporter
erlingrj Jun 29, 2023
a3ab9d4
Support TypeParameterizedReactors with token types
erlingrj Jun 30, 2023
9c405a1
Code auto-formatted with Spotless
erlingrj Jun 30, 2023
de93d76
Run formatter
erlingrj Jun 30, 2023
31dd940
Casting void to mutex
erlingrj Jun 30, 2023
be4a046
Cast malloc return
erlingrj Jun 30, 2023
af350b3
Move ShutdownCoordinated and bump reactor-c
erlingrj Jun 30, 2023
0a4d9ec
Code auto-formatted with Spotless
erlingrj Jun 30, 2023
6ad747d
Add JavaDocs to several funcions
erlingrj Jul 7, 2023
effa420
Add the hasAfterDelay parameter to the ConnectionReactors
erlingrj Jul 8, 2023
6878523
Add tests for the microstep index after an enclaved connection
erlingrj Jul 8, 2023
0fca3cc
Make pass on docs
erlingrj Jul 11, 2023
071c3c9
Code auto-formatted with Spotless
erlingrj Jul 11, 2023
81685f0
Fix more docs and add validator check to catch encalves in modes
erlingrj Jul 12, 2023
2ad1950
Update core/src/main/java/org/lflang/validation/AttributeSpec.java
erlingrj Jul 12, 2023
35bb9d1
Code auto-formatted with Spotless
erlingrj Jul 12, 2023
d6d19f9
Merge branch 'enclaves2' of github.com:lf-lang/lingua-franca into enc…
erlingrj Jul 12, 2023
0f25c8c
Make sure to delete everything federated related for Ardunio except l…
erlingrj Jul 13, 2023
1f73d34
Use new gradle API to run Zephyr tests
erlingrj Jul 13, 2023
99342b8
Fix Arduino file utils to delete federated-related files except RTI l…
erlingrj Jul 13, 2023
dcd0518
Code auto-formatted with Spotless
erlingrj Jul 13, 2023
42d659c
Merge remote-tracking branch 'origin/master' into enclaves2
erlingrj Jul 13, 2023
4522f43
Move EnclaveFederatedRequestStop to failing
erlingrj Jul 13, 2023
c0ee111
Merge branch 'master' into lfe-merge
erlingrj Sep 22, 2023
acb9be9
Bump reactor-c to merged
erlingrj Sep 22, 2023
28e4fe7
Merge branch 'master' into enclaves2
erlingrj Sep 26, 2023
ff27f40
Add enclave tests and other nitpicks from merge
erlingrj Oct 2, 2023
a0f1be4
Merge branch 'enclaves2' of github.com:lf-lang/lingua-franca into enc…
erlingrj Oct 2, 2023
5862c12
Merge remote-tracking branch 'origin/master' into enclaves2
erlingrj Oct 2, 2023
756f8a8
Remove unnecessary starvation test
erlingrj Oct 2, 2023
3fc9fd7
Spotless
erlingrj Oct 4, 2023
f451911
Fix enclave test that had a race condition
erlingrj Oct 4, 2023
7194624
Merge remote-tracking branch 'origin/test-fix-free-memory' into encla…
erlingrj Oct 5, 2023
7c75e15
Remove old LET calculations.
erlingrj Oct 19, 2023
edba77f
Merge master into enclaves2
edwardalee Nov 5, 2023
96f1fb1
Merged enclave2 into enclave3
edwardalee Nov 5, 2023
e3fe29d
Fixed compile errors from merge of master into enclaves2
edwardalee Nov 5, 2023
4f22fb7
Merge branch 'enclaves2' into enclaves3
edwardalee Nov 5, 2023
8e2b08d
Align reactor-c
edwardalee Nov 6, 2023
dd10eba
Merge branch 'enclaves3' of github.com:lf-lang/lingua-franca into enc…
erlingrj Nov 6, 2023
56e9957
Fix paths in arduino delete helper
erlingrj Nov 6, 2023
1d94e22
Merge remote-tracking branch 'origin/master' into enclaves3-erj
erlingrj Nov 8, 2023
420e30b
ArduinoDeleteHelper
erlingrj Nov 8, 2023
e0e4604
unthreaded->single_threaded rename
erlingrj Nov 8, 2023
5836067
Remove duplicate critical_section entering
erlingrj Nov 9, 2023
2bd5a23
Added tests
edwardalee Nov 9, 2023
b337fdb
Merge branch 'enclaves4' into enclaves3
erlingrj Nov 13, 2023
932c4f7
Checking in temporary status in new Enclave.
erlingrj Nov 14, 2023
b3bf068
Fix typo in setting the dest_env of a connection reactor
erlingrj Nov 14, 2023
81f9156
Fix setting of enclave connnection parameters
erlingrj Nov 15, 2023
13ae58b
Disable enclave tests in CI
erlingrj Nov 15, 2023
102804e
Merge remote-tracking branch 'origin/master' into c-enclaves
erlingrj Nov 15, 2023
df0cc14
Fix mistake in code-generated reaction preamble.
erlingrj Nov 15, 2023
a532d36
bump reactor-c
erlingrj Nov 15, 2023
169ec9e
Remove deprecated enclave connection reaction code-gen
erlingrj Nov 15, 2023
821326d
Code-generation is hard ...
erlingrj Nov 15, 2023
7da478c
Spotless
erlingrj Nov 15, 2023
88ece1f
Fix findEnclavedConnections
erlingrj Nov 15, 2023
3e5f158
Disable enclave tests until we figure out how to load library enclave…
erlingrj Nov 15, 2023
1a02bc0
Spotless
erlingrj Nov 15, 2023
472adf5
Update UnconnectedEnclave example
erlingrj Nov 16, 2023
7c38e3f
Enable enclave tests again
erlingrj Nov 16, 2023
93801a5
Bump reactor-c
erlingrj Nov 16, 2023
7689b93
Move all enclave tests to failing so we can run CI
erlingrj Nov 16, 2023
1ce1d7f
Spotless
erlingrj Nov 16, 2023
11d1dd9
Update isEarlierThan to consider NEVER
erlingrj Nov 22, 2023
893a61f
Rename EnclaveInfo-CEnclaveInstance
erlingrj Nov 22, 2023
a211cd6
Add a ConnectionGraph type that support annotations of edges (not nodes)
erlingrj Nov 22, 2023
33b19aa
Create a class to represent the mapping form ReactorInstance to CEncl…
erlingrj Nov 22, 2023
28ccd3b
Try to remove magic strings
erlingrj Nov 22, 2023
3bc811a
Refactoring enclave implementation. Try to move C specific things out…
erlingrj Nov 22, 2023
5376d0a
Merge branch 'c-enclaves' of github.com:lf-lang/lingua-franca into c-…
erlingrj Nov 22, 2023
54e7c49
Spotless
erlingrj Nov 22, 2023
5fccd93
load resource from jar as a library
erlingrj Nov 22, 2023
7f85593
Bring back the enclave tests
erlingrj Nov 22, 2023
1c44107
Spotless
erlingrj Nov 22, 2023
14b8991
Fix typo in ConnectionReactor param setting
erlingrj Nov 22, 2023
0b7b8c3
Refactoring and fixing mistake with TimeValue
erlingrj Nov 22, 2023
a1d5eca
Bump reactor-c
erlingrj Nov 22, 2023
39de65d
Improve docs and general refactorings.
erlingrj Nov 22, 2023
91b0aa1
Check for zero-delay-cycles of enclaves
erlingrj Nov 23, 2023
90122dc
Add validator check for connections between enclaves that are not "si…
erlingrj Nov 23, 2023
9035068
Array ports disallowed between enclaves
erlingrj Nov 23, 2023
e511d8a
Support physical connections between enclaves
erlingrj Nov 23, 2023
3509067
Improve enclave tests
erlingrj Nov 23, 2023
c3fa40e
Spotless
erlingrj Nov 23, 2023
66e5d96
Merge branch 'master' into c-enclaves
erlingrj Nov 23, 2023
ec4d6f4
getEnclaves returns Set of instantiations instead of List
erlingrj Nov 30, 2023
5692daa
Refactor rerouteViaInstance after Edwards suggestions
erlingrj Nov 30, 2023
9020241
Fix up some minor mistakes and address more feedbac
erlingrj Dec 1, 2023
3ecbf9a
Spotless
erlingrj Dec 5, 2023
d102db2
Enclaves: Remove the old call to getNumReactionsPerLevel
erlingrj Dec 5, 2023
fc38568
Spotless
erlingrj Dec 5, 2023
2155012
Update core/src/main/java/org/lflang/util/FileUtil.java
lhstrh Dec 6, 2023
294f2f3
Update core/src/main/java/org/lflang/generator/ReactionInstanceGraph.…
lhstrh Dec 6, 2023
f085020
Make searchForEnclavesInModes private
erlingrj Dec 13, 2023
ec45cac
Merge remote-tracking branch 'origin/master' into c-enclaves
erlingrj Dec 13, 2023
62f1d71
Bump reactor-c
erlingrj Dec 13, 2023
617d363
Apply suggestions from code review
erlingrj Dec 13, 2023
337236e
Apply suggestions from code review
erlingrj Dec 13, 2023
e1171ae
Address code review feedback
erlingrj Dec 13, 2023
d4ed8b6
Merge branch 'c-enclaves' of github.com:lf-lang/lingua-franca into c-…
erlingrj Dec 13, 2023
c8923f0
Spotless
erlingrj Dec 13, 2023
041e040
Bump reactor-c
erlingrj Dec 14, 2023
6872fd6
reactor-c
erlingrj Dec 14, 2023
fd7868d
Refactor to obtain after delay as a TimeValue
edwardalee Apr 9, 2024
77357b9
Allow after delay to be given as a parameter
edwardalee Apr 9, 2024
917f91b
Align to c-enclaves version of reactor-c
edwardalee Apr 9, 2024
ae7fd0a
Merge remote-tracking branch 'origin/master' into c-enclaves
erlingrj Apr 17, 2024
155be13
Watchdog updates
erlingrj Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/c-zephyr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path: core/src/main/resources/lib/c/reactor-c
ref: ${{ inputs.runtime-ref }}
if: ${{ inputs.runtime-ref }}
- name: Run Zephyr smoke tests
- name: Run integration tests on the Zephyr platform
run: |
./gradlew core:integrationTest \
--tests org.lflang.tests.runtime.CZephyrTest.buildZephyrUnthreaded* \
Expand Down
11 changes: 11 additions & 0 deletions core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ protected boolean supportsDockerOption() {
return true;
}

@Override
protected boolean supportsEnclaves() {
return true;
}

@Test
@Override
public void runBasicTests() {
Expand All @@ -72,6 +77,12 @@ public void runGenericsTests() {
super.runGenericsTests();
}

@Test
@Override
public void runEnclaveTests() {
super.runEnclaveTests();
}

@Test
@Override
public void runTargetSpecificTests() {
Expand Down
26 changes: 18 additions & 8 deletions core/src/main/java/org/lflang/AttributeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package org.lflang;

import static org.lflang.ast.ASTUtils.factory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -48,6 +46,7 @@
import org.lflang.lf.StateVar;
import org.lflang.lf.Timer;
import org.lflang.util.StringUtil;
import org.lflang.validation.AttributeSpec;

/**
* A helper class for processing attributes in the AST.
Expand Down Expand Up @@ -290,15 +289,26 @@ public static boolean isEnclave(Instantiation node) {
}

/**
* Annotate @{code node} with enclave @attribute
* Retrieve the number of worker parameter from an enclave attribute. Returns 1 if not specified
* or has illegal value
*
* @param node
* @return
*/
public static void setEnclaveAttribute(Instantiation node) {
if (!isEnclave(node)) {
Attribute enclaveAttr = factory.createAttribute();
enclaveAttr.setAttrName("enclave");
node.getAttributes().add(enclaveAttr);
public static int getEnclaveNumWorkersFromAttribute(Instantiation node) {
Attribute enclaveAttr = getEnclaveAttribute(node);
if (enclaveAttr != null) {
for (AttrParm attrParm : enclaveAttr.getAttrParms()) {
if (attrParm.getName().equals(AttributeSpec.WORKERS_ATTR)) {
int value = Integer.valueOf(attrParm.getValue());
if (value > 0) {
return value;
} else {
return 1;
}
}
}
}
return 1; // Not specified
}
}
4 changes: 4 additions & 0 deletions core/src/main/java/org/lflang/TimeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public final class TimeValue implements Comparable<TimeValue> {
public static final TimeValue MAX_VALUE = new TimeValue(Long.MAX_VALUE, TimeUnit.NANO);
/** A time value equal to zero. */
public static final TimeValue ZERO = new TimeValue(0, null);
/** A time value representing NEVER, which is less than any other time value. */
public static final TimeValue NEVER = new TimeValue(Long.MIN_VALUE, TimeUnit.NANO);
/** A time value representing FOREVER which is greater than any other time value. */
public static final TimeValue FOREVER = new TimeValue(Long.MAX_VALUE, TimeUnit.NANO);

/**
* Primitive numerical representation of this time value, to be interpreted in terms the
Expand Down
142 changes: 134 additions & 8 deletions core/src/main/java/org/lflang/ast/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.lflang.ast;

import static org.lflang.AttributeUtils.isEnclave;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
Expand All @@ -33,9 +35,11 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand All @@ -53,8 +57,6 @@
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.impl.HiddenLeafNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.Tuples;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
Expand All @@ -65,10 +67,12 @@
import org.lflang.generator.CodeMap;
import org.lflang.generator.InvalidSourceException;
import org.lflang.generator.NamedInstance;
import org.lflang.generator.ParameterInstance;
import org.lflang.generator.ReactorInstance;
import org.lflang.lf.Action;
import org.lflang.lf.Assignment;
import org.lflang.lf.Code;
import org.lflang.lf.CodeExpr;
import org.lflang.lf.Connection;
import org.lflang.lf.Element;
import org.lflang.lf.Expression;
Expand Down Expand Up @@ -103,6 +107,7 @@
import org.lflang.target.Target;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.util.Pair;
import org.lflang.util.StringUtil;

/**
Expand Down Expand Up @@ -199,15 +204,15 @@ public static Collection<Connection> findConflictingConnectionsInModalReactors(
for (var rea : allReactions(reactor)) {
for (var eff : rea.getEffects()) {
if (eff.getVariable() instanceof Port) {
allWriters.put(Tuples.pair(eff.getContainer(), eff.getVariable()), rea);
allWriters.put(new Pair<>(eff.getContainer(), eff.getVariable()), rea);
}
}
}
for (var con :
ASTUtils.<Connection>collectElements(
reactor, featurePackage.getReactor_Connections(), false, true)) {
for (var port : con.getRightPorts()) {
allWriters.put(Tuples.pair(port.getContainer(), port.getVariable()), con);
allWriters.put(new Pair<>(port.getContainer(), port.getVariable()), con);
}
}

Expand Down Expand Up @@ -626,14 +631,12 @@ public static ReactorInstance createMainReactorInstance(
return null;
}
// Inform the run-time of the breadth/parallelism of the reaction graph
var breadth = reactionInstanceGraph.getBreadth();
var breadth = reactionInstanceGraph.getBreadth(main);
if (breadth == 0) {
messageReporter.nowhere().warning("The program has no reactions");
} else {
CompileDefinitionsProperty.INSTANCE.update(
targetConfig,
Map.of(
"LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())));
targetConfig, Map.of("LF_REACTION_GRAPH_BREADTH", String.valueOf(breadth)));
}
return main;
}
Expand Down Expand Up @@ -1953,4 +1956,127 @@ public static void addReactionAttribute(Reaction reaction, String name) {
fedAttr.setAttrName(name);
reaction.getAttributes().add(fedAttr);
}

/**
* Given a reactor definition, e.g. the main reactor, returns the set of reactor instantiations
* contained in this definition.
*
* @param top The reactor definition to search in.
* @return The set of reactor instantiations within top.
*/
public static Set<Instantiation> getEnclaves(Reactor top) {
Set<Instantiation> enclaves = new HashSet<>();
Queue<Reactor> queue = new LinkedList<>();
queue.add(top);

while (!queue.isEmpty()) {
Reactor inst = queue.poll();
for (Instantiation child : ASTUtils.allInstantiations(inst)) {
if (isEnclave(child)) {
enclaves.add(child);
}
queue.add(ASTUtils.toDefinition(child.getReactorClass()));
}
}
return enclaves;
}

/**
* Given a list of pairs of an old connection and a newly created instantiation. For eac pair,
* create two connections to reroute specified connection to instead go through the specified
* instantiation. This is used when code-generating after-delay reactors and enclave connections.
* This assumes that the specified instantiation has at least one input port and at least one
* output port and uses the first of such ports. This returns a list of the two created
* connections. instantiation. This is used when code-generating after-delay reactors and enclaved
* connections. It inserts the added connections and the instantiations into the AST and removes
* the old connection.
*
* @param conns The list of pairs to reroute.
*/
public static void rerouteViaInstance(List<Pair<Connection, Instantiation>> conns) {

List<Pair<EObject, Connection>> newConnections = new ArrayList<>();
List<Pair<EObject, Connection>> oldConnections = new ArrayList<>();

for (var pair : conns) {
Connection connection = pair.first();
EObject parent = connection.eContainer();
Instantiation inst = pair.second();
Connection upstream = factory.createConnection();
Connection downstream = factory.createConnection();
VarRef input = factory.createVarRef();
VarRef output = factory.createVarRef();

Reactor delayClass = ASTUtils.toDefinition(inst.getReactorClass());

// Establish references to the involved ports.
input.setContainer(inst);
input.setVariable(delayClass.getInputs().get(0));
output.setContainer(inst);
output.setVariable(delayClass.getOutputs().get(0));
upstream.getLeftPorts().addAll(connection.getLeftPorts());
upstream.getRightPorts().add(input);
downstream.getLeftPorts().add(output);
downstream.getRightPorts().addAll(connection.getRightPorts());
downstream.setIterated(connection.isIterated());
newConnections.add(new Pair<>(parent, upstream));
newConnections.add(new Pair<>(parent, downstream));
oldConnections.add(new Pair<>(parent, connection));
}

// Insert the instances which we rerouted through.
conns.forEach(
(pair) -> {
Instantiation instantiation = pair.second();
EObject container = pair.first().eContainer();
if (container instanceof Reactor) {
((Reactor) container).getInstantiations().add(instantiation);
} else if (container instanceof Mode) {
((Mode) container).getInstantiations().add(instantiation);
}
});

// Remove old connections; insert new ones.
oldConnections.forEach(
(pair) -> {
EObject container = pair.first();
Connection connection = pair.second();
if (container instanceof Reactor) {
((Reactor) container).getConnections().remove(connection);
} else if (container instanceof Mode) {
((Mode) container).getConnections().remove(connection);
}
});
newConnections.forEach(
pair -> {
EObject container = pair.first();
Connection connection = pair.second();
if (container instanceof Reactor) {
((Reactor) container).getConnections().add(connection);
} else if (container instanceof Mode) {
((Mode) container).getConnections().add(connection);
}
});
}

/**
* Override the parameter initializer with a code expression.
*
* @param param
* @param expr
*/
public static void overrideParameter(ParameterInstance param, CodeExpr expr) {
Assignment existing = param.getOverride();
Initializer init = factory.createInitializer();
init.setBraces(true);
init.getExprs().add(expr);
if (existing != null) {
existing.setRhs(init);
} else {
Assignment a = factory.createAssignment();
a.setLhs(param.getDefinition());
a.setRhs(init);
param.getParent().getDefinition().getParameters().add(a);
}
}
}
Loading