mirror of
https://github.com/ceph/ceph
synced 2024-12-29 15:03:33 +00:00
os/bluestore: add crc32c_16 and crc32c_8
This is much faster than a slice-by-8 crc16, perhaps even without the intel instructions. Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
c9cdc74687
commit
e84c0ad933
@ -28,6 +28,44 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct crc32c_16 {
|
||||
typedef __le16 value_t;
|
||||
|
||||
// we have no execution context/state.
|
||||
typedef int state_t;
|
||||
static void init(state_t *state) {
|
||||
}
|
||||
static void fini(state_t *state) {
|
||||
}
|
||||
|
||||
static value_t calc(
|
||||
state_t state,
|
||||
size_t len,
|
||||
bufferlist::const_iterator& p
|
||||
) {
|
||||
return p.crc32c(len, -1) & 0xffff;
|
||||
}
|
||||
};
|
||||
|
||||
struct crc32c_8 {
|
||||
typedef __u8 value_t;
|
||||
|
||||
// we have no execution context/state.
|
||||
typedef int state_t;
|
||||
static void init(state_t *state) {
|
||||
}
|
||||
static void fini(state_t *state) {
|
||||
}
|
||||
|
||||
static value_t calc(
|
||||
state_t state,
|
||||
size_t len,
|
||||
bufferlist::const_iterator& p
|
||||
) {
|
||||
return p.crc32c(len, -1) & 0xff;
|
||||
}
|
||||
};
|
||||
|
||||
struct xxhash32 {
|
||||
typedef __le32 value_t;
|
||||
|
||||
|
@ -674,6 +674,14 @@ void bluestore_blob_t::calc_csum(uint64_t b_off, const bufferlist& bl)
|
||||
Checksummer::calculate<Checksummer::crc32c>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
|
||||
break;
|
||||
case CSUM_CRC32C_16:
|
||||
Checksummer::calculate<Checksummer::crc32c_16>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
|
||||
break;
|
||||
case CSUM_CRC32C_8:
|
||||
Checksummer::calculate<Checksummer::crc32c_8>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, &csum_data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -698,6 +706,14 @@ int bluestore_blob_t::verify_csum(uint64_t b_off, const bufferlist& bl,
|
||||
*b_bad_off = Checksummer::verify<Checksummer::crc32c>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, csum_data);
|
||||
break;
|
||||
case CSUM_CRC32C_16:
|
||||
*b_bad_off = Checksummer::verify<Checksummer::crc32c_16>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, csum_data);
|
||||
break;
|
||||
case CSUM_CRC32C_8:
|
||||
*b_bad_off = Checksummer::verify<Checksummer::crc32c_8>(
|
||||
get_csum_chunk_size(), b_off, bl.length(), bl, csum_data);
|
||||
break;
|
||||
default:
|
||||
r = -EOPNOTSUPP;
|
||||
break;
|
||||
|
@ -221,11 +221,12 @@ struct bluestore_blob_t {
|
||||
|
||||
enum CSumType {
|
||||
CSUM_NONE = 0,
|
||||
CSUM_CRC32C = 1,
|
||||
CSUM_XXHASH32 = 2,
|
||||
CSUM_XXHASH64 = 3,
|
||||
CSUM_XXHASH32 = 1,
|
||||
CSUM_XXHASH64 = 2,
|
||||
CSUM_CRC32C = 3,
|
||||
CSUM_CRC32C_16 = 4, // low 16 bits of crc32c
|
||||
CSUM_CRC32C_8 = 5, // low 8 bits of crc32c
|
||||
CSUM_MAX,
|
||||
CSUM_CRC16, // ** not yet implemented **
|
||||
};
|
||||
static const char *get_csum_type_string(unsigned t) {
|
||||
switch (t) {
|
||||
@ -233,7 +234,8 @@ struct bluestore_blob_t {
|
||||
case CSUM_XXHASH32: return "xxhash32";
|
||||
case CSUM_XXHASH64: return "xxhash64";
|
||||
case CSUM_CRC32C: return "crc32c";
|
||||
case CSUM_CRC16: return "crc16";
|
||||
case CSUM_CRC32C_16: return "crc32c_16";
|
||||
case CSUM_CRC32C_8: return "crc32c_8";
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
@ -246,8 +248,10 @@ struct bluestore_blob_t {
|
||||
return CSUM_XXHASH64;
|
||||
if (s == "crc32c")
|
||||
return CSUM_CRC32C;
|
||||
if (s == "crc16")
|
||||
return CSUM_CRC16;
|
||||
if (s == "crc32c_16")
|
||||
return CSUM_CRC32C_16;
|
||||
if (s == "crc32c_8")
|
||||
return CSUM_CRC32C_8;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@ -453,7 +457,8 @@ struct bluestore_blob_t {
|
||||
case CSUM_XXHASH32: return 4;
|
||||
case CSUM_XXHASH64: return 8;
|
||||
case CSUM_CRC32C: return 4;
|
||||
case CSUM_CRC16: return 2;
|
||||
case CSUM_CRC32C_16: return 2;
|
||||
case CSUM_CRC32C_8: return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user