Profiler.hh revision 6284
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
306284Snate@binkert.org   This file has been modified by Kevin Moore and Dan Nussbaum of the
316284Snate@binkert.org   Scalable Systems Research Group at Sun Microsystems Laboratories
326284Snate@binkert.org   (http://research.sun.com/scalable/) to support the Adaptive
336284Snate@binkert.org   Transactional Memory Test Platform (ATMTP).
346145Snate@binkert.org
356284Snate@binkert.org   Please send email to atmtp-interest@sun.com with feedback, questions, or
366284Snate@binkert.org   to request future announcements about ATMTP.
376145Snate@binkert.org
386284Snate@binkert.org   ----------------------------------------------------------------------
396145Snate@binkert.org
406284Snate@binkert.org   File modification date: 2008-02-23
416145Snate@binkert.org
426284Snate@binkert.org   ----------------------------------------------------------------------
436145Snate@binkert.org*/
446145Snate@binkert.org
456145Snate@binkert.org/*
466284Snate@binkert.org * Profiler.hh
476145Snate@binkert.org *
486145Snate@binkert.org * Description:
496145Snate@binkert.org *
506145Snate@binkert.org * $Id$
516145Snate@binkert.org *
526145Snate@binkert.org */
536145Snate@binkert.org
546145Snate@binkert.org#ifndef PROFILER_H
556145Snate@binkert.org#define PROFILER_H
566145Snate@binkert.org
576154Snate@binkert.org#include "mem/ruby/common/Global.hh"
586154Snate@binkert.org#include "mem/protocol/GenericMachineType.hh"
596154Snate@binkert.org#include "mem/ruby/config/RubyConfig.hh"
606154Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
616154Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
626154Snate@binkert.org#include "mem/protocol/AccessModeType.hh"
636154Snate@binkert.org#include "mem/protocol/AccessType.hh"
646154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
656154Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
666154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
676154Snate@binkert.org#include "mem/ruby/common/Address.hh"
686154Snate@binkert.org#include "mem/ruby/common/Set.hh"
696154Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
706154Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
716145Snate@binkert.org
726145Snate@binkert.orgclass CacheMsg;
736145Snate@binkert.orgclass CacheProfiler;
746145Snate@binkert.orgclass AddressProfiler;
756145Snate@binkert.org
766145Snate@binkert.orgtemplate <class KEY_TYPE, class VALUE_TYPE> class Map;
776145Snate@binkert.org
786145Snate@binkert.orgclass Profiler : public Consumer {
796145Snate@binkert.orgpublic:
806153Sgibson@cs.wisc.edu    // Constructors
816153Sgibson@cs.wisc.edu    Profiler();
826145Snate@binkert.org
836153Sgibson@cs.wisc.edu    // Destructor
846153Sgibson@cs.wisc.edu    ~Profiler();
856145Snate@binkert.org
866153Sgibson@cs.wisc.edu    // Public Methods
876153Sgibson@cs.wisc.edu    void wakeup();
886145Snate@binkert.org
896153Sgibson@cs.wisc.edu    void setPeriodicStatsFile(const string& filename);
906153Sgibson@cs.wisc.edu    void setPeriodicStatsInterval(integer_t period);
916145Snate@binkert.org
926153Sgibson@cs.wisc.edu    void printStats(ostream& out, bool short_stats=false);
936153Sgibson@cs.wisc.edu    void printShortStats(ostream& out) { printStats(out, true); }
946153Sgibson@cs.wisc.edu    void printTraceStats(ostream& out) const;
956153Sgibson@cs.wisc.edu    void clearStats();
966153Sgibson@cs.wisc.edu    void printConfig(ostream& out) const;
976153Sgibson@cs.wisc.edu    void printResourceUsage(ostream& out) const;
986145Snate@binkert.org
996153Sgibson@cs.wisc.edu    AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
1006153Sgibson@cs.wisc.edu    AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
1016145Snate@binkert.org
1026153Sgibson@cs.wisc.edu    void addPrimaryStatSample(const CacheMsg& msg, NodeID id);
1036153Sgibson@cs.wisc.edu    void addSecondaryStatSample(GenericRequestType requestType,
1046153Sgibson@cs.wisc.edu                                AccessModeType type, int msgSize,
1056153Sgibson@cs.wisc.edu                                PrefetchBit pfBit, NodeID id);
1066153Sgibson@cs.wisc.edu    void addSecondaryStatSample(CacheRequestType requestType,
1076153Sgibson@cs.wisc.edu                                AccessModeType type, int msgSize,
1086153Sgibson@cs.wisc.edu                                PrefetchBit pfBit, NodeID id);
1096153Sgibson@cs.wisc.edu    void addAddressTraceSample(const CacheMsg& msg, NodeID id);
1106145Snate@binkert.org
1116153Sgibson@cs.wisc.edu    void profileRequest(const string& requestStr);
1126153Sgibson@cs.wisc.edu    void profileSharing(const Address& addr, AccessType type,
1136153Sgibson@cs.wisc.edu                        NodeID requestor, const Set& sharers,
1146153Sgibson@cs.wisc.edu                        const Set& owner);
1156145Snate@binkert.org
1166153Sgibson@cs.wisc.edu    void profileMulticastRetry(const Address& addr, int count);
1176145Snate@binkert.org
1186153Sgibson@cs.wisc.edu    void profileFilterAction(int action);
1196145Snate@binkert.org
1206153Sgibson@cs.wisc.edu    void profileConflictingRequests(const Address& addr);
1216153Sgibson@cs.wisc.edu    void profileOutstandingRequest(int outstanding) {
1226153Sgibson@cs.wisc.edu        m_outstanding_requests.add(outstanding);
1236153Sgibson@cs.wisc.edu    }
1246145Snate@binkert.org
1256153Sgibson@cs.wisc.edu    void profileOutstandingPersistentRequest(int outstanding) {
1266153Sgibson@cs.wisc.edu        m_outstanding_persistent_requests.add(outstanding);
1276153Sgibson@cs.wisc.edu    }
1286153Sgibson@cs.wisc.edu    void profileAverageLatencyEstimate(int latency) {
1296153Sgibson@cs.wisc.edu        m_average_latency_estimate.add(latency);
1306153Sgibson@cs.wisc.edu    }
1316145Snate@binkert.org
1326153Sgibson@cs.wisc.edu    void countBAUnicast() { m_num_BA_unicasts++; }
1336153Sgibson@cs.wisc.edu    void countBABroadcast() { m_num_BA_broadcasts++; }
1346145Snate@binkert.org
1356153Sgibson@cs.wisc.edu    void recordPrediction(bool wasGood, bool wasPredicted);
1366145Snate@binkert.org
1376153Sgibson@cs.wisc.edu    void startTransaction(int cpu);
1386153Sgibson@cs.wisc.edu    void endTransaction(int cpu);
1396153Sgibson@cs.wisc.edu    void profilePFWait(Time waitTime);
1406145Snate@binkert.org
1416153Sgibson@cs.wisc.edu    void controllerBusy(MachineID machID);
1426153Sgibson@cs.wisc.edu    void bankBusy();
1436153Sgibson@cs.wisc.edu    void missLatency(Time t, CacheRequestType type,
1446153Sgibson@cs.wisc.edu                     GenericMachineType respondingMach);
1456153Sgibson@cs.wisc.edu    void swPrefetchLatency(Time t, CacheRequestType type,
1466153Sgibson@cs.wisc.edu                           GenericMachineType respondingMach);
1476153Sgibson@cs.wisc.edu    void stopTableUsageSample(int num) { m_stopTableProfile.add(num); }
1486153Sgibson@cs.wisc.edu    void L1tbeUsageSample(int num) { m_L1tbeProfile.add(num); }
1496153Sgibson@cs.wisc.edu    void L2tbeUsageSample(int num) { m_L2tbeProfile.add(num); }
1506153Sgibson@cs.wisc.edu    void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1516153Sgibson@cs.wisc.edu    void storeBuffer(int size, int blocks) {
1526153Sgibson@cs.wisc.edu        m_store_buffer_size.add(size);
1536153Sgibson@cs.wisc.edu        m_store_buffer_blocks.add(blocks);
1546153Sgibson@cs.wisc.edu    }
1556145Snate@binkert.org
1566153Sgibson@cs.wisc.edu    void profileGetXMaskPrediction(const Set& pred_set);
1576153Sgibson@cs.wisc.edu    void profileGetSMaskPrediction(const Set& pred_set);
1586153Sgibson@cs.wisc.edu    void profileTrainingMask(const Set& pred_set);
1596153Sgibson@cs.wisc.edu    void profileTransition(const string& component, NodeID id, NodeID version,
1606153Sgibson@cs.wisc.edu                           Address addr, const string& state,
1616153Sgibson@cs.wisc.edu                           const string& event, const string& next_state,
1626153Sgibson@cs.wisc.edu                           const string& note);
1636153Sgibson@cs.wisc.edu    void profileMsgDelay(int virtualNetwork, int delayCycles);
1646145Snate@binkert.org
1656153Sgibson@cs.wisc.edu    void print(ostream& out) const;
1666145Snate@binkert.org
1676153Sgibson@cs.wisc.edu    int64 getTotalInstructionsExecuted() const;
1686153Sgibson@cs.wisc.edu    int64 getTotalTransactionsExecuted() const;
1696145Snate@binkert.org
1706153Sgibson@cs.wisc.edu    Time getRubyStartTime(){
1716153Sgibson@cs.wisc.edu      return m_ruby_start;
1726153Sgibson@cs.wisc.edu    }
1736145Snate@binkert.org
1746153Sgibson@cs.wisc.edu    // added for MemoryControl:
1756153Sgibson@cs.wisc.edu    void profileMemReq(int bank);
1766153Sgibson@cs.wisc.edu    void profileMemBankBusy();
1776153Sgibson@cs.wisc.edu    void profileMemBusBusy();
1786153Sgibson@cs.wisc.edu    void profileMemTfawBusy();
1796153Sgibson@cs.wisc.edu    void profileMemReadWriteBusy();
1806153Sgibson@cs.wisc.edu    void profileMemDataBusBusy();
1816153Sgibson@cs.wisc.edu    void profileMemRefresh();
1826153Sgibson@cs.wisc.edu    void profileMemRead();
1836153Sgibson@cs.wisc.edu    void profileMemWrite();
1846153Sgibson@cs.wisc.edu    void profileMemWaitCycles(int cycles);
1856153Sgibson@cs.wisc.edu    void profileMemInputQ(int cycles);
1866153Sgibson@cs.wisc.edu    void profileMemBankQ(int cycles);
1876153Sgibson@cs.wisc.edu    void profileMemArbWait(int cycles);
1886153Sgibson@cs.wisc.edu    void profileMemRandBusy();
1896153Sgibson@cs.wisc.edu    void profileMemNotOld();
1906145Snate@binkert.org
1916145Snate@binkert.orgprivate:
1926153Sgibson@cs.wisc.edu    // Private Methods
1936153Sgibson@cs.wisc.edu    void addL2StatSample(GenericRequestType requestType, AccessModeType type,
1946153Sgibson@cs.wisc.edu                         int msgSize, PrefetchBit pfBit, NodeID id);
1956153Sgibson@cs.wisc.edu    void addL1DStatSample(const CacheMsg& msg, NodeID id);
1966153Sgibson@cs.wisc.edu    void addL1IStatSample(const CacheMsg& msg, NodeID id);
1976145Snate@binkert.org
1986153Sgibson@cs.wisc.edu    GenericRequestType CacheRequestType_to_GenericRequestType(const CacheRequestType& type);
1996145Snate@binkert.org
2006153Sgibson@cs.wisc.edu    // Private copy constructor and assignment operator
2016153Sgibson@cs.wisc.edu    Profiler(const Profiler& obj);
2026153Sgibson@cs.wisc.edu    Profiler& operator=(const Profiler& obj);
2036145Snate@binkert.org
2046153Sgibson@cs.wisc.edu    // Data Members (m_ prefix)
2056153Sgibson@cs.wisc.edu    CacheProfiler* m_L1D_cache_profiler_ptr;
2066153Sgibson@cs.wisc.edu    CacheProfiler* m_L1I_cache_profiler_ptr;
2076153Sgibson@cs.wisc.edu    CacheProfiler* m_L2_cache_profiler_ptr;
2086153Sgibson@cs.wisc.edu    AddressProfiler* m_address_profiler_ptr;
2096153Sgibson@cs.wisc.edu    AddressProfiler* m_inst_profiler_ptr;
2106145Snate@binkert.org
2116153Sgibson@cs.wisc.edu    Vector<int64> m_instructions_executed_at_start;
2126153Sgibson@cs.wisc.edu    Vector<int64> m_cycles_executed_at_start;
2136145Snate@binkert.org
2146153Sgibson@cs.wisc.edu    ostream* m_periodic_output_file_ptr;
2156153Sgibson@cs.wisc.edu    integer_t m_stats_period;
2166145Snate@binkert.org
2176153Sgibson@cs.wisc.edu    Time m_ruby_start;
2186153Sgibson@cs.wisc.edu    time_t m_real_time_start_time;
2196145Snate@binkert.org
2206153Sgibson@cs.wisc.edu    int m_num_BA_unicasts;
2216153Sgibson@cs.wisc.edu    int m_num_BA_broadcasts;
2226145Snate@binkert.org
2236153Sgibson@cs.wisc.edu    Vector<integer_t> m_perProcTotalMisses;
2246153Sgibson@cs.wisc.edu    Vector<integer_t> m_perProcUserMisses;
2256153Sgibson@cs.wisc.edu    Vector<integer_t> m_perProcSupervisorMisses;
2266153Sgibson@cs.wisc.edu    Vector<integer_t> m_perProcStartTransaction;
2276153Sgibson@cs.wisc.edu    Vector<integer_t> m_perProcEndTransaction;
2286153Sgibson@cs.wisc.edu    Vector < Vector < integer_t > > m_busyControllerCount;
2296153Sgibson@cs.wisc.edu    integer_t m_busyBankCount;
2306153Sgibson@cs.wisc.edu    Histogram m_multicast_retry_histogram;
2316145Snate@binkert.org
2326153Sgibson@cs.wisc.edu    Histogram m_L1tbeProfile;
2336153Sgibson@cs.wisc.edu    Histogram m_L2tbeProfile;
2346153Sgibson@cs.wisc.edu    Histogram m_stopTableProfile;
2356145Snate@binkert.org
2366153Sgibson@cs.wisc.edu    Histogram m_filter_action_histogram;
2376153Sgibson@cs.wisc.edu    Histogram m_tbeProfile;
2386145Snate@binkert.org
2396153Sgibson@cs.wisc.edu    Histogram m_sequencer_requests;
2406153Sgibson@cs.wisc.edu    Histogram m_store_buffer_size;
2416153Sgibson@cs.wisc.edu    Histogram m_store_buffer_blocks;
2426153Sgibson@cs.wisc.edu    Histogram m_read_sharing_histogram;
2436153Sgibson@cs.wisc.edu    Histogram m_write_sharing_histogram;
2446153Sgibson@cs.wisc.edu    Histogram m_all_sharing_histogram;
2456153Sgibson@cs.wisc.edu    int64 m_cache_to_cache;
2466153Sgibson@cs.wisc.edu    int64 m_memory_to_cache;
2476145Snate@binkert.org
2486153Sgibson@cs.wisc.edu    Histogram m_prefetchWaitHistogram;
2496145Snate@binkert.org
2506153Sgibson@cs.wisc.edu    Vector<Histogram> m_missLatencyHistograms;
2516153Sgibson@cs.wisc.edu    Vector<Histogram> m_machLatencyHistograms;
2526153Sgibson@cs.wisc.edu    Histogram m_L2MissLatencyHistogram;
2536153Sgibson@cs.wisc.edu    Histogram m_allMissLatencyHistogram;
2546145Snate@binkert.org
2556153Sgibson@cs.wisc.edu    Histogram  m_allSWPrefetchLatencyHistogram;
2566153Sgibson@cs.wisc.edu    Histogram  m_SWPrefetchL2MissLatencyHistogram;
2576153Sgibson@cs.wisc.edu    Vector<Histogram> m_SWPrefetchLatencyHistograms;
2586153Sgibson@cs.wisc.edu    Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2596145Snate@binkert.org
2606153Sgibson@cs.wisc.edu    Histogram m_delayedCyclesHistogram;
2616153Sgibson@cs.wisc.edu    Histogram m_delayedCyclesNonPFHistogram;
2626153Sgibson@cs.wisc.edu    Vector<Histogram> m_delayedCyclesVCHistograms;
2636145Snate@binkert.org
2646153Sgibson@cs.wisc.edu    int m_predictions;
2656153Sgibson@cs.wisc.edu    int m_predictionOpportunities;
2666153Sgibson@cs.wisc.edu    int m_goodPredictions;
2676145Snate@binkert.org
2686153Sgibson@cs.wisc.edu    Histogram m_gets_mask_prediction;
2696153Sgibson@cs.wisc.edu    Histogram m_getx_mask_prediction;
2706153Sgibson@cs.wisc.edu    Histogram m_explicit_training_mask;
2716145Snate@binkert.org
2726153Sgibson@cs.wisc.edu    // For profiling possibly conflicting requests
2736153Sgibson@cs.wisc.edu    Map<Address, Time>* m_conflicting_map_ptr;
2746153Sgibson@cs.wisc.edu    Histogram m_conflicting_histogram;
2756145Snate@binkert.org
2766153Sgibson@cs.wisc.edu    Histogram m_outstanding_requests;
2776153Sgibson@cs.wisc.edu    Histogram m_outstanding_persistent_requests;
2786145Snate@binkert.org
2796153Sgibson@cs.wisc.edu    Histogram m_average_latency_estimate;
2806145Snate@binkert.org
2816153Sgibson@cs.wisc.edu    Map<Address, int>* m_watch_address_list_ptr;
2826153Sgibson@cs.wisc.edu    // counts all initiated cache request including PUTs
2836153Sgibson@cs.wisc.edu    int m_requests;
2846153Sgibson@cs.wisc.edu    Map <string, int>* m_requestProfileMap_ptr;
2856145Snate@binkert.org
2866153Sgibson@cs.wisc.edu    // added for MemoryControl:
2876153Sgibson@cs.wisc.edu    long long int m_memReq;
2886153Sgibson@cs.wisc.edu    long long int m_memBankBusy;
2896153Sgibson@cs.wisc.edu    long long int m_memBusBusy;
2906153Sgibson@cs.wisc.edu    long long int m_memTfawBusy;
2916153Sgibson@cs.wisc.edu    long long int m_memReadWriteBusy;
2926153Sgibson@cs.wisc.edu    long long int m_memDataBusBusy;
2936153Sgibson@cs.wisc.edu    long long int m_memRefresh;
2946153Sgibson@cs.wisc.edu    long long int m_memRead;
2956153Sgibson@cs.wisc.edu    long long int m_memWrite;
2966153Sgibson@cs.wisc.edu    long long int m_memWaitCycles;
2976153Sgibson@cs.wisc.edu    long long int m_memInputQ;
2986153Sgibson@cs.wisc.edu    long long int m_memBankQ;
2996153Sgibson@cs.wisc.edu    long long int m_memArbWait;
3006153Sgibson@cs.wisc.edu    long long int m_memRandBusy;
3016153Sgibson@cs.wisc.edu    long long int m_memNotOld;
3026153Sgibson@cs.wisc.edu    Vector<long long int> m_memBankCount;
3036145Snate@binkert.org
3046145Snate@binkert.org};
3056145Snate@binkert.org
3066145Snate@binkert.org// Output operator declaration
3076145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj);
3086145Snate@binkert.org
3096145Snate@binkert.org// ******************* Definitions *******************
3106145Snate@binkert.org
3116145Snate@binkert.org// Output operator definition
3126145Snate@binkert.orgextern inline
3136145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj)
3146145Snate@binkert.org{
3156153Sgibson@cs.wisc.edu    obj.print(out);
3166153Sgibson@cs.wisc.edu    out << flush;
3176153Sgibson@cs.wisc.edu    return out;
3186145Snate@binkert.org}
3196145Snate@binkert.org
3206145Snate@binkert.org#endif //PROFILER_H
3216145Snate@binkert.org
3226145Snate@binkert.org
323