|
CCTLib
Calling-context and data-object attribution library for Intel Pin
|
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <atomic>#include <malloc.h>#include <iostream>#include <fstream>#include <unistd.h>#include <assert.h>#include <string.h>#include <sys/mman.h>#include <sstream>#include <functional>#include <unordered_set>#include <vector>#include <unordered_map>#include <algorithm>#include <list>#include <nlohmann/json.hpp>#include "pin.H"#include "cctlib.H"#include "shadow_memory.H"#include "rbtree.h"#include <xmmintrin.h>#include <immintrin.h>#include <sys/time.h>#include <sys/resource.h>#include "xed-interface.h"#include "xed-common-hdrs.h"#include <google/sparse_hash_map>#include <google/dense_hash_map>
Include dependency graph for ins_reuse_client.cpp:Go to the source code of this file.
Classes | |
| struct | InsReuseThreadData |
Macros | |
| #define | MAX_REUSE_DISTANCE_BINS (32) |
| #define | MAX_REUSE_DISTANCE (1ULL << (MAX_REUSE_DISTANCE_BINS)) |
| #define | CACHELINE_BIT (6) |
| #define | CACHELINE_SIZE (1L << CACHELINE_BIT) |
| #define | NUM_BLOCKS (3) |
| #define | NUM_CACHE_LEVELS (4) |
| #define | FIRST_USE (ULLONG_MAX) |
| #define | MULTI_THREADED |
Typedefs | |
| using | json = nlohmann::json |
| using | RBTree_t = RBTree< uint64_t, uint32_t, uint64_t > |
Functions | |
| static KNOB< bool > | KnobCCT (KNOB_MODE_WRITEONCE, "pintool", "cct", "0", "Enable CCT-level LRU eviction pair tracking") |
| static KNOB< UINT64 > | KnobL1iCap (KNOB_MODE_WRITEONCE, "pintool", "l1i_cap", "8192", "L1i capacity in unique instructions") |
| static KNOB< UINT64 > | KnobL2Cap (KNOB_MODE_WRITEONCE, "pintool", "l2_cap", "65536", "L2 capacity in unique instructions") |
| static KNOB< UINT64 > | KnobL3Cap (KNOB_MODE_WRITEONCE, "pintool", "l3_cap", "2097152", "L3 capacity in unique instructions") |
| static KNOB< UINT64 > | KnobITLBCap (KNOB_MODE_WRITEONCE, "pintool", "itlb_cap", "64", "iTLB capacity in 4K pages") |
| static KNOB< UINT32 > | KnobTopN (KNOB_MODE_WRITEONCE, "pintool", "topn", "100", "Top-N eviction pairs to report per level") |
| InsReuseThreadData * | ClientGetTLS (const THREADID threadId) |
| static size_t | GetBlock (size_t addr, size_t blockMask) |
| static INT32 | Usage () |
| static void | ClientInit (int argc, char *argv[]) |
| static void | UpdateInsReuseStats (uint64_t distance, uint64_t count, InsReuseThreadData *tData) |
| static void | UpdateBlockReuseStats (uint64_t distance, uint64_t count, uint64_t *reuseHisto) |
| static uint64_t | ComputeInsReuseDistance (uint64_t prevTick, uint64_t newTick, uint32_t v, InsReuseThreadData *tData, RBTree_t *rbt, uint32_t payload=0) |
| static VOID | InstrumentInsCallback (INS ins, VOID *v, const uint32_t slot) |
| static void | RecordEvictionPair (ContextHandle_t victimCtxt, ContextHandle_t curCtxt, unordered_map< uint64_t, uint64_t > &pairMap) |
| static void | CheckEvictions (RBTree_t &tree, ContextHandle_t curCtxt, uint64_t reuseDistance, bool isFirstUse, const uint64_t *capacities, int numLevels, unordered_map< uint64_t, uint64_t > *missPairs) |
| static uint64_t | ComputeBlockReuseDistance (uint64_t prevTick, uint64_t newTick, uint32_t v, InsReuseThreadData *tData, RBTree_t *rbt) |
| static void | AnalyzeInsLevelReuse (void *insAddr, uint32_t numInsInBBL, uint32_t slot, THREADID threadId) |
| template<int blockSize, int blkIdx> | |
| static void | AnalyzeBlockLevelReuse (void *block, uint32_t numInsInBlock, THREADID threadId) |
| static void | InstrumentInsLevelReuse (TRACE trace, void *f) |
| template<int blockSize, int blkIdx> | |
| static void | InstrumentMemBlockLevelReuse (TRACE trace, void *f) |
| static void | InstrumentTrace (TRACE trace, void *f) |
| static VOID | ImageUnload (IMG img, VOID *v) |
| static void | DumpHisto (uint64_t *histo, uint64_t footprint, const string &key1, const string &key2) |
| static VOID | ThreadFiniFunc (THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v) |
| static VOID | FiniFunc (INT32 code, VOID *v) |
| static void | InitThreadData (InsReuseThreadData *tdata) |
| static VOID | ThreadStart (THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v) |
| int | main (int argc, char *argv[]) |
Variables | |
| static bool | gCCTEnabled = false |
| static uint64_t | gCacheCapacities [NUM_CACHE_LEVELS] |
| static const char * | gCacheLevelNames [NUM_CACHE_LEVELS] = {"L1i", "L2", "L3", "iTLB"} |
| static unordered_map< ADDRINT, uint32_t > | gAddrToSlot |
| struct { | |
| char dummy1 [128] | |
| xed_state_t xedState | |
| char dummy2 [128] | |
| } | InsReuseGlobals |
| struct { | |
| size_t blkSize | |
| char * blkDescription | |
| } | BLK_INFO [NUM_BLOCKS] |
| struct { | |
| PIN_LOCK lock | |
| uint64_t numInsExecuted | |
| uint64_t footprint | |
| uint64_t insReuseHisto [MAX_REUSE_DISTANCE_BINS] | |
| struct { | |
| uint64_t numBlocksCounter | |
| uint64_t footprint | |
| uint64_t reuseHisto [MAX_REUSE_DISTANCE_BINS] | |
| } blockData [NUM_BLOCKS] | |
| unordered_map< uint64_t, uint64_t > missPairs [NUM_CACHE_LEVELS] | |
| } | GLOBAL_STATS |
| static TLS_KEY | client_tls_key |
| static InsReuseThreadData * | gSingleThreadedTData |
| static FILE * | gTraceFile |
| static ofstream | gJSONFile |
| #define CACHELINE_BIT (6) |
Definition at line 54 of file ins_reuse_client.cpp.
| #define CACHELINE_SIZE (1L << CACHELINE_BIT) |
Definition at line 55 of file ins_reuse_client.cpp.
| #define FIRST_USE (ULLONG_MAX) |
Definition at line 60 of file ins_reuse_client.cpp.
| #define MAX_REUSE_DISTANCE (1ULL << (MAX_REUSE_DISTANCE_BINS)) |
Definition at line 52 of file ins_reuse_client.cpp.
| #define MAX_REUSE_DISTANCE_BINS (32) |
Definition at line 51 of file ins_reuse_client.cpp.
| #define MULTI_THREADED |
Definition at line 62 of file ins_reuse_client.cpp.
| #define NUM_BLOCKS (3) |
Definition at line 57 of file ins_reuse_client.cpp.
| #define NUM_CACHE_LEVELS (4) |
Definition at line 58 of file ins_reuse_client.cpp.
| using json = nlohmann::json |
Definition at line 46 of file ins_reuse_client.cpp.
Definition at line 86 of file ins_reuse_client.cpp.
|
inlinestatic |
Definition at line 426 of file ins_reuse_client.cpp.
References InsReuseThreadData::blockData, blockData, ClientGetTLS(), ComputeBlockReuseDistance(), FIRST_USE, PAGE_OFFSET, and UpdateBlockReuseStats().
|
inlinestatic |
Definition at line 345 of file ins_reuse_client.cpp.
References CheckEvictions(), ClientGetTLS(), ComputeInsReuseDistance(), curCtxt, RBTree< K, V, S >::Delete(), RBTree< K, V, S >::FindNodeAtRankFromRight(), RBTree< K, V, S >::FindSumGreaterThan(), FIRST_USE, InsReuseThreadData::footprint, gCacheCapacities, gCCTEnabled, PinCCTLib::GetContextHandle(), ShadowMemory< Ts >::GetOrCreateShadowBaseAddress(), RBTree< K, V, S >::Insert(), InsReuseThreadData::insRBTree, InsReuseThreadData::itlbFootprint, InsReuseThreadData::itlbRBTree, InsReuseThreadData::itlbTick, TreeNode< K, V, S >::key, InsReuseThreadData::missPairs, InsReuseThreadData::numInsExecuted, PAGE_OFFSET, RecordEvictionPair(), InsReuseThreadData::smIns, InsReuseThreadData::smITLBPage, and UpdateInsReuseStats().
Referenced by InstrumentInsLevelReuse().
|
inlinestatic |
Definition at line 309 of file ins_reuse_client.cpp.
References curCtxt, RBTree< K, V, S >::FindNodeAtRankFromRight(), RBTree< K, V, S >::GetTotalSum(), missPairs, and RecordEvictionPair().
Referenced by AnalyzeInsLevelReuse().
|
inline |
Definition at line 147 of file ins_reuse_client.cpp.
References client_tls_key, and gSingleThreadedTData.
Referenced by AnalyzeBlockLevelReuse(), AnalyzeInsLevelReuse(), and ThreadFiniFunc().
|
static |
Definition at line 172 of file ins_reuse_client.cpp.
References gJSONFile, GLOBAL_STATS, gTraceFile, InsReuseGlobals, MAX_FILE_PATH, MAX_REUSE_DISTANCE_BINS, and NUM_BLOCKS.
Referenced by main().
|
inlinestatic |
Definition at line 327 of file ins_reuse_client.cpp.
References RBTree< K, V, S >::Delete(), RBTree< K, V, S >::FindSumGreaterThan(), FIRST_USE, RBTree< K, V, S >::Insert(), and TreeNode< K, V, S >::key.
Referenced by AnalyzeBlockLevelReuse().
|
inlinestatic |
Definition at line 280 of file ins_reuse_client.cpp.
References RBTree< K, V, S >::Delete(), RBTree< K, V, S >::FindSumGreaterThan(), FIRST_USE, RBTree< K, V, S >::Insert(), and TreeNode< K, V, S >::key.
Referenced by AnalyzeInsLevelReuse().
|
static |
Definition at line 613 of file ins_reuse_client.cpp.
References footprint, gJSONFile, gTraceFile, and MAX_REUSE_DISTANCE_BINS.
Referenced by FiniFunc(), and ThreadFiniFunc().
|
static |
Definition at line 681 of file ins_reuse_client.cpp.
References BLK_INFO, blkDescription, blkSize, DumpHisto(), gJSONFile, GLOBAL_STATS, gTraceFile, and NUM_BLOCKS.
Referenced by main().
Definition at line 157 of file ins_reuse_client.cpp.
Referenced by InstrumentMemBlockLevelReuse().
|
static |
Definition at line 547 of file ins_reuse_client.cpp.
References a, gCacheCapacities, gCacheLevelNames, gCCTEnabled, PinCCTLib::GetFullCallingContext(), gJSONFile, GLOBAL_STATS, gTraceFile, KnobTopN(), NUM_CACHE_LEVELS, and PinCCTLib::PrintFullCallingContext().
Referenced by main().
|
static |
Definition at line 711 of file ins_reuse_client.cpp.
References InsReuseThreadData::blockData, InsReuseThreadData::bytesLoad, InsReuseThreadData::footprint, InsReuseThreadData::insReuseHisto, InsReuseThreadData::itlbFootprint, InsReuseThreadData::itlbTick, MAX_REUSE_DISTANCE_BINS, NUM_BLOCKS, InsReuseThreadData::numBlocksCounter, InsReuseThreadData::numIns, InsReuseThreadData::numInsExecuted, InsReuseThreadData::prevBlock, InsReuseThreadData::reuseHisto, and InsReuseThreadData::sampleFlag.
Referenced by ThreadStart().
|
static |
|
static |
Definition at line 470 of file ins_reuse_client.cpp.
References AnalyzeInsLevelReuse(), gAddrToSlot, and gCCTEnabled.
Referenced by InstrumentTrace().
|
static |
Definition at line 492 of file ins_reuse_client.cpp.
References GetBlock().
Referenced by InstrumentTrace().
|
static |
Definition at line 537 of file ins_reuse_client.cpp.
References BLK_INFO, f(), InstrumentInsLevelReuse(), and InstrumentMemBlockLevelReuse().
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by main().
|
static |
Referenced by ImageUnload().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 744 of file ins_reuse_client.cpp.
References client_tls_key, ClientInit(), FiniFunc(), gCacheCapacities, gCCTEnabled, gTraceFile, ImageUnload(), InstrumentInsCallback(), InstrumentTrace(), INTERESTING_INS_ALL, KnobCCT(), KnobITLBCap(), KnobL1iCap(), KnobL2Cap(), KnobL3Cap(), PinCCTLib::PinCCTLibInit(), ThreadFiniFunc(), ThreadStart(), and Usage().
|
inlinestatic |
Definition at line 303 of file ins_reuse_client.cpp.
References curCtxt.
Referenced by AnalyzeInsLevelReuse(), and CheckEvictions().
|
static |
Definition at line 634 of file ins_reuse_client.cpp.
References BLK_INFO, blkDescription, blkSize, InsReuseThreadData::blockData, ClientGetTLS(), DumpHisto(), InsReuseThreadData::footprint, gCCTEnabled, GLOBAL_STATS, gTraceFile, InsReuseThreadData::insReuseHisto, MAX_REUSE_DISTANCE_BINS, InsReuseThreadData::missPairs, NUM_BLOCKS, NUM_CACHE_LEVELS, InsReuseThreadData::numBlocksCounter, InsReuseThreadData::numInsExecuted, and InsReuseThreadData::reuseHisto.
Referenced by main().
|
static |
Definition at line 731 of file ins_reuse_client.cpp.
References client_tls_key, gSingleThreadedTData, and InitThreadData().
Referenced by main().
|
inlinestatic |
Definition at line 258 of file ins_reuse_client.cpp.
References MAX_REUSE_DISTANCE, MAX_REUSE_DISTANCE_BINS, and reuseHisto.
Referenced by AnalyzeBlockLevelReuse().
|
inlinestatic |
Definition at line 239 of file ins_reuse_client.cpp.
References InsReuseThreadData::insReuseHisto, MAX_REUSE_DISTANCE, and MAX_REUSE_DISTANCE_BINS.
Referenced by AnalyzeInsLevelReuse().
|
static |
Definition at line 162 of file ins_reuse_client.cpp.
Referenced by main().
| constexpr { ... } BLK_INFO[NUM_BLOCKS] |
Referenced by FiniFunc(), InstrumentTrace(), and ThreadFiniFunc().
| char* blkDescription |
Definition at line 90 of file ins_reuse_client.cpp.
Referenced by FiniFunc(), and ThreadFiniFunc().
| size_t blkSize |
Definition at line 89 of file ins_reuse_client.cpp.
Referenced by FiniFunc(), and ThreadFiniFunc().
| struct { ... } blockData[NUM_BLOCKS] |
Referenced by AnalyzeBlockLevelReuse().
|
static |
Definition at line 143 of file ins_reuse_client.cpp.
Referenced by ClientGetTLS(), main(), and ThreadStart().
| char dummy1[128] |
Definition at line 81 of file ins_reuse_client.cpp.
| char dummy2[128] |
Definition at line 83 of file ins_reuse_client.cpp.
| uint64_t footprint |
Definition at line 131 of file ins_reuse_client.cpp.
Referenced by DumpHisto().
|
static |
Definition at line 77 of file ins_reuse_client.cpp.
Referenced by InstrumentInsCallback(), and InstrumentInsLevelReuse().
|
static |
Definition at line 73 of file ins_reuse_client.cpp.
Referenced by AnalyzeInsLevelReuse(), ImageUnload(), and main().
|
static |
Definition at line 74 of file ins_reuse_client.cpp.
Referenced by ImageUnload().
|
static |
Definition at line 72 of file ins_reuse_client.cpp.
Referenced by AnalyzeInsLevelReuse(), ImageUnload(), InstrumentInsLevelReuse(), main(), and ThreadFiniFunc().
|
static |
Definition at line 169 of file ins_reuse_client.cpp.
Referenced by ClientInit(), DumpHisto(), FiniFunc(), and ImageUnload().
| struct { ... } GLOBAL_STATS |
Referenced by ClientInit(), FiniFunc(), ImageUnload(), and ThreadFiniFunc().
|
static |
Definition at line 144 of file ins_reuse_client.cpp.
Referenced by ClientGetTLS(), and ThreadStart().
|
static |
Definition at line 168 of file ins_reuse_client.cpp.
Referenced by ClientInit(), DumpHisto(), FiniFunc(), ImageUnload(), main(), and ThreadFiniFunc().
| struct { ... } InsReuseGlobals |
Referenced by ClientInit().
| uint64_t insReuseHisto[MAX_REUSE_DISTANCE_BINS] |
Definition at line 132 of file ins_reuse_client.cpp.
| PIN_LOCK lock |
Definition at line 129 of file ins_reuse_client.cpp.
| unordered_map<uint64_t, uint64_t> missPairs[NUM_CACHE_LEVELS] |
Definition at line 138 of file ins_reuse_client.cpp.
Referenced by CheckEvictions().
| uint64_t numBlocksCounter |
Definition at line 134 of file ins_reuse_client.cpp.
| uint64_t numInsExecuted |
Definition at line 130 of file ins_reuse_client.cpp.
| uint64_t reuseHisto[MAX_REUSE_DISTANCE_BINS] |
Definition at line 136 of file ins_reuse_client.cpp.
Referenced by UpdateBlockReuseStats().
| xed_state_t xedState |
Definition at line 82 of file ins_reuse_client.cpp.