Skip to content

Commit a522ee8

Browse files
jkivilinherbertx
authored andcommitted
crypto: twofish-x86_64-3way - blacklist pentium4 and atom
Performance of twofish-x86_64-3way on Intel Pentium 4 and Atom is lower than of twofish-x86_64 module. So blacklist these CPUs. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f1df57d commit a522ee8

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎arch/x86/crypto/twofish_glue_3way.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
*/
2727

28+
#include <asm/processor.h>
2829
#include <linux/crypto.h>
2930
#include <linux/init.h>
3031
#include <linux/module.h>
@@ -637,10 +638,56 @@ static struct crypto_alg blk_xts_alg = {
637638
},
638639
};
639640

641+
static bool is_blacklisted_cpu(void)
642+
{
643+
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
644+
return false;
645+
646+
if (boot_cpu_data.x86 == 0x06 &&
647+
(boot_cpu_data.x86_model == 0x1c ||
648+
boot_cpu_data.x86_model == 0x26 ||
649+
boot_cpu_data.x86_model == 0x36)) {
650+
/*
651+
* On Atom, twofish-3way is slower than original assembler
652+
* implementation. Twofish-3way trades off some performance in
653+
* storing blocks in 64bit registers to allow three blocks to
654+
* be processed parallel. Parallel operation then allows gaining
655+
* more performance than was trade off, on out-of-order CPUs.
656+
* However Atom does not benefit from this parallellism and
657+
* should be blacklisted.
658+
*/
659+
return true;
660+
}
661+
662+
if (boot_cpu_data.x86 == 0x0f) {
663+
/*
664+
* On Pentium 4, twofish-3way is slower than original assembler
665+
* implementation because excessive uses of 64bit rotate and
666+
* left-shifts (which are really slow on P4) needed to store and
667+
* handle 128bit block in two 64bit registers.
668+
*/
669+
return true;
670+
}
671+
672+
return false;
673+
}
674+
675+
static int force;
676+
module_param(force, int, 0);
677+
MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist");
678+
640679
int __init init(void)
641680
{
642681
int err;
643682

683+
if (!force && is_blacklisted_cpu()) {
684+
printk(KERN_INFO
685+
"twofish-x86_64-3way: performance on this CPU "
686+
"would be suboptimal: disabling "
687+
"twofish-x86_64-3way.\n");
688+
return -ENODEV;
689+
}
690+
644691
err = crypto_register_alg(&blk_ecb_alg);
645692
if (err)
646693
goto ecb_err;

0 commit comments

Comments
 (0)