Measuring Function Duration with FTrace

From eLinux.org
Revision as of 08:26, 28 October 2011 by Cschalle (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Author

Tim Bird
Sony Corporation of America
tim dot bird (at) am dot sony dot com

Abstract

FTrace is a relatively new kernel tool for tracing function execution in the Linux kernel. Recently, FTrace supports the ability to trace function exit in addition to function entry. This allows for measurement of function duration, which adds an incredibly powerful tool for finding time-consuming areas of kernel execution. In this paper, the current state of the art for measuring function duration with FTrace is described. This includes recent work to add a new capability to filter the trace data by function duration, and tools for analyzing kernel function call graphs and visualizing kernel boot time execution.

Introduction

Overview of FTrace operation

instrumentation at compile time

  • instrumentation of the code using -pg
    • insertion of calls in each function prologue to 'mcount'
    • architecture-specific mcount routine
      • new mcount routine (_gnu_mcount) for ARM??
      • must use frame-pointers on ARM (can't use -fomit-frame-pointers)
      • Not sure it works with EABI (but assembly analysis indicates that all mcount callers have well-defined frames)
  • ability to manually instrument with markers??
    • out of scope

trace setup at run-time

  • pseudo file system
    • selecting a tracer
      • trace functions
        • stub, others
      • tracing parameters
  • collecting trace data
    • cat

tracing operation

  • ring buffer
    • generic mechanism for buffering time-stamped events, per-cpu
    • no other details here.
  • trace functions
    • ring operations
      • reservation, data fillout, commit?

function duration tracer

  • Measuring function duration
    • requires instrumenting function exit
      • option to use -finstrument-functions, which instruments both function entry and function exit
        • conflicts with mechanisms for dynamic ftrace instrumentation
    • hooking function exit using only mcount
      • implement a trampoline
      • details of the ARM trampoline

Using FTrace

  • example of use

interpreting the results

  • cat ftrace
    • trace sample
  • using kd to analyze data
    • measuring function counts


Measuring kernel boot

  • requirements for early boot
    • early clock
    • start location for tracing (optimally start_kernel)
    • static buffer
    • static parameters

performance issues

  • overhead of tracing
    • mention of dynamic tracing (not detailed here)
  • benchmark with and without function tracing?

Roadmap and future work

  • what has not been mainlined (as of 5/09)?

Things to do/add

  • use in early boot
  • mainline patches (again)
  • fix ftd bugs
    • fix negative local-time bug (?? - what is status?)
  • measure early startup
    • use an early-available clock source
      • determine how early the clock is available
    • use a statically-declared ring buffer
      • OR, use something besides a ring buffer temporarily during boot, then
      • transfer the data??
    • use statically-declared trace parameters

Things done

  • ARM function graph tracing - done
  • better clock on ARM - done - used MPU_TIMER instead of 32k timer
  • fix trace recursion on arm (notrace on sched_clock paths) - done
  • duration filtering - done
  • optimize ring_buffer_discard operation for function entry - done
  • convert kd to ftd - started, some issues remaining