EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.scheduler.strategy.impl]

COVERAGE SUMMARY FOR SOURCE FILE [PreemptiveScheduler.java]

nameclass, %method, %block, %line, %
PreemptiveScheduler.java0%   (0/1)0%   (0/14)0%   (0/251)0%   (0/76)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PreemptiveScheduler0%   (0/1)0%   (0/14)0%   (0/251)0%   (0/76)
PreemptiveScheduler (SchedulerModel, SimActiveResource, IQueueingStrategy, bo... 0%   (0/1)0%   (0/13)0%   (0/4)
applyStarvationBoost (ProcessWithPriority): void 0%   (0/1)0%   (0/17)0%   (0/4)
getInterval (): double 0%   (0/1)0%   (0/3)0%   (0/1)
getQueueLengthFor (SimResourceInstance): int 0%   (0/1)0%   (0/5)0%   (0/1)
hasHigherPriority (ProcessWithPriority, ProcessWithPriority): boolean 0%   (0/1)0%   (0/18)0%   (0/7)
isIdle (IResourceInstance): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
lookForStarvingProcessesAndApplyStarvationBoost (IResourceInstance): void 0%   (0/1)0%   (0/25)0%   (0/4)
schedule (IResourceInstance): void 0%   (0/1)0%   (0/39)0%   (0/13)
scheduleNextEvent (IResourceInstance): void 0%   (0/1)0%   (0/46)0%   (0/14)
scheduleNextProcess (IResourceInstance): void 0%   (0/1)0%   (0/14)0%   (0/4)
scheduleNextProcess (ProcessWithPriority, IResourceInstance): void 0%   (0/1)0%   (0/11)0%   (0/5)
terminateProcess (IActiveProcess, IResourceInstance): void 0%   (0/1)0%   (0/19)0%   (0/6)
toNow (ProcessWithPriority): void 0%   (0/1)0%   (0/5)0%   (0/3)
unschedule (ProcessWithPriority, boolean, IResourceInstance): void 0%   (0/1)0%   (0/31)0%   (0/9)

1package de.uka.ipd.sdq.scheduler.strategy.impl;
2 
3import scheduler.configuration.StarvationBoost;
4import de.uka.ipd.sdq.scheduler.ISchedulableProcess;
5import de.uka.ipd.sdq.scheduler.SchedulerModel;
6import de.uka.ipd.sdq.scheduler.priority.IPriority;
7import de.uka.ipd.sdq.scheduler.priority.IPriorityUpdateStrategy;
8import de.uka.ipd.sdq.scheduler.priority.update.SetToBaseUpdate;
9import de.uka.ipd.sdq.scheduler.processes.IActiveProcess;
10import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority;
11import de.uka.ipd.sdq.scheduler.queueing.IQueueingStrategy;
12import de.uka.ipd.sdq.scheduler.resources.IResourceInstance;
13import de.uka.ipd.sdq.scheduler.resources.active.SimActiveResource;
14import de.uka.ipd.sdq.scheduler.resources.active.SimResourceInstance;
15 
16public class PreemptiveScheduler extends AbstractScheduler {
17        
18    private SchedulerModel model;
19    
20        public PreemptiveScheduler(SchedulerModel model, SimActiveResource resource,
21                        IQueueingStrategy queueingStrategy, boolean in_front_after_waiting,
22                        double scheduling_interval, StarvationBoost starvationBoost) {
23                super(resource, queueingStrategy, in_front_after_waiting, starvationBoost);
24                this.model = model;
25                this.scheduling_interval = scheduling_interval;
26        }
27 
28        
29        public void schedule(IResourceInstance instance) {
30                if (instance.isScheduling())
31                        return;
32                
33                // Balance the runqueue of this instance with the runqueues of other
34                // instances. This might change the state of the instance's runqueue.
35                // So, the next runnable process can only be determined after the
36                // balancing was finished.
37                queueing_strategy.activelyBalance(instance);
38                
39                // get the currently scheduled process for the instance.
40                ProcessWithPriority running_process = (ProcessWithPriority) instance
41                                .getRunningProcess();
42 
43                // Update the timing variables and priority of the process. Possibly
44                // pending events of the process are canceled.
45                toNow(running_process);
46                
47                if (running_process == null){
48                } else if ( running_process.getTimeslice().isFinished()) {
49                        unschedule(running_process, false, instance);
50                } else {
51                        unschedule(running_process, true, instance);
52                }
53                scheduleNextProcess(instance);
54                scheduleNextEvent(instance);
55        }
56        
57 
58        private void scheduleNextProcess(ProcessWithPriority next_process, IResourceInstance instance) {
59                if (next_process != null) {
60                        next_process.toNow();
61                        next_process.update();
62                        fromReadyToRunningOn(next_process, instance);
63                }
64        }
65 
66        private void scheduleNextProcess(IResourceInstance instance) {
67                lookForStarvingProcessesAndApplyStarvationBoost(instance);
68                
69                ProcessWithPriority next_process = (ProcessWithPriority) queueing_strategy.getNextProcessFor(instance);
70                scheduleNextProcess(next_process, instance);
71        }
72 
73        private void lookForStarvingProcessesAndApplyStarvationBoost(IResourceInstance instance) {
74                if(starvationBoost != null){
75                        for (IActiveProcess p : queueing_strategy.getStarvingProcesses(instance, starvationBoost.getStarvationLimit())){
76                                applyStarvationBoost((ProcessWithPriority)p);
77                        }
78                                
79                }
80                
81        }
82 
83        private void applyStarvationBoost(ProcessWithPriority p) {
84                p.setToStaticPriorityWithBonus(starvationBoost.getBoost());
85                IPriorityUpdateStrategy priorityUpdateStrategy = new SetToBaseUpdate(starvationBoost.getDurationInTimeslices());
86                p.setPriorityUpdateStrategy(priorityUpdateStrategy);
87        }
88 
89 
90        private void toNow(ProcessWithPriority process) {
91                if (process != null){
92                        process.toNow();
93                }
94        }
95 
96        private void unschedule(ProcessWithPriority running_process,
97                        boolean next_has_higher_priority, IResourceInstance current) {
98                if (running_process != null) {
99                        if (running_process.getTimeslice().isFinished()){
100                                running_process.update(); 
101                                fromRunningToReady(running_process, current, false);
102                                running_process.getTimeslice().fullReset();
103                        } else {
104                                fromRunningToReady(running_process, current, next_has_higher_priority);
105                        }
106                        if (running_process.getRunQueue().getCurrentLoad() == 1){
107                                        running_process.getRunQueue().resetStarvationInfo();
108                        }
109                } 
110        }
111 
112        /**
113         * pOne > pTwo ?
114         * 
115         * @param pTwo
116         * @return
117         */
118        private boolean hasHigherPriority(ProcessWithPriority pOne,
119                        ProcessWithPriority pTwo) {
120                if (pOne == null)
121                        return false;
122                if (pTwo == null)
123                        return true;
124                IPriority prio_one = pOne.getDynamicPriority();
125                IPriority prio_two = pTwo.getDynamicPriority();
126                return prio_one.greaterThan(prio_two);
127        }
128 
129        public void scheduleNextEvent(IResourceInstance instance) {
130                double time = model.getSimulationControl().getCurrentSimulationTime();
131                ProcessWithPriority running = (ProcessWithPriority) instance
132                                .getRunningProcess();
133                if (running != null) {
134                        running.toNow();
135                        double remainingTime = running.getTimeslice().getRemainingTime();
136                        double currentDemand = running.getCurrentDemand();
137                        if ( currentDemand < remainingTime )
138                                running.scheduleProceedEvent(this);
139                        else
140                                instance.scheduleSchedulingEvent(remainingTime);
141                } else {
142                        if (!queueing_strategy.isIdle(instance))
143                                instance.scheduleSchedulingEvent(0);
144                        else
145                                instance.scheduleSchedulingEvent(scheduling_interval);
146                }
147        }
148 
149        
150        public boolean isIdle(IResourceInstance instance) {
151                return queueing_strategy.isIdle(instance);
152        }
153 
154        
155        public double getInterval() {
156                return scheduling_interval;
157        }
158        
159        @Override
160        public void terminateProcess(IActiveProcess process, IResourceInstance current) {
161                super.terminateProcess(process, current);
162                ISchedulableProcess sProcess = process.getSchedulableProcess();
163                if (sProcess.isFinished()
164                                // do NOT remove the originally defined processes as they
165                                // serve as prototypes for all spawned processes.
166                                && sProcess.getRootProcess() != sProcess){
167                        this.resource.unregisterProcess(process);
168                }
169        }
170 
171 
172        public int getQueueLengthFor(SimResourceInstance simResourceInstance) {
173                return this.queueing_strategy.getQueueLengthFor(simResourceInstance);
174        }
175 
176 
177}

[all classes][de.uka.ipd.sdq.scheduler.strategy.impl]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov