dwarves_fprintf: Count bitfield member sizes separately

Counting field sizes only in bits causes confusion and lots of differing
output, when compared to previous logic. This commit changes logic so
that it counts bit size of bitfield fields separately from byte size of
non-bitfield fields. In the end, if there were bit holes, this bit size
is emitted explicitly. This makes output for struct/unions not using
bitfields identical, while also preserving correctness (and data
completeness) for cases with bitfields and bit holes.

Example (-before/+after):
 struct cfg80211_pmsr_request_peer {
        u8                         addr[6];              /*     0     6 */

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

        struct cfg80211_chan_def   chandef;              /*     8    24 */

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

        u8                         report_ap_tsf:1;      /*    32: 0  1 */

        /* XXX 7 bits hole, try to pack */
        /* XXX 3 bytes hole, try to pack */

        struct cfg80211_pmsr_ftm_request_peer ftm;       /*    36    12 */

        /* XXX last struct has 1 byte of padding */

        /* size: 48, cachelines: 1, members: 4 */
-       /* sum members: 43, holes: 2, sum holes: 5 */
-       /* bit holes: 1, sum bit holes: 7 bits */
+       /* sum members: 42, holes: 2, sum holes: 5 */
+       /* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 7 bits */
        /* paddings: 2, sum paddings: 5 */
        /* last cacheline: 48 bytes */
 };

For cases where there is only byte or bit hole, we still emit total byte and
bit sizes of all members as to not mislead user:
 struct sched_dl_entity {
... <snip ...
        unsigned int               dl_non_contending:1;  /*    84: 3  4 */
        unsigned int               dl_overrun:1;         /*    84: 4  4 */

        /* XXX 27 bits hole, try to pack */

        struct hrtimer             dl_timer;             /*    88    64 */

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

        /* --- cacheline 2 boundary (128 bytes) was 24 bytes ago --- */
        struct hrtimer             inactive_timer;       /*   152    64 */

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

        /* size: 216, cachelines: 4, members: 16 */
-       /* bit holes: 1, sum bit holes: 27 bits */
+       /* sum members: 212 */
+       /* sum bitfield members: 5 bits, bit holes: 1, sum bit holes: 27 bits */
        /* paddings: 2, sum paddings: 10 */
        /* last cacheline: 24 bytes */
 };

For structs with tightly packed bitfield, we emit total number of bits and also
convert them to bytes. E.g., for struct sock output :
struct sock {
... <snip ...
        /* size: 720, cachelines: 12, members: 84 */
-       /* sum members: 712, holes: 4, sum holes: 8 */
+       /* sum members: 707, holes: 4, sum holes: 8 */
+       /* sum bitfield members: 40 bits (5 bytes) */
        /* paddings: 1, sum paddings: 4 */
        /* last cacheline: 16 bytes */
 };

Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 file changed