use of org.osate.aadl2.instance.FlowSpecificationInstance in project osate2 by osate.
the class FlowLatencyAnalysisSwitch method mapComponentInstance.
private void mapComponentInstance(final EndToEndFlowInstance etef, final FlowElementInstance flowElementInstance, LatencyReportEntry entry) {
ComponentInstance componentInstance;
final boolean hasLatency = flowElementInstance instanceof FlowSpecificationInstance || flowElementInstance instanceof ConnectionInstance || flowElementInstance instanceof EndToEndFlowInstance || latencyCats.contains(((ComponentInstance) flowElementInstance).getCategory());
final RealRange expected = hasLatency ? PropertyUtils.getScaledRange(org.osate.aadl2.contrib.communication.CommunicationProperties::getLatency, flowElementInstance, TimeUnits.MS).orElse(RealRange.ZEROED) : RealRange.ZEROED;
if (flowElementInstance instanceof FlowSpecificationInstance) {
componentInstance = flowElementInstance.getComponentInstance();
} else {
componentInstance = (ComponentInstance) flowElementInstance;
}
FeatureInstance incomingConnectionFI = FlowLatencyUtil.getIncomingConnectionFeatureInstance(etef, flowElementInstance);
/**
* Get all the relevant properties.
*/
double period = periodCats.contains(componentInstance.getCategory()) ? PropertyUtils.getScaled(TimingProperties::getPeriod, componentInstance, TimeUnits.MS).orElse(0.0) : 0.0;
double deadline = deadlineCats.contains(componentInstance.getCategory()) ? PropertyUtils.getScaled(TimingProperties::getDeadline, componentInstance, TimeUnits.MS).orElse(0.0) : 0.0;
boolean isAssignedDeadline = isAssignedDeadline(componentInstance);
final boolean isThreadOrDevice = InstanceModelUtil.isThread(componentInstance) || InstanceModelUtil.isDevice(componentInstance) || InstanceModelUtil.isAbstract(componentInstance);
final boolean isPeriodic = period > 0 && (isThreadOrDevice ? (!InstanceModelUtil.isSporadicComponent(componentInstance) && !InstanceModelUtil.isTimedComponent(componentInstance) && !InstanceModelUtil.isAperiodicComponent(componentInstance)) : true);
final RealRange responseTime = getResponseTimeInMilliSec(flowElementInstance, componentInstance, isPeriodic);
final RealRange executionTime = getExecutionTimeInMilliSec(flowElementInstance, componentInstance, isPeriodic);
/**
* The component is periodic. Therefore it will sample its input unless we have an immediate connection or delayed connection
*/
boolean checkLastImmediate = false;
if (isPeriodic) {
// we have a periodic component that samples
if (incomingConnectionFI != null) {
// it is not the first component in the ETEF. We need to add sampling latency
if (incomingConnectionFI.getCategory() == FeatureCategory.DATA_PORT || incomingConnectionFI.getCategory() == FeatureCategory.ABSTRACT_FEATURE) {
// sampling incoming data
// period is set, and if thread, abstract, or device needs to be dispatched as periodic
// We sample only data ports. Event and event data ports have queuing latency
LatencyContributorComponent samplingLatencyContributor = new LatencyContributorComponent(componentInstance, flowElementInstance, report.isMajorFrameDelay());
samplingLatencyContributor.setSamplingPeriod(period);
if ((InstanceModelUtil.isThread(componentInstance) || InstanceModelUtil.isDevice(componentInstance)) && !hasAssignedPropertyValue(componentInstance, "Dispatch_Protocol")) {
samplingLatencyContributor.reportInfo("Assume Periodic dispatch because period is set");
}
if (FlowLatencyUtil.isPreviousConnectionDelayed(etef, flowElementInstance)) {
samplingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.DELAYED);
samplingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.DELAYED);
} else if (FlowLatencyUtil.isPreviousConnectionImmediate(etef, flowElementInstance)) {
// the cumulative does not exceed the deadline of the last.
if (!FlowLatencyUtil.isNextConnectionImmediate(etef, flowElementInstance)) {
checkLastImmediate = true;
}
} else {
// sampled. We may under sample
ComponentInstance prevComp = FlowLatencyUtil.getPreviousComponent(etef, flowElementInstance);
double prevPeriod = prevComp != null ? PropertyUtils.getScaled(TimingProperties::getPeriod, prevComp, TimeUnits.MS).orElse(0.0) : 0;
if (period > 0 && prevPeriod > 0 && period % prevPeriod == 0.0) {
samplingLatencyContributor.setSamplingPeriod(prevPeriod);
} else {
samplingLatencyContributor.setSamplingPeriod(period);
}
samplingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.SAMPLED);
samplingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.SAMPLED);
}
entry.addContributor(samplingLatencyContributor);
} else {
// queuing latency handled later
// do nothing here
}
} else {
// The periodic component is the first component in the ETEF
// record fact that first element is periodic so we can process synchronous behavior correctly
LatencyContributorComponent samplingLatencyContributor = new LatencyContributorComponent(componentInstance, flowElementInstance, report.isMajorFrameDelay());
samplingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.FIRST_PERIODIC);
samplingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.FIRST_PERIODIC);
entry.addContributor(samplingLatencyContributor);
}
} else {
// the component is not executing periodically
if (entry.getContributors().isEmpty()) {
// insert first partition sampling for the aperiodic case. For other partitions it is inserted by connection processing
ComponentInstance firstPartition = FlowLatencyUtil.getPartition(componentInstance);
if (firstPartition != null) {
double partitionLatency = FlowLatencyUtil.getPartitionPeriod(firstPartition);
List<ScheduleWindow> schedule = FlowLatencyUtil.getModuleSchedule(firstPartition);
double partitionDuration = FlowLatencyUtil.getPartitionDuration(firstPartition, schedule);
LatencyContributorComponent platencyContributor = new LatencyContributorComponent(firstPartition, flowElementInstance, report.isMajorFrameDelay());
if (!FlowLatencyUtil.isInSchedule(firstPartition, schedule)) {
platencyContributor.reportWarning("Partition not found in ARINC653 schedule of processor " + FlowLatencyUtil.getModule(firstPartition).getName());
}
if (partitionDuration > 0) {
platencyContributor.setSamplingPeriod(partitionLatency);
double frameOffset = FlowLatencyUtil.getPartitionFrameOffset(firstPartition, schedule);
platencyContributor.setPartitionOffset(frameOffset);
platencyContributor.setPartitionDuration(partitionDuration);
platencyContributor.setWorstCaseMethod(LatencyContributorMethod.PARTITION_SCHEDULE);
platencyContributor.setBestCaseMethod(LatencyContributorMethod.PARTITION_SCHEDULE);
entry.addContributor(platencyContributor);
} else {
platencyContributor.setSamplingPeriod(partitionLatency);
platencyContributor.setWorstCaseMethod(LatencyContributorMethod.PARTITION_FRAME);
platencyContributor.setBestCaseMethod(LatencyContributorMethod.PARTITION_FRAME);
entry.addContributor(platencyContributor);
}
}
}
}
/**
* Selection of the worst case value, generic case.
*/
LatencyContributorMethod bestmethod;
LatencyContributorMethod worstmethod;
double worstCaseValue = 0.0;
double bestCaseValue = 0.0;
worstmethod = LatencyContributorMethod.UNKNOWN;
LatencyContributorComponent processingLatencyContributor = new LatencyContributorComponent(componentInstance, flowElementInstance, report.isMajorFrameDelay());
if (responseTime.getMaximum() != 0.0) {
worstCaseValue = responseTime.getMaximum();
worstmethod = LatencyContributorMethod.RESPONSE_TIME;
} else if (executionTime.getMaximum() != 0.0) {
if (!report.isWorstCaseDeadline()) {
// Use execution time for worst-case if preferences specify not deadline or no deadline is specified
worstCaseValue = executionTime.getMaximum();
worstmethod = LatencyContributorMethod.PROCESSING_TIME;
} else if (!isAssignedDeadline) {
worstCaseValue = executionTime.getMaximum();
worstmethod = LatencyContributorMethod.PROCESSING_TIME;
processingLatencyContributor.reportInfo("Using execution time as deadline was not set");
}
}
if ((worstCaseValue == 0.0) && isAssignedDeadline && report.isWorstCaseDeadline()) {
// use deadline if no execution time and deadline was explicitly assigned
worstCaseValue = deadline;
worstmethod = LatencyContributorMethod.DEADLINE;
}
if ((worstCaseValue == 0.0) && (expected.getMaximum() != 0.0)) {
// use flow latency if neither deadline nor execution time
worstCaseValue = expected.getMaximum();
worstmethod = LatencyContributorMethod.SPECIFIED;
} else if (worstCaseValue == 0.0 && deadline != 0.0) {
// if no flow spec value then use default deadline == period
worstCaseValue = deadline;
worstmethod = LatencyContributorMethod.DEADLINE;
processingLatencyContributor.reportInfo("Using deadline as execution time was not set");
}
/**
* Selection of the best case value, generic cases.
*/
bestmethod = LatencyContributorMethod.UNKNOWN;
if (responseTime.getMinimum() != 0.0) {
bestCaseValue = responseTime.getMinimum();
bestmethod = LatencyContributorMethod.RESPONSE_TIME;
} else if (executionTime.getMinimum() != 0.0) {
bestCaseValue = executionTime.getMinimum();
bestmethod = LatencyContributorMethod.PROCESSING_TIME;
}
if ((bestCaseValue == 0.0) && (expected.getMinimum() != 0.0)) {
bestCaseValue = expected.getMinimum();
bestmethod = LatencyContributorMethod.SPECIFIED;
}
// take into account queuing delay
if (incomingConnectionFI != null) {
double qs = 0;
LatencyContributorComponent ql = new LatencyContributorComponent(componentInstance, flowElementInstance, report.isMajorFrameDelay());
if (hasAssignedPropertyValue(incomingConnectionFI, org.osate.xtext.aadl2.properties.util.CommunicationProperties.QUEUE_SIZE)) {
qs = CommunicationProperties.getQueueSize(incomingConnectionFI).orElse(0);
} else if (incomingConnectionFI.getCategory() == FeatureCategory.DATA_PORT && isThreadOrDevice && (InstanceModelUtil.isSporadicComponent(componentInstance) || InstanceModelUtil.isTimedComponent(componentInstance) || InstanceModelUtil.isAperiodicComponent(componentInstance))) {
// treat data port as a port of queue size 1 when not a sampling thread
qs = 1;
ql.reportInfo("Data port as queue size 1 for sporadic, aperiodic, timed dispatch");
}
if (qs != 0) {
// take into account queuing delay on event and event data ports.
double dl = 0.0;
if (InstanceModelUtil.isSporadicComponent(componentInstance) || InstanceModelUtil.isPeriodicComponent(componentInstance)) {
dl = period;
ql.reportInfo("Sporadic or periodic has period delay per queue element");
} else {
dl = worstCaseValue;
}
double queuingDelay = qs * dl;
ql.setMaximum(queuingDelay);
if (report.isBestcaseEmptyQueue()) {
ql.setMinimum(0.0);
ql.reportInfo("Assume best case empty queue");
} else {
double mindl = (InstanceModelUtil.isSporadicComponent(componentInstance) || InstanceModelUtil.isPeriodicComponent(componentInstance) ? period : bestCaseValue);
ql.setMinimum(qs * mindl);
ql.reportInfo("Assume best case full queue");
}
ql.setWorstCaseMethod(LatencyContributorMethod.QUEUED);
ql.setBestCaseMethod(LatencyContributorMethod.QUEUED);
entry.addContributor(ql);
}
}
processingLatencyContributor.setWorstCaseMethod(worstmethod);
processingLatencyContributor.setBestCaseMethod(bestmethod);
processingLatencyContributor.setMaximum(worstCaseValue);
processingLatencyContributor.setMinimum(bestCaseValue);
processingLatencyContributor.setExpectedMaximum(expected.getMaximum());
processingLatencyContributor.setExpectedMinimum(expected.getMinimum());
if (checkLastImmediate && deadline > 0.0) {
processingLatencyContributor.setImmediateDeadline(deadline);
}
processingLatencyContributor.checkConsistency();
entry.addContributor(processingLatencyContributor);
}
use of org.osate.aadl2.instance.FlowSpecificationInstance in project osate2 by osate.
the class FlowLatencyAnalysisSwitch method getTimeInMilliSec2.
private RealRange getTimeInMilliSec2(final FlowElementInstance fei, final ComponentInstance ci, final boolean isPeriodic, final Function<NamedElement, Optional<IntegerRangeWithUnits<TimeUnits>>> getExecTime) {
/*
* If the flow element is a component instance or if the thread is periodic, we use the thread's
* computation time. Otherwise we try to use the compute execution time from the flow's input feature.
*/
if (!(isPeriodic || fei == ci)) {
// the flow element is a FlowSpecificationInstance (It is not periodic or a component instance)
final FlowSpecificationInstance fsi = (FlowSpecificationInstance) fei;
final FlowEnd allInEnd = fsi.getFlowSpecification().getAllInEnd();
if (allInEnd != null) {
// we have an input feature
FeatureInstance fi = null;
if (allInEnd.getContext() instanceof FeatureGroup) {
final FeatureInstance fgi = ci.findFeatureInstance((FeatureGroup) allInEnd.getContext());
fi = fgi.findFeatureInstance(allInEnd.getFeature());
} else {
fi = ci.findFeatureInstance(allInEnd.getFeature());
}
final FeatureCategory featureCategory = fi.getCategory();
if (featureCategory == FeatureCategory.EVENT_PORT || featureCategory == FeatureCategory.EVENT_DATA_PORT) {
final Optional<IntegerRangeWithUnits<TimeUnits>> fromFeature = getExecTime.apply(fi);
if (fromFeature.isPresent()) {
return AnalysisUtils.scaleTimeRange(PropertyUtils.scaleRange(fromFeature.get(), TimeUnits.MS), fi);
}
// otherwise fall through and get from component
}
// otherwise fall through and get from component
}
}
final ComponentCategory componentCategory = ci.getCategory();
if (componentCategory == ComponentCategory.THREAD || componentCategory == ComponentCategory.DEVICE || componentCategory == ComponentCategory.SUBPROGRAM || componentCategory == ComponentCategory.ABSTRACT) {
return AnalysisUtils.scaleTimeRange(PropertyUtils.scaleRange(getExecTime.apply(ci), TimeUnits.MS).orElse(RealRange.ZEROED), ci);
} else {
return RealRange.ZEROED;
}
}
use of org.osate.aadl2.instance.FlowSpecificationInstance in project osate2 by osate.
the class CreateEndToEndFlowsSwitch method getLastFeature.
private FeatureInstance getLastFeature(EndToEndFlowInstance etei) {
EList<FlowElementInstance> feis = etei.getFlowElements();
FeatureInstance lastFeature = null;
if (!feis.isEmpty()) {
FlowElementInstance lastElement = feis.get(feis.size() - 1);
if (lastElement instanceof EndToEndFlowInstance) {
lastFeature = getLastFeature((EndToEndFlowInstance) lastElement);
} else if (lastElement instanceof FlowSpecificationInstance) {
lastFeature = ((FlowSpecificationInstance) lastElement).getDestination();
} else if (lastElement instanceof ConnectionInstance) {
ConnectionInstanceEnd dst = ((ConnectionInstance) lastElement).getDestination();
if (dst instanceof FeatureInstance) {
lastFeature = (FeatureInstance) dst;
}
}
}
return lastFeature;
}
use of org.osate.aadl2.instance.FlowSpecificationInstance in project osate2 by osate.
the class CreateEndToEndFlowsSwitch method testConnection.
/**
* @param conni
* @param etei
* @param result
*/
private boolean testConnection(ConnectionInstance conni, EndToEndFlowInstance etei) {
Iterator<ConnectionReference> refIter = conni.getConnectionReferences().iterator();
boolean match = false;
while (refIter.hasNext()) {
String name1 = refIter.next().getConnection().getName();
String name2 = connections.get(0).getName();
if (name1.equalsIgnoreCase(name2)) {
Iterator<Connection> connIter = connections.iterator();
connIter.next();
match = true;
while (match && refIter.hasNext() && connIter.hasNext()) {
match &= refIter.next().getConnection().getName().equalsIgnoreCase(connIter.next().getName());
}
if (!refIter.hasNext() && connIter.hasNext()) {
match = false;
}
}
}
if (match && connections.size() == 1) {
// make sure connection instance goes in the same direction as the flow
ComponentInstance connci = conni.getSource().getComponentInstance();
FlowElementInstance fei = etei;
while (fei instanceof EndToEndFlowInstance) {
fei = ((EndToEndFlowInstance) fei).getFlowElements().get(((EndToEndFlowInstance) fei).getFlowElements().size() - 1);
}
if (fei instanceof FlowSpecificationInstance) {
fei = fei.getComponentInstance();
}
ComponentInstance flowci = (ComponentInstance) fei;
match = false;
ComponentInstance ci = connci;
while (!(ci instanceof SystemInstance)) {
if (ci == flowci) {
match = true;
break;
}
ci = ci.getContainingComponentInstance();
}
}
if (match) {
// test if the connection instance is connected to the end of the ete instance
// relevant if the flow goes through a port of a feature group and the connection
// instance comes from an expanded fg connection
ConnectionInstanceEnd src = conni.getSource();
if (src instanceof FeatureInstance) {
FeatureInstance firstFeature = (FeatureInstance) src;
FeatureInstance lastFeature = getLastFeature(etei);
if (lastFeature != null) {
match = isSameorContains(lastFeature, firstFeature);
}
}
}
return match;
}
use of org.osate.aadl2.instance.FlowSpecificationInstance in project osate2 by osate.
the class InstantiateModel method instantiateFlowSpecs.
/**
* same method but with different name exists in createEndToEndFlowSwitch.
* It adds the flow instances on demand when ETEF is created
* @param ci
*/
private void instantiateFlowSpecs(ComponentInstance ci) throws InterruptedException {
for (FlowSpecification spec : getComponentType(ci).getAllFlowSpecifications()) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
FlowSpecificationInstance speci = ci.createFlowSpecification();
speci.setName(spec.getName());
speci.setFlowSpecification(spec);
FlowEnd inend = spec.getAllInEnd();
if (inend != null) {
Feature srcfp = inend.getFeature();
Context srcpg = inend.getContext();
if (srcpg == null) {
FeatureInstance fi = ci.findFeatureInstance(srcfp);
if (fi != null) {
speci.setSource(fi);
}
} else if (srcpg instanceof FeatureGroup) {
FeatureInstance pgi = ci.findFeatureInstance((FeatureGroup) srcpg);
if (pgi != null) {
FeatureInstance fi = pgi.findFeatureInstance(srcfp);
if (fi != null) {
speci.setSource(fi);
}
}
}
}
FlowEnd outend = spec.getAllOutEnd();
if (outend != null) {
Feature dstfp = outend.getFeature();
Context dstpg = outend.getContext();
if (dstpg == null) {
FeatureInstance fi = ci.findFeatureInstance(dstfp);
if (fi != null) {
speci.setDestination(fi);
}
} else if (dstpg instanceof FeatureGroup) {
FeatureInstance pgi = ci.findFeatureInstance((FeatureGroup) dstpg);
if (pgi != null) {
FeatureInstance fi = pgi.findFeatureInstance(dstfp);
if (fi != null) {
speci.setDestination(fi);
}
}
}
}
for (Mode mode : spec.getAllInModes()) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
ModeInstance mi = ci.findModeInstance(mode);
if (mi != null) {
speci.getInModes().add(mi);
}
}
for (ModeTransition mt : spec.getInModeTransitions()) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
ModeTransitionInstance ti = ci.findModeTransitionInstance(mt);
if (ti != null) {
speci.getInModeTransitions().add(ti);
}
}
}
}
Aggregations