From 8b8db890e8b718447593a60c0393bb6ce32b9e69 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 6 Jun 2020 21:48:09 +0200 Subject: Added more cli to ruby scheduler --- sem4/embedded/eksamnen/M7opg.adoc | 61 +++++++++++++++++++++++++++++++++-- sem4/embedded/eksamnen/schedsolver.rb | 52 ++++++++++++++++++++++++++--- 2 files changed, 106 insertions(+), 7 deletions(-) diff --git a/sem4/embedded/eksamnen/M7opg.adoc b/sem4/embedded/eksamnen/M7opg.adoc index 7bb41c5..b98c43a 100644 --- a/sem4/embedded/eksamnen/M7opg.adoc +++ b/sem4/embedded/eksamnen/M7opg.adoc @@ -16,9 +16,6 @@ ____ _Does utilization guarantee feasibility of an RMA schedule?_ ____ -Ved at køre RMA fra 0 til 400, kan man se at der er schedulable. - - Først regner jeg utilization ud. @@ -33,3 +30,61 @@ Derefter kan man regne utilization critereon ud. ---- Her kan man garantere at RMA er schedulable. + +____ +_Validate an RMA schedule with the exact schedulability criterion._ +____ + +Her sætter jeg bægge til at starte på samme tid og tester hver. + +---- +i T0 T1 R0 R1 D0 D1 i T0 T1 R0 R1 D0 D1 +0 | 19 20 60 50 0 | 19 20 60 50 +1 | 18 20 59 49 1 | 18 20 59 49 +2 | 17 20 58 48 2 | 17 20 58 48 +3 | 16 20 57 47 3 | 16 20 57 47 +4 | 15 20 56 46 4 | 15 20 56 46 +5 | 14 20 55 45 5 | 14 20 55 45 +6 | 13 20 54 44 6 | 13 20 54 44 +7 | 12 20 53 43 7 | 12 20 53 43 +8 | 11 20 52 42 8 | 11 20 52 42 +9 | 10 20 51 41 9 | 10 20 51 41 +10 | 9 20 50 40 10 | 9 20 50 40 +11 | 8 20 49 39 11 | 8 20 49 39 +12 | 7 20 48 38 12 | 7 20 48 38 +13 | 6 20 47 37 13 | 6 20 47 37 +14 | 5 20 46 36 14 | 5 20 46 36 +15 | 4 20 45 35 15 | 4 20 45 35 +16 | 3 20 44 34 16 | 3 20 44 34 +17 | 2 20 43 33 17 | 2 20 43 33 +18 | 1 20 42 32 18 | 1 20 42 32 +19 | 0 20 41 31 19 | 0 20 41 31 + 20 | 0 19 40 30 + 21 | 0 18 39 29 + 22 | 0 17 38 28 + 23 | 0 16 37 27 + 24 | 0 15 36 26 + 25 | 0 14 35 25 + 26 | 0 13 34 24 + 27 | 0 12 33 23 + 28 | 0 11 32 22 + 29 | 0 10 31 21 + 30 | 0 9 30 20 + 31 | 0 8 29 19 + 32 | 0 7 28 18 + 33 | 0 6 27 17 + 34 | 0 5 26 16 + 35 | 0 4 25 15 + 36 | 0 3 24 14 + 37 | 0 2 23 13 + 38 | 0 1 22 12 + 39 | 0 0 21 11 +---- + +Her kan man se at de begge bliver completed. + +____ +_What is the optimal fixed priority schedule ?_ +____ + +Hvis alle deadlines er mindre end periode vil man sige at det er diff --git a/sem4/embedded/eksamnen/schedsolver.rb b/sem4/embedded/eksamnen/schedsolver.rb index bf9c467..c75b52b 100755 --- a/sem4/embedded/eksamnen/schedsolver.rb +++ b/sem4/embedded/eksamnen/schedsolver.rb @@ -3,11 +3,16 @@ require 'optparse' class Scheduler - def initialize(tasks) + def initialize() @states = [] + @tasks = [] + end + + def loadtasks(tasks) @tasks = tasks end + def printHeader() print "i".ljust(4, ' ') @tasks.length.times do |i| @@ -100,7 +105,7 @@ class Scheduler return new end - def run() + def run(runtil=nil) printHeader() # Run LCM times @@ -114,6 +119,9 @@ class Scheduler printState(i, new) + if runtil && new[:remain][runtil] == 0 + break + end end end end @@ -138,6 +146,25 @@ def taskFromString(str) return task end +class FixedSched < Scheduler + alias_method :parent_init, :initialize + def initialize(priorities) + @priorities = priorities + + parent_init + end + + def nextTask(index) + @priorities.each do |taskid| + if !@states.last or @states.last[:remain][taskid] > 0 + return taskid + end + end + + return nil + end +end + class RmaSched < Scheduler def nextTask(index) smallestTask = nil @@ -159,6 +186,17 @@ OptionParser.new do |opts| opts.on("-f", "--taskfile FILE", "Load tasks from FILE") do |f| options[:taskfile] = f end + opts.on("--until-done TASK", "Run until TASK finishes") do |task| + options[:runtil] = Integer(task) + end + opts.on("--sched-rma", "Schedule using rma") do + options[:sched] = RmaSched.new() + end + opts.on("--sched-fixed PRIO", "Schedule using fixed priority list PRIO") do |prio| + prio = prio.split(",") + prio.map! {|p| Integer(p) } + options[:sched] = FixedSched.new(prio) + end end.parse! tasks = [] @@ -183,5 +221,11 @@ end puts tasks.inspect -sch = RmaSched.new(tasks) -sch.run() +sch = nil +if options[:sched] + sch = options[:sched] +else + sch = Scheduler.new() +end +sch.loadtasks(tasks) +sch.run(options[:runtil]) -- cgit v1.2.3