From b8a1e6b0170f26924c35750ba387a656ea2c614c Mon Sep 17 00:00:00 2001
Message-Id: <b8a1e6b0170f26924c35750ba387a656ea2c614c.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 20:02:02 +0000
Subject: [PATCH 11/11] m48t59: avoid structure holes spotted by pahole
Report from pahole on amd64 host:
struct M48t59State {
uint32_t type; /* 0 4 */
/* XXX 4 bytes hole, try to pack */
qemu_irq IRQ; /* 8 8 */
uint32_t io_base; /* 16 4 */
uint32_t size; /* 20 4 */
time_t time_offset; /* 24 8 */
time_t stop_time; /* 32 8 */
struct tm alarm; /* 40 56 */
/* --- cacheline 1 boundary (64 bytes) was 32 bytes ago --- */
struct QEMUTimer * alrm_timer; /* 96 8 */
struct QEMUTimer * wd_timer; /* 104 8 */
uint8_t lock; /* 112 1 */
/* XXX 1 byte hole, try to pack */
uint16_t addr; /* 114 2 */
/* XXX 4 bytes hole, try to pack */
uint8_t * buffer; /* 120 8 */
/* --- cacheline 2 boundary (128 bytes) --- */
/* size: 128, cachelines: 2 */
/* sum members: 119, holes: 3, sum holes: 9 */
}; /* definitions: 1 */
Fix by rearranging the structure to avoid padding.
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
hw/m48t59.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
@@ -50,8 +50,6 @@
*/
struct M48t59State {
- /* Model parameters */
- uint32_t type; // 2 = m48t02, 8 = m48t08, 59 = m48t59
/* Hardware parameters */
qemu_irq IRQ;
uint32_t io_base;
@@ -64,9 +62,12 @@ struct M48t59State {
struct QEMUTimer *alrm_timer;
struct QEMUTimer *wd_timer;
/* NVRAM storage */
- uint8_t lock;
- uint16_t addr;
uint8_t *buffer;
+ /* Model parameters */
+ uint32_t type; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+ /* NVRAM storage */
+ uint16_t addr;
+ uint8_t lock;
};
typedef struct M48t59ISAState {
--
1.7.2.5
Report from pahole on amd64 host: struct M48t59State { uint32_t type; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ qemu_irq IRQ; /* 8 8 */ uint32_t io_base; /* 16 4 */ uint32_t size; /* 20 4 */ time_t time_offset; /* 24 8 */ time_t stop_time; /* 32 8 */ struct tm alarm; /* 40 56 */ /* --- cacheline 1 boundary (64 bytes) was 32 bytes ago --- */ struct QEMUTimer * alrm_timer; /* 96 8 */ struct QEMUTimer * wd_timer; /* 104 8 */ uint8_t lock; /* 112 1 */ /* XXX 1 byte hole, try to pack */ uint16_t addr; /* 114 2 */ /* XXX 4 bytes hole, try to pack */ uint8_t * buffer; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ /* size: 128, cachelines: 2 */ /* sum members: 119, holes: 3, sum holes: 9 */ }; /* definitions: 1 */ Fix by rearranging the structure to avoid padding. Signed-off-by: Blue Swirl <blauwirbel@gmail.com> --- hw/m48t59.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)