2 * Copyright (c) 2019 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 void wakeup(); // Used only for deadlock detection
89 void resetStats() override;
91 void regStats() override;
93 void writeCallback(Addr address,
95 const bool externalHit = false,
96 const MachineType mach = MachineType_NUM,
97 const Cycles initialRequestTime = Cycles(0),
98 const Cycles forwardRequestTime = Cycles(0),
99 const Cycles firstResponseTime = Cycles(0));
101 void readCallback(Addr address,
103 const bool externalHit = false,
104 const MachineType mach = MachineType_NUM,
105 const Cycles initialRequestTime = Cycles(0),
106 const Cycles forwardRequestTime = Cycles(0),
107 const Cycles firstResponseTime = Cycles(0));
109 RequestStatus makeRequest(PacketPtr pkt) override;
111 int outstandingCount() const override { return m_outstanding_count; }
113 bool isDeadlockEventScheduled() const override
114 { return deadlockCheckEvent.scheduled(); }
116 void descheduleDeadlockEvent() override
117 { deschedule(deadlockCheckEvent); }
119 void print(std::ostream& out) const;
120 void checkCoherence(Addr address);
123 void evictionCallback(Addr address);
124 void invalidateSC(Addr address);
125 int coreId() const { return m_coreId; }
127 virtual int functionalWrite(Packet *func_pkt) override;
129 void recordRequestType(SequencerRequestType requestType);
130 Stats::Histogram& getOutstandReqHist() { return m_outstandReqHist; }
132 Stats::Histogram& getLatencyHist() { return m_latencyHist; }
133 Stats::Histogram& getTypeLatencyHist(uint32_t t)
134 { return *m_typeLatencyHist[t]; }
136 Stats::Histogram& getHitLatencyHist() { return m_hitLatencyHist; }
137 Stats::Histogram& getHitTypeLatencyHist(uint32_t t)
138 { return *m_hitTypeLatencyHist[t]; }
140 Stats::Histogram& getHitMachLatencyHist(uint32_t t)
141 { return *m_hitMachLatencyHist[t]; }
143 Stats::Histogram& getHitTypeMachLatencyHist(uint32_t r, uint32_t t)
144 { return *m_hitTypeMachLatencyHist[r][t]; }
146 Stats::Histogram& getMissLatencyHist()
147 { return m_missLatencyHist; }
148 Stats::Histogram& getMissTypeLatencyHist(uint32_t t)
149 { return *m_missTypeLatencyHist[t]; }
151 Stats::Histogram& getMissMachLatencyHist(uint32_t t) const
152 { return *m_missMachLatencyHist[t]; }
155 getMissTypeMachLatencyHist(uint32_t r, uint32_t t) const
156 { return *m_missTypeMachLatencyHist[r][t]; }
158 Stats::Histogram& getIssueToInitialDelayHist(uint32_t t) const
159 { return *m_IssueToInitialDelayHist[t]; }
162 getInitialToForwardDelayHist(const MachineType t) const
163 { return *m_InitialToForwardDelayHist[t]; }
166 getForwardRequestToFirstResponseHist(const MachineType t) const
167 { return *m_ForwardToFirstResponseDelayHist[t]; }
170 getFirstResponseToCompletionDelayHist(const MachineType t) const
171 { return *m_FirstResponseToCompletionDelayHist[t]; }
173 Stats::Counter getIncompleteTimes(const MachineType t) const
174 { return m_IncompleteTimes[t]; }
177 void issueRequest(PacketPtr pkt, RubyRequestType type);
179 void hitCallback(SequencerRequest* srequest, DataBlock& data,
181 const MachineType mach, const bool externalHit,
182 const Cycles initialRequestTime,
183 const Cycles forwardRequestTime,
184 const Cycles firstResponseTime);
186 void recordMissLatency(SequencerRequest* srequest, bool llscSuccess,
187 const MachineType respondingMach,
188 bool isExternalHit, Cycles initialRequestTime,
189 Cycles forwardRequestTime,
190 Cycles firstResponseTime);
192 RequestStatus insertRequest(PacketPtr pkt, RubyRequestType primary_type,
193 RubyRequestType secondary_type);
194 bool handleLlsc(Addr address, SequencerRequest* request);
196 // Private copy constructor and assignment operator
197 Sequencer(const Sequencer& obj);
198 Sequencer& operator=(const Sequencer& obj);
201 int m_max_outstanding_requests;
202 Cycles m_deadlock_threshold;
204 CacheMemory* m_dataCache_ptr;
205 CacheMemory* m_instCache_ptr;
207 // The cache access latency for top-level caches (L0/L1). These are
208 // currently assessed at the beginning of each memory access through the
210 // TODO: Migrate these latencies into top-level cache controllers.
211 Cycles m_data_cache_hit_latency;
212 Cycles m_inst_cache_hit_latency;
214 // RequestTable contains both read and write requests, handles aliasing
215 std::unordered_map<Addr, std::list<SequencerRequest>> m_RequestTable;
217 // Global outstanding request count, across all request tables
218 int m_outstanding_count;
219 bool m_deadlock_check_scheduled;
223 bool m_runningGarnetStandalone;
225 //! Histogram for number of outstanding requests per cycle.
226 Stats::Histogram m_outstandReqHist;
228 //! Histogram for holding latency profile of all requests.
229 Stats::Histogram m_latencyHist;
230 std::vector<Stats::Histogram *> m_typeLatencyHist;
232 //! Histogram for holding latency profile of all requests that
233 //! hit in the controller connected to this sequencer.
234 Stats::Histogram m_hitLatencyHist;
235 std::vector<Stats::Histogram *> m_hitTypeLatencyHist;
237 //! Histograms for profiling the latencies for requests that
238 //! did not required external messages.
239 std::vector<Stats::Histogram *> m_hitMachLatencyHist;
240 std::vector< std::vector<Stats::Histogram *> > m_hitTypeMachLatencyHist;
242 //! Histogram for holding latency profile of all requests that
243 //! miss in the controller connected to this sequencer.
244 Stats::Histogram m_missLatencyHist;
245 std::vector<Stats::Histogram *> m_missTypeLatencyHist;
247 //! Histograms for profiling the latencies for requests that
248 //! required external messages.
249 std::vector<Stats::Histogram *> m_missMachLatencyHist;
250 std::vector< std::vector<Stats::Histogram *> > m_missTypeMachLatencyHist;
252 //! Histograms for recording the breakdown of miss latency
253 std::vector<Stats::Histogram *> m_IssueToInitialDelayHist;
254 std::vector<Stats::Histogram *> m_InitialToForwardDelayHist;
255 std::vector<Stats::Histogram *> m_ForwardToFirstResponseDelayHist;
256 std::vector<Stats::Histogram *> m_FirstResponseToCompletionDelayHist;
257 std::vector<Stats::Counter> m_IncompleteTimes;
259 EventFunctionWrapper deadlockCheckEvent;
263 operator<<(std::ostream& out, const Sequencer& obj)
270 #endif // __MEM_RUBY_SYSTEM_SEQUENCER_HH__