]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: add crc32c_16 and crc32c_8 9526/head
authorSage Weil <sage@redhat.com>
Wed, 15 Jun 2016 19:23:17 +0000 (15:23 -0400)
committerSage Weil <sage@redhat.com>
Wed, 15 Jun 2016 19:25:30 +0000 (15:25 -0400)
This is much faster than a slice-by-8 crc16, perhaps even without the
intel instructions.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/Checksummer.h
src/os/bluestore/bluestore_types.cc
src/os/bluestore/bluestore_types.h

index 28406540b37463d44c27512ec18600e30c46af0b..eda44734ebf6c61b2cb2fba5f9de720768275ca2 100644 (file)
@@ -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;
 
index 7a6494069449b3396ffdf7f0d00e54d47ebf2db0..2dbfec55e27c064ff5a4a966e47f9d0ba3d9c50b 100644 (file)
@@ -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;
index 54b84a059caff2781e67016e18cf556c1762fa20..080ae1e8b8db1904df3b7e84ba994c4170728f59 100644 (file)
@@ -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;
     }
   }