lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <37b2481ac9094f27bf21325e2770abdb@AcuMS.aculab.com>
Date:   Tue, 24 Sep 2019 10:43:35 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Anson Huang' <anson.huang@....com>,
        "thierry.reding@...il.com" <thierry.reding@...il.com>,
        "shawnguo@...nel.org" <shawnguo@...nel.org>,
        "s.hauer@...gutronix.de" <s.hauer@...gutronix.de>,
        "kernel@...gutronix.de" <kernel@...gutronix.de>,
        "festevam@...il.com" <festevam@...il.com>,
        "linux-pwm@...r.kernel.org" <linux-pwm@...r.kernel.org>,
        "linux-arm-kernel@...ts.infradead.org" 
        <linux-arm-kernel@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     dl-linux-imx <linux-imx@....com>
Subject: RE: [PATCH] pwm: pwm-imx27: Use 'dev' instead of dereferencing it
 repeatedly

From: Anson Huang
> Sent: 24 September 2019 11:03
> Hi, David
> 
> > Subject: RE: [PATCH] pwm: pwm-imx27: Use 'dev' instead of dereferencing it
> > repeatedly
> >
> > From: Anson Huang
> > > Sent: 24 September 2019 10:00
> > > Add helper variable dev = &pdev->dev to simply the code.
> > >
...
> > >  static int pwm_imx27_probe(struct platform_device *pdev)  {
> > > +	struct device *dev = &pdev->dev;
> > >  	struct pwm_imx27_chip *imx;
> > >
> > > -	imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
> > > +	imx = devm_kzalloc(dev, sizeof(*imx), GFP_KERNEL);
...
> > Hopefully the compiler will optimise this back otherwise you've added
> > another local variable which may cause spilling to stack.
> > For a setup function it probably doesn't matter, but in general it might have a
> > small negative performance impact.
> >
> > In any case this doesn't shorten any lines enough to remove line-wrap and
> > using &pdev->dev is really one less variable to mentally track when reading
> > the code.
> 
> Do we know which compiler will optimize this? I saw many of the patches doing
> this to avoid a lot of dereference, I understand it does NOT save lines, but my intention
> is to avoid dereference which might save some instructions.
> 
> I thought saving instructions is more important. So now there are different opinion about
> doing this?

Remember &pdev->dev is just 'pdev + constant'.
Assuming 'pdev' is held in a callee saved register (which you want it to be) then to access
dev->foo the compiler can remember the constant and use an offset from 'pdev' instead of
an extra 'dev' variable.
On most modern ABI the first function call arguments are passed in registers.
So an add  instruction (probably lea) can be used to add the constant offset at the same
time as the value is moved into the argument register.

However your extra variable could easily get spilled out to the stack.
So you get an extra memory read rather than (at most) an extra 'add' instruction.

Even if pdev->dev were a pointer, repeatedly reading it from pdev->dev could
easily generate better code than having an extra variable that would mean the
value was repeatedly read from the stack.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ