common/Finisher.cc \
common/environment.cc\
common/sctp_crc32.c\
+ common/crc32c.cc\
common/crc32c-intel.c\
common/assert.cc \
common/run_cmd.cc \
common/utf8.h\
common/mime.h\
common/pick_address.h\
+ common/sctp_crc32.h\
common/secret.h\
common/strtol.h\
common/static_assert.h\
--- /dev/null
+#include "include/crc32c.h"
+
+#include "common/sctp_crc32.h"
+
+/*
+ * choose best implementation based on the CPU architecture.
+ */
+ceph_crc32c_func_t ceph_choose_crc32(void)
+{
+ /* default */
+ return ceph_crc32c_sctp;
+}
+
+/*
+ * static global
+ *
+ * This is a bit of a no-no for shared libraries, but we don't care.
+ * It is effectively constant for the executing process as the value
+ * depends on the CPU architecture.
+ *
+ * We initialize it during program init using the magic of C++.
+ */
+ceph_crc32c_func_t ceph_crc32c_func = ceph_choose_crc32();
+
}
#endif
-uint32_t ceph_crc32c_le_generic(uint32_t crc, unsigned char const *data, unsigned length)
+uint32_t ceph_crc32c_sctp(uint32_t crc, unsigned char const *data, unsigned length)
{
return update_crc32(crc, data, length);
}
--- /dev/null
+#ifndef CEPH_COMMON_SCTP_CRC32_H
+#define CEPH_COMMON_SCTP_CRC32_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern uint32_t ceph_crc32c_sctp(uint32_t crc, unsigned char const *data, unsigned length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
it != _buffers.end();
++it)
if (it->length())
- crc = ceph_crc32c_le(crc, (unsigned char*)it->c_str(), it->length());
+ crc = ceph_crc32c(crc, (unsigned char*)it->c_str(), it->length());
return crc;
}
#ifndef CEPH_CRC32C_H
#define CEPH_CRC32C_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+#include "include/inttypes.h"
#include <string.h>
-extern int ceph_have_crc32c_intel(void);
-extern uint32_t ceph_crc32c_le_generic(uint32_t crc, unsigned char const *data, unsigned length);
-extern uint32_t ceph_crc32c_le_intel(uint32_t crc, unsigned char const *data, unsigned length);
+typedef uint32_t (*ceph_crc32c_func_t)(uint32_t crc, unsigned char const *data, unsigned length);
-static inline uint32_t ceph_crc32c_le(uint32_t crc, unsigned char const *data, unsigned length) {
- if (ceph_have_crc32c_intel()) //__builtin_cpu_supports("sse4.2"))
- return ceph_crc32c_le_intel(crc, data, length);
- else
- return ceph_crc32c_le_generic(crc, data, length);
-}
+/*
+ * this is a static global with the chosen crc32c implementation for
+ * the given architecture.
+ */
+extern ceph_crc32c_func_t ceph_crc32c_func;
-#ifdef __cplusplus
+extern ceph_crc32c_func_t ceph_choose_crc32(void);
+
+/*
+ * common entry point; use this!
+ */
+static inline uint32_t ceph_crc32c(uint32_t crc, unsigned char const *data, unsigned length)
+{
+ return ceph_crc32c_func(crc, data, length);
}
-#endif
#endif
const utime_t& get_recv_complete_stamp() const { return recv_complete_stamp; }
void calc_header_crc() {
- header.crc = ceph_crc32c_le(0, (unsigned char*)&header,
- sizeof(header) - sizeof(header.crc));
+ header.crc = ceph_crc32c(0, (unsigned char*)&header,
+ sizeof(header) - sizeof(header.crc));
}
void calc_front_crc() {
footer.front_crc = payload.crc32c(0);
if (connection_state->has_feature(CEPH_FEATURE_NOSRCADDR)) {
if (tcp_read((char*)&header, sizeof(header)) < 0)
return -1;
- header_crc = ceph_crc32c_le(0, (unsigned char *)&header, sizeof(header) - sizeof(header.crc));
+ header_crc = ceph_crc32c(0, (unsigned char *)&header, sizeof(header) - sizeof(header.crc));
} else {
ceph_msg_header_old oldheader;
if (tcp_read((char*)&oldheader, sizeof(oldheader)) < 0)
header.src = oldheader.src.name;
header.reserved = oldheader.reserved;
header.crc = oldheader.crc;
- header_crc = ceph_crc32c_le(0, (unsigned char *)&oldheader, sizeof(oldheader) - sizeof(oldheader.crc));
+ header_crc = ceph_crc32c(0, (unsigned char *)&oldheader, sizeof(oldheader) - sizeof(oldheader.crc));
}
ldout(msgr->cct,20) << "reader got envelope type=" << header.type
oldheader.src.addr = connection_state->get_peer_addr();
oldheader.orig_src = oldheader.src;
oldheader.reserved = header.reserved;
- oldheader.crc = ceph_crc32c_le(0, (unsigned char*)&oldheader,
- sizeof(oldheader) - sizeof(oldheader.crc));
+ oldheader.crc = ceph_crc32c(0, (unsigned char*)&oldheader,
+ sizeof(oldheader) - sizeof(oldheader.crc));
msgvec[msg.msg_iovlen].iov_base = (char*)&oldheader;
msgvec[msg.msg_iovlen].iov_len = sizeof(oldheader);
msglen += sizeof(oldheader);