blob: db336dd8602fd13893bca7e1e2a15c8e29fc728a (
plain)
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
|
#include "modeling/machine/Machine.h"
namespace Modeling
{
Machine::Machine(int id) : busy(false), currentWorkload(), id(id)
{}
void Machine::addCPU(CPU c)
{
cpus.push_back(c);
}
void Machine::addGPU(GPU g)
{
gpus.push_back(g);
}
void Machine::giveTask(Simulation::Workload* workload)
{
busy = true;
currentWorkload = workload;
}
bool Machine::isBusy() const
{
return this->busy;
}
uint32_t Machine::getSpeed()
{
int speed = 0;
for(auto cpu : cpus)
{
speed += cpu.getSpeed() * cpu.getCores();
}
return speed;
}
void Machine::work()
{
if(!currentWorkload)
return;
currentWorkload->doOperations(static_cast<int>(getSpeed() * load));
temperature += load * temperatureIncrease;
//load = temperature < 70.0f ? 1.0f : 1.0f / (temperature - 69.0f);
load = 1.0f;
temperature = temperature > maxTemperature ? maxTemperature
: temperature < minTemperature ? minTemperature
: temperature;
}
int Machine::getWorkloadId() const
{
if(currentWorkload)
return currentWorkload->getId();
return 0;
}
int Machine::getId() const
{
return this->id;
}
float Machine::getTemperature() const
{
return this->temperature;
}
int Machine::getMemory() const
{
return this->memory;
}
float Machine::getLoad() const
{
return this->load;
}
uint32_t Machine::getNumberOfCores() const
{
uint32_t cores = 0;
for (auto& processor : cpus) {
cores += processor.getCores();
}
return cores;
}
}
|