The Advantages of Post-link

Orna Raz, Moshe Klausner, Nitzan Peleg, Gad Haber, Eitan Farchi, Shachar Fienblit, Yakov Filiarsky, Shay Gammer and Sergey Novikov

IBM Labs in Haifa © 2006 IBM Corporation IBM Labs in Haifa

What is Code Coverage?

≥ A quality measurement used in ≥ A quantitative way to describe the degree to which the of a program has been tested ≤ Feedback for improving the tests

2 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

How is Code Coverage Done?

≥ Via instrumentation ≤ Adding additional code to collect coverage data ≤ Introduce overhead on time ≥ Source level instrumentation is the common practice ≤ Instrumentation done during compilation ≥ For example gnu tools ≤ gcc/ – compilation + instrumentation ≤ lcov – for analysis

3 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Common Code Coverage Process Obtain Code Coverage Data Analyze Code Coverage

Source Code Coverage Source Code Data

Compilation + Instrumentation Coverage Analysis

Instrumented Code Coverage Views Execution

4 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Post Link Code Coverage Process Obtain Code Coverage Data Analyze Code Coverage

Source Code Coverage Source Code Data Compilation

Executable Coverage Analysis Instrumentation

Instrumented Executable Code Coverage Views Execution

5 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa Motivation for Post-Link Instrumentation ≥ Challenging architectures like kernel & embedded systems ≤ The current solutions (e.g. GCOV) may not address all the issues ± No OS facilities ± Non-terminating code ≥ Integrate code coverage in all tests along the entire development cycle ≤ Same tests for coverage and functional ≤ Enables accumulation of coverage data between phases As a result, coverage: ≤ is done on actual (optimized) code (e.g. SVT) ≤ instrumentation must have low overhead ± The tests cycle period should be reasonable ± The behavior should not be affected (e.g. time outs)

6 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Post-link Code Coverage Characteristics

≥ Works on the running code and does not interfere with optimizations ≥ The coverage data is influenced by the compiler transformation and optimization ≥Different from source level coverage ≥More information available ≥ Enables further reduction in instrumentation overhead

7 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Our Post Link Code Coverage Process Obtain Code Coverage Data Analyze Code Coverage

Optimized Coverage Source Code Executable Data

FDPR-Pro FoCuS Instrumentation Analysis

Instrumented Executable Code Coverage Views Execution

8 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

FoCuS can work with gcov as well (and more) Obtain Code Coverage Data Analyze Code Coverage

Source Code Coverage Source Code Data

gcov Instrumentation FoCuS Analysis

Instrumented Executable Code Coverage Views Execution

9 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Raw Coverage Information From FDPR-Pro

Basic Block – stream of instructions with one entry and one exit with no control flow in the middle

10 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa FoCuS’ Source View with Post-link Mapping

switch (a) { BBS1: li r4, N case 1: cmp r3, r4 a = a * 2 bgt BBD break; BBS2: li r4, 1 case 2: cmp r3,r4 a = a * 4; blt BBD break; BBS3: sub r5,r3,r4 …. ld r6,(BT+r5*4) case N: br r6 a = a * 2^(N-4) BBC1: shl r3, 1 break; b BBE White – no matching BB default: ….. Red – Uncovered Code a = 0; BBCN: shl r3, N Green – Covered code break; b BBE Yellow – Partially } BBD: li r3,0 covered, matches to = a * b BBE: mul r12,r3,r11 covered and non- covered BBs

11 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Working with Post-Link Code Coverage ≥ At the high level same as in regular code coverage ≥ The new methodology provides a compiler transformations dictionary to help with: ≤ White lines – not in the code ± Due to compiler optimization ± No need for additional tests to cover these lines ≤ Yellow lines – partially covered ± Due to the translation of language constructs (e.g. switch statement) ± Due to compiler optimization

12 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Understanding Coverage – Macro Example Partial coverage

13 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa Understanding Coverage - If Example Partial coverage

14 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa Understanding Coverage - If Example (cont) Partial coverage

15 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Low Overhead Instrumentation at Post-Link ≥ Motivation: integrating coverage along the entire development process ≤ More constraints as we approach shipment ≤ And beyond – at the customer site ≥ Post link – a better starting point ≤ Works on optimized code ≤ Lend itself for reducing instrumentation overhead ± Only covered/no-covered is needed ± Using self modifying instrumentation

16 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa Low Overhead Instrumentation - Results

16

) 14 Linux on % (

12

d SPECint2000 a 10 e h

r 8 POWER e v 6 O

e 4 m i

T 2

n gcc 4.1 –O3 0 o i t r f f 2 c y p p n r l e i k t c u p c p -2 a e f o o i z g c v g s g m a e m z a g e r w r r b

-4 t b x a l c e r E p g -6 e v p

A Using Self-modifying 6 4 )

% Code

( 2

d

a 0 e i t h e k d a e p u r e r i s l m g c s k e -2 i r s a p p m i a v a e a g w r a p r w u O m t s e a m

-4 m p q Average a x g e i u e v s m w i

-6 A T

n -8 o i t Function Level INT: 4% / 0.9% u -10 c

e Basic Block Level x -12 SPECfp2000 E -14 FP: 0.4% / -1.4%

17 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Conclusion ≥ Post-link code coverage is useful ≤ Can be mapped back to source code ≤ Enables compiler optimization ≤ Supported by compiler transformation dictionary ≥ In some cases post-link code coverage is better ≤ Enables integrating coverage in the development process ± Near shipment and beyond ≤ More flexible for low overhead instrumentation ≥ Future work - enhancing the visual aids to improve the understanding of more complex compiler optimizations

18 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Questions ?

FoCuS: www.alphaworks.ibm.com/tech/focus

FDPR-Pro: www.haifa.il.ibm.com/projects/systems/cot/fdpr

19 Haifa Verification Conference 2007 © 2007 IBM Corporation IBM Labs in Haifa

Line Number Information and optimization ≥ GCC man “Unlike most other C , GCC allows you to use `-g' with `-O‘” ≥ xlc man “If you specify the -qlinedebug option, the inlining option defaults to -Q! (no functions are inlined).” But inline can be forced and the line-number info will be correct

20 Haifa Verification Conference 2007 © 2007 IBM Corporation