Pin Tutorial - Unicamp

2y ago
26 Views
3 Downloads
1.35 MB
40 Pages
Last View : 3m ago
Last Download : 3m ago
Upload by : Bennett Almond
Transcription

Pin Tutorial

What is Instrumentation?A technique that inserts extra code intoa program to collect runtime informationInstrumentation approaches: Source instrumentation:– Instrument source programs Binary instrumentation:– Instrument executables directly1Pin Tutorial 2007

Why use Dynamic Instrumentation? No need to recompile or relink Discover code at runtime Handle dynamically-generated code Attach to running processes2Pin Tutorial 2007

Advantages of Pin InstrumentationEasy-to-use Instrumentation: Uses dynamic instrumentation– Do not need source code, recompilation, post-linkingProgrammable Instrumentation: Provides rich APIs to write in C/C your owninstrumentation tools (called Pintools)Multiplatform: Supports x86, x86-64, Itanium, Xscale Supports Linux, Windows, MacOSRobust: Instruments real-life applications: Database, web browsers, Instruments multithreaded applications Supports signalsEfficient: Applies compiler optimizations on instrumentation code3Pin Tutorial 2007

Using PinLaunch and instrument an application pin –t pintool –- applicationInstrumentation engine(provided in the kit)Instrumentation tool(write your own, or use oneprovided in the kit)Attach to and instrument an application pin –t pintool –pid 12344Pin Tutorial 2007

Pin Instrumentation APIsBasic APIs are architecture independent: Provide common functionalities like determining:– Control-flow changes– Memory accessesArchitecture-specific APIs e.g., Info about segmentation registers on IA32Call-based APIs: Instrumentation routines Analysis routines5Pin Tutorial 2007

Instrumentation vs. AnalysisConcepts borrowed from the ATOM tool:Instrumentation routines define whereinstrumentation is inserted e.g., before instruction Occurs first time an instruction is executedAnalysis routines define what to do wheninstrumentation is activated e.g., increment counter Occurs every time an instruction is executed6Pin Tutorial 2007

Pintool 1: Instruction Countsub 0xff, %edxcounter ;cmp %esi, %edxcounter ;jle L1 counter ;mov 0x1, %edicounter ;add 0x10, %eaxcounter ;7Pin Tutorial 2007

Pintool 1: Instruction Count Output /bin/lsMakefile imageload.out itrace proccountimageload inscount0 atrace itrace.out pin -t inscount0 -- /bin/lsMakefile imageload.out itrace proccountimageload inscount0 atrace itrace.outCount 4228388Pin Tutorial 2007

#include iostream #include "pin.h"ManualExamples/inscount0.cppUINT64 icount 0;void docount() { icount ; }analysis routinevoid Instruction(INS ins, void *v)instrumentation routine{INS InsertCall(ins, IPOINT BEFORE, (AFUNPTR)docount, IARG END);Same source code works on the 4 architectures}Pin automaticallyapplicationvoid Fini(INT32code, void saves/restores*v){ std::cerr "Count " icount endl; }int main(int argc, char * argv[]){PIN Init(argc, argv);INS AddInstrumentFunction(Instruction, 0);PIN AddFiniFunction(Fini, 0);PIN StartProgram();return 0;}9Pin Tutorial 2007state

Pintool 2: Instruction TracePrint(ip);sub 0xff, %edxPrint(ip);cmp %esi, %edxPrint(ip);jle L1 Print(ip);mov 0x1, %ediPrint(ip);add 0x10, %eaxNeed to pass ip argument to the analysis routine (printip())10Pin Tutorial 2007

Pintool 2: Instruction Trace Output pin -t itrace -- /bin/lsMakefile imageload.out itrace proccountimageload inscount0 atrace itrace.out head -4 11Pin Tutorial 2007

ManualExamples/itrace.cpp#include stdio.h #include "pin.H"argument to analysis routineFILE * trace;void printip(void *ip) { fprintf(trace, "%p\n", ip); }analysis routineinstrumentation routinevoid Instruction(INS ins, void *v) {INS InsertCall(ins, IPOINT BEFORE, (AFUNPTR)printip,IARG INST PTR, IARG END);}void Fini(INT32 code, void *v) { fclose(trace); }int main(int argc, char * argv[]) {trace fopen("itrace.out", "w");PIN Init(argc, argv);INS AddInstrumentFunction(Instruction, 0);PIN AddFiniFunction(Fini, 0);PIN StartProgram();return 0;}12Pin Tutorial 2007

Examples of Arguments to AnalysisRoutineIARG INST PTR Instruction pointer (program counter) valueIARG UINT32 value An integer valueIARG REG VALUE register name Value of the register specifiedIARG BRANCH TARGET ADDR Target address of the branch instrumentedIARG MEMORY READ EA Effective address of a memory readAnd many more (refer to the Pin manual for details)13Pin Tutorial 2007

Instrumentation PointsInstrument points relative to an instruction: Before (IPOINT BEFORE) After:– Fall-through edge (IPOINT AFTER)– Taken edge (IPOINT TAKEN BRANCH)count()count()14cmp%esi, %edx count()jle L1 mov L1 :mov 0x8,%edi 0x1, %ediPin Tutorial 2007

Instrumentation GranularityInstrumentation can be done at threedifferent granularities: Instruction Basic blocksub 0xff, %edx– A sequence of instructionscmp %esi, %edxterminated at a control-flowchanging instructionjle L1 – Single entry, single exit Tracemov 0x1, %edi– A sequence of basic blocksadd 0x10, %eaxterminated at anjmp L2 unconditional control-flow1 Trace, 2 BBs, 6 instschanging instruction– Single entry, multiple exits15Pin Tutorial 2007

Recap of Pintool 1: Instruction Countcounter ;sub 0xff, %edxcounter ;cmp %esi, %edxcounter ;jle L1 counter ;mov 0x1, %edicounter ;add 0x10, %eaxStraightforward, but the counting can be more efficient16Pin Tutorial 2007

Pintool 3: Faster Instruction Countcounter 3sub 0xff, %edxcmp%esi, %edxjle L1 counter 2mov 0x1, %ediadd17 0x10, %eaxPin Tutorial 2007basic blocks (bbl)

ManualExamples/inscount1.cpp#include stdio.h #include "pin.H“UINT64 icount 0;analysis routinevoid docount(INT32 c) { icount c; }void Trace(TRACE trace, void *v) { instrumentation routinefor (BBL bbl TRACE BblHead(trace);BBL Valid(bbl); bbl BBL Next(bbl)) {BBL InsertCall(bbl, IPOINT BEFORE, (AFUNPTR)docount,IARG UINT32, BBL NumIns(bbl), IARG END);}}void Fini(INT32 code, void *v) {fprintf(stderr, "Count %lld\n", icount);}int main(int argc, char * argv[]) {PIN Init(argc, argv);TRACE AddInstrumentFunction(Trace, 0);PIN AddFiniFunction(Fini, 0);PIN StartProgram();return 0;}18Pin Tutorial 2007

Modifying Program BehaviorPin allows you not only to observe but alsochange program behaviorWays to change program behavior: Add/delete instructions Change register values Change memory values Change control flow19Pin Tutorial 2007

Instrumentation Library#include iostream #include "pin.H"UINT64 icount 0;Instruction counting Pin Tool#include iostream #include "pin.H"#include "instlib.H"VOID Fini(INT32 code, VOID *v) {std::cerr "Count " icount endl;INSTLIB::ICOUNT icount;}VOID docount() {icount ;}VOID Fini(INT32 code, VOID *v) {cout "Count" icount.Count() endl;}VOID Instruction(INS ins, VOID *v) {int main(int argc,IARG END);char * argv[]) {INS InsertCall(ins, IPOINT BEFORE,(AFUNPTR)docount,PIN Init(argc, argv);}PIN AddFiniFunction(Fini, 0);int main(int argc, char * argv[]) {icount.Activate();PIN Init(argc, argv);INS AddInstrumentFunction(Instruction,PIN StartProgram();0);return0;PIN AddFiniFunction(Fini, 0);}PIN StartProgram();return 0;}20Pin Tutorial 2007

Useful InstLib abstractions ICOUNT– # of instructions executed FILTER– Instrument specific routines or libraries only ALARM– Execution count timer for address, routines, etc. FOLLOW CHILD– Inject Pin into new process created by parent process TIME WARP– Preserves RDTSC behavior across executions CONTROL– Limit instrumentation address ranges21Pin Tutorial 2007

Useful InstLib ALARM Example22Pin Tutorial 2007

Debugging Pintools1. Invoke gdb with your pintool (don’t “run”) gdb inscount0(gdb)2. In another window, start your pintool withthe “-pause tool” flag pin –pause tool 5 –t inscount0 -- /bin/lsPausing to attach to pid 320173. Go back to gdb window:a) Attach to the processb) “cont” to continue execution; can set breakpoints as usual(gdb) attach 32017(gdb) break main(gdb) cont23Pin Tutorial 2007

24Pin Tutorial gccgobmk200%xalancbmksjengperlbenchRelative to NativePin OverheadSPEC Integer 2006180%160%140%120%

Adding User 264refgccxalancbmksjenggobmkPin Tutorial 2007mcfPinPin e to Native800%

Instrumentation Driven SimulationFast exploratory studies Instrumentation native execution Simulation speeds at MIPSCharacterize complex applications E.g. Oracle, Java, parallel data-mining appsSimple to build instrumentation tools Tools can feed simulation models in real time Tools can gather instruction traces for later use26Pin Tutorial 2007

Performance ModelsBranch Predictor Models: PC of conditional instructions Direction Predictor: Taken/not-taken information Target Predictor: PC of target instruction if takenCache Models: Thread ID (if multi-threaded workload) Memory address Size of memory operation Type of memory operation (Read/Write)Simple Timing Models: Latency information27Pin Tutorial 2007

Branch Predictor ModelAPI dataPinInstrumentation ToolAPI()BPSimPin ToolBranch instr infoInstrumentation RoutinesModelAnalysis RoutinesBPSim Pin Tool Instruments all branches Uses API to set up call backs to analysis routinesBranch Predictor Model: Detailed branch predictor simulator28Pin Tutorial 2007BP

BP ImplementationINSTRUMENTVOID ProcessBranch(ADDRINT PC, ADDRINT targetPC, bool BrTaken) {BP Info pred myBPU.GetPrediction( PC );if( pred.Taken ! BrTaken ) {// Direction Mispredicted}if( pred.predTarget ! targetPC ) {// Target Mispredicted}myBPU.Update( PC, BrTaken, targetPC);}VOID Instruction(INS ins, VOID *v){if( INS IsDirectBranchOrCall(ins) INS HasFallThrough(ins) )INS InsertCall(ins, IPOINT BEFORE, (AFUNPTR) ProcessBranch,ADDRINT, INS Address(ins),IARG UINT32, INS DirectBranchOrCallTargetAddress(ins),IARG BRANCH TAKEN, IARG END);}MAINANALYSISBranchPredictor myBPU;int main() {PIN Init();INS AddInstrumentationFunction(Instruction, 0);PIN StartProgram();}29Pin Tutorial 2007

Branch Predictor Performance - GCCBimodal not chosenBimodal In McFarling PredictorMcFarling PredictorBranch prediction accuracies range from 0-100%Branches are hard to predict in some phases Can simulate these regions alone by fast forwarding tothem in real time30Pin Tutorial 2007

Performance Model InputsBranch Predictor Models: PC of conditional instructions Direction Predictor: Taken/not-taken information Target Predictor: PC of target instruction if takenCache Models: Thread ID (if multi-threaded workload) Memory address Size of memory operation Type of memory operation (Read/Write)Simple Timing Models: Latency information31Pin Tutorial 2007

Cache SimulatorsAPI dataPinInstrumentation ToolCachePin ToolAPI()Mem Addr infoInstrumentation RoutinesCacheModelAnalysis RoutinesCache Pin Tool Instruments all instructions that reference memory Use API to set up call backs to analysis routinesCache Model: Detailed cache simulator32Pin Tutorial 2007

Cache ImplementationMAININSTRUMENTANALYSISCACHE t CacheHierarchy[MAX NUM THREADS][MAX NUM LEVELS];33VOID MemRef(int tid, ADDRINT addrStart, int size, int type) {for(addr addrStart; addr (addrStart size); addr LINE SIZE)LookupHierarchy( tid, FIRST LEVEL CACHE, addr, type);}VOID LookupHierarchy(int tid, int level, ADDRINT addr, int accessType){result cacheHier[tid][cacheLevel]- Lookup(addr, accessType );if( result CACHE MISS ) {if( level LAST LEVEL CACHE ) return;LookupHierarchy(tid, level 1, addr, accessType);}}VOID Instruction(INS ins, VOID *v){if( INS IsMemoryRead(ins) )INS InsertCall(ins, IPOINT BEFORE, (AFUNPTR) MemRef,IARG THREAD ID, IARG MEMORYREAD EA, IARG MEMORYREAD SIZE,IARG UINT32, ACCESS TYPE LOAD, IARG END);if( INS IsMemoryWrite(ins) )INS InsertCall(ins, IPOINT BEFORE, (AFUNPTR) MemRef,IARG THREAD ID, IARG MEMORYWRITE EA, IARG MEMORYWRITE SIZE,IARG UINT32, ACCESS TYPE STORE, IARG END);}int main() {PIN Init();INS AddInstrumentationFunction(Instruction, 0);Pin Tutorial 2007PIN StartProgram();}

Performance ModelsBranch Predictor Models: PC of conditional instructions Direction Predictor: Taken/not-taken information Target Predictor: PC of target instruction if takenCache Models: Thread ID (if multi-threaded workload) Memory address Size of memory operation Type of memory operation (Read/Write)Simple Timing Models: Latency information34Pin Tutorial 2007

Simple Timing ModelAssume 1-stage pipeline Ti cycles for instruction executionAssume branch misprediction penalty Tb cycles penalty for branch mispredictionAssume cache access & miss penalty Tl cycles for demand reference to cache level l Tm cycles for demand reference to memoryLLCTotal cycles αTi βTb ΣAlTl ηTml 1α instruction count; β # branch mispredicts ;Al # accesses to cache level l ; η # last level cache (LLC) misses35Pin Tutorial 2007

Performance - GCCIPCL1 Miss Rate2-way 32KBL2 Miss Rate4-way 256KBL3 Miss Rate8-way 2MBcumulative10 mil phaseSeveral phases of execution Important to pick the correct phase of execution36Pin Tutorial 2007

Performance – AMMPIPCinitrepetitiveL1 Miss Rate2-way 32KBL2 Miss Rate4-way 256KBL3 Miss Rate8-way 2MBcumulative10 mil phaseOne loop (3 billion instructions) is representative High miss rate at beginning; exploits locality at end37Pin Tutorial 2007

Knobs- Getting command argumentsto your PIN toolExample declarations:KNOB string KnobOutputFile(KNOB MODE WRITEONCE,"pintool", "o", "dcache.out", "specify dcache file name");KNOB BOOL KnobTrackLoads(KNOB MODE WRITEONCE,"pintool", "l", "0", "track individual loads -- increasesprofiling time");KNOB UINT32 KnobThresholdMiss(KNOB MODE WRITEONCE, "pintool", "m","100", "onlyreport memops with miss count above threshold");-m # is the command flag to the pin tool100 is the default value“only report ” usage of that parm38Pin Tutorial 2007

Knobs- Getting command argumentsto your PIN toolExample knob use:TrackLoads KnobTrackLoads.Value();if( TrackLoads ){}39Pin Tutorial 2007

3 Pin Tutorial 2007 Advantages of Pin Instrumentation Easy-to-use Instrumentation: Uses dynamic instrumentation – Do not need source code, recompilation, post-linking Programmable Instrumentation: Provides rich APIs to write in C/C your o

Related Documents:

JP3 LVDS VLCD 5V/3.3V /12V Select 4-Pin Block J1 (Pin 1-3) Clear CMOS Setting 10-Pin Block J1 (Pin 5-7) Clear ME Setting 10-Pin Block J1 (Pin 2-4) AT/ATX Mode Function Select 10-Pin Block J1 (Pin 6-8) Disable ME Function Select 10-Pin Block J1 (Pin 9-10) 2-Pin Buzzer Header 10-Pin Block .

6 Cylinders 1 MODEL NO. 1 Product Numbers 2 Keyways 2 KEYWAY 3 CAM OR TAILPIECE 4 FINISH 5 KEYING Mortise Cylinders Model Description 7124 3 4" (19 mm) 4 Pin 7155 15 16" (23.8 mm) 5 Pin 7165 1" (25.4 mm) 5 Pin 7185 11 8" (28.6 mm) 5 Pin Drilled 6 Pin 7186 11 8" (28.6 mm) 6 Pin 7205 11 4" (31.7 mm) 5 Pin Drilled 7 Pin 7206 11 4" (31.7 mm) 6 Pin Drilled 7 Pin .

Refer to AC 43.13-2A/1B. . 2955 Main Road East Emmaus, PA 18049 610-928-3420 www.tcwtech.com email: support@tcwtech.com. 4 pin 9- start contactor pin 8- LED power pin 7- power pin 6- start switch pin 5- arming switch pin 4- armed pwr pin 3- armed LED - pin 1-ground pin 2-ground SmartStart TM Battery Master Solenoid 5 amp Wiring Diagram SS-12v

Infiniti G25 (Smart Key) 2011-2012 Gray, pin 2 Lt. Blue or Red, pin 2 G35 (Smart Key) 2007-2009 Gray, pin 2 Lt. Blue or Red, pin 2 G37 (Smart Key) 2008-2013 Gray, pin 2 Lt. Blue or Red, pin 2 Nissan 370Z (Smart Key) 2009-2013 Gray, pin 2 Brown, pin 2, or Lt. Blue, pin 1 Altima (Smart Key) 2

6sp0134 parts catalog - 8v149 / 12v149 / 16v149 298.33 5126236 pilot 2.00 103385 pin 0.41 103709 pin 0.51 142487 pin 0.01 273436 pin 0.37 455862 pin 0.48 8923521 pin 1.27 9411410 pin 1.93 103373 pin cotter 0.38 103361 pin cotter 1/16x.50lg 1.56

c145580@dac.unicamp.br e m147141@dac.unicamp.br Instituto de Física "Gleb Wataghin" - UNICAMP 20 de outubro de 2017 . devemos inferir tal informação. Ao resolvermos as equações envolvidas para identifi-car os parâmetros de rede, sempre iremos acabar com . inviável fazer tal análise a mão e por isso software espe-cíficos para .

IDS 700 1.0 V A Pin 3 Gnd Pin 3 1000 µF to ground Vin 400 500 Power Supply Voltage (Pin 3) VCC 40 V T Input Voltage Range Voltage Feedback Input (Pin 10) Compensation (Pin 9) Overvoltage Protection Input (Pin 11) R (Pin 6) CT (Pin 7) VIR –1.0 to Vreg V θ Thermal Characteristics P Suff

WITH COTTER PIN BNT-P5 5" CROSS PIN 10 2 5.750 4.250 4.250 .060 WITH COTTER PIN BNT-H1 HUMPED 40 .6 3.750 3.125 2.125 .014 COTTER PIN NOTES: 1) 1 each BNT-H1 humped cotter pin is included with each BNT-P pin. 2) Use the BNT-P4 cross pin with existing steel stanchions. 3) Use the BNT-P5 cross pin with BNT-S nonmetallic stanchions.