package mvd.jester.tests; import java.math.RoundingMode; import java.util.Map.Entry; import com.google.common.math.LongMath; import mvd.jester.model.Segment; import mvd.jester.model.Task; import mvd.jester.model.SystemSetup; /** * SchmidMottok */ public class SchmidMottok extends AbstractTest { public SchmidMottok(SystemSetup systemSetup) { super(systemSetup); } @Override public boolean runSchedulabilityCheck() { responseTimes.clear(); for (Task t : systemSetup.getTasks()) { responseTimes.put(t, calculateResponseTime(t)); } for (Entry taskResponsePair : responseTimes.entrySet()) { if (taskResponsePair.getKey().getDeadline() < taskResponsePair.getValue().longValue()) { return false; } } return true; } @Override public String getName() { return "SchmidMottok"; } private long calculateResponseTime(Task task) { long minimumWcet = getMinimumWcet(task); long responseTime = minimumWcet; long previousResponseTime = 0; long numberOfProcessors = systemSetup.getNumberOfProcessors(); do { previousResponseTime = responseTime; double taskInterference = 0; for (Task t : systemSetup.getTasks()) { if (t.getPeriod() < task.getPeriod()) { long numberOfJobs = t.getMaximumParallelism() > numberOfProcessors ? numberOfProcessors : t.getMaximumParallelism(); for (int p = 0; p < numberOfJobs; ++p) { taskInterference += Math.min(getTaskInterference(t, responseTime, p + 1), responseTime - minimumWcet + 1); } } } taskInterference /= numberOfProcessors; double selfInterference = getSelfInterference(task); long totalInterference = (long) Math.floor(taskInterference + selfInterference); responseTime = minimumWcet + totalInterference; } while (previousResponseTime != responseTime); return responseTime; } private double getSelfInterference(Task task) { double interference = 0; long numberOfProcessors = systemSetup.getNumberOfProcessors(); long numberOfJobs = task.getMaximumParallelism() > numberOfProcessors ? numberOfProcessors : task.getMaximumParallelism(); for (Segment s : task.getSegments()) { interference += (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet(); } interference /= numberOfJobs; return interference; } private double getTaskInterference(Task task, long interval, long parallelism) { if (responseTimes.containsKey(task)) { long responseTime = responseTimes.get(task); long minWcet = getMinimumWcet(task); long period = task.getPeriod(); long numberOfProcessors = systemSetup.getNumberOfProcessors(); long amountOfJobs = (LongMath.divide(interval + responseTime - minWcet, period, RoundingMode.FLOOR) + 1); double workload = 0; for (Segment s : task.getSegments()) { long numberOfJobs = s.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors : s.getNumberOfJobs(); if (numberOfJobs >= parallelism) { workload += s.getNumberOfTasklets() * s.getTaskletWcet() / numberOfJobs; } } double interference = amountOfJobs * workload; return interference; } else { throw new RuntimeException("Task was not found in task set!"); } } private long getMinimumWcet(Task task) { long minWcet = 0; for (Segment s : task.getSegments()) { minWcet += s.getTaskletWcet(); } return minWcet; } }