| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: trapcount.h |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | /* |
| 24 | * trapcount.h |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #ifndef _trapcount_h_9ecb7c16_ |
| 29 | #define _trapcount_h_9ecb7c16_ |
| 30 | |
| 31 | |
| 32 | // standard C++ and STL includes |
| 33 | #include <map> |
| 34 | |
| 35 | |
| 36 | // base class for tracers/timing-models/analyzers |
| 37 | #include "vtracer.h" |
| 38 | |
| 39 | |
| 40 | |
| 41 | enum { MAX_TRAPTYPES = 512 }; // 256 HW traps, 256 Tcc instrs |
| 42 | enum { MAX_SYSCALLS = 256 }; |
| 43 | enum { MAX_NCPUS = 1024 }; // 5-bit NodeID, 5-bit AgentID |
| 44 | // enum { MAX_INOS = 65536 }; // 5-bit NodeID, 5-bit AgentID, 6-bit DeviceID |
| 45 | enum { MAX_MMUCNTXS = 8192 }; // 13-bit field in TLB/TTE |
| 46 | |
| 47 | typedef volatile long vint64_t; |
| 48 | |
| 49 | |
| 50 | |
| 51 | typedef std::map<int, int64_t, std::less<int> > inoarray64_t; |
| 52 | typedef inoarray64_t::iterator inoiter; |
| 53 | |
| 54 | class Counters { // -------------------------------------------------- Counters |
| 55 | public: |
| 56 | vint64_t instrcount, |
| 57 | hypercount, |
| 58 | kernelcount, |
| 59 | usercount; |
| 60 | vint64_t traptypecount[ MAX_TRAPTYPES ]; |
| 61 | vint64_t syscallscount[ MAX_SYSCALLS ]; |
| 62 | vint64_t mondoxcalcount[ MAX_NCPUS ]; |
| 63 | // vint64_t mondoinocount[ MAX_INOS ]; |
| 64 | inoarray64_t mondoinocount; // better choice, always very sparse |
| 65 | |
| 66 | Counters (); |
| 67 | void Reset (); // clear all counts to zero |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | typedef Counters * CpuCounters/*[MAX_NCPUS]*/; // ---------------- CpuCounters |
| 72 | |
| 73 | |
| 74 | // ------------ MmucntxCounters |
| 75 | typedef std::map<int, Counters, std::less<int> > MmucntxCounters; |
| 76 | |
| 77 | |
| 78 | // ------------- ThreadCounters |
| 79 | typedef std::map<int64_t, Counters, std::less<int64_t> > ThreadCounters; |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | class trapcount : public VTracer { // ================================= VTracer |
| 87 | |
| 88 | public: // this is the exported interface that blaze calls |
| 89 | // the imported interface that vtracers call is still implicit |
| 90 | |
| 91 | trapcount(const char * tmp_modname); |
| 92 | ~trapcount(); |
| 93 | |
| 94 | static int trapcount_ui_cmds (void*, int argc, char * argv[]); |
| 95 | |
| 96 | int process_ui_cmd (int argc, char **tmp_argv); |
| 97 | int attach (VTracer_SAM_intf * sam_intf); |
| 98 | |
| 99 | int instr (VCPU_Instruction * ii); |
| 100 | int trap (VCPU_Trap * ti); |
| 101 | int tlb (VCPU_TLB * ti); |
| 102 | int async (VCPU_AsyncData * di); |
| 103 | int sync (VCPU_Sync * si); |
| 104 | |
| 105 | private: |
| 106 | |
| 107 | int numcpus; |
| 108 | |
| 109 | int64_t intervalsCounter; // counts cpu[0] 0x04e traps |
| 110 | |
| 111 | typedef enum { |
| 112 | MODE_NONE, |
| 113 | MODE_AGGREGATE, |
| 114 | MODE_BY_CPU, |
| 115 | MODE_BY_MMUCNTX, |
| 116 | MODE_BY_THREAD, |
| 117 | MODE_SEL_CPU, |
| 118 | MODE_SEL_MMUCNTX, |
| 119 | MODE_SEL_THREAD |
| 120 | } modes; |
| 121 | |
| 122 | modes mode; |
| 123 | |
| 124 | void configure_for_mode (modes _mode); |
| 125 | |
| 126 | Counters * aggregate; // MODE_AGGREGATE |
| 127 | Counters * cpus /*array[MAX_NCPUS]*/; // MODE_BY_CPU |
| 128 | MmucntxCounters * mmucntxs; // MODE_BY_MMUCNTX |
| 129 | ThreadCounters * threads; // MODE_BY_THREAD |
| 130 | |
| 131 | void printCounts (int reset); |
| 132 | |
| 133 | int parse_args_v4(int argc, const char * tmp_argv[]); // !=0 --> error |
| 134 | int parse_args_v5(int argc, const char * tmp_argv[]); // ditto |
| 135 | |
| 136 | void trace_on(); // initialize a new trace |
| 137 | |
| 138 | void print_status(); |
| 139 | |
| 140 | void trace_off(); |
| 141 | |
| 142 | const char * modname; |
| 143 | |
| 144 | VTracer_SAM_intf * SAM_intf; |
| 145 | |
| 146 | }; // class trapcount |
| 147 | |
| 148 | |
| 149 | |
| 150 | #endif // _trapcount_h_9ecb7c16_ |