Пример #1
0
	def __init__(self):
	  self.APC_GPU_DB = []
	  self.VM_Identifier = Identifier()
	  self.coordinator = PStateRebalance()
Пример #2
0
class VirtualThief:
	APC_GPU_DB = []
	VM_Identifier = Identifier()
	coordinator = PStateRebalance()
	statesPool = [1600000, 1800000, 1900000, 2100000, 2200000, 2400000, 2500000, 2700000, 2900000, 3000000, 3200000, 3300000, 3500000, 3600000, 3800000, 3801000]

	# Constructor
	def __init__(self):
	  self.APC_GPU_DB = []
	  self.VM_Identifier = Identifier()
	  self.coordinator = PStateRebalance()

	# VM_Identifier initialization
	def initialize_VM_Identifier(self):
	  self.VM_Identifier.initializeST()
	  #self.VM_Identifier.printVMStandard()

	# VM characterization
	def characterize_VM(self):
	  self.VM_Identifier.analyzeVM()
	  #self.VM_Identifier.printVMPool()

	# APC_GPU_DB initialization
	def initializeDB(self):
	  try:
	    fd = open("APC_GPU_DB.txt", "r")
	  except IOError:
	    print "APC_GPU_DB.txt doesn't exist!" 

	  try:
	    while 1:
	      line = fd.readline()
	      if not line:
		  break

	      powerEntry = GPUAppPower()
	      j = 0
	      for i in line.split():
		if j == 0:
		  powerEntry.setName(i)
		else:
		  powerEntry.addPower(i)
		j += 1
	      self.APC_GPU_DB.append(powerEntry)

	    fd.close()
	  except IOError:
	    print "APC_GPU_DB.txt can't be processed!"
	    fd.close()

	# get incread power from GPU execution
	def obtainIncreasedPower(self, gpuApp, input):
	  for i in self.APC_GPU_DB:
	    if i.getName() == gpuApp:
	      if int(input) < 0:
	        return None
	      if int(input) >= len(i.getIncreasedPower()):
		return None
	      else:
		return (i.getIncreasedPower())[int(input)]

	# performance state rebalance
	def rebalance(self, gpuIncreasedPower, Method, Degradation):
	  # Set VM instance
	  for i in self.VM_Identifier.getVMPool():
	    state = i.getState()
	    if i.getType() == "CPU_VM" or i.getType() == "CPU_MEM_VM" or i.getType() == "GPU_VM_S":
	      priority = 1
	    else:
	      priority = 0

	    for j in self.VM_Identifier.getVMStandard():
	      if i.getType() == j.getType():
		tmpI = Instance(i.getType(), i.getDomainID(), state, priority, j.getPerfD(), j.getPowerC())
	        self.coordinator.addInstance(tmpI)
		break
	  # State Rebalance Execution
	  self.coordinator.rebalance(gpuIncreasedPower, Method, Degradation) 

	  # Execute xenpm command 
	  for i in self.coordinator.getInstancePool():
	    for j in self.VM_Identifier.getVMPool():
	      if i.domID == j.id:
		for k in j.vcpu_list:
		  cmd = "xenpm set-scaling-speed " + str(k.getCPU()) + " " + str(self.statesPool[i.targetState])
	 	  print cmd
		  os.system(cmd)

	  # print instance pool list
	  #self.coordinator.printInstancePool()

	# Destructor	
	def __del__(self):
	  pass

	# Test function
	def test(self):
	  print "Hello World!"
	  for i in self.APC_GPU_DB:
	    i.printData()