RubyTester.hh revision 8854
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 <iostream>
34#include <string>
35#include <vector>
36
37#include "cpu/testers/rubytest/CheckTable.hh"
38#include "mem/ruby/common/Global.hh"
39#include "mem/ruby/common/SubBlock.hh"
40#include "mem/ruby/system/RubyPort.hh"
41#include "mem/mem_object.hh"
42#include "mem/packet.hh"
43#include "params/RubyTester.hh"
44
45class RubyTester : public MemObject
46{
47  public:
48    class CpuPort : public Port
49    {
50      private:
51        RubyTester *tester;
52
53      public:
54        CpuPort(const std::string &_name, RubyTester *_tester, int _idx)
55            : Port(_name, _tester), tester(_tester), idx(_idx)
56        {}
57
58        int idx;
59
60      protected:
61        virtual bool recvTiming(PacketPtr pkt);
62        virtual Tick recvAtomic(PacketPtr pkt);
63        virtual void recvFunctional(PacketPtr pkt) { }
64        virtual void recvRangeChange() { }
65    };
66
67    struct SenderState : public Packet::SenderState
68    {
69        SubBlock* subBlock;
70        Packet::SenderState *saved;
71
72        SenderState(Address addr, int size,
73                    Packet::SenderState *sender_state = NULL)
74            : saved(sender_state)
75        {
76            subBlock = new SubBlock(addr, size);
77        }
78
79        ~SenderState()
80        {
81            delete subBlock;
82        }
83    };
84
85    typedef RubyTesterParams Params;
86    RubyTester(const Params *p);
87    ~RubyTester();
88
89    virtual Port *getPort(const std::string &if_name, int idx = -1);
90
91    Port* getCpuPort(int idx);
92
93    virtual void init();
94
95    void wakeup();
96
97    void incrementCheckCompletions() { m_checks_completed++; }
98
99    void printStats(std::ostream& out) const {}
100    void clearStats() {}
101    void printConfig(std::ostream& out) const {}
102
103    void print(std::ostream& out) const;
104    bool getCheckFlush() { return m_check_flush; }
105
106    MasterID masterId() { return _masterId; }
107  protected:
108    class CheckStartEvent : public Event
109    {
110      private:
111        RubyTester *tester;
112
113      public:
114        CheckStartEvent(RubyTester *_tester)
115            : Event(CPU_Tick_Pri), tester(_tester)
116        {}
117        void process() { tester->wakeup(); }
118        virtual const char *description() const { return "RubyTester tick"; }
119    };
120
121    CheckStartEvent checkStartEvent;
122
123    MasterID _masterId;
124
125  private:
126    void hitCallback(NodeID proc, SubBlock* data);
127
128    void checkForDeadlock();
129
130    // Private copy constructor and assignment operator
131    RubyTester(const RubyTester& obj);
132    RubyTester& operator=(const RubyTester& obj);
133
134    CheckTable* m_checkTable_ptr;
135    std::vector<Time> m_last_progress_vector;
136
137    uint64 m_checks_completed;
138    std::vector<CpuPort*> ports;
139    uint64 m_checks_to_complete;
140    int m_deadlock_threshold;
141    int m_num_cpu_sequencers;
142    int m_wakeup_frequency;
143    bool m_check_flush;
144};
145
146inline std::ostream&
147operator<<(std::ostream& out, const RubyTester& obj)
148{
149    obj.print(out);
150    out << std::flush;
151    return out;
152}
153
154#endif // __CPU_RUBYTEST_RUBYTESTER_HH__
155