Skip to content

Commit 685784a

Browse files
committed
xor: make 'xor_blocks' a library routine for use with async_tx
The async_tx api tries to use a dma engine for an operation, but will fall back to an optimized software routine otherwise. Xor support is implemented using the raid5 xor routines. For organizational purposes this routine is moved to a common area. The following fixes are also made: * rename xor_block => xor_blocks, suggested by Adrian Bunk * ensure that xor.o initializes before md.o in the built-in case * checkpatch.pl fixes * mark calibrate_xor_blocks __init, Adrian Bunk Cc: Adrian Bunk <bunk@stusta.de> Cc: NeilBrown <neilb@suse.de> Cc: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent d379b01 commit 685784a

8 files changed

Lines changed: 38 additions & 23 deletions

File tree

‎crypto/Kconfig‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#
2+
# Generic algorithms support
3+
#
4+
config XOR_BLOCKS
5+
tristate
6+
17
#
28
# Cryptographic API Configuration
39
#

‎crypto/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
5050
obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
5151

5252
obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
53+
54+
#
55+
# generic algorithms and the async_tx api
56+
#
57+
obj-$(CONFIG_XOR_BLOCKS) += xor.o
58+

drivers/md/xor.c renamed to crypto/xor.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
static struct xor_block_template *active_template;
2727

2828
void
29-
xor_block(unsigned int count, unsigned int bytes, void **ptr)
29+
xor_blocks(unsigned int count, unsigned int bytes, void **ptr)
3030
{
3131
unsigned long *p0, *p1, *p2, *p3, *p4;
3232

@@ -52,6 +52,7 @@ xor_block(unsigned int count, unsigned int bytes, void **ptr)
5252
p4 = (unsigned long *) ptr[4];
5353
active_template->do_5(bytes, p0, p1, p2, p3, p4);
5454
}
55+
EXPORT_SYMBOL(xor_blocks);
5556

5657
/* Set of all registered templates. */
5758
static struct xor_block_template *template_list;
@@ -78,7 +79,7 @@ do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)
7879
now = jiffies;
7980
count = 0;
8081
while (jiffies == now) {
81-
mb();
82+
mb(); /* prevent loop optimzation */
8283
tmpl->do_2(BENCH_SIZE, b1, b2);
8384
mb();
8485
count++;
@@ -91,26 +92,26 @@ do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)
9192
speed = max * (HZ * BENCH_SIZE / 1024);
9293
tmpl->speed = speed;
9394

94-
printk(" %-10s: %5d.%03d MB/sec\n", tmpl->name,
95+
printk(KERN_INFO " %-10s: %5d.%03d MB/sec\n", tmpl->name,
9596
speed / 1000, speed % 1000);
9697
}
9798

98-
static int
99-
calibrate_xor_block(void)
99+
static int __init
100+
calibrate_xor_blocks(void)
100101
{
101102
void *b1, *b2;
102103
struct xor_block_template *f, *fastest;
103104

104105
b1 = (void *) __get_free_pages(GFP_KERNEL, 2);
105-
if (! b1) {
106-
printk("raid5: Yikes! No memory available.\n");
106+
if (!b1) {
107+
printk(KERN_WARNING "xor: Yikes! No memory available.\n");
107108
return -ENOMEM;
108109
}
109110
b2 = b1 + 2*PAGE_SIZE + BENCH_SIZE;
110111

111112
/*
112-
* If this arch/cpu has a short-circuited selection, don't loop through all
113-
* the possible functions, just test the best one
113+
* If this arch/cpu has a short-circuited selection, don't loop through
114+
* all the possible functions, just test the best one
114115
*/
115116

116117
fastest = NULL;
@@ -122,19 +123,20 @@ calibrate_xor_block(void)
122123
#define xor_speed(templ) do_xor_speed((templ), b1, b2)
123124

124125
if (fastest) {
125-
printk(KERN_INFO "raid5: automatically using best checksumming function: %s\n",
126+
printk(KERN_INFO "xor: automatically using best "
127+
"checksumming function: %s\n",
126128
fastest->name);
127129
xor_speed(fastest);
128130
} else {
129-
printk(KERN_INFO "raid5: measuring checksumming speed\n");
131+
printk(KERN_INFO "xor: measuring checksumming speed\n");
130132
XOR_TRY_TEMPLATES;
131133
fastest = template_list;
132134
for (f = fastest; f; f = f->next)
133135
if (f->speed > fastest->speed)
134136
fastest = f;
135137
}
136138

137-
printk("raid5: using function: %s (%d.%03d MB/sec)\n",
139+
printk(KERN_INFO "xor: using function: %s (%d.%03d MB/sec)\n",
138140
fastest->name, fastest->speed / 1000, fastest->speed % 1000);
139141

140142
#undef xor_speed
@@ -147,8 +149,8 @@ calibrate_xor_block(void)
147149

148150
static __exit void xor_exit(void) { }
149151

150-
EXPORT_SYMBOL(xor_block);
151152
MODULE_LICENSE("GPL");
152153

153-
module_init(calibrate_xor_block);
154+
/* when built-in xor.o must initialize before drivers/md/md.o */
155+
core_initcall(calibrate_xor_blocks);
154156
module_exit(xor_exit);

‎drivers/md/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ config MD_RAID10
109109
config MD_RAID456
110110
tristate "RAID-4/RAID-5/RAID-6 mode"
111111
depends on BLK_DEV_MD
112+
select XOR_BLOCKS
112113
---help---
113114
A RAID-5 set of N drives with a capacity of C MB per drive provides
114115
the capacity of C * (N - 1) MB, and protects against a failure

‎drivers/md/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ raid456-objs := raid5.o raid6algos.o raid6recov.o raid6tables.o \
1717
hostprogs-y := mktables
1818

1919
# Note: link order is important. All raid personalities
20-
# and xor.o must come before md.o, as they each initialise
20+
# and must come before md.o, as they each initialise
2121
# themselves, and md.o may use the personalities when it
2222
# auto-initialised.
2323

2424
obj-$(CONFIG_MD_LINEAR) += linear.o
2525
obj-$(CONFIG_MD_RAID0) += raid0.o
2626
obj-$(CONFIG_MD_RAID1) += raid1.o
2727
obj-$(CONFIG_MD_RAID10) += raid10.o
28-
obj-$(CONFIG_MD_RAID456) += raid456.o xor.o
28+
obj-$(CONFIG_MD_RAID456) += raid456.o
2929
obj-$(CONFIG_MD_MULTIPATH) += multipath.o
3030
obj-$(CONFIG_MD_FAULTY) += faulty.o
3131
obj-$(CONFIG_BLK_DEV_MD) += md-mod.o

‎drivers/md/md.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5814,7 +5814,7 @@ static __exit void md_exit(void)
58145814
}
58155815
}
58165816

5817-
module_init(md_init)
5817+
subsys_initcall(md_init);
58185818
module_exit(md_exit)
58195819

58205820
static int get_ro(char *buffer, struct kernel_param *kp)

‎drivers/md/raid5.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static void copy_data(int frombio, struct bio *bio,
918918

919919
#define check_xor() do { \
920920
if (count == MAX_XOR_BLOCKS) { \
921-
xor_block(count, STRIPE_SIZE, ptr); \
921+
xor_blocks(count, STRIPE_SIZE, ptr); \
922922
count = 1; \
923923
} \
924924
} while(0)
@@ -949,7 +949,7 @@ static void compute_block(struct stripe_head *sh, int dd_idx)
949949
check_xor();
950950
}
951951
if (count != 1)
952-
xor_block(count, STRIPE_SIZE, ptr);
952+
xor_blocks(count, STRIPE_SIZE, ptr);
953953
set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
954954
}
955955

@@ -1004,7 +1004,7 @@ static void compute_parity5(struct stripe_head *sh, int method)
10041004
break;
10051005
}
10061006
if (count>1) {
1007-
xor_block(count, STRIPE_SIZE, ptr);
1007+
xor_blocks(count, STRIPE_SIZE, ptr);
10081008
count = 1;
10091009
}
10101010

@@ -1038,7 +1038,7 @@ static void compute_parity5(struct stripe_head *sh, int method)
10381038
}
10391039
}
10401040
if (count != 1)
1041-
xor_block(count, STRIPE_SIZE, ptr);
1041+
xor_blocks(count, STRIPE_SIZE, ptr);
10421042

10431043
if (method != CHECK_PARITY) {
10441044
set_bit(R5_UPTODATE, &sh->dev[pd_idx].flags);
@@ -1160,7 +1160,7 @@ static void compute_block_1(struct stripe_head *sh, int dd_idx, int nozero)
11601160
check_xor();
11611161
}
11621162
if (count != 1)
1163-
xor_block(count, STRIPE_SIZE, ptr);
1163+
xor_blocks(count, STRIPE_SIZE, ptr);
11641164
if (!nozero) set_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
11651165
else clear_bit(R5_UPTODATE, &sh->dev[dd_idx].flags);
11661166
}

‎include/linux/raid/xor.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#define MAX_XOR_BLOCKS 5
77

8-
extern void xor_block(unsigned int count, unsigned int bytes, void **ptr);
8+
extern void xor_blocks(unsigned int count, unsigned int bytes, void **ptr);
99

1010
struct xor_block_template {
1111
struct xor_block_template *next;

0 commit comments

Comments
 (0)