RubyDirectedTester.hh revision 7454
16657Snate@binkert.org/*
26657Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36657Snate@binkert.org * Copyright (c) 2009 Advanced Micro Devices, Inc.
46657Snate@binkert.org * All rights reserved.
56657Snate@binkert.org *
66657Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76657Snate@binkert.org * modification, are permitted provided that the following conditions are
86657Snate@binkert.org * met: redistributions of source code must retain the above copyright
96657Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106657Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126657Snate@binkert.org * documentation and/or other materials provided with the distribution;
136657Snate@binkert.org * neither the name of the copyright holders nor the names of its
146657Snate@binkert.org * contributors may be used to endorse or promote products derived from
156657Snate@binkert.org * this software without specific prior written permission.
166657Snate@binkert.org *
176657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286657Snate@binkert.org */
296657Snate@binkert.org
306657Snate@binkert.org#ifndef __CPU_RUBYTEST_RUBYTESTER_HH__
316657Snate@binkert.org#define __CPU_RUBYTEST_RUBYTESTER_HH__
326657Snate@binkert.org
336657Snate@binkert.org#include <iostream>
346657Snate@binkert.org#include <vector>
356657Snate@binkert.org#include <string>
366657Snate@binkert.org
376657Snate@binkert.org#include "cpu/rubytest/CheckTable.hh"
386657Snate@binkert.org#include "mem/mem_object.hh"
396657Snate@binkert.org#include "mem/packet.hh"
406657Snate@binkert.org#include "mem/ruby/common/DataBlock.hh"
416657Snate@binkert.org#include "mem/ruby/common/Global.hh"
426657Snate@binkert.org#include "mem/ruby/common/SubBlock.hh"
436657Snate@binkert.org#include "mem/ruby/system/RubyPort.hh"
446657Snate@binkert.org#include "params/RubyTester.hh"
456657Snate@binkert.org
466657Snate@binkert.orgclass RubyTester : public MemObject
476657Snate@binkert.org{
486657Snate@binkert.org  public:
496657Snate@binkert.org    class CpuPort : public SimpleTimingPort
506657Snate@binkert.org    {
516657Snate@binkert.org      private:
526657Snate@binkert.org        RubyTester *tester;
536657Snate@binkert.org
546657Snate@binkert.org      public:
556657Snate@binkert.org        CpuPort(const std::string &_name, RubyTester *_tester, int _idx)
566657Snate@binkert.org            : SimpleTimingPort(_name, _tester), tester(_tester), idx(_idx)
576657Snate@binkert.org        {}
586657Snate@binkert.org
596657Snate@binkert.org        int idx;
606657Snate@binkert.org
616657Snate@binkert.org      protected:
626657Snate@binkert.org        virtual bool recvTiming(PacketPtr pkt);
636657Snate@binkert.org        virtual Tick recvAtomic(PacketPtr pkt);
646657Snate@binkert.org    };
656657Snate@binkert.org
666657Snate@binkert.org    struct SenderState : public Packet::SenderState
676657Snate@binkert.org    {
686657Snate@binkert.org        SubBlock* subBlock;
696657Snate@binkert.org        Packet::SenderState *saved;
706657Snate@binkert.org
716657Snate@binkert.org        SenderState(Address addr, int size,
726657Snate@binkert.org                    Packet::SenderState *sender_state = NULL)
736657Snate@binkert.org            : saved(sender_state)
746657Snate@binkert.org        {
756657Snate@binkert.org            subBlock = new SubBlock(addr, size);
766657Snate@binkert.org        }
776657Snate@binkert.org
786657Snate@binkert.org        ~SenderState()
796657Snate@binkert.org        {
806657Snate@binkert.org            delete subBlock;
816657Snate@binkert.org        }
826657Snate@binkert.org    };
836657Snate@binkert.org
846657Snate@binkert.org    typedef RubyTesterParams Params;
856657Snate@binkert.org    RubyTester(const Params *p);
866657Snate@binkert.org    ~RubyTester();
876657Snate@binkert.org
886657Snate@binkert.org    virtual Port *getPort(const std::string &if_name, int idx = -1);
896657Snate@binkert.org
906657Snate@binkert.org    Port* getCpuPort(int idx);
916657Snate@binkert.org
926657Snate@binkert.org    virtual void init();
936657Snate@binkert.org
946657Snate@binkert.org    void wakeup();
956657Snate@binkert.org
966657Snate@binkert.org    void incrementCheckCompletions() { m_checks_completed++; }
976657Snate@binkert.org
986657Snate@binkert.org    void printStats(std::ostream& out) const {}
996657Snate@binkert.org    void clearStats() {}
1006657Snate@binkert.org    void printConfig(std::ostream& out) const {}
1016657Snate@binkert.org
1026657Snate@binkert.org    void print(std::ostream& out) const;
1036657Snate@binkert.org
1046657Snate@binkert.org  protected:
1056657Snate@binkert.org    class CheckStartEvent : public Event
1066657Snate@binkert.org    {
1076657Snate@binkert.org      private:
1086657Snate@binkert.org        RubyTester *tester;
1096657Snate@binkert.org
1106657Snate@binkert.org      public:
1116657Snate@binkert.org        CheckStartEvent(RubyTester *_tester)
1126657Snate@binkert.org            : Event(CPU_Tick_Pri), tester(_tester)
1136657Snate@binkert.org        {}
1146657Snate@binkert.org        void process() { tester->wakeup(); }
1156657Snate@binkert.org        virtual const char *description() const { return "RubyTester tick"; }
1166657Snate@binkert.org    };
1176657Snate@binkert.org
1186657Snate@binkert.org    CheckStartEvent checkStartEvent;
1196657Snate@binkert.org
1206657Snate@binkert.org  private:
1216657Snate@binkert.org    void hitCallback(NodeID proc, SubBlock* data);
1226657Snate@binkert.org
1236657Snate@binkert.org    void checkForDeadlock();
1246657Snate@binkert.org
1256657Snate@binkert.org    // Private copy constructor and assignment operator
1266657Snate@binkert.org    RubyTester(const RubyTester& obj);
1276657Snate@binkert.org    RubyTester& operator=(const RubyTester& obj);
128
129    CheckTable* m_checkTable_ptr;
130    std::vector<Time> m_last_progress_vector;
131
132    uint64 m_checks_completed;
133    std::vector<CpuPort*> ports;
134    uint64 m_checks_to_complete;
135    int m_deadlock_threshold;
136    int m_num_cpu_sequencers;
137    int m_wakeup_frequency;
138};
139
140inline std::ostream&
141operator<<(std::ostream& out, const RubyTester& obj)
142{
143    obj.print(out);
144    out << std::flush;
145    return out;
146}
147
148#endif // __CPU_RUBYTEST_RUBYTESTER_HH__
149