-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPowerTestVmSchedulerTimeShared.java
104 lines (87 loc) · 2.94 KB
/
PowerTestVmSchedulerTimeShared.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.cloudsub.cloudsim.power_examples;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
/**
*
* @author Zahra Bagheri
*/
public class PowerTestVmSchedulerTimeShared extends VmSchedulerTimeShared{
public PowerTestVmSchedulerTimeShared(List<? extends Pe> pelist) {
super(pelist);
}
/*
* (non-Javadoc)
* @see cloudsim.VmScheduler#allocatePesForVm(cloudsim.Vm, java.util.List)
*/
@Override
public boolean allocatePesForVm(Vm vm, List<Double> mipsShareRequested) {
/**
* TODO: add the same to RAM and BW provisioners
*/
if (vm.isInMigration()) {
if (!getVmsMigratingIn().contains(vm.getUid()) && !getVmsMigratingOut().contains(vm.getUid())) {
getVmsMigratingOut().add(vm.getUid());
}
} else {
if (getVmsMigratingOut().contains(vm.getUid())) {
getVmsMigratingOut().remove(vm.getUid());
}
// if (getVmsMigratingIn().contains(vm.getUid())){
mipsShareRequested.set(0, vm.getMips());
// }
}
boolean result = allocatePesForVm(vm.getUid(), mipsShareRequested);
updatePeProvisioning();
return result;
}
/**
* Allocate pes for vm.
*
* @param vmUid the vm uid
* @param mipsShareRequested the mips share requested
* @return true, if successful
*/
@Override
protected boolean allocatePesForVm(String vmUid, List<Double> mipsShareRequested) {
double totalRequestedMips = 0;
double peMips = getPeCapacity();
for (Double mips : mipsShareRequested) {
// each virtual PE of a VM must require not more than the capacity of a physical PE
if (mips > peMips) {
return false;
}
totalRequestedMips += mips;
}
// This scheduler does not allow over-subscription
if (getAvailableMips() < totalRequestedMips) {
return false;
}
getMipsMapRequested().put(vmUid, mipsShareRequested);
setPesInUse(getPesInUse() + mipsShareRequested.size());
if (getVmsMigratingIn().contains(vmUid)) {
// the destination host only experience 10% of the migrating VM's MIPS
totalRequestedMips *= 0.1;
}
List<Double> mipsShareAllocated = new ArrayList<Double>();
for (Double mipsRequested : mipsShareRequested) {
if (getVmsMigratingOut().contains(vmUid)) {
// performance degradation due to migration = 10% MIPS
mipsRequested *= 0.9;
} else if (getVmsMigratingIn().contains(vmUid)) {
// the destination host only experience 10% of the migrating VM's MIPS
mipsRequested *= 0.1;
}
mipsShareAllocated.add(mipsRequested);
}
getMipsMap().put(vmUid, mipsShareAllocated);
setAvailableMips(getAvailableMips() - totalRequestedMips);
return true;
}
}