|
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 <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 "pin.H"#include "pin_isa_compat.H"#include "cctlib.H"#include "shadow_memory.H"#include <xmmintrin.h>#include <immintrin.h>#include "xed-interface.h"#include "xed-common-hdrs.h"#include <google/sparse_hash_map>#include <google/dense_hash_map>
Include dependency graph for zerospy_cachepage.cpp:Go to the source code of this file.
Classes | |
| struct | RedSpyThreadData |
| struct | RedLogs |
| struct | UnrolledCount< start, end, step > |
| struct | UnrolledCount< end, end, step > |
| struct | ZeroSpyAnalysis< T, AccessLen, isApprox > |
| struct | LoadSpyInstrument |
| struct | DRedData |
Macros | |
| #define | READ_ACTION (0) |
| #define | WRITE_ACTION (0xff) |
| #define | ONE_BYTE_READ_ACTION (0) |
| #define | TWO_BYTE_READ_ACTION (0) |
| #define | FOUR_BYTE_READ_ACTION (0) |
| #define | EIGHT_BYTE_READ_ACTION (0) |
| #define | ONE_BYTE_WRITE_ACTION (0xff) |
| #define | TWO_BYTE_WRITE_ACTION (0xffff) |
| #define | FOUR_BYTE_WRITE_ACTION (0xffffffff) |
| #define | EIGHT_BYTE_WRITE_ACTION (0xffffffffffffffff) |
| #define | IS_ACCESS_WITHIN_PAGE_BOUNDARY(accessAddr, accessLen) (PAGE_OFFSET((accessAddr)) <= (PAGE_OFFSET_MASK - (accessLen))) |
| #define | MAX_REDUNDANT_CONTEXTS_TO_LOG (1000) |
| #define | THREAD_MAX (1024) |
| #define | ENCODE_ADDRESS_AND_ACCESS_LEN(addr, len) ((addr) | (((uint64_t)(len)) << 48)) |
| #define | DECODE_ADDRESS(addrAndLen) ((addrAndLen) & ((1L << 48) - 1)) |
| #define | DECODE_ACCESS_LEN(addrAndLen) ((addrAndLen) >> 48) |
| #define | MAX_WRITE_OP_LENGTH (512) |
| #define | MAX_WRITE_OPS_IN_INS (8) |
| #define | MAX_REG_LENGTH (64) |
| #define | MAX_SIMD_LENGTH (64) |
| #define | MAX_SIMD_REGS (32) |
| #define | CACHELINE_ALIGNMENT 64 |
| #define | PAGE_ALIGNMENT 0x1000 |
| #define | CACHELINE_MASK (~63) |
| #define | PAGE_MASK (~0xfff) |
| #define | ISSAMECACHELINE(addr, accesslen) (((uint64_t)(addr) & (CACHELINE_ALIGNMENT - 1)) + (uint64_t)(accesslen) < CACHELINE_ALIGNMENT) |
| #define | GET_CACHELINE_INDEX(x) ((x)&CACHELINE_MASK) |
| #define | GET_PAGE_INDEX(x) ((x)&PAGE_MASK) |
| #define | GET_CACHELINE_INNER_INDEX(x) ((x) & (CACHELINE_ALIGNMENT - 1)) |
| #define | GET_PAGE_INNER_INDEX(x) ((x) & (PAGE_ALIGNMENT - 1)) |
| #define | STATE_NONZERO 0 |
| #define | STATE_ZERO 1 |
| #define | STATE_NOVISIT 2 |
| #define | VAL2STAT(value) (value == 0) |
| #define | HANDLE_CASE(T, ACCESS_LEN, IS_APPROX) INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)ZeroSpyAnalysis<T, (ACCESS_LEN), (IS_APPROX)>::CheckNByteValueAfterRead, IARG_MEMORYOP_EA, memOp, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_INST_PTR, IARG_END) |
| #define | HANDLE_LARGE() INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)CheckAfterLargeRead, IARG_MEMORYOP_EA, memOp, IARG_MEMORYREAD_SIZE, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_END) |
| #define | LEVEL_1_RED_THRESHOLD 0.90 |
| #define | LEVEL_2_RED_THRESHOLD 0.70 |
| #define | LEVEL_3_RED_THRESHOLD 0.50 |
| #define | PRINT_ALL_PAGE_INFO |
Functions | |
| RedSpyThreadData * | ClientGetTLS (const THREADID threadId) |
| static INT32 | Usage () |
| static void | ClientInit (int argc, char *argv[]) |
| static void | AddToRedTable (uint64_t key, uint16_t value, uint16_t zero, THREADID threadId) __attribute__((always_inline |
| static bool | IsOkToApproximate (xed_decoded_inst_t &xedd) |
| static bool | IsFloatInstructionAndOkToApproximate (ADDRINT ip) |
| static bool | IsFloatInstructionOld (ADDRINT ip) |
| static uint16_t | FloatOperandSize (ADDRINT ip, uint32_t oper) |
| static VOID | CheckAfterLargeRead (void *addr, UINT32 accessLen, uint32_t opaqueHandle, THREADID threadId) |
| static int | GetNumReadOperandsInIns (INS ins, UINT32 &whichOp) |
| static bool | INS_IsIgnorable (INS ins) |
| static VOID | InstrumentInsCallback (INS ins, VOID *v, const uint32_t opaqueHandle) |
| VOID | Update (uint32_t bytes, THREADID threadId) |
| static void | InstrumentTrace (TRACE trace, void *f) |
| static bool | DRedundacyCompare (const struct DRedData &first, const struct DRedData &second) |
| static void | PrintPageRedundancy (THREADID threadId) |
| static void | PrintCacheRedundancy (THREADID threadId) |
| static VOID | ImageUnload (IMG img, VOID *v) |
| static VOID | ThreadFiniFunc (THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v) |
| static VOID | FiniFunc (INT32 code, VOID *v) |
| static void | InitThreadData (RedSpyThreadData *tdata) |
| static VOID | ThreadStart (THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v) |
| uint64_t | computeMetricVal (void *metric) |
| int | main (int argc, char *argv[]) |
Variables | |
| struct { | |
| char dummy1 [128] | |
| xed_state_t xedState | |
| char dummy2 [128] | |
| } | LoadSpyGlobals |
| int | redload_metric_id = 0 |
| int | redload_approx_metric_id = 0 |
| uint64_t | grandTotBytesLoad |
| uint64_t | grandTotBytesRedLoad |
| uint64_t | grandTotBytesApproxRedLoad |
| static TLS_KEY | client_tls_key |
| static RedSpyThreadData * | gSingleThreadedTData |
| static FILE * | gTraceFile |
| static const uint64_t | READ_ACCESS_STATES [] = { 0, ONE_BYTE_READ_ACTION, TWO_BYTE_READ_ACTION, 0, FOUR_BYTE_READ_ACTION, 0, 0, 0, EIGHT_BYTE_READ_ACTION} |
| static const uint64_t | WRITE_ACCESS_STATES [] = { 0, ONE_BYTE_WRITE_ACTION, TWO_BYTE_WRITE_ACTION, 0, FOUR_BYTE_WRITE_ACTION, 0, 0, 0, EIGHT_BYTE_WRITE_ACTION} |
| static const uint8_t | OVERFLOW_CHECK [] = { 0, 0, 0, 1, 2, 3, 4, 5, 6} |
| static unordered_map< uint64_t, RedLogs > | RedMap [THREAD_MAX] |
| static void | flatten |
| #define CACHELINE_ALIGNMENT 64 |
Definition at line 162 of file zerospy_cachepage.cpp.
| #define CACHELINE_MASK (~63) |
Definition at line 166 of file zerospy_cachepage.cpp.
| #define DECODE_ACCESS_LEN | ( | addrAndLen | ) | ((addrAndLen) >> 48) |
Definition at line 63 of file zerospy_cachepage.cpp.
| #define DECODE_ADDRESS | ( | addrAndLen | ) | ((addrAndLen) & ((1L << 48) - 1)) |
Definition at line 62 of file zerospy_cachepage.cpp.
| #define EIGHT_BYTE_READ_ACTION (0) |
Definition at line 48 of file zerospy_cachepage.cpp.
| #define EIGHT_BYTE_WRITE_ACTION (0xffffffffffffffff) |
Definition at line 53 of file zerospy_cachepage.cpp.
| #define ENCODE_ADDRESS_AND_ACCESS_LEN | ( | addr, | |
| len | |||
| ) | ((addr) | (((uint64_t)(len)) << 48)) |
Definition at line 61 of file zerospy_cachepage.cpp.
| #define FOUR_BYTE_READ_ACTION (0) |
Definition at line 47 of file zerospy_cachepage.cpp.
| #define FOUR_BYTE_WRITE_ACTION (0xffffffff) |
Definition at line 52 of file zerospy_cachepage.cpp.
| #define GET_CACHELINE_INDEX | ( | x | ) | ((x)&CACHELINE_MASK) |
Definition at line 170 of file zerospy_cachepage.cpp.
| #define GET_CACHELINE_INNER_INDEX | ( | x | ) | ((x) & (CACHELINE_ALIGNMENT - 1)) |
Definition at line 173 of file zerospy_cachepage.cpp.
| #define GET_PAGE_INDEX | ( | x | ) | ((x)&PAGE_MASK) |
Definition at line 171 of file zerospy_cachepage.cpp.
| #define GET_PAGE_INNER_INDEX | ( | x | ) | ((x) & (PAGE_ALIGNMENT - 1)) |
Definition at line 174 of file zerospy_cachepage.cpp.
| #define HANDLE_CASE | ( | T, | |
| ACCESS_LEN, | |||
| IS_APPROX | |||
| ) | INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)ZeroSpyAnalysis<T, (ACCESS_LEN), (IS_APPROX)>::CheckNByteValueAfterRead, IARG_MEMORYOP_EA, memOp, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_INST_PTR, IARG_END) |
Definition at line 633 of file zerospy_cachepage.cpp.
| #define HANDLE_LARGE | ( | ) | INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)CheckAfterLargeRead, IARG_MEMORYOP_EA, memOp, IARG_MEMORYREAD_SIZE, IARG_UINT32, opaqueHandle, IARG_THREAD_ID, IARG_END) |
Definition at line 639 of file zerospy_cachepage.cpp.
| #define IS_ACCESS_WITHIN_PAGE_BOUNDARY | ( | accessAddr, | |
| accessLen | |||
| ) | (PAGE_OFFSET((accessAddr)) <= (PAGE_OFFSET_MASK - (accessLen))) |
Definition at line 55 of file zerospy_cachepage.cpp.
| #define ISSAMECACHELINE | ( | addr, | |
| accesslen | |||
| ) | (((uint64_t)(addr) & (CACHELINE_ALIGNMENT - 1)) + (uint64_t)(accesslen) < CACHELINE_ALIGNMENT) |
Definition at line 168 of file zerospy_cachepage.cpp.
| #define LEVEL_1_RED_THRESHOLD 0.90 |
Definition at line 864 of file zerospy_cachepage.cpp.
| #define LEVEL_2_RED_THRESHOLD 0.70 |
Definition at line 865 of file zerospy_cachepage.cpp.
| #define LEVEL_3_RED_THRESHOLD 0.50 |
Definition at line 866 of file zerospy_cachepage.cpp.
| #define MAX_REDUNDANT_CONTEXTS_TO_LOG (1000) |
Definition at line 58 of file zerospy_cachepage.cpp.
| #define MAX_REG_LENGTH (64) |
Definition at line 68 of file zerospy_cachepage.cpp.
| #define MAX_SIMD_LENGTH (64) |
Definition at line 70 of file zerospy_cachepage.cpp.
| #define MAX_SIMD_REGS (32) |
Definition at line 71 of file zerospy_cachepage.cpp.
| #define MAX_WRITE_OP_LENGTH (512) |
Definition at line 66 of file zerospy_cachepage.cpp.
| #define MAX_WRITE_OPS_IN_INS (8) |
Definition at line 67 of file zerospy_cachepage.cpp.
| #define ONE_BYTE_READ_ACTION (0) |
Definition at line 45 of file zerospy_cachepage.cpp.
| #define ONE_BYTE_WRITE_ACTION (0xff) |
Definition at line 50 of file zerospy_cachepage.cpp.
| #define PAGE_ALIGNMENT 0x1000 |
Definition at line 164 of file zerospy_cachepage.cpp.
| #define PAGE_MASK (~0xfff) |
Definition at line 167 of file zerospy_cachepage.cpp.
| #define PRINT_ALL_PAGE_INFO |
Definition at line 867 of file zerospy_cachepage.cpp.
| #define READ_ACTION (0) |
Definition at line 42 of file zerospy_cachepage.cpp.
| #define STATE_NONZERO 0 |
Definition at line 176 of file zerospy_cachepage.cpp.
| #define STATE_NOVISIT 2 |
Definition at line 178 of file zerospy_cachepage.cpp.
| #define STATE_ZERO 1 |
Definition at line 177 of file zerospy_cachepage.cpp.
| #define THREAD_MAX (1024) |
Definition at line 59 of file zerospy_cachepage.cpp.
| #define TWO_BYTE_READ_ACTION (0) |
Definition at line 46 of file zerospy_cachepage.cpp.
| #define TWO_BYTE_WRITE_ACTION (0xffff) |
Definition at line 51 of file zerospy_cachepage.cpp.
Definition at line 179 of file zerospy_cachepage.cpp.
| #define WRITE_ACTION (0xff) |
Definition at line 43 of file zerospy_cachepage.cpp.
|
inlinestatic |
Definition at line 192 of file zerospy_cachepage.cpp.
References RedLogs::reads, RedMap, RedLogs::state, value, RedLogs::zerobytes, and RedLogs::zeroreads.
Referenced by CheckAfterLargeRead(), and ZeroSpyAnalysis< T, AccessLen, isApprox >::if().
|
inlinestatic |
Definition at line 592 of file zerospy_cachepage.cpp.
References AddToRedTable(), GET_CACHELINE_INDEX, and ISSAMECACHELINE.
|
inline |
Definition at line 109 of file zerospy_cachepage.cpp.
References client_tls_key, and gSingleThreadedTData.
Referenced by PrintCacheRedundancy(), PrintPageRedundancy(), ThreadFiniFunc(), and Update().
|
static |
Definition at line 128 of file zerospy_cachepage.cpp.
References gTraceFile, LoadSpyGlobals, and MAX_FILE_PATH.
Referenced by main().
| uint64_t computeMetricVal | ( | void * | metric | ) |
Definition at line 1153 of file zerospy_cachepage.cpp.
References PinCCTLib::metric.
|
inlinestatic |
Definition at line 860 of file zerospy_cachepage.cpp.
References DRedData::frequency.
Referenced by PrintCacheRedundancy(), and PrintPageRedundancy().
|
static |
Definition at line 1107 of file zerospy_cachepage.cpp.
References grandTotBytesApproxRedLoad, grandTotBytesLoad, grandTotBytesRedLoad, gTraceFile, RedMap, and THREAD_MAX.
Referenced by main().
|
inlinestatic |
Definition at line 513 of file zerospy_cachepage.cpp.
References ip, and LoadSpyGlobals.
Referenced by LoadSpyInstrument::if().
|
static |
Definition at line 644 of file zerospy_cachepage.cpp.
Referenced by InstrumentInsCallback().
|
static |
Definition at line 1078 of file zerospy_cachepage.cpp.
References gTraceFile, PrintCacheRedundancy(), PrintPageRedundancy(), and RedMap.
Referenced by main().
|
static |
Definition at line 1128 of file zerospy_cachepage.cpp.
References RedSpyThreadData::bytesLoad, RedSpyThreadData::numIns, and RedSpyThreadData::sampleFlag.
Referenced by ThreadStart().
|
inlinestatic |
Definition at line 748 of file zerospy_cachepage.cpp.
References INS_IsMaskedJump().
Referenced by InstrumentInsCallback(), and InstrumentTrace().
|
static |
Definition at line 772 of file zerospy_cachepage.cpp.
References GetNumReadOperandsInIns(), and INS_IsIgnorable().
Referenced by main().
|
static |
Definition at line 827 of file zerospy_cachepage.cpp.
References INS_IsIgnorable(), INS_MemoryReadSize(), and Update().
Referenced by main().
|
inlinestatic |
Definition at line 234 of file zerospy_cachepage.cpp.
References ip, IsOkToApproximate(), and LoadSpyGlobals.
|
inlinestatic |
Definition at line 298 of file zerospy_cachepage.cpp.
References ip, and LoadSpyGlobals.
|
inlinestatic |
Definition at line 216 of file zerospy_cachepage.cpp.
Referenced by IsFloatInstructionAndOkToApproximate().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 1159 of file zerospy_cachepage.cpp.
References client_tls_key, ClientInit(), FiniFunc(), gTraceFile, ImageUnload(), InstrumentInsCallback(), InstrumentTrace(), INTERESTING_INS_ALL, PinCCTLib::PinCCTLibInit(), ThreadFiniFunc(), ThreadStart(), and Usage().
|
static |
Definition at line 951 of file zerospy_cachepage.cpp.
References DRedData::all0freq, ClientGetTLS(), DRedundacyCompare(), DRedData::frequency, grandTotBytesRedLoad, gTraceFile, LEVEL_1_RED_THRESHOLD, LEVEL_2_RED_THRESHOLD, LEVEL_3_RED_THRESHOLD, DRedData::ltot, MAX_REDUNDANT_CONTEXTS_TO_LOG, RedMap, DRedData::state, and STATE_ZERO.
Referenced by ImageUnload().
|
static |
Definition at line 869 of file zerospy_cachepage.cpp.
References DRedData::all0freq, ClientGetTLS(), DRedundacyCompare(), DRedData::frequency, GET_PAGE_INDEX, gTraceFile, LEVEL_1_RED_THRESHOLD, LEVEL_2_RED_THRESHOLD, LEVEL_3_RED_THRESHOLD, DRedData::ltot, MAX_REDUNDANT_CONTEXTS_TO_LOG, RedMap, DRedData::state, and STATE_ZERO.
Referenced by ImageUnload().
|
static |
Definition at line 1098 of file zerospy_cachepage.cpp.
References ClientGetTLS(), and grandTotBytesLoad.
Referenced by main().
|
static |
Definition at line 1139 of file zerospy_cachepage.cpp.
References client_tls_key, gSingleThreadedTData, InitThreadData(), and RedMap.
Referenced by main().
|
inline |
Definition at line 815 of file zerospy_cachepage.cpp.
References RedSpyThreadData::bytesLoad, and ClientGetTLS().
Referenced by InstrumentTrace().
|
static |
Definition at line 119 of file zerospy_cachepage.cpp.
Referenced by main().
|
static |
Definition at line 105 of file zerospy_cachepage.cpp.
Referenced by ClientGetTLS(), main(), and ThreadStart().
| char dummy1[128] |
Definition at line 79 of file zerospy_cachepage.cpp.
| char dummy2[128] |
Definition at line 81 of file zerospy_cachepage.cpp.
| void flatten |
Definition at line 191 of file zerospy_cachepage.cpp.
| uint64_t grandTotBytesApproxRedLoad |
Definition at line 100 of file zerospy_cachepage.cpp.
Referenced by FiniFunc().
| uint64_t grandTotBytesLoad |
Definition at line 98 of file zerospy_cachepage.cpp.
Referenced by FiniFunc(), and ThreadFiniFunc().
| uint64_t grandTotBytesRedLoad |
Definition at line 99 of file zerospy_cachepage.cpp.
Referenced by FiniFunc(), and PrintCacheRedundancy().
|
static |
Definition at line 106 of file zerospy_cachepage.cpp.
Referenced by ClientGetTLS(), and ThreadStart().
|
static |
Definition at line 125 of file zerospy_cachepage.cpp.
Referenced by ClientInit(), FiniFunc(), ImageUnload(), main(), PrintCacheRedundancy(), and PrintPageRedundancy().
| struct { ... } LoadSpyGlobals |
Referenced by ClientInit(), FloatOperandSize(), IsFloatInstructionAndOkToApproximate(), and IsFloatInstructionOld().
|
static |
Definition at line 160 of file zerospy_cachepage.cpp.
|
static |
Definition at line 158 of file zerospy_cachepage.cpp.
| int redload_approx_metric_id = 0 |
Definition at line 95 of file zerospy_cachepage.cpp.
| int redload_metric_id = 0 |
Definition at line 94 of file zerospy_cachepage.cpp.
|
static |
Definition at line 190 of file zerospy_cachepage.cpp.
Referenced by AddToRedTable(), FiniFunc(), ImageUnload(), PrintCacheRedundancy(), PrintPageRedundancy(), and ThreadStart().
|
static |
Definition at line 159 of file zerospy_cachepage.cpp.
| xed_state_t xedState |
Definition at line 80 of file zerospy_cachepage.cpp.