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

COVERAGE SUMMARY FOR SOURCE FILE [SimProcessorSharingResource.java]

nameclass, %method, %block, %line, %
SimProcessorSharingResource.java0%   (0/2)0%   (0/18)0%   (0/356)0%   (0/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimProcessorSharingResource0%   (0/1)0%   (0/16)0%   (0/304)0%   (0/62)
<static initializer> 0%   (0/1)0%   (0/10)0%   (0/2)
SimProcessorSharingResource (SchedulerModel, String, String, int): void 0%   (0/1)0%   (0/19)0%   (0/4)
access$0 (SimProcessorSharingResource): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (SimProcessorSharingResource): Hashtable 0%   (0/1)0%   (0/3)0%   (0/1)
dequeue (ISchedulableProcess): void 0%   (0/1)0%   (0/1)0%   (0/1)
doProcessing (ISchedulableProcess, int, double): void 0%   (0/1)0%   (0/54)0%   (0/11)
enqueue (ISchedulableProcess): void 0%   (0/1)0%   (0/1)0%   (0/1)
getQueueLengthFor (SimResourceInstance): int 0%   (0/1)0%   (0/4)0%   (0/1)
getRemainingDemand (ISchedulableProcess): double 0%   (0/1)0%   (0/16)0%   (0/4)
getSpeed (): double 0%   (0/1)0%   (0/17)0%   (0/2)
registerProcess (IRunningProcess): void 0%   (0/1)0%   (0/1)0%   (0/1)
scheduleNextEvent (): void 0%   (0/1)0%   (0/81)0%   (0/11)
start (): void 0%   (0/1)0%   (0/1)0%   (0/1)
stop (): void 0%   (0/1)0%   (0/1)0%   (0/1)
toNow (): void 0%   (0/1)0%   (0/48)0%   (0/9)
updateDemand (ISchedulableProcess, double): void 0%   (0/1)0%   (0/44)0%   (0/12)
     
class SimProcessorSharingResource$ProcessingFinishedEvent0%   (0/1)0%   (0/2)0%   (0/52)0%   (0/13)
SimProcessorSharingResource$ProcessingFinishedEvent (SimProcessorSharingResou... 0%   (0/1)0%   (0/9)0%   (0/3)
eventRoutine (ISchedulableProcess): void 0%   (0/1)0%   (0/43)0%   (0/10)

1package de.uka.ipd.sdq.scheduler.resources.active;
2 
3import java.util.Hashtable;
4import java.util.Map.Entry;
5 
6import de.uka.ipd.sdq.probfunction.math.util.MathTools;
7import de.uka.ipd.sdq.scheduler.IRunningProcess;
8import de.uka.ipd.sdq.scheduler.ISchedulableProcess;
9import de.uka.ipd.sdq.scheduler.LoggingWrapper;
10import de.uka.ipd.sdq.scheduler.SchedulerModel;
11import de.uka.ipd.sdq.simulation.abstractsimengine.AbstractSimEventDelegator;
12 
13public class SimProcessorSharingResource extends AbstractActiveResource {
14        
15        /**
16         * The minimum amount of time used for scheduling an event 
17         */
18        static double JIFFY = 1e-9;
19        
20        private class ProcessingFinishedEvent extends AbstractSimEventDelegator<ISchedulableProcess> {
21                                
22                public ProcessingFinishedEvent(SchedulerModel model) {
23                        super(model, ProcessingFinishedEvent.class.getName());
24                }
25 
26                @Override
27                public void eventRoutine(ISchedulableProcess process) {
28                        ISchedulableProcess last = process;
29                        toNow();
30                        running_processes.remove(last);
31                        // fire changes of the queue length only, if there is one single core. 
32                        // With more cores, one cannot say on which core a job has been processed.
33                        if (getCapacity() == 1) {
34                                fireStateChange(running_processes.size(), 0);
35                        }
36                        fireDemandCompleted(last);
37                        LoggingWrapper.log(last + " finished.");
38                        scheduleNextEvent();
39                        last.activate();
40                }
41                
42        }
43        
44        private ProcessingFinishedEvent processingFinished;
45        private Hashtable<ISchedulableProcess,Double> running_processes = new Hashtable<ISchedulableProcess, Double>();
46        private double last_time; 
47 
48        public SimProcessorSharingResource(SchedulerModel model, String name, String id, int i) {
49                super(model, i, name, id);
50                this.processingFinished = new ProcessingFinishedEvent(model);
51        }
52 
53        public void scheduleNextEvent() {
54                ISchedulableProcess shortest = null;
55                for (ISchedulableProcess process : running_processes.keySet()) {
56                        if (shortest == null || running_processes.get(shortest) > running_processes.get(process)){
57                                shortest = process;
58                        }
59                }
60                processingFinished.removeEvent();
61                if (shortest!=null){
62                        double remainingTime = running_processes.get(shortest) * getSpeed();
63                        
64                        // avoid trouble caused by rounding issues
65                        remainingTime = remainingTime < JIFFY ? 0.0 : remainingTime; 
66                        
67                        assert remainingTime >= 0 : "Remaining time ("+ remainingTime +")small than zero!";
68                        
69                        processingFinished.schedule(shortest, remainingTime);
70                }
71        }
72 
73 
74        private void toNow() {
75                double now = getModel().getSimulationControl().getCurrentSimulationTime();
76                double passed_time = now - last_time;
77                if (MathTools.less(0, passed_time)){
78                        passed_time /= getSpeed(); 
79                        for (Entry<ISchedulableProcess,Double> e : running_processes.entrySet()) {
80                                double rem =   e.getValue() - passed_time;
81                                e.setValue(rem);
82                        }
83                }
84                last_time = now;
85        }
86 
87 
88        private double getSpeed() {
89                double speed = (double)running_processes.size() / (double)getCapacity();
90                return speed < 1.0 ? 1.0 : speed;
91        }
92 
93 
94        public void start() {
95        }
96 
97 
98        @Override
99        protected void dequeue(ISchedulableProcess process) {
100        }
101 
102 
103        @Override
104        protected void doProcessing(ISchedulableProcess process, int resourceServiceID, double demand) {
105                toNow();
106                LoggingWrapper.log("PS: " + process + " demands " + demand);
107                if(demand < JIFFY)
108                {
109                        demand = JIFFY;
110                        LoggingWrapper.log("PS: " + process + " demand was increased to match JIFFY " + demand);
111                }
112        
113                running_processes.put(process, demand);
114                // fire changes of the queue length only, if there is one single core. 
115                // With more cores, one cannot say on which core a job has been processed.
116                if (getCapacity() == 1) {
117                        fireStateChange(running_processes.size(), 0);
118                }
119                scheduleNextEvent();
120                process.passivate();
121        }
122        
123        
124        @Override
125        public double getRemainingDemand(ISchedulableProcess process) {
126                if (!running_processes.contains(process)) {
127                        return 0.0;
128                }
129                toNow();
130                return running_processes.get(process);
131        }
132        
133        @Override
134        public void updateDemand(ISchedulableProcess process, double demand) {
135                boolean updated = false;
136                for (Entry<ISchedulableProcess,Double> e : running_processes.entrySet()) {
137                        if (e.getKey().equals(process)) {
138                                if (Double.isNaN(demand)) {
139                                    // TODO PM: Should an exception be thrown here? At least, a log entry should be written. 
140                                        System.out.println();
141                                }
142                                e.setValue(demand);
143                                updated = true;
144                                break;
145                        }
146                }
147                if (updated == false) {
148                        throw new RuntimeException("COULD NOT UPDATE PROCESS!");
149                }
150                scheduleNextEvent();
151        }
152 
153        @Override
154        protected void enqueue(ISchedulableProcess process) {
155        }
156 
157        public void registerProcess(IRunningProcess runningProcess) {
158        }
159        
160        public int getQueueLengthFor(SimResourceInstance simResourceInstance) {
161                return this.running_processes.size();
162        }
163 
164        public void stop() {
165        }
166 
167}

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