gem5 v24.0.0.0
Loading...
Searching...
No Matches
AbstractController.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017,2019-2023 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2009-2014 Mark D. Hill and David A. Wood
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
42#define __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
43
44#include <exception>
45#include <iostream>
46#include <string>
47#include <unordered_map>
48
49#include "base/addr_range.hh"
51#include "base/callback.hh"
52#include "mem/packet.hh"
53#include "mem/qport.hh"
60#include "mem/ruby/protocol/AccessPermission.hh"
62#include "params/RubyController.hh"
63#include "sim/clocked_object.hh"
64#include "sim/eventq.hh"
65
66namespace gem5
67{
68
69namespace ruby
70{
71
72class Network;
73class GPUCoalescer;
74class DMASequencer;
75
76// used to communicate that an in_port peeked the wrong message type
77class RejectException: public std::exception
78{
79 virtual const char* what() const throw()
80 { return "Port rejected message based on type"; }
81};
82
84{
85 public:
86 PARAMS(RubyController);
88 void init();
89
90 NodeID getVersion() const { return m_machineID.getNum(); }
91 MachineType getType() const { return m_machineID.getType(); }
92
93 void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
94
95 // return instance name
97 bool isBlocked(Addr) const;
98 void unblock(Addr);
99 bool isBlocked(Addr);
100
101 virtual MessageBuffer* getMandatoryQueue() const = 0;
102 virtual MessageBuffer* getMemReqQueue() const = 0;
103 virtual MessageBuffer* getMemRespQueue() const = 0;
104
105 // That function must be called by controller when dequeuing mem resp queue
106 // for memory controller to receive the retry request in time
108 // Or that function can be called to perform both dequeue and notification
109 // at once.
110 void dequeueMemRespQueue();
111
112 virtual AccessPermission getAccessPermission(const Addr &addr) = 0;
113
114 virtual void print(std::ostream & out) const = 0;
115 virtual void wakeup() = 0;
116 virtual void resetStats() = 0;
117 virtual void regStats();
118
119 virtual void recordCacheTrace(int cntrl, CacheRecorder* tr) = 0;
120 virtual Sequencer* getCPUSequencer() const = 0;
121 virtual DMASequencer* getDMASequencer() const = 0;
122 virtual GPUCoalescer* getGPUCoalescer() const = 0;
123
124 // This latency is used by the sequencer when enqueueing requests.
125 // Different latencies may be used depending on the request type.
126 // This is the hit latency unless the top-level cache controller
127 // introduces additional cycles in the response path.
128 virtual Cycles mandatoryQueueLatency(const RubyRequestType& param_type)
129 { return m_mandatory_queue_latency; }
130
134 virtual void functionalRead(const Addr &addr, PacketPtr)
135 { panic("functionalRead(Addr,PacketPtr) not implemented"); }
136
140 virtual void functionalRead(const Addr &addr, PacketPtr pkt,
142 { panic("functionalRead(Addr,PacketPtr,WriteMask) not implemented"); }
143
148 virtual int functionalWrite(const Addr &addr, PacketPtr) = 0;
150
152 virtual void enqueuePrefetch(const Addr &, const RubyRequestType&)
153 { fatal("Prefetches not implemented!");}
154
157 virtual void notifyCoalesced(const Addr& addr,
158 const RubyRequestType& type,
159 const RequestPtr& req,
160 const DataBlock& data_blk,
161 const bool& was_miss)
162 { }
163
167 virtual void collateStats()
168 {fatal("collateStats() should be overridden!");}
169
171 virtual void initNetQueues() = 0;
172
174 Port &getPort(const std::string &if_name,
176
177 bool recvTimingResp(PacketPtr pkt);
179
180 const AddrRangeList &getAddrRanges() const { return addrRanges; }
181
182 public:
184 RequestorID getRequestorId() const { return m_id; }
185
189
191 {
192 for (auto &range: addrRanges)
193 if (range.contains(addr)) return true;
194 return false;
195 }
196
210 MachineID mapAddressToMachine(Addr addr, MachineType mtype) const;
211
224 MachineType mtype = MachineType_NUM) const;
225
228
231
232 protected:
234 void profileRequest(const std::string &request);
236 void profileMsgDelay(uint32_t virtualNetwork, Cycles delay);
237
238 // Tracks outstanding transactions for latency profiling
239 struct TransMapPair { unsigned transaction; unsigned state; Tick time; };
240 std::unordered_map<Addr, TransMapPair> m_inTransAddressed;
241 std::unordered_map<Addr, TransMapPair> m_outTransAddressed;
242
243 std::unordered_map<Addr, TransMapPair> m_inTransUnaddressed;
244 std::unordered_map<Addr, TransMapPair> m_outTransUnaddressed;
245
260 template<typename EventType, typename StateType>
262 EventType type, StateType initialState, bool retried,
263 bool isAddressed=true)
264 {
265 auto& m_inTrans =
267 assert(m_inTrans.find(addr) == m_inTrans.end());
268 m_inTrans[addr] = {type, initialState, curTick()};
269 if (retried)
271 }
272
283 template<typename StateType>
284 void incomingTransactionEnd(Addr addr, StateType finalState,
285 bool isAddressed=true)
286 {
287 auto& m_inTrans =
289 auto iter = m_inTrans.find(addr);
290 assert(iter != m_inTrans.end());
291 auto &trans = iter->second;
292
293 auto stat_iter_ev = stats.inTransStateChanges.find(trans.transaction);
294 gem5_assert(stat_iter_ev != stats.inTransStateChanges.end(),
295 "%s: event type=%d not marked as in_trans in SLICC",
296 name(), trans.transaction);
297
298 auto stat_iter_state = stat_iter_ev->second.find(trans.state);
299 gem5_assert(stat_iter_state != stat_iter_ev->second.end(),
300 "%s: event type=%d has no transition from state=%d",
301 name(), trans.transaction, trans.state);
302
303 ++(*stat_iter_state->second[(unsigned)finalState]);
304
305 stats.inTransLatHist[iter->second.transaction]->sample(
306 ticksToCycles(curTick() - trans.time));
307
308 m_inTrans.erase(iter);
309 }
310
322 template<typename EventType>
324 bool isAddressed=true)
325 {
326 auto& m_outTrans =
328 assert(m_outTrans.find(addr) == m_outTrans.end());
329 m_outTrans[addr] = {type, 0, curTick()};
330 }
331
342 void outgoingTransactionEnd(Addr addr, bool retried,
343 bool isAddressed=true)
344 {
345 auto& m_outTrans =
347 auto iter = m_outTrans.find(addr);
348 assert(iter != m_outTrans.end());
349 auto &trans = iter->second;
350
351 auto stat_iter = stats.outTransLatHist.find(trans.transaction);
352 gem5_assert(stat_iter != stats.outTransLatHist.end(),
353 "%s: event type=%d not marked as out_trans in SLICC",
354 name(), trans.transaction);
355
356 stat_iter->second->sample(
357 ticksToCycles(curTick() - trans.time));
358 if (retried)
359 ++(*stats.outTransRetryCnt[trans.transaction]);
360 m_outTrans.erase(iter);
361 }
362
365 void wakeUpBuffers(Addr addr);
367 void wakeUpAllBuffers();
368 bool serviceMemoryQueue();
369
374 virtual bool inCache(const Addr &addr, const bool &is_secure)
375 { fatal("inCache: prefetching not supported"); return false; }
376
377 virtual bool hasBeenPrefetched(const Addr &addr, const bool &is_secure)
378 { fatal("hasBeenPrefetched: prefetching not supported"); return false; }
379
380 virtual bool hasBeenPrefetched(const Addr &addr, const bool &is_secure,
381 const RequestorID &requestor)
382 { fatal("hasBeenPrefetched: prefetching not supported"); return false; }
383
384 virtual bool inMissQueue(const Addr &addr, const bool &is_secure)
385 { fatal("inMissQueue: prefetching not supported"); return false; }
386
387 virtual bool coalesce()
388 { fatal("coalesce: prefetching not supported"); return false; }
389
391
392 protected:
396
397 // RequestorID used by some components of gem5.
399
402 std::map<Addr, MessageBuffer*> m_block_map;
403
405 typedef std::set<MessageBuffer*> MsgBufType;
406 typedef std::map<Addr, MsgVecType* > WaitingBufType;
408
409 unsigned int m_in_ports;
410 unsigned int m_cur_in_port;
413 const unsigned int m_buffer_size;
418
423 class MemoryPort : public RequestPort
424 {
425 private:
426 // Controller that operates this port.
428
429 public:
430 MemoryPort(const std::string &_name, AbstractController *_controller,
431 PortID id = InvalidPortID);
432
433 protected:
434 // Function for receiving a timing response from the peer port.
435 // Currently the pkt is handed to the coherence controller
436 // associated with this port.
437 bool recvTimingResp(PacketPtr pkt);
438
439 void recvReqRetry();
440 };
441
442 /* Request port to the memory controller. */
444
445 // State that is stored in packets sent to the memory controller.
447 {
448 // Id of the machine from which the request originated.
450
452 {}
453 };
454
455 private:
458
459 std::unordered_map<MachineType, AddrRangeMap<MachineID, 3>>
461
464
465 void sendRetryRespToMem();
467
468 public:
470 {
472
473 // Initialized by the SLICC compiler for all events with the
474 // "in_trans" property.
475 // Only histograms with samples will appear in the stats
476 std::unordered_map<unsigned, statistics::Histogram*> inTransLatHist;
477 std::unordered_map<unsigned, statistics::Scalar*> inTransRetryCnt;
478 // Initialized by the SLICC compiler for all combinations of events
479 // with the "in_trans" property, potential initial states, and
480 // potential final states. Potential initial states are states that
481 // appear in transitions triggered by that event. Currently all states
482 // are considered as potential final states.
483 std::unordered_map<unsigned, std::unordered_map<unsigned,
485
486 // Initialized by the SLICC compiler for all events with the
487 // "out_trans" property.
488 // Only histograms with samples will appear in the stats.
489 std::unordered_map<unsigned, statistics::Histogram*> outTransLatHist;
490 std::unordered_map<unsigned, statistics::Scalar*>
492
496
502
503};
504
505} // namespace ruby
506} // namespace gem5
507
508#endif // __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObjectParams Params
Parameters of ClockedObject.
Cycles ticksToCycles(Tick t) const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
Wrap a member function inside MemberEventWrapper to use it as an event callback.
Definition eventq.hh:1092
const std::string _name
Definition named.hh:41
virtual std::string name() const
Definition named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
Port that forwards requests and receives responses from the memory controller.
MemoryPort(const std::string &_name, AbstractController *_controller, PortID id=InvalidPortID)
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
void initNetworkPtr(Network *net_ptr)
std::vector< MessageBuffer * > MsgVecType
void profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
Profiles the delay associated with messages.
std::map< Addr, MsgVecType * > WaitingBufType
virtual void initNetQueues()=0
Initialize the message buffers.
virtual void notifyCoalesced(const Addr &addr, const RubyRequestType &type, const RequestPtr &req, const DataBlock &data_blk, const bool &was_miss)
Notifies controller of a request coalesced at the sequencer.
void wakeUpBuffer(MessageBuffer *buf, Addr addr)
statistics::Histogram & getDelayVCHist(uint32_t index)
virtual void regStats()
Callback to set stat parameters.
virtual void print(std::ostream &out) const =0
const NetDest & allUpstreamDest() const
List of upstream destinations (towards the CPU)
std::unordered_map< Addr, TransMapPair > m_outTransAddressed
void incomingTransactionStart(Addr addr, EventType type, StateType initialState, bool retried, bool isAddressed=true)
Profiles an event that initiates a protocol transactions for a specific line (e.g.
virtual Cycles mandatoryQueueLatency(const RubyRequestType &param_type)
const AddrRangeList addrRanges
The address range to which the controller responds on the CPU side.
std::unordered_map< MachineType, AddrRangeMap< MachineID, 3 > > downstreamAddrMap
virtual AccessPermission getAccessPermission(const Addr &addr)=0
const AddrRangeList & getAddrRanges() const
virtual MessageBuffer * getMemReqQueue() const =0
std::set< MessageBuffer * > MsgBufType
virtual DMASequencer * getDMASequencer() const =0
virtual int functionalWrite(const Addr &addr, PacketPtr)=0
virtual void recordCacheTrace(int cntrl, CacheRecorder *tr)=0
virtual bool functionalReadBuffers(PacketPtr &)=0
These functions are used by ruby system to read/write the data blocks that exist with in the controll...
const NetDest & allDownstreamDest() const
List of downstream destinations (towards memory)
virtual bool hasBeenPrefetched(const Addr &addr, const bool &is_secure, const RequestorID &requestor)
void outgoingTransactionStart(Addr addr, EventType type, bool isAddressed=true)
Profiles an event that initiates a transaction in a peer controller (e.g.
MachineID mapAddressToDownstreamMachine(Addr addr, MachineType mtype=MachineType_NUM) const
Maps an address to the correct dowstream MachineID (i.e.
virtual void enqueuePrefetch(const Addr &, const RubyRequestType &)
Function for enqueuing a prefetch request.
virtual void collateStats()
Function for collating statistics from all the controllers of this particular type.
virtual MessageBuffer * getMemRespQueue() const =0
virtual bool functionalReadBuffers(PacketPtr &, WriteMask &mask)=0
Functional read that reads only blocks not present in the mask.
virtual void functionalRead(const Addr &addr, PacketPtr)
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
MemberEventWrapper<&AbstractController::sendRetryRespToMem > mRetryRespEvent
std::unordered_map< Addr, TransMapPair > m_inTransAddressed
virtual Sequencer * getCPUSequencer() const =0
std::unordered_map< Addr, TransMapPair > m_inTransUnaddressed
virtual void resetStats()=0
Callback to reset stats.
virtual void functionalRead(const Addr &addr, PacketPtr pkt, WriteMask &mask)
void blockOnQueue(Addr, MessageBuffer *)
MachineID mapAddressToMachine(Addr addr, MachineType mtype) const
Map an address to the correct MachineID.
virtual bool inCache(const Addr &addr, const bool &is_secure)
Functions needed by CacheAccessor.
virtual MessageBuffer * getMandatoryQueue() const =0
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
A function used to return the port associated with this bus object.
virtual bool inMissQueue(const Addr &addr, const bool &is_secure)
void outgoingTransactionEnd(Addr addr, bool retried, bool isAddressed=true)
Profiles the end of an outgoing transaction.
gem5::ruby::AbstractController::ControllerStats stats
virtual GPUCoalescer * getGPUCoalescer() const =0
void profileRequest(const std::string &request)
Profiles original cache requests including PUTs.
void incomingTransactionEnd(Addr addr, StateType finalState, bool isAddressed=true)
Profiles an event that ends a transaction.
std::unordered_map< Addr, TransMapPair > m_outTransUnaddressed
std::map< Addr, MessageBuffer * > m_block_map
statistics::Histogram & getDelayHist()
virtual bool hasBeenPrefetched(const Addr &addr, const bool &is_secure)
void stallBuffer(MessageBuffer *buf, Addr addr)
virtual int functionalWriteBuffers(PacketPtr &)=0
The return value indicates the number of messages written with the data from the packet.
virtual const char * what() const
This is a proxy for prefetcher class in classic memory.
Statistics container.
Definition group.hh:93
A simple histogram stat.
This is a simple scalar statistic, like a counter.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:317
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 30, 0 > index
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
unsigned int NodeID
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
const PortID InvalidPortID
Definition types.hh:246
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
Declaration of the Packet class.
Declaration of the queued port.
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition packet.hh:469
std::unordered_map< unsigned, statistics::Histogram * > outTransLatHist
statistics::Scalar fullyBusyCycles
Counter for the number of cycles when the transitions carried out were equal to the maximum allowed.
std::unordered_map< unsigned, statistics::Scalar * > outTransRetryCnt
std::unordered_map< unsigned, std::unordered_map< unsigned, std::vector< statistics::Scalar * > > > inTransStateChanges
statistics::Histogram delayHistogram
Histogram for profiling delay for the messages this controller cares for.
std::unordered_map< unsigned, statistics::Scalar * > inTransRetryCnt
std::vector< statistics::Histogram * > delayVCHistogram
std::unordered_map< unsigned, statistics::Histogram * > inTransLatHist
MachineType getType() const
Definition MachineID.hh:66
NodeID getNum() const
Definition MachineID.hh:67

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0