/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2010, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.core.CloudSim;
/**
* cloudletschedulerspaceshared实现了vm对于cloudlet的一个调度策略
*
* CloudletSchedulerSpaceShared implements a policy of
* scheduling performed by a virtual machine. It consider
* that there will be only one cloudlet per VM. Other cloudlets will be in a
* waiting list. We consider that file transfer from cloudlets waiting happens
* before cloudlet execution. I.e., even though cloudlets must wait for CPU,
* data transfer happens as soon as cloudlets are submitted.
*
* @author Rodrigo N. Calheiros
* @author Anton Beloglazov
* @since CloudSim Toolkit 1.0
*/
public class CloudletSchedulerSpaceShared extends CloudletScheduler {
/** The cloudlet waiting list. */
private List<? extends ResCloudlet> cloudletWaitingList;
/** The cloudlet exec list. */
private List<? extends ResCloudlet> cloudletExecList;
/** The cloudlet paused list. */
private List<? extends ResCloudlet> cloudletPausedList;
/** The cloudlet finished list. */
private List<? extends ResCloudlet> cloudletFinishedList;
/** The current CPUs. */
protected int currentCpus;
/** The used PEs. */
protected int usedPes;
/**
* Creates a new CloudletSchedulerSpaceShared object. This method must be invoked
* before starting the actual simulation.
*
* @pre $none
* @post $none
*/
public CloudletSchedulerSpaceShared() {
//父类字段:previoustime和currentmipshare
super();
this.cloudletWaitingList = new ArrayList<ResCloudlet>();
this.cloudletExecList = new ArrayList<ResCloudlet>();
this.cloudletPausedList = new ArrayList<ResCloudlet>();
this.cloudletFinishedList = new ArrayList<ResCloudlet>();
this.usedPes = 0;
this.currentCpus = 0;
}
/**
* 当前时间,更新cloudlet状态,当有任务完成时,加入新的任务,返回下一个任务完成的时刻
* Updates the processing of cloudlets running under management of this scheduler.
*
* @param currentTime current simulation time
* @param mipsShare array with MIPS share of each processor available to the scheduler
* 每个cpu提供的计算能力
* @return time predicted completion time of the earliest finishing cloudlet, or 0
* if there is no next events
*
* @pre currentTime >= 0
* @post $none
*/
@Override
public double updateVmProcessing(double currentTime, List<Double> mipsShare) {
setCurrentMipsShare(mipsShare);
double timeSpam = currentTime - getPreviousTime(); // time since last update
double capacity = 0.0;
int cpus = 0;
for (Double mips : mipsShare) { // count the CPUs available to the VMM
capacity += mips;
if (mips > 0) {
cpus++;
}
}
currentCpus = cpus;
capacity /= cpus; // average capacity of each cpu
for (ResCloudlet rcl : getCloudletExecList()) { // cpu个数等于任务在exec队列中乘以pe个数each machine in the exec list has the same amount of cpu
rcl.updateCloudletFinishedSoFar((long) (capacity * timeSpam * rcl.getPesNumber()));
}
if (getCloudletExecList().size() == 0 && getCloudletWaitingList().size() == 0) { // no more cloudlets in this scheduler
setPreviousTime(currentTime); //所有任务执行完毕,设置此时刻
return 0.0;
}
//update each cloudlet
int finished = 0;
int cont = 0;
List<ResCloudlet> toRemove = new ArrayList<ResCloudlet>();
for (ResCloudlet rcl : getCloudletExecList()) {
if (rcl.getRemainingCloudletLength() == 0.0) {// finished anyway, rounding issue...
toRemove.add(rcl);
clo
云计算仿真工具中文注释CloudletSchedulerSpaceShared.java
最新推荐文章于 2022-03-23 16:35:35 发布