gem5  v20.1.0.0
token_port.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2020 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef __MEM_TOKEN_PORT_HH__
35 #define __MEM_TOKEN_PORT_HH__
36 
37 #include "mem/port.hh"
38 #include "sim/clocked_object.hh"
39 
40 class TokenManager;
41 class TokenResponsePort;
42 
44 {
45  private:
46  /* Manager to track tokens between this token port pair. */
48 
49  public:
50  TokenRequestPort(const std::string& name, SimObject* owner,
51  PortID id = InvalidPortID) :
52  RequestPort(name, owner, id), tokenManager(nullptr)
53  { }
54 
59  void bind(Port &peer) override;
60 
64  void unbind() override {}
65 
70  void recvTokens(int num_tokens);
71 
75  bool haveTokens(int num_tokens);
76 
81  void acquireTokens(int num_tokens);
82 
87  void setTokenManager(TokenManager *_tokenManager);
88 };
89 
91 {
92  private:
94 
96 
97  void recvRespRetry() override;
98 
99  public:
101  PortID id = InvalidPortID) :
103  { }
105 
111  void bind(Port &peer) override;
112 
116  void unbind() override;
117 
121  void sendTokens(int num_tokens);
122 
123  bool sendTimingResp(PacketPtr pkt);
124 
125  /* There is no storage here so the packet will not be found. */
126  bool trySatisfyFunctional(PacketPtr) { return false; }
127 };
128 
130 {
131  protected:
132  /* Maximum tokens possible */
134 
135  /* Number of currently available tokens */
137 
138  public:
139  TokenManager(int init_tokens);
141 
145  int getMaxTokenCount() const;
146 
150  void recvTokens(int num_tokens);
151 
155  bool haveTokens(int num_tokens);
156 
160  void acquireTokens(int num_tokens);
161 };
162 
163 #endif
TokenManager::recvTokens
void recvTokens(int num_tokens)
Increment the number of available tokens by num_tokens.
Definition: token_port.cc:156
ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:265
TokenRequestPort::tokenManager
TokenManager * tokenManager
Definition: token_port.hh:47
TokenManager::acquireTokens
void acquireTokens(int num_tokens)
Decrement the number of available tokens by num_tokens.
Definition: token_port.cc:174
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:238
TokenManager::availableTokens
int availableTokens
Definition: token_port.hh:136
TokenManager::haveTokens
bool haveTokens(int num_tokens)
Query is num_tokens tokens are available.
Definition: token_port.cc:168
TokenResponsePort::bind
void bind(Port &peer) override
Bind this response port to a request port.
Definition: token_port.cc:88
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
TokenResponsePort::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr)
Definition: token_port.hh:126
TokenManager::getMaxTokenCount
int getMaxTokenCount() const
Return the maximum possible tokens.
Definition: token_port.cc:150
TokenRequestPort::recvTokens
void recvTokens(int num_tokens)
Receive tokens returned by the response port.
Definition: token_port.cc:49
TokenManager::maxTokens
int maxTokens
Definition: token_port.hh:133
TokenResponsePort::~TokenResponsePort
~TokenResponsePort()
Definition: token_port.hh:104
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
TokenManager::TokenManager
TokenManager(int init_tokens)
Definition: token_port.cc:143
TokenRequestPort::acquireTokens
void acquireTokens(int num_tokens)
Acquire tokens by decrementing the number of available tokens across the port.
Definition: token_port.cc:65
TokenResponsePort::sendTimingResp
bool sendTimingResp(PacketPtr pkt)
Definition: token_port.cc:132
TokenResponsePort::respQueue
std::deque< PacketPtr > respQueue
Definition: token_port.hh:95
TokenRequestPort::TokenRequestPort
TokenRequestPort(const std::string &name, SimObject *owner, PortID id=InvalidPortID)
Definition: token_port.hh:50
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
port.hh
TokenResponsePort::unbind
void unbind() override
Unbind this response port and associated request port.
Definition: token_port.cc:110
Port::id
const PortID id
A numeric identifier to distinguish ports in a vector, and set to InvalidPortID in case this port is ...
Definition: port.hh:74
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
Port::name
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:106
TokenRequestPort::bind
void bind(Port &peer) override
Bind this request port to response port.
Definition: token_port.cc:43
ResponsePort::owner
SimObject & owner
Definition: port.hh:276
RequestPort::owner
SimObject & owner
Definition: port.hh:83
TokenResponsePort::recvRespRetry
void recvRespRetry() override
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Definition: token_port.cc:117
TokenResponsePort::tokenRequestPort
TokenRequestPort * tokenRequestPort
Definition: token_port.hh:93
TokenRequestPort::unbind
void unbind() override
Unbind port.
Definition: token_port.hh:64
TokenRequestPort::haveTokens
bool haveTokens(int num_tokens)
Query if there are at least num_tokens tokens available to acquire.
Definition: token_port.cc:57
TokenRequestPort
Definition: token_port.hh:43
clocked_object.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
std::deque
STL deque class.
Definition: stl.hh:44
TokenResponsePort::TokenResponsePort
TokenResponsePort(const std::string &name, ClockedObject *owner, PortID id=InvalidPortID)
Definition: token_port.hh:100
TokenManager
Definition: token_port.hh:129
TokenResponsePort
Definition: token_port.hh:90
TokenRequestPort::setTokenManager
void setTokenManager(TokenManager *_tokenManager)
Specify a token manger, which will handle tracking of tokens for a TokenRequestPort/ResponseRequestPo...
Definition: token_port.cc:73
TokenManager::~TokenManager
~TokenManager()
Definition: token_port.hh:140
TokenResponsePort::sendTokens
void sendTokens(int num_tokens)
Return num_tokens tokens back to the request port.
Definition: token_port.cc:79
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17