linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] video/hdmi: Reorder fields in 'struct hdmi_avi_infoframe'
@ 2023-06-18 20:52 Christophe JAILLET
  2023-06-19  6:11 ` Helge Deller
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2023-06-18 20:52 UTC (permalink / raw)
  To: deller
  Cc: linux-fbdev, dri-devel, linux-kernel, kernel-janitors,
	Christophe JAILLET

Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct hdmi_avi_infoframe'
from 68 to 60 bytes.

It saves a few bytes of memory and is more cache-line friendly.

This also reduces the union hdmi_infoframe the same way.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole

Before:
======
struct hdmi_avi_infoframe {
	enum hdmi_infoframe_type   type;                 /*     0     4 */
	unsigned char              version;              /*     4     1 */
	unsigned char              length;               /*     5     1 */

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

	enum hdmi_colorspace       colorspace;           /*     8     4 */
	enum hdmi_scan_mode        scan_mode;            /*    12     4 */
	enum hdmi_colorimetry      colorimetry;          /*    16     4 */
	enum hdmi_picture_aspect   picture_aspect;       /*    20     4 */
	enum hdmi_active_aspect    active_aspect;        /*    24     4 */
	bool                       itc;                  /*    28     1 */

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

	enum hdmi_extended_colorimetry extended_colorimetry; /*    32     4 */
	enum hdmi_quantization_range quantization_range; /*    36     4 */
	enum hdmi_nups             nups;                 /*    40     4 */
	unsigned char              video_code;           /*    44     1 */

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

	enum hdmi_ycc_quantization_range ycc_quantization_range; /*    48     4 */
	enum hdmi_content_type     content_type;         /*    52     4 */
	unsigned char              pixel_repeat;         /*    56     1 */

	/* XXX 1 byte hole, try to pack */

	short unsigned int         top_bar;              /*    58     2 */
	short unsigned int         bottom_bar;           /*    60     2 */
	short unsigned int         left_bar;             /*    62     2 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	short unsigned int         right_bar;            /*    64     2 */

	/* size: 68, cachelines: 2, members: 20 */
	/* sum members: 57, holes: 4, sum holes: 9 */
	/* padding: 2 */
	/* last cacheline: 4 bytes */
};


After:
=====
struct hdmi_avi_infoframe {
	enum hdmi_infoframe_type   type;                 /*     0     4 */
	unsigned char              version;              /*     4     1 */
	unsigned char              length;               /*     5     1 */
	bool                       itc;                  /*     6     1 */
	unsigned char              pixel_repeat;         /*     7     1 */
	enum hdmi_colorspace       colorspace;           /*     8     4 */
	enum hdmi_scan_mode        scan_mode;            /*    12     4 */
	enum hdmi_colorimetry      colorimetry;          /*    16     4 */
	enum hdmi_picture_aspect   picture_aspect;       /*    20     4 */
	enum hdmi_active_aspect    active_aspect;        /*    24     4 */
	enum hdmi_extended_colorimetry extended_colorimetry; /*    28     4 */
	enum hdmi_quantization_range quantization_range; /*    32     4 */
	enum hdmi_nups             nups;                 /*    36     4 */
	unsigned char              video_code;           /*    40     1 */

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

	enum hdmi_ycc_quantization_range ycc_quantization_range; /*    44     4 */
	enum hdmi_content_type     content_type;         /*    48     4 */
	short unsigned int         top_bar;              /*    52     2 */
	short unsigned int         bottom_bar;           /*    54     2 */
	short unsigned int         left_bar;             /*    56     2 */
	short unsigned int         right_bar;            /*    58     2 */

	/* size: 60, cachelines: 1, members: 20 */
	/* sum members: 57, holes: 1, sum holes: 3 */
	/* last cacheline: 60 bytes */
};
---
 include/linux/hdmi.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h
index 2f4dcc8d060e..3bb87bf6bc65 100644
--- a/include/linux/hdmi.h
+++ b/include/linux/hdmi.h
@@ -170,19 +170,19 @@ struct hdmi_avi_infoframe {
 	enum hdmi_infoframe_type type;
 	unsigned char version;
 	unsigned char length;
+	bool itc;
+	unsigned char pixel_repeat;
 	enum hdmi_colorspace colorspace;
 	enum hdmi_scan_mode scan_mode;
 	enum hdmi_colorimetry colorimetry;
 	enum hdmi_picture_aspect picture_aspect;
 	enum hdmi_active_aspect active_aspect;
-	bool itc;
 	enum hdmi_extended_colorimetry extended_colorimetry;
 	enum hdmi_quantization_range quantization_range;
 	enum hdmi_nups nups;
 	unsigned char video_code;
 	enum hdmi_ycc_quantization_range ycc_quantization_range;
 	enum hdmi_content_type content_type;
-	unsigned char pixel_repeat;
 	unsigned short top_bar;
 	unsigned short bottom_bar;
 	unsigned short left_bar;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] video/hdmi: Reorder fields in 'struct hdmi_avi_infoframe'
  2023-06-18 20:52 [PATCH] video/hdmi: Reorder fields in 'struct hdmi_avi_infoframe' Christophe JAILLET
@ 2023-06-19  6:11 ` Helge Deller
  0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2023-06-19  6:11 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: linux-fbdev, dri-devel, linux-kernel, kernel-janitors

On 6/18/23 22:52, Christophe JAILLET wrote:
> Group some variables based on their sizes to reduce hole and avoid padding.
> On x86_64, this shrinks the size of 'struct hdmi_avi_infoframe'
> from 68 to 60 bytes.
>
> It saves a few bytes of memory and is more cache-line friendly.
>
> This also reduces the union hdmi_infoframe the same way.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

applied.

Thanks!
Helge


> ---
> Using pahole
>
> Before:
> ======
> struct hdmi_avi_infoframe {
> 	enum hdmi_infoframe_type   type;                 /*     0     4 */
> 	unsigned char              version;              /*     4     1 */
> 	unsigned char              length;               /*     5     1 */
>
> 	/* XXX 2 bytes hole, try to pack */
>
> 	enum hdmi_colorspace       colorspace;           /*     8     4 */
> 	enum hdmi_scan_mode        scan_mode;            /*    12     4 */
> 	enum hdmi_colorimetry      colorimetry;          /*    16     4 */
> 	enum hdmi_picture_aspect   picture_aspect;       /*    20     4 */
> 	enum hdmi_active_aspect    active_aspect;        /*    24     4 */
> 	bool                       itc;                  /*    28     1 */
>
> 	/* XXX 3 bytes hole, try to pack */
>
> 	enum hdmi_extended_colorimetry extended_colorimetry; /*    32     4 */
> 	enum hdmi_quantization_range quantization_range; /*    36     4 */
> 	enum hdmi_nups             nups;                 /*    40     4 */
> 	unsigned char              video_code;           /*    44     1 */
>
> 	/* XXX 3 bytes hole, try to pack */
>
> 	enum hdmi_ycc_quantization_range ycc_quantization_range; /*    48     4 */
> 	enum hdmi_content_type     content_type;         /*    52     4 */
> 	unsigned char              pixel_repeat;         /*    56     1 */
>
> 	/* XXX 1 byte hole, try to pack */
>
> 	short unsigned int         top_bar;              /*    58     2 */
> 	short unsigned int         bottom_bar;           /*    60     2 */
> 	short unsigned int         left_bar;             /*    62     2 */
> 	/* --- cacheline 1 boundary (64 bytes) --- */
> 	short unsigned int         right_bar;            /*    64     2 */
>
> 	/* size: 68, cachelines: 2, members: 20 */
> 	/* sum members: 57, holes: 4, sum holes: 9 */
> 	/* padding: 2 */
> 	/* last cacheline: 4 bytes */
> };
>
>
> After:
> =====
> struct hdmi_avi_infoframe {
> 	enum hdmi_infoframe_type   type;                 /*     0     4 */
> 	unsigned char              version;              /*     4     1 */
> 	unsigned char              length;               /*     5     1 */
> 	bool                       itc;                  /*     6     1 */
> 	unsigned char              pixel_repeat;         /*     7     1 */
> 	enum hdmi_colorspace       colorspace;           /*     8     4 */
> 	enum hdmi_scan_mode        scan_mode;            /*    12     4 */
> 	enum hdmi_colorimetry      colorimetry;          /*    16     4 */
> 	enum hdmi_picture_aspect   picture_aspect;       /*    20     4 */
> 	enum hdmi_active_aspect    active_aspect;        /*    24     4 */
> 	enum hdmi_extended_colorimetry extended_colorimetry; /*    28     4 */
> 	enum hdmi_quantization_range quantization_range; /*    32     4 */
> 	enum hdmi_nups             nups;                 /*    36     4 */
> 	unsigned char              video_code;           /*    40     1 */
>
> 	/* XXX 3 bytes hole, try to pack */
>
> 	enum hdmi_ycc_quantization_range ycc_quantization_range; /*    44     4 */
> 	enum hdmi_content_type     content_type;         /*    48     4 */
> 	short unsigned int         top_bar;              /*    52     2 */
> 	short unsigned int         bottom_bar;           /*    54     2 */
> 	short unsigned int         left_bar;             /*    56     2 */
> 	short unsigned int         right_bar;            /*    58     2 */
>
> 	/* size: 60, cachelines: 1, members: 20 */
> 	/* sum members: 57, holes: 1, sum holes: 3 */
> 	/* last cacheline: 60 bytes */
> };
> ---
>   include/linux/hdmi.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h
> index 2f4dcc8d060e..3bb87bf6bc65 100644
> --- a/include/linux/hdmi.h
> +++ b/include/linux/hdmi.h
> @@ -170,19 +170,19 @@ struct hdmi_avi_infoframe {
>   	enum hdmi_infoframe_type type;
>   	unsigned char version;
>   	unsigned char length;
> +	bool itc;
> +	unsigned char pixel_repeat;
>   	enum hdmi_colorspace colorspace;
>   	enum hdmi_scan_mode scan_mode;
>   	enum hdmi_colorimetry colorimetry;
>   	enum hdmi_picture_aspect picture_aspect;
>   	enum hdmi_active_aspect active_aspect;
> -	bool itc;
>   	enum hdmi_extended_colorimetry extended_colorimetry;
>   	enum hdmi_quantization_range quantization_range;
>   	enum hdmi_nups nups;
>   	unsigned char video_code;
>   	enum hdmi_ycc_quantization_range ycc_quantization_range;
>   	enum hdmi_content_type content_type;
> -	unsigned char pixel_repeat;
>   	unsigned short top_bar;
>   	unsigned short bottom_bar;
>   	unsigned short left_bar;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-19  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 20:52 [PATCH] video/hdmi: Reorder fields in 'struct hdmi_avi_infoframe' Christophe JAILLET
2023-06-19  6:11 ` Helge Deller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).