linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Markus Elfring <Markus.Elfring@web.de>
Cc: linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Colin Ian King <colin.king@canonical.com>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end()
Date: Sat, 12 Dec 2020 01:16:39 -0800	[thread overview]
Message-ID: <031a64e4261e1543a136d737436abefd63dbaee1.camel@perches.com> (raw)
In-Reply-To: <20201211080301.GC1781038@piout.net>

On Fri, 2020-12-11 at 09:03 +0100, Alexandre Belloni wrote:
> On 11/12/2020 07:34:41+0100, Markus Elfring wrote:
> > > > How do you think about a patch like “staging: speakup: remove redundant initialization
> > > > of pointer p_key” for comparison?
> > > > https://lore.kernel.org/patchwork/patch/1199128/
> > > > https://lore.kernel.org/driverdev-devel/20200223153954.420731-1-colin.king@canonical.com/
> > > > 
> > > > Would you tolerate to omit the initialisation for the variable “slot”?
> > > 
> > > If you were able to provide one good technical reason.
> > 
> > I find that the positions of variable definitions (and similar assignments) influence
> > the generation of executable code.
> > 
> And you are wrong, it doesn't.

I rarely reply or read any Markus' emails as everything
from Markus goes into a 'don't read' folder but I was cc'd
directly on one from someone else recently so I think I
should reply to this one too.

In this case Alexandre it seems true, but in the generic case
it may be false.  It may depend on stack size and location.

For instance, with large structs declared either at the top
of a function or in separate branches within the function:

$ cat t_structs.c
struct a {
	int a[2000];
	int b[4000];
};

struct b {
	char a[100];
	char b[10000];
};

void foo1(struct a *a);
void foo2(struct b *b);

void foo(int index)
{
	if (index) {
		struct a ai = {};

		ai.a[index] = index;
		foo1(&ai);
	} else {
		struct b bi = {};

		bi.b[0] = 1;
		foo2(&bi);
	}
}

void bar(int index)
{
	struct a ai = {};
	struct b bi = {};

	if (index) {
		ai.a[index] = index;
		foo1(&ai);
	} else {
		bi.b[0] = 1;
		foo2(&bi);
	}
}

$

newer gcc versions are smart enough to minimize
stack use in foo() but not bar() so ai and bi start
at the same address in foo() so the total stack
used is smaller.

older gcc versions like 4.8 use separate addresses
for ai and bi in foo() so the total stack used is
larger.

$ gcc-4.8 -Wframe-larger-than=1000 -c t_structs.c
t_structs.c: In function ‘foo’:
t_structs.c:27:1: warning: the frame size of 34116 bytes is larger than 1000 bytes [-Wframe-larger-than=]
 }
 ^
t_structs.c: In function ‘bar’:
t_structs.c:41:1: warning: the frame size of 34116 bytes is larger than 1000 bytes [-Wframe-larger-than=]
 }
 ^

$ gcc-5 -Wframe-larger-than=1000 -c t_structs.c
t_structs.c: In function ‘foo’:
t_structs.c:27:1: warning: the frame size of 24032 bytes is larger than 1000 bytes [-Wframe-larger-than=]
 }
 ^
t_structs.c: In function ‘bar’:
t_structs.c:41:1: warning: the frame size of 34144 bytes is larger than 1000 bytes [-Wframe-larger-than=]
 }
 ^



  reply	other threads:[~2020-12-12  9:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <466b4c6d-032f-fbcc-58ac-75f6f39d734f@web.de>
2020-12-10 15:10 ` [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() Alexandre Belloni
     [not found]   ` <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de>
2020-12-10 17:07     ` Alexandre Belloni
     [not found]       ` <2667790c-fad2-aaa9-36e8-6be66949ac8d@web.de>
2020-12-10 18:21         ` Alexandre Belloni
     [not found]           ` <4c0d8efe-de25-f168-8b8d-b7f1ede6c6b1@web.de>
2020-12-11  8:03             ` Alexandre Belloni
2020-12-12  9:16               ` Joe Perches [this message]
2020-12-12 13:17                 ` Alexandre Belloni
2020-12-12 18:48                   ` Joe Perches
2020-12-11  8:37   ` [PATCH] " Dan Carpenter
     [not found]     ` <e7910b04-4c4a-567b-d87d-d12352a48cfc@web.de>
2020-12-14  7:05       ` Dan Carpenter

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=031a64e4261e1543a136d737436abefd63dbaee1.camel@perches.com \
    --to=joe@perches.com \
    --cc=Markus.Elfring@web.de \
    --cc=alexandre.belloni@bootlin.com \
    --cc=colin.king@canonical.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=ulf.hansson@linaro.org \
    /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;
as well as URLs for NNTP newsgroup(s).