1 | package de.uka.ipd.sdq.scheduler.priority.update; |
2 | |
3 | import de.uka.ipd.sdq.scheduler.SchedulerModel; |
4 | import de.uka.ipd.sdq.scheduler.priority.IPriorityUpdateStrategy; |
5 | import de.uka.ipd.sdq.scheduler.processes.IActiveProcess; |
6 | import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority; |
7 | import de.uka.ipd.sdq.scheduler.sensors.impl.SleepAverageSensor; |
8 | |
9 | |
10 | public class SleepAverageDependentUpdate implements IPriorityUpdateStrategy { |
11 | |
12 | private SchedulerModel model; |
13 | private SleepAverageSensor sleepAverageSensor; |
14 | |
15 | // parameters according to the Linux 2.6.22 scheduler. |
16 | private double max_sleep_average; |
17 | private int max_bonus; |
18 | |
19 | public SleepAverageDependentUpdate(SchedulerModel model, IActiveProcess process, double max_sleep_average, int max_bonus) { |
20 | sleepAverageSensor = new SleepAverageSensor(model, process, max_sleep_average, max_bonus); |
21 | process.addStateSensor(sleepAverageSensor); |
22 | this.model = model; |
23 | this.max_bonus = max_bonus; |
24 | this.max_sleep_average = max_sleep_average; |
25 | } |
26 | |
27 | /** |
28 | * Implementation according to the current Linux 2.6.18 Scheduler |
29 | */ |
30 | public boolean update(ProcessWithPriority process) { |
31 | int current_bonus = sleepAverageSensor.getCurrentBonus(); |
32 | current_bonus -= max_bonus / 2; |
33 | process.setToStaticPriorityWithBonus(current_bonus); |
34 | if (process.getRunQueue() != null){ |
35 | double starvation_limit = max_sleep_average * process.getRunQueue().getCurrentLoad(); |
36 | boolean process_starving = process.getRunQueue().processStarving(starvation_limit); |
37 | if (isInteractive(process) |
38 | && process.getTimeslice().isFinished() |
39 | && !process_starving){ |
40 | process.getTimeslice().fullReset(); |
41 | } |
42 | } |
43 | return true; |
44 | } |
45 | |
46 | |
47 | |
48 | public boolean isInteractive(ProcessWithPriority p){ |
49 | // int delta = p.getStaticPriority().getValue() * max_bonus / 40 + 2; |
50 | // IPriority threshold = p.getStaticPriority().addBonus(delta); |
51 | // IPriority prio = p.getDynamicPriority(); |
52 | // return threshold.lessOrEqual(prio); |
53 | double sleep = sleepAverageSensor.interactiveSleep(p); |
54 | return sleepAverageSensor.getSleepAverage() > sleep; |
55 | } |
56 | |
57 | public SleepAverageDependentUpdate cloneFor(ProcessWithPriority process) { |
58 | return new SleepAverageDependentUpdate(model, process, max_sleep_average, max_bonus); |
59 | } |
60 | |
61 | } |