Kernel Code Coverage Nilofer Motiwala Computer Sciences Department

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
File Management Systems
Processes CSCI 444/544 Operating Systems Fall 2008.
CS 104 Introduction to Computer Science and Graphics Problems
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
OS Organization. OS Requirements Provide resource abstractions –Process abstraction of CPU/memory use Address space Concurrency Thread abstraction of.
Slide 3-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3 Operating System Organization.
Slide 3-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
© 2004, D. J. Foreman 1 Memory Management. © 2004, D. J. Foreman 2 Building a Module -1  Compiler ■ generates references for function addresses may be.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
March 12, 2001 Kperfmon-MP Multiprocessor Kernel Performance Profiling Alex Mirgorodskii Computer Sciences Department University of Wisconsin.
Slide 3-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3.
Chapter 4 Memory Management Virtual Memory.
Processes Introduction to Operating Systems: Module 3.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
Processes and Virtual Memory
Full and Para Virtualization
© 1999 Ariel TamchesFebruary 19, 1999OSDI ‘99 Fine-Grained Dynamic Instrumentation of Commodity Operating System Kernels Ariel Tamches Barton P. Miller.
© 2001 Week (14 March 2001)Paradyn & Dyninst Demonstrations Paradyn & Dyninst Demos Barton P. Miller Computer.
Department of Computer Sciences, University of Wisconsin Madison DADA – Dynamic Allocation of Disk Area Jayaram Bobba Vivek Shrivastava.
Operating Systems: Summary INF1060: Introduction to Operating Systems and Data Communication.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
1 University of Maryland Using Information About Cache Evictions to Measure the Interactions of Application Data Structures Bryan R. Buck Jeffrey K. Hollingsworth.
WORKING OF SCHEDULER IN OS
Introduction to Operating Systems
Chapter 2: The Linux System Part 4
Non Contiguous Memory Allocation
Virtual Memory CSSE 332 Operating Systems
Virtualization Virtualize hardware resources through abstraction CPU
Chapter 2 Memory and process management
Segmentation COMP 755.
Memory Caches & TLB Virtual Memory
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Modeling Page Replacement Algorithms
Memory Management © 2004, D. J. Foreman.
Swapping Segmented paging allows us to have non-contiguous allocations
PA1 is out Best by Feb , 10:00 pm Enjoy early
DADA – Dynamic Allocation of Disk Area
Chapter 8: Main Memory.
What we need to be able to count to tune programs
Introduction to Operating Systems
O.S Lecture 13 Virtual Memory.
Chapter 9: Virtual-Memory Management
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Page Replacement.
Operating Systems Lecture November 2018.
Modeling Page Replacement Algorithms
Efficient x86 Instrumentation:
CSE 451: Operating Systems Autumn 2005 Memory Management
Operating System Chapter 7. Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Operating Systems: A Modern Perspective, Chapter 3
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
CSE 542: Operating Systems
COMP755 Advanced Operating Systems
Chapter 1: Introduction CSS503 Systems Programming
Dynamic Binary Translators and Instrumenters
Chapter 8 & 9 Main Memory and Virtual Memory
Adaptive Operating Systems: An Architecture for Evolving Systems
Presentation transcript:

Kernel Code Coverage Nilofer Motiwala Computer Sciences Department University of Wisconsin 1210 W. Dayton Street Madison, WI 53706-1685 USA

Motivation Code coverage answers the basic question: How much of my code did I test? Workloads exercise only a subset of the programs functionality Code coverage for an OS kernel Critical due to complex interactions in kernel More difficult to extract information from kernel (Kerninst makes it easy)

Motivation Kernel code coverage is important Workload does not guarantee the same execution pattern over multiple runs Networking behavior Filesystem behavior Error checking code is rarely executed Coverage at basic block level Make sure we are precise in our analysis

Basic Strategy Dynamically instrument all basic blocks Increment a counter at beginning of basic block Periodically sample counter values De-instrument if block has been reached Reduces execution overhead Similar to DynInst code coverage tool for user-level applications, but with new challenges…

Basic Strategy Dynamically instrument all basic blocks Increment a counter at beginning of basic block Periodically sample counter values De-instrument if block has been reached Reduces execution overhead Similar to DynInst code coverage tool for user-level applications, but with new challenges… First application of mass instrumentation

Previous Applications Kernel performance tool (kperfmon) Incremental approach Mass instrumentation not encouraged As a result, no significant issues regarding allocation of space for large number of instrumentation code patches

Previous Applications Kernel performance tool (kperfmon) Incremental approach Mass instrumentation not encouraged As a result, no significant issues regarding allocation of space for large number of instrumentation code patches However, a code coverage tool calls for mass instrumentation, and a perf tool can benefit too

The Problem Challenge is mass instrumentation in kernel Sparc-Solaris7 kernel is large (~3MB) 96 modules 13,000 functions 188,000 basic blocks Jump to instrumentation code using a single instruction Jump range limitation of +/- 8MB Finding space within 8MB for large quantity of instrumentation code is a problem

Instrumentation method Patch Area foo() counter++ (bb1 entry) displaced code counter++ (bb2 entry) displaced code Patch area reached via a branch instruction Replace one instruction w/ branch to patch area However, +/-8MB range limitation of branch Need 188,000 patch areas within range

Instrumentation method Springboards Patch Area foo() jmp patch_addr counter++ (bb1 entry) displaced code jmp patch_addr (bb2 entry) displaced code Mitigate problem by adding indirection Springboard is smaller than a patch area Now, only Springboards have to be in 8MB range Still, need 188,000 Springboards nearby

Patch Area v/s Springboard Kerninst is set up to allocate patch areas anywhere in kernel virtual address space Would like to allocate them close to the code we are instrumenting However, for purposes of code coverage, Springboards are given preference Tradeoff between efficiency and instrumenting more blocks

How much space is needed? Springboard size dictated by patch area address Jump to 32-bit address  three instructions Need ~2 MB in 8 MB range Jump to 64-bit address  six instructions Need ~4 MB in 8 MB range Fortunately, we can place all patches in 32 bit address space

How much space is needed? Springboard size dictated by patch area address Jump to 32-bit address  three instructions Need ~2 MB in 8 MB range Jump to 64-bit address  six instructions Need ~4 MB in 8 MB range Fortunately, we can place all patches in 32 bit address space Still need 2 MB in 8 MB range Trade off space v/s execution effeciency Patch heap space for incrementing counter Seven instructions (confirm!!) Jump to 64-bit address  six instructions  Need ~2.4 MB in 8 MB range Want to place all patch areas in 32-bit address space 7 instructions to inc. counter  need ~2.8 MB in 32-bit address space

Kernel Address Space(64 bit) 0x000.0000.0000 Invalid Kernel Address Space(64 bit) 0x000.1000.0000 Kernel Nucleus 0x000.1040.0000 0x000.1080.0000 0x000.7802.0000 32 bit Kernel heap 0x000.7c00.0000 0x300.0000.0000 64 bit kernel heap 0x302.0000.0000

Kernel Address Space(64 bit) 0x000.0000.0000 Invalid Kernel Address Space(64 bit) 0x000.1000.0000 Kernel Text Segment 0x000.1040.0000 Kernel Data Segment Memory Mgmt Structures 0x000.1080.0000 0x000.7802.0000 32 bit Kernel heap 0x000.7c00.0000 File System Cache 0x300.0000.0000 64 bit kernel heap 0x302.0000.0000

Kernel Address Space(64 bit) 0x000.0000.0000 Invalid Kernel Address Space(64 bit) 0x000.1000.0000 Kernel Text Segment 0x000.1040.0000 Kernel Data Segment Memory Mgmt Structures 8 MB Range 0x000.1080.0000 0x000.7802.0000 32 bit Kernel heap 0x000.7c00.0000 0x300.0000.0000 64 bit kernel heap 0x302.0000.0000

Kernel Address Space(64 bit) 0x000.0000.0000 Invalid Kernel Address Space(64 bit) 0x000.1000.0000 Trap table Kernel Text Segment 0x000.1040.0000 Kernel Data Segment Memory Mgmt Structures 0x000.1080.0000 0x000.7802.0000 32 bit Kernel heap 0x000.7c00.0000 0x300.0000.0000 64 bit kernel heap 0x302.0000.0000

Finding Springboard Space Use all available space in nucleus Allocate free memory directly Overwrite routines that will not be invoked Load dummy modules in kernel 256 MB invalid region in kernel space Unmapped but could it be mapped and used?? 6 MB of free space will be within our branch range

Kernel Address Space(64 bit) 0x000.0000.0000 Invalid Kernel Address Space(64 bit) 0x000.1000.0000 Kernel Text Segment 0x000.1040.0000 Kernel Data Segment Memory Mgmt Structures 8 MB Range 0x000.1080.0000 0x000.7802.0000 32 bit Kernel heap 0x000.7c00.0000 0x300.0000.0000 64 bit kernel heap 0x302.0000.0000

Current Allocations Inside nucleus, able to obtain 260 KB via nucleus malloc (mach_mod_alloc) 64 KB via dummy module and 8 KB by overwriting routines 28,000 Springboards for basic blocks inside nucleus Can successfully allocate all patch heap space in 32 bit kernel heap Able to instrument afs (18,000 basic blocks) 210 KB Springboard space in 32 bit kernel heap Not yet able to instrument the entire kernel

Code Coverage kerninstd Information Flow Kernel Space Data Heap Instrumentation request Sampling request kerninstd ioctl() Patch Heap Data Heap (counters) /dev/kerninst Kernel Space

Code Coverage kerninstd Information Flow Kernel Space Data Heap Instrumentation request Individual counter values Sampling request kerninstd ioctl() Patch Heap Data Heap (counters) /dev/kerninst Kernel Space

Experimental Results Instrumented afs Workload Measurements Build for a large program (code coverage) Find through multiple layers of directories Read all files in /usr/include Measurements Number of functions covered Number of basic blocks covered

Experimental Results for AFS Basic blocks: 18163 Functions: 922

Current Challenges Memory allocation issues Parsing issues More springboard space needed to instrument all basic blocks Parsing issues 206 of 13,000 functions, currently cannot be parsed Unanalyzable jump instructions

Future Work Reduction in number of instrumentation points needed Dominator tree analysis Dyninst Code Coverage tool achieves a reduction of 33%-49% De-instrumentation policy Based on time interval Based on de-instrumentation request queue size Sampling optimization Only samples reflecting a change in value should be sent

Conclusion Kernel Code Coverage Mass instrumentation Gives the ability to know at a fine level, what kernel code is exercised by a given workload Dynamically de-instrument Ongoing work