Patchwork [09/11] fdc: avoid structure holes spotted by pahole

login
register
mail settings
Submitter Blue Swirl
Date Aug. 7, 2011, 9:01 p.m.
Message ID <CAAu8pHtxgJ02AC3oMmm-pYeYOCGPAkRPdiUOeRtVFZmn-p2kwQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/108849/
State New
Headers show

Comments

Blue Swirl - Aug. 7, 2011, 9:01 p.m.
Edited report from pahole on amd64 host:
struct FDCtrl {
	uint8_t                    version;              /*     0     1 */

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

	qemu_irq                   irq;                  /*     8     8 */
	int                        dma_chann;            /*    16     4 */

	/* XXX 4 bytes hole, try to pack */
...
	uint8_t                    status2;              /*    42     1 */

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

	uint8_t *                  fifo;                 /*    48     8 */
...
	uint8_t                    pwrd;                 /*    76     1 */

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

	int                        sun4m;                /*    80     4 */
	uint8_t                    num_floppies;         /*    84     1 */

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

	FDrive                     drives[2];            /*    88    64 */
	/* --- cacheline 2 boundary (128 bytes) was 24 bytes ago --- */
	int                        reset_sensei;         /*   152     4 */

	/* size: 160, cachelines: 3 */
	/* sum members: 134, holes: 5, sum holes: 22 */
	/* padding: 4 */
	/* last cacheline: 32 bytes */
};	/* definitions: 1 */

Fix by rearranging the structure to avoid padding.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/fdc.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

Patch

From 12ec5e100f9198cd6a6be2b00e17b5399eecbaa7 Mon Sep 17 00:00:00 2001
Message-Id: <12ec5e100f9198cd6a6be2b00e17b5399eecbaa7.1312750600.git.blauwirbel@gmail.com>
In-Reply-To: <54eae070f9056790fa41b468360d23cdd17503f4.1312750600.git.blauwirbel@gmail.com>
References: <54eae070f9056790fa41b468360d23cdd17503f4.1312750600.git.blauwirbel@gmail.com>
From: Blue Swirl <blauwirbel@gmail.com>
Date: Sun, 7 Aug 2011 19:43:38 +0000
Subject: [PATCH 09/11] fdc:avoid structure holes spotted by pahole

Edited report from pahole on amd64 host:
struct FDCtrl {
	uint8_t                    version;              /*     0     1 */

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

	qemu_irq                   irq;                  /*     8     8 */
	int                        dma_chann;            /*    16     4 */

	/* XXX 4 bytes hole, try to pack */
...
	uint8_t                    status2;              /*    42     1 */

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

	uint8_t *                  fifo;                 /*    48     8 */
...
	uint8_t                    pwrd;                 /*    76     1 */

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

	int                        sun4m;                /*    80     4 */
	uint8_t                    num_floppies;         /*    84     1 */

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

	FDrive                     drives[2];            /*    88    64 */
	/* --- cacheline 2 boundary (128 bytes) was 24 bytes ago --- */
	int                        reset_sensei;         /*   152     4 */

	/* size: 160, cachelines: 3 */
	/* sum members: 134, holes: 5, sum holes: 22 */
	/* padding: 4 */
	/* last cacheline: 32 bytes */
};	/* definitions: 1 */

Fix by rearranging the structure to avoid padding.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/fdc.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index edf0360..580b657 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -374,13 +374,13 @@  enum {
 #define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
 
 struct FDCtrl {
-    /* Controller's identification */
-    uint8_t version;
-    /* HW */
     qemu_irq irq;
-    int dma_chann;
     /* Controller state */
     QEMUTimer *result_timer;
+    int dma_chann;
+    /* Controller's identification */
+    uint8_t version;
+    /* HW */
     uint8_t sra;
     uint8_t srb;
     uint8_t dor;
@@ -401,21 +401,21 @@  struct FDCtrl {
     uint8_t data_dir;
     uint8_t eot; /* last wanted sector */
     /* States kept only to be returned back */
-    /* Timers state */
-    uint8_t timer0;
-    uint8_t timer1;
     /* precompensation */
     uint8_t precomp_trk;
     uint8_t config;
     uint8_t lock;
     /* Power down config (also with status regB access mode */
     uint8_t pwrd;
-    /* Sun4m quirks? */
-    int sun4m;
     /* Floppy drives */
     uint8_t num_floppies;
+    /* Sun4m quirks? */
+    int sun4m;
     FDrive drives[MAX_FD];
     int reset_sensei;
+    /* Timers state */
+    uint8_t timer0;
+    uint8_t timer1;
 };
 
 typedef struct FDCtrlSysBus {
-- 
1.7.2.5