WireBuffer.hh revision 8191
1/*
2 * Copyright (c) 2010 Advanced Micro Devices, Inc.
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 * Author: Lisa Hsu
29 *
30 */
31
32#ifndef __MEM_RUBY_SYSTEM_WIREBUFFER_HH__
33#define __MEM_RUBY_SYSTEM_WIREBUFFER_HH__
34
35#include <iostream>
36#include <vector>
37#include <string>
38
39#include "mem/ruby/buffers/MessageBufferNode.hh"
40#include "mem/ruby/common/Global.hh"
41#include "mem/ruby/eventqueue/RubyEventQueue.hh"
42#include "params/RubyWireBuffer.hh"
43#include "sim/sim_object.hh"
44
45
46//////////////////////////////////////////////////////////////////////////////
47// This object was written to literally mimic a Wire in Ruby, in the sense
48// that there is no way for messages to get reordered en route on the WireBuffer.
49// With Message Buffers, even if randomization is off and ordered is on,
50// messages can arrive in different orders than they were sent because of
51// network issues. This mimics a Wire, such that that is not possible. This can
52// allow for messages between closely coupled controllers that are not actually
53// separated by a network in real systems to simplify coherence.
54/////////////////////////////////////////////////////////////////////////////
55
56class Consumer;
57class Message;  // I added this and removed Message.hh
58
59class WireBuffer : public SimObject
60{
61  public:
62    typedef RubyWireBufferParams Params;
63    WireBuffer(const Params *p);
64    void init();
65
66    ~WireBuffer();
67
68    void wakeup();
69
70    void setConsumer(Consumer* consumer_ptr)
71    {
72        m_consumer_ptr = consumer_ptr;
73    }
74    Consumer* getConsumer() { return m_consumer_ptr; };
75    void setDescription(const std::string& name) { m_description = name; };
76    std::string getDescription() { return m_description; };
77
78    void enqueue(MsgPtr message, int latency );
79    void dequeue();
80    const Message* peek();
81    MessageBufferNode peekNode();
82    void recycle();
83    bool isReady();
84    bool areNSlotsAvailable(int n) { return true; };  // infinite queue length
85
86    void printConfig(std::ostream& out);
87    void print(std::ostream& out) const;
88    void clearStats() const;
89    void printStats(std::ostream& out) const;
90
91//    int m_dummy;
92    uint64_t m_msg_counter;
93
94  private:
95    // Private copy constructor and assignment operator
96    WireBuffer (const WireBuffer& obj);
97    WireBuffer& operator=(const WireBuffer& obj);
98
99    // data members
100    Consumer* m_consumer_ptr;  // Consumer to signal a wakeup()
101    std::string m_description;
102
103    // queues where memory requests live
104    std::vector<MessageBufferNode> m_message_queue;
105
106};
107
108#endif // __MEM_RUBY_SYSTEM_WireBuffer_HH__
109