From ba3a1d704fd9555586502da24991fb1502ed098a Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Wed, 12 Jul 2017 23:32:17 +0200 Subject: [PATCH] Read Priorization for FR_FCFS I Added the feature that RD is always prioritized before WR for FR_FCFS. Instead of searching the next row hit for a specific bank it searches for the next row hit which is a read. If there is not read hit found it searches for a write read. If no write read is found it takes the oldest request. Even this could be further improved of course because RD/WR switching is actually not a per bank problem its because of the shared busses. --- DRAMSys/simulator/library.pro | 6 +- .../configs/mcconfigs/fr_fcfs_rp.xml | 13 ++ .../simulator/src/controller/Controller.cpp | 4 + DRAMSys/simulator/src/controller/Controller.h | 1 + .../src/controller/scheduler/Fr_Fcfs.h | 4 +- .../scheduler/Fr_Fcfs_read_priority.cpp | 111 ++++++++++++++++++ .../scheduler/Fr_Fcfs_read_priority.h | 54 +++++++++ 7 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs_rp.xml create mode 100644 DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.cpp create mode 100644 DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.h diff --git a/DRAMSys/simulator/library.pro b/DRAMSys/simulator/library.pro index a0bb357c..fcbdeb0a 100644 --- a/DRAMSys/simulator/library.pro +++ b/DRAMSys/simulator/library.pro @@ -117,7 +117,8 @@ SOURCES += \ src/error/ECC/ECC.cpp \ src/error/ECC/Word.cpp \ src/error/eccbaseclass.cpp \ - src/error/ecchamming.cpp + src/error/ecchamming.cpp \ + src/controller/scheduler/Fr_Fcfs_read_priority.cpp HEADERS += \ src/common/third_party/tinyxml2/tinyxml2.h \ @@ -186,7 +187,8 @@ HEADERS += \ src/error/ECC/ECC.h \ src/error/ECC/Word.h \ src/error/eccbaseclass.h \ - src/error/ecchamming.h + src/error/ecchamming.h \ + src/controller/scheduler/Fr_Fcfs_read_priority.h thermalsim = $$(THERMALSIM) isEmpty(thermalsim) { diff --git a/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs_rp.xml b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs_rp.xml new file mode 100644 index 00000000..caa9ff67 --- /dev/null +++ b/DRAMSys/simulator/resources/configs/mcconfigs/fr_fcfs_rp.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/DRAMSys/simulator/src/controller/Controller.cpp b/DRAMSys/simulator/src/controller/Controller.cpp index bf68d7d4..e9686617 100644 --- a/DRAMSys/simulator/src/controller/Controller.cpp +++ b/DRAMSys/simulator/src/controller/Controller.cpp @@ -53,6 +53,10 @@ void Controller::buildScheduler() { scheduler = new FR_FCFS(*controllerCore); } + else if (selectedScheduler == "FR_FCFS_RP") + { + scheduler = new FR_FCFS_RP(*controllerCore); + } else if (selectedScheduler == "SMS") { scheduler = new SMS("SMS", *controllerCore, Configuration::getInstance().SJFProbability); diff --git a/DRAMSys/simulator/src/controller/Controller.h b/DRAMSys/simulator/src/controller/Controller.h index b5f67ff7..cc833aae 100644 --- a/DRAMSys/simulator/src/controller/Controller.h +++ b/DRAMSys/simulator/src/controller/Controller.h @@ -67,6 +67,7 @@ #include "scheduler/Fifo.h" #include "scheduler/FifoStrict.h" #include "scheduler/Fr_Fcfs.h" +#include "scheduler/Fr_Fcfs_read_priority.h" #include "scheduler/SMS.h" #include "scheduler/IScheduler.h" diff --git a/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs.h b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs.h index 9347c21f..3b2450de 100644 --- a/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs.h +++ b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs.h @@ -55,8 +55,10 @@ public: std::pair getNextRequest(Bank bank) override; virtual gp* getPendingRequest(Bank bank) override; -private: +protected: std::map> buffer; + +private: std::deque::iterator FindRowHit(Bank bank); }; diff --git a/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.cpp b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.cpp new file mode 100644 index 00000000..750bfc92 --- /dev/null +++ b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Matthias Jung + */ + +#include "Fr_Fcfs_read_priority.h" + +// The FR_FCFS_Read_Priority works exactly like the FR_FCFS but reads are +// prioratized over writes. For detailed documentation look into the FR_FCFS. + +std::pair FR_FCFS_RP::getNextRequest(Bank bank) +{ + // If the bank is empty like Bank0 in the example we do nothing + if(buffer[bank].empty()) + { + return pair(Command::NOP, NULL); + } + + // In FR_FCFS row hits have always the highest priority, therefore we search + // for row hits. If we find a row hit, we remove the transaction from the + // queue and send it to the DRAM. + deque::iterator it = FindRowHit_RP(bank); + if(it != buffer[bank].end()) + { + gp* payload = *it; + buffer[bank].erase(it); + return pair(getReadWriteCommand(*payload), payload); + } + + // If there is no row hit, the FR_FCFS takes always the oldest transaction + // in the buffer, i.e. the transaction in the front. + return pair(getNextCommand(buffer[bank].front()), + buffer[bank].front()); +} + +// This function searches for a row hit in the scheduling queue of the specific +// bank like FindRowHit in FR_FCFS. However, it will search for reads first and +// it will take a write only if there is no read row hit. +// If no row hit is found the end of the queue is returned. +// +// Note: end() Returns an iterator referring to the past-the-end element in the +// deque container. The past-the-end element is the theoretical element that +// would follow the last element in the deque container. It does not point to +// any element, and thus shall not be dereferenced. +deque::iterator FR_FCFS_RP::FindRowHit_RP(Bank bank) +{ + deque &queue = buffer[bank]; + + if(!controllerCore.getRowBufferStates().rowBufferIsOpen(bank)) + return queue.end(); + + // Traverse the scheduling queue of the specific + // bank and serach for read hits: + for(auto it = queue.begin(); it!=queue.end(); it++) + { + gp* payload = *it; + //Found read row-hit and return the according iterator + if(DramExtension::getRow(payload) + == controllerCore.getRowBufferStates().getRowInRowBuffer(bank) + && payload->get_command() == tlm::TLM_READ_COMMAND) + { + return it; + } + } + // Traverse the scheduling queue of the specific + // bank and serach for write hits in case no read was found: + for(auto it = queue.begin(); it!=queue.end(); it++) + { + gp* payload = *it; + //Found read row-hit and return the according iterator + if(DramExtension::getRow(payload) + == controllerCore.getRowBufferStates().getRowInRowBuffer(bank) + && payload->get_command() == tlm::TLM_WRITE_COMMAND) + { + return it; + } + } + + // If neither read or write hit was found we return the end: + return queue.end(); +} diff --git a/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.h b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.h new file mode 100644 index 00000000..d0cab41c --- /dev/null +++ b/DRAMSys/simulator/src/controller/scheduler/Fr_Fcfs_read_priority.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, University of Kaiserslautern + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: + * Matthias Jung + */ + +#ifndef FR_FCFS_READ_PRIORITY_H +#define FR_FCFS_READ_PRIORITY_H + +#include "Fr_Fcfs.h" + +class FR_FCFS_RP : public FR_FCFS +{ +public: + FR_FCFS_RP(ControllerCore &controllerCore) : FR_FCFS(controllerCore) {} + + std::pair + getNextRequest(Bank bank) override; + +private: + + std::deque::iterator FindRowHit_RP(Bank bank); +}; + +#endif // FR_FCFS_READ_PRIORITY_H