Bug 562793: add blocking to NPRTA, update test class
Change-Id: I698b1038de855088525db37f60452ed887081b85
Signed-off-by: The Bao Bui <ZeroVNB@Gmail.com>
diff --git a/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/NPandPRTA.java b/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/NPandPRTA.java
index 9c90963..01370c8 100644
--- a/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/NPandPRTA.java
+++ b/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/NPandPRTA.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.app4mc.gsoc_rta;
+import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
@@ -31,9 +32,11 @@
import org.eclipse.app4mc.amalthea.model.Task;
import org.eclipse.app4mc.amalthea.model.Time;
import org.eclipse.app4mc.amalthea.model.TimeUnit;
+import org.eclipse.app4mc.amalthea.model.io.AmaltheaLoader;
import org.eclipse.app4mc.amalthea.model.util.FactoryUtil;
import org.eclipse.app4mc.amalthea.model.util.SoftwareUtil;
import org.eclipse.app4mc.amalthea.model.util.RuntimeUtil.TimeType;
+import org.eclipse.app4mc.gsoc_rta.test.NonPreemptMixTest;
import org.eclipse.emf.common.util.EList;
public class NPandPRTA {
@@ -41,8 +44,8 @@
private final Amalthea model;
private final int[] preemptionTypeArray;
private boolean schedubilityCheck = true;
- //Adding decimal Format for better visual checking when debugging
- //ie 6000000000 ps -> 6,000,000,000 ps
+ // Adding decimal Format for better visual checking when debugging
+ // ie 6000000000 ps -> 6,000,000,000 ps
private DecimalFormat df = new DecimalFormat("#,###.##");
final Logger log = LoggerFactory.getLogger(NPandPRTA.class);
boolean logDebug = log.isDebugEnabled();
@@ -50,77 +53,97 @@
boolean logError = log.isErrorEnabled();
/*
- * PreemptionTypeArray will have the same length with mapping indexArray (ia), just with different value
- * This will be set up when the class is initialize, the meaning of the number in array are:
- * 0 = preemptive
- * 1 = non-preemptive
- * 2 = cooperative
+ * PreemptionTypeArray will have the same length with mapping indexArray (ia),
+ * just with different value This will be set up when the class is initialize,
+ * the meaning of the number in array are: 0 = preemptive 1 = non-preemptive 2 =
+ * cooperative
*
- * ia = { 5, 1, 5, 0, 1, 0, 2, 1, 2, 1, 6, 3, 4, 6 } - mapping array
- * pta = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,} - the preemption type array
- * this mean the first and second task of the model have non-preemption mode, the rest are preemptive
+ * ia = { 5, 1, 5, 0, 1, 0, 2, 1, 2, 1, 6, 3, 4, 6 } - mapping array pta = { 1,
+ * 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,} - the preemption type array this mean
+ * the first and second task of the model have non-preemption mode, the rest are
+ * preemptive
*/
-
+ public static void main(String[] args) {
+ final Amalthea inputModel = AmaltheaLoader.loadFromFile(new File(SharedConsts.FHDO_MODELZNP));
+ int[] iap = { 5, 2, 5, 3, 3, 1, 3, 5, 1, 0, 0, 6, 4, 6 };
+ NPandPRTA nprta = new NPandPRTA(inputModel, iap);
+ EList<Task> listTask = inputModel.getSwModel().getTasks();
+ for ( Task task: listTask) {
+ BigInteger timeValue = nprta.getRTAinMixedPreempiveEnvironment(task, iap, TimeType.WCET, null, false).getValue();
+ System.out.println(timeValue + " - " + listTask.indexOf(task));
+ }
+
+ }
public boolean isSchedubilityCheck() {
return schedubilityCheck;
}
- /**Default = true.
+ /**
+ * Default = true.
*
- * True = return result after comparing task's blocking time and period.
- * False = return result as long as ultilization value is less than 100 percent.
+ * True = return result after comparing task's blocking time and period. False =
+ * return result as long as ultilization value is less than 100 percent.
+ *
* @param schedubilityCheck
*/
public void setSchedubilityCheck(boolean schedubilityCheck) {
this.schedubilityCheck = schedubilityCheck;
}
-
+
public NPandPRTA(final Amalthea modelp, final int[] iap) {
this.ia = iap;
this.model = modelp;
this.preemptionTypeArray = new int[iap.length];
setupPTArray();
}
-
+
/**
- * Calculate task's response time in non-mixed/mixed preemptive environment
- * this function will get data from thisTask and ia to decide what kind of environment calculate response time accordingly
- * Check the comment part in the function for more info. Or just use it if you are lazy.
+ * Calculate task's response time in non-mixed/mixed preemptive environment this
+ * function will get data from thisTask and ia to decide what kind of
+ * environment calculate response time accordingly Check the comment part in the
+ * function for more info. Or just use it if you are lazy.
+ *
* @param thisTask
* @param ia
* @param executionCase
- * @param pTypeArray - leave null if don't use, index value meaning : 0 = preemp, 1 = non-preemp, 2 = coop
+ * @param pTypeArray - leave null if don't use, index value meaning : 0 =
+ * preemp, 1 = non-preemp, 2 = coop
* @boolean usePtypeArray - true if use pType array, otherwise false
* @return
*/
- public Time getRTAinMixedPreempiveEnvironment(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray, boolean usePtypeArray) {
+ public Time getRTAinMixedPreempiveEnvironment(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray,
+ boolean usePtypeArray) {
- /*How to decide what to use for thisTask
- * Step 1: determine what preemptive type thisTask is
- * Step 2: find out whether there is blocking from lp task (cuz np/c type task)
- * Step 3: choose the method by these criteria
- * - if (taskType == preemp/cooperative) && (blockingTime == 0)
- * => use normal level-i (getResponseTimeViaLvI) (1)
+ /*
+ * How to decide what to use for thisTask Step 1: determine what preemptive type
+ * thisTask is Step 2: find out whether there is blocking from lp task (cuz np/c
+ * type task) Step 3: choose the method by these criteria - if (taskType ==
+ * preemp/cooperative) && (blockingTime == 0) => use normal level-i
+ * (getResponseTimeViaLvI) (1)
*
- * - if (taskType == preemp/cooperative) && (blockingTime !=0)
- * => use level-i with preemptive mixed environment (getPreempCoopMixedTaskRTA) (2)
- * finishing time here is different than the above. finishingTime = startTime + execution time + preemption time
- * preemption time = time thisTask get preempted by other higher priority task in the same core.
- *
- * - if (taskType == non-preemp))
- * => use level-i with blocking (getNonPreemptaskRA) (3)
- * blockingTime doesn't matter here since even if there is no blocking time, the equation still hold true
- * important part is taskType is non-preemp which make finishingTime = startTime + execution time;
- *
- * */
+ * - if (taskType == preemp/cooperative) && (blockingTime !=0) => use level-i
+ * with preemptive mixed environment (getPreempCoopMixedTaskRTA) (2) finishing
+ * time here is different than the above. finishingTime = startTime + execution
+ * time + preemption time preemption time = time thisTask get preempted by other
+ * higher priority task in the same core.
+ *
+ * - if (taskType == non-preemp)) => use level-i with blocking
+ * (getNonPreemptaskRA) (3) blockingTime doesn't matter here since even if there
+ * is no blocking time, the equation still hold true important part is taskType
+ * is non-preemp which make finishingTime = startTime + execution time;
+ *
+ */
Time responseTime = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
- //time that lp tasks may block thisTask in worst case response time
- BigDecimal blockingTime = new BigDecimal(getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
+ // time that lp tasks may block thisTask in worst case response time
+ BigDecimal blockingTime = new BigDecimal(
+ getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
- /*check whether there is blocking time or not, see criteria above if confused */
+ /*
+ * check whether there is blocking time or not, see criteria above if confused
+ */
boolean blockingCheck = true;
if (blockingTime.equals(BigDecimal.ZERO)) {
blockingCheck = false;
@@ -129,15 +152,16 @@
int[] preemptiveArray;
if (usePtypeArray) {
preemptiveArray = pTypeArray.clone();
- }
- else {
+ } else {
preemptiveArray = this.preemptionTypeArray.clone();
}
- //Can just use the preemptionTypeArray for this but well whatever float the boat, FLOAT THE BOAT
- // String taskType = thisTask.getPreemption().getLiteral();
+ // Can just use the preemptionTypeArray for this but well whatever float the
+ // boat, FLOAT THE BOAT
+ // String taskType = thisTask.getPreemption().getLiteral();
/**
- * Have to use preemptive array here for more flexibility in the future. BOAT STILL FLOAT
+ * Have to use preemptive array here for more flexibility in the future. BOAT
+ * STILL FLOAT
*/
EList<Task> listTask = this.model.getSwModel().getTasks();
int taskIndex = listTask.indexOf(thisTask);
@@ -146,18 +170,17 @@
if (preempTypeValue == 0) {
taskType = "preemptive";
- }
- else if (preempTypeValue == 1) {
+ } else if (preempTypeValue == 1) {
taskType = "non_preemptive";
- }
- else if (preempTypeValue == 2) {
+ } else if (preempTypeValue == 2) {
taskType = "cooperative";
}
// (1) task is preemptable and there is no blocking time
if ((taskType.matches("preemptive") || taskType.matches("cooperative")) && !blockingCheck) {
if (logDebug) {
- log.debug("-------------- Task [{}] preemptive type is {} and there are no blocking from lower priority task, use normal Lv-i ",
+ log.debug(
+ "-------------- Task [{}] preemptive type is {} and there are no blocking from lower priority task, use normal Lv-i ",
thisTask.getName(), taskType);
}
@@ -166,7 +189,8 @@
// (2), task is preemptable and there is blocking time
else if ((taskType.matches("preemptive") || taskType.matches("cooperative")) && blockingCheck) {
if (logDebug) {
- log.debug("-------------- Task [{}] preemptive type is {} and there are are blocking from lower priority task, use Lv-i for mixed environment",
+ log.debug(
+ "-------------- Task [{}] preemptive type is {} and there are are blocking from lower priority task, use Lv-i for mixed environment",
thisTask.getName(), taskType);
}
@@ -176,26 +200,30 @@
// (3), task is non-preemptive
else if (taskType.matches("non_preemptive")) {
if (logDebug) {
- log.debug("-------------- Task [{}] preemptive type is {}, use Lv-i for non premptive task", thisTask.getName(), taskType);
+ log.debug("-------------- Task [{}] preemptive type is {}, use Lv-i for non premptive task",
+ thisTask.getName(), taskType);
}
responseTime = getNonPreemptaskRTA(thisTask, ia, executionCase, preemptiveArray, usePtypeArray);
}
-
return responseTime;
}
/**
- * Calculate classic RTA of task using this formula Ri = Ci + Sum j among HP(i)[Ri/Tj]*Cj
+ * Calculate classic RTA of task using this formula Ri = Ci + Sum j among
+ * HP(i)[Ri/Tj]*Cj
* https://www.it.uu.se/edu/course/homepage/realtid/ht10/schedule/Scheduling-periodic.pdf
+ *
* @param thisTask
* @param thisIA
* @return
*/
public Time getResponseTimeViaRecurrenceRelation(Task thisTask, int[] ia, final TimeType executionCase) {
Time result = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
- /*Initialize variable to compare previous and current iteration in the formula*/
+ /*
+ * Initialize variable to compare previous and current iteration in the formula
+ */
BigDecimal temp = BigDecimal.valueOf(2.0);
int[] thisIA = ia.clone();
@@ -203,17 +231,17 @@
List<Task> groupTaskList = groupTask(thisTask, thisIA);
List<Task> sortedTaskList = rtaia.taskSorting(groupTaskList);
- /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false*/
+ /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false */
boolean ultiCheck = getUltilizationCheck(sortedTaskList, thisIA, executionCase);
if (!ultiCheck) {
- //result is 0
+ // result is 0
return result;
}
int taskIndex = sortedTaskList.indexOf(thisTask);
- //Loop through all task inside the list (until thisTask)
+ // Loop through all task inside the list (until thisTask)
for (int i = 0; i < taskIndex + 1; i++) {
- //Highest priority -> get executed first all the damn time
+ // Highest priority -> get executed first all the damn time
if (taskIndex == 0) {
if (logDebug) {
String exeTimeString = df.format(getExecutionTime(thisTask, thisIA, executionCase).getValue());
@@ -223,10 +251,11 @@
return getExecutionTime(thisTask, thisIA, executionCase);
}
- //Calculate rta by looping until the result of the previous and current are the same
+ // Calculate rta by looping until the result of the previous and current are the
+ // same
else if (i == taskIndex) {
BigDecimal rZero = BigDecimal.ZERO;
- /*Set up r_0 for the calculation*/
+ /* Set up r_0 for the calculation */
for (int j = 0; j < i + 1; j++) {
Task jTask = sortedTaskList.get(j);
Time jTaskExecutionTime = getExecutionTime(jTask, thisIA, executionCase);
@@ -236,50 +265,52 @@
BigDecimal currentVal = rZero;
- //iterate until current value = previous value
+ // iterate until current value = previous value
while (!temp.equals(currentVal)) {
temp = currentVal;
/**
- * The iteration loop of
- * Ri = Ci + Sum of all hp(i)[Ri/Tj]*Cj (round up)
- * k loop are the part after the Sum symbol, after the loop we add Ci
+ * The iteration loop of Ri = Ci + Sum of all hp(i)[Ri/Tj]*Cj (round up) k loop
+ * are the part after the Sum symbol, after the loop we add Ci
*/
BigDecimal iteration = BigDecimal.ZERO;
for (int k = 0; k < i; k++) {
Task kTask = sortedTaskList.get(k);
Time kTaskExecutionTime = getExecutionTime(kTask, thisIA, executionCase);
Time kTaskPeriod = CommonUtils.getStimInTime(kTask);
- //Need to change all time value to PS for calculation
+ // Need to change all time value to PS for calculation
BigInteger kTaskPeriodInPs = AmaltheaServices.convertToPicoSeconds(kTaskPeriod);
- //execution time and period in bigDecimal
+ // execution time and period in bigDecimal
BigDecimal kTaskExetimeDec = new BigDecimal(kTaskExecutionTime.getValue());
BigDecimal kTaskPeriodDec = new BigDecimal(kTaskPeriodInPs);
- // multiplyPart = [Ri/Tj] * Cj
+ // multiplyPart = [Ri/Tj] * Cj
// RiTj = roundupPart, Cj = kTaskExetimeDec
BigDecimal roundUpPart = currentVal.divide(kTaskPeriodDec, 0, RoundingMode.CEILING);
BigDecimal multiplyPart = roundUpPart.multiply(kTaskExetimeDec);
iteration = iteration.add(multiplyPart);
}
- //Adding Ci after the iteration
+ // Adding Ci after the iteration
Task iTask = sortedTaskList.get(i);
- BigDecimal iTaskExecutionTimeDec = new BigDecimal(getExecutionTime(iTask, thisIA, executionCase).getValue());
+ BigDecimal iTaskExecutionTimeDec = new BigDecimal(
+ getExecutionTime(iTask, thisIA, executionCase).getValue());
currentVal = iteration.add(iTaskExecutionTimeDec);
}
- BigDecimal thisTaskPeriodInBigDec = new BigDecimal(AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(thisTask)));
+ BigDecimal thisTaskPeriodInBigDec = new BigDecimal(
+ AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(thisTask)));
if (currentVal.compareTo(thisTaskPeriodInBigDec) > 0 && this.schedubilityCheck) {
if (logError) {
String currentValString = df.format(currentVal);
String thisTaskPeriodInBigDecString = df.format(thisTaskPeriodInBigDec);
log.error("!!! UNSCHEDULABLE !!!");
- log.error("Response time of task [{}] is bigger than its period, return 0 for RT ", thisTask.getName());
+ log.error("Response time of task [{}] is bigger than its period, return 0 for RT ",
+ thisTask.getName());
log.error("{} > {}", currentValString, thisTaskPeriodInBigDecString);
}
- //result is 0
+ // result is 0
return result;
}
if (logInfo) {
@@ -287,7 +318,7 @@
log.info("{} ps - Task [{}] recurrence response time", currentValString, thisTask.getName());
}
- //result is currentVal calculated above
+ // result is currentVal calculated above
result.setValue(currentVal.toBigInteger());
}
}
@@ -295,8 +326,10 @@
}
/**
- * Calculate RT of thisTask using busy window technique (level-i busy period)
- * No blocking time is present here. This function is used for just simple preemptive environment case
+ * Calculate RT of thisTask using busy window technique (level-i busy period) No
+ * blocking time is present here. This function is used for just simple
+ * preemptive environment case
+ *
* @param thisTask
* @param ia
* @param executionCase
@@ -310,11 +343,10 @@
List<Task> groupTaskList = groupTask(thisTask, thisIA);
List<Task> sortedTaskList = rtaia.taskSorting(groupTaskList);
-
- /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false*/
+ /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false */
boolean ultiCheck = getUltilizationCheck(sortedTaskList, thisIA, executionCase);
if (!ultiCheck) {
- //result is 0
+ // result is 0
return responseTime;
}
@@ -332,11 +364,12 @@
BigDecimal iResponseTime = BigDecimal.ZERO;
while (!currentLv.equals(lv0)) {
lv0 = currentLv;
- //entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
+ // entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex + 1; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -348,7 +381,6 @@
log.debug("{} round up x {}entryValue", roundUpString, entryValueString);
}
-
iterationValue = iterationValue.add(entryValue);
}
currentLv = iterationValue;
@@ -358,7 +390,6 @@
log.debug("{} ps - level-i ", lv0String);
}
-
/* ----- Get K (total task iteration) ------ */
int bigK = lv0.divide(iPeriod, 0, RoundingMode.CEILING).intValue();
@@ -374,11 +405,12 @@
while (!kLv.equals(currentKLv)) {
currentKLv = kLv;
- //entry = each small sum of [Li/Tj]Cj, p_j > p_i, not >=
+ // entry = each small sum of [Li/Tj]Cj, p_j > p_i, not >=
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -393,7 +425,7 @@
}
}
kLv = iterationValue;
- kLv = kLv.add(kCi); //add k*Ci at the end of iteration
+ kLv = kLv.add(kCi); // add k*Ci at the end of iteration
if (logDebug) {
log.debug("finishTime = iterationValue + k*Ci: ");
String s1 = df.format(iterationValue);
@@ -402,7 +434,6 @@
log.debug("{} + {} + {}", s1, s2, s3);
}
-
}
/* ----- Get response time for each task (k) ------ */
BigDecimal taskStartTime = iPeriod.multiply(BigDecimal.valueOf(smallK1));
@@ -432,8 +463,7 @@
log.info("{} ps - Task [{}] level-i response time", s1, taskName);
}
-
- //Check schedulability
+ // Check schedulability
if (iResponseTime.compareTo(iPeriod) > 0 && this.schedubilityCheck) {
log.error("!!! UNSCHEDULABLE !!!");
log.error("Response time of task [{}] is bigger than its period, return 0 for RT ", taskName);
@@ -443,11 +473,10 @@
log.error("{} > {} ", s1, s2);
}
-
- //result is 0
+ // result is 0
return responseTime;
}
- //Set response time value after all calculation above
+ // Set response time value after all calculation above
responseTime.setValue(iResponseTime.toBigInteger());
return responseTime;
@@ -456,26 +485,28 @@
/**
* Calculate the execution time of longest/biggest runnable within task.
+ *
* @param thisTask
* @param ia
* @param executionCase
* @return
*/
private Time getLongestRunnableExecutionTime(Task thisTask, int[] ia, TimeType executionCase) {
- //set up decimal format for debugging
+ // set up decimal format for debugging
DecimalFormat df = new DecimalFormat("#,###.##");
- final int currentIndex = this.model.getSwModel().getTasks().indexOf(thisTask); //get index of the task in the array
+ final int currentIndex = this.model.getSwModel().getTasks().indexOf(thisTask); // get index of the task in the
+ // array
final int PUI = ia[currentIndex]; // get the index of processing unit
final List<ProcessingUnit> pul = CommonUtils.getPUs(this.model);
final ProcessingUnit pu = pul.get(PUI);
- //comparing value to get the longer one
+ // comparing value to get the longer one
Time longest = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
final List<Runnable> runnableList = SoftwareUtil.getRunnableList(thisTask, null);
RTARuntimeUtil rtautil = new RTARuntimeUtil();
- //In case a task doesn't invoke any runnable, better be careful than be sorry
+ // In case a task doesn't invoke any runnable, better be careful than be sorry
if (!runnableList.isEmpty()) {
for (Runnable r : runnableList) {
Time runnableTime = rtautil.getExecutionTimeForRTARunnable(r, pu, executionCase);
@@ -486,12 +517,11 @@
}
if (runnableList.isEmpty()) {
-
- log.error("!!!The task [{}] is doing nothing, no runnable called",thisTask.getName());
+
+ log.error("!!!The task [{}] is doing nothing, no runnable called", thisTask.getName());
}
- if (logDebug)
- {
+ if (logDebug) {
String s1 = df.format(longest.getValue());
log.debug("{} ps - Longest runnable of task [{}]", s1, thisTask.getName());
}
@@ -499,35 +529,37 @@
}
/**
- * Use when task is non-preemptive
- * Calculation thisTask's response time via level-i busy window technique.
- * reason is for non-preemp task, finishing time = start time + execution time.
- * Response time = finishing time - period, (using k-instance)
+ * Use when task is non-preemptive Calculation thisTask's response time via
+ * level-i busy window technique. reason is for non-preemp task, finishing time
+ * = start time + execution time. Response time = finishing time - period,
+ * (using k-instance)
+ *
* @param thisTask
* @param ia
* @param executionCase
- * @param pTypeArray - leave null if don't use
+ * @param pTypeArray - leave null if don't use
* @boolean usePtypeArray - true if use pType array, otherwise false
* @return
*/
- public Time getNonPreemptaskRTA(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray, boolean usePtypeArray) {
- //Adding decimal Format for better visual checking when debugging
- //ie 6000000000 ps -> 6,000,000,000 ps
+ private Time getNonPreemptaskRTA(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray,
+ boolean usePtypeArray) {
+ // Adding decimal Format for better visual checking when debugging
+ // ie 6000000000 ps -> 6,000,000,000 ps
Time responseTime = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
-
- //time that lp tasks may block thisTask in worst case response time
- BigDecimal blockingTime = new BigDecimal(getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
+ // time that lp tasks may block thisTask in worst case response time
+ BigDecimal blockingTime = new BigDecimal(
+ getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
CPURta rtaia = new CPURta(this.model);
int[] thisIA = ia.clone();
List<Task> sortedTaskList = rtaia.taskSorting(groupTask(thisTask, thisIA));
- /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false*/
+ /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false */
boolean ultiCheck = getUltilizationCheck(sortedTaskList, thisIA, executionCase);
if (!ultiCheck) {
- //response time = 0 here, cuz the core would be damned if we use this set
+ // response time = 0 here, cuz the core would be damned if we use this set
return responseTime;
}
@@ -536,7 +568,6 @@
BigInteger iPeriodInPs = AmaltheaServices.convertToPicoSeconds(iPeriodTime);
Time iExecutionTime = getExecutionTime(thisTask, thisIA, executionCase);
-
/* ----- Get LEVEL - I for each task ------ */
BigDecimal lv0 = BigDecimal.ZERO;
BigDecimal currentLv = BigDecimal.ONE;
@@ -545,8 +576,10 @@
BigDecimal iExe = new BigDecimal(iExecutionTime.getValue());
BigDecimal iResponseTime = BigDecimal.ZERO;
String taskName = thisTask.getName();
- /* If blocking time is equal/bigger than task period, then unschedulable for sure,
- * just return 0 and warning, no need for further calculation*/
+ /*
+ * If blocking time is equal/bigger than task period, then unschedulable for
+ * sure, just return 0 and warning, no need for further calculation
+ */
if (blockingTime.compareTo(iPeriod) >= 0 && this.schedubilityCheck) {
log.error("!!! UNSCHEDULABLE !!!");
log.error("Blocking time of task [{}] is bigger than its period, return 0 for RT ", taskName);
@@ -555,22 +588,24 @@
String s2 = df.format(iPeriod);
log.error("{} > {} ", s1, s2);
}
- //result is 0
+ // result is 0
return responseTime;
}
- //sum of execution time of all tasks with higher prio not including this task (in TU Dortmund say included, they are imbecile )
+ // sum of execution time of all tasks with higher prio not including this task
+ // (in TU Dortmund say included, they are imbecile )
BigDecimal hpCiSum = BigDecimal.ZERO;
int iterationCounterLvI = 0;
while (!currentLv.equals(lv0)) {
lv0 = currentLv;
- //entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
+ // entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex + 1; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -579,13 +614,14 @@
iterationValue = iterationValue.add(entryValue);
}
- //First entry of level-i = Bi + Ci, the sum above doesn't exist (or maybe 1, not gonna risk it hence the code below)
- //check non-premptive scheduler from TUDortmund pdf, google that shit
+ // First entry of level-i = Bi + Ci, the sum above doesn't exist (or maybe 1,
+ // not gonna risk it hence the code below)
+ // check non-premptive scheduler from TUDortmund pdf, google that shit
if (iterationCounterLvI == 0) {
iterationValue = iExe;
}
iterationCounterLvI++;
- /* -- Add blocking for nonpreemptive here-- current lv plus blocking*/
+ /* -- Add blocking for nonpreemptive here-- current lv plus blocking */
iterationValue = iterationValue.add(blockingTime);
currentLv = iterationValue;
}
@@ -598,8 +634,9 @@
/* ----- Get start time for each task ------ */
/**
- * Things get more complicated from here, we get preemption from higher prio, blocking from lower prio
- * so we have to calculate the START TIMEEEE with blocking, my man
+ * Things get more complicated from here, we get preemption from higher prio,
+ * blocking from lower prio so we have to calculate the START TIMEEEE with
+ * blocking, my man
*/
for (int smallK = 1; smallK <= bigK; smallK++) {
log.debug(" --- k instance : {}/{} --------------------------------------------", smallK, bigK);
@@ -608,7 +645,7 @@
int smallK1 = smallK - 1;
BigDecimal kCi1 = iExe.multiply(BigDecimal.valueOf(smallK1));
- //Equation from Tu Dortmund for this is wrong, it's < taskIndex, not < i.
+ // Equation from Tu Dortmund for this is wrong, it's < taskIndex, not < i.
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -619,11 +656,12 @@
while (!kLv.equals(currentKLv)) {
currentKLv = kLv;
- //entry = each small sum of [Li/Tj]Cj (rown down), j > i, not >=
+ // entry = each small sum of [Li/Tj]Cj (rown down), j > i, not >=
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -634,13 +672,13 @@
iterationValue = iterationValue.add(entryValue);
}
kLv = iterationValue;
- kLv = kLv.add(kCi1); //add k*Ci at the end of iteration
+ kLv = kLv.add(kCi1); // add k*Ci at the end of iteration
- //first iteration = Bi + hpCiSum
+ // first iteration = Bi + hpCiSum
if (iterationCounterK == 0) {
log.debug("hpCiSum - {} blocking {}", hpCiSum, blockingTime);
kLv = hpCiSum;
- //reseti this for next k-task
+ // reseti this for next k-task
hpCiSum = BigDecimal.ZERO;
}
log.debug("iterationValue + (k-1)*Ci + blockingtime (ignore if first iteration)");
@@ -680,7 +718,7 @@
log.info("{} ps - Task [{}] response time (non-preemp level-i)", s1, taskName);
}
- //Check schedulability
+ // Check schedulability
if (iResponseTime.compareTo(iPeriod) > 0 && this.schedubilityCheck) {
log.error("!!! UNSCHEDULABLE !!!");
log.error("Response time of task [{}] is bigger than its period, return 0 for RT ", taskName);
@@ -689,39 +727,45 @@
String s2 = df.format(iPeriod);
log.error("{} > {} ", s1, s2);
}
- //result is 0
+ // result is 0
return responseTime;
}
- //Set response time value after all calculation above
+ // Set response time value after all calculation above
responseTime.setValue(iResponseTime.toBigInteger());
return responseTime;
}
/**
- * Calculate time that [thisTask] would be blocked by lower priority task (when lp task is non-preemptive type or cooperative type)
+ * Calculate time that [thisTask] would be blocked by lower priority task (when
+ * lp task is non-preemptive type or cooperative type)
+ *
* @param thisTask
* @param ia
* @param executionCase
- * @param pTypeArray - leave null if don't use
+ * @param pTypeArray - leave null if don't use
* @boolean usePtypeArray - true if use pType array, otherwise false
* @return Time blockingTime
*/
- public Time getLowerPriorityBlockingTime(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray, boolean usePtypeArray) {
+ private Time getLowerPriorityBlockingTime(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray,
+ boolean usePtypeArray) {
Time blockingTime = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
int[] preemptiveArray;
int[] thisIA = ia.clone();
if (usePtypeArray) {
preemptiveArray = pTypeArray.clone();
- }
- else {
+ } else {
preemptiveArray = this.preemptionTypeArray.clone();
}
- /*Get list of tasks that are on the same processor, then sort it from higher prio -> lower prio*/
+ /*
+ * Get list of tasks that are on the same processor, then sort it from higher
+ * prio -> lower prio
+ */
CPURta rtaia = new CPURta(this.model);
- EList<Task> listTask = this.model.getSwModel().getTasks(); //just get all the task on the list, for fun, or check it yourself below
+ EList<Task> listTask = this.model.getSwModel().getTasks(); // just get all the task on the list, for fun, or
+ // check it yourself below
List<Task> groupTaskList = groupTask(thisTask, thisIA);
List<Task> sortedTaskList = rtaia.taskSorting(groupTaskList);
String taskName = thisTask.getName();
@@ -731,31 +775,37 @@
log.debug("-- get blocking time of task [{}] - period: {} ", taskName, s1);
}
- /*Reverse the order from highest -> lowest to the opposite lowest -> highest,whatever in front of our index is lower priority */
+ /*
+ * Reverse the order from highest -> lowest to the opposite lowest ->
+ * highest,whatever in front of our index is lower priority
+ */
Collections.reverse(sortedTaskList);
/*------------------- Get blocking time from lp task ------------------*/
- /* Loop through all the task in the sorted Task list and until we see thisTask, calculate blocking time while looping,
- * the longest among all blocking time will be WCBlockingTime for [thisTask]
- * I have reversed the order of the task list above so we will capture all task with lower priority via top down iteration
- * lowest -> highest prio
- * and when we get to [thisTask], that means we have scanned all task with lower priority -> break the loop
+ /*
+ * Loop through all the task in the sorted Task list and until we see thisTask,
+ * calculate blocking time while looping, the longest among all blocking time
+ * will be WCBlockingTime for [thisTask] I have reversed the order of the task
+ * list above so we will capture all task with lower priority via top down
+ * iteration lowest -> highest prio and when we get to [thisTask], that means we
+ * have scanned all task with lower priority -> break the loop
*/
for (Task task : sortedTaskList) {
- //Get out of the loop when we met thisTask in the sorted task list
- //Without this, lowerPriorityTaskList will add the task with higher priority
+ // Get out of the loop when we met thisTask in the sorted task list
+ // Without this, lowerPriorityTaskList will add the task with higher priority
if (task.equals(thisTask)) {
break;
}
Time tempBlockingTime = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
int taskIndex = listTask.indexOf(task);
- int preempTypeValue = preemptiveArray[taskIndex];//listTask used to get preemptive type my dude,
+ int preempTypeValue = preemptiveArray[taskIndex];// listTask used to get preemptive type my dude,
String preemp = task.getPreemption().getLiteral();
Time taskPeriod = CommonUtils.getStimInTime(task);
log.debug(" checking task" + " [{}] - period {}- preemptiveType : {}", task.getName(), taskPeriod, preemp);
- //If task has lower priority and is non-preemptive (preempTypeValue = 1 ), calculate that task's execution time
+ // If task has lower priority and is non-preemptive (preempTypeValue = 1 ),
+ // calculate that task's execution time
if (!task.equals(thisTask) && preempTypeValue == 1) {
tempBlockingTime = getExecutionTime(task, thisIA, executionCase);
if (logDebug) {
@@ -768,7 +818,8 @@
}
- //If task has lower priority and is cooperative (preempTypeValue = 2 ), calculate the longest runnable
+ // If task has lower priority and is cooperative (preempTypeValue = 2 ),
+ // calculate the longest runnable
else if (!task.equals(thisTask) && preempTypeValue == 2) {
tempBlockingTime = getLongestRunnableExecutionTime(task, thisIA, executionCase);
if (logDebug) {
@@ -779,8 +830,11 @@
if (tempBlockingTime.compareTo(blockingTime) >= 0)
blockingTime = tempBlockingTime;
}
- /* If all lower priority task are neither non-preemptive nor cooperative, blocking time = 0 (because it can only be preemptive)
- * These line can be omit but meh, for a clearer picture (or messy I don't know)*/
+ /*
+ * If all lower priority task are neither non-preemptive nor cooperative,
+ * blocking time = 0 (because it can only be preemptive) These line can be omit
+ * but meh, for a clearer picture (or messy I don't know)
+ */
if (tempBlockingTime.compareTo(blockingTime) >= 0)
blockingTime = tempBlockingTime;
}
@@ -791,33 +845,38 @@
}
return blockingTime;
}
+
/**
- * calculate task's response time when thisTask is preemptive/cooperative type and there exist non-preemp/cooperative task with lower priority
- * finishing time = start time + execution time + preemption by higher priority task(s).
+ * calculate task's response time when thisTask is preemptive/cooperative type
+ * and there exist non-preemp/cooperative task with lower priority finishing
+ * time = start time + execution time + preemption by higher priority task(s).
* Response time = finishing time - period, (using k-instance)
+ *
* @param thisTask
* @param ia
* @param executionCase
- * @param pTypeArray - leave null if don't use
+ * @param pTypeArray - leave null if don't use
* @boolean usePtypeArray - true if use pType array, otherwise false
* @return
*/
- public Time getPreempCoopMixedTaskRTA(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray, boolean usePtypeArray) {
- //Adding decimal Format for better visual checking when debugging
- //ie 6000000000 ps -> 6,000,000,000 ps
+ private Time getPreempCoopMixedTaskRTA(Task thisTask, int[] ia, TimeType executionCase, int[] pTypeArray,
+ boolean usePtypeArray) {
+ // Adding decimal Format for better visual checking when debugging
+ // ie 6000000000 ps -> 6,000,000,000 ps
Time responseTime = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
- //time that lp tasks may block thisTask in worst case response time
- BigDecimal blockingTime = new BigDecimal(getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
+ // time that lp tasks may block thisTask in worst case response time
+ BigDecimal blockingTime = new BigDecimal(
+ getLowerPriorityBlockingTime(thisTask, ia, executionCase, pTypeArray, usePtypeArray).getValue());
CPURta rtaia = new CPURta(this.model);
int[] thisIA = ia.clone();
List<Task> sortedTaskList = rtaia.taskSorting(groupTask(thisTask, thisIA));
- /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false*/
+ /* Check ultilization value here, if ultiValue > 100% then ultiCheck = false */
boolean ultiCheck = getUltilizationCheck(sortedTaskList, thisIA, executionCase);
if (!ultiCheck) {
- //response time = 0 here, cuz the core would be damned if we use this set
+ // response time = 0 here, cuz the core would be damned if we use this set
return responseTime;
}
@@ -826,7 +885,6 @@
BigInteger iPeriodInPs = AmaltheaServices.convertToPicoSeconds(iPeriodTime);
Time iExecutionTime = getExecutionTime(thisTask, thisIA, executionCase);
-
/* ----- Get LEVEL - I for each task ------ */
BigDecimal lv0 = BigDecimal.ZERO;
BigDecimal currentLv = BigDecimal.ONE;
@@ -836,8 +894,10 @@
BigDecimal iResponseTime = BigDecimal.ZERO;
String taskName = thisTask.getName();
- /* If blocking time is equal/bigger than task period, then unschedulable for sure,
- * just return 0 and warning, no need for further calculation*/
+ /*
+ * If blocking time is equal/bigger than task period, then unschedulable for
+ * sure, just return 0 and warning, no need for further calculation
+ */
if (blockingTime.compareTo(iPeriod) >= 0 && schedubilityCheck) {
log.error("!!! UNSCHEDULABLE !!!");
log.error("Blocking time of task [{}] is bigger than its period, return 0 for RT ", taskName);
@@ -846,22 +906,24 @@
String s2 = df.format(iPeriod);
log.error("{} > {} ", s1, s2);
}
- //result is 0
+ // result is 0
return responseTime;
}
- //sum of execution time of all tasks with higher prio not including this task (in TU Dortmund say included, they are imbecile )
+ // sum of execution time of all tasks with higher prio not including this task
+ // (in TU Dortmund say included, they are imbecile )
BigDecimal hpCiSum = BigDecimal.ZERO;
int iterationCounterLvI = 0;
while (!currentLv.equals(lv0)) {
lv0 = currentLv;
- //entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
+ // entry = each small sum of [Li/Tj]Cj, p_j >= p_i ( i = taskIndex)
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex + 1; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -870,14 +932,17 @@
iterationValue = iterationValue.add(entryValue);
}
- //First entry of level-i = Bi + Ci, the sum above doesn't exist (or maybe 1, not gonna risk it hence the code below)
- //check non-premptive scheduler from TUDortmund pdf, google that shit
+ // First entry of level-i = Bi + Ci, the sum above doesn't exist (or maybe 1,
+ // not gonna risk it hence the code below)
+ // check non-premptive scheduler from TUDortmund pdf, google that shit
if (iterationCounterLvI == 0) {
iterationValue = iExe;
}
iterationCounterLvI++;
- /* -- Add blocking if there is non-preemptive or cooperative in the set ----
- * iteration = current lv + blocking*/
+ /*
+ * -- Add blocking if there is non-preemptive or cooperative in the set ----
+ * iteration = current lv + blocking
+ */
iterationValue = iterationValue.add(blockingTime);
currentLv = iterationValue;
}
@@ -890,8 +955,9 @@
/* ----- Get start time for each task ------ */
/**
- * Things get more complicated from here, we get preemption from higher prio, blocking from lower prio
- * so we have to calculate the START TIMEEEE with blocking, my man
+ * Things get more complicated from here, we get preemption from higher prio,
+ * blocking from lower prio so we have to calculate the START TIMEEEE with
+ * blocking, my man
*/
for (int smallK = 1; smallK <= bigK; smallK++) {
log.debug(" --- k instance : {}/{} --------------------------------------------", smallK, bigK);
@@ -900,7 +966,7 @@
int smallK1 = smallK - 1;
BigDecimal kCi1 = iExe.multiply(BigDecimal.valueOf(smallK1));
- //Equation from Tu Dortmund for this is wrong, it's < taskIndex, not < i.
+ // Equation from Tu Dortmund for this is wrong, it's < taskIndex, not < i.
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -911,11 +977,12 @@
while (!kLv.equals(currentKLv)) {
currentKLv = kLv;
- //entry = each small sum of [Li/Tj]Cj (rown down), j > i, not >=
+ // entry = each small sum of [Li/Tj]Cj (rown down), j > i, not >=
BigDecimal iterationValue = BigDecimal.ZERO;
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
@@ -926,13 +993,13 @@
iterationValue = iterationValue.add(entryValue);
}
kLv = iterationValue;
- kLv = kLv.add(kCi1); //add k*Ci at the end of iteration
+ kLv = kLv.add(kCi1); // add k*Ci at the end of iteration
- //first iteration = Bi + hpCiSum
+ // first iteration = Bi + hpCiSum
if (iterationCounterK == 0) {
log.debug("hpCiSum - {} blocking {}", hpCiSum, blockingTime);
kLv = hpCiSum;
- //reseti this for next k-task
+ // reseti this for next k-task
hpCiSum = BigDecimal.ZERO;
}
log.debug("iterationValue + (k-1)*Ci + blockingtime (ignore if first iteration)");
@@ -945,51 +1012,58 @@
/* ----- Get response time for each task (k) ------ */
BigDecimal taskStartTime = kLv;
BigDecimal taskStartPeriod = iPeriod.multiply(BigDecimal.valueOf(smallK1));
- /*task finishing time in this case = startTime + Ci + hp_task's preemptive time */
+ /*
+ * task finishing time in this case = startTime + Ci + hp_task's preemptive time
+ */
BigDecimal taskFinishingTime;
BigDecimal kTaskFinishingTime = BigDecimal.ONE;
BigDecimal currentFinishingTime = BigDecimal.ZERO;
- /* if task is not non-preemptive (coop-preemptive) then
- * finishingTime = startTime + Ci + hp_task's preemptive time
- * challenge here is to calculate the preemption from higher priority task*/
+ /*
+ * if task is not non-preemptive (coop-preemptive) then finishingTime =
+ * startTime + Ci + hp_task's preemptive time challenge here is to calculate the
+ * preemption from higher priority task
+ */
while (!kTaskFinishingTime.equals(currentFinishingTime)) {
currentFinishingTime = kTaskFinishingTime;
BigDecimal iterationValue = BigDecimal.ZERO;
- /*this entry loop will return the preemption time from higher priority task*/
+ /* this entry loop will return the preemption time from higher priority task */
for (int entry = 0; entry < taskIndex; entry++) {
Task entryTask = sortedTaskList.get(entry);
- BigInteger entryPeriodInPs = AmaltheaServices.convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
+ BigInteger entryPeriodInPs = AmaltheaServices
+ .convertToPicoSeconds(CommonUtils.getStimInTime(entryTask));
BigDecimal entryPeriod = new BigDecimal(entryPeriodInPs);
BigDecimal entryExe = new BigDecimal(getExecutionTime(entryTask, thisIA, executionCase).getValue());
- //roundUp = [fi/tj]up
+ // roundUp = [fi/tj]up
BigDecimal roundUp = currentFinishingTime.divide(entryPeriod, 0, RoundingMode.CEILING);
- //roundDown = [si/tj]down
+ // roundDown = [si/tj]down
BigDecimal roundDown = kLv.divide(entryPeriod, 0, RoundingMode.FLOOR);
- //roundDownPlusOne = [si/tj]down +1
+ // roundDownPlusOne = [si/tj]down +1
BigDecimal roundDownPlusOne = roundDown.add(BigDecimal.ONE);
- //bigSum =([fi/tj]up - ([si/tj]down + 1))
+ // bigSum =([fi/tj]up - ([si/tj]down + 1))
BigDecimal bigSum = roundUp.subtract(roundDownPlusOne);
- //this is the preemption time from higher prio task
+ // this is the preemption time from higher prio task
BigDecimal entryValue = bigSum.multiply(entryExe);
- // iteration value = Sum of all entry (each hp task give 1 entry, sum all entry = preemption time, hence the for loop mate)
+ // iteration value = Sum of all entry (each hp task give 1 entry, sum all entry
+ // = preemption time, hence the for loop mate)
iterationValue = iterationValue.add(entryValue);
log.debug("([fi/tj]up - ([si/tj]down + 1)) : {} - {}", roundUp, roundDownPlusOne);
log.debug("Sum*Ci= {} = {} x {}", entryValue, bigSum, entryExe);
}
- /*finishingTime = startTime + Ci + hp_task's preemptive time */
+ /* finishingTime = startTime + Ci + hp_task's preemptive time */
log.debug("Finishing time = s + Ci + preemp (Sum*Ci) : {} + {} + {}", kLv, iExe, iterationValue);
iterationValue = iterationValue.add(kLv).add(iExe);
kTaskFinishingTime = iterationValue;
}
- //I can just use the kTaskFinishingTime for the calculation below but
- //....well for the asthetic, taskfinishingTime sound more...in sync with the others
+ // I can just use the kTaskFinishingTime for the calculation below but
+ // ....well for the asthetic, taskfinishingTime sound more...in sync with the
+ // others
taskFinishingTime = kTaskFinishingTime;
if (logDebug) {
String s1 = df.format(taskStartTime);
@@ -1003,8 +1077,9 @@
String s1 = df.format(taskResponseTime);
log.debug("{} - this k instance response time ", s1);
}
- //biggest value among all k-instance in our busy period would be the worse case response time
- //but...best case? it is thisTask execution time :))
+ // biggest value among all k-instance in our busy period would be the worse case
+ // response time
+ // but...best case? it is thisTask execution time :))
if (taskResponseTime.compareTo(iResponseTime) >= 0) {
iResponseTime = taskResponseTime;
}
@@ -1018,7 +1093,7 @@
log.info("{} ps - Task [{}] level-i response time in mixed preemptive environment", s1, taskName);
}
- //Check schedulability
+ // Check schedulability
if (iResponseTime.compareTo(iPeriod) > 0 && schedubilityCheck) {
log.error("!!! UNSCHEDULABLE !!!");
log.error("Response time of task [{}] is bigger than its period, return 0 for RT ", taskName);
@@ -1027,26 +1102,27 @@
String s2 = df.format(iPeriod);
log.error("{} > {} ", s1, s2);
}
- //result is 0
+ // result is 0
return responseTime;
}
- //Set response time value after all calculation above
+ // Set response time value after all calculation above
responseTime.setValue(iResponseTime.toBigInteger());
return responseTime;
}
-
-
/**
- * this function will get PURE execution time via calculate execution time of task's runnables
+ * this function will get PURE execution time via calculate execution time of
+ * task's runnables
+ *
* @param thisTask
* @param ia
* @return
*/
public Time getPureExecutionTime(Task thisTask, int[] ia, final TimeType executionCase) {
Time result = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
- final int currentIndex = this.model.getSwModel().getTasks().indexOf(thisTask); //get index of the task in the array
+ final int currentIndex = this.model.getSwModel().getTasks().indexOf(thisTask); // get index of the task in the
+ // array
final int PUI = ia[currentIndex]; // get the index of processing unit
final List<ProcessingUnit> pul = CommonUtils.getPUs(this.model);
final ProcessingUnit pu = pul.get(PUI);
@@ -1055,7 +1131,10 @@
/* The list of runnables of the given task */
final List<Runnable> runnableList = SoftwareUtil.getRunnableList(thisTask, null);
- /*Add all execution time of runnable inside thisTask to get its PURE execution time*/
+ /*
+ * Add all execution time of runnable inside thisTask to get its PURE execution
+ * time
+ */
for (Runnable r : runnableList) {
Time runnableExecutionTime = rtautil.getExecutionTimeForRTARunnable(r, pu, executionCase);
result = result.add(runnableExecutionTime);
@@ -1063,8 +1142,10 @@
return result;
}
- /**May sound stupid in the beginning but this will make things easier to control when
- * Adding blocking/contention at the end of the function.
+ /**
+ * May sound stupid in the beginning but this will make things easier to control
+ * when Adding blocking/contention at the end of the function.
+ *
* @param thisTask
* @param ia
* @param executionCase
@@ -1073,24 +1154,37 @@
private Time getExecutionTime(Task thisTask, int[] ia, final TimeType executionCase) {
Time result = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
- result = result.add(getPureExecutionTime(thisTask, ia, executionCase));
/**
- * Add other blocking/waiting method here if needed.
+ * Add other blocking/waiting method here if needed.
*/
+
+ /*------------------------------Blocking--------------------------------------*/
+ Blocking blk = new Blocking(ia, this.model);
+ Time localBlockingTime = blk.getLocalBlockingTime(thisTask, executionCase);
+ Time globalBlockingTIme = blk.getGlobalBlockingTime(thisTask, executionCase);
+
+ /*Add local and global blocking time of this task to its execution*/
+ result = result.add(localBlockingTime).add(globalBlockingTIme);
+
+ /*-----------------------Pure execution (Label access + ticks)----------------*/
+ /*Add task execution time (label access + ticks)*/
+ result = result.add(getPureExecutionTime(thisTask, ia, executionCase));
+
return result;
}
-
+
/**
- * Get core ultilization percentage by Sum all [Ci/Ti] (i = tasks in the same core)
- * return false If [Ci/Ti] > 1 or ulti percentage > 100%
- * groupTask = List<Task> that in the same core
+ * Get core ultilization percentage by Sum all [Ci/Ti] (i = tasks in the same
+ * core) return false If [Ci/Ti] > 1 or ulti percentage > 100% groupTask =
+ * List<Task> that in the same core
+ *
* @param groupTask
* @param ia
* @param executionCase
* @return
*/
- public boolean getUltilizationCheck(List<Task> groupTask, int[] ia, TimeType executionCase) {
+ private boolean getUltilizationCheck(List<Task> groupTask, int[] ia, TimeType executionCase) {
boolean checkValue = true;
BigDecimal ultiValue = BigDecimal.ZERO;
int[] thisIA = ia.clone();
@@ -1099,26 +1193,25 @@
Time taskExe = getExecutionTime(task, thisIA, executionCase);
BigDecimal numerator = new BigDecimal(taskExe.getValue());
BigDecimal denominator = new BigDecimal(AmaltheaServices.convertToPicoSeconds(taskPeriod));
- //scale = 9 here means 9 digit after the damn commaaaaa, why scale 9? because feng shui my dude.
+ // scale = 9 here means 9 digit after the damn commaaaaa, why scale 9? because
+ // feng shui my dude.
BigDecimal division = numerator.divide(denominator, 9, RoundingMode.HALF_UP);
ultiValue = ultiValue.add(division);
}
- if (logDebug)
- {
+ if (logDebug) {
String s1 = ultiValue.multiply(BigDecimal.valueOf(100)).toString();
log.debug("{} % - core ultilization Value ", s1);
}
-
- //if ultilization percentage > 100% then core exceed it maximum workable ability, should never happen
+ // if ultilization percentage > 100% then core exceed it maximum workable
+ // ability, should never happen
if (ultiValue.compareTo(BigDecimal.ONE) > 0) {
log.error("!!! UNSCHEDULABLE !!!");
- if (logError)
- {
+ if (logError) {
String s1 = ultiValue.multiply(BigDecimal.valueOf(100)).toString();
- log.error("Ultilization value :{} exceed 100% ",s1);
+ log.error("Ultilization value :{} exceed 100% ", s1);
}
-
+
checkValue = false;
}
@@ -1126,7 +1219,7 @@
}
/**
- * Initialize preemptive array.
+ * Initialize preemptive array.
*/
private void setupPTArray() {
@@ -1137,23 +1230,19 @@
String preemp = task.getPreemption().getLiteral();
if (preemp.matches("preemptive")) {
this.preemptionTypeArray[taskIndex] = 0;
- }
- else if (preemp.matches("non_preemptive")) {
+ } else if (preemp.matches("non_preemptive")) {
this.preemptionTypeArray[taskIndex] = 1;
- }
- else if (preemp.matches("cooperative")) {
+ } else if (preemp.matches("cooperative")) {
this.preemptionTypeArray[taskIndex] = 2;
}
}
- if (logDebug)
- {
+ if (logDebug) {
String s1 = Arrays.toString(this.ia);
- String s2 = Arrays.toString(this.preemptionTypeArray) ;
+ String s2 = Arrays.toString(this.preemptionTypeArray);
log.debug("{} - ia", s1);
- log.debug("{} - pta",s2);
+ log.debug("{} - pta", s2);
}
-
}
@@ -1174,5 +1263,4 @@
}
-
}
diff --git a/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/test/NonPreemptMixTest.java b/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/test/NonPreemptMixTest.java
index bd54ce5..c4df587 100644
--- a/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/test/NonPreemptMixTest.java
+++ b/eclipse-tools/responseTime-analyzer/plugins/org.eclipse.app4mc.gsoc_rta/src/org/eclipse/app4mc/gsoc_rta/test/NonPreemptMixTest.java
@@ -19,8 +19,6 @@
import java.io.File;
import java.math.BigInteger;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
import org.eclipse.app4mc.amalthea.model.Amalthea;
import org.eclipse.app4mc.amalthea.model.Task;
import org.eclipse.app4mc.amalthea.model.io.AmaltheaLoader;
@@ -28,22 +26,17 @@
import org.eclipse.app4mc.gsoc_rta.NPandPRTA;
import org.eclipse.app4mc.gsoc_rta.SharedConsts;
import org.eclipse.emf.common.util.EList;
-import org.junit.BeforeClass;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class NonPreemptMixTest {
int[] iap = { 5, 2, 5, 3, 3, 1, 3, 5, 1, 0, 0, 6, 4, 6 };
- @BeforeClass
- public static void init() {
- org.apache.log4j.BasicConfigurator.configure();
- Logger.getRootLogger().setLevel(Level.DEBUG);
- }
@Test
- public void testPureExecutionForTask()
- {
- final Logger log = Logger.getLogger(NonPreemptMixTest.class);
+ public void testPureExecutionForTask() {
+ final Logger log = LoggerFactory.getLogger(NonPreemptMixTest.class);
final Amalthea inputModel = AmaltheaLoader.loadFromFile(new File(SharedConsts.FHDO_MODELZNP));
NPandPRTA nprta = new NPandPRTA(inputModel, iap);
EList<Task> listTask = inputModel.getSwModel().getTasks();
@@ -57,162 +50,123 @@
else if (i == 1) {
assertEquals(BigInteger.valueOf(14753760000l), timeValue);
- }
- else if (i == 2) {
+ } else if (i == 2) {
assertEquals(BigInteger.valueOf(1861275000l), timeValue);
- }
- else if (i == 3) {
+ } else if (i == 3) {
assertEquals(BigInteger.valueOf(600000000l), timeValue);
- }
- else if (i == 4) {
+ } else if (i == 4) {
assertEquals(BigInteger.valueOf(4762510000l), timeValue);
- }
- else if (i == 5) {
+ } else if (i == 5) {
assertEquals(BigInteger.valueOf(12597052500l), timeValue);
- }
- else if (i == 6) {
+ } else if (i == 6) {
assertEquals(BigInteger.valueOf(9785855000l), timeValue);
- }
- else if (i == 7) {
+ } else if (i == 7) {
assertEquals(BigInteger.valueOf(18579392500l), timeValue);
- }
- else if (i == 8) {
+ } else if (i == 8) {
assertEquals(BigInteger.valueOf(8125495500l), timeValue);
- }
- else if (i == 9) {
+ } else if (i == 9) {
assertEquals(BigInteger.valueOf(4775267000l), timeValue);
- }
- else if (i == 10) {
+ } else if (i == 10) {
assertEquals(BigInteger.valueOf(28317754000l), timeValue);
- }
- else if (i == 11) {
+ } else if (i == 11) {
assertEquals(BigInteger.valueOf(124156673331l), timeValue);
- }
- else if (i == 12) {
+ } else if (i == 12) {
assertEquals(BigInteger.valueOf(52294720000l), timeValue);
- }
- else if (i == 13) {
+ } else if (i == 13) {
assertEquals(BigInteger.valueOf(116286459997l), timeValue);
}
}
}
-
+
@Test
- public void testNonPreempMixForTask()
- {
+ public void testRTAinMixedPreemptive() {
final Amalthea inputModel = AmaltheaLoader.loadFromFile(new File(SharedConsts.FHDO_MODELZNP));
- final Logger log = Logger.getLogger(NonPreemptMixTest.class);
+ final Logger log = LoggerFactory.getLogger(NonPreemptMixTest.class);
NPandPRTA nprta = new NPandPRTA(inputModel, iap);
EList<Task> listTask = inputModel.getSwModel().getTasks();
log.info("Start testing non-preemp mix");
for (int i = 0; i < listTask.size(); i++) {
Task thisTask = listTask.get(i);
- BigInteger timeValue = nprta.getNonPreemptaskRTA(thisTask, iap, TimeType.WCET).getValue();
+ nprta.setSchedubilityCheck(false);
+ BigInteger timeValue = nprta.getRTAinMixedPreempiveEnvironment(thisTask, iap, TimeType.WCET, null, false)
+ .getValue();
if (i == 0) {
- assertEquals(BigInteger.valueOf(79780400000l), timeValue);
+ assertEquals(BigInteger.valueOf(51861531000l), timeValue);
}
else if (i == 1) {
- assertEquals(BigInteger.valueOf(14753760000l), timeValue);
+ assertEquals(BigInteger.valueOf(15831910666l), timeValue);
+ } else if (i == 2) {
+ assertEquals(BigInteger.valueOf(51861531000l), timeValue);
+ } else if (i == 3) {
+ assertEquals(BigInteger.valueOf(5367192665l), timeValue);
}
- else if (i == 2) {
- assertEquals(BigInteger.valueOf(0), timeValue);
- }
- else if (i == 3) {
- assertEquals(BigInteger.valueOf(5362510000l), timeValue);
- }
-
else if (i == 4) {
- assertEquals(BigInteger.valueOf(5362510000l), timeValue);
- }
- else if (i == 5) {
- assertEquals(BigInteger.valueOf(12597052500l), timeValue);
- }
- else if (i == 6) {
- assertEquals(BigInteger.valueOf(21110875000l), timeValue);
- }
- else if (i == 7) {
- assertEquals(BigInteger.valueOf(189307842500l), timeValue);
- }
- else if (i == 8) {
- assertEquals(BigInteger.valueOf(58513705500l), timeValue);
- }
- else if (i == 9) {
- assertEquals(BigInteger.valueOf(61410775000l), timeValue);
- }
- else if (i == 10) {
- assertEquals(BigInteger.valueOf(28317754000l), timeValue);
- }
- else if (i == 11) {
- assertEquals(BigInteger.valueOf(356729593325l), timeValue);
- }
- else if (i == 12) {
- assertEquals(BigInteger.valueOf(52294720000l), timeValue);
- }
- else if (i == 13) {
- assertEquals(BigInteger.valueOf(116286459997l), timeValue);
+ assertEquals(BigInteger.valueOf(5367192665l), timeValue);
+ } else if (i == 5) {
+ assertEquals(BigInteger.valueOf(12997745165l), timeValue);
+ } else if (i == 6) {
+ assertEquals(BigInteger.valueOf(21377381663l), timeValue);
+ } else if (i == 7) {
+ assertEquals(BigInteger.valueOf(192198033498l), timeValue);
+ } else if (i == 8) {
+ assertEquals(BigInteger.valueOf(76220158810l), timeValue);
+ } else if (i == 9) {
+ assertEquals(BigInteger.valueOf(65418756999l), timeValue);
+ } else if (i == 10) {
+ assertEquals(BigInteger.valueOf(30203254000l), timeValue);
+ } else if (i == 11) {
+ assertEquals(BigInteger.valueOf(360172777325l), timeValue);
+ } else if (i == 12) {
+ assertEquals(BigInteger.valueOf(52794816000l), timeValue);
+ } else if (i == 13) {
+ assertEquals(BigInteger.valueOf(117067715997l), timeValue);
}
}
}
-
+
@Test
- public void testClassicRTAForTask()
- {
+ public void testClassicRTAForTask() {
final Amalthea inputModel = AmaltheaLoader.loadFromFile(new File(SharedConsts.FHDO_MODELZNP));
- final Logger log = Logger.getLogger(NonPreemptMixTest.class);
+ final Logger log = LoggerFactory.getLogger(NonPreemptMixTest.class);
NPandPRTA nprta = new NPandPRTA(inputModel, iap);
EList<Task> listTask = inputModel.getSwModel().getTasks();
log.info("Start testing classic rta");
for (int i = 0; i < listTask.size(); i++) {
Task thisTask = listTask.get(i);
- BigInteger timeValue = nprta.getClassicRTA(thisTask, iap, TimeType.WCET).getValue();
+ BigInteger timeValue = nprta.getResponseTimeViaRecurrenceRelation(thisTask, iap, TimeType.WCET).getValue();
if (i == 0) {
assertEquals(BigInteger.valueOf(79780400000l), timeValue);
}
else if (i == 1) {
assertEquals(BigInteger.valueOf(14753760000l), timeValue);
- }
- else if (i == 2) {
+ } else if (i == 2) {
assertEquals(BigInteger.valueOf(1861275000l), timeValue);
- }
- else if (i == 3) {
+ } else if (i == 3) {
assertEquals(BigInteger.valueOf(600000000l), timeValue);
- }
- else if (i == 4) {
+ } else if (i == 4) {
assertEquals(BigInteger.valueOf(5362510000l), timeValue);
- }
- else if (i == 5) {
+ } else if (i == 5) {
assertEquals(BigInteger.valueOf(12597052500l), timeValue);
- }
- else if (i == 6) {
+ } else if (i == 6) {
assertEquals(BigInteger.valueOf(21110875000l), timeValue);
- }
- else if (i == 7) {
+ } else if (i == 7) {
assertEquals(BigInteger.valueOf(189307842500l), timeValue);
- }
- else if (i == 8) {
+ } else if (i == 8) {
assertEquals(BigInteger.valueOf(58513705500l), timeValue);
- }
- else if (i == 9) {
+ } else if (i == 9) {
assertEquals(BigInteger.valueOf(61410775000l), timeValue);
- }
- else if (i == 10) {
+ } else if (i == 10) {
assertEquals(BigInteger.valueOf(28317754000l), timeValue);
- }
- else if (i == 11) {
+ } else if (i == 11) {
assertEquals(BigInteger.valueOf(356729593325l), timeValue);
- }
- else if (i == 12) {
+ } else if (i == 12) {
assertEquals(BigInteger.valueOf(52294720000l), timeValue);
- }
- else if (i == 13) {
+ } else if (i == 13) {
assertEquals(BigInteger.valueOf(116286459997l), timeValue);
}
}
}
-
-
-
}