a software performance monitoring tool daniele francesco kruse march 2010

24
Software Performance Monitoring To Software Performance Monitoring To Daniele Francesco Kruse Daniele Francesco Kruse March 2010 March 2010

Upload: miles-domenic-garrett

Post on 08-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

Performance Monitoring DEF : The action of collecting information related to how an application or system performs HOW : Obtain micro-architectural level information from hardware performance counters WHY : To identify bottlenecks, and possibly remove them in order to improve application performance 3

TRANSCRIPT

Page 1: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

A Software Performance Monitoring ToolA Software Performance Monitoring Tool

Daniele Francesco KruseDaniele Francesco Kruse

March 2010March 2010

Page 2: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

SummarySummary

1. Performance Monitoring2. Performance Counters3. Perfmon24. Cycle Accounting Analysis5. Problems6. Overall Analysis7. Symbol Level Analysis8. Module Level Analysis9. Modular Symbol Level Analysis10.What can we do with counters?11.The 3-step empirical optimization

procedure12.Conclusions13.What’s next?

2

Page 3: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Performance MonitoringPerformance Monitoring

DEFDEF : The action of collecting information : The action of collecting information relatedrelated

to how an application or system performsto how an application or system performs

HOWHOW : Obtain micro-architectural level : Obtain micro-architectural level informationinformation

from hardware performance countersfrom hardware performance counters

WHYWHY : To identify bottlenecks, and possibly : To identify bottlenecks, and possibly remove themremove them

in order to improve application performancein order to improve application performance3

Page 4: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Performance CountersPerformance Counters

• All recent processor architectures include a processor–specific PMU

• The Performance Monitoring Unit contains several performance counters

• Performance counters are able to count micro-architectural events from many hardware sources (cpu pipeline, caches, bus, etc…)

• In the Intel Core Microarchitecture :• 3 fixed counters• 2 programmable counters 4

Page 5: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Perfmon2Perfmon2• A generic API to access the PMU (libpfm)• Developed by Stéphane Eranian• Portable across all new processor micro-

architectures• Supports system-wide and per-thread

monitoring• Supports counting and sampling

CPU Hardware

Linux KernelGeneric PerfmonGeneric Perfmon

Architectural Architectural PerfmonPerfmon

PMUPMU

User spacePfmonPfmon Other libpfm-based Other libpfm-based AppsApps

libpfmlibpfm

5

Page 6: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Cycle Accounting AnalysisCycle Accounting Analysis

Total Cycles (Application total execution time)Total Cycles (Application total execution time)

Issuing Issuing μμopsops Not Issuing Not Issuing μμopsops

StalledStalled(no work)(no work)

Not retiring Not retiring μμopsops

(useless work)(useless work)

Retiring Retiring μμopsops

(useful (useful work)work)

Store-FwdStore-FwdL2 L2 missmiss

L2 L2 hithit

LCLCPP

L1 TLB L1 TLB missmiss 6

Page 7: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

ProblemsProblems

• The stall decomposition approach implies a simplification: other kinds of stalls occur

• Performance impact of stalls may have different degree of errors (5% - 20%)

• Is the whole the sum of its parts? Usually, NO. Some events may overlap or their impact be over-estimated

• Values read with performance counters are good approximations of real values (1% - 3%)

• Nevertheless, although quantities may be over or under-estimated, they allow a good qualitative analysis

7

Page 8: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

The 4-way Performance MonitoringThe 4-way Performance Monitoring

8

1. OverallAnalysis

2. Symbol LevelAnalysis

3. Module LevelAnalysis

4. Modular SymbolLevel Analysis

Overall (pfmon)

Modular

Sampling

Counting

Page 9: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Overall AnalysisOverall Analysis

• Uses Pfmon and it is based on the Cycle Accounting Analysis

• Good for showing overall performance and for checking improvements

• Good for identifying general software problems

• Good for comparing different versions of the code

• NOT enough for• finding inefficient parts of the software• finding bad programming practices

9

Page 10: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Overall AnalysisOverall Analysis

10

Page 11: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Symbol Level AnalysisSymbol Level Analysis

• Uses sampling capabilities of pfmon

• Good for identifying general bad programming practices

• Can identify problems of functions which are frequently used

• Shows functions that use most of the execution cycles and functions that spend a lot of time doing nothing (stalling)

• NOT good for finding specific problems in the code

11

Page 12: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Stalled CyclesStalled Cycles

Symbol Level AnalysisSymbol Level Analysis

Total CyclesTotal Cyclescounts %self symbol 54894 3.79% _int_malloc 50972 3.52% __GI___libc_malloc 41321 2.85% __cfree 36294 2.51% ROOT::Math::SMatrix::operator= 31100 2.15% __ieee754_exp 25636 1.77% ROOT::Math::SMatrix::operator= 24833 1.72% do_lookup_x 23206 1.60% ROOT::Math::SMatrix::operator= 22970 1.59% __ieee754_log 21741 1.50% __atan2 20467 1.41% ROOT::Math::SMatrix::operator= 19922 1.38% _int_free 18354 1.27% G__defined_typename 16026 1.11% strcmp 15979 1.10% TList::FindLink 14601 1.01% G__defined_tagname

counts %self symbol 24955 5.09% _int_malloc 19797 4.04% do_lookup_x 19084 3.89% __GI___libc_malloc 14282 2.91% __ieee754_exp 13564 2.77% strcmp 13065 2.66% __cfree 9927 2.02% __atan2 8998 1.83% __ieee754_log 7666 1.56% TList::FindLink 7575 1.54% _int_free 5392 1.10% std::basic_string::find 4911 1.00% computeFullJacobian 4410 0.90% malloc_consolidate 4285 0.87% operator new 4104 0.84% ROOT::Math::SMatrix::operator= 3949 0.81% 33.84% makeAtomStep

12

Page 13: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Module Level AnalysisModule Level Analysis• Uses the Perfmon2 interface (libpfm)

directly

• Analyses each CMSSW module separately

• Allows the identification of “troubled” modules through a sortable HTML table

• Gives instruction statistics and produces detailed graphs to make analysis easier

• It requires 21 identical cmsRun’s (no multiple sets of events are used → more accurate results), but it can be parallelized so (using 7 cores): time = ~3 runs

• Code outside modules is not monitored (framework)

13

DEMO

Page 14: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Module Level Analysis - Results SnapshotModule Level Analysis - Results Snapshot

14

Page 15: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Single Module GraphsSingle Module Graphs

15

Page 16: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Modular Symbol Level Analysis - OverviewModular Symbol Level Analysis - Overview

16

• Uses the Perfmon2 interface (libpfm) directly and analyses each CMSSW module separately

• Sampling periods are specific to each event in order to have reasonable measurements

• The list of modules is a HTML table sortable by number of samples of UNHALTED_CORE_CYCLES

• For each module the complete set of usual events (Cycle Accounting Analysis & others) is sampled

• Results of each module are presented in separate HTML pages in tables sorted by decreasing sample count

DEMO

Page 17: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

The List of ModulesThe List of Modules

17

Page 18: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Table Example of a ModuleTable Example of a Module

18

Page 19: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

An empirical study: An empirical study: What can we do with counters?What can we do with counters?

19

Question:

Is all this useful?

Answer:We don’t

know,but we shall

see• Lack of papers and literature about the

subject

• An empirical study is underway to find out:1. A relationship between counter results and coding

practices2. A practical procedure to use counter results to

optimize a program

• A procedure has already been developed and will be tested

• The trial study will be conducted on Gaudi together with Karol Kruzelecki (PH-LBC group)

Page 20: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

The 3-step empirical optimization procedureThe 3-step empirical optimization procedure

20

• We start from counter results and choose one algorithm to work on using the Improvement Margin and the iFactor.

• We then apply the following procedure:MyAlg : Total Cycles: 1000 , Total Instructions: 1000 MyAlg : Total Cycles: 1000 , Total Instructions: 1000 → CPI: 1.00 → CPI: 1.00

MyAlg : Total Cycles: 300 , Total Instructions: 250 → MyAlg : Total Cycles: 300 , Total Instructions: 250 → CPI: 1.20 CPI: 1.20

MyAlg : Total Cycles: 250 , Total Instructions: 250 → MyAlg : Total Cycles: 250 , Total Instructions: 250 → CPI: 1.00 CPI: 1.00

MyAlg : Total Cycles: 230 , Total Instructions: 250 → MyAlg : Total Cycles: 230 , Total Instructions: 250 → CPI: 0.92 CPI: 0.92

1. Change to a more efficient algorithm and vectorize it

2. Remove stall sources (L1 & L2 misses, store-fwd, etc..)

3. Remove misprediction sources (branches, calls, etc..)

Page 21: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

PfmCodeAnalyserPfmCodeAnalyser : a new tool for fast monitoring : a new tool for fast monitoring

21

• Unreasonable (and useless) to run a complete analysis for every change in code

• Often interested in only small part of code and in one single event

• Solution: a fast, precise and light “singleton” class called PfmCodeAnalyser

• How to use it:#include<PfmCodeAnalyser.h>

PfmCodeAnalyser::Instance(“INSTRUCTIONS_RETIRED”).start();

//code to monitor

PfmCodeAnalyser::Instance().stop();

Page 22: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

From From CoreCore to to NehalemNehalem

22

• All the work described was done for the Intel Core Microarchitecture

• The porting to Nehalem was completed yesterday and will be validated and tested soon

• A new Cycle Accounting model, new performance counters, different latencies and stall impacts, etc...

• Core i7, Xeon 5500 series and NUMA: core (4+3) and uncore counters (8+1)

• CMSSW has been profiled successfully on my Nehalem machine and the results can be found here.

Page 23: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

ConclusionsConclusions

23

1. A consistent set of events has been monitored across the 4 different analysis approaches both in CMSSW and in Gaudi (Cycle Accounting Analysis)

2. An empirical counter-based optimization approach is being studied and tested

3. A new monitoring tool has been developed for quick performance monitoring: PfmCodeAnalyser

4. A new Cycle Accounting Analysis model for Nehalem processors is currently being validated on CMSSW

5. The report and background of the work done for CMSSW is available at http://cern.ch/dkruse/pfmon.pdf

Page 24: A Software Performance Monitoring Tool Daniele Francesco Kruse March 2010

Questions ?Questions ?