diff options
| author | Waqar Hameed <waqar.hameed@axis.com> | 2026-09-01 21:35:07 +0200 |
|---|---|---|
| committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2026-09-10 00:43:05 +0200 |
| commit | f170c05e3e08aa2068601db369078bb83dc5e7e7 (patch) | |
| tree | 02cb62db5cdb7f97d1047f47b5f9f2b03311808e | |
| parent | 4798fbcd9148455a143b03985d89f956c78c53ba (diff) | |
| download | linux-next-f170c05e3e08aa2068601db369078bb83dc5e7e7.tar.gz linux-next-f170c05e3e08aa2068601db369078bb83dc5e7e7.zip | |
power: supply: Pack power_supply_desc to eliminate holes
`pahole` reports that there are two holes in `struct power_supply_desc`:
struct power_supply_desc {
const char * name; /* 0 4 */
enum power_supply_type type; /* 4 4 */
u8 charge_behaviours; /* 8 1 */
/* XXX 3 bytes hole, try to pack */
u32 charge_types; /* 12 4 */
u32 usb_types; /* 16 4 */
const enum power_supply_property * properties; /* 20 4 */
size_t num_properties; /* 24 4 */
int (*get_property)(...); /* 28 4 */
int (*set_property)(...); /* 32 4 */
int (*property_is_writeable)(...); /* 36 4 */
void (*external_power_changed)(...); /* 40 4 */
int (*init)(struct power_supply *); /* 44 4 */
bool no_thermal; /* 48 1 */
/* XXX 3 bytes hole, try to pack */
int use_for_apm; /* 52 4 */
/* size: 56, cachelines: 1, members: 14 */
/* sum members: 50, holes: 2, sum holes: 6 */
/* last cacheline: 56 bytes */
};
This can be optimized by moving `u8 charge_behaviours` to the end and
swapping `int use_for_apm` with `bool no_thermal`:
struct power_supply_desc {
const char * name; /* 0 4 */
enum power_supply_type type; /* 4 4 */
u32 charge_types; /* 8 4 */
u32 usb_types; /* 12 4 */
const enum power_supply_property * properties; /* 16 4 */
size_t num_properties; /* 20 4 */
int (*get_property)(...); /* 24 4 */
int (*set_property)(...); /* 28 4 */
int (*property_is_writeable)(...); /* 32 4 */
void (*external_power_changed)(...); /* 36 4 */
int (*init)(struct power_supply *); /* 40 4 */
int use_for_apm; /* 44 4 */
bool no_thermal; /* 48 1 */
u8 charge_behaviours; /* 49 1 */
/* size: 52, cachelines: 1, members: 14 */
/* padding: 2 */
/* last cacheline: 52 bytes */
};
Do this in order to save 4 bytes. This will also help when adding new
members in the future to this `struct`.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
Link: https://patch.msgid.link/5b6d1d588c8aaf237c45638c29a2ff23f0a07f34.1788290289.git.waqar.hameed@axis.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
| -rw-r--r-- | include/linux/power_supply.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index e749d2189335..fcd05f4a8883 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -259,7 +259,6 @@ struct power_supply_config { struct power_supply_desc { const char *name; enum power_supply_type type; - u8 charge_behaviours; u32 charge_types; u32 usb_types; const enum power_supply_property *properties; @@ -295,14 +294,17 @@ struct power_supply_desc { */ int (*init)(struct power_supply *psy); + /* For APM emulation, think legacy userspace. */ + int use_for_apm; + /* * Set if thermal zone should not be created for this power supply. * For example for virtual supplies forwarding calls to actual * sensors or other supplies. */ bool no_thermal; - /* For APM emulation, think legacy userspace. */ - int use_for_apm; + + u8 charge_behaviours; }; struct power_supply_ext { |
