Atomics bug fix
[gem5.git] / src / mem / rubymem.hh
1 /*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Daniel Sanchez
29 */
30
31 #ifndef __RUBY_MEMORY_HH__
32 #define __RUBY_MEMORY_HH__
33
34 #include <map>
35 #include <vector>
36
37 #include "base/callback.hh"
38 #include "mem/packet.hh"
39 #include "mem/physical.hh"
40 #include "mem/ruby/system/RubyPort.hh"
41 #include "params/RubyMemory.hh"
42
43 class RubyMemory : public PhysicalMemory
44 {
45 public:
46 std::vector<RubyPort *> ruby_ports;
47 class Port : public MemoryPort
48 {
49 friend void ruby_hit_callback(int64_t req_id);
50
51 RubyMemory *ruby_mem;
52
53 public:
54 Port(const std::string &_name, RubyMemory *_memory);
55 void sendTiming(PacketPtr pkt);
56
57 protected:
58 virtual bool recvTiming(PacketPtr pkt);
59 };
60
61 class RubyEvent : public Event
62 {
63 RubyMemory *ruby_ptr;
64 public:
65 RubyEvent(RubyMemory *p)
66 : Event(), ruby_ptr(p) {}
67
68 virtual void process() { ruby_ptr->tick(); }
69
70 virtual const char *description() const { return "ruby tick"; }
71 };
72
73 struct SenderState : public Packet::SenderState
74 {
75 Port *port;
76 Packet::SenderState *saved;
77
78 SenderState(Port *p, Packet::SenderState *s = NULL)
79 : port(p), saved(s)
80 {}
81 };
82
83 private:
84 // prevent copying of a RubyMemory object
85 RubyMemory(const RubyMemory &specmem);
86 const RubyMemory &operator=(const RubyMemory &specmem);
87
88 RubyEvent* rubyTickEvent;
89
90 public:
91 typedef RubyMemoryParams Params;
92 RubyMemory(const Params *p);
93 virtual ~RubyMemory();
94
95 const Params *
96 params() const
97 {
98 return safe_cast<const Params *>(_params);
99 }
100
101 public:
102 virtual ::Port *getPort(const std::string &if_name, int idx = -1);
103 void virtual init();
104
105 //Ruby-related specifics
106 void printConfigStats(); //dsm: Maybe this function should
107 //disappear once the configuration
108 //options change & M5 determines the
109 //stats file to use
110
111 void hitCallback(PacketPtr pkt, Port *port);
112
113 void printStats(std::ostream & out) const;
114 void clearStats();
115 void printConfig(std::ostream & out) const;
116
117 void tick();
118
119 private:
120 Tick ruby_clock;
121 Tick ruby_phase;
122
123 public:
124 static std::map<int64_t, PacketPtr> pending_requests;
125 };
126
127 void ruby_hit_callback(int64_t);
128
129 class RubyExitCallback : public Callback
130 {
131 private:
132 RubyMemory* ruby;
133
134 public:
135 /**
136 * virtualize the destructor to make sure that the correct one
137 * gets called.
138 */
139
140 virtual ~RubyExitCallback() {};
141
142 RubyExitCallback(RubyMemory* rm) {ruby=rm;};
143
144 /**
145 * virtual process function that is invoked when the callback
146 * queue is executed.
147 */
148 virtual void process() {ruby->printConfigStats(); /*delete ruby; was doing double delete...*/};
149 };
150
151
152 #endif //__RUBY_MEMORY_HH__
153