CmdScheduler.h revision 10428
110381Sdam.sunwoo@arm.com/*
210381Sdam.sunwoo@arm.com * Copyright (c) 2012-2014, TU Delft
310381Sdam.sunwoo@arm.com * Copyright (c) 2012-2014, TU Eindhoven
410381Sdam.sunwoo@arm.com * Copyright (c) 2012-2014, TU Kaiserslautern
510381Sdam.sunwoo@arm.com * All rights reserved.
610381Sdam.sunwoo@arm.com *
710381Sdam.sunwoo@arm.com * Redistribution and use in source and binary forms, with or without
810381Sdam.sunwoo@arm.com * modification, are permitted provided that the following conditions are
910381Sdam.sunwoo@arm.com * met:
1010381Sdam.sunwoo@arm.com *
1110381Sdam.sunwoo@arm.com * 1. Redistributions of source code must retain the above copyright
1210381Sdam.sunwoo@arm.com * notice, this list of conditions and the following disclaimer.
1310381Sdam.sunwoo@arm.com *
1410381Sdam.sunwoo@arm.com * 2. Redistributions in binary form must reproduce the above copyright
1510381Sdam.sunwoo@arm.com * notice, this list of conditions and the following disclaimer in the
1610381Sdam.sunwoo@arm.com * documentation and/or other materials provided with the distribution.
1710381Sdam.sunwoo@arm.com *
1810381Sdam.sunwoo@arm.com * 3. Neither the name of the copyright holder nor the names of its
1910381Sdam.sunwoo@arm.com * contributors may be used to endorse or promote products derived from
2010381Sdam.sunwoo@arm.com * this software without specific prior written permission.
2110381Sdam.sunwoo@arm.com *
2210381Sdam.sunwoo@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2310381Sdam.sunwoo@arm.com * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2410381Sdam.sunwoo@arm.com * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
2510381Sdam.sunwoo@arm.com * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2610381Sdam.sunwoo@arm.com * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2710381Sdam.sunwoo@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2810381Sdam.sunwoo@arm.com * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2910381Sdam.sunwoo@arm.com * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3010381Sdam.sunwoo@arm.com * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3110381Sdam.sunwoo@arm.com * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3210381Sdam.sunwoo@arm.com * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3310381Sdam.sunwoo@arm.com *
3410381Sdam.sunwoo@arm.com * Authors: Karthik Chandrasekar
3510381Sdam.sunwoo@arm.com *
3610381Sdam.sunwoo@arm.com */
3710381Sdam.sunwoo@arm.com
3810381Sdam.sunwoo@arm.com#ifndef CMDSCHEDULER_H
3910381Sdam.sunwoo@arm.com#define CMDSCHEDULER_H
4010381Sdam.sunwoo@arm.com
4111793Sbrandon.potter@amd.com#include <string>
4211793Sbrandon.potter@amd.com#include <vector>
4310381Sdam.sunwoo@arm.com#include <functional>  // for binary_function<>
4410381Sdam.sunwoo@arm.com#include <fstream>
4510381Sdam.sunwoo@arm.com
4610381Sdam.sunwoo@arm.com#include "MemorySpecification.h"
4710381Sdam.sunwoo@arm.com#include "Utils.h"
4810381Sdam.sunwoo@arm.com
4910381Sdam.sunwoo@arm.comnamespace Data {
5010381Sdam.sunwoo@arm.comclass cmdScheduler {
5110381Sdam.sunwoo@arm.com public:
5210381Sdam.sunwoo@arm.com        #define READ            0
5310381Sdam.sunwoo@arm.com        #define WRITE           1
5410381Sdam.sunwoo@arm.com        #define ACTIVATE        2
5510381Sdam.sunwoo@arm.com        #define PRECHARGE       3
5610381Sdam.sunwoo@arm.com        #define POWER_DOWN      1
5710381Sdam.sunwoo@arm.com        #define SELF_REFRESH    2
5810381Sdam.sunwoo@arm.com
5910381Sdam.sunwoo@arm.com  // the format of a transaction.
6010381Sdam.sunwoo@arm.com  class trans {
6110381Sdam.sunwoo@arm.com   public:
6210381Sdam.sunwoo@arm.com    int type;
6310381Sdam.sunwoo@arm.com    double timeStamp;
6410381Sdam.sunwoo@arm.com    unsigned logicalAddress;
6510381Sdam.sunwoo@arm.com  };
6610381Sdam.sunwoo@arm.com
6710381Sdam.sunwoo@arm.com  std::vector<trans> transTrace; // to store the transactions.
6810381Sdam.sunwoo@arm.com
6910381Sdam.sunwoo@arm.com  // the format of physical address.
7010381Sdam.sunwoo@arm.com  class physicalAddr {
7110381Sdam.sunwoo@arm.com   public:
7210381Sdam.sunwoo@arm.com    unsigned rowAddr;
7310381Sdam.sunwoo@arm.com    unsigned bankAddr;
7410381Sdam.sunwoo@arm.com    unsigned bankGroupAddr;
7510381Sdam.sunwoo@arm.com    unsigned colAddr;
7610381Sdam.sunwoo@arm.com  };
7710381Sdam.sunwoo@arm.com
7810381Sdam.sunwoo@arm.com  // the format of a command.
7910381Sdam.sunwoo@arm.com  class commandItem {
8010381Sdam.sunwoo@arm.com   public:
8110417Sandreas.hansson@arm.com    int Type;
8210381Sdam.sunwoo@arm.com    int bank;
8310651Snikos.nikoleris@gmail.com    double time;
8410651Snikos.nikoleris@gmail.com    std::string  name;
8510651Snikos.nikoleris@gmail.com    physicalAddr PhysicalAddr;
8610381Sdam.sunwoo@arm.com    // sorting the commands according to their scheduling time.
8710381Sdam.sunwoo@arm.com    struct commandItemSorter : public std::binary_function<commandItem&,
8810381Sdam.sunwoo@arm.com                                                           commandItem&, bool>{
8910381Sdam.sunwoo@arm.com      bool operator()(const commandItem& lhs,
9010381Sdam.sunwoo@arm.com                      const commandItem& rhs) const
9110381Sdam.sunwoo@arm.com      {
9210381Sdam.sunwoo@arm.com        return lhs.time < rhs.time;
9310381Sdam.sunwoo@arm.com      }
9410381Sdam.sunwoo@arm.com    };
9510381Sdam.sunwoo@arm.com  };
9610381Sdam.sunwoo@arm.com
9710381Sdam.sunwoo@arm.com  commandItem cmd;
9810381Sdam.sunwoo@arm.com  commandItem transFinish; // the last scheduled command for a transaction.
9910381Sdam.sunwoo@arm.com  commandItem PreRDWR;     // the latest scheduled READ or WRITE command.
10010381Sdam.sunwoo@arm.com  // the scheduled ACTIVATE commands are stored in ACT.
10110381Sdam.sunwoo@arm.com  std::vector<commandItem> ACT;
10210381Sdam.sunwoo@arm.com  // PRE is sued to keep recording the time when a precharge occurs.
10310381Sdam.sunwoo@arm.com  std::vector<commandItem> PRE;
10410381Sdam.sunwoo@arm.com  // the scheduled READ or WRITE commands are stored in RDWR.
10510381Sdam.sunwoo@arm.com  std::vector<std::vector<commandItem> > RDWR;
10610381Sdam.sunwoo@arm.com  // all the scheduled commands for a transaction is stored by cmdScheduling.
10710381Sdam.sunwoo@arm.com  std::vector<commandItem> cmdScheduling;
10810381Sdam.sunwoo@arm.com  std::vector<commandItem> cmdList;
10910381Sdam.sunwoo@arm.com  unsigned elements;
11010381Sdam.sunwoo@arm.com  int BI, BC, BGI;
11110381Sdam.sunwoo@arm.com
11210381Sdam.sunwoo@arm.com  // the function used to translate a transaction into a sequence of
11310381Sdam.sunwoo@arm.com  // commands which are scheduled to the memory.
11410381Sdam.sunwoo@arm.com  void transTranslation(Data::MemorySpecification memSpec,
11510381Sdam.sunwoo@arm.com                        std::ifstream&            trans_trace,
11610381Sdam.sunwoo@arm.com                        int                       grouping,
11710381Sdam.sunwoo@arm.com                        int                       interleaving,
11810381Sdam.sunwoo@arm.com                        int                       burst,
11910381Sdam.sunwoo@arm.com                        int                       powerdown);
12010381Sdam.sunwoo@arm.com  // get the transactions by reading the traces.
12110381Sdam.sunwoo@arm.com  void getTrans(std::ifstream&      pwr_trace,
12210381Sdam.sunwoo@arm.com                MemorySpecification memSpec);
12310381Sdam.sunwoo@arm.com  // the initialization function for scheduling.
12410381Sdam.sunwoo@arm.com  void schedulingInitialization(MemorySpecification memSpec);
12510381Sdam.sunwoo@arm.com  // the function used to schedule commands according to the timing constraints.
12610381Sdam.sunwoo@arm.com  void analyticalScheduling(MemorySpecification memSpec);
12710381Sdam.sunwoo@arm.com  // translate the logical address into physical address.
12810381Sdam.sunwoo@arm.com  physicalAddr memoryMap(trans               Trans,
12910381Sdam.sunwoo@arm.com                         MemorySpecification memSpec);
13011359Sandreas@sandberg.pp.se  // the power down and power up are scheduled by pdScheduling
13110381Sdam.sunwoo@arm.com  void pdScheduling(double              endTime,
13210381Sdam.sunwoo@arm.com                    double              timer,
13311359Sandreas@sandberg.pp.se                    MemorySpecification memSpec);
13410381Sdam.sunwoo@arm.com  // get the timings for scheduling a precharge since a read or write command
13510381Sdam.sunwoo@arm.com  // is scheduled.
13611359Sandreas@sandberg.pp.se  int getRWTP(int                 transType,
13710381Sdam.sunwoo@arm.com              MemorySpecification memSpec);
13810381Sdam.sunwoo@arm.com  // get different kind of timing constraints according to the used memory.
13910381Sdam.sunwoo@arm.com  void getTimingConstraints(bool                BGSwitch,
14010381Sdam.sunwoo@arm.com                            MemorySpecification memSpec,
14110381Sdam.sunwoo@arm.com                            int                 PreType,
14210381Sdam.sunwoo@arm.com                            int                 CurrentType);
14310381Sdam.sunwoo@arm.com
14410381Sdam.sunwoo@arm.com  double transTime;
14510381Sdam.sunwoo@arm.com  // the flag for power down.
14610381Sdam.sunwoo@arm.com  int    power_down;
14710381Sdam.sunwoo@arm.com  int    Inselfrefresh;
14810381Sdam.sunwoo@arm.com  int    tRRD_init;
14910381Sdam.sunwoo@arm.com  int    tCCD_init;
150  int    tWTR_init;
151  double tREF;
152  double tSwitch_init;
153  double tRWTP;
154  int    bankaccess;
155  unsigned nBanks;
156  unsigned nColumns;
157  unsigned burstLength;
158  unsigned nbrOfBankGroups;
159  bool timingsGet;
160  double   startTime;
161
162  // the scheduling results for all the transactions are written into
163  // commands which will be used by the power analysis part.
164  std::ofstream commands;
165};
166}
167
168#endif // ifndef CMDSCHEDULER_H
169