RubyTester.hh revision 11017
16899SN/A/*
29542Sandreas.hansson@arm.com * Copyright (c) 2013 ARM Limited
39542Sandreas.hansson@arm.com * All rights reserved
49542Sandreas.hansson@arm.com *
59542Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
69542Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
79542Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
89542Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
99542Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
109542Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
119542Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
129542Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
139542Sandreas.hansson@arm.com *
146899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
156899SN/A * Copyright (c) 2009 Advanced Micro Devices, Inc.
166899SN/A * All rights reserved.
176899SN/A *
186899SN/A * Redistribution and use in source and binary forms, with or without
196899SN/A * modification, are permitted provided that the following conditions are
206899SN/A * met: redistributions of source code must retain the above copyright
216899SN/A * notice, this list of conditions and the following disclaimer;
226899SN/A * redistributions in binary form must reproduce the above copyright
236899SN/A * notice, this list of conditions and the following disclaimer in the
246899SN/A * documentation and/or other materials provided with the distribution;
256899SN/A * neither the name of the copyright holders nor the names of its
266899SN/A * contributors may be used to endorse or promote products derived from
276899SN/A * this software without specific prior written permission.
286899SN/A *
296899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406899SN/A */
416899SN/A
427053SN/A#ifndef __CPU_RUBYTEST_RUBYTESTER_HH__
437053SN/A#define __CPU_RUBYTEST_RUBYTESTER_HH__
446899SN/A
457055SN/A#include <iostream>
468229Snate@binkert.org#include <string>
477454SN/A#include <vector>
487055SN/A
497632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/CheckTable.hh"
508229Snate@binkert.org#include "mem/mem_object.hh"
518229Snate@binkert.org#include "mem/packet.hh"
5211017Snilay@cs.wisc.edu#include "mem/ruby/common/SubBlock.hh"
5311017Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh"
546899SN/A#include "params/RubyTester.hh"
556899SN/A
567053SN/Aclass RubyTester : public MemObject
576899SN/A{
587053SN/A  public:
598922Swilliam.wang@arm.com    class CpuPort : public MasterPort
607053SN/A    {
617053SN/A      private:
627053SN/A        RubyTester *tester;
6311266SBrad.Beckmann@amd.com
6411266SBrad.Beckmann@amd.com      public:
656899SN/A        //
667053SN/A        // Currently, each instatiation of the RubyTester::CpuPort supports
678932SBrad.Beckmann@amd.com        // only instruction or data requests, not both.  However, for those
688932SBrad.Beckmann@amd.com        // RubyPorts that support both types of requests, separate InstOnly
698932SBrad.Beckmann@amd.com        // and DataOnly CpuPorts will map to that RubyPort
708932SBrad.Beckmann@amd.com
718932SBrad.Beckmann@amd.com        CpuPort(const std::string &_name, RubyTester *_tester, PortID _id)
728932SBrad.Beckmann@amd.com            : MasterPort(_name, _tester, _id), tester(_tester)
7311266SBrad.Beckmann@amd.com        {}
7411266SBrad.Beckmann@amd.com
7511266SBrad.Beckmann@amd.com      protected:
7611266SBrad.Beckmann@amd.com        virtual bool recvTimingResp(PacketPtr pkt);
777053SN/A        virtual void recvReqRetry()
786899SN/A        { panic("%s does not expect a retry\n", name()); }
797053SN/A    };
808975Sandreas.hansson@arm.com
8110713Sandreas.hansson@arm.com    struct SenderState : public Packet::SenderState
828922Swilliam.wang@arm.com    {
837053SN/A        SubBlock subBlock;
846899SN/A
857053SN/A        SenderState(Address addr, int size) : subBlock(addr, size) {}
867053SN/A
879542Sandreas.hansson@arm.com    };
886899SN/A
8911025Snilay@cs.wisc.edu    typedef RubyTesterParams Params;
906899SN/A    RubyTester(const Params *p);
917053SN/A    ~RubyTester();
926899SN/A
937053SN/A    virtual BaseMasterPort &getMasterPort(const std::string &if_name,
947053SN/A                                          PortID idx = InvalidPortID);
957053SN/A
966899SN/A    bool isInstReadableCpuPort(int idx);
9713784Sgabeblack@google.com
9813784Sgabeblack@google.com    MasterPort* getReadableCpuPort(int idx);
996899SN/A    MasterPort* getWritableCpuPort(int idx);
10011266SBrad.Beckmann@amd.com
10111266SBrad.Beckmann@amd.com    virtual void init();
1028950Sandreas.hansson@arm.com
1038932SBrad.Beckmann@amd.com    void wakeup();
1048932SBrad.Beckmann@amd.com
1056899SN/A    void incrementCheckCompletions() { m_checks_completed++; }
1067053SN/A
1076899SN/A    void printStats(std::ostream& out) const {}
1087053SN/A    void clearStats() {}
1096899SN/A    void printConfig(std::ostream& out) const {}
1107053SN/A
1116899SN/A    void print(std::ostream& out) const;
1127055SN/A    bool getCheckFlush() { return m_check_flush; }
1137053SN/A
1147055SN/A    MasterID masterId() { return _masterId; }
1156899SN/A  protected:
1167055SN/A    class CheckStartEvent : public Event
1178184Ssomayeh@cs.wisc.edu    {
1186899SN/A      private:
1198832SAli.Saidi@ARM.com        RubyTester *tester;
1207053SN/A
12112129Sspwilson2@wisc.edu      public:
1227053SN/A        CheckStartEvent(RubyTester *_tester)
1238832SAli.Saidi@ARM.com            : Event(CPU_Tick_Pri), tester(_tester)
1248832SAli.Saidi@ARM.com        {}
1256899SN/A        void process() { tester->wakeup(); }
1267053SN/A        virtual const char *description() const { return "RubyTester tick"; }
1276899SN/A    };
1287053SN/A
1296899SN/A    CheckStartEvent checkStartEvent;
1307053SN/A
1317053SN/A    MasterID _masterId;
1327053SN/A
1336899SN/A  private:
1347053SN/A    void hitCallback(NodeID proc, SubBlock* data);
13510302Snilay@cs.wisc.edu
1366899SN/A    void checkForDeadlock();
1378932SBrad.Beckmann@amd.com
13811061Snilay@cs.wisc.edu    // Private copy constructor and assignment operator
1398950Sandreas.hansson@arm.com    RubyTester(const RubyTester& obj);
1408950Sandreas.hansson@arm.com    RubyTester& operator=(const RubyTester& obj);
14111061Snilay@cs.wisc.edu
1427053SN/A    CheckTable* m_checkTable_ptr;
1438932SBrad.Beckmann@amd.com    std::vector<Cycles> m_last_progress_vector;
1448932SBrad.Beckmann@amd.com
1457053SN/A    int m_num_cpus;
1468184Ssomayeh@cs.wisc.edu    uint64 m_checks_completed;
14711266SBrad.Beckmann@amd.com    std::vector<MasterPort*> writePorts;
14811266SBrad.Beckmann@amd.com    std::vector<MasterPort*> readPorts;
1496899SN/A    uint64 m_checks_to_complete;
1506899SN/A    int m_deadlock_threshold;
1517055SN/A    int m_num_writers;
1527055SN/A    int m_num_readers;
1536899SN/A    int m_wakeup_frequency;
1547053SN/A    bool m_check_flush;
1557055SN/A    int m_num_inst_ports;
1567053SN/A};
1576899SN/A
1586899SN/Ainline std::ostream&
1597053SN/Aoperator<<(std::ostream& out, const RubyTester& obj)
160{
161    obj.print(out);
162    out << std::flush;
163    return out;
164}
165
166#endif // __CPU_RUBYTEST_RUBYTESTER_HH__
167