RubyTester.hh revision 7053
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __CPU_RUBYTEST_RUBYTESTER_HH__
31#define __CPU_RUBYTEST_RUBYTESTER_HH__
32
33#include "cpu/rubytest/CheckTable.hh"
34#include "mem/mem_object.hh"
35#include "mem/packet.hh"
36#include "mem/ruby/common/DataBlock.hh"
37#include "mem/ruby/common/Global.hh"
38#include "mem/ruby/common/SubBlock.hh"
39#include "mem/ruby/system/RubyPort.hh"
40#include "params/RubyTester.hh"
41
42class RubyTester : public MemObject
43{
44  public:
45    class CpuPort : public SimpleTimingPort
46    {
47      private:
48        RubyTester *tester;
49
50      public:
51        CpuPort(const std::string &_name, RubyTester *_tester, int _idx)
52            : SimpleTimingPort(_name, _tester), tester(_tester), idx(_idx)
53        {}
54
55        int idx;
56
57      protected:
58        virtual bool recvTiming(PacketPtr pkt);
59        virtual Tick recvAtomic(PacketPtr pkt);
60    };
61
62    struct SenderState : public Packet::SenderState
63    {
64        SubBlock* subBlock;
65        Packet::SenderState *saved;
66
67        SenderState(Address addr, int size,
68                    Packet::SenderState *sender_state = NULL)
69            : saved(sender_state)
70        {
71            subBlock = new SubBlock(addr, size);
72        }
73
74        ~SenderState()
75        {
76            delete subBlock;
77        }
78    };
79
80    typedef RubyTesterParams Params;
81    RubyTester(const Params *p);
82    ~RubyTester();
83
84    virtual Port *getPort(const std::string &if_name, int idx = -1);
85
86    Port* getCpuPort(int idx);
87
88    virtual void init();
89
90    void wakeup();
91
92    void incrementCheckCompletions() { m_checks_completed++; }
93
94    void printStats(ostream& out) const {}
95    void clearStats() {}
96    void printConfig(ostream& out) const {}
97
98    void print(ostream& out) const;
99
100  protected:
101    class CheckStartEvent : public Event
102    {
103      private:
104        RubyTester *tester;
105
106      public:
107        CheckStartEvent(RubyTester *_tester)
108            : Event(CPU_Tick_Pri), tester(_tester)
109        {}
110        void process() { tester->wakeup(); }
111        virtual const char *description() const { return "RubyTester tick"; }
112    };
113
114    CheckStartEvent checkStartEvent;
115
116  private:
117    void hitCallback(NodeID proc, SubBlock* data);
118
119    void checkForDeadlock();
120
121    // Private copy constructor and assignment operator
122    RubyTester(const RubyTester& obj);
123    RubyTester& operator=(const RubyTester& obj);
124
125    CheckTable* m_checkTable_ptr;
126    Vector<Time> m_last_progress_vector;
127
128    uint64 m_checks_completed;
129    std::vector<CpuPort*> ports;
130    uint64 m_checks_to_complete;
131    int m_deadlock_threshold;
132    int m_num_cpu_sequencers;
133    int m_wakeup_frequency;
134};
135
136inline ostream&
137operator<<(ostream& out, const RubyTester& obj)
138{
139    obj.print(out);
140    out << flush;
141    return out;
142}
143
144#endif // __CPU_RUBYTEST_RUBYTESTER_HH__
145