diff --git a/README.md b/README.md index c125619..b36a23b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config/config.cpp b/config/config.cpp index 1265b95..da07b8d 100644 --- a/config/config.cpp +++ b/config/config.cpp @@ -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*/ }; @@ -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" }; @@ -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); diff --git a/config/config.h b/config/config.h index ed28d4a..64f88a9 100644 --- a/config/config.h +++ b/config/config.h @@ -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 diff --git a/config/default_config b/config/default_config index 5f4e9b0..6ae0cc8 100644 --- a/config/default_config +++ b/config/default_config @@ -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 diff --git a/qat.cpp b/qat.cpp index bcebea7..71380ca 100644 --- a/qat.cpp +++ b/qat.cpp @@ -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(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(qzSession), " returned ", rc, "\n"); } delete qzSession; diff --git a/zlib_accel.cpp b/zlib_accel.cpp index 4101b88..1c5fa74 100644 --- a/zlib_accel.cpp +++ b/zlib_accel.cpp @@ -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(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(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) { @@ -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(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(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) { @@ -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(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(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) {