- 1 - Copyright © 2006 Intel Corporation. All Rights Reserved. Using the Pin Instrumentation Tool for Computer Architecture Research Aamer Jaleel, Chi-Keung.

Slides:



Advertisements
Similar presentations
Profiler In software engineering, profiling ("program profiling", "software profiling") is a form of dynamic program analysis that measures, for example,
Advertisements

Instrumentation of Linux Programs with Pin Robert Cohn & C-K Luk Platform Technology & Architecture Development Enterprise Platform Group Intel Corporation.
Integrity & Malware Dan Fleck CS469 Security Engineering Some of the slides are modified with permission from Quan Jia. Coming up: Integrity – Who Cares?
- 1 - Copyright © 2006 Intel Corporation. All Rights Reserved. Fault Analysis Using Pin Srilatha (Bobbie) Manne Intel.
Threads. Readings r Silberschatz et al : Chapter 4.
Pin : Building Customized Program Analysis Tools with Dynamic Instrumentation Chi-Keung Luk, Robert Cohn, Robert Muth, Harish Patil, Artur Klauser, Geoff.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Pin PLDI Tutorial Advantages of Pin Instrumentation Easy-to-use Instrumentation: Uses dynamic instrumentation –Do not need source code, recompilation,
SuperPin: Parallelizing Dynamic Instrumentation for Real-Time Performance Steven Wallace and Kim Hazelwood.
Helper Threads via Virtual Multithreading on an experimental Itanium 2 processor platform. Perry H Wang et. Al.
Enabling Efficient On-the-fly Microarchitecture Simulation Thierry Lafage September 2000.
Pin Tutorial Robert Cohn Intel. Pin Tutorial Academia Sinica About Me Robert Cohn –Original author of Pin –Senior Principal Engineer at Intel –Ph.D.
Software & Services Group PinADX: Customizable Debugging with Dynamic Instrumentation Gregory Lueck, Harish Patil, Cristiano Pereira Intel Corporation.
Aamer Jaleel Intel® Corporation, VSSAD June 17, 2006
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Quiz Wei Hsu 8/16/2006. Which of the following instructions are speculative in nature? A)Data cache prefetch instruction B)Non-faulting loads C)Speculative.
Interrupt Processing Haibo Wang ECE Department
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
San Diego Supercomputer Center Performance Modeling and Characterization Lab PMaC Pin: Building Customized Program Analysis Tools with Dynamic Instrumentation.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
University of Colorado
Fast Dynamic Binary Translation for the Kernel Piyus Kedia and Sorav Bansal IIT Delhi.
Pin2 Tutorial1 Pin Tutorial Kim Hazelwood Robert Muth VSSAD Group, Intel.
Pin PLDI Tutorial Kim Hazelwood David Kaeli Dan Connors Vijay Janapa Reddi.
About Us Kim Hazelwood Vijay Janapa Reddi
Software & Services Group 1 Pin: Intel’s Dynamic Binary Instrumentation Engine Pin Tutorial Intel Corporation Presented By: Tevi Devor CGO ISPASS 2012.
Day 3: Using Process Virtualization Systems Kim Hazelwood ACACES Summer School July 2009.
Orchestra: Intrusion Detection Using Parallel Execution and Monitoring of Program Variants in User-Space Babak Salamat, Todd Jackson, Andreas Gal, Michael.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Analyzing parallel programs with Pin Moshe Bach, Mark Charney, Robert Cohn, Elena Demikhovsky, Tevi Devor, Kim Hazelwood, Aamer Jaleel, Chi- Keung Luk,
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training module provides an overview of optimization techniques used in.
Process Virtualization and Symbiotic Optimization Kim Hazelwood ACACES Summer School July 2009.
Pin: Intel’s Dynamic Binary Instrumentation Engine Pin Tutorial
Support for Debugging Automatically Parallelized Programs Robert Hood Gabriele Jost CSC/MRJ Technology Solutions NASA.
PMaC Performance Modeling and Characterization Performance Modeling and Analysis with PEBIL Michael Laurenzano, Ananta Tiwari, Laura Carrington Performance.
Pin Tutorial Kim Hazelwood David Kaeli Dan Connors Vijay Janapa Reddi.
1 Instrumentation of Intel® Itanium® Linux* Programs with Pin download: Robert Cohn MMDC Intel * Other names and brands.
1 Software Instrumentation and Hardware Profiling for Intel® Itanium® Linux* CGO’04 Tutorial 3/21/04 Robert Cohn, Intel Stéphane Eranian, HP CK Luk, Intel.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Dynamic Compilation and Modification CS 671 April 15, 2008.
Scalable Support for Multithreaded Applications on Dynamic Binary Instrumentation Systems Kim Hazelwood Greg Lueck Robert Cohn.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Day 2: Building Process Virtualization Systems Kim Hazelwood ACACES Summer School July 2009.
1 ICS 51 Introductory Computer Organization Fall 2009.
JIT Instrumentation – A Novel Approach To Dynamically Instrument Operating Systems Marek Olszewski Keir Mierle Adam Czajkowski Angela Demke Brown University.
Part Two: Optimizing Pintools Robert Cohn Kim Hazelwood.
HPC F ORUM S EPTEMBER 8-10, 2009 Steve Rowan srowan at conveycomputer.com.
Performance Optimization of Pintools C K Luk Copyright © 2006 Intel Corporation. All Rights Reserved. Reducing Instrumentation Overhead Total Overhead.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
1 ROGUE Dynamic Optimization Framework Using Pin Vijay Janapa Reddi PhD. Candidate - Electrical And Computer Engineering University of Colorado at Boulder.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Qin Zhao1, Joon Edward Sim2, WengFai Wong1,2 1SingaporeMIT Alliance 2Department of Computer Science National University of Singapore
??? ple r B Amulya Sai EDM14b005 What is simple scalar?? Simple scalar is an open source computer architecture simulator developed by Todd.
Pin: Intel’s Dynamic Binary Instrumentation Engine Pin Tutorial
Kim Hazelwood Robert Cohn Intel SPI-ST
PinADX: Customizable Debugging with Dynamic Instrumentation
CS399 New Beginnings Jonathan Walpole.
Pin: Intel’s Dynamic Binary Instrumentation Engine Pin Tutorial
Advantages of Pin Instrumentation
When your program crashes
Programming with Shared Memory
Programming with Shared Memory
Functions Reasons Concepts Passing arguments to a function
Dynamic Binary Translators and Instrumenters
Computer Architecture and System Programming Laboratory
Presentation transcript:

- 1 - Copyright © 2006 Intel Corporation. All Rights Reserved. Using the Pin Instrumentation Tool for Computer Architecture Research Aamer Jaleel, Chi-Keung Luk, Bobbie Manne, Harish Patil Intel ® Corporation June 17, 2006

- 2 - Copyright © 2006 Intel Corporation. All Rights Reserved. Introduction to Pin CK Luk

- 3 - Copyright © 2006 Intel Corporation. All Rights Reserved. Tutorial Agenda 1:30 – 2:15Introduction to Pin 2:15 – 3:45 Micro-architecture Studies Using Pin: Branch Predictors, Caches, & Simple Timing Models 2:45 – 3:30Techniques for Speeding Up Pin Based Simulation 4:00 – 4:30Performance Optimizations of Pin Tools 4:30 – 5:00Fault Analysis Using Pin 3:30 – 4:00Break

- 4 - Copyright © 2006 Intel Corporation. All Rights Reserved. What is Instrumentation? A technique that inserts extra code into a program to collect runtime information A technique that inserts extra code into a program to collect runtime information Instrumentation approaches: Instrumentation approaches: –Source instrumentation: Instrument source programs –Binary instrumentation: Instrument executables directly our approach

- 5 - Copyright © 2006 Intel Corporation. All Rights Reserved. Example: Instruction Count sub$0xff, %edx cmp%esi, %edx jle jle mov$0x1, %edi add$0x10, %eax counter++;

- 6 - Copyright © 2006 Intel Corporation. All Rights Reserved. Example: Instruction Trace sub$0xff, %edx cmp%esi, %edx jle jle mov$0x1, %edi add$0x10, %eax Print(ip);

- 7 - Copyright © 2006 Intel Corporation. All Rights Reserved. Instrumentation vs. Simulation Advantages of Simulation: Advantages of Simulation: –Detailed modeling of processors –Can model non-existing hardware Advantages of Instrumentation: Advantages of Instrumentation: –Easy to prototype –Fast to run (allowing complete runs)

- 8 - Copyright © 2006 Intel Corporation. All Rights Reserved. How is Instrumentation used in Computer Architecture? Trace Generation Trace Generation Branch Predictor and Cache Modeling Branch Predictor and Cache Modeling Fault Tolerance Study Fault Tolerance Study Emulating Speculation Emulating Speculation Emulating New Instructions Emulating New Instructions

- 9 - Copyright © 2006 Intel Corporation. All Rights Reserved. What is Pin? Easy-to-use Instrumentation: Easy-to-use Instrumentation: –Uses dynamic instrumentation Do not need source code, recompilation, post-linking Programmable Instrumentation: Programmable Instrumentation: –Provides rich APIs to write in C/C++ your own instrumentation tools (called Pintools) Multiplatform: Multiplatform: –Supports IA-32, EM64T, Itanium, Xscale –Supports Linux, Windows, MacOS Robust: Robust: –Instruments real-life applications Database, search engines, web browsers, … –Instruments multithreaded applications Efficient: Efficient: –Applies compiler optimizations on instrumentation code

Copyright © 2006 Intel Corporation. All Rights Reserved. How to use Pin? Launch and instrument an application Launch and instrument an application $ pin –t pintool –- application $ pin –t pintool –- application Instrumentation engine (provided in our kit) Instrumentation tool (write your own, or use one provided in our kit) Attach to and instrument an application Attach to and instrument an application $ pin –t pintool –pid 1234 $ pin –t pintool –pid 1234

Copyright © 2006 Intel Corporation. All Rights Reserved. Writing Pintools

Copyright © 2006 Intel Corporation. All Rights Reserved. Pin Instrumentation APIs Basic APIs are architecture independent: Basic APIs are architecture independent: –Provide common functionalities like determining: Control-flow changes Memory accesses Architecture-specific APIs Architecture-specific APIs –E.g., Info about segmentation registers on IA32 Call-based APIs: Call-based APIs: –Instrumentation routines –Analysis routines

Copyright © 2006 Intel Corporation. All Rights Reserved. Instrumentation vs. Analysis Concepts borrowed from the ATOM tool: Concepts borrowed from the ATOM tool: Instrumentation routines define where instrumentation is inserted Instrumentation routines define where instrumentation is inserted –e.g. before instruction  Occurs first time an instruction is executed Analysis routines define what to do when instrumentation is activated Analysis routines define what to do when instrumentation is activated –e.g. increment counter  Occurs every time an instruction is executed

Copyright © 2006 Intel Corporation. All Rights Reserved. Pintool 1: Instruction Count sub$0xff, %edx cmp%esi, %edx jle jle mov$0x1, %edi add$0x10, %eax counter++;

Copyright © 2006 Intel Corporation. All Rights Reserved. Pintool 1: Instruction Count Output $ /bin/ls Makefile atrace.o imageload.out itrace proccount Makefile.example imageload inscount0 itrace.o proccount.o atrace imageload.o inscount0.o itrace.out $ pin -t inscount0 -- /bin/ls Makefile atrace.o imageload.out itrace proccount Makefile.example imageload inscount0 itrace.o proccount.o atrace imageload.o inscount0.o itrace.out Count

Copyright © 2006 Intel Corporation. All Rights Reserved. ManualExamples/inscount0.C instrumentation routine analysis routine #include #include "pin.h" UINT64 icount = 0; void docount() { icount++; } void Instruction(INS ins, void *v) { INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END); } void Fini(INT32 code, void *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; } Same source code works on the 4 architectures Pin automatically and efficiently saves/restores application state

Copyright © 2006 Intel Corporation. All Rights Reserved. Pintool 2: Instruction Trace sub$0xff, %edx cmp%esi, %edx jle jle mov$0x1, %edi add$0x10, %eax Print(ip); Need to pass an argument (ip) to the analysis routine (printip())

Copyright © 2006 Intel Corporation. All Rights Reserved. Pintool 2: Instruction Trace Output $ pin -t itrace -- /bin/ls Makefile atrace.o imageload.out itrace proccount Makefile.example imageload inscount0 itrace.o proccount.o atrace imageload.o inscount0.o itrace.out $ head -4 itrace.out 0x40001e900x40001e910x40001ee40x40001ee5

Copyright © 2006 Intel Corporation. All Rights Reserved. ManualExamples/itrace.C argument to analysis routine analysis routine instrumentation routine #include #include #include "pin.H" FILE * trace; void printip(void *ip) { fprintf(trace, "%p\n", ip); } void Instruction(INS ins, void *v) { INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR, IARG_END); 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"); trace = fopen("itrace.out", "w"); PIN_Init(argc, argv); PIN_Init(argc, argv); INS_AddInstrumentFunction(Instruction, 0); INS_AddInstrumentFunction(Instruction, 0); PIN_AddFiniFunction(Fini, 0); PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); PIN_StartProgram(); return 0; return 0;}

Copyright © 2006 Intel Corporation. All Rights Reserved. Examples of Arguments to Analysis Routine IARG_INST_PTR IARG_INST_PTR –Instruction pointer (program counter) value IARG_UINT32 IARG_UINT32 –An integer value IARG_REG_VALUE IARG_REG_VALUE –Value of the register specified IARG_BRANCH_TARGET_ADDR IARG_BRANCH_TARGET_ADDR –Target address of the branch instrumented IARG_MEMORY_READ_EA IARG_MEMORY_READ_EA –Effective address of a memory read And many more … (refer to the Pin manual for details)

Copyright © 2006 Intel Corporation. All Rights Reserved. Instrumentation Points Instrument points relative to an instruction: Instrument points relative to an instruction: –Before (IPOINT_BEFORE) –After: Fall-through edge (IPOINT_AFTER) Taken edge (IPOINT_TAKEN) cmp%esi, %edx jle mov$0x1, %edi : mov $0x8,%edi count()

Copyright © 2006 Intel Corporation. All Rights Reserved. Instrumentation Granularity Instrumentation with Pin can be done at 3 different granularities: Instrumentation with Pin can be done at 3 different granularities: –Instruction –Basic block A sequence of instructions terminated at a (conditional or unconditional) control-flow changing instruction Single entry, single exit –Trace A sequence of basic blocks terminated at an unconditional control-flow changing instruction Single entry, multiple exits sub$0xff, %edx cmp%esi, %edx jle mov$0x1, %edi add$0x10, %eax jmp 1 Trace, 2 basic blocks, 6 insts

Copyright © 2006 Intel Corporation. All Rights Reserved. Recap of Pintool 1: Instruction Count sub$0xff, %edx cmp%esi, %edx jle mov$0x1, %edi add$0x10, %eax counter++; Straightforward, but the counting can be more efficient

Copyright © 2006 Intel Corporation. All Rights Reserved. Pintool 3: Faster Instruction Count sub$0xff, %edx cmp%esi, %edx jle mov$0x1, %edi add$0x10, %eax counter += 3 counter += 2 basic blocks (bbl)

Copyright © 2006 Intel Corporation. All Rights Reserved. ManualExamples/inscount1.C #include #include #include "pin.H“ UINT64 icount = 0; void docount(INT32 c) { icount += c; } void Trace(TRACE trace, void *v) { for (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); 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); PIN_Init(argc, argv); TRACE_AddInstrumentFunction(Trace, 0); TRACE_AddInstrumentFunction(Trace, 0); PIN_AddFiniFunction(Fini, 0); PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); PIN_StartProgram(); return 0; return 0;} analysis routine instrumentation routine

Copyright © 2006 Intel Corporation. All Rights Reserved. Modifying Program Behavior Pin allows you not only observing but also changing program behavior Pin allows you not only observing but also changing program behavior Ways to change program behavior: Ways to change program behavior: –Add/delete instructions –Change register values –Change memory values –Change control flow

Copyright © 2006 Intel Corporation. All Rights Reserved. Example: Emulation of Loads sub $0x11c,%esp mov 0xc(%ebp),%eax add $0x128, %eax mov 0x8(%ebp),%edi xor %eax, %edi

Copyright © 2006 Intel Corporation. All Rights Reserved. Example: Emulation of Loads sub $0x11c,%esp mov 0xc(%ebp),%eax add $0x128, %eax mov 0x8(%ebp),%edi xor %eax, %edi EmulateLoad(%ebp+0xc, %eax) EmulateLoad(%ebp+0x8, %edi)

Copyright © 2006 Intel Corporation. All Rights Reserved. Emulation of Loads $ pin -t emuload -- /bin/ls Emulate loading from addr 0xbfffe188 Emulate loading from addr 0x40016ae0 Emulate loading from addr 0x40016c74 Emulate loading from addr 0x40016c7c Emulate loading from addr 0x40016c84 … _insprofiler.Cimageload imageload.out insprofiler.C proccount.C atrace.C

Copyright © 2006 Intel Corporation. All Rights Reserved. SimpleExamples/emuload.C #include #include "pin.H" #include "pin_isa.H" #include // Move from memory to register ADDRINT DoLoad(ADDRINT * addr) { cout << "Emulate loading from addr " << addr << endl; return *addr; } VOID EmulateLoad(INS ins, VOID* v) { if (INS_Opcode(ins) == XEDICLASS_MOV && INS_IsMemoryRead(ins) && INS_OperandIsReg(ins, 0) && INS_OperandIsMemory(ins, 1)) { // op0 <- *op1 INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(DoLoad), IARG_MEMORYREAD_EA, IARG_RETURN_REGS, INS_OperandReg(ins, 0), IARG_END); INS_Delete(ins); } int main(int argc, char * argv[]) { PIN_Init(argc, argv); INS_AddInstrumentFunction(EmulateLoad, 0); PIN_StartProgram(); return 0; } check if ins is a load pass the load data address to DoLoad() use DoLoad()’s return value to modify the register which is the first operand of ins remove ins (the original load)

Copyright © 2006 Intel Corporation. All Rights Reserved. Multithreading Support Notify the pintool when a thread is created or exited Notify the pintool when a thread is created or exited Provide a “thread id” for pintools to identify a thread Provide a “thread id” for pintools to identify a thread Provide locks for pintools to access shared data structures Provide locks for pintools to access shared data structures

Copyright © 2006 Intel Corporation. All Rights Reserved. Example of Instrumenting Multithreaded Programs $ pin –mt -t mtest –- thread Creating thread Joined 0 Joined 1 $ cat mtest.out 0x400109a8: 0 thread begin 1 sp 0x80acc00 flags f00 0x40001d38: 1 thread begin 3 sp 0x43305bd8 flags f21 0x : 3 thread begin 2 sp 0x42302bd8 flags f21 0x40010e15: 2 0x40005cdc: 2 thread end 3 code 0 0x40005e90: 0 thread end 2 code 0 thread end 1 code 0

Copyright © 2006 Intel Corporation. All Rights Reserved. Tests/mtest.C instrumentation routines FILE * out; PIN_LOCK lock; VOID TraceBegin(VOID * ip, UINT32 threadid) { GetLock(&lock, threadid+1); fprintf(out, "%p: %d\n", ip, threadid); ReleaseLock(&lock); } VOID Trace(TRACE trace, VOID *v) { TRACE_InsertCall(trace, IPOINT_BEFORE, AFUNPTR(TraceBegin), IARG_INST_PTR, IARG_THREAD_ID, IARG_END); } VOID ThreadBegin(UINT32 threadid, VOID * sp, int flags, VOID *v) { GetLock(&lock, threadid+1); fprintf(out, "thread begin %d sp %p flags %x\n",threadid, sp, flags); ReleaseLock(&lock); } VOID ThreadEnd(UINT32 threadid, INT32 code, VOID *v) { GetLock(&lock, threadid+1); fprintf(out, "thread end %d code %d\n",threadid, code); ReleaseLock(&lock); } VOID Fini(INT32 code, VOID *v) { fprintf(out, "Fini: code %d\n", code); } int main(INT32 argc, CHAR **argv) { InitLock(&lock); out = fopen("mtest.out", "w"); PIN_Init(argc, argv); PIN_AddThreadBeginFunction(ThreadBegin, 0); PIN_AddThreadEndFunction(ThreadEnd, 0); TRACE_AddInstrumentFunction(Trace, 0); PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); return 0; } analysis routine

Copyright © 2006 Intel Corporation. All Rights Reserved. Debugging Pintools 1. Invoke gdb with your pintool (but don’t use “run”) 2. On another window, start your pintool with “- pause_tool” 3. Go back to gdb: a)Attach to the process b)Use “cont” to continue execution; can set breakpoints as usual (gdb) attach (gdb) break main (gdb) cont $ pin –pause_tool 5 –t inscount0 -- /bin/ls Pausing to attach to pid $ gdb inscount0 (gdb)

Copyright © 2006 Intel Corporation. All Rights Reserved. Conclusions Pin Build your own architectural tools with ease Build your own architectural tools with ease Run on multiple platforms: Run on multiple platforms: –IA-32, EM64T, Itanium, and XScale –Linux, Windows, MacOS Work on real-life applications Work on real-life applications Efficient instrumentation Efficient instrumentation

Copyright © 2006 Intel Corporation. All Rights Reserved. Call For Action Try it out! Free download from: * User manual, many example tools, tutorials * ~7000 downloads since 2004 July Group: