memtest.hh revision 5034
11689SN/A/*
28707Sandreas.hansson@arm.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
37849SAli.Saidi@ARM.com * All rights reserved.
47849SAli.Saidi@ARM.com *
57849SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
67849SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
77849SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
87849SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
97849SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
107849SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
117849SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
127849SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
137849SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
142329SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271689SN/A *
281689SN/A * Authors: Erik Hallnor
291689SN/A *          Steve Reinhardt
301689SN/A */
311689SN/A
321689SN/A#ifndef __CPU_MEMTEST_MEMTEST_HH__
331689SN/A#define __CPU_MEMTEST_MEMTEST_HH__
341689SN/A
351689SN/A#include <set>
361689SN/A
371689SN/A#include "base/statistics.hh"
381689SN/A#include "params/MemTest.hh"
392665Ssaidi@eecs.umich.edu#include "sim/eventq.hh"
402665Ssaidi@eecs.umich.edu#include "sim/sim_exit.hh"
412756Sksewell@umich.edu#include "sim/sim_object.hh"
421689SN/A#include "sim/stats.hh"
431689SN/A#include "mem/mem_object.hh"
442292SN/A#include "mem/port.hh"
452292SN/A
461060SN/Aclass Packet;
479020Sgblack@eecs.umich.educlass MemTest : public MemObject
482669Sktlim@umich.edu{
491461SN/A  public:
506658Snate@binkert.org    typedef MemTestParams Params;
511060SN/A    MemTest(const Params *p);
528229Snate@binkert.org
537849SAli.Saidi@ARM.com    virtual void init();
543348Sbinkertn@umich.edu
552669Sktlim@umich.edu    // register statistics
561461SN/A    virtual void regStats();
571060SN/A
588737Skoansin.tan@gmail.com    inline Tick cycles(int numCycles) const { return numCycles; }
595529Snate@binkert.org
601060SN/A    // main simulation loop (one cycle)
612329SN/A    void tick();
622329SN/A
632329SN/A    virtual Port *getPort(const std::string &if_name, int idx = -1);
642329SN/A
652348SN/A  protected:
662329SN/A    class TickEvent : public Event
671060SN/A    {
681060SN/A      private:
692292SN/A        MemTest *cpu;
701060SN/A      public:
711060SN/A        TickEvent(MemTest *c)
721060SN/A            : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {}
731061SN/A        void process() {cpu->tick();}
741060SN/A        virtual const char *description() { return "MemTest tick"; }
751061SN/A    };
762733Sktlim@umich.edu
771060SN/A    TickEvent tickEvent;
782292SN/A
791061SN/A    class CpuPort : public Port
801061SN/A    {
811061SN/A        MemTest *memtest;
821060SN/A
831060SN/A      public:
842107SN/A
852292SN/A        CpuPort(const std::string &_name, MemTest *_memtest)
862632Sstever@eecs.umich.edu            : Port(_name, _memtest), memtest(_memtest)
877849SAli.Saidi@ARM.com        { }
887849SAli.Saidi@ARM.com
897849SAli.Saidi@ARM.com        bool snoopRangeSent;
907849SAli.Saidi@ARM.com
917849SAli.Saidi@ARM.com      protected:
927849SAli.Saidi@ARM.com
937849SAli.Saidi@ARM.com        virtual bool recvTiming(PacketPtr pkt);
947849SAli.Saidi@ARM.com
957849SAli.Saidi@ARM.com        virtual Tick recvAtomic(PacketPtr pkt);
967849SAli.Saidi@ARM.com
977849SAli.Saidi@ARM.com        virtual void recvFunctional(PacketPtr pkt);
987944SGiacomo.Gabrielli@arm.com
997944SGiacomo.Gabrielli@arm.com        virtual void recvStatusChange(Status status);
1007944SGiacomo.Gabrielli@arm.com
1017944SGiacomo.Gabrielli@arm.com        virtual void recvRetry();
1027849SAli.Saidi@ARM.com
1037849SAli.Saidi@ARM.com        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1047849SAli.Saidi@ARM.com                                            bool &snoop)
1057849SAli.Saidi@ARM.com        { resp.clear(); snoop = false; }
1067849SAli.Saidi@ARM.com    };
1077849SAli.Saidi@ARM.com
1087849SAli.Saidi@ARM.com    CpuPort cachePort;
1097849SAli.Saidi@ARM.com    CpuPort funcPort;
1102935Sksewell@umich.edu
1118462Sgeoffrey.blake@arm.com    bool snoopRangeSent;
1128462Sgeoffrey.blake@arm.com
1138462Sgeoffrey.blake@arm.com    class MemTestSenderState : public Packet::SenderState
1148462Sgeoffrey.blake@arm.com    {
1158462Sgeoffrey.blake@arm.com      public:
1168462Sgeoffrey.blake@arm.com        /** Constructor. */
1178462Sgeoffrey.blake@arm.com        MemTestSenderState(uint8_t *_data)
1188462Sgeoffrey.blake@arm.com            : data(_data)
1198462Sgeoffrey.blake@arm.com        { }
1208462Sgeoffrey.blake@arm.com
1218462Sgeoffrey.blake@arm.com        // Hold onto data pointer
1228462Sgeoffrey.blake@arm.com        uint8_t *data;
1238462Sgeoffrey.blake@arm.com    };
1248462Sgeoffrey.blake@arm.com
1258462Sgeoffrey.blake@arm.com    PacketPtr retryPkt;
1268462Sgeoffrey.blake@arm.com
1278462Sgeoffrey.blake@arm.com    bool accessRetry;
1288462Sgeoffrey.blake@arm.com
1298462Sgeoffrey.blake@arm.com    unsigned size;		// size of testing memory region
1308462Sgeoffrey.blake@arm.com
1318462Sgeoffrey.blake@arm.com    unsigned percentReads;	// target percentage of read accesses
1328462Sgeoffrey.blake@arm.com    unsigned percentFunctional;	// target percentage of functional accesses
1338462Sgeoffrey.blake@arm.com    unsigned percentUncacheable;
1348462Sgeoffrey.blake@arm.com
1358462Sgeoffrey.blake@arm.com    int id;
1368462Sgeoffrey.blake@arm.com
1378462Sgeoffrey.blake@arm.com    std::set<unsigned> outstandingAddrs;
1388462Sgeoffrey.blake@arm.com
1398462Sgeoffrey.blake@arm.com    unsigned blockSize;
1408462Sgeoffrey.blake@arm.com
1418462Sgeoffrey.blake@arm.com    Addr blockAddrMask;
1428462Sgeoffrey.blake@arm.com
1438462Sgeoffrey.blake@arm.com    Addr blockAddr(Addr addr)
1448462Sgeoffrey.blake@arm.com    {
1458462Sgeoffrey.blake@arm.com        return (addr & ~blockAddrMask);
1468462Sgeoffrey.blake@arm.com    }
1478462Sgeoffrey.blake@arm.com
1488462Sgeoffrey.blake@arm.com    Addr traceBlockAddr;
1498462Sgeoffrey.blake@arm.com
1501060SN/A    Addr baseAddr1;		// fix this to option
1512329SN/A    Addr baseAddr2;		// fix this to option
1522329SN/A    Addr uncacheAddr;
1532292SN/A
1542292SN/A    unsigned progressInterval;	// frequency of progress reports
1552292SN/A    Tick nextProgressMessage;	// access # for next progress report
1562292SN/A
1572292SN/A    unsigned percentSourceUnaligned;
1582292SN/A    unsigned percentDestUnaligned;
1592292SN/A
1602292SN/A    Tick noResponseCycles;
1611060SN/A
1621060SN/A    uint64_t numReads;
1631060SN/A    uint64_t maxLoads;
1641060SN/A
1652292SN/A    bool atomic;
1662292SN/A
1672292SN/A    Stats::Scalar<> numReadsStat;
1682307SN/A    Stats::Scalar<> numWritesStat;
1697849SAli.Saidi@ARM.com    Stats::Scalar<> numCopiesStat;
1702669Sktlim@umich.edu
1712696Sktlim@umich.edu    // called by MemCompleteEvent::process()
1728460SAli.Saidi@ARM.com    void completeRequest(PacketPtr pkt);
1738460SAli.Saidi@ARM.com
1741060SN/A    void sendPkt(PacketPtr pkt);
1751060SN/A
1762292SN/A    void doRetry();
1772292SN/A
1782292SN/A    friend class MemCompleteEvent;
1792292SN/A};
1802292SN/A
1812292SN/A#endif // __CPU_MEMTEST_MEMTEST_HH__
1822292SN/A
1832292SN/A
1841060SN/A
1852292SN/A