timing.hh revision 9087
12623SN/A/* 22623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32623SN/A * All rights reserved. 42623SN/A * 52623SN/A * Redistribution and use in source and binary forms, with or without 62623SN/A * modification, are permitted provided that the following conditions are 72623SN/A * met: redistributions of source code must retain the above copyright 82623SN/A * notice, this list of conditions and the following disclaimer; 92623SN/A * redistributions in binary form must reproduce the above copyright 102623SN/A * notice, this list of conditions and the following disclaimer in the 112623SN/A * documentation and/or other materials provided with the distribution; 122623SN/A * neither the name of the copyright holders nor the names of its 132623SN/A * contributors may be used to endorse or promote products derived from 142623SN/A * this software without specific prior written permission. 152623SN/A * 162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292623SN/A */ 302623SN/A 312623SN/A#ifndef __CPU_SIMPLE_TIMING_HH__ 322623SN/A#define __CPU_SIMPLE_TIMING_HH__ 332623SN/A 342623SN/A#include "cpu/simple/base.hh" 356973Stjones1@inf.ed.ac.uk#include "cpu/translation.hh" 365529Snate@binkert.org#include "params/TimingSimpleCPU.hh" 375529Snate@binkert.org 382623SN/Aclass TimingSimpleCPU : public BaseSimpleCPU 392623SN/A{ 402623SN/A public: 412623SN/A 425529Snate@binkert.org TimingSimpleCPU(TimingSimpleCPUParams * params); 432623SN/A virtual ~TimingSimpleCPU(); 442623SN/A 452623SN/A virtual void init(); 462623SN/A 472623SN/A public: 482839Sktlim@umich.edu Event *drainEvent; 492798Sktlim@umich.edu 502623SN/A private: 512623SN/A 525728Sgblack@eecs.umich.edu /* 535728Sgblack@eecs.umich.edu * If an access needs to be broken into fragments, currently at most two, 545728Sgblack@eecs.umich.edu * the the following two classes are used as the sender state of the 555728Sgblack@eecs.umich.edu * packets so the CPU can keep track of everything. In the main packet 565728Sgblack@eecs.umich.edu * sender state, there's an array with a spot for each fragment. If a 575728Sgblack@eecs.umich.edu * fragment has already been accepted by the CPU, aka isn't waiting for 585728Sgblack@eecs.umich.edu * a retry, it's pointer is NULL. After each fragment has successfully 595728Sgblack@eecs.umich.edu * been processed, the "outstanding" counter is decremented. Once the 605728Sgblack@eecs.umich.edu * count is zero, the entire larger access is complete. 615728Sgblack@eecs.umich.edu */ 625728Sgblack@eecs.umich.edu class SplitMainSenderState : public Packet::SenderState 635728Sgblack@eecs.umich.edu { 645728Sgblack@eecs.umich.edu public: 655728Sgblack@eecs.umich.edu int outstanding; 665728Sgblack@eecs.umich.edu PacketPtr fragments[2]; 675728Sgblack@eecs.umich.edu 685728Sgblack@eecs.umich.edu int 695728Sgblack@eecs.umich.edu getPendingFragment() 705728Sgblack@eecs.umich.edu { 715728Sgblack@eecs.umich.edu if (fragments[0]) { 725728Sgblack@eecs.umich.edu return 0; 735728Sgblack@eecs.umich.edu } else if (fragments[1]) { 745728Sgblack@eecs.umich.edu return 1; 755728Sgblack@eecs.umich.edu } else { 765728Sgblack@eecs.umich.edu return -1; 775728Sgblack@eecs.umich.edu } 785728Sgblack@eecs.umich.edu } 795728Sgblack@eecs.umich.edu }; 805728Sgblack@eecs.umich.edu 815728Sgblack@eecs.umich.edu class SplitFragmentSenderState : public Packet::SenderState 825728Sgblack@eecs.umich.edu { 835728Sgblack@eecs.umich.edu public: 845728Sgblack@eecs.umich.edu SplitFragmentSenderState(PacketPtr _bigPkt, int _index) : 855728Sgblack@eecs.umich.edu bigPkt(_bigPkt), index(_index) 865728Sgblack@eecs.umich.edu {} 875728Sgblack@eecs.umich.edu PacketPtr bigPkt; 885728Sgblack@eecs.umich.edu int index; 895728Sgblack@eecs.umich.edu 905728Sgblack@eecs.umich.edu void 915728Sgblack@eecs.umich.edu clearFromParent() 925728Sgblack@eecs.umich.edu { 935728Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = 945728Sgblack@eecs.umich.edu dynamic_cast<SplitMainSenderState *>(bigPkt->senderState); 955728Sgblack@eecs.umich.edu main_send_state->fragments[index] = NULL; 965728Sgblack@eecs.umich.edu } 975728Sgblack@eecs.umich.edu }; 985728Sgblack@eecs.umich.edu 995894Sgblack@eecs.umich.edu class FetchTranslation : public BaseTLB::Translation 1005894Sgblack@eecs.umich.edu { 1015894Sgblack@eecs.umich.edu protected: 1025894Sgblack@eecs.umich.edu TimingSimpleCPU *cpu; 1035894Sgblack@eecs.umich.edu 1045894Sgblack@eecs.umich.edu public: 1056023Snate@binkert.org FetchTranslation(TimingSimpleCPU *_cpu) 1066023Snate@binkert.org : cpu(_cpu) 1075894Sgblack@eecs.umich.edu {} 1085894Sgblack@eecs.umich.edu 1096023Snate@binkert.org void 1107944SGiacomo.Gabrielli@arm.com markDelayed() 1117945SAli.Saidi@ARM.com { 1127945SAli.Saidi@ARM.com assert(cpu->_status == Running); 1137945SAli.Saidi@ARM.com cpu->_status = ITBWaitResponse; 1147945SAli.Saidi@ARM.com } 1157944SGiacomo.Gabrielli@arm.com 1167944SGiacomo.Gabrielli@arm.com void 1176023Snate@binkert.org finish(Fault fault, RequestPtr req, ThreadContext *tc, 1186023Snate@binkert.org BaseTLB::Mode mode) 1195894Sgblack@eecs.umich.edu { 1205894Sgblack@eecs.umich.edu cpu->sendFetch(fault, req, tc); 1215894Sgblack@eecs.umich.edu } 1225894Sgblack@eecs.umich.edu }; 1235894Sgblack@eecs.umich.edu FetchTranslation fetchTranslation; 1245894Sgblack@eecs.umich.edu 1256973Stjones1@inf.ed.ac.uk void sendData(RequestPtr req, uint8_t *data, uint64_t *res, bool read); 1266973Stjones1@inf.ed.ac.uk void sendSplitData(RequestPtr req1, RequestPtr req2, RequestPtr req, 1276973Stjones1@inf.ed.ac.uk uint8_t *data, bool read); 1285894Sgblack@eecs.umich.edu 1295894Sgblack@eecs.umich.edu void translationFault(Fault fault); 1305894Sgblack@eecs.umich.edu 1315894Sgblack@eecs.umich.edu void buildPacket(PacketPtr &pkt, RequestPtr req, bool read); 1325894Sgblack@eecs.umich.edu void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, 1335894Sgblack@eecs.umich.edu RequestPtr req1, RequestPtr req2, RequestPtr req, 1345894Sgblack@eecs.umich.edu uint8_t *data, bool read); 1355744Sgblack@eecs.umich.edu 1365728Sgblack@eecs.umich.edu bool handleReadPacket(PacketPtr pkt); 1375728Sgblack@eecs.umich.edu // This function always implicitly uses dcache_pkt. 1385728Sgblack@eecs.umich.edu bool handleWritePacket(); 1395728Sgblack@eecs.umich.edu 1408707Sandreas.hansson@arm.com /** 1418707Sandreas.hansson@arm.com * A TimingCPUPort overrides the default behaviour of the 1428707Sandreas.hansson@arm.com * recvTiming and recvRetry and implements events for the 1438707Sandreas.hansson@arm.com * scheduling of handling of incoming packets in the following 1448707Sandreas.hansson@arm.com * cycle. 1458707Sandreas.hansson@arm.com */ 1468707Sandreas.hansson@arm.com class TimingCPUPort : public CpuPort 1472623SN/A { 1482623SN/A public: 1492623SN/A 1508707Sandreas.hansson@arm.com TimingCPUPort(const std::string& _name, TimingSimpleCPU* _cpu) 1518707Sandreas.hansson@arm.com : CpuPort(_name, _cpu), cpu(_cpu), retryEvent(this) 1522623SN/A { } 1532623SN/A 1542623SN/A protected: 1552623SN/A 1568948Sandreas.hansson@arm.com /** 1578948Sandreas.hansson@arm.com * Snooping a coherence request, do nothing. 1588948Sandreas.hansson@arm.com */ 1598975Sandreas.hansson@arm.com virtual void recvTimingSnoopReq(PacketPtr pkt) { } 1608948Sandreas.hansson@arm.com 1618707Sandreas.hansson@arm.com TimingSimpleCPU* cpu; 1622948Ssaidi@eecs.umich.edu 1632948Ssaidi@eecs.umich.edu struct TickEvent : public Event 1642948Ssaidi@eecs.umich.edu { 1653349Sbinkertn@umich.edu PacketPtr pkt; 1662948Ssaidi@eecs.umich.edu TimingSimpleCPU *cpu; 1672948Ssaidi@eecs.umich.edu 1688707Sandreas.hansson@arm.com TickEvent(TimingSimpleCPU *_cpu) : pkt(NULL), cpu(_cpu) {} 1695336Shines@cs.fsu.edu const char *description() const { return "Timing CPU tick"; } 1703349Sbinkertn@umich.edu void schedule(PacketPtr _pkt, Tick t); 1712948Ssaidi@eecs.umich.edu }; 1722948Ssaidi@eecs.umich.edu 1739087Sandreas.hansson@arm.com EventWrapper<MasterPort, &MasterPort::sendRetry> retryEvent; 1742623SN/A }; 1752623SN/A 1768707Sandreas.hansson@arm.com class IcachePort : public TimingCPUPort 1772623SN/A { 1782623SN/A public: 1792623SN/A 1808707Sandreas.hansson@arm.com IcachePort(TimingSimpleCPU *_cpu) 1818707Sandreas.hansson@arm.com : TimingCPUPort(_cpu->name() + "-iport", _cpu), 1828707Sandreas.hansson@arm.com tickEvent(_cpu) 1832623SN/A { } 1842623SN/A 1852623SN/A protected: 1862623SN/A 1878975Sandreas.hansson@arm.com virtual bool recvTimingResp(PacketPtr pkt); 1882623SN/A 1892657Ssaidi@eecs.umich.edu virtual void recvRetry(); 1902948Ssaidi@eecs.umich.edu 1912948Ssaidi@eecs.umich.edu struct ITickEvent : public TickEvent 1922948Ssaidi@eecs.umich.edu { 1932948Ssaidi@eecs.umich.edu 1942948Ssaidi@eecs.umich.edu ITickEvent(TimingSimpleCPU *_cpu) 1952948Ssaidi@eecs.umich.edu : TickEvent(_cpu) {} 1962948Ssaidi@eecs.umich.edu void process(); 1975336Shines@cs.fsu.edu const char *description() const { return "Timing CPU icache tick"; } 1982948Ssaidi@eecs.umich.edu }; 1992948Ssaidi@eecs.umich.edu 2002948Ssaidi@eecs.umich.edu ITickEvent tickEvent; 2012948Ssaidi@eecs.umich.edu 2022623SN/A }; 2032623SN/A 2048707Sandreas.hansson@arm.com class DcachePort : public TimingCPUPort 2052623SN/A { 2062623SN/A public: 2072623SN/A 2088707Sandreas.hansson@arm.com DcachePort(TimingSimpleCPU *_cpu) 2098707Sandreas.hansson@arm.com : TimingCPUPort(_cpu->name() + "-dport", _cpu), tickEvent(_cpu) 2102623SN/A { } 2112623SN/A 2122623SN/A protected: 2132623SN/A 2148975Sandreas.hansson@arm.com virtual bool recvTimingResp(PacketPtr pkt); 2152623SN/A 2162657Ssaidi@eecs.umich.edu virtual void recvRetry(); 2172948Ssaidi@eecs.umich.edu 2182948Ssaidi@eecs.umich.edu struct DTickEvent : public TickEvent 2192948Ssaidi@eecs.umich.edu { 2202948Ssaidi@eecs.umich.edu DTickEvent(TimingSimpleCPU *_cpu) 2212948Ssaidi@eecs.umich.edu : TickEvent(_cpu) {} 2222948Ssaidi@eecs.umich.edu void process(); 2235336Shines@cs.fsu.edu const char *description() const { return "Timing CPU dcache tick"; } 2242948Ssaidi@eecs.umich.edu }; 2252948Ssaidi@eecs.umich.edu 2262948Ssaidi@eecs.umich.edu DTickEvent tickEvent; 2272948Ssaidi@eecs.umich.edu 2282623SN/A }; 2292623SN/A 2302623SN/A IcachePort icachePort; 2312623SN/A DcachePort dcachePort; 2322623SN/A 2333349Sbinkertn@umich.edu PacketPtr ifetch_pkt; 2343349Sbinkertn@umich.edu PacketPtr dcache_pkt; 2352623SN/A 2363222Sktlim@umich.edu Tick previousTick; 2373170Sstever@eecs.umich.edu 2388850Sandreas.hansson@arm.com protected: 2398850Sandreas.hansson@arm.com 2408850Sandreas.hansson@arm.com /** Return a reference to the data port. */ 2418850Sandreas.hansson@arm.com virtual CpuPort &getDataPort() { return dcachePort; } 2428850Sandreas.hansson@arm.com 2438850Sandreas.hansson@arm.com /** Return a reference to the instruction port. */ 2448850Sandreas.hansson@arm.com virtual CpuPort &getInstPort() { return icachePort; } 2458850Sandreas.hansson@arm.com 2462623SN/A public: 2472623SN/A 2482623SN/A virtual void serialize(std::ostream &os); 2492623SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 2502623SN/A 2512901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *drain_event); 2522798Sktlim@umich.edu virtual void resume(); 2532798Sktlim@umich.edu 2542798Sktlim@umich.edu void switchOut(); 2552623SN/A void takeOverFrom(BaseCPU *oldCPU); 2562623SN/A 2578737Skoansin.tan@gmail.com virtual void activateContext(ThreadID thread_num, int delay); 2588737Skoansin.tan@gmail.com virtual void suspendContext(ThreadID thread_num); 2592623SN/A 2608444Sgblack@eecs.umich.edu Fault readMem(Addr addr, uint8_t *data, unsigned size, unsigned flags); 2617520Sgblack@eecs.umich.edu 2628444Sgblack@eecs.umich.edu Fault writeMem(uint8_t *data, unsigned size, 2638444Sgblack@eecs.umich.edu Addr addr, unsigned flags, uint64_t *res); 2647520Sgblack@eecs.umich.edu 2652623SN/A void fetch(); 2665894Sgblack@eecs.umich.edu void sendFetch(Fault fault, RequestPtr req, ThreadContext *tc); 2673349Sbinkertn@umich.edu void completeIfetch(PacketPtr ); 2685894Sgblack@eecs.umich.edu void completeDataAccess(PacketPtr pkt); 2692644Sstever@eecs.umich.edu void advanceInst(Fault fault); 2704471Sstever@eecs.umich.edu 2715315Sstever@gmail.com /** 2725315Sstever@gmail.com * Print state of address in memory system via PrintReq (for 2735315Sstever@gmail.com * debugging). 2745315Sstever@gmail.com */ 2755315Sstever@gmail.com void printAddr(Addr a); 2765315Sstever@gmail.com 2776973Stjones1@inf.ed.ac.uk /** 2786973Stjones1@inf.ed.ac.uk * Finish a DTB translation. 2796973Stjones1@inf.ed.ac.uk * @param state The DTB translation state. 2806973Stjones1@inf.ed.ac.uk */ 2816973Stjones1@inf.ed.ac.uk void finishTranslation(WholeTranslationState *state); 2826973Stjones1@inf.ed.ac.uk 2832798Sktlim@umich.edu private: 2844471Sstever@eecs.umich.edu 2854471Sstever@eecs.umich.edu typedef EventWrapper<TimingSimpleCPU, &TimingSimpleCPU::fetch> FetchEvent; 2865710Scws3k@cs.virginia.edu FetchEvent fetchEvent; 2874471Sstever@eecs.umich.edu 2885103Ssaidi@eecs.umich.edu struct IprEvent : Event { 2895103Ssaidi@eecs.umich.edu Packet *pkt; 2905103Ssaidi@eecs.umich.edu TimingSimpleCPU *cpu; 2915103Ssaidi@eecs.umich.edu IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t); 2925103Ssaidi@eecs.umich.edu virtual void process(); 2935336Shines@cs.fsu.edu virtual const char *description() const; 2945103Ssaidi@eecs.umich.edu }; 2955103Ssaidi@eecs.umich.edu 2962839Sktlim@umich.edu void completeDrain(); 2972623SN/A}; 2982623SN/A 2992623SN/A#endif // __CPU_SIMPLE_TIMING_HH__ 300