forked from anish-palakurthi/cloudsim_eec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduler.cpp
More file actions
165 lines (141 loc) · 6.13 KB
/
Scheduler.cpp
File metadata and controls
165 lines (141 loc) · 6.13 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Scheduler.cpp
// CloudSim
//
// Created by ELMOOTAZBELLAH ELNOZAHY on 10/20/24.
//
#include "Scheduler.hpp"
static bool migrating = false;
static unsigned active_machines = 16;
void Scheduler::Init() {
// Find the parameters of the clusters
// Get the total number of machines
// For each machine:
// Get the type of the machine
// Get the memory of the machine
// Get the number of CPUs
// Get if there is a GPU or not
//
SimOutput("Scheduler::Init(): Total number of machines is " + to_string(Machine_GetTotal()), 3);
SimOutput("Scheduler::Init(): Initializing scheduler", 1);
for(unsigned i = 0; i < active_machines; i++)
vms.push_back(VM_Create(LINUX, X86));
for(unsigned i = 0; i < active_machines; i++) {
machines.push_back(MachineId_t(i));
}
for(unsigned i = 0; i < active_machines; i++) {
VM_Attach(vms[i], machines[i]);
}
bool dynamic = false;
if(dynamic)
for(unsigned i = 0; i<4 ; i++)
for(unsigned j = 0; j < 8; j++)
Machine_SetCorePerformance(MachineId_t(0), j, P3);
// Turn off the ARM machines
for(unsigned i = 24; i < Machine_GetTotal(); i++)
Machine_SetState(MachineId_t(i), S5);
SimOutput("Scheduler::Init(): VM ids are " + to_string(vms[0]) + " ahd " + to_string(vms[1]), 3);
}
void Scheduler::MigrationComplete(Time_t time, VMId_t vm_id) {
// Update your data structure. The VM now can receive new tasks
}
void Scheduler::NewTask(Time_t now, TaskId_t task_id) {
// Get the task parameters
// IsGPUCapable(task_id);
// GetMemory(task_id);
// RequiredVMType(task_id);
// RequiredSLA(task_id);
// RequiredCPUType(task_id);
// Decide to attach the task to an existing VM,
// vm.AddTask(taskid, Priority_T priority); or
// Create a new VM, attach the VM to a machine
// VM vm(type of the VM)
// vm.Attach(machine_id);
// vm.AddTask(taskid, Priority_t priority) or
// Turn on a machine, create a new VM, attach it to the VM, then add the task
//
// Turn on a machine, migrate an existing VM from a loaded machine....
//
// Other possibilities as desired
Priority_t priority = (task_id == 0 || task_id == 64)? HIGH_PRIORITY : MID_PRIORITY;
if(migrating) {
VM_AddTask(vms[0], task_id, priority);
}
else {
VM_AddTask(vms[task_id % active_machines], task_id, priority);
}// Skeleton code, you need to change it according to your algorithm
}
void Scheduler::PeriodicCheck(Time_t now) {
// This method should be called from SchedulerCheck()
// SchedulerCheck is called periodically by the simulator to allow you to monitor, make decisions, adjustments, etc.
// Unlike the other invocations of the scheduler, this one doesn't report any specific event
// Recommendation: Take advantage of this function to do some monitoring and adjustments as necessary
}
void Scheduler::Shutdown(Time_t time) {
// Do your final reporting and bookkeeping here.
// Report about the total energy consumed
// Report about the SLA compliance
// Shutdown everything to be tidy :-)
for(auto & vm: vms) {
VM_Shutdown(vm);
}
SimOutput("SimulationComplete(): Finished!", 4);
SimOutput("SimulationComplete(): Time is " + to_string(time), 4);
}
void Scheduler::TaskComplete(Time_t now, TaskId_t task_id) {
// Do any bookkeeping necessary for the data structures
// Decide if a machine is to be turned off, slowed down, or VMs to be migrated according to your policy
// This is an opportunity to make any adjustments to optimize performance/energy
SimOutput("Scheduler::TaskComplete(): Task " + to_string(task_id) + " is complete at " + to_string(now), 4);
}
// Public interface below
static Scheduler Scheduler;
void InitScheduler() {
SimOutput("InitScheduler(): Initializing scheduler", 4);
Scheduler.Init();
}
void HandleNewTask(Time_t time, TaskId_t task_id) {
SimOutput("HandleNewTask(): Received new task " + to_string(task_id) + " at time " + to_string(time), 4);
Scheduler.NewTask(time, task_id);
}
void HandleTaskCompletion(Time_t time, TaskId_t task_id) {
SimOutput("HandleTaskCompletion(): Task " + to_string(task_id) + " completed at time " + to_string(time), 4);
Scheduler.TaskComplete(time, task_id);
}
void MemoryWarning(Time_t time, MachineId_t machine_id) {
// The simulator is alerting you that machine identified by machine_id is overcommitted
SimOutput("MemoryWarning(): Overflow at " + to_string(machine_id) + " was detected at time " + to_string(time), 0);
}
void MigrationDone(Time_t time, VMId_t vm_id) {
// The function is called on to alert you that migration is complete
SimOutput("MigrationDone(): Migration of VM " + to_string(vm_id) + " was completed at time " + to_string(time), 4);
Scheduler.MigrationComplete(time, vm_id);
migrating = false;
}
void SchedulerCheck(Time_t time) {
// This function is called periodically by the simulator, no specific event
SimOutput("SchedulerCheck(): SchedulerCheck() called at " + to_string(time), 4);
Scheduler.PeriodicCheck(time);
static unsigned counts = 0;
counts++;
if(counts == 10) {
migrating = true;
VM_Migrate(1, 9);
}
}
void SimulationComplete(Time_t time) {
// This function is called before the simulation terminates Add whatever you feel like.
cout << "SLA violation report" << endl;
cout << "SLA0: " << GetSLAReport(SLA0) << "%" << endl;
cout << "SLA1: " << GetSLAReport(SLA1) << "%" << endl;
cout << "SLA2: " << GetSLAReport(SLA2) << "%" << endl; // SLA3 do not have SLA violation issues
cout << "Total Energy " << Machine_GetClusterEnergy() << "KW-Hour" << endl;
cout << "Simulation run finished in " << double(time)/1000000 << " seconds" << endl;
SimOutput("SimulationComplete(): Simulation finished at time " + to_string(time), 4);
Scheduler.Shutdown(time);
}
void SLAWarning(Time_t time, TaskId_t task_id) {
}
void StateChangeComplete(Time_t time, MachineId_t machine_id) {
// Called in response to an earlier request to change the state of a machine
}