Profiler.hh revision 7055:4e24742201d7
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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
29/*
30   This file has been modified by Kevin Moore and Dan Nussbaum of the
31   Scalable Systems Research Group at Sun Microsystems Laboratories
32   (http://research.sun.com/scalable/) to support the Adaptive
33   Transactional Memory Test Platform (ATMTP).
34
35   Please send email to atmtp-interest@sun.com with feedback, questions, or
36   to request future announcements about ATMTP.
37
38   ----------------------------------------------------------------------
39
40   File modification date: 2008-02-23
41
42   ----------------------------------------------------------------------
43*/
44
45#ifndef __MEM_RUBY_PROFILER_PROFILER_HH__
46#define __MEM_RUBY_PROFILER_PROFILER_HH__
47
48#include <iostream>
49#include <string>
50
51#include "mem/protocol/AccessModeType.hh"
52#include "mem/protocol/AccessType.hh"
53#include "mem/protocol/CacheRequestType.hh"
54#include "mem/protocol/GenericMachineType.hh"
55#include "mem/protocol/GenericRequestType.hh"
56#include "mem/protocol/PrefetchBit.hh"
57#include "mem/ruby/common/Address.hh"
58#include "mem/ruby/common/Consumer.hh"
59#include "mem/ruby/common/Global.hh"
60#include "mem/ruby/common/Histogram.hh"
61#include "mem/ruby/common/Set.hh"
62#include "mem/ruby/libruby.hh"
63#include "mem/ruby/system/MachineID.hh"
64#include "mem/ruby/system/MemoryControl.hh"
65#include "mem/ruby/system/NodeID.hh"
66#include "params/RubyProfiler.hh"
67#include "sim/sim_object.hh"
68
69class CacheMsg;
70class AddressProfiler;
71
72template <class KEY_TYPE, class VALUE_TYPE> class Map;
73
74class Profiler : public SimObject, public Consumer
75{
76  public:
77    typedef RubyProfilerParams Params;
78    Profiler(const Params *);
79    ~Profiler();
80
81    void wakeup();
82
83    void setPeriodicStatsFile(const std::string& filename);
84    void setPeriodicStatsInterval(integer_t period);
85
86    void printStats(std::ostream& out, bool short_stats=false);
87    void printShortStats(std::ostream& out) { printStats(out, true); }
88    void printTraceStats(std::ostream& out) const;
89    void clearStats();
90    void printConfig(std::ostream& out) const;
91    void printResourceUsage(std::ostream& out) const;
92
93    AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
94    AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
95
96    void addAddressTraceSample(const CacheMsg& msg, NodeID id);
97
98    void profileRequest(const std::string& requestStr);
99    void profileSharing(const Address& addr, AccessType type,
100                        NodeID requestor, const Set& sharers,
101                        const Set& owner);
102
103    void profileMulticastRetry(const Address& addr, int count);
104
105    void profileFilterAction(int action);
106
107    void profileConflictingRequests(const Address& addr);
108
109    void
110    profileOutstandingRequest(int outstanding)
111    {
112        m_outstanding_requests.add(outstanding);
113    }
114
115    void
116    profileOutstandingPersistentRequest(int outstanding)
117    {
118        m_outstanding_persistent_requests.add(outstanding);
119    }
120
121    void
122    profileAverageLatencyEstimate(int latency)
123    {
124        m_average_latency_estimate.add(latency);
125    }
126
127    void recordPrediction(bool wasGood, bool wasPredicted);
128
129    void startTransaction(int cpu);
130    void endTransaction(int cpu);
131    void profilePFWait(Time waitTime);
132
133    void controllerBusy(MachineID machID);
134    void bankBusy();
135    void missLatency(Time t, RubyRequestType type);
136    void swPrefetchLatency(Time t, CacheRequestType type,
137                           GenericMachineType respondingMach);
138    void sequencerRequests(int num) { m_sequencer_requests.add(num); }
139
140    void profileTransition(const std::string& component, NodeID version,
141        Address addr, const std::string& state, const std::string& event,
142        const std::string& next_state, const std::string& note);
143    void profileMsgDelay(int virtualNetwork, int delayCycles);
144
145    void print(std::ostream& out) const;
146
147    void rubyWatch(int proc);
148    bool watchAddress(Address addr);
149
150    // return Ruby's start time
151    Time
152    getRubyStartTime()
153    {
154        return m_ruby_start;
155    }
156
157    // added by SS
158    bool getHotLines() { return m_hot_lines; }
159    bool getAllInstructions() { return m_all_instructions; }
160
161  private:
162    // Private copy constructor and assignment operator
163    Profiler(const Profiler& obj);
164    Profiler& operator=(const Profiler& obj);
165
166    AddressProfiler* m_address_profiler_ptr;
167    AddressProfiler* m_inst_profiler_ptr;
168
169    Vector<int64> m_instructions_executed_at_start;
170    Vector<int64> m_cycles_executed_at_start;
171
172    std::ostream* m_periodic_output_file_ptr;
173    integer_t m_stats_period;
174
175    Time m_ruby_start;
176    time_t m_real_time_start_time;
177
178    Vector <Vector<integer_t> > m_busyControllerCount;
179    integer_t m_busyBankCount;
180    Histogram m_multicast_retry_histogram;
181
182    Histogram m_filter_action_histogram;
183    Histogram m_tbeProfile;
184
185    Histogram m_sequencer_requests;
186    Histogram m_read_sharing_histogram;
187    Histogram m_write_sharing_histogram;
188    Histogram m_all_sharing_histogram;
189    int64 m_cache_to_cache;
190    int64 m_memory_to_cache;
191
192    Histogram m_prefetchWaitHistogram;
193
194    Vector<Histogram> m_missLatencyHistograms;
195    Vector<Histogram> m_machLatencyHistograms;
196    Histogram m_allMissLatencyHistogram;
197
198    Histogram m_allSWPrefetchLatencyHistogram;
199    Histogram m_SWPrefetchL2MissLatencyHistogram;
200    Vector<Histogram> m_SWPrefetchLatencyHistograms;
201    Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
202
203    Histogram m_delayedCyclesHistogram;
204    Histogram m_delayedCyclesNonPFHistogram;
205    Vector<Histogram> m_delayedCyclesVCHistograms;
206
207    Histogram m_outstanding_requests;
208    Histogram m_outstanding_persistent_requests;
209
210    Histogram m_average_latency_estimate;
211
212    Map<Address, int>* m_watch_address_list_ptr;
213    // counts all initiated cache request including PUTs
214    int m_requests;
215    Map <std::string, int>* m_requestProfileMap_ptr;
216
217    //added by SS
218    bool m_hot_lines;
219    bool m_all_instructions;
220
221    int m_num_of_sequencers;
222};
223
224inline std::ostream&
225operator<<(std::ostream& out, const Profiler& obj)
226{
227    obj.print(out);
228    out << std::flush;
229    return out;
230}
231
232#endif // __MEM_RUBY_PROFILER_PROFILER_HH__
233
234
235