public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Binbin Zhou <zhoubb.aaron@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
	Huacai Chen <chenhuacai@loongson.cn>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Andi Shyti <andi.shyti@kernel.org>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Andy Shevchenko <andy@kernel.org>,
	linux-i2c@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>,
	Xuerui Wang <kernel@xen0n.name>,
	loongarch@lists.linux.dev, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller
Date: Tue, 3 Feb 2026 11:53:10 +0200	[thread overview]
Message-ID: <aYHFhsjUo1SzAlQF@smile.fi.intel.com> (raw)
In-Reply-To: <CAMpQs4+Rk7-ERUetW_V4ojGxLtpzoX+hGgr7wV+0iQ8Uhdri4A@mail.gmail.com>

On Mon, Feb 02, 2026 at 02:39:28PM +0800, Binbin Zhou wrote:
> On Thu, Jan 29, 2026 at 10:38 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Thu, Jan 29, 2026 at 04:07:06PM +0800, Binbin Zhou wrote:
> > > On Tue, Jan 27, 2026 at 4:18 PM Andy Shevchenko
> > > <andriy.shevchenko@intel.com> wrote:
> > > > On Tue, Jan 27, 2026 at 10:47:57AM +0800, Binbin Zhou wrote:

...

> > > After run `pahole`, the structs are reorganized as follow:
> > >
> > > pahole --show_reorg_steps --reorganize --sort -C loongson2_i2c_priv
> > > i2c-ls2x-v2.o
> > > struct loongson2_i2c_priv {
> > >         struct i2c_adapter         adapter
> > > __attribute__((__aligned__(8))); /*     0  1064 */
> > >         /* --- cacheline 16 boundary (1024 bytes) was 40 bytes ago ---
> > > */
> > >         struct clk *               clk;                  /*  1064
> > > 8 */
> > >         struct completion          complete;             /*  1072
> > > 32 */
> > >         /* --- cacheline 17 boundary (1088 bytes) was 16 bytes ago ---
> > > */
> > >         struct regmap *            regmap;               /*  1104
> >
> > It's better to keep pointers like clk and regmap next to each other.
> > They are semantically coupled as "resources".
> >
> > > 8 */
> > >         int                        speed;                /*  1112
> > > 4 */
> > >         int                        parent_rate;          /*  1116
> > > 4 */
> > >         struct loongson2_i2c_msg   msg;                  /*  1120
> > > 24 */
> > >
> > >         /* XXX last struct has 4 bytes of padding */
> > >
> > >         /* size: 1144, cachelines: 18, members: 7 */
> > >         /* paddings: 1, sum paddings: 4 */
> > >         /* forced alignments: 1 */
> > >         /* last cacheline: 56 bytes */
> > > } __attribute__((__aligned__(8)));
> >
> > ...
> >
> > > pahole --show_reorg_steps --reorganize --sort -C loongson2_i2c_msg
> > > i2c-ls2x-v2.o
> > > struct loongson2_i2c_msg {
> > >         u8                         addr;                 /*     0
> > > 1 */
> > >         bool                       stop;                 /*     1
> > > 1 */
> > >
> > >         /* XXX 2 bytes hole, try to pack */
> >
> > >         u32                        count;                /*     4
> > > 4 */
> > >         u8 *                       buf;                  /*     8
> > > 8 */
> >
> > Also think about it (don't blindly follow the `pahole` automatic mode).
> > This is much better if you move the pointer to be the first, followed
> > by a count, result, and others.
> >
> > >         int                        result;               /*    16
> > > 4 */
> > >
> > >         /* size: 24, cachelines: 1, members: 5 */
> > >         /* sum members: 18, holes: 1, sum holes: 2 */
> > >         /* padding: 4 */
> > >         /* last cacheline: 24 bytes */
> > > };
> >
> > TL;DR: don't use `pahole` blindly. Use the common sense.
> 
> Sorry, I slacked off.
> How about the organized data structure as follows:
> 
> struct loongson2_i2c_msg {
>         u8      *buf;
>         u32     count;
>         int     result;
>         u8      addr;
>         bool    stop;
> };
> 
> struct loongson2_i2c_priv {
>         struct i2c_adapter              adapter;
>         struct completion               complete;
>         struct clk                      *clk;
>         struct regmap                   *regmap;
>         int                             speed;
>         int                             parent_rate;
>         struct loongson2_i2c_msg        msg;
> };

At the first glance looks okay to me.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-02-03  9:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  2:47 [PATCH v2 0/2] i2c: Add Loongson-2K0300 I2C controller support Binbin Zhou
2026-01-27  2:47 ` [PATCH v2 1/2] dt-bindings: i2c: loongson,ls2x: Add ls2k0300-i2c compatible Binbin Zhou
2026-01-27  2:47 ` [PATCH v2 2/2] i2c: ls2x-v2: Add driver for Loongson-2K0300 I2C controller Binbin Zhou
2026-01-27  8:18   ` Andy Shevchenko
2026-01-29  8:07     ` Binbin Zhou
2026-01-29 14:38       ` Andy Shevchenko
2026-02-02  6:39         ` Binbin Zhou
2026-02-03  9:53           ` Andy Shevchenko [this message]
2026-01-28  4:15   ` Huacai Chen
2026-01-28  9:08     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aYHFhsjUo1SzAlQF@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andi.shyti@kernel.org \
    --cc=andy@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@xen0n.name \
    --cc=krzk+dt@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=robh@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=zhoubb.aaron@gmail.com \
    --cc=zhoubinbin@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox