[CLASSES]: Print cacheline boundary at the end of a struct too

Useful for structs where cacheline crossings happens on the last
member:

[acme@newtoy net-2.6]$ pahole --cacheline 32 net/ipv4/route.o hh_cache
/* /pub/scm/linux/kernel/git/acme/net-2.6/include/linux/netdevice.h:193 */
struct hh_cache {
        struct hh_cache *  hh_next;          /*  0   4 */
        atomic_t           hh_refcnt;        /*  4   4 */
        __be16             hh_type;          /*  8   2 */
        u16                hh_len;           /* 10   2 */
        int                (*hh_output)();   /* 12   4 */
        rwlock_t           hh_lock;          /* 16   0 */
        long unsigned int  hh_data[24];      /* 16  96 */
        /* --- cacheline 3 boundary (96 bytes) was 16 bytes ago --- */
}; /* size: 112, cachelines: 4 */
   /* last cacheline: 16 bytes */

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2006-12-07 19:20:46 -02:00
parent d479b9c8e5
commit fd1b4cadc2
1 changed files with 29 additions and 18 deletions

View File

@ -945,6 +945,30 @@ void function__print(const struct function *self, int show_stats,
}
}
static int class__print_cacheline_boundary(uint32_t last_cacheline,
size_t sum, size_t sum_holes)
{
const unsigned int real_sum = sum + sum_holes;
const unsigned int cacheline = real_sum / cacheline_size;
if (cacheline > last_cacheline) {
const unsigned int cacheline_pos = real_sum % cacheline_size;
const unsigned cacheline_in_bytes = real_sum - cacheline_pos;
if (cacheline_pos == 0)
printf(" /* --- cacheline "
"%u boundary (%u bytes) --- */\n",
cacheline, cacheline_in_bytes);
else
printf(" /* --- cacheline "
"%u boundary (%u bytes) was %u "
"bytes ago --- */\n",
cacheline, cacheline_in_bytes,
cacheline_pos);
}
return cacheline;
}
static void class__print_struct(struct class *self)
{
unsigned long sum = 0;
@ -959,24 +983,9 @@ static void class__print_struct(struct class *self)
printf("%s {\n", class__name(self, name, sizeof(name)));
list_for_each_entry(pos, &self->members, tag.node) {
const unsigned int real_sum = sum + sum_holes;
const unsigned int cacheline = real_sum / cacheline_size;
if (cacheline > last_cacheline) {
const unsigned int cacheline_pos = real_sum % cacheline_size;
const unsigned cacheline_in_bytes = real_sum - cacheline_pos;
if (cacheline_pos == 0)
printf(" /* --- cacheline "
"%u boundary (%u bytes) --- */\n",
cacheline, cacheline_in_bytes);
else
printf(" /* --- cacheline "
"%u boundary (%u bytes) was %u "
"bytes ago --- */\n",
cacheline, cacheline_in_bytes,
cacheline_pos);
last_cacheline = cacheline;
}
last_cacheline = class__print_cacheline_boundary(last_cacheline,
sum,
sum_holes);
fputs(" ", stdout);
size = class_member__print(pos);
@ -1015,6 +1024,8 @@ static void class__print_struct(struct class *self)
last_bit_size = pos->bit_size;
}
class__print_cacheline_boundary(last_cacheline, sum, sum_holes);
printf("}; /* size: %llu, cachelines: %llu */\n", self->size,
(self->size + cacheline_size - 1) / cacheline_size);
if (sum_holes > 0)