Commit e798b3f8 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh

ocfs2: Don't hand-code xor in ocfs2_hamming_encode().

When I wrote ocfs2_hamming_encode(), I was following documentation of
the algorithm and didn't have quite the (possibly still imperfect) grasp
of it I do now.  As part of this, I literally hand-coded xor.  I would
test a bit, and then add that bit via xor to the parity word.

I can, of course, just do a single xor of the parity word and the source
word (the code buffer bit offset).  This cuts CPU usage by 53% on a
mostly populated buffer (an inode containing utmp.h inline).

Joel
Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 9d28cfb7
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include "blockcheck.h" #include "blockcheck.h"
/* /*
* We use the following conventions: * We use the following conventions:
* *
...@@ -39,26 +38,6 @@ ...@@ -39,26 +38,6 @@
* p = # parity bits * p = # parity bits
* c = # total code bits (d + p) * c = # total code bits (d + p)
*/ */
static int calc_parity_bits(unsigned int d)
{
unsigned int p;
/*
* Bits required for Single Error Correction is as follows:
*
* d + p + 1 <= 2^p
*
* We're restricting ourselves to 31 bits of parity, that should be
* sufficient.
*/
for (p = 1; p < 32; p++)
{
if ((d + p + 1) <= (1 << p))
return p;
}
return 0;
}
/* /*
* Calculate the bit offset in the hamming code buffer based on the bit's * Calculate the bit offset in the hamming code buffer based on the bit's
...@@ -109,10 +88,9 @@ static unsigned int calc_code_bit(unsigned int i) ...@@ -109,10 +88,9 @@ static unsigned int calc_code_bit(unsigned int i)
*/ */
u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr) u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr)
{ {
unsigned int p = calc_parity_bits(nr + d); unsigned int i, b;
unsigned int i, j, b;
BUG_ON(!p); BUG_ON(!d);
/* /*
* b is the hamming code bit number. Hamming code specifies a * b is the hamming code bit number. Hamming code specifies a
...@@ -131,8 +109,6 @@ u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr ...@@ -131,8 +109,6 @@ u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr
*/ */
b = calc_code_bit(nr + i); b = calc_code_bit(nr + i);
for (j = 0; j < p; j++)
{
/* /*
* Data bits in the resultant code are checked by * Data bits in the resultant code are checked by
* parity bits that are part of the bit number * parity bits that are part of the bit number
...@@ -149,9 +125,7 @@ u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr ...@@ -149,9 +125,7 @@ u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr
* Note that 'k' is the _code_ bit number. 'b' in * Note that 'k' is the _code_ bit number. 'b' in
* our loop. * our loop.
*/ */
if (b & (1 << j)) parity ^= b;
parity ^= (1 << j);
}
} }
/* While the data buffer was treated as little endian, the /* While the data buffer was treated as little endian, the
...@@ -174,10 +148,9 @@ u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize) ...@@ -174,10 +148,9 @@ u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize)
void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr, void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
unsigned int fix) unsigned int fix)
{ {
unsigned int p = calc_parity_bits(nr + d);
unsigned int i, b; unsigned int i, b;
BUG_ON(!p); BUG_ON(!d);
/* /*
* If the bit to fix has an hweight of 1, it's a parity bit. One * If the bit to fix has an hweight of 1, it's a parity bit. One
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment