[PATCH] x86, MCE, AMD: move invariant code out from loop body

From: Chen Yucong
Date: Thu Oct 02 2014 - 11:20:27 EST


On Thu, 2014-10-02 at 16:38 +0200, Borislav Petkov wrote:
>
> On Mon, Sep 22, 2014 at 09:11:00PM +0200, Borislav Petkov wrote:
> > On Mon, Sep 22, 2014 at 05:23:32PM +0800, Chen Yucong wrote:
> > > Hi Boris,
> > >
> > > I have found the following code snippet in mce_amd.c.
> > >
> > > /* cpu init entry point, called from mce.c with preempt off */
> > > void mce_amd_feature_init(struct cpuinfo_x86 *c)
> > > {
> > > ... ...
> > > for (bank = 0; bank < mca_cfg.banks; ++bank) {
> > > for (block = 0; block < NR_BLOCKS; ++block) {
> > > ... ...
> > > mce_threshold_block_init(&b, offset);
> > > mce_threshold_vector = amd_threshold_interrupt;
> > > }
> > > }
> > > }
> > >
> > > Why should "mce_threshold_vector = amd_threshold_interrupt" be placed in
> > > the inner loop body?
> >
> > Yeah, it was added sloppily with b276268631af3, I'm not surprised. Feel
> > free to send a fix.
>
> do you still want to send a fix or should I fix it up quickly?
>

From: Chen Yucong <slaoub@xxxxxxxxx>
Subject: [PATCH] x86, MCE, AMD: move invariant code out from loop body

"mce_threshold_vector = amd_threshold_interrupt;" is loop invariant code
in mce_amd_feature_init(). So it should be moved out from loop body.

Signed-off-by: Chen Yucong <slaoub@xxxxxxxxx>
---
arch/x86/kernel/cpu/mcheck/mce_amd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 5d4999f..f727701 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -253,9 +253,10 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
}

mce_threshold_block_init(&b, offset);
- mce_threshold_vector = amd_threshold_interrupt;
}
}
+
+ mce_threshold_vector = amd_threshold_interrupt;
}

/*
--
1.7.10.4




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/