summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Anderson <dda@ddanderson.com>2013-10-04 17:30:36 -0400
committerDon Anderson <dda@ddanderson.com>2013-10-04 17:30:36 -0400
commite11341052470a39aeb3c47f7646b799cd3e945a4 (patch)
treed13e902a537041605747061713e7bb338986d1aa
parentd5f8cb6f7d246e5ed71768ff9642723360bb76d8 (diff)
downloadmongo-e11341052470a39aeb3c47f7646b799cd3e945a4.tar.gz
Use funcptr, inited from __wt_library_init.
Alphabetize and other cleanup. refs #582
-rw-r--r--src/include/extern.h1
-rw-r--r--src/support/cksum.c96
-rw-r--r--src/support/global.c1
3 files changed, 35 insertions, 63 deletions
diff --git a/src/include/extern.h b/src/include/extern.h
index 1ef100c6ef9..d4abcf3615b 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -1169,6 +1169,7 @@ extern int __wt_session_discard_btree( WT_SESSION_IMPL *session,
WT_DATA_HANDLE_CACHE *dhandle_cache);
extern int __wt_salvage(WT_SESSION_IMPL *session, const char *cfg[]);
extern uint32_t __wt_cksum(const void *chunk, size_t len);
+extern void __wt_cksum_init();
extern void __wt_event_handler_set(WT_SESSION_IMPL *session,
WT_EVENT_HANDLER *handler);
extern void __wt_err(WT_SESSION_IMPL *session,
diff --git a/src/support/cksum.c b/src/support/cksum.c
index b6fd45072cf..383b899b9ab 100644
--- a/src/support/cksum.c
+++ b/src/support/cksum.c
@@ -26,39 +26,20 @@
*/
#include "wt_internal.h"
-#include <stddef.h>
-#include <stdint.h>
-
-#define CRC_HARDWARE_UNKNOWN 0
-#define CRC_HARDWARE_PRESENT 1
-#define CRC_HARDWARE_ABSENT 2
/*
- * This file contains two ways of computing CRC: one that uses a hardware CRC
- * instruction (only on newer x86_64/amd64), and one that uses a fast software
- * algorithm. __wt_cksum() provides a common entry point that uses one of these
- * two methods.
- *
- * To take advantage of the CRC hardware instruction, we detect it using
- * get_cpuid() on the first call to __wt_cksum(). Using runtime detection with
- * get_cpuid allows for single compatible binary that can be used across all
- * x86_64/amd64 processors, even those without the CRC hardware.
- *
- * If we do not have CPUID, or if the detection fails to find hardware CRC,
- * we'll use a software algorithm as a fallback.
+ * This file contains two implementations for computing CRC: one that uses
+ * hardware CRC instructions, available on newer x86_64/amd64, and one that uses
+ * a fast software algorithm. __wt_cksum() provides a common entry point that
+ * indirects to one of these two methods.
*/
-#undef TEST_CRC_HARDWARE
-#if (defined(__amd64) || defined(__x86_64))
-#define CRC_HARDWARE_DEFAULT CRC_HARDWARE_UNKNOWN
-#define TEST_CRC_HARDWARE
-#else
-#define CRC_HARDWARE_DEFAULT CRC_HARDWARE_ABSENT
-#endif
+static uint32_t __wt_cksum_sw(const void *chunk, size_t len);
+static uint32_t __wt_cksum_hw(const void *chunk, size_t len);
-static volatile int crc_hardware_check = CRC_HARDWARE_DEFAULT;
+static uint32_t (*__wt_cksum_func)(const void *chunk, size_t len);
/*
- * The CRC slicing tables are used by cksum_sw.
+ * The CRC slicing tables are used by __wt_cksum_sw.
*/
static const uint32_t g_crc_slicing[8][256] = {
#ifdef WORDS_BIGENDIAN
@@ -1113,7 +1094,7 @@ static const uint32_t g_crc_slicing[8][256] = {
};
/*
- * cksum_sw --
+ * __wt_cksum_sw --
* Return a checksum for a chunk of memory, computed in software.
*
* Slicing-by-8 algorithm by Michael E. Kounavis and Frank L. Berry from
@@ -1128,7 +1109,7 @@ static const uint32_t g_crc_slicing[8][256] = {
* little endian.
*/
static uint32_t
-cksum_sw(const void *chunk, size_t len)
+__wt_cksum_sw(const void *chunk, size_t len)
{
uint32_t crc, next;
size_t nqwords;
@@ -1192,14 +1173,14 @@ cksum_sw(const void *chunk, size_t len)
return (~crc);
}
-#ifdef TEST_CRC_HARDWARE
+#if (defined(__amd64) || defined(__x86_64))
/*
- * cksum_hw --
+ * __wt_cksum_hw --
* Return a checksum for a chunk of memory, computed in hardware
* using 8 byte steps.
*/
static uint32_t
-cksum_hw(const void *chunk, size_t len)
+__wt_cksum_hw(const void *chunk, size_t len)
{
uint32_t crc;
size_t nqwords;
@@ -1238,15 +1219,28 @@ cksum_hw(const void *chunk, size_t len)
}
return (~crc);
}
+#endif
+
+/*
+ * __wt_cksum --
+ * Return a checksum for a chunk of memory
+ * using the fastest method available.
+ */
+uint32_t
+__wt_cksum(const void *chunk, size_t len)
+{
+ return (*__wt_cksum_func)(chunk, len);
+}
/*
- * detect_crc_hardware --
+ * __wt_cksum_init --
* Detect CRC hardware if possible, and return one of
* CRC_HARDWARE_PRESENT or CRC_HARDWARE_ABSENT.
*/
-static int
-detect_crc_hardware(void)
+void
+__wt_cksum_init()
{
+#if (defined(__amd64) || defined(__x86_64))
unsigned int eax, ebx, ecx, edx;
__asm__ __volatile__ (
@@ -1257,35 +1251,11 @@ detect_crc_hardware(void)
#define CPUID_ECX_HAS_SSE42 (1 << 20)
if (ecx & CPUID_ECX_HAS_SSE42)
- return (CRC_HARDWARE_PRESENT);
- return (CRC_HARDWARE_ABSENT);
-}
-#endif
-
-/*
- * __wt_cksum --
- * Return a checksum for a chunk of memory
- * using the fastest method available.
- */
-uint32_t
-__wt_cksum(const void *chunk, size_t len)
-{
-#ifdef TEST_CRC_HARDWARE
- uint32_t result;
+ __wt_cksum_func = __wt_cksum_hw;
+ else
+ __wt_cksum_func = __wt_cksum_sw;
- if (crc_hardware_check == CRC_HARDWARE_UNKNOWN)
- crc_hardware_check = detect_crc_hardware();
-
- switch (crc_hardware_check) {
- case CRC_HARDWARE_PRESENT:
- result = cksum_hw(chunk, len);
- break;
- default:
- result = cksum_sw(chunk, len);
- break;
- }
- return (result);
#else
- return (cksum_sw(chunk, len));
+ __wt_cksum_func = __wt_cksum_sw;
#endif
}
diff --git a/src/support/global.c b/src/support/global.c
index 644b5c19a94..1afd5de6d2f 100644
--- a/src/support/global.c
+++ b/src/support/global.c
@@ -32,6 +32,7 @@ static void
__wt_pthread_once(void)
{
__wt_spin_init(NULL, &__wt_process.spinlock);
+ __wt_cksum_init();
TAILQ_INIT(&__wt_process.connqh);