linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: "Shaohui Xie" <Shaohui.Xie@freescale.com>,
	"Jason Uhlenkott" <juhlenko@akamai.com>,
	"Aristeu Rozanski" <arozansk@redhat.com>,
	"Hitoshi Mitake" <h.mitake@gmail.com>,
	"Mark Gross" <mark.gross@intel.com>,
	"Dmitry Eremin-Solenikov" <dbaryshkov@gmail.com>,
	"Ranganathan Desikan" <ravi@jetztechnologies.com>,
	"Egor Martovetsky" <egor@pasemi.com>,
	"Niklas Söderlund" <niklas.soderlund@ericsson.com>,
	"Tim Small" <tim@buttersideup.com>,
	"Arvind R." <arvino55@gmail.com>,
	"Chris Metcalf" <cmetcalf@tilera.com>,
	"Olof Johansson" <olof@lixom.net>,
	"Doug Thompson" <norsk5@yahoo.com>,
	"Linux Edac Mailing List" <linux-edac@vger.kernel.org>,
	"Michal Marek" <mmarek@suse.cz>, "Jiri Kosina" <jkosina@suse.cz>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Joe Perches" <joe@perches.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH EDACv16 1/2] edac: Change internal representation to work with layers
Date: Mon, 30 Apr 2012 09:59:40 +0200	[thread overview]
Message-ID: <20120430075940.GC8182@aftab.osrc.amd.com> (raw)
In-Reply-To: <4F9D4D55.9070705@redhat.com>

On Sun, Apr 29, 2012 at 11:16:53AM -0300, Mauro Carvalho Chehab wrote:
> > Hey, are you looking at compiled code or at source code? Because I'm
> > looking at source code, and it is a pretty safe bet the majority of the
> > people here do that too.
> 
> What I said is that, from source code POV, a code where the loop variables are
> initialized just before the loop is easier to read it when the initialization
> of those vars are on another part of the code.
> 
> That's basically why the "for" syntax starts with a var initialization clause.
> 
> The tot_dimms & friends are loop vars: their value is calculated within the loop.
> 
> At the object code, this won't bring any difference.
> 
> > 
> >> it, either by using registers for those vars or by moving the initialization
> >> to the top of the function.
> >>
> >> This function is too complex, so it is better to initialize those vars
> >> just before the loops that are calculating those totals.
> > 
> > Simply initialize those variables at declaration time and that's it.
> > Initializing them before the loop doesn't make the function less complex
> > - splitting it and sanitizing it does.
> 
> Initializing loop-calculated vars just before the loop makes the code easier
> to read, and may avoid issues that might happen during code lifecycle.

This is getting ridiculous: the variable declaration and initialization
are on the same screen as the loop (unless one uses a screen which can
only show less than 40ish lines).

So the argument about making the code easier to read is bogus.

This function is already cluttered with a lot of crap, and is very large
so adding more lines which can simply be stashed away at declaration
time is better readability.

Besides, every modern editor can jump to the declaration of a local
variable so that the user can see to what it is initialized to.

> +struct mem_ctl_info *new_edac_mc_alloc(unsigned edac_index,
> +                                    unsigned n_layers,
> +                                    struct edac_mc_layer *layers,
> +                                    bool rev_order,
> +                                    unsigned sz_pvt)
>  {
>       void *ptr = NULL;
>       struct mem_ctl_info *mci;
> -     struct csrow_info *csi, *csrow;
> +     struct edac_mc_layer *layer;
> +     struct csrow_info *csi, *csr;
>       struct rank_info *chi, *chp, *chan;
>       struct dimm_info *dimm;
> +     u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS];
>       void *pvt;
> -     unsigned size;
> -     int row, chn;
> +     unsigned size, tot_dimms, count, pos[EDAC_MAX_LAYERS];
> +     unsigned tot_csrows, tot_channels, tot_errcount = 0;
> +     int i, j;
>       int err;
> +     int row, chn;
> +     bool per_rank = false;
> +
> +     BUG_ON(n_layers > EDAC_MAX_LAYERS || n_layers == 0);
> +     /*
> +      * Calculate the total amount of dimms and csrows/cschannels while
> +      * in the old API emulation mode
> +      */
> +     tot_dimms = 1;
> +     tot_channels = 1;
> +     tot_csrows = 1;
> +     for (i = 0; i < n_layers; i++) {
> +             tot_dimms *= layers[i].size;
> +             if (layers[i].is_virt_csrow)
> +                     tot_csrows *= layers[i].size;
> +             else
> +                     tot_channels *= layers[i].size;
> +
> +             if (layers[i].type == EDAC_MC_LAYER_CHIP_SELECT)
> +                     per_rank = true;


-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551

  reply	other threads:[~2012-04-30  7:59 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1335289087-11337-1-git-send-email-mchehab@redhat.com>
2012-04-24 18:15 ` [PATCH EDACv16 1/2] edac: Change internal representation to work with layers Mauro Carvalho Chehab
2012-04-27 13:33   ` Borislav Petkov
2012-04-27 14:11     ` Joe Perches
2012-04-27 15:12       ` Borislav Petkov
2012-04-27 16:07       ` Mauro Carvalho Chehab
2012-04-28  8:52         ` Borislav Petkov
2012-04-28 20:38           ` Joe Perches
2012-04-29 14:25           ` Mauro Carvalho Chehab
2012-04-29 15:11             ` Mauro Carvalho Chehab
2012-04-29 16:03               ` Joe Perches
2012-04-29 17:18                 ` Mauro Carvalho Chehab
2012-04-27 15:36     ` Mauro Carvalho Chehab
2012-04-28  9:05       ` Borislav Petkov
2012-04-29 13:49         ` Mauro Carvalho Chehab
2012-04-30  8:15           ` Borislav Petkov
2012-04-30 10:58             ` Mauro Carvalho Chehab
2012-04-30 11:11               ` Borislav Petkov
2012-04-30 11:45                 ` Mauro Carvalho Chehab
2012-04-30 12:38                   ` Borislav Petkov
2012-04-30 13:00                     ` Mauro Carvalho Chehab
2012-04-30 13:53                       ` Mauro Carvalho Chehab
2012-04-30 11:37             ` Mauro Carvalho Chehab
2012-04-27 17:52     ` Mauro Carvalho Chehab
2012-04-27 18:11       ` Luck, Tony
2012-04-27 19:24         ` Mauro Carvalho Chehab
2012-04-28  8:58           ` Borislav Petkov
2012-04-28  9:16       ` Borislav Petkov
2012-04-28 17:07         ` Joe Perches
2012-04-29 14:02           ` Mauro Carvalho Chehab
2012-04-29 14:16         ` Mauro Carvalho Chehab
2012-04-30  7:59           ` Borislav Petkov [this message]
2012-04-30 11:23             ` Mauro Carvalho Chehab
2012-04-30 12:51               ` Borislav Petkov
2012-05-02 13:30 Borislav Petkov
2012-05-03 14:16 ` Mauro Carvalho Chehab
2012-05-04  9:52   ` Borislav Petkov
2012-05-04 10:15     ` Mauro Carvalho Chehab

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=20120430075940.GC8182@aftab.osrc.amd.com \
    --to=bp@amd64.org \
    --cc=Shaohui.Xie@freescale.com \
    --cc=akpm@linux-foundation.org \
    --cc=arozansk@redhat.com \
    --cc=arvino55@gmail.com \
    --cc=cmetcalf@tilera.com \
    --cc=dbaryshkov@gmail.com \
    --cc=egor@pasemi.com \
    --cc=h.mitake@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=joe@perches.com \
    --cc=juhlenko@akamai.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark.gross@intel.com \
    --cc=mchehab@redhat.com \
    --cc=mmarek@suse.cz \
    --cc=niklas.soderlund@ericsson.com \
    --cc=norsk5@yahoo.com \
    --cc=olof@lixom.net \
    --cc=ravi@jetztechnologies.com \
    --cc=tim@buttersideup.com \
    /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).