From: Ingo Molnar <mingo@elte.hu>
To: yhlu.kernel@gmail.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Gabriel C <nix.or.die@googlemail.com>,
Mika Fischer <mika.fischer@zoopnet.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] x86: mtrr cleanup for converting continuous to discrete layout v8
Date: Tue, 29 Apr 2008 15:07:04 +0200 [thread overview]
Message-ID: <20080429130704.GC24766@elte.hu> (raw)
In-Reply-To: <200804290352.33543.yhlu.kernel@gmail.com>
a few minor cleanliness observations:
> +#ifdef CONFIG_MTRR_SANITIZER
> +
> +#ifdef CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT
> +static int enable_mtrr_cleanup __initdata = 1;
> +#else
> +static int enable_mtrr_cleanup __initdata;
> +#endif
> +
> +#else
> +
> +static int enable_mtrr_cleanup __initdata = -1;
> +
> +#endif
this should be a single:
#ifdef CONFIG_MTRR_SANITIZER
static int mtrr_cleanup_enabled = CONFIG_MTRR_SANITIZER_DEFAULT;
#endif
block.
> +#define RANGE_NUM 256
small explaination (comment) about what the limit means.
> +static int __init add_range(struct res_range *range, int nr_range, unsigned long start,
> + unsigned long end, int merge)
looks cleaner this way:
static int __init
add_range(struct res_range *range, int nr_range, unsigned long start,
unsigned long end, int merge)
> +{
> + int i;
> +
> + if (!merge)
> + goto addit;
> +
> + /* try to merge it with old one */
> + for (i = 0; i < nr_range; i++) {
> + unsigned long final_start, final_end;
> + unsigned long common_start, common_end;
> +
> + if (!range[i].end)
> + continue;
> +
> + common_start = max(range[i].start, start);
> + common_end = min(range[i].end, end);
> + if (common_start > common_end + 1)
> + continue;
> +
> + final_start = min(range[i].start, start);
> + final_end = max(range[i].end, end);
> +
> + range[i].start = final_start;
> + range[i].end = final_end;
> + return nr_range;
> + }
> +
> +addit:
perhaps factor out the loop into a separate function and avoid the goto.
> +static void __init subtract_range(struct res_range *range, unsigned long start,
> + unsigned long end)
should be:
static void __init
subtract_range(struct res_range *range, unsigned long start,
unsigned long end)
> + int i;
> + int j;
can be:
int i, j;
> + }
> +
> +
stale newline.
> + if (start > range[j].start && end >= range[j].end && range[j].end > start - 1) {
should be some sort of more readable in_range() check?
> + range[j].end = start - 1;
> + continue;
> + }
> +
> + if (start > range[j].start && end < range[j].end) {
> + /* find the new spare */
> + for (i = 0; i < RANGE_NUM; i++) {
> + if (range[i].end == 0)
> + break;
> + }
> + if (i < RANGE_NUM) {
> + range[i].end = range[j].end;
> + range[i].start = end + 1;
> + } else {
> + printk(KERN_ERR "run of slot in ranges\n");
> + }
> + range[j].end = start - 1;
> + continue;
> + }
> + }
> +}
> +struct var_mtrr_state {
> + unsigned long range_startk, range_sizek;
> + unsigned long chunk_sizek;
> + unsigned long gran_sizek;
> + unsigned int reg;
> + unsigned address_bits;
> +};
s/unsigned address_bits/unsigned int address_bits/
also move range_sizek on a separate line.
plus we tend to align structures this way:
> +struct var_mtrr_state {
> + unsigned long range_startk;
> + unsigned long range_sizek;
> + unsigned long chunk_sizek;
> + unsigned long gran_sizek;
> + unsigned int reg;
> + unsigned int address_bits;
> +};
(to put the types and field names into a visually more consistent form)
> +static void __init set_var_mtrr(
> + unsigned int reg, unsigned long basek, unsigned long sizek,
> + unsigned char type, unsigned address_bits)
should be:
static void __init
set_var_mtrr(unsigned int reg, unsigned long basek, unsigned long sizek,
unsigned char type, unsigned address_bits)
> + u32 base_lo, base_hi, mask_lo, mask_hi;
> + unsigned address_mask_high;
s/unsigned/unsigned int
hm, will this work on 64-bit? Above-4G is controlled via separate
mechanisms though so i guess it does.
> + address_mask_high = ((1u << (address_bits - 32u)) - 1u);
use alignment macros instead.
> + unsigned long sizek;
> + /* Compute the maximum size I can make a range */
> + if (range_startk)
put extra newline between variable definition and code.
> + var_state.range_startk = 0;
> + var_state.range_sizek = 0;
> + var_state.reg = 0;
> + var_state.address_bits = address_bits;
> + var_state.chunk_sizek = mtrr_chunk_size >> 10;
> + var_state.gran_sizek = mtrr_gran_size >> 10;
initialization looks nicer with vertical alignment, i.e.:
> + var_state.range_startk = 0;
> + var_state.range_sizek = 0;
> + var_state.reg = 0;
> + var_state.address_bits = address_bits;
> + var_state.chunk_sizek = mtrr_chunk_size >> 10;
> + var_state.gran_sizek = mtrr_gran_size >> 10;
> + /* Clear out the extra MTRR's */
> + while (var_state.reg < num_var_ranges)
> + set_var_mtrr(var_state.reg++, 0, 0, 0, var_state.address_bits);
the ++ is a hard to notice side-effect of the loop. It's cleaner to
separate it out or to have a for() loop for it.
> +static int __init mtrr_cleanup(unsigned address_bits)
> +{
> + unsigned long i, base, size, def, dummy;
> + mtrr_type type;
> + struct res_range range[RANGE_NUM];
> + int nr_range;
> + unsigned long extra_remove_base, extra_remove_size;
try to use a 'christmas tree' ordering of variables, i.e.:
> + unsigned long extra_remove_base, extra_remove_size;
> + unsigned long i, base, size, def, dummy;
> + struct res_range range[RANGE_NUM];
> + mtrr_type type;
> + int nr_range;
> + return 1;
> +
> +}
superfluous newline.
all in one, this is a very useful and nice feature.
Ingo
next prev parent reply other threads:[~2008-04-29 13:07 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-28 6:37 [PATCH] x86: mtrr cleanup for converting continuous to discrete layout Yinghai Lu
2008-04-28 9:06 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v2 Yinghai Lu
2008-04-28 13:08 ` Ingo Molnar
2008-04-28 13:49 ` Arjan van de Ven
2008-04-28 15:28 ` Mika Fischer
2008-04-28 5:50 ` Arjan van de Ven
2008-04-28 16:01 ` Gabriel C
2008-04-28 16:28 ` Mika Fischer
2008-04-28 19:44 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v3 Yinghai Lu
2008-04-28 20:15 ` Ingo Molnar
2008-04-28 20:18 ` Yinghai Lu
2008-04-28 20:29 ` Ingo Molnar
2008-04-28 20:16 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v4 Yinghai Lu
2008-04-28 22:05 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v5 Yinghai Lu
2008-04-28 22:36 ` Randy Dunlap
2008-04-28 22:47 ` Yinghai Lu
2008-04-29 2:42 ` Andrew Morton
2008-04-29 3:01 ` Yinghai Lu
[not found] ` <200804290157.30651.yhlu.kernel@gmail.com>
2008-04-29 8:59 ` [PATCH 2/2] x86: fix trimming e820 with MTRR holes Yinghai Lu
2008-04-29 11:35 ` Ingo Molnar
2008-04-29 17:18 ` Yinghai Lu
2008-04-29 17:20 ` Yinghai Lu
2008-04-30 3:25 ` [PATCH] x86: fix trimming e820 with MTRR holes. - fix Yinghai Lu
2008-04-30 12:09 ` Ingo Molnar
2008-04-29 9:00 ` [PATCH 1/2] x86: mtrr cleanup for converting continuous to discrete layout v7 Yinghai Lu
2008-04-29 9:47 ` Gabriel C
2008-04-29 10:30 ` Yinghai Lu
2008-04-29 10:56 ` Yinghai Lu
2008-04-29 11:26 ` Ingo Molnar
2008-04-29 11:51 ` Gabriel C
2008-04-29 17:11 ` Yinghai Lu
2008-04-29 20:25 ` Gabriel C
2008-04-29 21:49 ` Yinghai Lu
2008-04-29 23:56 ` Gabriel C
2008-04-30 0:06 ` Gabriel C
2008-04-30 0:38 ` Yinghai Lu
2008-04-30 1:02 ` Gabriel C
2008-04-30 3:00 ` Yinghai Lu
2008-04-30 3:29 ` Yinghai Lu
2008-04-30 4:12 ` Gabriel C
2008-04-30 4:25 ` Yinghai Lu
2008-04-30 12:04 ` Gabriel C
2008-04-30 16:26 ` Yinghai Lu
2008-04-30 0:13 ` Yinghai Lu
2008-04-29 10:52 ` [PATCH 1/2] x86: mtrr cleanup for converting continuous to discrete layout v8 Yinghai Lu
2008-04-29 13:07 ` Ingo Molnar [this message]
2008-04-29 17:25 ` Yinghai Lu
2008-04-29 20:46 ` Randy Dunlap
2008-04-29 21:54 ` Yinghai Lu
2008-04-30 3:25 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v8 - fix Yinghai Lu
2008-04-30 12:09 ` Ingo Molnar
2008-05-01 8:00 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete - auto detect Yinghai Lu
2008-05-01 11:45 ` Gabriel C
2008-05-02 0:06 ` Yinghai Lu
2008-05-02 0:29 ` Gabriel C
2008-05-02 0:35 ` Yinghai Lu
2008-05-02 1:18 ` Gabriel C
2008-05-02 1:55 ` Yinghai Lu
2008-05-01 12:09 ` Mika Fischer
2008-05-01 16:35 ` Yinghai Lu
2008-05-01 16:59 ` Mika Fischer
2008-05-01 17:40 ` Yinghai Lu
2008-05-01 15:09 ` Randy Dunlap
2008-05-01 16:38 ` Yinghai Lu
2008-05-01 18:57 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete - auto detect v2 Yinghai Lu
2008-05-01 19:42 ` H. Peter Anvin
2008-05-01 21:02 ` Yinghai Lu
2008-05-01 21:10 ` H. Peter Anvin
2008-05-01 21:20 ` Yinghai Lu
2008-05-01 21:26 ` H. Peter Anvin
2008-05-01 21:31 ` Yinghai Lu
2008-05-01 21:33 ` H. Peter Anvin
2008-05-01 21:44 ` Yinghai Lu
2008-05-01 21:49 ` H. Peter Anvin
2008-05-01 22:52 ` Yinghai Lu
2008-05-01 22:57 ` H. Peter Anvin
2008-05-01 23:10 ` Yinghai Lu
2008-05-02 0:52 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete - auto detect v3 Yinghai Lu
2008-05-02 9:40 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete - auto detect v4 Yinghai Lu
2008-04-29 19:00 ` [PATCH] x86: mtrr cleanup for converting continuous to discrete layout v5 Eric W. Biederman
2008-04-29 20:04 ` Yinghai Lu
2008-04-29 20:29 ` Eric W. Biederman
2008-04-29 21:57 ` Yinghai Lu
2008-04-29 22:09 ` Ingo Molnar
2008-04-29 22:18 ` Yinghai Lu
2008-04-29 22:14 ` Eric W. Biederman
2008-04-29 22:54 ` Thomas Gleixner
2008-04-30 1:16 ` Eric W. Biederman
2008-04-30 9:57 ` Alan Cox
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=20080429130704.GC24766@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.fischer@zoopnet.de \
--cc=nix.or.die@googlemail.com \
--cc=tglx@linutronix.de \
--cc=yhlu.kernel@gmail.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
Powered by JetHome