Profiler.hh revision 6876
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/common/Histogram.hh"
626154Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
636154Snate@binkert.org#include "mem/protocol/AccessModeType.hh"
646154Snate@binkert.org#include "mem/protocol/AccessType.hh"
656154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
666154Snate@binkert.org#include "mem/ruby/system/MachineID.hh"
676154Snate@binkert.org#include "mem/protocol/PrefetchBit.hh"
686154Snate@binkert.org#include "mem/ruby/common/Address.hh"
696154Snate@binkert.org#include "mem/ruby/common/Set.hh"
706154Snate@binkert.org#include "mem/protocol/CacheRequestType.hh"
716154Snate@binkert.org#include "mem/protocol/GenericRequestType.hh"
726285Snate@binkert.org#include "mem/ruby/system/MemoryControl.hh"
736145Snate@binkert.org
746876Ssteve.reinhardt@amd.com#include "params/RubyProfiler.hh"
756876Ssteve.reinhardt@amd.com#include "sim/sim_object.hh"
766876Ssteve.reinhardt@amd.com
776145Snate@binkert.orgclass CacheMsg;
786145Snate@binkert.orgclass AddressProfiler;
796145Snate@binkert.org
806145Snate@binkert.orgtemplate <class KEY_TYPE, class VALUE_TYPE> class Map;
816145Snate@binkert.org
826285Snate@binkert.orgstruct memory_control_profiler {
836285Snate@binkert.org  long long int m_memReq;
846285Snate@binkert.org  long long int m_memBankBusy;
856285Snate@binkert.org  long long int m_memBusBusy;
866285Snate@binkert.org  long long int m_memTfawBusy;
876285Snate@binkert.org  long long int m_memReadWriteBusy;
886285Snate@binkert.org  long long int m_memDataBusBusy;
896285Snate@binkert.org  long long int m_memRefresh;
906285Snate@binkert.org  long long int m_memRead;
916285Snate@binkert.org  long long int m_memWrite;
926285Snate@binkert.org  long long int m_memWaitCycles;
936285Snate@binkert.org  long long int m_memInputQ;
946285Snate@binkert.org  long long int m_memBankQ;
956285Snate@binkert.org  long long int m_memArbWait;
966285Snate@binkert.org  long long int m_memRandBusy;
976285Snate@binkert.org  long long int m_memNotOld;
986285Snate@binkert.org  Vector<long long int> m_memBankCount;
996285Snate@binkert.org  int m_banks_per_rank;
1006285Snate@binkert.org  int m_ranks_per_dimm;
1016285Snate@binkert.org  int m_dimms_per_channel;
1026285Snate@binkert.org};
1036285Snate@binkert.org
1046285Snate@binkert.org
1056876Ssteve.reinhardt@amd.comclass Profiler : public SimObject, public Consumer {
1066145Snate@binkert.orgpublic:
1076285Snate@binkert.org  // Constructors
1086876Ssteve.reinhardt@amd.com    typedef RubyProfilerParams Params;
1096876Ssteve.reinhardt@amd.com  Profiler(const Params *);
1106145Snate@binkert.org
1116285Snate@binkert.org  void init(const vector<string> & argv, vector<string> memory_control_names);
1126145Snate@binkert.org
1136285Snate@binkert.org  // Destructor
1146285Snate@binkert.org  ~Profiler();
1156145Snate@binkert.org
1166285Snate@binkert.org  // Public Methods
1176285Snate@binkert.org  void wakeup();
1186145Snate@binkert.org
1196285Snate@binkert.org  void setPeriodicStatsFile(const string& filename);
1206285Snate@binkert.org  void setPeriodicStatsInterval(integer_t period);
1216145Snate@binkert.org
1226285Snate@binkert.org  void printStats(ostream& out, bool short_stats=false);
1236285Snate@binkert.org  void printShortStats(ostream& out) { printStats(out, true); }
1246285Snate@binkert.org  void printTraceStats(ostream& out) const;
1256285Snate@binkert.org  void clearStats();
1266285Snate@binkert.org  void printConfig(ostream& out) const;
1276285Snate@binkert.org  void printResourceUsage(ostream& out) const;
1286145Snate@binkert.org
1296285Snate@binkert.org  AddressProfiler* getAddressProfiler() { return m_address_profiler_ptr; }
1306285Snate@binkert.org  AddressProfiler* getInstructionProfiler() { return m_inst_profiler_ptr; }
1316145Snate@binkert.org
1326285Snate@binkert.org  void addAddressTraceSample(const CacheMsg& msg, NodeID id);
1336145Snate@binkert.org
1346285Snate@binkert.org  void profileRequest(const string& requestStr);
1356285Snate@binkert.org  void profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner);
1366145Snate@binkert.org
1376285Snate@binkert.org  void profileMulticastRetry(const Address& addr, int count);
1386145Snate@binkert.org
1396285Snate@binkert.org  void profileFilterAction(int action);
1406145Snate@binkert.org
1416285Snate@binkert.org  void profileConflictingRequests(const Address& addr);
1426285Snate@binkert.org  void profileOutstandingRequest(int outstanding) { m_outstanding_requests.add(outstanding); }
1436285Snate@binkert.org  void profileOutstandingPersistentRequest(int outstanding) { m_outstanding_persistent_requests.add(outstanding); }
1446285Snate@binkert.org  void profileAverageLatencyEstimate(int latency) { m_average_latency_estimate.add(latency); }
1456145Snate@binkert.org
1466285Snate@binkert.org  void recordPrediction(bool wasGood, bool wasPredicted);
1476145Snate@binkert.org
1486285Snate@binkert.org  void startTransaction(int cpu);
1496285Snate@binkert.org  void endTransaction(int cpu);
1506285Snate@binkert.org  void profilePFWait(Time waitTime);
1516145Snate@binkert.org
1526285Snate@binkert.org  void controllerBusy(MachineID machID);
1536285Snate@binkert.org  void bankBusy();
1546285Snate@binkert.org  void missLatency(Time t, RubyRequestType type);
1556285Snate@binkert.org  void swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach);
1566285Snate@binkert.org  void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1576145Snate@binkert.org
1586285Snate@binkert.org  void profileTransition(const string& component, NodeID version, Address addr,
1596285Snate@binkert.org                         const string& state, const string& event,
1606285Snate@binkert.org                         const string& next_state, const string& note);
1616285Snate@binkert.org  void profileMsgDelay(int virtualNetwork, int delayCycles);
1626145Snate@binkert.org
1636285Snate@binkert.org  void print(ostream& out) const;
1646145Snate@binkert.org
1656285Snate@binkert.org  int64 getTotalTransactionsExecuted() const;
1666145Snate@binkert.org
1676285Snate@binkert.org  void rubyWatch(int proc);
1686285Snate@binkert.org  bool watchAddress(Address addr);
1696145Snate@binkert.org
1706285Snate@binkert.org  // return Ruby's start time
1716285Snate@binkert.org  Time getRubyStartTime(){
1726285Snate@binkert.org    return m_ruby_start;
1736285Snate@binkert.org  }
1746285Snate@binkert.org
1756285Snate@binkert.org  // added for MemoryControl:
1766285Snate@binkert.org  void profileMemReq(string name, int bank);
1776285Snate@binkert.org  void profileMemBankBusy(string name);
1786285Snate@binkert.org  void profileMemBusBusy(string name);
1796285Snate@binkert.org  void profileMemTfawBusy(string name);
1806285Snate@binkert.org  void profileMemReadWriteBusy(string name);
1816285Snate@binkert.org  void profileMemDataBusBusy(string name);
1826285Snate@binkert.org  void profileMemRefresh(string name);
1836285Snate@binkert.org  void profileMemRead(string name);
1846285Snate@binkert.org  void profileMemWrite(string name);
1856285Snate@binkert.org  void profileMemWaitCycles(string name, int cycles);
1866285Snate@binkert.org  void profileMemInputQ(string name, int cycles);
1876285Snate@binkert.org  void profileMemBankQ(string name, int cycles);
1886285Snate@binkert.org  void profileMemArbWait(string name, int cycles);
1896285Snate@binkert.org  void profileMemRandBusy(string name);
1906285Snate@binkert.org  void profileMemNotOld(string name);
1916285Snate@binkert.org  //added by SS
1926285Snate@binkert.org  bool getHotLines() { return m_hot_lines; }
1936285Snate@binkert.org  bool getAllInstructions() { return m_all_instructions; }
1946145Snate@binkert.org
1956145Snate@binkert.orgprivate:
1966285Snate@binkert.org  //added by SS
1976285Snate@binkert.org  vector<string> m_memory_control_names;
1986145Snate@binkert.org
1996285Snate@binkert.org  // Private copy constructor and assignment operator
2006285Snate@binkert.org  Profiler(const Profiler& obj);
2016285Snate@binkert.org  Profiler& operator=(const Profiler& obj);
2026145Snate@binkert.org
2036285Snate@binkert.org  // Data Members (m_ prefix)
2046285Snate@binkert.org  AddressProfiler* m_address_profiler_ptr;
2056285Snate@binkert.org  AddressProfiler* m_inst_profiler_ptr;
2066145Snate@binkert.org
2076285Snate@binkert.org  Vector<int64> m_instructions_executed_at_start;
2086285Snate@binkert.org  Vector<int64> m_cycles_executed_at_start;
2096145Snate@binkert.org
2106285Snate@binkert.org  ostream* m_periodic_output_file_ptr;
2116285Snate@binkert.org  integer_t m_stats_period;
2126145Snate@binkert.org
2136285Snate@binkert.org  Time m_ruby_start;
2146285Snate@binkert.org  time_t m_real_time_start_time;
2156145Snate@binkert.org
2166285Snate@binkert.org  Vector<integer_t> m_perProcTotalMisses;
2176285Snate@binkert.org  Vector<integer_t> m_perProcUserMisses;
2186285Snate@binkert.org  Vector<integer_t> m_perProcSupervisorMisses;
2196285Snate@binkert.org  Vector<integer_t> m_perProcStartTransaction;
2206285Snate@binkert.org  Vector<integer_t> m_perProcEndTransaction;
2216285Snate@binkert.org  Vector < Vector < integer_t > > m_busyControllerCount;
2226285Snate@binkert.org  integer_t m_busyBankCount;
2236285Snate@binkert.org  Histogram m_multicast_retry_histogram;
2246145Snate@binkert.org
2256285Snate@binkert.org  Histogram m_filter_action_histogram;
2266285Snate@binkert.org  Histogram m_tbeProfile;
2276145Snate@binkert.org
2286285Snate@binkert.org  Histogram m_sequencer_requests;
2296285Snate@binkert.org  Histogram m_read_sharing_histogram;
2306285Snate@binkert.org  Histogram m_write_sharing_histogram;
2316285Snate@binkert.org  Histogram m_all_sharing_histogram;
2326285Snate@binkert.org  int64 m_cache_to_cache;
2336285Snate@binkert.org  int64 m_memory_to_cache;
2346145Snate@binkert.org
2356285Snate@binkert.org  Histogram m_prefetchWaitHistogram;
2366145Snate@binkert.org
2376285Snate@binkert.org  Vector<Histogram> m_missLatencyHistograms;
2386285Snate@binkert.org  Vector<Histogram> m_machLatencyHistograms;
2396285Snate@binkert.org  Histogram m_allMissLatencyHistogram;
2406145Snate@binkert.org
2416285Snate@binkert.org  Histogram  m_allSWPrefetchLatencyHistogram;
2426285Snate@binkert.org  Histogram  m_SWPrefetchL2MissLatencyHistogram;
2436285Snate@binkert.org  Vector<Histogram> m_SWPrefetchLatencyHistograms;
2446285Snate@binkert.org  Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2456145Snate@binkert.org
2466285Snate@binkert.org  Histogram m_delayedCyclesHistogram;
2476285Snate@binkert.org  Histogram m_delayedCyclesNonPFHistogram;
2486285Snate@binkert.org  Vector<Histogram> m_delayedCyclesVCHistograms;
2496145Snate@binkert.org
2506285Snate@binkert.org  Histogram m_outstanding_requests;
2516285Snate@binkert.org  Histogram m_outstanding_persistent_requests;
2526145Snate@binkert.org
2536285Snate@binkert.org  Histogram m_average_latency_estimate;
2546145Snate@binkert.org
2556285Snate@binkert.org  Map<Address, int>* m_watch_address_list_ptr;
2566285Snate@binkert.org  // counts all initiated cache request including PUTs
2576285Snate@binkert.org  int m_requests;
2586285Snate@binkert.org  Map <string, int>* m_requestProfileMap_ptr;
2596145Snate@binkert.org
2606285Snate@binkert.org  // added for MemoryControl:
2616285Snate@binkert.org  //added by SS
2626285Snate@binkert.org  map< string, memory_control_profiler* > m_memory_control_profilers;
2636285Snate@binkert.org
2646285Snate@binkert.org  //added by SS
2656285Snate@binkert.org  bool m_hot_lines;
2666285Snate@binkert.org  bool m_all_instructions;
2676145Snate@binkert.org};
2686145Snate@binkert.org
2696145Snate@binkert.org// Output operator declaration
2706145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj);
2716145Snate@binkert.org
2726145Snate@binkert.org// ******************* Definitions *******************
2736145Snate@binkert.org
2746145Snate@binkert.org// Output operator definition
2756145Snate@binkert.orgextern inline
2766145Snate@binkert.orgostream& operator<<(ostream& out, const Profiler& obj)
2776145Snate@binkert.org{
2786285Snate@binkert.org  obj.print(out);
2796285Snate@binkert.org  out << flush;
2806285Snate@binkert.org  return out;
2816145Snate@binkert.org}
2826145Snate@binkert.org
2836145Snate@binkert.org#endif //PROFILER_H
2846145Snate@binkert.org
2856145Snate@binkert.org
286