2007-01-29 14:18:46 +01:00
|
|
|
/*
|
2006-10-25 17:49:47 +02:00
|
|
|
Copyright (C) 2006 Mandriva Conectiva S.A.
|
|
|
|
Copyright (C) 2006 Arnaldo Carvalho de Melo <acme@mandriva.com>
|
2007-01-29 14:18:46 +01:00
|
|
|
Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
|
2006-10-25 17:49:47 +02:00
|
|
|
|
2006-10-25 01:42:39 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2007-03-30 15:07:01 +02:00
|
|
|
#include <argp.h>
|
2006-10-25 01:42:39 +02:00
|
|
|
#include <stdio.h>
|
2006-10-28 23:22:42 +02:00
|
|
|
#include <dwarf.h>
|
2006-12-18 13:47:39 +01:00
|
|
|
#include <stdarg.h>
|
2006-10-25 01:42:39 +02:00
|
|
|
#include <stdlib.h>
|
2006-11-11 17:15:50 +01:00
|
|
|
#include <string.h>
|
2006-10-25 01:42:39 +02:00
|
|
|
|
2007-05-07 05:30:02 +02:00
|
|
|
#include "dwarves_reorganize.h"
|
2007-01-11 19:07:05 +01:00
|
|
|
#include "dwarves.h"
|
2006-10-25 01:42:39 +02:00
|
|
|
|
2007-01-28 14:07:22 +01:00
|
|
|
static uint8_t class__include_anonymous;
|
|
|
|
static uint8_t class__include_nested_anonymous;
|
|
|
|
|
2006-12-01 02:23:41 +01:00
|
|
|
static char *class__exclude_prefix;
|
|
|
|
static size_t class__exclude_prefix_len;
|
2006-12-01 02:12:21 +01:00
|
|
|
|
2006-12-01 02:36:55 +01:00
|
|
|
static char *cu__exclude_prefix;
|
|
|
|
static size_t cu__exclude_prefix_len;
|
|
|
|
|
2006-12-01 03:08:10 +01:00
|
|
|
static char *decl_exclude_prefix;
|
|
|
|
static size_t decl_exclude_prefix_len;
|
|
|
|
|
2006-12-28 14:18:43 +01:00
|
|
|
static uint16_t nr_holes;
|
|
|
|
static uint16_t nr_bit_holes;
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
static uint16_t hole_size_ge;
|
2006-12-18 19:27:14 +01:00
|
|
|
static uint8_t show_packable;
|
[PAHOLE]: Reorganize bitfields
This cset also does a fixup for cases where the compiler keeps the type
specified by the programmer for a bitfield but uses less space to combine with
the next, non-bitfield member, these cases can be caught using plain pahole and
will appear with this comment:
/* --- cacheline 1 boundary (64 bytes) --- */
int bitfield1:1; /* 64 4 */
int bitfield2:1; /* 64 4 */
/* XXX 14 bits hole, try to pack */
/* Bitfield WARNING: DWARF size=4, real size=2 */
short int d; /* 66 2 */
The fixup is done prior to reorganizing the fields.
Now an example of this code in action:
[acme@filo examples]$ cat swiss_cheese.c
<SNIP>
struct cheese {
char id;
short number;
char name[52];
int a:1;
int b;
int bitfield1:1;
int bitfield2:1;
short d;
short e;
short last:5;
};
<SNIP>
[acme@filo examples]$
Lets look at the layout:
[acme@filo examples]$ pahole swiss_cheese cheese
/* <11b> /home/acme/git/pahole/examples/swiss_cheese.c:3 */
struct cheese {
char id; /* 0 1 */
/* XXX 1 byte hole, try to pack */
short int number; /* 2 2 */
char name[52]; /* 4 52 */
int a:1; /* 56 4 */
/* XXX 31 bits hole, try to pack */
int b; /* 60 4 */
/* --- cacheline 1 boundary (64 bytes) --- */
int bitfield1:1; /* 64 4 */
int bitfield2:1; /* 64 4 */
/* XXX 14 bits hole, try to pack */
/* Bitfield WARNING: DWARF size=4, real size=2 */
short int d; /* 66 2 */
short int e; /* 68 2 */
short int last:5; /* 70 2 */
}; /* size: 72, cachelines: 2 */
/* sum members: 71, holes: 1, sum holes: 1 */
/* bit holes: 2, sum bit holes: 45 bits */
/* bit_padding: 11 bits */
/* last cacheline: 8 bytes */
[acme@filo examples]$
Full of holes, has bit padding and uses more than one 64 bytes cacheline.
Now lets ask pahole to reorganize it:
[acme@filo examples]$ pahole --reorganize --verbose swiss_cheese cheese
/* Demoting bitfield ('a' ... 'a') from 'int' to 'unsigned char' */
/* Demoting bitfield ('bitfield1' ... 'bitfield2') from 'short unsigned int' to 'unsigned char' */
/* Demoting bitfield ('last') from 'short int' to 'unsigned char' */
/* Moving 'bitfield2:1' from after 'bitfield1' to after 'a:1' */
/* Moving 'bitfield1:1' from after 'b' to after 'bitfield2:1' */
/* Moving 'last:5' from after 'e' to after 'bitfield1:1' */
/* Moving bitfield('a' ... 'last') from after 'name' to after 'id' */
/* Moving 'e' from after 'd' to after 'b' */
/* <11b> /home/acme/git/pahole/examples/swiss_cheese.c:3 */
struct cheese {
char id; /* 0 1 */
unsigned char a:1; /* 1 1 */
unsigned char bitfield2:1; /* 1 1 */
unsigned char bitfield1:1; /* 1 1 */
unsigned char last:5; /* 1 1 */
short int number; /* 2 2 */
char name[52]; /* 4 52 */
int b; /* 56 4 */
short int e; /* 60 2 */
short int d; /* 62 2 */
/* --- cacheline 1 boundary (64 bytes) --- */
}; /* size: 64, cachelines: 1 */
/* saved 8 bytes and 1 cacheline! */
[acme@filo examples]$
Instant karma, it gets completely packed, and look ma, no
__attribute__((packed)) :-)
With this struct task_struct in the linux kernel is shrunk by 12 bytes, there
is more 4 bytes to save with another technique that involves not combining
holes, but using the last single hole to fill it with members at the tail of
the struct.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 13:51:16 +01:00
|
|
|
static uint8_t global_verbose;
|
2007-05-11 00:11:51 +02:00
|
|
|
static uint8_t recursive;
|
2007-03-30 15:07:01 +02:00
|
|
|
static size_t cacheline_size;
|
2007-05-10 20:28:00 +02:00
|
|
|
static uint8_t find_containers;
|
2007-03-30 15:07:01 +02:00
|
|
|
static int reorganize;
|
|
|
|
static int show_reorg_steps;
|
2007-04-24 21:09:34 +02:00
|
|
|
static char *class_name;
|
2007-05-23 21:15:21 +02:00
|
|
|
static char separator = '\t';
|
2007-05-24 22:41:16 +02:00
|
|
|
static Dwarf_Off class_dwarf_offset;
|
2006-12-07 19:14:15 +01:00
|
|
|
|
2007-06-22 21:43:29 +02:00
|
|
|
static struct conf_fprintf conf = {
|
2007-05-24 22:18:32 +02:00
|
|
|
.emit_stats = 1,
|
|
|
|
};
|
|
|
|
|
2006-11-04 00:24:37 +01:00
|
|
|
struct structure {
|
2007-05-24 23:45:34 +02:00
|
|
|
struct list_head node;
|
|
|
|
struct class *class;
|
|
|
|
const struct cu *cu;
|
|
|
|
uint32_t nr_files;
|
|
|
|
uint32_t nr_methods;
|
2006-11-04 00:24:37 +01:00
|
|
|
};
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static struct structure *structure__new(struct class *class,
|
2007-01-04 04:41:11 +01:00
|
|
|
const struct cu *cu)
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
|
|
|
struct structure *self = malloc(sizeof(*self));
|
|
|
|
|
|
|
|
if (self != NULL) {
|
2007-01-13 16:59:32 +01:00
|
|
|
self->class = class;
|
|
|
|
self->cu = cu;
|
|
|
|
self->nr_files = 1;
|
|
|
|
self->nr_methods = 0;
|
2006-11-04 00:24:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LIST_HEAD(structures__list);
|
|
|
|
|
|
|
|
static struct structure *structures__find(const char *name)
|
|
|
|
{
|
|
|
|
struct structure *pos;
|
|
|
|
|
2007-01-28 14:07:22 +01:00
|
|
|
if (name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &structures__list, node) {
|
2007-05-24 23:45:34 +02:00
|
|
|
struct class *c = pos->class;
|
|
|
|
const char *cname = class__name(c, pos->cu);
|
2007-04-04 19:44:56 +02:00
|
|
|
|
2007-04-24 21:09:34 +02:00
|
|
|
if (cname == NULL) {
|
2007-04-04 19:44:56 +02:00
|
|
|
if (class__include_anonymous) {
|
|
|
|
const struct tag *tdef =
|
|
|
|
cu__find_first_typedef_of_type(pos->cu,
|
|
|
|
class__tag(c)->id);
|
|
|
|
if (tdef == NULL)
|
|
|
|
continue;
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
cname = class__name(tag__class(tdef), pos->cu);
|
2007-04-24 21:09:34 +02:00
|
|
|
if (cname == NULL)
|
2007-04-04 19:44:56 +02:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-04-24 21:09:34 +02:00
|
|
|
if (strcmp(cname, name) == 0)
|
2006-11-04 00:24:37 +01:00
|
|
|
return pos;
|
2007-01-28 14:07:22 +01:00
|
|
|
}
|
|
|
|
|
2006-11-04 00:24:37 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void structures__add(struct class *class, const struct cu *cu)
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
2007-01-04 04:41:11 +01:00
|
|
|
struct structure *str = structure__new(class, cu);
|
2006-11-04 00:24:37 +01:00
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
if (str != NULL)
|
|
|
|
list_add(&str->node, &structures__list);
|
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void nr_definitions_formatter(struct structure *self)
|
2006-12-18 13:47:39 +01:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
printf("%s%c%u\n", class__name(self->class, self->cu), separator,
|
2007-05-23 21:15:21 +02:00
|
|
|
self->nr_files);
|
2006-11-04 00:24:37 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void nr_members_formatter(struct structure *self)
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
printf("%s%c%u\n", class__name(self->class, self->cu), separator,
|
2007-01-09 13:00:47 +01:00
|
|
|
class__nr_members(self->class));
|
2006-11-04 00:24:37 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void nr_methods_formatter(struct structure *self)
|
2007-01-13 16:59:32 +01:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
printf("%s%c%u\n", class__name(self->class, self->cu), separator,
|
2007-05-23 21:15:21 +02:00
|
|
|
self->nr_methods);
|
2007-01-13 16:59:32 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void size_formatter(struct structure *self)
|
2006-12-18 13:47:39 +01:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
printf("%s%c%zd%c%u\n", class__name(self->class, self->cu), separator,
|
2007-05-23 21:15:21 +02:00
|
|
|
class__size(self->class), separator,
|
|
|
|
self->class->nr_holes);
|
2006-12-18 13:47:39 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class_name_len_formatter(struct structure *self)
|
2006-12-18 13:47:39 +01:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
const char *name = class__name(self->class, self->cu);
|
2007-05-23 21:15:21 +02:00
|
|
|
printf("%s%c%zd\n", name, separator, strlen(name));
|
2006-12-18 13:47:39 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class_name_formatter(struct structure *self)
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
{
|
2007-05-24 23:45:34 +02:00
|
|
|
puts(class__name(self->class, self->cu));
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class_formatter(struct structure *self)
|
2006-12-18 13:47:39 +01:00
|
|
|
{
|
2007-01-28 14:07:22 +01:00
|
|
|
struct tag *typedef_alias = NULL;
|
|
|
|
struct tag *tag = class__tag(self->class);
|
2007-05-24 23:45:34 +02:00
|
|
|
const char *name = class__name(self->class, self->cu);
|
2007-01-28 14:07:22 +01:00
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
/*
|
|
|
|
* Find the first typedef for this struct, this is enough
|
|
|
|
* as if we optimize the struct all the typedefs will be
|
|
|
|
* affected.
|
|
|
|
*/
|
|
|
|
typedef_alias = cu__find_first_typedef_of_type(self->cu,
|
|
|
|
tag->id);
|
|
|
|
/*
|
|
|
|
* If there is no typedefs for this anonymous struct it is
|
|
|
|
* found just inside another struct, and in this case it'll
|
|
|
|
* be printed when the type it is in is printed, but if
|
|
|
|
* the user still wants to see its statistics, just use
|
|
|
|
* --nested_anon_include.
|
|
|
|
*/
|
|
|
|
if (typedef_alias == NULL && !class__include_nested_anonymous)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typedef_alias != NULL) {
|
2007-05-24 23:45:34 +02:00
|
|
|
struct type *tdef = tag__type(typedef_alias);
|
2007-04-28 21:13:35 +02:00
|
|
|
|
|
|
|
conf.prefix = "typedef";
|
2007-05-24 23:45:34 +02:00
|
|
|
conf.suffix = type__name(tdef, self->cu);
|
2007-05-24 22:18:32 +02:00
|
|
|
} else
|
|
|
|
conf.prefix = conf.suffix = NULL;
|
2007-04-28 21:13:35 +02:00
|
|
|
|
|
|
|
tag__fprintf(tag, self->cu, &conf, stdout);
|
2007-01-28 14:07:22 +01:00
|
|
|
|
2007-06-22 21:43:29 +02:00
|
|
|
if (conf.emit_stats)
|
|
|
|
printf("\t/* definitions: %u */\n", self->nr_files);
|
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void print_classes(void (*formatter)(struct structure *s))
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
|
|
|
struct structure *pos;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &structures__list, node)
|
2007-04-01 15:03:04 +02:00
|
|
|
if (show_packable && !global_verbose) {
|
2007-05-24 23:45:34 +02:00
|
|
|
struct class *c = pos->class;
|
2007-04-04 19:11:40 +02:00
|
|
|
const struct tag *t = class__tag(c);
|
2007-04-02 15:12:09 +02:00
|
|
|
const size_t orig_size = class__size(c);
|
|
|
|
const size_t new_size = class__size(c->priv);
|
|
|
|
const size_t savings = orig_size - new_size;
|
2007-05-24 23:45:34 +02:00
|
|
|
const char *name = class__name(c, pos->cu);
|
2007-04-04 18:59:54 +02:00
|
|
|
|
|
|
|
/* Anonymous struct? Try finding a typedef */
|
|
|
|
if (name == NULL) {
|
|
|
|
const struct tag *tdef =
|
|
|
|
cu__find_first_typedef_of_type(pos->cu,
|
2007-04-04 19:11:40 +02:00
|
|
|
t->id);
|
2007-04-04 18:59:54 +02:00
|
|
|
if (tdef != NULL)
|
2007-05-24 23:45:34 +02:00
|
|
|
name = class__name(tag__class(tdef),
|
|
|
|
pos->cu);
|
2007-04-04 18:59:54 +02:00
|
|
|
}
|
2007-04-04 19:11:40 +02:00
|
|
|
if (name != NULL)
|
2007-05-23 21:15:21 +02:00
|
|
|
printf("%s%c%zd%c%zd%c%zd\n",
|
|
|
|
name, separator,
|
|
|
|
orig_size, separator,
|
|
|
|
new_size, separator,
|
|
|
|
savings);
|
2007-04-04 19:11:40 +02:00
|
|
|
else
|
2007-05-23 21:15:21 +02:00
|
|
|
printf("%s(%d)%c%zd%c%zd%c%zd\n",
|
|
|
|
t->decl_file, t->decl_line, separator,
|
|
|
|
orig_size, separator,
|
|
|
|
new_size, separator,
|
|
|
|
savings);
|
2007-04-01 15:03:04 +02:00
|
|
|
} else
|
|
|
|
formatter(pos);
|
2006-11-04 00:24:37 +01:00
|
|
|
}
|
|
|
|
|
2006-12-05 17:58:27 +01:00
|
|
|
static struct cu *cu__filter(struct cu *cu)
|
2006-12-01 02:36:55 +01:00
|
|
|
{
|
|
|
|
if (cu__exclude_prefix != NULL &&
|
|
|
|
(cu->name == NULL ||
|
|
|
|
strncmp(cu__exclude_prefix, cu->name,
|
|
|
|
cu__exclude_prefix_len) == 0))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return cu;
|
|
|
|
}
|
|
|
|
|
2007-04-01 15:03:04 +02:00
|
|
|
static int class__packable(struct class *self, const struct cu *cu)
|
2006-12-07 19:14:15 +01:00
|
|
|
{
|
2007-04-01 14:31:35 +02:00
|
|
|
struct class *clone;
|
|
|
|
size_t savings;
|
2006-12-07 19:14:15 +01:00
|
|
|
|
|
|
|
if (self->nr_holes == 0 && self->nr_bit_holes == 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-04-01 14:31:35 +02:00
|
|
|
clone = class__clone(self, NULL);
|
|
|
|
if (clone == NULL)
|
|
|
|
return 0;
|
|
|
|
class__reorganize(clone, cu, 0, stdout);
|
|
|
|
savings = class__size(self) - class__size(clone);
|
2007-04-01 15:03:04 +02:00
|
|
|
if (savings != 0) {
|
|
|
|
self->priv = clone;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-04-01 14:31:35 +02:00
|
|
|
class__delete(clone);
|
2007-04-01 15:03:04 +02:00
|
|
|
return 0;
|
2006-12-07 19:14:15 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class__dupmsg(struct class *self, const struct cu *cu,
|
2007-01-29 13:42:03 +01:00
|
|
|
const struct class *dup __unused,
|
|
|
|
const struct cu *dup_cu,
|
2006-12-18 13:47:39 +01:00
|
|
|
char *hdr, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (!*hdr)
|
|
|
|
printf("class: %s\nfirst: %s\ncurrent: %s\n",
|
2007-05-24 23:45:34 +02:00
|
|
|
class__name(self, cu), cu->name, dup_cu->name);
|
2007-01-29 14:18:46 +01:00
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
va_start(args, fmt);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
*hdr = 1;
|
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class__chkdupdef(struct class *self, const struct cu *cu,
|
2007-01-04 04:41:11 +01:00
|
|
|
struct class *dup, const struct cu *dup_cu)
|
2006-12-18 13:47:39 +01:00
|
|
|
{
|
|
|
|
char hdr = 0;
|
|
|
|
|
2007-01-09 13:00:47 +01:00
|
|
|
if (class__size(self) != class__size(dup))
|
2007-01-04 04:41:11 +01:00
|
|
|
class__dupmsg(self, cu, dup, dup_cu,
|
|
|
|
&hdr, "size: %u != %u\n",
|
2007-01-09 13:00:47 +01:00
|
|
|
class__size(self), class__size(dup));
|
2006-12-18 13:47:39 +01:00
|
|
|
|
2007-01-09 13:00:47 +01:00
|
|
|
if (class__nr_members(self) != class__nr_members(dup))
|
2007-01-04 04:41:11 +01:00
|
|
|
class__dupmsg(self, cu, dup, dup_cu,
|
|
|
|
&hdr, "nr_members: %u != %u\n",
|
2007-01-09 13:00:47 +01:00
|
|
|
class__nr_members(self), class__nr_members(dup));
|
2006-12-18 14:05:07 +01:00
|
|
|
|
|
|
|
if (self->nr_holes != dup->nr_holes)
|
2007-01-04 04:41:11 +01:00
|
|
|
class__dupmsg(self, cu, dup, dup_cu,
|
|
|
|
&hdr, "nr_holes: %u != %u\n",
|
2006-12-18 14:05:07 +01:00
|
|
|
self->nr_holes, dup->nr_holes);
|
|
|
|
|
|
|
|
if (self->nr_bit_holes != dup->nr_bit_holes)
|
2007-01-04 04:41:11 +01:00
|
|
|
class__dupmsg(self, cu, dup, dup_cu,
|
|
|
|
&hdr, "nr_bit_holes: %u != %u\n",
|
2006-12-18 14:05:07 +01:00
|
|
|
self->nr_bit_holes, dup->nr_bit_holes);
|
|
|
|
|
|
|
|
if (self->padding != dup->padding)
|
2007-01-04 04:41:11 +01:00
|
|
|
class__dupmsg(self, cu, dup, dup_cu,
|
|
|
|
&hdr, "padding: %u != %u\n",
|
2006-12-18 14:05:07 +01:00
|
|
|
self->padding, dup->padding);
|
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
/* XXX put more checks here: member types, member ordering, etc */
|
|
|
|
|
|
|
|
if (hdr)
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static struct tag *tag__filter(struct tag *tag, struct cu *cu,
|
|
|
|
void *cookie __unused)
|
2006-12-01 02:12:21 +01:00
|
|
|
{
|
2006-12-18 13:47:39 +01:00
|
|
|
struct structure *str;
|
2006-12-29 18:28:58 +01:00
|
|
|
struct class *class;
|
2007-01-07 15:30:58 +01:00
|
|
|
const char *name;
|
2006-12-18 13:47:39 +01:00
|
|
|
|
2007-05-31 06:53:01 +02:00
|
|
|
if (!tag__is_struct(tag))
|
2006-12-01 02:12:21 +01:00
|
|
|
return NULL;
|
|
|
|
|
2006-12-29 18:28:58 +01:00
|
|
|
class = tag__class(tag);
|
2007-05-24 23:45:34 +02:00
|
|
|
name = class__name(class, cu);
|
2006-12-01 03:00:24 +01:00
|
|
|
|
2007-01-09 13:00:47 +01:00
|
|
|
if (class__is_declaration(class))
|
2006-12-18 13:47:39 +01:00
|
|
|
return NULL;
|
|
|
|
|
2007-01-28 14:07:22 +01:00
|
|
|
if (!class__include_anonymous && name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2007-04-04 19:21:41 +02:00
|
|
|
if (class__exclude_prefix != NULL) {
|
|
|
|
if (name == NULL) {
|
|
|
|
const struct tag *tdef =
|
|
|
|
cu__find_first_typedef_of_type(cu, tag->id);
|
|
|
|
if (tdef != NULL)
|
2007-05-24 23:45:34 +02:00
|
|
|
name = class__name(tag__class(tdef), cu);
|
2007-04-04 19:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name != NULL && strncmp(class__exclude_prefix, name,
|
|
|
|
class__exclude_prefix_len) == 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-12-01 02:12:21 +01:00
|
|
|
|
2006-12-01 03:08:10 +01:00
|
|
|
if (decl_exclude_prefix != NULL &&
|
2007-01-07 15:30:58 +01:00
|
|
|
(tag->decl_file == NULL ||
|
|
|
|
strncmp(decl_exclude_prefix, tag->decl_file,
|
2006-12-01 03:08:10 +01:00
|
|
|
decl_exclude_prefix_len) == 0))
|
|
|
|
return NULL;
|
|
|
|
|
2007-01-04 04:41:11 +01:00
|
|
|
class__find_holes(class, cu);
|
2006-12-07 19:14:15 +01:00
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
if (class->nr_holes < nr_holes ||
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
class->nr_bit_holes < nr_bit_holes ||
|
|
|
|
(hole_size_ge != 0 && !class__has_hole_ge(class, hole_size_ge)))
|
2006-12-18 13:47:39 +01:00
|
|
|
return NULL;
|
|
|
|
|
2007-01-07 15:30:58 +01:00
|
|
|
str = structures__find(name);
|
2006-12-18 13:47:39 +01:00
|
|
|
if (str != NULL) {
|
[PAHOLE]: Reorganize bitfields
This cset also does a fixup for cases where the compiler keeps the type
specified by the programmer for a bitfield but uses less space to combine with
the next, non-bitfield member, these cases can be caught using plain pahole and
will appear with this comment:
/* --- cacheline 1 boundary (64 bytes) --- */
int bitfield1:1; /* 64 4 */
int bitfield2:1; /* 64 4 */
/* XXX 14 bits hole, try to pack */
/* Bitfield WARNING: DWARF size=4, real size=2 */
short int d; /* 66 2 */
The fixup is done prior to reorganizing the fields.
Now an example of this code in action:
[acme@filo examples]$ cat swiss_cheese.c
<SNIP>
struct cheese {
char id;
short number;
char name[52];
int a:1;
int b;
int bitfield1:1;
int bitfield2:1;
short d;
short e;
short last:5;
};
<SNIP>
[acme@filo examples]$
Lets look at the layout:
[acme@filo examples]$ pahole swiss_cheese cheese
/* <11b> /home/acme/git/pahole/examples/swiss_cheese.c:3 */
struct cheese {
char id; /* 0 1 */
/* XXX 1 byte hole, try to pack */
short int number; /* 2 2 */
char name[52]; /* 4 52 */
int a:1; /* 56 4 */
/* XXX 31 bits hole, try to pack */
int b; /* 60 4 */
/* --- cacheline 1 boundary (64 bytes) --- */
int bitfield1:1; /* 64 4 */
int bitfield2:1; /* 64 4 */
/* XXX 14 bits hole, try to pack */
/* Bitfield WARNING: DWARF size=4, real size=2 */
short int d; /* 66 2 */
short int e; /* 68 2 */
short int last:5; /* 70 2 */
}; /* size: 72, cachelines: 2 */
/* sum members: 71, holes: 1, sum holes: 1 */
/* bit holes: 2, sum bit holes: 45 bits */
/* bit_padding: 11 bits */
/* last cacheline: 8 bytes */
[acme@filo examples]$
Full of holes, has bit padding and uses more than one 64 bytes cacheline.
Now lets ask pahole to reorganize it:
[acme@filo examples]$ pahole --reorganize --verbose swiss_cheese cheese
/* Demoting bitfield ('a' ... 'a') from 'int' to 'unsigned char' */
/* Demoting bitfield ('bitfield1' ... 'bitfield2') from 'short unsigned int' to 'unsigned char' */
/* Demoting bitfield ('last') from 'short int' to 'unsigned char' */
/* Moving 'bitfield2:1' from after 'bitfield1' to after 'a:1' */
/* Moving 'bitfield1:1' from after 'b' to after 'bitfield2:1' */
/* Moving 'last:5' from after 'e' to after 'bitfield1:1' */
/* Moving bitfield('a' ... 'last') from after 'name' to after 'id' */
/* Moving 'e' from after 'd' to after 'b' */
/* <11b> /home/acme/git/pahole/examples/swiss_cheese.c:3 */
struct cheese {
char id; /* 0 1 */
unsigned char a:1; /* 1 1 */
unsigned char bitfield2:1; /* 1 1 */
unsigned char bitfield1:1; /* 1 1 */
unsigned char last:5; /* 1 1 */
short int number; /* 2 2 */
char name[52]; /* 4 52 */
int b; /* 56 4 */
short int e; /* 60 2 */
short int d; /* 62 2 */
/* --- cacheline 1 boundary (64 bytes) --- */
}; /* size: 64, cachelines: 1 */
/* saved 8 bytes and 1 cacheline! */
[acme@filo examples]$
Instant karma, it gets completely packed, and look ma, no
__attribute__((packed)) :-)
With this struct task_struct in the linux kernel is shrunk by 12 bytes, there
is more 4 bytes to save with another technique that involves not combining
holes, but using the last single hole to fill it with members at the tail of
the struct.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-02-01 13:51:16 +01:00
|
|
|
if (global_verbose)
|
2007-01-12 01:11:31 +01:00
|
|
|
class__chkdupdef(str->class, str->cu, class, cu);
|
2006-12-18 13:47:39 +01:00
|
|
|
str->nr_files++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-01 14:31:35 +02:00
|
|
|
if (show_packable && !class__packable(class, cu))
|
2006-12-07 19:14:15 +01:00
|
|
|
return NULL;
|
|
|
|
|
2006-12-29 18:28:58 +01:00
|
|
|
return tag;
|
2006-12-01 02:12:21 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static int unique_iterator(struct tag *tag, struct cu *cu,
|
|
|
|
void *cookie __unused)
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
2007-01-04 04:41:11 +01:00
|
|
|
structures__add(tag__class(tag), cu);
|
2006-11-04 00:24:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
static int cu_unique_iterator(struct cu *cu, void *cookie)
|
2006-11-04 00:24:37 +01:00
|
|
|
{
|
2006-12-29 18:28:58 +01:00
|
|
|
return cu__for_each_tag(cu, unique_iterator, cookie, tag__filter);
|
2006-11-04 00:24:37 +01:00
|
|
|
}
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static struct tag *nr_methods__filter(struct tag *tag, struct cu *cu __unused,
|
|
|
|
void *cookie __unused)
|
2007-01-13 16:59:32 +01:00
|
|
|
{
|
|
|
|
if (tag->tag != DW_TAG_subprogram)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (function__declared_inline(tag__function(tag)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static int nr_methods_iterator(struct tag *tag, struct cu *cu,
|
|
|
|
void *cookie __unused)
|
2007-01-13 16:59:32 +01:00
|
|
|
{
|
|
|
|
struct parameter *pos;
|
|
|
|
struct structure *str;
|
|
|
|
struct type *ctype;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &tag__ftype(tag)->parms, tag.node) {
|
|
|
|
struct tag *type =
|
|
|
|
cu__find_tag_by_id(cu, parameter__type(pos, cu));
|
|
|
|
|
|
|
|
if (type == NULL || type->tag != DW_TAG_pointer_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
type = cu__find_tag_by_id(cu, type->type);
|
2007-05-31 06:53:01 +02:00
|
|
|
if (type == NULL || !tag__is_struct(type))
|
2007-01-13 16:59:32 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ctype = tag__type(type);
|
2007-05-24 23:45:34 +02:00
|
|
|
if (type__name(ctype, cu) == NULL)
|
2007-01-13 16:59:32 +01:00
|
|
|
continue;
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
str = structures__find(type__name(ctype, cu));
|
2007-01-13 16:59:32 +01:00
|
|
|
if (str != NULL)
|
|
|
|
++str->nr_methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cu_nr_methods_iterator(struct cu *cu, void *cookie)
|
|
|
|
{
|
|
|
|
return cu__for_each_tag(cu, nr_methods_iterator, cookie,
|
|
|
|
nr_methods__filter);
|
|
|
|
}
|
|
|
|
|
2007-05-11 00:11:51 +02:00
|
|
|
static char tab[128];
|
|
|
|
|
|
|
|
static void print_containers(const struct structure *s, int ident)
|
2007-05-10 20:28:00 +02:00
|
|
|
{
|
|
|
|
struct structure *pos;
|
2007-05-24 17:16:59 +02:00
|
|
|
const Dwarf_Off type = s->class->type.namespace.tag.id;
|
2007-05-10 20:28:00 +02:00
|
|
|
|
|
|
|
list_for_each_entry(pos, &structures__list, node) {
|
2007-05-24 23:45:34 +02:00
|
|
|
struct class *c = pos->class;
|
2007-05-10 20:28:00 +02:00
|
|
|
const uint32_t n = type__nr_members_of_type(&c->type, type);
|
|
|
|
|
|
|
|
if (n != 0) {
|
2007-05-24 23:45:34 +02:00
|
|
|
printf("%.*s%s", ident * 2, tab, class__name(c, pos->cu));
|
2007-05-10 20:28:00 +02:00
|
|
|
if (global_verbose)
|
|
|
|
printf(": %u", n);
|
|
|
|
putchar('\n');
|
2007-05-11 00:11:51 +02:00
|
|
|
if (recursive)
|
|
|
|
print_containers(pos, ident + 1);
|
2007-05-10 20:28:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 15:07:01 +02:00
|
|
|
static const struct argp_option pahole__options[] = {
|
|
|
|
{
|
|
|
|
.name = "bit_holes",
|
|
|
|
.key = 'B',
|
|
|
|
.arg = "NR_HOLES",
|
|
|
|
.doc = "Show only structs at least NR_HOLES bit holes"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "cacheline_size",
|
|
|
|
.key = 'c',
|
|
|
|
.arg = "SIZE",
|
|
|
|
.doc = "set cacheline size to SIZE"
|
|
|
|
},
|
2007-04-24 21:09:34 +02:00
|
|
|
{
|
|
|
|
.name = "class_name",
|
|
|
|
.key = 'C',
|
|
|
|
.arg = "CLASS_NAME",
|
|
|
|
.doc = "Show just this class"
|
|
|
|
},
|
2007-05-10 20:28:00 +02:00
|
|
|
{
|
|
|
|
.name = "contains",
|
|
|
|
.key = 'i',
|
|
|
|
.arg = "CLASS_NAME",
|
|
|
|
.doc = "Show classes that contains CLASS_NAME"
|
|
|
|
},
|
2007-05-30 16:28:16 +02:00
|
|
|
{
|
|
|
|
.name = "show_decl_info",
|
|
|
|
.key = 'I',
|
|
|
|
.doc = "Show the file and line number where the tags were defined"
|
|
|
|
},
|
2007-03-30 15:07:01 +02:00
|
|
|
{
|
|
|
|
.name = "holes",
|
|
|
|
.key = 'H',
|
|
|
|
.arg = "NR_HOLES",
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
.doc = "show only structs with at least NR_HOLES holes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "hole_size_ge",
|
|
|
|
.key = 'z',
|
|
|
|
.arg = "HOLE_SIZE",
|
|
|
|
.doc = "show only structs with at least one hole greater "
|
|
|
|
"or equal to HOLE_SIZE",
|
2007-03-30 15:07:01 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "packable",
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
.key = 'P',
|
2007-03-30 15:07:01 +02:00
|
|
|
.doc = "show only structs that has holes that can be packed",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "expand_types",
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
.key = 'E',
|
2007-03-30 15:07:01 +02:00
|
|
|
.doc = "expand class members",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "nr_members",
|
|
|
|
.key = 'n',
|
|
|
|
.doc = "show number of members",
|
|
|
|
},
|
2007-05-02 21:14:20 +02:00
|
|
|
{
|
|
|
|
.name = "rel_offset",
|
|
|
|
.key = 'r',
|
|
|
|
.doc = "show relative offsets of members in inner structs"
|
|
|
|
},
|
2007-05-11 00:11:51 +02:00
|
|
|
{
|
|
|
|
.name = "recursive",
|
|
|
|
.key = 'd',
|
|
|
|
.doc = "recursive mode, affects several other flags",
|
|
|
|
},
|
2007-03-30 15:07:01 +02:00
|
|
|
{
|
|
|
|
.name = "reorganize",
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
.key = 'R',
|
2007-03-30 15:07:01 +02:00
|
|
|
.doc = "reorg struct trying to kill holes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "show_reorg_steps",
|
|
|
|
.key = 'S',
|
|
|
|
.doc = "show the struct layout at each reorganization step",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "class_name_len",
|
|
|
|
.key = 'N',
|
|
|
|
.doc = "show size of classes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "nr_methods",
|
|
|
|
.key = 'm',
|
|
|
|
.doc = "show number of methods",
|
|
|
|
},
|
2007-05-30 16:36:54 +02:00
|
|
|
{
|
|
|
|
.name = "show_only_data_members",
|
|
|
|
.key = 'M',
|
|
|
|
.doc = "show only the members that use space in the class layout",
|
|
|
|
},
|
2007-07-05 01:36:28 +02:00
|
|
|
{
|
|
|
|
.name = "expand_pointers",
|
|
|
|
.key = 'p',
|
|
|
|
.doc = "expand class pointer members",
|
|
|
|
},
|
2007-03-30 15:07:01 +02:00
|
|
|
{
|
|
|
|
.name = "sizes",
|
|
|
|
.key = 's',
|
|
|
|
.doc = "show size of classes",
|
|
|
|
},
|
|
|
|
{
|
[PAHOLE]: Introduce --separator/-t
[acme@filo pahole]$ pahole -t, --packable examples/ipv6.ko.debug.x86-64 | sort -t, -k2 -n | tail
inode,1008,1000,8
hh_cache,256,128,128
proto,8512,8504,8
super_block,1184,1168,16
task_struct,3776,3704,72
module,8832,8800,32
pglist_data,10752,10744,8
zone,1536,1352,184
net_device,1664,1208,456
softnet_data,1920,1792,128
[acme@filo pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-23 21:26:39 +02:00
|
|
|
.name = "separator",
|
2007-03-30 15:07:01 +02:00
|
|
|
.key = 't',
|
[PAHOLE]: Introduce --separator/-t
[acme@filo pahole]$ pahole -t, --packable examples/ipv6.ko.debug.x86-64 | sort -t, -k2 -n | tail
inode,1008,1000,8
hh_cache,256,128,128
proto,8512,8504,8
super_block,1184,1168,16
task_struct,3776,3704,72
module,8832,8800,32
pglist_data,10752,10744,8
zone,1536,1352,184
net_device,1664,1208,456
softnet_data,1920,1792,128
[acme@filo pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-23 21:26:39 +02:00
|
|
|
.arg = "SEP",
|
|
|
|
.doc = "use SEP as the field separator",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "nr_definitions",
|
|
|
|
.key = 'T',
|
2007-03-30 15:07:01 +02:00
|
|
|
.doc = "show how many times struct was defined",
|
|
|
|
},
|
2007-05-24 22:41:16 +02:00
|
|
|
{
|
|
|
|
.name = "dwarf_offset",
|
|
|
|
.key = 'O',
|
|
|
|
.arg = "OFFSET",
|
|
|
|
.doc = "Show tag with DWARF OFFSET",
|
|
|
|
},
|
2007-03-30 15:07:01 +02:00
|
|
|
{
|
|
|
|
.name = "decl_exclude",
|
|
|
|
.key = 'D',
|
|
|
|
.arg = "PREFIX",
|
|
|
|
.doc = "exclude classes declared in files with PREFIX",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "exclude",
|
|
|
|
.key = 'x',
|
|
|
|
.arg = "PREFIX",
|
|
|
|
.doc = "exclude PREFIXed classes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "cu_exclude",
|
|
|
|
.key = 'X',
|
|
|
|
.arg = "PREFIX",
|
|
|
|
.doc = "exclude PREFIXed compilation units",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "anon_include",
|
|
|
|
.key = 'a',
|
|
|
|
.doc = "include anonymous classes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "nested_anon_include",
|
|
|
|
.key = 'A',
|
|
|
|
.doc = "include nested (inside other structs) anonymous classes",
|
|
|
|
},
|
2007-06-22 21:43:29 +02:00
|
|
|
{
|
|
|
|
.name = "quiet",
|
|
|
|
.key = 'q',
|
|
|
|
.doc = "be quieter",
|
|
|
|
},
|
2007-03-30 15:07:01 +02:00
|
|
|
{
|
|
|
|
.name = "verbose",
|
|
|
|
.key = 'V',
|
|
|
|
.doc = "be verbose",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = NULL,
|
|
|
|
}
|
2006-11-02 17:47:37 +01:00
|
|
|
};
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void (*formatter)(struct structure *s) = class_formatter;
|
2007-03-30 15:07:01 +02:00
|
|
|
|
|
|
|
static error_t pahole__options_parser(int key, char *arg,
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
struct argp_state *state)
|
2006-11-02 17:47:37 +01:00
|
|
|
{
|
2007-03-30 15:07:01 +02:00
|
|
|
switch (key) {
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
case ARGP_KEY_INIT: state->child_inputs[0] = state->input; break;
|
2007-03-30 15:07:01 +02:00
|
|
|
case 'c': cacheline_size = atoi(arg); break;
|
2007-04-24 21:09:34 +02:00
|
|
|
case 'C': class_name = arg; break;
|
2007-05-11 00:11:51 +02:00
|
|
|
case 'd': recursive = 1; break;
|
2007-05-10 20:28:00 +02:00
|
|
|
case 'i': find_containers = 1;
|
|
|
|
class_name = arg; break;
|
2007-05-30 16:28:16 +02:00
|
|
|
case 'I': conf.show_decl_info = 1; break;
|
2007-03-30 15:07:01 +02:00
|
|
|
case 'H': nr_holes = atoi(arg); break;
|
[LIB]: Introduce class__has_hole_ge()
That returns if the class has a hole greater or equal to the size specified.
Pahole now has a --hole_size_ge command line option to use it.
Example on a linux kernel built for x86_64 where we list the structs that have
holes bigger than 32 bytes, that provides an approximation of structs with
____cacheline_aligned_in_smp annotated members:
[acme@filo pahole]$ pahole --hole_size_ge 32 examples/vmlinux-x86_64
inet_hashinfo
rcu_ctrlblk
hh_cache
net_device
files_struct
module
zone
For instance, look at struct zone clever use of such construct:
_pad1_ is defined with ZONE_PADDING(_pad1_), that is:
/* <40e> /home/acme/git/net-2.6.22/include/linux/mmzone.h:179 */
struct zone {
long unsigned int pages_min; /* 0 8 */
long unsigned int pages_low; /* 8 8 */
long unsigned int pages_high; /* 16 8 */
long unsigned int lowmem_reserve[3]; /* 24 24 */
int node; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
long unsigned int min_unmapped_pages; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int min_slab_pages; /* 64 8 */
struct per_cpu_pageset * pageset[255]; /* 72 2040 */
/* --- cacheline 33 boundary (2112 bytes) --- */
spinlock_t lock; /* 2112 4 */
/* XXX 4 bytes hole, try to pack */
struct free_area free_area[11]; /* 2120 264 */
/* XXX 48 bytes hole, try to pack */
/* --- cacheline 38 boundary (2432 bytes) --- */
struct zone_padding _pad1_; /* 2432 0 */
spinlock_t lru_lock; /* 2432 4 */
/* XXX 4 bytes hole, try to pack */
struct list_head active_list; /* 2440 16 */
struct list_head inactive_list; /* 2456 16 */
long unsigned int nr_scan_active; /* 2472 8 */
long unsigned int nr_scan_inactive; /* 2480 8 */
long unsigned int pages_scanned; /* 2488 8 */
/* --- cacheline 39 boundary (2496 bytes) --- */
int all_unreclaimable; /* 2496 4 */
atomic_t reclaim_in_progress; /* 2500 4 */
atomic_long_t vm_stat[20]; /* 2504 160 */
/* --- cacheline 41 boundary (2624 bytes) was 40 bytes ago --- */
int prev_priority; /* 2664 4 */
/* XXX 20 bytes hole, try to pack */
/* --- cacheline 42 boundary (2688 bytes) --- */
struct zone_padding _pad2_; /* 2688 0 */
wait_queue_head_t * wait_table; /* 2688 8 */
long unsigned int wait_table_hash_nr_entries; /* 2696 8 */
long unsigned int wait_table_bits; /* 2704 8 */
struct pglist_data * zone_pgdat; /* 2712 8 */
long unsigned int zone_start_pfn; /* 2720 8 */
long unsigned int spanned_pages; /* 2728 8 */
long unsigned int present_pages; /* 2736 8 */
const char * name; /* 2744 8 */
/* --- cacheline 43 boundary (2752 bytes) --- */
}; /* size: 2752, cachelines: 43 */
/* sum members: 2672, holes: 5, sum holes: 80 */
/* definitions: 933 */
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-11 18:32:53 +02:00
|
|
|
case 'z':
|
|
|
|
hole_size_ge = atoi(arg);
|
|
|
|
if (!global_verbose)
|
|
|
|
formatter = class_name_formatter;
|
|
|
|
break;
|
2007-03-30 15:07:01 +02:00
|
|
|
case 'B': nr_bit_holes = atoi(arg); break;
|
2007-05-24 22:18:32 +02:00
|
|
|
case 'E': conf.expand_types = 1; break;
|
2007-07-05 01:36:28 +02:00
|
|
|
case 'p': conf.expand_pointers = 1; break;
|
2007-05-24 22:18:32 +02:00
|
|
|
case 'r': conf.rel_offset = 1; break;
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
case 'R': reorganize = 1; break;
|
2007-03-30 15:07:01 +02:00
|
|
|
case 'S': show_reorg_steps = 1; break;
|
|
|
|
case 's': formatter = size_formatter; break;
|
|
|
|
case 'n': formatter = nr_members_formatter; break;
|
|
|
|
case 'N': formatter = class_name_len_formatter; break;
|
|
|
|
case 'm': formatter = nr_methods_formatter; break;
|
2007-05-30 16:36:54 +02:00
|
|
|
case 'M': conf.show_only_data_members = 1; break;
|
2007-05-24 22:41:16 +02:00
|
|
|
case 'O': class_dwarf_offset = strtoul(arg, NULL, 0); break;
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
case 'P': show_packable = 1; break;
|
[PAHOLE]: Introduce --separator/-t
[acme@filo pahole]$ pahole -t, --packable examples/ipv6.ko.debug.x86-64 | sort -t, -k2 -n | tail
inode,1008,1000,8
hh_cache,256,128,128
proto,8512,8504,8
super_block,1184,1168,16
task_struct,3776,3704,72
module,8832,8800,32
pglist_data,10752,10744,8
zone,1536,1352,184
net_device,1664,1208,456
softnet_data,1920,1792,128
[acme@filo pahole]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-05-23 21:26:39 +02:00
|
|
|
case 't': separator = arg[0]; break;
|
|
|
|
case 'T': formatter = nr_definitions_formatter; break;
|
2007-03-30 15:07:01 +02:00
|
|
|
case 'a': class__include_anonymous = 1; break;
|
|
|
|
case 'A': class__include_nested_anonymous = 1; break;
|
|
|
|
case 'D': decl_exclude_prefix = arg;
|
|
|
|
decl_exclude_prefix_len = strlen(decl_exclude_prefix);
|
|
|
|
break;
|
|
|
|
case 'x': class__exclude_prefix = arg;
|
|
|
|
class__exclude_prefix_len = strlen(class__exclude_prefix);
|
|
|
|
break;
|
|
|
|
case 'X': cu__exclude_prefix = arg;
|
|
|
|
cu__exclude_prefix_len = strlen(cu__exclude_prefix);
|
|
|
|
break;
|
2007-06-22 21:52:00 +02:00
|
|
|
case 'q': conf.emit_stats = 0;
|
|
|
|
conf.suppress_comments = 1; break;
|
2007-05-30 16:28:16 +02:00
|
|
|
case 'V': global_verbose = 1; break;
|
2007-03-30 15:07:01 +02:00
|
|
|
default:
|
|
|
|
return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-11-02 17:47:37 +01:00
|
|
|
}
|
|
|
|
|
2007-04-24 21:09:34 +02:00
|
|
|
static const char pahole__args_doc[] = "[FILE]";
|
2007-03-30 15:07:01 +02:00
|
|
|
|
|
|
|
static struct argp pahole__argp = {
|
|
|
|
.options = pahole__options,
|
|
|
|
.parser = pahole__options_parser,
|
|
|
|
.args_doc = pahole__args_doc,
|
|
|
|
};
|
|
|
|
|
2006-10-28 19:08:46 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-11-11 19:31:04 +01:00
|
|
|
struct cus *cus;
|
2007-05-11 00:11:51 +02:00
|
|
|
int err;
|
2006-11-02 17:47:37 +01:00
|
|
|
|
2007-01-07 15:30:58 +01:00
|
|
|
cus = cus__new(NULL, NULL);
|
2006-11-11 19:31:04 +01:00
|
|
|
if (cus == NULL) {
|
|
|
|
fputs("pahole: insufficient memory\n", stderr);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-04-24 21:09:34 +02:00
|
|
|
err = cus__loadfl(cus, &pahole__argp, argc, argv);
|
[PAHOLE]: Use cus__loadfl, i.e. libdwfl
Now we have:
[acme@filo pahole]$ pahole --help
Usage: pahole [OPTION...] [FILE] {[CLASS]}
-a, --anon_include include anonymous classes
-A, --nested_anon_include include nested (inside other structs) anonymous
classes
-B, --bit_holes=NR_HOLES Show only structs at least NR_HOLES bit holes
-c, --cacheline_size=SIZE set cacheline size to SIZE
-D, --decl_exclude=PREFIX exclude classes declared in files with PREFIX
-E, --expand_types expand class members
-H, --holes=NR_HOLES show only structs at least NR_HOLES holes
-m, --nr_methods show number of methods
-n, --nr_members show number of members
-N, --class_name_len show size of classes
-P, --packable show only structs that has holes that can be
packed
-R, --reorganize reorg struct trying to kill holes
-s, --sizes show size of classes
-S, --show_reorg_steps show the struct layout at each reorganization step
-t, --nr_definitions show how many times struct was defined
-V, --verbose be verbose
-x, --exclude=PREFIX exclude PREFIXed classes
-X, --cu_exclude=PREFIX exclude PREFIXed compilation units
Input Selection:
--debuginfo-path=PATH Search path for separate debuginfo files
-e, --executable=FILE Find addresses in FILE
-k, --kernel Find addresses in the running kernel
-K, --offline-kernel[=RELEASE] Kernel with all modules
-M, --linux-process-map=FILE Find addresses in files mapped as read from
FILE in Linux /proc/PID/maps format
-p, --pid=PID Find addresses in files mapped into process PID
-?, --help Give this help list
--usage Give a short usage message
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
2007-03-30 18:25:51 +02:00
|
|
|
if (err != 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
dwarves__init(cacheline_size);
|
|
|
|
|
2007-05-24 22:41:16 +02:00
|
|
|
if (class_dwarf_offset != 0) {
|
|
|
|
struct cu *cu;
|
|
|
|
struct tag *tag = cus__find_tag_by_id(cus, &cu,
|
|
|
|
class_dwarf_offset);
|
|
|
|
if (tag == NULL) {
|
|
|
|
fprintf(stderr, "id %llx not found!\n",
|
|
|
|
class_dwarf_offset);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag__fprintf(tag, cu, &conf, stdout);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
cus__for_each_cu(cus, cu_unique_iterator, NULL, cu__filter);
|
2007-01-13 16:59:32 +01:00
|
|
|
if (formatter == nr_methods_formatter)
|
|
|
|
cus__for_each_cu(cus, cu_nr_methods_iterator, NULL, cu__filter);
|
2006-12-18 13:47:39 +01:00
|
|
|
|
2007-05-11 00:11:51 +02:00
|
|
|
memset(tab, ' ', sizeof(tab) - 1);
|
|
|
|
|
2006-12-18 13:47:39 +01:00
|
|
|
if (class_name != NULL) {
|
|
|
|
struct structure *s = structures__find(class_name);
|
|
|
|
|
|
|
|
if (s == NULL) {
|
2007-03-30 15:07:01 +02:00
|
|
|
fprintf(stderr, "struct %s not found!\n", class_name);
|
2006-12-18 13:47:39 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2007-01-30 16:32:55 +01:00
|
|
|
if (reorganize) {
|
|
|
|
size_t savings;
|
2007-02-01 15:27:43 +01:00
|
|
|
const uint8_t reorg_verbose =
|
|
|
|
show_reorg_steps ? 2 : global_verbose;
|
2007-02-01 17:09:48 +01:00
|
|
|
struct class *clone = class__clone(s->class, NULL);
|
2007-01-30 16:32:55 +01:00
|
|
|
if (clone == NULL) {
|
2007-03-30 15:07:01 +02:00
|
|
|
fprintf(stderr, "pahole: out of memory!\n");
|
2007-01-30 16:32:55 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2007-02-01 16:50:28 +01:00
|
|
|
class__reorganize(clone, s->cu, reorg_verbose, stdout);
|
2007-01-30 16:32:55 +01:00
|
|
|
savings = class__size(s->class) - class__size(clone);
|
2007-02-01 15:27:43 +01:00
|
|
|
if (savings != 0 && reorg_verbose) {
|
2007-01-30 16:32:55 +01:00
|
|
|
putchar('\n');
|
2007-02-01 15:27:43 +01:00
|
|
|
if (show_reorg_steps)
|
|
|
|
puts("/* Final reorganized struct: */");
|
|
|
|
}
|
2007-04-28 21:13:35 +02:00
|
|
|
tag__fprintf(class__tag(clone), s->cu, &conf, stdout);
|
2007-01-30 16:32:55 +01:00
|
|
|
if (savings != 0) {
|
|
|
|
const size_t cacheline_savings =
|
|
|
|
(tag__nr_cachelines(class__tag(s->class),
|
|
|
|
s->cu) -
|
|
|
|
tag__nr_cachelines(class__tag(clone),
|
|
|
|
s->cu));
|
|
|
|
|
2007-03-28 16:38:32 +02:00
|
|
|
printf(" /* saved %zd byte%s", savings,
|
2007-01-30 16:32:55 +01:00
|
|
|
savings != 1 ? "s" : "");
|
|
|
|
if (cacheline_savings != 0)
|
|
|
|
printf(" and %zu cacheline%s",
|
|
|
|
cacheline_savings,
|
|
|
|
cacheline_savings != 1 ?
|
|
|
|
"s" : "");
|
|
|
|
puts("! */");
|
|
|
|
}
|
2007-05-10 20:28:00 +02:00
|
|
|
} else if (find_containers)
|
2007-05-11 00:11:51 +02:00
|
|
|
print_containers(s, 0);
|
2007-05-10 20:28:00 +02:00
|
|
|
else
|
2007-04-28 21:13:35 +02:00
|
|
|
tag__fprintf(class__tag(s->class), s->cu, &conf, stdout);
|
2006-12-18 19:27:14 +01:00
|
|
|
} else
|
2006-12-18 13:47:39 +01:00
|
|
|
print_classes(formatter);
|
2006-10-25 18:32:07 +02:00
|
|
|
|
2006-10-28 19:08:46 +02:00
|
|
|
return EXIT_SUCCESS;
|
2006-10-25 01:42:39 +02:00
|
|
|
}
|