Skip to content

Bug #79747: CRC32: add aarch64 and power8, use optimized for binlogs and CRC32() #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions extra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,26 @@ IF(WITH_INNOBASE_STORAGE_ENGINE)
ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM")
SET(INNOBASE_SOURCES
../storage/innobase/buf/buf0checksum.cc
../storage/innobase/ut/ut0crc32.cc
../mysys/ut0crc32.cc
../storage/innobase/ut/ut0ut.cc
../storage/innobase/buf/buf0buf.cc
../storage/innobase/page/page0zip.cc
../storage/innobase/os/os0file.cc
)

IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
enable_language(ASM)
LIST(APPEND INNOBASE_SOURCES
../mysys/crc32_power8/crc32.S
../mysys/crc32_power8/crc32_wrapper.c)
ENDIF()

# Avoid generating Hardware Capabilities due to crc32 instructions
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND
CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
ADD_COMPILE_FLAGS(
../storage/innobase/ut/ut0crc32.cc
../mysys/ut0crc32.cc
COMPILE_FLAGS "-Wa,-nH"
)
ENDIF()
Expand Down
32 changes: 29 additions & 3 deletions storage/innobase/include/ut0crc32.h → include/ut0crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ Created Aug 10, 2011 Vasil Dimov
#ifndef ut0crc32_h
#define ut0crc32_h

#include "univ.i"
#ifndef byte
#define byte unsigned char
#endif

#include <stdint.h>
#include <inttypes.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* #include "univ.i" defines ULINTPF and types within storage/innodb but
* we duplicated those here since crc32 is used globally */
#ifndef ULINTPF
#ifdef _WIN64
typedef unsigned __int64 ulint;
#else
typedef unsigned long int ulint;
#endif /* _WIN64 */
#endif


/********************************************************************//**
Initializes the data structures used by ut_crc32*(). Does not do any
Expand All @@ -46,6 +64,14 @@ typedef uint32_t (*ut_crc32_func_t)(const byte* ptr, ulint len);
/** Pointer to CRC32 calculation function. */
extern ut_crc32_func_t ut_crc32;

/********************************************************************//**
Appends CRC32 onto intial value.
This mirrors the zlib crc32 interface
@param crc - initial crc32 value
@param ptr - data over which to calculate CRC32. ptr==NULL to initialize
@param len - data length in bytes. */
uint32_t checksum_crc32(uint32_t crc, const byte* ptr, ulint len);

/** Pointer to CRC32 calculation function, which uses big-endian byte order
when converting byte strings to integers internally. */
extern ut_crc32_func_t ut_crc32_legacy_big_endian;
Expand All @@ -54,7 +80,7 @@ extern ut_crc32_func_t ut_crc32_legacy_big_endian;
but very slow). */
extern ut_crc32_func_t ut_crc32_byte_by_byte;

/** Flag that tells whether the CPU supports CRC32 or not */
extern bool ut_crc32_sse2_enabled;
/** Text description of CRC32 implementation */
extern const char *ut_crc32_implementation;

#endif /* ut0crc32_h */
19 changes: 0 additions & 19 deletions libbinlogevents/include/binlog_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
#include "byteorder.h"
#include "wrapper_functions.h"
#include <zlib.h> //for checksum calculations
#include <cstdio>
#include <iostream>
#include <climits>
Expand Down Expand Up @@ -405,24 +404,6 @@ enum enum_binlog_checksum_alg
#define BINLOG_CHECKSUM_ALG_DESC_LEN 1 /* 1 byte checksum alg descriptor */
#define LOG_EVENT_HEADER_SIZE 20

/**
Calculate a long checksum for a memoryblock.

@param crc start value for crc
@param pos pointer to memory block
@param length length of the block

@return checksum for a memory block
*/
inline uint32_t checksum_crc32(uint32_t crc, const unsigned char *pos,
size_t length)
{
BAPI_ASSERT(length <= UINT_MAX);
return static_cast<uint32_t>(crc32(static_cast<unsigned int>(crc), pos,
static_cast<unsigned int>(length)));
}


/*
Reads string from buf.

Expand Down
7 changes: 4 additions & 3 deletions libbinlogevents/src/binlog_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "binary_log_types.h"

#include "statement_events.h"
#include "ut0crc32.h"

#include <algorithm>
#include <stdint.h>
Expand Down Expand Up @@ -255,9 +256,9 @@ bool Log_event_footer::event_checksum_test(unsigned char *event_buf,

computed= checksum_crc32(0L, NULL, 0);
/* checksum the event content but not the checksum part itself */
computed= binary_log::checksum_crc32(computed,
(const unsigned char*) event_buf,
event_len - BINLOG_CHECKSUM_LEN);
computed= checksum_crc32(computed,
(const unsigned char*) event_buf,
event_len - BINLOG_CHECKSUM_LEN);

if (flags != 0)
{
Expand Down
18 changes: 17 additions & 1 deletion mysys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c
thr_rwlock.c tree.c typelib.c base64.c my_memmem.c
lf_alloc-pin.c lf_dynarray.c lf_hash.c
my_rdtsc.c psi_noop.c my_syslog.c
my_chmod.c my_thread.c)
my_chmod.c my_thread.c ut0crc32.cc)

IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
enable_language(ASM)
LIST(APPEND MYSYS_SOURCES
crc32_power8/crc32.S
crc32_power8/crc32_wrapper.c)
ENDIF()

IF (WIN32)
LIST(APPEND MYSYS_SOURCES
Expand All @@ -54,6 +61,15 @@ IF(HAVE_KQUEUE_TIMERS)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} kqueue_timers.c)
ENDIF()

# Avoid generating Hardware Capabilities due to crc32 instructions
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
ADD_COMPILE_FLAGS(
ut0crc32.cc
COMPILE_FLAGS "-Wa,-nH"
)
ENDIF()

IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro")
# Inline assembly template for rdtsc
SET_SOURCE_FILES_PROPERTIES(my_rdtsc.c
Expand Down
Loading