Profiler.hh revision 6285
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
576285Snate@binkert.org#include "mem/ruby/libruby.hh"
586285Snate@binkert.org
596154Snate@binkert.org#include "mem/ruby/common/Global.hh"
606154Snate@binkert.org#include "mem/protocol/GenericMachineType.hh"
616154Snate@binkert.org#include "mem/ruby/config/RubyConfig.hh"
626154Snate@binkert.org#include "mem/ruby/common/Histogram.hh"
636154Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
646154Snate@binkert.org#include "mem/protocol/AccessModeType.hh"
656154Snate@binkert.org#include "mem/protocol/AccessType.hh"
666154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
676154Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
686154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
696154Snate@binkert.org#include "mem/ruby/common/Address.hh"
706154Snate@binkert.org#include "mem/ruby/common/Set.hh"
716154Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
726154Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
736285Snate@binkert.org#include "mem/ruby/system/MemoryControl.hh"
746145Snate@binkert.org
756145Snate@binkert.orgclass CacheMsg;
766145Snate@binkert.orgclass CacheProfiler;
776145Snate@binkert.orgclass AddressProfiler;
786145Snate@binkert.org
796145Snate@binkert.orgtemplate <class KEY_TYPE, class VALUE_TYPE> class Map;
806145Snate@binkert.org
816285Snate@binkert.orgstruct memory_control_profiler {
826285Snate@binkert.org  long long int m_memReq;
836285Snate@binkert.org  long long int m_memBankBusy;
846285Snate@binkert.org  long long int m_memBusBusy;
856285Snate@binkert.org  long long int m_memTfawBusy;
866285Snate@binkert.org  long long int m_memReadWriteBusy;
876285Snate@binkert.org  long long int m_memDataBusBusy;
886285Snate@binkert.org  long long int m_memRefresh;
896285Snate@binkert.org  long long int m_memRead;
906285Snate@binkert.org  long long int m_memWrite;
916285Snate@binkert.org  long long int m_memWaitCycles;
926285Snate@binkert.org  long long int m_memInputQ;
936285Snate@binkert.org  long long int m_memBankQ;
946285Snate@binkert.org  long long int m_memArbWait;
956285Snate@binkert.org  long long int m_memRandBusy;
966285Snate@binkert.org  long long int m_memNotOld;
976285Snate@binkert.org  Vector<long long int> m_memBankCount;
986285Snate@binkert.org  int m_banks_per_rank;
996285Snate@binkert.org  int m_ranks_per_dimm;
1006285Snate@binkert.org  int m_dimms_per_channel;
1016285Snate@binkert.org};
1026285Snate@binkert.org
1036285Snate@binkert.org
1046145Snate@binkert.orgclass Profiler : public Consumer {
1056145Snate@binkert.orgpublic:
1066285Snate@binkert.org  // Constructors
1076285Snate@binkert.org  Profiler(const string & name);
1086145Snate@binkert.org
1096285Snate@binkert.org  void init(const vector<string> & argv, vector<string> memory_control_names);
1106145Snate@binkert.org
1116285Snate@binkert.org  // Destructor
1126285Snate@binkert.org  ~Profiler();
1136145Snate@binkert.org
1146285Snate@binkert.org  // Public Methods
1156285Snate@binkert.org  void wakeup();
1166145Snate@binkert.org
1176285Snate@binkert.org  void setPeriodicStatsFile(const string& filename);
1186285Snate@binkert.org  void setPeriodicStatsInterval(integer_t period);
1196145Snate@binkert.org
1206285Snate@binkert.org  void printStats(ostream& out, bool short_stats=false);
1216285Snate@binkert.org  void printShortStats(ostream& out) { printStats(out, true); }
1226285Snate@binkert.org  void printTraceStats(ostream& out) const;
1236285Snate@binkert.org  void clearStats();
1246285Snate@binkert.org  void printConfig(ostream& out) const;
1256285Snate@binkert.org  void printResourceUsage(ostream& out) const;
1266145Snate@binkert.org
1276285Snate@binkert.org  AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
1286285Snate@binkert.org  AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
1296145Snate@binkert.org
1306285Snate@binkert.org  void addPrimaryStatSample(const CacheMsg& msg, NodeID id);
1316285Snate@binkert.org  void addSecondaryStatSample(GenericRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id);
1326285Snate@binkert.org  void addSecondaryStatSample(CacheRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id);
1336285Snate@binkert.org  void addAddressTraceSample(const CacheMsg& msg, NodeID id);
1346145Snate@binkert.org
1356285Snate@binkert.org  void profileRequest(const string& requestStr);
1366285Snate@binkert.org  void profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner);
1376145Snate@binkert.org
1386285Snate@binkert.org  void profileMulticastRetry(const Address& addr, int count);
1396145Snate@binkert.org
1406285Snate@binkert.org  void profileFilterAction(int action);
1416145Snate@binkert.org
1426285Snate@binkert.org  void profileConflictingRequests(const Address& addr);
1436285Snate@binkert.org  void profileOutstandingRequest(int outstanding) { m_outstanding_requests.add(outstanding); }
1446285Snate@binkert.org  void profileOutstandingPersistentRequest(int outstanding) { m_outstanding_persistent_requests.add(outstanding); }
1456285Snate@binkert.org  void profileAverageLatencyEstimate(int latency) { m_average_latency_estimate.add(latency); }
1466145Snate@binkert.org
1476285Snate@binkert.org  void countBAUnicast() { m_num_BA_unicasts++; }
1486285Snate@binkert.org  void countBABroadcast() { m_num_BA_broadcasts++; }
1496145Snate@binkert.org
1506285Snate@binkert.org  void recordPrediction(bool wasGood, bool wasPredicted);
1516145Snate@binkert.org
1526285Snate@binkert.org  void startTransaction(int cpu);
1536285Snate@binkert.org  void endTransaction(int cpu);
1546285Snate@binkert.org  void profilePFWait(Time waitTime);
1556145Snate@binkert.org
1566285Snate@binkert.org  void controllerBusy(MachineID machID);
1576285Snate@binkert.org  void bankBusy();
1586285Snate@binkert.org  void missLatency(Time t, RubyRequestType type);
1596285Snate@binkert.org  void swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach);
1606285Snate@binkert.org  void stopTableUsageSample(int num) { m_stopTableProfile.add(num); }
1616285Snate@binkert.org  void L1tbeUsageSample(int num) { m_L1tbeProfile.add(num); }
1626285Snate@binkert.org  void L2tbeUsageSample(int num) { m_L2tbeProfile.add(num); }
1636285Snate@binkert.org  void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1646285Snate@binkert.org  void storeBuffer(int size, int blocks) { m_store_buffer_size.add(size); m_store_buffer_blocks.add(blocks);}
1656145Snate@binkert.org
1666285Snate@binkert.org  void profileGetXMaskPrediction(const Set& pred_set);
1676285Snate@binkert.org  void profileGetSMaskPrediction(const Set& pred_set);
1686285Snate@binkert.org  void profileTrainingMask(const Set& pred_set);
1696285Snate@binkert.org  void profileTransition(const string& component, NodeID version, Address addr,
1706285Snate@binkert.org                         const string& state, const string& event,
1716285Snate@binkert.org                         const string& next_state, const string& note);
1726285Snate@binkert.org  void profileMsgDelay(int virtualNetwork, int delayCycles);
1736145Snate@binkert.org
1746285Snate@binkert.org  void print(ostream& out) const;
1756145Snate@binkert.org
1766285Snate@binkert.org  int64 getTotalInstructionsExecuted() const;
1776285Snate@binkert.org  int64 getTotalTransactionsExecuted() const;
1786145Snate@binkert.org
1796285Snate@binkert.org  void rubyWatch(int proc);
1806285Snate@binkert.org  bool watchAddress(Address addr);
1816145Snate@binkert.org
1826285Snate@binkert.org  // return Ruby's start time
1836285Snate@binkert.org  Time getRubyStartTime(){
1846285Snate@binkert.org    return m_ruby_start;
1856285Snate@binkert.org  }
1866285Snate@binkert.org
1876285Snate@binkert.org  // added for MemoryControl:
1886285Snate@binkert.org  void profileMemReq(string name, int bank);
1896285Snate@binkert.org  void profileMemBankBusy(string name);
1906285Snate@binkert.org  void profileMemBusBusy(string name);
1916285Snate@binkert.org  void profileMemTfawBusy(string name);
1926285Snate@binkert.org  void profileMemReadWriteBusy(string name);
1936285Snate@binkert.org  void profileMemDataBusBusy(string name);
1946285Snate@binkert.org  void profileMemRefresh(string name);
1956285Snate@binkert.org  void profileMemRead(string name);
1966285Snate@binkert.org  void profileMemWrite(string name);
1976285Snate@binkert.org  void profileMemWaitCycles(string name, int cycles);
1986285Snate@binkert.org  void profileMemInputQ(string name, int cycles);
1996285Snate@binkert.org  void profileMemBankQ(string name, int cycles);
2006285Snate@binkert.org  void profileMemArbWait(string name, int cycles);
2016285Snate@binkert.org  void profileMemRandBusy(string name);
2026285Snate@binkert.org  void profileMemNotOld(string name);
2036285Snate@binkert.org  //added by SS
2046285Snate@binkert.org  bool getHotLines() { return m_hot_lines; }
2056285Snate@binkert.org  bool getAllInstructions() { return m_all_instructions; }
2066145Snate@binkert.org
2076145Snate@binkert.orgprivate:
2086285Snate@binkert.org  //added by SS
2096285Snate@binkert.org  vector<string> m_memory_control_names;
2106285Snate@binkert.org  // Private Methods
2116285Snate@binkert.org  void addL2StatSample(GenericRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id);
2126285Snate@binkert.org  void addL1DStatSample(const CacheMsg& msg, NodeID id);
2136285Snate@binkert.org  void addL1IStatSample(const CacheMsg& msg, NodeID id);
2146145Snate@binkert.org
2156285Snate@binkert.org  GenericRequestType CacheRequestType_to_GenericRequestType(const CacheRequestType& type);
2166145Snate@binkert.org
2176285Snate@binkert.org  // Private copy constructor and assignment operator
2186285Snate@binkert.org  Profiler(const Profiler& obj);
2196285Snate@binkert.org  Profiler& operator=(const Profiler& obj);
2206145Snate@binkert.org
2216285Snate@binkert.org  // Data Members (m_ prefix)
2226285Snate@binkert.org  CacheProfiler* m_L1D_cache_profiler_ptr;
2236285Snate@binkert.org  CacheProfiler* m_L1I_cache_profiler_ptr;
2246285Snate@binkert.org  CacheProfiler* m_L2_cache_profiler_ptr;
2256285Snate@binkert.org  AddressProfiler* m_address_profiler_ptr;
2266285Snate@binkert.org  AddressProfiler* m_inst_profiler_ptr;
2276145Snate@binkert.org
2286285Snate@binkert.org  Vector<int64> m_instructions_executed_at_start;
2296285Snate@binkert.org  Vector<int64> m_cycles_executed_at_start;
2306145Snate@binkert.org
2316285Snate@binkert.org  ostream* m_periodic_output_file_ptr;
2326285Snate@binkert.org  integer_t m_stats_period;
2336145Snate@binkert.org
2346285Snate@binkert.org  Time m_ruby_start;
2356285Snate@binkert.org  time_t m_real_time_start_time;
2366145Snate@binkert.org
2376285Snate@binkert.org  int m_num_BA_unicasts;
2386285Snate@binkert.org  int m_num_BA_broadcasts;
2396145Snate@binkert.org
2406285Snate@binkert.org  Vector<integer_t> m_perProcTotalMisses;
2416285Snate@binkert.org  Vector<integer_t> m_perProcUserMisses;
2426285Snate@binkert.org  Vector<integer_t> m_perProcSupervisorMisses;
2436285Snate@binkert.org  Vector<integer_t> m_perProcStartTransaction;
2446285Snate@binkert.org  Vector<integer_t> m_perProcEndTransaction;
2456285Snate@binkert.org  Vector < Vector < integer_t > > m_busyControllerCount;
2466285Snate@binkert.org  integer_t m_busyBankCount;
2476285Snate@binkert.org  Histogram m_multicast_retry_histogram;
2486145Snate@binkert.org
2496285Snate@binkert.org  Histogram m_L1tbeProfile;
2506285Snate@binkert.org  Histogram m_L2tbeProfile;
2516285Snate@binkert.org  Histogram m_stopTableProfile;
2526145Snate@binkert.org
2536285Snate@binkert.org  Histogram m_filter_action_histogram;
2546285Snate@binkert.org  Histogram m_tbeProfile;
2556145Snate@binkert.org
2566285Snate@binkert.org  Histogram m_sequencer_requests;
2576285Snate@binkert.org  Histogram m_store_buffer_size;
2586285Snate@binkert.org  Histogram m_store_buffer_blocks;
2596285Snate@binkert.org  Histogram m_read_sharing_histogram;
2606285Snate@binkert.org  Histogram m_write_sharing_histogram;
2616285Snate@binkert.org  Histogram m_all_sharing_histogram;
2626285Snate@binkert.org  int64 m_cache_to_cache;
2636285Snate@binkert.org  int64 m_memory_to_cache;
2646145Snate@binkert.org
2656285Snate@binkert.org  Histogram m_prefetchWaitHistogram;
2666145Snate@binkert.org
2676285Snate@binkert.org  Vector<Histogram> m_missLatencyHistograms;
2686285Snate@binkert.org  Vector<Histogram> m_machLatencyHistograms;
2696285Snate@binkert.org  Histogram m_L2MissLatencyHistogram;
2706285Snate@binkert.org  Histogram m_allMissLatencyHistogram;
2716145Snate@binkert.org
2726285Snate@binkert.org  Histogram  m_allSWPrefetchLatencyHistogram;
2736285Snate@binkert.org  Histogram  m_SWPrefetchL2MissLatencyHistogram;
2746285Snate@binkert.org  Vector<Histogram> m_SWPrefetchLatencyHistograms;
2756285Snate@binkert.org  Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2766145Snate@binkert.org
2776285Snate@binkert.org  Histogram m_delayedCyclesHistogram;
2786285Snate@binkert.org  Histogram m_delayedCyclesNonPFHistogram;
2796285Snate@binkert.org  Vector<Histogram> m_delayedCyclesVCHistograms;
2806145Snate@binkert.org
2816285Snate@binkert.org  int m_predictions;
2826285Snate@binkert.org  int m_predictionOpportunities;
2836285Snate@binkert.org  int m_goodPredictions;
2846145Snate@binkert.org
2856285Snate@binkert.org  Histogram m_gets_mask_prediction;
2866285Snate@binkert.org  Histogram m_getx_mask_prediction;
2876285Snate@binkert.org  Histogram m_explicit_training_mask;
2886145Snate@binkert.org
2896285Snate@binkert.org  // For profiling possibly conflicting requests
2906285Snate@binkert.org  Map<Address, Time>* m_conflicting_map_ptr;
2916285Snate@binkert.org  Histogram m_conflicting_histogram;
2926145Snate@binkert.org
2936285Snate@binkert.org  Histogram m_outstanding_requests;
2946285Snate@binkert.org  Histogram m_outstanding_persistent_requests;
2956145Snate@binkert.org
2966285Snate@binkert.org  Histogram m_average_latency_estimate;
2976145Snate@binkert.org
2986285Snate@binkert.org  Map<Address, int>* m_watch_address_list_ptr;
2996285Snate@binkert.org  // counts all initiated cache request including PUTs
3006285Snate@binkert.org  int m_requests;
3016285Snate@binkert.org  Map <string, int>* m_requestProfileMap_ptr;
3026145Snate@binkert.org
3036285Snate@binkert.org  // added for MemoryControl:
3046285Snate@binkert.org  //added by SS
3056285Snate@binkert.org  map< string, memory_control_profiler* > m_memory_control_profilers;
3066285Snate@binkert.org
3076285Snate@binkert.org  //added by SS
3086285Snate@binkert.org  bool m_hot_lines;
3096285Snate@binkert.org  bool m_all_instructions;
3106285Snate@binkert.org  string m_name;
3116145Snate@binkert.org
3126145Snate@binkert.org};
3136145Snate@binkert.org
3146145Snate@binkert.org// Output operator declaration
3156145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj);
3166145Snate@binkert.org
3176145Snate@binkert.org// ******************* Definitions *******************
3186145Snate@binkert.org
3196145Snate@binkert.org// Output operator definition
3206145Snate@binkert.orgextern inline
3216145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj)
3226145Snate@binkert.org{
3236285Snate@binkert.org  obj.print(out);
3246285Snate@binkert.org  out << flush;
3256285Snate@binkert.org  return out;
3266145Snate@binkert.org}
3276145Snate@binkert.org
3286145Snate@binkert.org#endif //PROFILER_H
3296145Snate@binkert.org
3306145Snate@binkert.org
331