Skip to content
Merged
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ qat_compression_allow_chunking
- If set to 1, data larger than the QAT HW buffer (512kB) will be split into chunks of HW buffer size when compressing with QAT. This causes the compressed data to be a concatenation of multiple streams (one per chunk). This is not the same behavior as for zlib, which creates a single stream. If decompression expects a single stream, this may cause issues.
- If set to 0, this option disables chunking for QAT compression. If the input data is larger than the QAT HW buffer, QAT will not be used. This improves zlib compatibility, but it may reduce QAT utilization depending on the workload.

ignore_zlib_dictionary
- Values: 0, 1. Default: 0
- If set to 1, zlib-accel ignores deflateSetDictionary and inflateSetDictionary.
- If set to 0, zlib-accel honors inflateSetDictionary and deflateSetDictionary.

log_level
- Values: 0,1,2. Default 2
- This option applies only if the shim is built with DEBUG_LOG=ON.
Expand Down
3 changes: 3 additions & 0 deletions config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ uint32_t configs[CONFIG_MAX] = {
0, /*qat_periodical_polling*/
1, /*qat_compression_level*/
0, /*qat_compression_allow_chunking*/
0, /*ignore_zlib_dictionary*/
2, /*log_level*/
1000 /*log_stats_samples*/
};
Expand All @@ -51,6 +52,7 @@ bool LoadConfigFile(std::string& file_content, const char* file_path) {
"qat_periodical_polling",
"qat_compression_level",
"qat_compression_allow_chunking",
"ignore_zlib_dictionary",
"log_level",
"log_stats_samples"
};
Expand Down Expand Up @@ -83,6 +85,7 @@ bool LoadConfigFile(std::string& file_content, const char* file_path) {
trySetConfig(QAT_PERIODICAL_POLLING, 1, 0);
trySetConfig(QAT_COMPRESSION_LEVEL, 9, 1);
trySetConfig(QAT_COMPRESSION_ALLOW_CHUNKING, 1, 0);
trySetConfig(IGNORE_ZLIB_DICTIONARY, 1, 0);
trySetConfig(LOG_LEVEL, 2, 0);
trySetConfig(LOG_STATS_SAMPLES, UINT32_MAX, 0);

Expand Down
1 change: 1 addition & 0 deletions config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum ConfigOption {
QAT_PERIODICAL_POLLING,
QAT_COMPRESSION_LEVEL,
QAT_COMPRESSION_ALLOW_CHUNKING,
IGNORE_ZLIB_DICTIONARY,
LOG_LEVEL,
LOG_STATS_SAMPLES,
CONFIG_MAX
Expand Down
1 change: 1 addition & 0 deletions config/default_config
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ iaa_prepend_empty_block = 0
qat_periodical_polling = 0
qat_compression_level = 1
qat_compression_allow_chunking = 0
ignore_zlib_dictionary = 0
log_level = 2
log_file = /tmp/zlib-accel.log
9 changes: 4 additions & 5 deletions qat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ void QATJob::QzSessionDeleter::operator()(QzSession_T *qzSession) const {

int rc = qzTeardownSession(qzSession);
if (rc != QZ_OK) {
Log(LogLevel::LOG_ERROR,
"qzTeardownSession() Line %d session %p returned %d\n", __LINE__,
qzSession, rc);
Log(LogLevel::LOG_ERROR, "qzTeardownSession() Line ", __LINE__, " session ",
static_cast<void *>(qzSession), " returned ", rc, "\n");
}

// Attempt to close the session
rc = qzClose(qzSession);
if (rc != QZ_OK) {
Log(LogLevel::LOG_ERROR, "qzClose() Line %d session %p returned %d\n",
__LINE__, qzSession, rc);
Log(LogLevel::LOG_ERROR, "qzClose() Line ", __LINE__, " session ",
static_cast<void *>(qzSession), " returned ", rc, "\n");
}

delete qzSession;
Expand Down
64 changes: 37 additions & 27 deletions zlib_accel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,21 @@ static int init_zlib_accel(void) __attribute__((constructor));
static void cleanup_zlib_accel(void) __attribute__((destructor));

// Macro that load symbols with error checking
#define LOAD_SYMBOL(fptr, type, name) \
do { \
dlerror(); \
fptr = reinterpret_cast<type>(dlsym(RTLD_NEXT, name)); \
const char* error = dlerror(); \
if (error != nullptr) { \
Log(LogLevel::LOG_ERROR, \
"init_zlib_accel Line %d Failed to load symbol '%s': %s\n", \
__LINE__, name, error); \
return 1; \
} \
if (fptr == nullptr) { \
Log(LogLevel::LOG_ERROR, \
"init_zlib_accel Line %d Symbol '%s' resolved to NULL\n", __LINE__, \
name); \
return 1; \
} \
#define LOAD_SYMBOL(fptr, type, name) \
do { \
dlerror(); \
fptr = reinterpret_cast<type>(dlsym(RTLD_NEXT, name)); \
const char* error = dlerror(); \
if (error != nullptr) { \
Log(LogLevel::LOG_ERROR, "init_zlib_accel Line ", __LINE__, \
"Failed to load symbol '", name, "': ", error, "\n"); \
return 1; \
} \
if (fptr == nullptr) { \
Log(LogLevel::LOG_ERROR, "init_zlib_accel Line ", __LINE__, " Symbol '", \
name, "' resolved to NULL\n"); \
return 1; \
} \
} while (0)

static int init_zlib_accel(void) {
Expand Down Expand Up @@ -262,11 +260,17 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,

int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef* dictionary,
uInt dictLength) {
Log(LogLevel::LOG_INFO, "deflateSetDictionary Line ", __LINE__, ", strm ",
static_cast<void*>(strm), ", dictLength ", dictLength, "\n");
DeflateSettings* deflate_settings = deflate_stream_settings.Get(strm);
deflate_settings->path = ZLIB;
return orig_deflateSetDictionary(strm, dictionary, dictLength);
if (!configs[IGNORE_ZLIB_DICTIONARY]) {
Log(LogLevel::LOG_INFO, "deflateSetDictionary Line ", __LINE__, ", strm ",
static_cast<void*>(strm), ", dictLength ", dictLength, "\n");
DeflateSettings* deflate_settings = deflate_stream_settings.Get(strm);
deflate_settings->path = ZLIB;
return orig_deflateSetDictionary(strm, dictionary, dictLength);
}
Log(LogLevel::LOG_INFO, "deflateSetDictionary Line ", __LINE__,
" ignored because ignore_zlib_dictionary is set to ",
configs[IGNORE_ZLIB_DICTIONARY], "\n");
return Z_OK;
}

int ZEXPORT deflate(z_streamp strm, int flush) {
Expand Down Expand Up @@ -416,11 +420,17 @@ int ZEXPORT inflateInit2_(z_streamp strm, int window_bits, const char* version,

int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef* dictionary,
uInt dictLength) {
Log(LogLevel::LOG_INFO, "inflateSetDictionary Line ", __LINE__, ", strm ",
static_cast<void*>(strm), ", dictLength ", dictLength, "\n");
InflateSettings* inflate_settings = inflate_stream_settings.Get(strm);
inflate_settings->path = ZLIB;
return orig_inflateSetDictionary(strm, dictionary, dictLength);
if (!configs[IGNORE_ZLIB_DICTIONARY]) {
Log(LogLevel::LOG_INFO, "inflateSetDictionary Line ", __LINE__, ", strm ",
static_cast<void*>(strm), "dictLength ", dictLength, "\n");
InflateSettings* inflate_settings = inflate_stream_settings.Get(strm);
inflate_settings->path = ZLIB;
return orig_inflateSetDictionary(strm, dictionary, dictLength);
}
Log(LogLevel::LOG_INFO, "inflateSetDictionary Line ", __LINE__,
" ignored because ignore_zlib_dictionary is set to ",
configs[IGNORE_ZLIB_DICTIONARY], "\n");
return Z_OK;
}

int ZEXPORT inflate(z_streamp strm, int flush) {
Expand Down