Skip to content

Commit

Permalink
[POWER] Several fixed for power models
Browse files Browse the repository at this point in the history
  • Loading branch information
haugoug committed Feb 4, 2022
1 parent 7ff029b commit 886a56f
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 114 deletions.
75 changes: 67 additions & 8 deletions engine/include/gv/power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,41 @@ namespace vp
*/
void setup(double temp, double volt, double freq);

/**
* @brief Turn on a power source
*
* This power source should be turned on when its power domain is turned on, in order to start consuming power
*/
void turn_on();

/**
* @brief Turn off a power source
*
* This power source should be turned off when its power domain is turned off, in order to stop consuming power
*/
void turn_off();

/**
* @brief Turn on a power source
*
* This power source should be turned on when its power domain is turned on, in order to start consuming power
*/
void turn_dynamic_power_on();

/**
* @brief Turn off a power source
*
* This power source should be turned off when its power domain is turned off, in order to stop consuming power
*/
void turn_dynamic_power_off();

private:
Linear_table *table = NULL; // Table of power values for all supported temperatures and voltages
// imported from the json configuration given when trace was initialized.
void check();

Linear_table *dyn_table = NULL; // Table of power values for all supported temperatures and voltages
// imported from the json configuration given when trace was initialized.
Linear_table *leakage_table = NULL; // Table of power values for all supported temperatures and voltages
// imported from the json configuration given when trace was initialized.
double quantum; // Current quantumm of energy, for quantum-based power consumption.
// The current value is estimated depending on voltage and temperature according
// to the provided json configuration.
Expand All @@ -162,7 +194,12 @@ namespace vp
// to the provided json configuration.
component *top; // Top component containing the power source
power_trace *trace; // Power trace where the power consumption should be reported.
bool is_on = false; // True is the source is on and backgroun-power and leakage should be reported
bool is_dynamic_power_started = false; // True is the source consuming dynamic backgroun power
bool is_leakage_power_started = false; // True is the source should start consuming leakage power
bool is_on = false; // True is the power domain containing the power source is on and backgroun-power and leakage should be reported
bool is_dynamic_power_on = false; // True is the power domain containing the power source is on and backgroun-power and leakage should be reported
bool dynamic_power_is_on_sync = false;
bool leakage_power_is_on_sync = false;
};


Expand Down Expand Up @@ -327,12 +364,16 @@ namespace vp
// power consumed.
void account_leakage_power();

// Check if the current amount of cycle energy is not for the current cycle
// Check if the current amount of power due to quantum of energies
// is not for the current cycle
// (by checking the timestamp), and if not, reset it to zero.
inline void flush_dynamic_energy_for_cycle();
inline void flush_quantum_power_for_cycle();

// Get the amount of energy spent in the current cycle
inline double get_dynamic_energy_for_cycle();
// Get the average power of the current cycle due to quantums of energy
inline double get_quantum_power_for_cycle();

// Get the energy spent in the current cycle due to quantums of energy
inline double get_quantum_energy_for_cycle();

// Return the total amount of dynamic energy spent since the beginning
// of the report windows (since report_start was called)
Expand Down Expand Up @@ -363,7 +404,7 @@ namespace vp
int64_t curent_cycle_timestamp; // Timestamp of the current cycle, used to compute energy spent in the
// current cycle. As soon as current time is different, the timestamp
// is set to current time and the current energy is set to 0.
double dynamic_energy_for_cycle; // Amount of energy spent in the current cycle.
double quantum_power_for_cycle; // Power spent by quentum of energy in the current cycle.
// It is increased everytime a quantum of energy is
// spent and reset to zero when the current cycle is
// over. It is mostly used to compute the instant power
Expand Down Expand Up @@ -468,6 +509,15 @@ namespace vp
*/
vp::power::power_trace *get_power_trace() { return &this->power_trace; }

/**
* @brief Set power supply state
*
* This sets the power supply for this component and all his childs.
*
* @param state Supply state
*/
void power_supply_set_all(int state);

protected:
/**
* @brief Get the report energy from childs object
Expand Down Expand Up @@ -516,10 +566,15 @@ namespace vp
// Get instant power for this component and the whole hierarchy below him.
double get_power_from_self_and_childs();

// Set power supply state
static void power_supply_sync(void *_this, int state);

component ⊤ // Component containing the power component object
vp::power::power_trace power_trace; // Default power trace of this component
std::vector<vp::power::power_trace *> traces; // Vector of power traces of this component
std::vector<vp::power::power_source *> sources; // Vector of power sources of this component
power::engine *engine = NULL; // Power engine
vp::wire_slave<int> power_port; // Slave port for setting power supply state
};


Expand All @@ -542,6 +597,8 @@ namespace vp
*/
engine(vp::component *top);

~engine();

/**
* @brief Start power report generation
*
Expand Down Expand Up @@ -570,6 +627,8 @@ namespace vp
std::vector<vp::power::power_trace *> traces; // Vector of all traces.

vp::component *top; // Top component of the simulated architecture

FILE *file; // File where the power reports are dumped
};

};
Expand Down
10 changes: 10 additions & 0 deletions engine/include/vp/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ namespace vp {
{

friend class component_clock;
friend class vp::power::component_power;

public:
component(js::config *config);
Expand All @@ -410,6 +411,7 @@ namespace vp {
virtual void quit(int status) {}
virtual void pre_reset() {}
virtual void reset(bool active) {}
virtual void power_supply_set(int state) {}
virtual void load() {}
virtual void elab();
virtual void run() {}
Expand Down Expand Up @@ -568,6 +570,14 @@ namespace vp {

vp::component *__gv_create(std::string config_path, struct gv_conf *gv_conf);

class top
{
public:
component *top_instance;
power::engine *power_engine;
private:
};

};

#endif
61 changes: 44 additions & 17 deletions engine/include/vp/power/power_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,86 @@
#include "vp/vp_data.hpp"


inline void vp::power::power_source::turn_on()
{
this->is_on = true;
this->is_dynamic_power_on = true;
this->check();
}


inline void vp::power::power_source::turn_off()
{
this->is_on = false;
this->is_dynamic_power_on = false;
this->check();
}

inline void vp::power::power_source::turn_dynamic_power_on()
{
this->is_dynamic_power_on = true;
this->check();
}

inline void vp::power::power_source::turn_dynamic_power_off()
{
this->is_dynamic_power_on = false;
this->check();
}


inline void vp::power::power_source::leakage_power_start()
{
// Only start accounting leakage if not already done and if leakage is defined
if (!this->is_on && this->leakage != -1)
// Only start if leakage is defined
if (this->leakage != -1)
{
this->trace->inc_leakage_power(this->leakage);
this->is_leakage_power_started = true;
this->check();
}
this->is_on = true;
}



inline void vp::power::power_source::leakage_power_stop()
{
// Only stop accounting leakage if not already done and if leakage is defined
if (this->is_on && this->leakage != -1)
// Only stop if leakage is defined
if (this->leakage != -1)
{
this->trace->inc_leakage_power(-this->leakage);
this->is_leakage_power_started = false;
this->check();
}
this->is_on = false;
}



inline void vp::power::power_source::dynamic_power_start()
{
// Only start accounting background power if not already done and if it is is defined
if (!this->is_on && this->background_power != -1)
// Only start accounting background power if it is is defined
if (this->background_power != -1)
{
this->trace->inc_dynamic_power(this->background_power);
this->is_dynamic_power_started = true;
this->check();
}
this->is_on = true;
}



inline void vp::power::power_source::dynamic_power_stop()
{
// Only stop accounting background power if not already done and if it is is defined
if (this->is_on && this->background_power != -1)
// Only stop accounting background power if it is is defined
if (this->background_power != -1)
{
this->trace->inc_dynamic_power(-this->background_power);
this->is_dynamic_power_started = false;
this->check();
}
this->is_on = false;
}



inline void vp::power::power_source::account_energy_quantum()
{
// Only account energy is a quantum is defined
if (this->quantum != -1)
if (this->is_on && this->is_dynamic_power_on && this->quantum != -1)
{
this->trace->inc_dynamic_energy(this->quantum);
}
Expand Down
32 changes: 25 additions & 7 deletions engine/include/vp/power/power_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,43 @@ inline double vp::power::power_trace::get_power()



inline double vp::power::power_trace::get_dynamic_energy_for_cycle()
inline double vp::power::power_trace::get_quantum_power_for_cycle()
{
// First check if the current energy is for an old cycle
this->flush_dynamic_energy_for_cycle();
this->flush_quantum_power_for_cycle();

// And return the current total
return this->dynamic_energy_for_cycle;
return this->quantum_power_for_cycle;
}


inline double vp::power::power_trace::get_quantum_energy_for_cycle()
{
double power = this->get_quantum_power_for_cycle();

inline void vp::power::power_trace::flush_dynamic_energy_for_cycle()
if (power != 0)
{
return power * this->top->get_period();
}

return 0;
}



inline void vp::power::power_trace::flush_quantum_power_for_cycle()
{
// Clear the current total if it is not for the current cycle
if (this->curent_cycle_timestamp < this->top->get_time())
if (this->quantum_power_for_cycle && this->curent_cycle_timestamp < this->top->get_time())
{
this->curent_cycle_timestamp = this->top->get_time();
this->dynamic_energy_for_cycle = 0;
if (this->parent)
{
this->parent->inc_dynamic_power(-this->quantum_power_for_cycle);
}
this->quantum_power_for_cycle = 0;
}

this->curent_cycle_timestamp = this->top->get_time();
}


Expand Down
12 changes: 7 additions & 5 deletions engine/src/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Gvsoc_launcher : public gv::Gvsoc

private:

void *handler;
vp::component *instance;
};

Expand All @@ -53,19 +54,20 @@ gv::Gvsoc *gv::gvsoc_new()

void Gvsoc_launcher::open(std::string config_path)
{
this->instance = vp::__gv_create(config_path, NULL);
this->handler = vp::__gv_create(config_path, NULL);
this->instance = ((vp::top *)this->handler)->top_instance;

gv_start((void *)this->instance);
gv_start(this->handler);
}

void Gvsoc_launcher::close()
{
gv_destroy((void *)this->instance);
gv_destroy(this->handler);
}

void Gvsoc_launcher::run()
{
gv_step((void *)this->instance, 0);
gv_step(this->handler, 0);
}

int64_t Gvsoc_launcher::stop()
Expand All @@ -76,7 +78,7 @@ int64_t Gvsoc_launcher::stop()

int64_t Gvsoc_launcher::step(int64_t duration)
{
gv_step((void *)this->instance, duration);
gv_step(this->handler, duration);
return 0;
}

Expand Down
Loading

0 comments on commit 886a56f

Please sign in to comment.