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