Development/Pahole

From bwHPC Wiki
< Development
Revision as of 15:08, 21 February 2022 by R Keller (talk | contribs) (Update part 1)
Jump to navigation Jump to search

The main documentation is available via module help devel/pahole on the cluster. Most software modules for applications provide working example batch scripts.


Description Content
module load devel/pahole
Availability bwUniCluster
License GPL
Citing n/a
Links Homepage | Releases
Graphical Interface No


Introduction

The poke-a-hole, or short pahole tool is part of the dwarves tool-set. It dissects data structures in binary object files, showing (otherwise useless) padding and data crossing cachelines, allowing optimization and performance analysis of data structures in user- or kernel-code. This tool is worthy to be known by any C and Fortran developer -- the article The lost Art of Structure Packingg by Eric S. Raymond provides an in-detail answer, why.

Documentation

There currently is no web documentation, or tutorial. After loading the module, documentation is provided in the man page.

$ man pahole



Basic commands

Dissecting data structures

You may receive information on the padding and alignment of data structures using pahole. If interested in the data layout pass the option to expand data structures, e.g. the kernel's data structure for every single task, use pahole -E task_struct

struct task_struct {
  struct thread_info {
    long unsigned int  flags;         /*     0     8 */
    unsigned int       status;        /*     8     4 */
  } thread_info;                      /*     0    16 */

  /* XXX last struct has 4 bytes of padding */

  volatile long int    state;         /*    16     8 */
  void *   stack;                     /*    24     8 */
  struct {
    int    counter;                   /*    32     4 */
  } usage;                            /*    32     4 */
  unsigned int         flags;         /*    36     4 */
  unsigned int         ptrace;        /*    40     4 */

  /* XXX 4 bytes hole, try to pack */

  struct llist_node {
    struct llist_node * next;         /*    48     8 */
  } wake_entry;                       /*    48     8 */
  int      on_cpu;                    /*    56     4 */
  unsigned int         cpu;           /*    60     4 */
  /* --- cacheline 1 boundary (64 bytes) --- */
  unsigned int         wakee_flips;   /*    64     4 */
  ...
}

This nicely shows, where the compiler needed to insert padding to adhere to the architecture's alignment requirements specified by the ABI. Additionally it layouts the crossing of past cacheline boundaries, which might be problematic in false sharing of cachelines in multi-threaded programming. Both of this information may be used by You to re-layout your data-structures to minimize them and limit cache-thrashing.

Usage in own application

To employ this in your own application, recompile with compiler option -g. For the following code (part of the Open MPI implementation):