Commit f083f79d authored by Millian Poquet's avatar Millian Poquet

Implementation of the energy mechanism.

If the energy is enabled (by setting the -p run option), the platform is assumed to contain energy information.
Such information is read by SimGrid itself but another ones, such as the 'sleep_pstates' property, are read by Batsim.
A lot of assertions has been put in the reading of the platform file which will help generating energy platforms.
An example of such a platform can be found in platforms/energy_platform.xml. This platform follows the same rules
that those of SimGrid energy platforms but assures pstate coherency via the 'sleep_pstates' property: it says
which pstates are sleep pstates and which pstates are its associated virtual pstates (for switching ON and OFF
each pstate). More information can be found in the file 'platforms/energy_platform.xml'

The scheduler can now send messages of the form TIMESTAMP:P:M=S where M is a machineID and S the asked new pstate
for machineID. Batsim does the stuff to simulate the time & energy consumptions of the switchON/OFF (if any, you
can also switch from one computation state to another). Once the pstate of a machine has changed, Batsim sends
it on the socket with messages of the form TIMESTAMP:p:M=S where M is a machineID and S the new pstate of the
corresponding machine (note the lowercase 'p' instead of an uppercase 'P').

To simulate the energy & time costs of the switch ON/OFF, the exact same mechanism as the one presented in
SimGrid energy 1O1 is used: computing 1 flop on virtual pstates whose computational power and power
consumption met our time and energy consumptions needs.
parent feb4031e
...@@ -24,7 +24,7 @@ include_directories(${RAPIDJSON_INCLUDE_DIRS}) ...@@ -24,7 +24,7 @@ include_directories(${RAPIDJSON_INCLUDE_DIRS})
# Executables # Executables
add_executable(batsim batsim.cpp export.cpp ipp.cpp job_submitter.cpp jobs.cpp jobs_execution.cpp machines.cpp network.cpp profiles.cpp workload.cpp) add_executable(batsim batsim.cpp export.cpp ipp.cpp job_submitter.cpp jobs.cpp jobs_execution.cpp machines.cpp network.cpp profiles.cpp pstate.cpp workload.cpp context.hpp export.hpp ipp.hpp job_submitter.hpp jobs.hpp jobs_execution.hpp machines.hpp network.hpp profiles.hpp pstate.hpp workload.hpp)
#add_executable(batexec batexec.c job.c utils.c export.c) #add_executable(batexec batexec.c job.c utils.c export.c)
# Libraries to link # Libraries to link
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <unistd.h> #include <unistd.h>
#include <simgrid/msg.h> #include <simgrid/msg.h>
#include <simgrid/plugins.h>
#include "context.hpp" #include "context.hpp"
#include "export.hpp" #include "export.hpp"
...@@ -34,6 +35,8 @@ struct MainArguments ...@@ -34,6 +35,8 @@ struct MainArguments
std::string masterHostName; //! The name of the SimGrid host which runs scheduler processes and not user tasks std::string masterHostName; //! The name of the SimGrid host which runs scheduler processes and not user tasks
std::string exportPrefix; //! The filename prefix used to export simulation information std::string exportPrefix; //! The filename prefix used to export simulation information
bool energy_used; //! True if and only if the SimGrid energy plugin should be used.
bool abort; //! A boolean value. If set to yet, the launching should be aborted for reason abortReason bool abort; //! A boolean value. If set to yet, the launching should be aborted for reason abortReason
std::string abortReason; //! Human readable reasons which explains why the launch should be aborted std::string abortReason; //! Human readable reasons which explains why the launch should be aborted
}; };
...@@ -57,6 +60,9 @@ static int parse_opt (int key, char *arg, struct argp_state *state) ...@@ -57,6 +60,9 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
case 'm': case 'm':
mainArgs->masterHostName = arg; mainArgs->masterHostName = arg;
break; break;
case 'p':
mainArgs->energy_used = true;
break;
case 's': case 's':
mainArgs->socketFilename = arg; mainArgs->socketFilename = arg;
break; break;
...@@ -100,10 +106,12 @@ static int parse_opt (int key, char *arg, struct argp_state *state) ...@@ -100,10 +106,12 @@ static int parse_opt (int key, char *arg, struct argp_state *state)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
// TODO : boolean option to enable the energy plugin
MainArguments mainArgs; MainArguments mainArgs;
mainArgs.socketFilename = "/tmp/bat_socket"; mainArgs.socketFilename = "/tmp/bat_socket";
mainArgs.masterHostName = "master_host"; mainArgs.masterHostName = "master_host";
mainArgs.exportPrefix = "out"; mainArgs.exportPrefix = "out";
mainArgs.energy_used = false;
mainArgs.abort = false; mainArgs.abort = false;
struct argp_option options[] = struct argp_option options[] =
...@@ -111,6 +119,7 @@ int main(int argc, char * argv[]) ...@@ -111,6 +119,7 @@ int main(int argc, char * argv[])
{"socket", 's', "FILENAME", 0, "Unix Domain Socket filename", 0}, {"socket", 's', "FILENAME", 0, "Unix Domain Socket filename", 0},
{"master-host", 'm', "NAME", 0, "The name of the host in PLATFORM_FILE which will run SimGrid scheduling processes and won't be used to compute tasks", 0}, {"master-host", 'm', "NAME", 0, "The name of the host in PLATFORM_FILE which will run SimGrid scheduling processes and won't be used to compute tasks", 0},
{"export", 'e', "FILENAME_PREFIX", 0, "The export filename prefix used to generate simulation output", 0}, {"export", 'e', "FILENAME_PREFIX", 0, "The export filename prefix used to generate simulation output", 0},
{"energy-plugin", 'p', 0, 0, "Enables energy-aware experiments", 0},
{0, '\0', 0, 0, 0, 0} // The options array must be NULL-terminated {0, '\0', 0, 0, 0, 0} // The options array must be NULL-terminated
}; };
struct argp argp = {options, parse_opt, "PLATFORM_FILE WORKLOAD_FILE", "A tool to simulate (via SimGrid) the behaviour of scheduling algorithms.", 0, 0, 0}; struct argp argp = {options, parse_opt, "PLATFORM_FILE WORKLOAD_FILE", "A tool to simulate (via SimGrid) the behaviour of scheduling algorithms.", 0, 0, 0};
...@@ -122,10 +131,16 @@ int main(int argc, char * argv[]) ...@@ -122,10 +131,16 @@ int main(int argc, char * argv[])
return 1; return 1;
} }
if (mainArgs.energy_used)
sg_energy_plugin_init();
// Initialization // Initialization
MSG_init(&argc, argv); MSG_init(&argc, argv);
BatsimContext context; BatsimContext context;
context.platform_filename = mainArgs.platformFilename;
context.workload_filename = mainArgs.workloadFilename;
context.energy_used = mainArgs.energy_used;
load_json_workload(&context, mainArgs.workloadFilename); load_json_workload(&context, mainArgs.workloadFilename);
context.jobs.setProfiles(&context.profiles); context.jobs.setProfiles(&context.profiles);
...@@ -146,7 +161,7 @@ int main(int argc, char * argv[]) ...@@ -146,7 +161,7 @@ int main(int argc, char * argv[])
MSG_create_environment(mainArgs.platformFilename.c_str()); MSG_create_environment(mainArgs.platformFilename.c_str());
xbt_dynar_t hosts = MSG_hosts_as_dynar(); xbt_dynar_t hosts = MSG_hosts_as_dynar();
context.machines.createMachines(hosts, mainArgs.masterHostName); context.machines.createMachines(hosts, &context, mainArgs.masterHostName);
xbt_dynar_free(&hosts); xbt_dynar_free(&hosts);
const Machine * masterMachine = context.machines.masterMachine(); const Machine * masterMachine = context.machines.masterMachine();
context.machines.setTracer(&context.tracer); context.machines.setTracer(&context.tracer);
......
...@@ -18,5 +18,8 @@ struct BatsimContext ...@@ -18,5 +18,8 @@ struct BatsimContext
Profiles profiles; Profiles profiles;
PajeTracer tracer; PajeTracer tracer;
long long microseconds_used_by_scheduler; long long microseconds_used_by_scheduler = 0;
bool energy_used = false;
std::string platform_filename;
std::string workload_filename;
}; };
...@@ -7,6 +7,8 @@ SEP2 = ':' ...@@ -7,6 +7,8 @@ SEP2 = ':'
'N' : NOP 'N' : NOP
'S' : Job Submission 'S' : Job Submission
'C' : Job Completion 'C' : Job Completion
'P' : Ask for a machine pstate change
'p' : Machine pstate changed
SCHEDULER -> SIMULATOR SCHEDULER -> SIMULATOR
0:15.000015|15.000015:J:1=1,2,0,3;2=3 0:15.000015|15.000015:J:1=1,2,0,3;2=3
...@@ -27,4 +29,14 @@ SEP2 = ':' ...@@ -27,4 +29,14 @@ SEP2 = ':'
0:30.000030|30.000030:S:3 0:30.000030|30.000030:S:3
0:35.001305|30.005125:C:2 0:35.001305|30.005125:C:2
0:40.001320|38.002565:C:3|40.000030:S:4 0:40.001320|38.002565:C:3|40.000030:S:4
0:145.003855|145.003855:C:4 0:145.003855|145.003855:C:4
\ No newline at end of file
Machine pstate change example.
Sched asks that machine 2 switches to pstate 3
Scheduler -> Simulator
0:20|20:P:2=3
Simulator -> Scheduler
0:21|21:p:2=3
...@@ -42,3 +42,54 @@ void send_message(const char *destination_mailbox, IPMessageType type, void *dat ...@@ -42,3 +42,54 @@ void send_message(const char *destination_mailbox, IPMessageType type, void *dat
const string str = destination_mailbox; const string str = destination_mailbox;
send_message(str, type, data); send_message(str, type, data);
} }
IPMessage::~IPMessage()
{
switch (type)
{
case IPMessageType::JOB_SUBMITTED:
{
JobSubmittedMessage * msg = (JobSubmittedMessage *) data;
delete msg;
} break;
case IPMessageType::JOB_COMPLETED:
{
JobCompletedMessage * msg = (JobCompletedMessage *) data;
delete msg;
} break;
case IPMessageType::PSTATE_MODIFICATION:
{
PStateModificationMessage * msg = (PStateModificationMessage *) data;
delete msg;
} break;
case IPMessageType::SCHED_ALLOCATION:
{
SchedulingAllocationMessage * msg = (SchedulingAllocationMessage *) data;
delete msg;
} break;
case IPMessageType::SCHED_NOP:
{
} break;
case IPMessageType::SCHED_READY:
{
} break;
case IPMessageType::SUBMITTER_HELLO:
{
} break;
case IPMessageType::SUBMITTER_BYE:
{
} break;
case IPMessageType::SWITCHED_ON:
{
PStateModificationMessage * msg = (PStateModificationMessage *) data;
delete msg;
} break;
case IPMessageType::SWITCHED_OFF:
{
PStateModificationMessage * msg = (PStateModificationMessage *) data;
delete msg;
} break;
}
data = nullptr;
}
...@@ -15,11 +15,14 @@ enum class IPMessageType ...@@ -15,11 +15,14 @@ enum class IPMessageType
{ {
JOB_SUBMITTED //!< Submitter -> Server. The submitter tells the server a new job has been submitted. JOB_SUBMITTED //!< Submitter -> Server. The submitter tells the server a new job has been submitted.
,JOB_COMPLETED //!< Launcher/killer -> Server. The launcher tells the server a job has been completed. ,JOB_COMPLETED //!< Launcher/killer -> Server. The launcher tells the server a job has been completed.
,PSTATE_MODIFICATION//!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a pstate modification).
,SCHED_ALLOCATION //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a job allocation). ,SCHED_ALLOCATION //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a job allocation).
,SCHED_NOP //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a NOP message). ,SCHED_NOP //!< SchedulerHandler -> Server. The scheduler handler tells the server a scheduling event occured (a NOP message).
,SCHED_READY //!< SchedulerHandler -> Server. The scheduler handler tells the server that the scheduler is ready (messages can be sent to it). ,SCHED_READY //!< SchedulerHandler -> Server. The scheduler handler tells the server that the scheduler is ready (messages can be sent to it).
,SUBMITTER_HELLO //!< Submitter -> Server. The submitter tells it starts submitting to the server. ,SUBMITTER_HELLO //!< Submitter -> Server. The submitter tells it starts submitting to the server.
,SUBMITTER_BYE //!< Submitter -> Server. The submitter tells it stops submitting to the server. ,SUBMITTER_BYE //!< Submitter -> Server. The submitter tells it stops submitting to the server.
,SWITCHED_ON //!< SwitcherON -> Server. The switcherON process tells the server the machine pstate has been changed
,SWITCHED_OFF //!< SwitcherOFF -> Server. The switcherOFF process tells the server the machine pstate has been changed.
}; };
struct JobSubmittedMessage struct JobSubmittedMessage
...@@ -44,8 +47,15 @@ struct SchedulingAllocationMessage ...@@ -44,8 +47,15 @@ struct SchedulingAllocationMessage
std::vector<SchedulingAllocation> allocations; //! Possibly several allocations std::vector<SchedulingAllocation> allocations; //! Possibly several allocations
}; };
struct PStateModificationMessage
{
int machine;
int new_pstate;
};
struct IPMessage struct IPMessage
{ {
~IPMessage();
IPMessageType type; //! The message type IPMessageType type; //! The message type
void * data; //! The message data (can be NULL if type is in [SCHED_NOP, SUBMITTER_HELLO, SUBMITTER_BYE, SUBMITTER_READY]). Otherwise, it is either a JobSubmittedMessage*, a JobCompletedMessage* or a SchedulingAllocationMessage* according to type. void * data; //! The message data (can be NULL if type is in [SCHED_NOP, SUBMITTER_HELLO, SUBMITTER_BYE, SUBMITTER_READY]). Otherwise, it is either a JobSubmittedMessage*, a JobCompletedMessage* or a SchedulingAllocationMessage* according to type.
}; };
...@@ -71,7 +81,13 @@ struct KillerProcessArguments ...@@ -71,7 +81,13 @@ struct KillerProcessArguments
{ {
msg_task_t task; //! The task that will be cancelled if the walltime is reached msg_task_t task; //! The task that will be cancelled if the walltime is reached
double walltime; //! The number of seconds to wait before cancelling the task double walltime; //! The number of seconds to wait before cancelling the task
} ; };
struct SwitchPStateProcessArguments
{
BatsimContext * context;
PStateModificationMessage * message;
};
struct JobSubmitterProcessArguments struct JobSubmitterProcessArguments
{ {
......
This diff is collapsed.
...@@ -3,26 +3,40 @@ ...@@ -3,26 +3,40 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <set> #include <set>
#include <map>
#include <string> #include <string>
#include <simgrid/msg.h> #include <simgrid/msg.h>
#include "pstate.hpp"
class PajeTracer; class PajeTracer;
struct BatsimContext;
enum class MachineState enum class MachineState
{ {
SLEEPING, SLEEPING,
IDLE, IDLE,
COMPUTING, COMPUTING,
TRANSITING_FROM_SLEEPING_TO_COMPUTING,
TRANSITING_FROM_COMPUTING_TO_SLEEPING,
}; };
struct Machine struct Machine
{ {
~Machine();
int id; int id;
std::string name; std::string name;
msg_host_t host; msg_host_t host;
MachineState state; MachineState state;
std::set<int> jobs_being_computed; std::set<int> jobs_being_computed;
std::map<int, PStateType> pstates;
std::map<int, SleepPState *> sleep_pstates;
bool has_pstate(int pstate) const;
void display_machine(bool is_energy_used) const;
}; };
std::ostream & operator<<(std::ostream & out, const Machine & machine); std::ostream & operator<<(std::ostream & out, const Machine & machine);
...@@ -32,7 +46,7 @@ class Machines ...@@ -32,7 +46,7 @@ class Machines
public: public:
Machines(); Machines();
~Machines(); ~Machines();
void createMachines(xbt_dynar_t hosts, const std::string & masterHostName); void createMachines(xbt_dynar_t hosts, BatsimContext * context, const std::string & masterHostName);
void updateMachinesOnJobRun(int jobID, const std::vector<int> & usedMachines); void updateMachinesOnJobRun(int jobID, const std::vector<int> & usedMachines);
void updateMachinesOnJobEnd(int jobID, const std::vector<int> & usedMachines); void updateMachinesOnJobEnd(int jobID, const std::vector<int> & usedMachines);
......
This diff is collapsed.
...@@ -9,7 +9,8 @@ enum NetworkStamp : char ...@@ -9,7 +9,8 @@ enum NetworkStamp : char
JOB_REJECTION = 'R', JOB_REJECTION = 'R',
NOP = 'N', NOP = 'N',
STATIC_JOB_SUBMISSION = 'S', STATIC_JOB_SUBMISSION = 'S',
STATIC_JOB_COMPLETION = 'C' STATIC_JOB_COMPLETION = 'C',
PSTATE_SET = 'P'
}; };
class UnixDomainSocket class UnixDomainSocket
......
<?xml version='1.0'?>
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
<platform version="3">
<AS id="AS0" routing="Full">
<host id="master_host" power="100Mf">
<prop id="watt_per_state" value="100:200" />
<prop id="watt_off" value="10" />
</host>
<!-- The state 3 of Mercury is a sleep state.
When switching from a computing state to the state 3, passing by the virtual pstate 4 is mandatory to simulate the time and energy consumed by the switch off.
When switching from the state 3 to a computing state, passing by the virtual pstate 5 is mandatory to simulate the time and energy consumed by the switch on.
-->
<host id="Mercury" power="100.0Mf, 50.0Mf, 20.0Mf, 0.0Mf, 0.006666667f, 0.1429f" pstate="0" >
<prop id="watt_per_state" value="100.0:200.0, 93.0:170.0, 90.0:150.0, 10:10, 120:120, 110:110" />
<prop id="watt_off" value="10" />
<!-- The following property allows to bind a sleep state to its switch ON/off virtual pstates -->
<prop id="sleep_pstates" value="3:4:5" />
</host>
<!-- Venus has two sleep states : 3 and 6. They share their virtual pstates. -->
<host id="Venus" power="100.0Mf, 50.0Mf, 20.0Mf, 0.0Mf, 0.006666667f, 0.1429f, 0.0Mf" pstate="0" >
<prop id="watt_per_state" value="100.0:200.0, 93.0:170.0, 90.0:150.0, 10:10, 120:120, 110:110" />
<prop id="watt_off" value="10" />
<!-- The following property allows to bind a sleep state to its switch ON/off virtual pstates -->
<prop id="sleep_pstates" value="3:4:5, 6:4:5" />
</host>
<!-- Earth has two sleep states : 3 and 6. They don't have the same virtual pstates. -->
<host id="Earth" power="100.0Mf, 50.0Mf, 20.0Mf, 0.0Mf, 0.006666667f, 0.1429f, 0.0Mf, 0.006666667f, 0.1429f" pstate="0" >
<prop id="watt_per_state" value="100.0:200.0, 93.0:170.0, 90.0:150.0, 10:10, 120:120, 110:110" />
<prop id="watt_off" value="10" />
<prop id="sleep_pstates" value="3:4:5, 6:7:8" />
</host>
<!-- Mars has no sleep_pstate. In this case, an empty-value sleep_pstates property is valid. Not setting the sleep_pstates property at all is also valid. -->
<host id="Mars" power="100.0Mf, 50.0Mf, 20.0Mf, 0.0Mf, 0.006666667f, 0.1429f" pstate="0" >
<prop id="watt_per_state" value="100.0:200.0, 93.0:170.0, 90.0:150.0, 10:10, 120:120, 110:110" />
<prop id="watt_off" value="10" />
</host>
<link id="6" bandwidth="41.279125MBps" latency="59.904us"/>
<link id="3" bandwidth="34.285625MBps" latency="514.433us"/>
<link id="7" bandwidth="11.618875MBps" latency="189.98us"/>
<link id="9" bandwidth="7.20975MBps" latency="1.461517ms"/>
<link id="2" bandwidth="118.6825MBps" latency="136.931us"/>
<link id="8" bandwidth="8.158MBps" latency="270.544us"/>
<link id="1" bandwidth="34.285625MBps" latency="514.433us"/>
<link id="4" bandwidth="10.099625MBps" latency="479.78us"/>
<link id="0" bandwidth="41.279125MBps" latency="59.904us"/>
<link id="5" bandwidth="27.94625MBps" latency="278.066us"/>
<link id="loopback" bandwidth="498MBps" latency="15us" sharing_policy="FATPIPE"/>
<route src="master_host" dst="master_host"><link_ctn id="loopback"/></route>
<route src="Mercury" dst="Mercury"><link_ctn id="loopback"/></route>
<route src="Venus" dst="Venus"><link_ctn id="loopback"/></route>
<route src="Earth" dst="Earth"><link_ctn id="loopback"/></route>
<route src="Mars" dst="Mars"><link_ctn id="loopback"/></route>
<route src="master_host" dst="Mercury">
<link_ctn id="9"/>
</route>
<route src="master_host" dst="Venus">
<link_ctn id="4"/><link_ctn id="3"/><link_ctn id="2"/><link_ctn id="0"/><link_ctn id="1"/><link_ctn id="8"/>
</route>
<route src="master_host" dst="Earth">
<link_ctn id="4"/><link_ctn id="3"/><link_ctn id="5"/>
</route>
<route src="master_host" dst="Mars">
<link_ctn id="4"/><link_ctn id="3"/><link_ctn id="2"/><link_ctn id="0"/><link_ctn id="1"/><link_ctn id="6"/><link_ctn id="7"/>
</route>
<route src="Mercury" dst="Venus">
<link_ctn id="9"/><link_ctn id="4"/><link_ctn id="3"/><link_ctn id="2"/><link_ctn id="0"/><link_ctn id="1"/><link_ctn id="8"/>
</route>
<route src="Mercury" dst="Earth">
<link_ctn id="9"/><link_ctn id="4"/><link_ctn id="3"/><link_ctn id="5"/>
</route>
<route src="Mercury" dst="Mars">
<link_ctn id="9"/><link_ctn id="4"/><link_ctn id="3"/><link_ctn id="2"/><link_ctn id="0"/><link_ctn id="1"/><link_ctn id="6"/><link_ctn id="7"/>
</route>
<route src="Venus" dst="Earth">
<link_ctn id="8"/><link_ctn id="1"/><link_ctn id="0"/><link_ctn id="2"/><link_ctn id="5"/>
</route>
<route src="Venus" dst="Mars">
<link_ctn id="8"/><link_ctn id="6"/><link_ctn id="7"/>
</route>
<route src="Earth" dst="Mars">
<link_ctn id="5"/><link_ctn id="2"/><link_ctn id="0"/><link_ctn id="1"/><link_ctn id="6"/><link_ctn id="7"/>
</route>
</AS>
</platform>
#include "pstate.hpp"
#include <simgrid/msg.h>
#include "ipp.hpp"
#include "context.hpp"
XBT_LOG_NEW_DEFAULT_CATEGORY(pstate, "pstate");
int switch_on_machine_process(int argc, char *argv[])
{
(void) argc;
(void) argv;
SwitchPStateProcessArguments * args = (SwitchPStateProcessArguments *) MSG_process_get_data(MSG_process_self());
int machineID = args->message->machine;
int pstate = args->message->new_pstate;
xbt_assert(args->context->machines.exists(machineID));
Machine * machine = args->context->machines[machineID];
xbt_assert(machine->host->id() == MSG_process_get_host(MSG_process_self())->id());
xbt_assert(machine->state == MachineState::TRANSITING_FROM_SLEEPING_TO_COMPUTING);
xbt_assert(machine->jobs_being_computed.empty());
xbt_assert(machine->has_pstate(pstate));
xbt_assert(machine->pstates[pstate] == PStateType::COMPUTATION_PSTATE);
int on_ps = machine->sleep_pstates[pstate]->switch_on_virtual_pstate;
XBT_INFO("Switching machine %d ('%s') ON. Passing in virtual pstate %d to do so", machine->id,
machine->name.c_str(), on_ps);
MSG_host_set_pstate(machine->host, on_ps);
msg_host_t host_list[1] = {machine->host};
double flop_amount[1] = {1};
double bytes_amount[1] = {0};
msg_task_t bootup = MSG_parallel_task_create("switch ON", 1, host_list, flop_amount, bytes_amount, NULL);
XBT_INFO("Computing 1 flop to simulate time & energy cost of switch ON");
MSG_task_execute(bootup);
MSG_task_destroy(bootup);
XBT_INFO("1 flop has been computed. Switching machine %d ('%s') to computing pstate %d",
machine->id, machine->name.c_str(), pstate);
MSG_host_set_pstate(machine->host, pstate);
send_message("server", IPMessageType::SWITCHED_ON, (void *) args->message);
delete args;
return 0;
}
int switch_off_machine_process(int argc, char *argv[])
{
(void) argc;
(void) argv;
SwitchPStateProcessArguments * args = (SwitchPStateProcessArguments *) MSG_process_get_data(MSG_process_self());
int machineID = args->message->machine;
int pstate = args->message->new_pstate;
xbt_assert(args->context->machines.exists(machineID));
Machine * machine = args->context->machines[machineID];
xbt_assert(machine->host->id() == MSG_process_get_host(MSG_process_self())->id());
xbt_assert(machine->state == MachineState::TRANSITING_FROM_COMPUTING_TO_SLEEPING);
xbt_assert(machine->jobs_being_computed.empty());
xbt_assert(machine->has_pstate(pstate));
xbt_assert(machine->pstates[pstate] == PStateType::SLEEP_PSTATE);
int off_ps = machine->sleep_pstates[pstate]->switch_off_virtual_pstate;
XBT_INFO("Switching machine %d ('%s') OFF. Passing in virtual pstate %d to do so", machine->id,
machine->name.c_str(), off_ps);
MSG_host_set_pstate(machine->host, off_ps);
msg_host_t host_list[1] = {machine->host};
double flop_amount[1] = {1};
double bytes_amount[1] = {0};
msg_task_t shutdown = MSG_parallel_task_create("switch OFF", 1, host_list, flop_amount, bytes_amount, NULL);
XBT_INFO("Computing 1 flop to simulate time & energy cost of switch OFF");
MSG_task_execute(shutdown);
MSG_task_destroy(shutdown);
XBT_INFO("1 flop has been computed. Switching machine %d ('%s') to sleeping pstate %d",
machine->id, machine->name.c_str(), pstate);
MSG_host_set_pstate(machine->host, pstate);
send_message("server", IPMessageType::SWITCHED_OFF, (void *) args->message);
delete args;
return 0;
}
#pragma once
struct Machine;
enum class PStateType
{
COMPUTATION_PSTATE,
SLEEP_PSTATE,
TRANSITION_VIRTUAL_PSTATE
};
struct SleepPState
{
int sleep_pstate;
int switch_on_virtual_pstate;
int switch_off_virtual_pstate;
};
int switch_on_machine_process(int argc, char * argv[]);
int switch_off_machine_process(int argc, char * argv[]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment