2 * Copyright (c) 2019-2020 ARM Limited
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.
14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15 * All rights reserved.
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.
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.
41 #ifndef __MEM_RUBY_SYSTEM_SEQUENCER_HH__
42 #define __MEM_RUBY_SYSTEM_SEQUENCER_HH__
46 #include <unordered_map>
48 #include "mem/ruby/common/Address.hh"
49 #include "mem/ruby/protocol/MachineType.hh"
50 #include "mem/ruby/protocol/RubyRequestType.hh"
51 #include "mem/ruby/protocol/SequencerRequestType.hh"
52 #include "mem/ruby/structures/CacheMemory.hh"
53 #include "mem/ruby/system/RubyPort.hh"
54 #include "params/RubySequencer.hh"
56 struct SequencerRequest
59 RubyRequestType m_type;
60 RubyRequestType m_second_type;
62 SequencerRequest(PacketPtr _pkt, RubyRequestType _m_type,
63 RubyRequestType _m_second_type, Cycles _issue_time)
64 : pkt(_pkt), m_type(_m_type), m_second_type(_m_second_type),
65 issue_time(_issue_time)
68 bool functionalWrite(Packet *func_pkt) const
70 // Follow-up on RubyRequest::functionalWrite
71 // This makes sure the hitCallback won't overrite the value we
73 assert(func_pkt->isWrite());
74 return func_pkt->trySatisfyFunctional(pkt);
78 std::ostream& operator<<(std::ostream& out, const SequencerRequest& obj);
80 class Sequencer : public RubyPort
83 typedef RubySequencerParams Params;
84 Sequencer(const Params *);
88 * Proxy function to writeCallback that first
89 * invalidates the line address in the local monitor.
91 void writeCallbackScFail(Addr address,
95 virtual void wakeup(); // Used only for deadlock detection
96 void resetStats() override;
98 void regStats() override;
100 void writeCallback(Addr address,
102 const bool externalHit = false,
103 const MachineType mach = MachineType_NUM,
104 const Cycles initialRequestTime = Cycles(0),
105 const Cycles forwardRequestTime = Cycles(0),
106 const Cycles firstResponseTime = Cycles(0));
108 void readCallback(Addr address,
110 const bool externalHit = false,
111 const MachineType mach = MachineType_NUM,
112 const Cycles initialRequestTime = Cycles(0),
113 const Cycles forwardRequestTime = Cycles(0),
114 const Cycles firstResponseTime = Cycles(0));
116 RequestStatus makeRequest(PacketPtr pkt) override;
117 virtual bool empty() const;
118 int outstandingCount() const override { return m_outstanding_count; }
120 bool isDeadlockEventScheduled() const override
121 { return deadlockCheckEvent.scheduled(); }
123 void descheduleDeadlockEvent() override
124 { deschedule(deadlockCheckEvent); }
126 virtual void print(std::ostream& out) const;
129 void evictionCallback(Addr address);
130 int coreId() const { return m_coreId; }
132 virtual int functionalWrite(Packet *func_pkt) override;
134 void recordRequestType(SequencerRequestType requestType);
135 Stats::Histogram& getOutstandReqHist() { return m_outstandReqHist; }
137 Stats::Histogram& getLatencyHist() { return m_latencyHist; }
138 Stats::Histogram& getTypeLatencyHist(uint32_t t)
139 { return *m_typeLatencyHist[t]; }
141 Stats::Histogram& getHitLatencyHist() { return m_hitLatencyHist; }
142 Stats::Histogram& getHitTypeLatencyHist(uint32_t t)
143 { return *m_hitTypeLatencyHist[t]; }
145 Stats::Histogram& getHitMachLatencyHist(uint32_t t)
146 { return *m_hitMachLatencyHist[t]; }
148 Stats::Histogram& getHitTypeMachLatencyHist(uint32_t r, uint32_t t)
149 { return *m_hitTypeMachLatencyHist[r][t]; }
151 Stats::Histogram& getMissLatencyHist()
152 { return m_missLatencyHist; }
153 Stats::Histogram& getMissTypeLatencyHist(uint32_t t)
154 { return *m_missTypeLatencyHist[t]; }
156 Stats::Histogram& getMissMachLatencyHist(uint32_t t) const
157 { return *m_missMachLatencyHist[t]; }
160 getMissTypeMachLatencyHist(uint32_t r, uint32_t t) const
161 { return *m_missTypeMachLatencyHist[r][t]; }
163 Stats::Histogram& getIssueToInitialDelayHist(uint32_t t) const
164 { return *m_IssueToInitialDelayHist[t]; }
167 getInitialToForwardDelayHist(const MachineType t) const
168 { return *m_InitialToForwardDelayHist[t]; }
171 getForwardRequestToFirstResponseHist(const MachineType t) const
172 { return *m_ForwardToFirstResponseDelayHist[t]; }
175 getFirstResponseToCompletionDelayHist(const MachineType t) const
176 { return *m_FirstResponseToCompletionDelayHist[t]; }
178 Stats::Counter getIncompleteTimes(const MachineType t) const
179 { return m_IncompleteTimes[t]; }
182 void issueRequest(PacketPtr pkt, RubyRequestType type);
184 void hitCallback(SequencerRequest* srequest, DataBlock& data,
186 const MachineType mach, const bool externalHit,
187 const Cycles initialRequestTime,
188 const Cycles forwardRequestTime,
189 const Cycles firstResponseTime);
191 void recordMissLatency(SequencerRequest* srequest, bool llscSuccess,
192 const MachineType respondingMach,
193 bool isExternalHit, Cycles initialRequestTime,
194 Cycles forwardRequestTime,
195 Cycles firstResponseTime);
197 // Private copy constructor and assignment operator
198 Sequencer(const Sequencer& obj);
199 Sequencer& operator=(const Sequencer& obj);
202 // RequestTable contains both read and write requests, handles aliasing
203 std::unordered_map<Addr, std::list<SequencerRequest>> m_RequestTable;
205 Cycles m_deadlock_threshold;
207 virtual RequestStatus insertRequest(PacketPtr pkt,
208 RubyRequestType primary_type,
209 RubyRequestType secondary_type);
212 int m_max_outstanding_requests;
214 CacheMemory* m_dataCache_ptr;
215 CacheMemory* m_instCache_ptr;
217 // The cache access latency for top-level caches (L0/L1). These are
218 // currently assessed at the beginning of each memory access through the
220 // TODO: Migrate these latencies into top-level cache controllers.
221 Cycles m_data_cache_hit_latency;
222 Cycles m_inst_cache_hit_latency;
224 // Global outstanding request count, across all request tables
225 int m_outstanding_count;
226 bool m_deadlock_check_scheduled;
230 bool m_runningGarnetStandalone;
232 //! Histogram for number of outstanding requests per cycle.
233 Stats::Histogram m_outstandReqHist;
235 //! Histogram for holding latency profile of all requests.
236 Stats::Histogram m_latencyHist;
237 std::vector<Stats::Histogram *> m_typeLatencyHist;
239 //! Histogram for holding latency profile of all requests that
240 //! hit in the controller connected to this sequencer.
241 Stats::Histogram m_hitLatencyHist;
242 std::vector<Stats::Histogram *> m_hitTypeLatencyHist;
244 //! Histograms for profiling the latencies for requests that
245 //! did not required external messages.
246 std::vector<Stats::Histogram *> m_hitMachLatencyHist;
247 std::vector< std::vector<Stats::Histogram *> > m_hitTypeMachLatencyHist;
249 //! Histogram for holding latency profile of all requests that
250 //! miss in the controller connected to this sequencer.
251 Stats::Histogram m_missLatencyHist;
252 std::vector<Stats::Histogram *> m_missTypeLatencyHist;
254 //! Histograms for profiling the latencies for requests that
255 //! required external messages.
256 std::vector<Stats::Histogram *> m_missMachLatencyHist;
257 std::vector< std::vector<Stats::Histogram *> > m_missTypeMachLatencyHist;
259 //! Histograms for recording the breakdown of miss latency
260 std::vector<Stats::Histogram *> m_IssueToInitialDelayHist;
261 std::vector<Stats::Histogram *> m_InitialToForwardDelayHist;
262 std::vector<Stats::Histogram *> m_ForwardToFirstResponseDelayHist;
263 std::vector<Stats::Histogram *> m_FirstResponseToCompletionDelayHist;
264 std::vector<Stats::Counter> m_IncompleteTimes;
266 EventFunctionWrapper deadlockCheckEvent;
271 * Places the cache line address into the global monitor
272 * tagged with this Sequencer object's version id.
274 void llscLoadLinked(const Addr);
277 * Removes the cache line address from the global monitor.
278 * This is independent of this Sequencer object's version id.
280 void llscClearMonitor(const Addr);
283 * Searches for cache line address in the global monitor
284 * tagged with this Sequencer object's version id.
285 * If a match is found, the entry is is erased from
286 * the global monitor.
288 * @return a boolean indicating if the line address was found.
290 bool llscStoreConditional(const Addr);
294 * Searches for cache line address in the global monitor
295 * tagged with this Sequencer object's version id.
297 * @return a boolean indicating if the line address was found.
299 bool llscCheckMonitor(const Addr);
303 * Removes all addresses from the local monitor.
304 * This is independent of this Sequencer object's version id.
306 void llscClearLocalMonitor();
310 operator<<(std::ostream& out, const Sequencer& obj)
317 #endif // __MEM_RUBY_SYSTEM_SEQUENCER_HH__