1/*
2 * Copyright (c) 2012-2014, TU Delft
3 * Copyright (c) 2012-2014, TU Eindhoven
4 * Copyright (c) 2012-2014, TU Kaiserslautern
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are

--- 17 unchanged lines hidden (view full) ---

26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Authors: Matthias Jung, Omar Naji
34 * Authors: Matthias Jung
35 * Omar Naji
36 * Subash Kannoth
37 * Éder F. Zulian
38 * Felipe S. Prado
39 *
40 */
41
42#include "LibDRAMPower.h"
43
44using namespace Data;
45
46libDRAMPower::libDRAMPower(const MemorySpecification& memSpec, bool includeIoAndTermination) :
47 memSpec(memSpec),
44 counters(CommandAnalysis(memSpec.memArchSpec.nbrOfBanks)),
45 includeIoAndTermination(includeIoAndTermination)
48 counters(memSpec),
49 includeIoAndTermination(includeIoAndTermination),
50 mpm(MemoryPowerModel())
51{
52 MemBankWiseParams p (100,100,false,0,false,static_cast<unsigned>(memSpec.memArchSpec.nbrOfBanks));
53 libDRAMPower DRAMPower = libDRAMPower(memSpec, 0, p);
54}
55
56libDRAMPower::libDRAMPower(const MemorySpecification& memSpec, bool includeIoAndTermination, const Data::MemBankWiseParams& bwPowerParams) :
57 memSpec(memSpec),
58 counters(CommandAnalysis(memSpec)),
59 includeIoAndTermination(includeIoAndTermination),
60 bwPowerParams(bwPowerParams)
61{
62}
63
64libDRAMPower::~libDRAMPower()
65{
66}
67
68void libDRAMPower::doCommand(MemCommand::cmds type, int bank, int64_t timestamp)
69{
70 MemCommand cmd(type, static_cast<unsigned>(bank), timestamp);
71 cmdList.push_back(cmd);
72}
73
59void libDRAMPower::updateCounters(bool lastUpdate)
74void libDRAMPower::updateCounters(bool lastUpdate, int64_t timestamp)
75{
61 counters.getCommands(memSpec, cmdList, lastUpdate);
76 counters.getCommands(cmdList, lastUpdate, timestamp);
77 cmdList.clear();
78}
79
80void libDRAMPower::calcEnergy()
81{
67 mpm.power_calc(memSpec, counters, includeIoAndTermination);
82 updateCounters(true);
83 mpm.power_calc(memSpec, counters, includeIoAndTermination, bwPowerParams);
84}
85
86void libDRAMPower::calcWindowEnergy(int64_t timestamp)
87{
88 doCommand(MemCommand::NOP, 0, timestamp);
89 updateCounters(false, timestamp);
90 mpm.power_calc(memSpec, counters, includeIoAndTermination, bwPowerParams);
91 clearCounters(timestamp);
92}
93
94
95void libDRAMPower::clearState()
96{
97 counters.clear();
98}
99
100void libDRAMPower::clearCounters(int64_t timestamp)
101{
102 counters.clearStats(timestamp);
103}
104
105const Data::MemoryPowerModel::Energy& libDRAMPower::getEnergy() const
106{
107 return mpm.energy;
108}
109
110const Data::MemoryPowerModel::Power& libDRAMPower::getPower() const
111{
112 return mpm.power;
113}