1/*
2 * Copyright (c) 2014, TU Delft, TU Eindhoven and TU Kaiserslautern
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Authors: Matthias Jung, Omar Naji, Felipe S. Prado
33 *
34 */
35
36#include <iostream>
37#include <string>
38#include "libdrampower/LibDRAMPower.h"
39
40#if USE_XERCES
41#include "xmlparser/MemSpecParser.h"
42#endif
43
44using namespace std;
45using namespace Data;
46
47int main(int argc, char* argv[])
48{
49  assert(argc == 2);
50  //Setup of DRAMPower for your simulation
51  string filename;
52  //type path to memspec file
53  filename = argv[1];
54  //Parsing the Memspec specification of found in memspec folder
55#if USE_XERCES
56  MemorySpecification memSpec(MemSpecParser::getMemSpecFromXML(filename));
57#else
58  MemorySpecification memSpec;
59#endif
60  libDRAMPower test = libDRAMPower(memSpec, 0);
61
62  ios_base::fmtflags flags = cout.flags();
63  streamsize precision = cout.precision();
64  cout.precision(2);
65  cout << fixed << endl;
66
67  // During the simulation you can report activity
68  // to DRAMPower with the doCommand(...) function:
69  test.doCommand(MemCommand::ACT,0,35);
70  test.doCommand(MemCommand::RDA,0,50);
71  test.doCommand(MemCommand::ACT,4,51);
72  test.doCommand(MemCommand::RDA,4,66);
73  test.doCommand(MemCommand::ACT,0,86);
74  test.doCommand(MemCommand::RDA,0,101);
75  test.doCommand(MemCommand::ACT,2,102);
76  test.doCommand(MemCommand::RDA,2,117);
77  test.doCommand(MemCommand::ACT,5,119);
78  test.doCommand(MemCommand::RDA,5,134);
79  test.doCommand(MemCommand::ACT,0,137);
80  test.doCommand(MemCommand::RDA,0,152);
81  test.doCommand(MemCommand::ACT,3,159);
82  test.doCommand(MemCommand::RDA,3,174);
83  test.doCommand(MemCommand::ACT,0,195);
84  test.doCommand(MemCommand::RDA,0,210);
85  test.doCommand(MemCommand::ACT,4,232);
86  test.doCommand(MemCommand::WRA,4,247);
87  // Need at least tWRAPDEN = AL + CWL + BL/2 + WR + 1 cycles between WR and PDN_F_PRE
88  test.doCommand(MemCommand::PDN_F_PRE,3,265);
89  // Exit from Precharge Power-down
90  test.doCommand(MemCommand::PUP_PRE,3,300);
91  // Activate bank 0
92  test.doCommand(MemCommand::ACT,0,350);
93  // Precharge all banks with bank 0 active
94  test.doCommand(MemCommand::PREA,0,400);
95  // Precharge all banks again
96  // XXX: For testing purpose only! Double precharge all should never
97  // happen. Warnings are generated.
98  test.doCommand(MemCommand::PREA,0,450);
99  // Activate bank 0 twice
100  // XXX: For testing purpose only! Double activate should never happen.
101  // Warnings are generated.
102  test.doCommand(MemCommand::ACT,0,500);
103  test.doCommand(MemCommand::ACT,0,550);
104  // Precharge bank 0 twice
105  // XXX: For testing purpose only! Double precharge for the same bank
106  // should never happen. Warnings are generated.
107  test.doCommand(MemCommand::PRE,0,600);
108  test.doCommand(MemCommand::PRE,0,650);
109
110  // At the end of your simulation call the getEnergy(...)
111  // function to print the power report
112  test.calcEnergy();
113
114  // Accesing the results:
115
116  // Number of issued Commands
117  std::cout << "Number of ACTs: " << std::accumulate(test.counters.numberofactsBanks.begin(),
118      test.counters.numberofactsBanks.end()
119      ,0)<< endl;
120  std::cout << "Number of RDs: " << std::accumulate(test.counters.numberofreadsBanks.begin(),
121      test.counters.numberofreadsBanks.end()
122      ,0)<< endl;
123  std::cout << "Number of PREs: " << std::accumulate(test.counters.numberofpresBanks.begin(),
124      test.counters.numberofpresBanks.end()
125      ,0)<< endl;
126  // many other timing parameters in test.mpm.timings
127
128  //ENERGIES per Rank
129  std::cout << "ACT Cmd Energy: " << test.getEnergy().act_energy << " pJ" << endl;
130  std::cout << "PRE Cmd Energy: " << test.getEnergy().pre_energy << " pJ" << endl;
131  std::cout << "RD Cmd Energy: " << test.getEnergy().read_energy << " pJ" << endl;
132  std::cout << "WR Cmd Energy: "  << test.getEnergy().write_energy << " pJ" << endl << endl;
133  //Standby Energy for 1 rank
134  //In total energy calculated for both ranks= test.memSpec.memArchSpec *
135  //test.getEnergy().act_stdby_energy
136  std::cout << "ACT Stdby Energy: "  << test.getEnergy().act_stdby_energy << " pJ" << endl;
137  //total active standby energy for both ranks
138  std::cout << "ACT Stdby Energy total ranks: "  << static_cast<double>(memSpec.memArchSpec.nbrOfRanks) *
139    test.getEnergy().act_stdby_energy << " pJ" << endl ;
140  std::cout << "PRE Stdby Energy: " << test.getEnergy().pre_stdby_energy << " pJ" << endl << endl;
141  std::cout << "Total Trace Energy: " <<  test.getEnergy().total_energy << " pJ" <<  endl;
142  //many other energies in test.mpm.energy
143
144  //Powers per Rank
145  std::cout << "Average Power: " << test.getPower().average_power <<  " mW" <<  endl;
146  //many other powers in test.getPower()
147
148  cout.flags(flags);
149  cout.precision(precision);
150
151  return 0;
152}
153