Profiler.hh revision 6896
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 {
836889SBrad.Beckmann@amd.com  uint64 m_memReq;
846889SBrad.Beckmann@amd.com  uint64 m_memBankBusy;
856889SBrad.Beckmann@amd.com  uint64 m_memBusBusy;
866889SBrad.Beckmann@amd.com  uint64 m_memTfawBusy;
876889SBrad.Beckmann@amd.com  uint64 m_memReadWriteBusy;
886889SBrad.Beckmann@amd.com  uint64 m_memDataBusBusy;
896889SBrad.Beckmann@amd.com  uint64 m_memRefresh;
906889SBrad.Beckmann@amd.com  uint64 m_memRead;
916889SBrad.Beckmann@amd.com  uint64 m_memWrite;
926889SBrad.Beckmann@amd.com  uint64 m_memWaitCycles;
936889SBrad.Beckmann@amd.com  uint64 m_memInputQ;
946889SBrad.Beckmann@amd.com  uint64 m_memBankQ;
956889SBrad.Beckmann@amd.com  uint64 m_memArbWait;
966889SBrad.Beckmann@amd.com  uint64 m_memRandBusy;
976889SBrad.Beckmann@amd.com  uint64 m_memNotOld;
986889SBrad.Beckmann@amd.com  Vector<uint64> 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  // 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 addAddressTraceSample(const CacheMsg& msg, NodeID id);
1316145Snate@binkert.org
1326285Snate@binkert.org  void profileRequest(const string& requestStr);
1336285Snate@binkert.org  void profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner);
1346145Snate@binkert.org
1356285Snate@binkert.org  void profileMulticastRetry(const Address& addr, int count);
1366145Snate@binkert.org
1376285Snate@binkert.org  void profileFilterAction(int action);
1386145Snate@binkert.org
1396285Snate@binkert.org  void profileConflictingRequests(const Address& addr);
1406285Snate@binkert.org  void profileOutstandingRequest(int outstanding) { m_outstanding_requests.add(outstanding); }
1416285Snate@binkert.org  void profileOutstandingPersistentRequest(int outstanding) { m_outstanding_persistent_requests.add(outstanding); }
1426285Snate@binkert.org  void profileAverageLatencyEstimate(int latency) { m_average_latency_estimate.add(latency); }
1436145Snate@binkert.org
1446285Snate@binkert.org  void recordPrediction(bool wasGood, bool wasPredicted);
1456145Snate@binkert.org
1466285Snate@binkert.org  void startTransaction(int cpu);
1476285Snate@binkert.org  void endTransaction(int cpu);
1486285Snate@binkert.org  void profilePFWait(Time waitTime);
1496145Snate@binkert.org
1506285Snate@binkert.org  void controllerBusy(MachineID machID);
1516285Snate@binkert.org  void bankBusy();
1526285Snate@binkert.org  void missLatency(Time t, RubyRequestType type);
1536285Snate@binkert.org  void swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach);
1546285Snate@binkert.org  void sequencerRequests(int num) { m_sequencer_requests.add(num); }
1556145Snate@binkert.org
1566285Snate@binkert.org  void profileTransition(const string& component, NodeID version, Address addr,
1576285Snate@binkert.org                         const string& state, const string& event,
1586285Snate@binkert.org                         const string& next_state, const string& note);
1596285Snate@binkert.org  void profileMsgDelay(int virtualNetwork, int delayCycles);
1606145Snate@binkert.org
1616285Snate@binkert.org  void print(ostream& out) const;
1626145Snate@binkert.org
1636285Snate@binkert.org  int64 getTotalTransactionsExecuted() const;
1646145Snate@binkert.org
1656285Snate@binkert.org  void rubyWatch(int proc);
1666285Snate@binkert.org  bool watchAddress(Address addr);
1676145Snate@binkert.org
1686285Snate@binkert.org  // return Ruby's start time
1696285Snate@binkert.org  Time getRubyStartTime(){
1706285Snate@binkert.org    return m_ruby_start;
1716285Snate@binkert.org  }
1726285Snate@binkert.org
1736285Snate@binkert.org  // added for MemoryControl:
1746889SBrad.Beckmann@amd.com  void profileMemReq(int mem_cntrl, int bank);
1756889SBrad.Beckmann@amd.com  void profileMemBankBusy(int mem_cntrl);
1766889SBrad.Beckmann@amd.com  void profileMemBusBusy(int mem_cntrl);
1776889SBrad.Beckmann@amd.com  void profileMemTfawBusy(int mem_cntrl);
1786889SBrad.Beckmann@amd.com  void profileMemReadWriteBusy(int mem_cntrl);
1796889SBrad.Beckmann@amd.com  void profileMemDataBusBusy(int mem_cntrl);
1806889SBrad.Beckmann@amd.com  void profileMemRefresh(int mem_cntrl);
1816889SBrad.Beckmann@amd.com  void profileMemRead(int mem_cntrl);
1826889SBrad.Beckmann@amd.com  void profileMemWrite(int mem_cntrl);
1836889SBrad.Beckmann@amd.com  void profileMemWaitCycles(int mem_cntrl, int cycles);
1846889SBrad.Beckmann@amd.com  void profileMemInputQ(int mem_cntrl, int cycles);
1856889SBrad.Beckmann@amd.com  void profileMemBankQ(int mem_cntrl, int cycles);
1866889SBrad.Beckmann@amd.com  void profileMemArbWait(int mem_cntrl, int cycles);
1876889SBrad.Beckmann@amd.com  void profileMemRandBusy(int mem_cntrl);
1886889SBrad.Beckmann@amd.com  void profileMemNotOld(int mem_cntrl);
1896285Snate@binkert.org  //added by SS
1906285Snate@binkert.org  bool getHotLines() { return m_hot_lines; }
1916285Snate@binkert.org  bool getAllInstructions() { return m_all_instructions; }
1926145Snate@binkert.org
1936145Snate@binkert.orgprivate:
1946285Snate@binkert.org  //added by SS
1956285Snate@binkert.org  vector<string> m_memory_control_names;
1966145Snate@binkert.org
1976285Snate@binkert.org  // Private copy constructor and assignment operator
1986285Snate@binkert.org  Profiler(const Profiler& obj);
1996285Snate@binkert.org  Profiler& operator=(const Profiler& obj);
2006145Snate@binkert.org
2016285Snate@binkert.org  // Data Members (m_ prefix)
2026285Snate@binkert.org  AddressProfiler* m_address_profiler_ptr;
2036285Snate@binkert.org  AddressProfiler* m_inst_profiler_ptr;
2046145Snate@binkert.org
2056285Snate@binkert.org  Vector<int64> m_instructions_executed_at_start;
2066285Snate@binkert.org  Vector<int64> m_cycles_executed_at_start;
2076145Snate@binkert.org
2086285Snate@binkert.org  ostream* m_periodic_output_file_ptr;
2096285Snate@binkert.org  integer_t m_stats_period;
2106145Snate@binkert.org
2116285Snate@binkert.org  Time m_ruby_start;
2126285Snate@binkert.org  time_t m_real_time_start_time;
2136145Snate@binkert.org
2146285Snate@binkert.org  Vector<integer_t> m_perProcTotalMisses;
2156285Snate@binkert.org  Vector<integer_t> m_perProcUserMisses;
2166285Snate@binkert.org  Vector<integer_t> m_perProcSupervisorMisses;
2176285Snate@binkert.org  Vector<integer_t> m_perProcStartTransaction;
2186285Snate@binkert.org  Vector<integer_t> m_perProcEndTransaction;
2196285Snate@binkert.org  Vector < Vector < integer_t > > m_busyControllerCount;
2206285Snate@binkert.org  integer_t m_busyBankCount;
2216285Snate@binkert.org  Histogram m_multicast_retry_histogram;
2226145Snate@binkert.org
2236285Snate@binkert.org  Histogram m_filter_action_histogram;
2246285Snate@binkert.org  Histogram m_tbeProfile;
2256145Snate@binkert.org
2266285Snate@binkert.org  Histogram m_sequencer_requests;
2276285Snate@binkert.org  Histogram m_read_sharing_histogram;
2286285Snate@binkert.org  Histogram m_write_sharing_histogram;
2296285Snate@binkert.org  Histogram m_all_sharing_histogram;
2306285Snate@binkert.org  int64 m_cache_to_cache;
2316285Snate@binkert.org  int64 m_memory_to_cache;
2326145Snate@binkert.org
2336285Snate@binkert.org  Histogram m_prefetchWaitHistogram;
2346145Snate@binkert.org
2356285Snate@binkert.org  Vector<Histogram> m_missLatencyHistograms;
2366285Snate@binkert.org  Vector<Histogram> m_machLatencyHistograms;
2376285Snate@binkert.org  Histogram m_allMissLatencyHistogram;
2386145Snate@binkert.org
2396285Snate@binkert.org  Histogram  m_allSWPrefetchLatencyHistogram;
2406285Snate@binkert.org  Histogram  m_SWPrefetchL2MissLatencyHistogram;
2416285Snate@binkert.org  Vector<Histogram> m_SWPrefetchLatencyHistograms;
2426285Snate@binkert.org  Vector<Histogram> m_SWPrefetchMachLatencyHistograms;
2436145Snate@binkert.org
2446285Snate@binkert.org  Histogram m_delayedCyclesHistogram;
2456285Snate@binkert.org  Histogram m_delayedCyclesNonPFHistogram;
2466285Snate@binkert.org  Vector<Histogram> m_delayedCyclesVCHistograms;
2476145Snate@binkert.org
2486285Snate@binkert.org  Histogram m_outstanding_requests;
2496285Snate@binkert.org  Histogram m_outstanding_persistent_requests;
2506145Snate@binkert.org
2516285Snate@binkert.org  Histogram m_average_latency_estimate;
2526145Snate@binkert.org
2536285Snate@binkert.org  Map<Address, int>* m_watch_address_list_ptr;
2546285Snate@binkert.org  // counts all initiated cache request including PUTs
2556285Snate@binkert.org  int m_requests;
2566285Snate@binkert.org  Map <string, int>* m_requestProfileMap_ptr;
2576145Snate@binkert.org
2586285Snate@binkert.org  // added for MemoryControl:
2596285Snate@binkert.org  //added by SS
2606889SBrad.Beckmann@amd.com  Vector < memory_control_profiler* > m_mc_profilers;
2616285Snate@binkert.org
2626285Snate@binkert.org  //added by SS
2636285Snate@binkert.org  bool m_hot_lines;
2646285Snate@binkert.org  bool m_all_instructions;
2656896SBrad.Beckmann@amd.com
2666896SBrad.Beckmann@amd.com  int m_num_of_sequencers;
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