Notes - MIECT
Sistemas Operativos E De Tempo-real
Notes - MIECT
Sistemas Operativos E De Tempo-real
  • Sistemas Operativos e de Tempo-real
  • Basic Concepts About Real-Time Systems
    • Preliminaries
    • Definitions
    • Objective of the Study of RTS
    • Requirements of Real-Time Systems
  • Real Time Model
    • Real Time Model
    • Temporal Control
    • Task states and execution
    • Kernel/RTOS Architecture
      • Time Management Functions
    • Examples of RTOS
  • Practical Class 01
    • Real-Time Services in Linux
    • Using the Linux real-time services
  • Scheduling Basics
    • Basic concepts
    • Scheduling Algorithms
      • Basic algorithms
    • Static Cyclic Scheduling
    • Exercise
  • Fixed Priority Scheduling
    • Online scheduling with fixed priorities
    • Schedulability tests based on utilization
      • Deadline Monotonic Scheduling DM
    • Response-time analysis
  • Practical Class 2
    • Xenomai brief introduction
    • API
    • Developing an application
  • Dynamic Priority Scheduling
    • On-line scheduling with dynamic priorities
    • Analysis: CPU utilization bound
    • Analysis: CPU Load Analysis
    • Other deadline assignment criteria
  • Exclusive Access to Shared Resources
    • The priority inversion problem
    • Techniques for allowing exclusive access
    • Priority Inheritance Protocol
    • Priority Ceiling Protocol
    • Stack Resource Policy
    • Notes
  • Aperiodic Servers
    • Joint scheduling of periodic and aperiodic tasks
    • Aperiodic Servers
    • Fixed Priority Servers
    • Dynamic Priority Servers
  • Limited preemption, release jitter and overheads
    • Non-preemptive scheduling
    • Impact of Release Jitter
    • Accounting for overheads
    • Considerations about the WCET
  • Profiling and Code Optimization
    • Code optimization techniques
      • CPU independent optimization techniques
      • Cache impact
      • Optimization techniques dependent on memory architecture
      • Architecture-dependent optimization techniques
    • Profiling
  • Multiprocessor Scheduling, V1.2
    • Introduction
    • Definitions, Assumptions and Scheduling Model
    • Scheduling for Multicore Platforms
    • Task allocation
Powered by GitBook
On this page
  • Where to start?
  • Profiling
  • Example
  • Tools
  1. Profiling and Code Optimization

Profiling

PreviousArchitecture-dependent optimization techniquesNextIntroduction

Last updated 2 years ago

Task

Given the source code of a program, possibly written by someone else, perform its optimization!

Where to start?

  • Analyze the source code and detect inefficient “C” code.

  • Re-write some sections in assembly.

  • Use more efficient algorithms.

How to determine which sections to optimize?

  • A typical application consists of many functions spread over different source files.

  • Manual inspection of the entire application code to determine which sections to optimize is in many cases unpractical!

Amdahl’s law

The performance gain that may be obtained when optimizing a section of code is limited to the fraction of the total time that is spent on that particular section.

But how to determine the parts of code that consume the more significant share of CPU?

Profiling

Collection of statistical data carried out on the execution of an application

Fundamental to determine the relative weight of each function.

Approaches:

  • Call graph profiling: function invocation is instrumented.

    • Intrusive requires access to the source code, computationally heavy (overhead can reach 20%).

  • Flat profiling: the application status is sampled at regular time intervals.

    • Accurate as long as the functions execution time is much bigger than the sampling period.

Example

“80/20 Law”

In a “typical” application about 80% of the time is spent in about 20% of the code.

Tools

GNU Gprof

Profiling requires several steps.

  • Compilation and “linking” of the application with debug and profiling active.

    • gcc -pg -o sample sample.c

  • Run the program to generate statistical data (profiling data).

    • ./sample

  • Run the gprof program to analyze the data.

    • gprof ./sample [> text.file]

“-pg”

Generate extra code to write profile information suitable for the analysis program gprof.

GNU Gcov

Coverage test, complementary to gprof.

Indicates the number of times each line is executed.

  • Must compile and link with “-fprofile-arcs -ftest-coverage” to generate additional information needed by gcov.

    • gcc -pg -fprofile-arcs -ftest-coverage -o sample sample.c -lm

  • Run the program to generate statistical data and then run gcov.

    • ./sample

    • gcov sample.c

  • File “sample.c.cov” contains the execution data.

Analyzing the code, an optimization was identified ...

Results with gprof.

There are many other profiling tools. E.g. “perf”:

  • Performance counters for Linux (“perf” or “perf events”): Linux tool that shows performance measurements in the command line interface.

  • Can be used for finding bottlenecks, analysing applications’ execution time, wait latency, CPU cycles, etc.

  • Events of interest can be selected by the user (“perf list” allows to see the supported events).

Execution time reduced by a factor of 106!!!!