From: Ingo Molnar <mingo@elte.hu>
To: Cliff Wickman <cpw@sgi.com>
Cc: linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v2] x86: UV uv_tlb.c cleanup
Date: Fri, 20 May 2011 15:31:28 +0200 [thread overview]
Message-ID: <20110520133128.GC17699@elte.hu> (raw)
In-Reply-To: <E1QNPH2-0006eo-8E@eag09.americas.sgi.com>
* Cliff Wickman <cpw@sgi.com> wrote:
> +static ssize_t tunables_write(struct file *file, const char __user *user,
> + size_t count, loff_t *data)
> +{
> + int cpu;
> + int ret;
> + char instr[100];
> + struct bau_control *bcp;
> +
> + if (count == 0 || count > sizeof(instr)-1)
> + return -EINVAL;
> + if (copy_from_user(instr, user, count))
> + return -EFAULT;
> + instr[count] = '\0';
> + bcp = &per_cpu(bau_control, smp_processor_id());
> + ret = parse_tunables_write(bcp, instr, count);
> + if (ret)
> + return ret;
> for_each_present_cpu(cpu) {
> bcp = &per_cpu(bau_control, cpu);
> - bcp->max_bau_concurrent = max_bau_concurrent;
> - bcp->max_bau_concurrent_constant = max_bau_concurrent;
> + bcp->max_concurr = max_concurr;
> + bcp->max_concurr_const = max_concurr;
> bcp->plugged_delay = plugged_delay;
> bcp->plugsb4reset = plugsb4reset;
> bcp->timeoutsb4reset = timeoutsb4reset;
> bcp->ipi_reset_limit = ipi_reset_limit;
> bcp->complete_threshold = complete_threshold;
> - bcp->congested_response_us = congested_response_us;
> - bcp->congested_reps = congested_reps;
> - bcp->congested_period = congested_period;
> + bcp->cong_response_us = congested_response_us;
> + bcp->cong_reps = congested_reps;
> + bcp->cong_period = congested_period;
> }
> return count;
> }
>
> static const struct seq_operations uv_ptc_seq_ops = {
> - .start = uv_ptc_seq_start,
> - .next = uv_ptc_seq_next,
> - .stop = uv_ptc_seq_stop,
> - .show = uv_ptc_seq_show
> + .start = ptc_seq_start,
> + .next = ptc_seq_next,
> + .stop = ptc_seq_stop,
> + .show = ptc_seq_show
Please apply vertical alignment for mass-initializations as well, like the ones further above.
This:
for_each_present_cpu(cpu) {
bcp = &per_cpu(bau_control, cpu);
bcp->max_concurr = max_concurr;
bcp->max_concurr_const = max_concurr;
bcp->plugged_delay = plugged_delay;
bcp->plugsb4reset = plugsb4reset;
bcp->timeoutsb4reset = timeoutsb4reset;
bcp->ipi_reset_limit = ipi_reset_limit;
bcp->complete_threshold = complete_threshold;
bcp->cong_response_us = congested_response_us;
bcp->cong_reps = congested_reps;
bcp->cong_period = congested_period;
}
Looks a *lot* tidier visually.
Another detail is the lack of separation between blocks of code:
> + if (count == 0 || count > sizeof(instr)-1)
> + return -EINVAL;
> + if (copy_from_user(instr, user, count))
> + return -EFAULT;
> + instr[count] = '\0';
> + bcp = &per_cpu(bau_control, smp_processor_id());
> + ret = parse_tunables_write(bcp, instr, count);
> + if (ret)
> + return ret;
> for_each_present_cpu(cpu) {
> bcp = &per_cpu(bau_control, cpu);
It looks more structured if it's written like this:
static ssize_t tunables_write(struct file *file, const char __user *user,
size_t count, loff_t *data)
{
int cpu;
int ret;
char instr[100];
struct bau_control *bcp;
if (count == 0 || count > sizeof(instr)-1)
return -EINVAL;
if (copy_from_user(instr, user, count))
return -EFAULT;
instr[count] = '\0';
bcp = &per_cpu(bau_control, smp_processor_id());
ret = parse_tunables_write(bcp, instr, count);
if (ret)
return ret;
for_each_present_cpu(cpu) {
bcp = &per_cpu(bau_control, cpu);
Let the code breath and keep bits together that belong together.
That way the reviewer can see the various key steps at a glance, the code
becomes more structured.
The patterns above repeat in many places in uv_tlb.c.
And clean code works: for example, when i look at this restructured code a real
bug in the code sticks out at me like a sore thumb: the smp_processor_id() is
called with preemption enabled, this will generate an ugly kernel warning when
this tunable is tweaked, with the right debug options turned on ...
Btw., please fix the bug in a separate patch, the cleanup patch itself should
have no functional changes at all.
Thanks,
Ingo
prev parent reply other threads:[~2011-05-20 13:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-20 12:57 Cliff Wickman
2011-05-20 13:19 ` Ingo Molnar
2011-05-20 13:31 ` Ingo Molnar [this message]
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=20110520133128.GC17699@elte.hu \
--to=mingo@elte.hu \
--cc=cpw@sgi.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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