timing.hh revision 5728
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
362623SN/A#include "params/TimingSimpleCPU.hh"
375529Snate@binkert.org
385529Snate@binkert.orgclass TimingSimpleCPU : public BaseSimpleCPU
392623SN/A{
402623SN/A  public:
412623SN/A
422623SN/A    TimingSimpleCPU(TimingSimpleCPUParams * params);
435529Snate@binkert.org    virtual ~TimingSimpleCPU();
442623SN/A
452623SN/A    virtual void init();
462623SN/A
472623SN/A  public:
482623SN/A    Event *drainEvent;
492839Sktlim@umich.edu
502798Sktlim@umich.edu  private:
512623SN/A
522623SN/A    /*
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        SplitMainSenderState()
695728Sgblack@eecs.umich.edu        {
705728Sgblack@eecs.umich.edu            fragments[0] = NULL;
715728Sgblack@eecs.umich.edu            fragments[1] = NULL;
725728Sgblack@eecs.umich.edu        }
735728Sgblack@eecs.umich.edu
745728Sgblack@eecs.umich.edu        int
755728Sgblack@eecs.umich.edu        getPendingFragment()
765728Sgblack@eecs.umich.edu        {
775728Sgblack@eecs.umich.edu            if (fragments[0]) {
785728Sgblack@eecs.umich.edu                return 0;
795728Sgblack@eecs.umich.edu            } else if (fragments[1]) {
805728Sgblack@eecs.umich.edu                return 1;
815728Sgblack@eecs.umich.edu            } else {
825728Sgblack@eecs.umich.edu                return -1;
835728Sgblack@eecs.umich.edu            }
845728Sgblack@eecs.umich.edu        }
855728Sgblack@eecs.umich.edu    };
865728Sgblack@eecs.umich.edu
875728Sgblack@eecs.umich.edu    class SplitFragmentSenderState : public Packet::SenderState
885728Sgblack@eecs.umich.edu    {
895728Sgblack@eecs.umich.edu      public:
905728Sgblack@eecs.umich.edu        SplitFragmentSenderState(PacketPtr _bigPkt, int _index) :
915728Sgblack@eecs.umich.edu            bigPkt(_bigPkt), index(_index)
925728Sgblack@eecs.umich.edu        {}
935728Sgblack@eecs.umich.edu        PacketPtr bigPkt;
945728Sgblack@eecs.umich.edu        int index;
955728Sgblack@eecs.umich.edu
965728Sgblack@eecs.umich.edu        void
975728Sgblack@eecs.umich.edu        clearFromParent()
985728Sgblack@eecs.umich.edu        {
995728Sgblack@eecs.umich.edu            SplitMainSenderState * main_send_state =
1005894Sgblack@eecs.umich.edu                dynamic_cast<SplitMainSenderState *>(bigPkt->senderState);
1015894Sgblack@eecs.umich.edu            main_send_state->fragments[index] = NULL;
1025894Sgblack@eecs.umich.edu        }
1035894Sgblack@eecs.umich.edu    };
1045894Sgblack@eecs.umich.edu
1055894Sgblack@eecs.umich.edu    bool handleReadPacket(PacketPtr pkt);
1066023Snate@binkert.org    // This function always implicitly uses dcache_pkt.
1076023Snate@binkert.org    bool handleWritePacket();
1085894Sgblack@eecs.umich.edu
1095894Sgblack@eecs.umich.edu    class CpuPort : public Port
1106023Snate@binkert.org    {
1117944SGiacomo.Gabrielli@arm.com      protected:
1127945SAli.Saidi@ARM.com        TimingSimpleCPU *cpu;
1137945SAli.Saidi@ARM.com        Tick lat;
1147945SAli.Saidi@ARM.com
1157945SAli.Saidi@ARM.com      public:
1167944SGiacomo.Gabrielli@arm.com
1177944SGiacomo.Gabrielli@arm.com        CpuPort(const std::string &_name, TimingSimpleCPU *_cpu, Tick _lat)
1186023Snate@binkert.org            : Port(_name, _cpu), cpu(_cpu), lat(_lat)
1196023Snate@binkert.org        { }
1205894Sgblack@eecs.umich.edu
1215894Sgblack@eecs.umich.edu        bool snoopRangeSent;
1225894Sgblack@eecs.umich.edu
1235894Sgblack@eecs.umich.edu      protected:
1245894Sgblack@eecs.umich.edu
1255894Sgblack@eecs.umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1266973Stjones1@inf.ed.ac.uk
1276973Stjones1@inf.ed.ac.uk        virtual void recvFunctional(PacketPtr pkt);
1286973Stjones1@inf.ed.ac.uk
1295894Sgblack@eecs.umich.edu        virtual void recvStatusChange(Status status);
1305894Sgblack@eecs.umich.edu
1315894Sgblack@eecs.umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1325894Sgblack@eecs.umich.edu                                            bool &snoop)
1335894Sgblack@eecs.umich.edu        { resp.clear(); snoop = false; }
1345894Sgblack@eecs.umich.edu
1355894Sgblack@eecs.umich.edu        struct TickEvent : public Event
1365744Sgblack@eecs.umich.edu        {
1375728Sgblack@eecs.umich.edu            PacketPtr pkt;
1385728Sgblack@eecs.umich.edu            TimingSimpleCPU *cpu;
1395728Sgblack@eecs.umich.edu
1405728Sgblack@eecs.umich.edu            TickEvent(TimingSimpleCPU *_cpu) : cpu(_cpu) {}
1412623SN/A            const char *description() const { return "Timing CPU tick"; }
1422623SN/A            void schedule(PacketPtr _pkt, Tick t);
1432623SN/A        };
1442623SN/A
1452948Ssaidi@eecs.umich.edu    };
1462623SN/A
1472623SN/A    class IcachePort : public CpuPort
1482623SN/A    {
1492948Ssaidi@eecs.umich.edu      public:
1507745SAli.Saidi@ARM.com
1512623SN/A        IcachePort(TimingSimpleCPU *_cpu, Tick _lat)
1522623SN/A            : CpuPort(_cpu->name() + "-iport", _cpu, _lat), tickEvent(_cpu)
1533647Srdreslin@umich.edu        { }
1543647Srdreslin@umich.edu
1552623SN/A      protected:
1562623SN/A
1573349Sbinkertn@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1582623SN/A
1593349Sbinkertn@umich.edu        virtual void recvRetry();
1602623SN/A
1612623SN/A        struct ITickEvent : public TickEvent
1622623SN/A        {
1632623SN/A
1644475Sstever@eecs.umich.edu            ITickEvent(TimingSimpleCPU *_cpu)
1654475Sstever@eecs.umich.edu                : TickEvent(_cpu) {}
1662948Ssaidi@eecs.umich.edu            void process();
1672948Ssaidi@eecs.umich.edu            const char *description() const { return "Timing CPU icache tick"; }
1682948Ssaidi@eecs.umich.edu        };
1693349Sbinkertn@umich.edu
1702948Ssaidi@eecs.umich.edu        ITickEvent tickEvent;
1717745SAli.Saidi@ARM.com
1722948Ssaidi@eecs.umich.edu    };
1735606Snate@binkert.org
1745336Shines@cs.fsu.edu    class DcachePort : public CpuPort
1753349Sbinkertn@umich.edu    {
1762948Ssaidi@eecs.umich.edu      public:
1772948Ssaidi@eecs.umich.edu
1787745SAli.Saidi@ARM.com        DcachePort(TimingSimpleCPU *_cpu, Tick _lat)
1792623SN/A            : CpuPort(_cpu->name() + "-dport", _cpu, _lat), tickEvent(_cpu)
1802623SN/A        { }
1812623SN/A
1822623SN/A        virtual void setPeer(Port *port);
1832623SN/A
1842623SN/A      protected:
1852948Ssaidi@eecs.umich.edu
1862948Ssaidi@eecs.umich.edu        virtual bool recvTiming(PacketPtr pkt);
1872623SN/A
1882623SN/A        virtual void recvRetry();
1892623SN/A
1902623SN/A        struct DTickEvent : public TickEvent
1913349Sbinkertn@umich.edu        {
1922623SN/A            DTickEvent(TimingSimpleCPU *_cpu)
1932657Ssaidi@eecs.umich.edu                : TickEvent(_cpu) {}
1942948Ssaidi@eecs.umich.edu            void process();
1952948Ssaidi@eecs.umich.edu            const char *description() const { return "Timing CPU dcache tick"; }
1962948Ssaidi@eecs.umich.edu        };
1972948Ssaidi@eecs.umich.edu
1982948Ssaidi@eecs.umich.edu        DTickEvent tickEvent;
1992948Ssaidi@eecs.umich.edu
2002948Ssaidi@eecs.umich.edu    };
2015336Shines@cs.fsu.edu
2022948Ssaidi@eecs.umich.edu    IcachePort icachePort;
2032948Ssaidi@eecs.umich.edu    DcachePort dcachePort;
2042948Ssaidi@eecs.umich.edu
2052948Ssaidi@eecs.umich.edu    PacketPtr ifetch_pkt;
2062623SN/A    PacketPtr dcache_pkt;
2072623SN/A
2082623SN/A    Tick previousTick;
2092623SN/A
2102623SN/A  public:
2112623SN/A
2122948Ssaidi@eecs.umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
2132948Ssaidi@eecs.umich.edu
2142623SN/A    virtual void serialize(std::ostream &os);
2152623SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
2164192Sktlim@umich.edu
2174192Sktlim@umich.edu    virtual unsigned int drain(Event *drain_event);
2182623SN/A    virtual void resume();
2192623SN/A
2203349Sbinkertn@umich.edu    void switchOut();
2212623SN/A    void takeOverFrom(BaseCPU *oldCPU);
2222657Ssaidi@eecs.umich.edu
2232948Ssaidi@eecs.umich.edu    virtual void activateContext(int thread_num, int delay);
2242948Ssaidi@eecs.umich.edu    virtual void suspendContext(int thread_num);
2252948Ssaidi@eecs.umich.edu
2262948Ssaidi@eecs.umich.edu    template <class T>
2272948Ssaidi@eecs.umich.edu    Fault read(Addr addr, T &data, unsigned flags);
2282948Ssaidi@eecs.umich.edu
2295336Shines@cs.fsu.edu    Fault translateDataReadAddr(Addr vaddr, Addr &paddr,
2302948Ssaidi@eecs.umich.edu            int size, unsigned flags);
2312948Ssaidi@eecs.umich.edu
2322948Ssaidi@eecs.umich.edu    template <class T>
2332948Ssaidi@eecs.umich.edu    Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
2342623SN/A
2352623SN/A    Fault translateDataWriteAddr(Addr vaddr, Addr &paddr,
2362623SN/A            int size, unsigned flags);
2372623SN/A
2382623SN/A    void fetch();
2393349Sbinkertn@umich.edu    void completeIfetch(PacketPtr );
2403349Sbinkertn@umich.edu    void completeDataAccess(PacketPtr );
2412623SN/A    void advanceInst(Fault fault);
2423222Sktlim@umich.edu
2433170Sstever@eecs.umich.edu    /**
2442623SN/A     * Print state of address in memory system via PrintReq (for
2452623SN/A     * debugging).
2462856Srdreslin@umich.edu     */
2472856Srdreslin@umich.edu    void printAddr(Addr a);
2482623SN/A
2492623SN/A  private:
2502623SN/A
2512901Ssaidi@eecs.umich.edu    typedef EventWrapper<TimingSimpleCPU, &TimingSimpleCPU::fetch> FetchEvent;
2522798Sktlim@umich.edu    FetchEvent fetchEvent;
2532798Sktlim@umich.edu
2542798Sktlim@umich.edu    struct IprEvent : Event {
2552623SN/A        Packet *pkt;
2562623SN/A        TimingSimpleCPU *cpu;
2572623SN/A        IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t);
2582623SN/A        virtual void process();
2592623SN/A        virtual const char *description() const;
2602623SN/A    };
2612623SN/A
2622623SN/A    void completeDrain();
2637520Sgblack@eecs.umich.edu};
2647520Sgblack@eecs.umich.edu
2652623SN/A#endif // __CPU_SIMPLE_TIMING_HH__
2662623SN/A