gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WireBuffer.cc
Go to the documentation of this file.
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 
33 
34 #include <algorithm>
35 #include <functional>
36 
37 #include "base/cprintf.hh"
38 #include "base/stl_helpers.hh"
40 
41 using namespace std;
42 
43 // Output operator definition
44 
45 ostream&
46 operator<<(ostream& out, const WireBuffer& obj)
47 {
48  obj.print(out);
49  out << flush;
50  return out;
51 }
52 
53 
54 // ****************************************************************
55 
56 // CONSTRUCTOR
58  : SimObject(p)
59 {
60  m_msg_counter = 0;
61 }
62 
63 void
65 {
66 }
67 
69 {
70 }
71 
72 void
73 WireBuffer::enqueue(MsgPtr message, Tick current_time, Tick delta)
74 {
75  m_msg_counter++;
76  Tick arrival_time = current_time + delta;
77  assert(arrival_time > current_time);
78 
79  Message* msg_ptr = message.get();
80  msg_ptr->setLastEnqueueTime(arrival_time);
81  m_message_queue.push_back(message);
82  if (m_consumer_ptr != NULL) {
84  scheduleEventAbsolute(arrival_time);
85  } else {
86  panic("No Consumer for WireBuffer! %s\n", *this);
87  }
88 }
89 
90 void
92 {
93  assert(isReady(current_time));
94  pop_heap(m_message_queue.begin(), m_message_queue.end(),
95  greater<MsgPtr>());
96  m_message_queue.pop_back();
97 }
98 
99 const Message*
101 {
102  Message* msg_ptr = m_message_queue.front().get();
103  assert(msg_ptr != NULL);
104  return msg_ptr;
105 }
106 
107 void
108 WireBuffer::recycle(Tick current_time, Tick recycle_latency)
109 {
110  // Because you don't want anything reordered, make sure the recycle latency
111  // is just 1 cycle. As a result, you really want to use this only in
112  // Wire-like situations because you don't want to deadlock as a result of
113  // being stuck behind something if you're not actually supposed to.
114  assert(isReady(current_time));
115  MsgPtr node = m_message_queue.front();
116  pop_heap(m_message_queue.begin(), m_message_queue.end(), greater<MsgPtr>());
117 
118  Tick future_time = current_time + recycle_latency;
119  node->setLastEnqueueTime(future_time);
120 
121  m_message_queue.back() = node;
122  push_heap(m_message_queue.begin(), m_message_queue.end(),
123  greater<MsgPtr>());
125  scheduleEventAbsolute(future_time);
126 }
127 
128 bool
130 {
131  return ((!m_message_queue.empty()) &&
132  (m_message_queue.front()->getLastEnqueueTime() <= current_time));
133 }
134 
135 void
136 WireBuffer::print(ostream& out) const
137 {
138 }
139 
140 void
142 {
143 }
144 
145 WireBuffer *
146 RubyWireBufferParams::create()
147 {
148  return new WireBuffer(this);
149 }
std::shared_ptr< Message > MsgPtr
Definition: Message.hh:40
void enqueue(MsgPtr message, Tick current_time, Tick delta)
Definition: WireBuffer.cc:73
#define panic(...)
Definition: misc.hh:153
void wakeup()
Definition: WireBuffer.cc:141
ostream & operator<<(ostream &out, const WireBuffer &obj)
Definition: WireBuffer.cc:46
RubyWireBufferParams Params
Definition: WireBuffer.hh:59
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: WireBuffer.cc:64
uint64_t Tick
Tick count type.
Definition: types.hh:63
void recycle(Tick current_time, Tick recycle_latency)
Definition: WireBuffer.cc:108
void dequeue(Tick current_time)
Definition: WireBuffer.cc:91
const Message * peek()
Definition: WireBuffer.cc:100
Consumer * m_consumer_ptr
Definition: WireBuffer.hh:92
WireBuffer(const Params *p)
Definition: WireBuffer.cc:57
void print(std::ostream &out) const
Definition: WireBuffer.cc:136
bool isReady(Tick current_time)
Definition: WireBuffer.cc:129
Bitfield< 0 > p
std::vector< MsgPtr > m_message_queue
Definition: WireBuffer.hh:96
uint64_t m_msg_counter
Definition: WireBuffer.hh:84
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
void setLastEnqueueTime(const Tick &time)
Definition: Message.hh:88

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6