From cc4589ebfae6f8dbb5cf880a0a67eedab3416492 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Wed, 11 Aug 2010 00:19:05 +0100 Subject: Rename raid6 files now they're in a 'raid6' directory. Linus asks 'why "raid6" twice?'. No reason. Signed-off-by: David Woodhouse --- lib/raid6/algos.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 lib/raid6/algos.c (limited to 'lib/raid6/algos.c') diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c new file mode 100644 index 000000000000..1f8784bfd44d --- /dev/null +++ b/lib/raid6/algos.c @@ -0,0 +1,154 @@ +/* -*- linux-c -*- ------------------------------------------------------- * + * + * Copyright 2002 H. Peter Anvin - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * raid6algos.c + * + * Algorithm list and algorithm selection for RAID-6 + */ + +#include +#include +#ifndef __KERNEL__ +#include +#include +#else +#if !RAID6_USE_EMPTY_ZERO_PAGE +/* In .bss so it's zeroed */ +const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); +EXPORT_SYMBOL(raid6_empty_zero_page); +#endif +#endif + +struct raid6_calls raid6_call; +EXPORT_SYMBOL_GPL(raid6_call); + +const struct raid6_calls * const raid6_algos[] = { + &raid6_intx1, + &raid6_intx2, + &raid6_intx4, + &raid6_intx8, +#if defined(__ia64__) + &raid6_intx16, + &raid6_intx32, +#endif +#if defined(__i386__) && !defined(__arch_um__) + &raid6_mmxx1, + &raid6_mmxx2, + &raid6_sse1x1, + &raid6_sse1x2, + &raid6_sse2x1, + &raid6_sse2x2, +#endif +#if defined(__x86_64__) && !defined(__arch_um__) + &raid6_sse2x1, + &raid6_sse2x2, + &raid6_sse2x4, +#endif +#ifdef CONFIG_ALTIVEC + &raid6_altivec1, + &raid6_altivec2, + &raid6_altivec4, + &raid6_altivec8, +#endif + NULL +}; + +#ifdef __KERNEL__ +#define RAID6_TIME_JIFFIES_LG2 4 +#else +/* Need more time to be stable in userspace */ +#define RAID6_TIME_JIFFIES_LG2 9 +#define time_before(x, y) ((x) < (y)) +#endif + +/* Try to pick the best algorithm */ +/* This code uses the gfmul table as convenient data set to abuse */ + +int __init raid6_select_algo(void) +{ + const struct raid6_calls * const * algo; + const struct raid6_calls * best; + char *syndromes; + void *dptrs[(65536/PAGE_SIZE)+2]; + int i, disks; + unsigned long perf, bestperf; + int bestprefer; + unsigned long j0, j1; + + disks = (65536/PAGE_SIZE)+2; + for ( i = 0 ; i < disks-2 ; i++ ) { + dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i; + } + + /* Normal code - use a 2-page allocation to avoid D$ conflict */ + syndromes = (void *) __get_free_pages(GFP_KERNEL, 1); + + if ( !syndromes ) { + printk("raid6: Yikes! No memory available.\n"); + return -ENOMEM; + } + + dptrs[disks-2] = syndromes; + dptrs[disks-1] = syndromes + PAGE_SIZE; + + bestperf = 0; bestprefer = 0; best = NULL; + + for ( algo = raid6_algos ; *algo ; algo++ ) { + if ( !(*algo)->valid || (*algo)->valid() ) { + perf = 0; + + preempt_disable(); + j0 = jiffies; + while ( (j1 = jiffies) == j0 ) + cpu_relax(); + while (time_before(jiffies, + j1 + (1<gen_syndrome(disks, PAGE_SIZE, dptrs); + perf++; + } + preempt_enable(); + + if ( (*algo)->prefer > bestprefer || + ((*algo)->prefer == bestprefer && + perf > bestperf) ) { + best = *algo; + bestprefer = best->prefer; + bestperf = perf; + } + printk("raid6: %-8s %5ld MB/s\n", (*algo)->name, + (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); + } + } + + if (best) { + printk("raid6: using algorithm %s (%ld MB/s)\n", + best->name, + (bestperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2)); + raid6_call = *best; + } else + printk("raid6: Yikes! No algorithm found!\n"); + + free_pages((unsigned long)syndromes, 1); + + return best ? 0 : -EINVAL; +} + +static void raid6_exit(void) +{ + do { } while (0); +} + +subsys_initcall(raid6_select_algo); +module_exit(raid6_exit); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("RAID6 Q-syndrome calculations"); -- cgit v1.2.3 From d5302fe41ffb28d0a48be6a71becba36d3453ae0 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 12 Aug 2010 06:38:24 +1000 Subject: Make lib/raid6/test build correctly. Some bit-rot needs to be cleaned out. Signed-off-by: NeilBrown --- include/linux/raid/pq.h | 2 ++ lib/raid6/algos.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/raid6/algos.c') diff --git a/include/linux/raid/pq.h b/include/linux/raid/pq.h index 1cbbd2c11aa9..2b59cc824395 100644 --- a/include/linux/raid/pq.h +++ b/include/linux/raid/pq.h @@ -62,7 +62,9 @@ extern const char raid6_empty_zero_page[PAGE_SIZE]; #define disable_kernel_altivec() #define EXPORT_SYMBOL(sym) +#define EXPORT_SYMBOL_GPL(sym) #define MODULE_LICENSE(licence) +#define MODULE_DESCRIPTION(desc) #define subsys_initcall(x) #define module_exit(x) #endif /* __KERNEL__ */ diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index 1f8784bfd44d..df7ff72777b8 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c @@ -17,11 +17,11 @@ */ #include -#include #ifndef __KERNEL__ #include #include #else +#include #if !RAID6_USE_EMPTY_ZERO_PAGE /* In .bss so it's zeroed */ const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256))); -- cgit v1.2.3 From a8e026c785b3fecef0ef5c00c15223542c4db8f5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 12 Aug 2010 06:44:54 +1000 Subject: Further tidyup of raid6 naming in lib/raid6 Rename raid6/raid6x86.h to raid6/x86.h and modify some comments. Signed-off-by: NeilBrown --- lib/raid6/algos.c | 2 +- lib/raid6/mmx.c | 6 +++--- lib/raid6/raid6x86.h | 61 ---------------------------------------------------- lib/raid6/recov.c | 2 +- lib/raid6/sse1.c | 6 +++--- lib/raid6/sse2.c | 4 ++-- lib/raid6/x86.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 lib/raid6/raid6x86.h create mode 100644 lib/raid6/x86.h (limited to 'lib/raid6/algos.c') diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index df7ff72777b8..b595f560bee7 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c @@ -11,7 +11,7 @@ * ----------------------------------------------------------------------- */ /* - * raid6algos.c + * raid6/algos.c * * Algorithm list and algorithm selection for RAID-6 */ diff --git a/lib/raid6/mmx.c b/lib/raid6/mmx.c index e7f6c13132bf..279347f23094 100644 --- a/lib/raid6/mmx.c +++ b/lib/raid6/mmx.c @@ -11,7 +11,7 @@ * ----------------------------------------------------------------------- */ /* - * raid6mmx.c + * raid6/mmx.c * * MMX implementation of RAID-6 syndrome functions */ @@ -19,9 +19,9 @@ #if defined(__i386__) && !defined(__arch_um__) #include -#include "raid6x86.h" +#include "x86.h" -/* Shared with raid6sse1.c */ +/* Shared with raid6/sse1.c */ const struct raid6_mmx_constants { u64 x1d; } raid6_mmx_constants = { diff --git a/lib/raid6/raid6x86.h b/lib/raid6/raid6x86.h deleted file mode 100644 index 4c22c1568558..000000000000 --- a/lib/raid6/raid6x86.h +++ /dev/null @@ -1,61 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, - * Boston MA 02111-1307, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * raid6x86.h - * - * Definitions common to x86 and x86-64 RAID-6 code only - */ - -#ifndef LINUX_RAID_RAID6X86_H -#define LINUX_RAID_RAID6X86_H - -#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) - -#ifdef __KERNEL__ /* Real code */ - -#include - -#else /* Dummy code for user space testing */ - -static inline void kernel_fpu_begin(void) -{ -} - -static inline void kernel_fpu_end(void) -{ -} - -#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ -#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions - * (fast save and restore) */ -#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ -#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ -#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ - -/* Should work well enough on modern CPUs for testing */ -static inline int boot_cpu_has(int flag) -{ - u32 eax = (flag >> 5) ? 0x80000001 : 1; - u32 edx; - - asm volatile("cpuid" - : "+a" (eax), "=d" (edx) - : : "ecx", "ebx"); - - return (edx >> (flag & 31)) & 1; -} - -#endif /* ndef __KERNEL__ */ - -#endif -#endif diff --git a/lib/raid6/recov.c b/lib/raid6/recov.c index 2609f00e0d61..8590d19cf522 100644 --- a/lib/raid6/recov.c +++ b/lib/raid6/recov.c @@ -11,7 +11,7 @@ * ----------------------------------------------------------------------- */ /* - * raid6recov.c + * raid6/recov.c * * RAID-6 data recovery in dual failure mode. In single failure mode, * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct diff --git a/lib/raid6/sse1.c b/lib/raid6/sse1.c index b274dd5eab8f..10dd91948c07 100644 --- a/lib/raid6/sse1.c +++ b/lib/raid6/sse1.c @@ -11,7 +11,7 @@ * ----------------------------------------------------------------------- */ /* - * raid6sse1.c + * raid6/sse1.c * * SSE-1/MMXEXT implementation of RAID-6 syndrome functions * @@ -24,9 +24,9 @@ #if defined(__i386__) && !defined(__arch_um__) #include -#include "raid6x86.h" +#include "x86.h" -/* Defined in raid6mmx.c */ +/* Defined in raid6/mmx.c */ extern const struct raid6_mmx_constants { u64 x1d; } raid6_mmx_constants; diff --git a/lib/raid6/sse2.c b/lib/raid6/sse2.c index 6ed6c6c0389f..bc2d57daa589 100644 --- a/lib/raid6/sse2.c +++ b/lib/raid6/sse2.c @@ -11,7 +11,7 @@ * ----------------------------------------------------------------------- */ /* - * raid6sse2.c + * raid6/sse2.c * * SSE-2 implementation of RAID-6 syndrome functions * @@ -20,7 +20,7 @@ #if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) #include -#include "raid6x86.h" +#include "x86.h" static const struct raid6_sse_constants { u64 x1d[2]; diff --git a/lib/raid6/x86.h b/lib/raid6/x86.h new file mode 100644 index 000000000000..cb2a8c91c886 --- /dev/null +++ b/lib/raid6/x86.h @@ -0,0 +1,61 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +/* + * raid6/x86.h + * + * Definitions common to x86 and x86-64 RAID-6 code only + */ + +#ifndef LINUX_RAID_RAID6X86_H +#define LINUX_RAID_RAID6X86_H + +#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__) + +#ifdef __KERNEL__ /* Real code */ + +#include + +#else /* Dummy code for user space testing */ + +static inline void kernel_fpu_begin(void) +{ +} + +static inline void kernel_fpu_end(void) +{ +} + +#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */ +#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions + * (fast save and restore) */ +#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */ +#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */ +#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */ + +/* Should work well enough on modern CPUs for testing */ +static inline int boot_cpu_has(int flag) +{ + u32 eax = (flag >> 5) ? 0x80000001 : 1; + u32 edx; + + asm volatile("cpuid" + : "+a" (eax), "=d" (edx) + : : "ecx", "ebx"); + + return (edx >> (flag & 31)) & 1; +} + +#endif /* ndef __KERNEL__ */ + +#endif +#endif -- cgit v1.2.3