You can extend SimGrid without modifying it, thanks to our plugin mechanism. This page describes how to write your own plugin, and documents some of the plugins distributed with SimGrid:
You can activate these plugins with the –cfg=plugin command
line option, for example with
--cfg=plugin:host_energy. You can get the full
list of existing plugins with
Defining a Plugin¶
A plugin can get some additional code executed within the SimGrid kernel, and attach the data needed by that code to the SimGrid objects.
The host load plugin in
constitutes a good introductory example. It defines a class
`HostLoad` that is meant to be attached to each host. This class
`EXTENSION_ID` field that is mandatory to our extension
mechanism. Then, the function
initializes the plugin. It first calls
simgrid::s4u::Host::extension_create() to register its
extension to the
`s4u::Host` objects, and then attaches some
callbacks to signals.
Partial list of existing signals in s4u:
Only the major plugins are described here. Please check in src/plugins to explore the other ones.
Host Energy Plugin¶
This is the energy plugin, enabling to account not only for computation time, but also for the dissipated energy in the simulated platform. To activate this plugin, first call
MSG_init(), and then use
MSG_host_get_consumed_energy()to retrieve the consumption of a given host.
When the host is on, this energy consumption naturally depends on both the current CPU load and the host energy profile. According to our measurements, the consumption is somehow linear in the amount of cores at full speed, with an abnormality when all the cores are idle. The full details are in our scientific paper on that topic.
As a result, our energy model takes 4 parameters:
Idlewattage (i.e., instantaneous consumption in Watt) when your host is up and running, but without anything to do.
Epsilonwattage when all cores are at 0 or epsilon%, but not in Idle state.
AllCoreswattage when all cores of the host are at 100%.
Offwattage when the host is turned off.
Here is an example of XML declaration:
<host id="HostA" speed="100.0Mf" core="4"> <prop id="wattage_per_state" value="100.0:120.0:200.0" /> <prop id="wattage_off" value="10" /> </host>
If only two values are given,
Idleis used for the missing
This example gives the following parameters:
Offis 10 Watts;
Idleis 100 Watts;
Epsilonis 120 Watts and
AllCoresis 200 Watts. This is enough to compute the wattage as a function of the amount of loaded cores:
#Cores loaded Wattage Explanation 0 (idle) 100 Watts Idle value 0 (not idle) 120 Watts Epsilon value 1 140 Watts Linear extrapolation between Epsilon and AllCores 2 160 Watts Linear extrapolation between Epsilon and AllCores 3 180 Watts Linear extrapolation between Epsilon and AllCores 4 200 Watts AllCores value
How does DVFS interact with the host energy model?
If your host has several DVFS levels (several pstates), then you should give the energetic profile of each pstate level:
<host id="HostC" speed="100.0Mf,50.0Mf,20.0Mf" core="4"> <prop id="wattage_per_state" value="95.0:120.0:200.0, 93.0:115.0:170.0, 90.0:110.0:150.0" /> <prop id="wattage_off" value="10" /> </host>
This encodes the following values:
pstate Performance Idle Epsilon AllCores 0 100 Mflop/s 95 Watts 120 Watts 200 Watts 1 50 Mflop/s 93 Watts 115 Watts 170 Watts 2 20 Mflop/s 90 Watts 110 Watts 150 Watts
How accurate are these models?
This model cannot be more accurate than your instantiation: with the default values, your result will not be accurate at all. You can still get accurate energy prediction, provided that you carefully instantiate the model. The first step is to ensure that your timing prediction match perfectly. But this is only the first step of the path, and you really want to read this paper to see all what you need to do before you can get accurate energy predictions.
Enable host energy plugin.
Enable energy plugin to get joules consumption of each cpu. Call this function before #MSG_init().
updates the consumption of all hosts
After this call, sg_host_get_consumed_energy() will not interrupt your process (until after the next clock update).
Returns the total energy consumed by the host so far (in Joules)
Please note that since the consumption is lazily updated, it may require a simcall to update it. The result is that the actor requesting this value will be interrupted, the value will be updated in kernel mode before returning the control to the requesting actor.
Get the amount of watt dissipated when the host is idling.
sg_host_get_idle_consumption_at(sg_host_t host, int pstate)¶
Get the amount of watt dissipated at the given pstate when the host is idling.
sg_host_get_wattmin_at(sg_host_t host, int pstate)¶
Get the amount of watt dissipated at the given pstate when the host is at 0 or epsilon% CPU usage.
sg_host_get_wattmax_at(sg_host_t host, int pstate)¶
Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100%.
sg_host_get_power_range_slope_at(sg_host_t host, int pstate)¶
Returns the power slope at the given pstate.
Returns the current consumption of the host.
Host Load Plugin¶
Simple plugin that monitors the current load for each host.
In addition, this constitutes a good introductory example on how to write a plugin. It attaches an extension to each host to store some data, and places callbacks in the following signals:
simgrid::s4u::Host::on_creation: Attach a new extension to the newly created host.
simgrid::s4u::Exec::on_start: Make note that a new execution started, increasing the load.
simgrid::s4u::Exec::on_completion: Make note that an execution completed, decreasing the load.
simgrid::s4u::Host::on_state_change: Do what is appropriate when the host gets suspended, turned off or similar.
simgrid::s4u::Host::on_speed_change: Do what is appropriate when the DVFS is modified.
Note that extensions are automatically destroyed when the host gets destroyed.
Initializes the HostLoad plugin.
Returns the current load of that host, as a ratio = achieved_flops / (core_current_speed * core_amount)
Returns the current load of that host.
Returns the time this host was idle since the last reset.
Returns the time this host was idle since the beginning of the simulation.
Returns the amount of flops computed by that host since the last reset.
Resets the idle time and flops amount of that host.