GreenCloud Simulator
dchost.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
2 /*
3  */
4 
5 #include "dchost.h"
6 #include <lib/builtin.h>
7 
8 static class DcHostClass : public TclClass {
9 public:
10  DcHostClass() : TclClass("DcHost") {}
11  TclObject* create(int argc, const char*const*argv) {
12  return (new DcHost());
13  }
14 } class_dchost;
15 
16 DcHost::DcHost(): eConsumed_(0.0), eNominalrate_ (0.0), eCurrentConsumption_ (0.0), eDNS_enabled_(0.0) , eLastUpdateTime_(0.0)
17 {
18  bind("id_", &id_);
19  bind("ntasks_", &ntasks_);
20  bind("currentLoad_", &currentLoad_);
21  bind("currentLoadMem_", &currentLoadMem_);
22  bind("currentLoadStor_", &currentLoadStor_);
23  bind("tskFailed_", &tskFailed_);
24 
25  bind("eConsumed_", &eConsumed_); /* total W of energy consumed */
26  bind("eNominalrate_", &eNominalrate_);
27  bind("eCurrentConsumption_", &eCurrentConsumption_); /* current consumption rate */
28 
29  bind("eDVFS_enabled_", &eDVFS_enabled_); /* ON when DVFS is enabled */
30  bind("eDNS_enabled_", &eDNS_enabled_); /* ON when DNS is enabled */
31 
32 }
33 
35 {
36  delete powerModel;
37 }
38 
40  powerModel = pModel;
41 }
42 
43 
44 int DcHost::command(int argc, const char*const* argv)
45 {
46  Tcl& tcl = Tcl::instance();
47 
48  if (argc == 2) {
49  if (strcmp(argv[1], "start") == 0) {
50 
51  /* start counting energy consumed */
53  eLastUpdateTime_ = Scheduler::instance().clock();
54  started_ = true;
55  return (TCL_OK);
56  } else if (strcmp(argv[1], "stop") == 0) {
57  /* update total energy consumed */
59  return (TCL_OK);
60  } else if (strcmp(argv[1], "print") == 0) {
61  /* print general info */
62  print();
63  return (TCL_OK);
64  }
65  } else if (argc == 3) {
66  if (strcmp(argv[1], "set-power-model") == 0) {
67  PowerModel* pModel = (PowerModel*) TclObject::lookup(argv[2]);
68  if (pModel == NULL) {
69  tcl.resultf("no such power model %s", argv[2]);
70  return(TCL_ERROR);
71  }
72  setPowerModel(pModel);
73  return(TCL_OK);
74  }
75  }
76  return (ResourceProvider::command(argc, argv));
77 }
78 
80  std::cout << "DcHost:\t";
81  std::cout << id_;
82  std::cout << "\n";
83  std::cout << "Resources:\n";
84  std::vector <std::vector<DcResource*> >::iterator iter_out;
85  for(iter_out = resource_list.begin(); iter_out!=resource_list.end() ;iter_out++){
86  std::vector <DcResource*>::iterator iter;
87  for (iter = iter_out->begin(); iter!=iter_out->end(); iter++)
88  {
89  (*iter)->print();
90  }
91  }
92  std::cout << "\n";
93 
94 }
95 
97  std::vector<CloudTask *>::iterator iter;
98  std::cout <<"Host " <<this->id_ << "\n";
100 }
101 
103 {
104  double * predictors = new double[LastResType+1];
105  bool idle = true;
106  for(int i = Computing; i <= LastResType; i++){
107  predictors[i]=updateResTypeUtil(static_cast<res_type>(i));
108  if(predictors[i]!=0){
109  idle=false;
110  }
111  }
112  if((eDNS_enabled_) && (idle)){
114  } else {
115  eCurrentConsumption_ = powerModel->estimate(4,predictors);
116  }
117  delete[] predictors;
118 }
119 
121 {
122  /* Get time spent since last update */
123  double etime = (Scheduler::instance().clock() - eLastUpdateTime_)/3600; /* time in hours */
124 
125  eConsumed_ += etime * eCurrentConsumption_;
126  eLastUpdateTime_ = Scheduler::instance().clock();
127 
128 }
129 
132  if(res->specification->getPowerModel()!=NULL){
133  powerModel->addComponent(res);
134  }
135 }
136 
137 
140  eUpdate();
141 }
void setPowerModel(PowerModel *pModel)
Definition: dchost.cc:39
std::vector< std::vector< DcResource * > > resource_list
ResourceSpec * specification
Definition: dcresource.h:34
virtual ~DcHost()
Definition: dchost.cc:34
double updateResTypeUtil(res_type type)
virtual void print()
Definition: dchost.cc:79
virtual void addResource(DcResource *res)
virtual void addComponent(DcResource *component)=0
DcHostClass()
Definition: dchost.cc:10
TclObject * create(int argc, const char *const *argv)
Definition: dchost.cc:11
virtual void updateEnergyAndConsumption()
Definition: dchost.cc:138
virtual void printTasklist()
double eNominalrate_
Definition: dchost.h:40
void eUpdate()
Definition: dchost.cc:120
PowerModel * getPowerModel()
Definition: resourcespec.cc:53
virtual int command(int argc, const char *const *argv)
Definition: dchost.cc:44
double eLastUpdateTime_
Definition: dchost.h:57
virtual void addResource(DcResource *res)
Definition: dchost.cc:130
void setCurrentConsumption()
Definition: dchost.cc:102
Definition: dchost.h:27
DcHost()
Definition: dchost.cc:16
virtual void printTasklist()
Definition: dchost.cc:96
virtual double estimate(int size, double *predictors)=0
DcHostClass class_dchost
double eCurrentConsumption_
Definition: dchost.h:41
virtual int command(int argc, const char *const *argv)
double eConsumed_
Definition: dchost.h:39
PowerModel * powerModel
Definition: dchost.h:34
int eDNS_enabled_
Definition: dchost.h:44