Skip to content

Commit

Permalink
QATAPP-30476: Replace macro with compress-bound API
Browse files Browse the repository at this point in the history
* QATAPP-30476: Replace macro with compress-bound API

Signed-off-by: GarenJian-Intel <[email protected]>
  • Loading branch information
GarenJian-Intel committed Sep 8, 2023
1 parent edda050 commit 0d92ab3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/qatseqprod.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@

#define INTER_SZ(src_sz) (2 * (src_sz))
#define COMPRESS_SRC_BUFF_SZ (ZSTD_BLOCKSIZE_MAX)
#define DC_CEIL_DIV(x, y) (((x) + (y)-1) / (y))
/* Formula for GEN4 LZ4S:
* sourceLen + Ceil(sourceLen/18) * 1 + 1024 */
#define INTERMEDIATE_BUFFER_SZ (ZSTD_BLOCKSIZE_MAX + 1024 + DC_CEIL_DIV(ZSTD_BLOCKSIZE_MAX, 18))

#define ML_BITS 4
#define ML_MASK ((1U << ML_BITS) - 1)
Expand Down Expand Up @@ -1134,6 +1130,7 @@ size_t qatSequenceProducer(
struct timeval timeStart;
struct timeval timeNow;
QZSTD_Session_T *zstdSess = (QZSTD_Session_T *)sequenceProducerState;
Cpa32U intermediateBufLen = 0;

if (windowSize < (srcSize < 32 * KB ? srcSize : 32 * KB) || dictSize > 0 ||
dict) {
Expand Down Expand Up @@ -1215,10 +1212,17 @@ size_t qatSequenceProducer(
}
}

if (CPA_STATUS_SUCCESS != cpaDcLZ4SCompressBound(gProcess.dcInstHandle[i],
ZSTD_BLOCKSIZE_MAX, &intermediateBufLen)) {
QZSTD_LOG(1, "Failed to caculate compress bound\n");
rc = ZSTD_SEQUENCE_PRODUCER_ERROR;
goto exit;
}

/* Allocate intermediate buffer for storing lz4s format compressed by QAT */
if (NULL == zstdSess->qatIntermediateBuf) {
zstdSess->qatIntermediateBuf =
(unsigned char *)QZSTD_calloc(1, INTERMEDIATE_BUFFER_SZ,
(unsigned char *)QZSTD_calloc(1, intermediateBufLen,
zstdSess->reqPhyContMem);
if (NULL == zstdSess->qatIntermediateBuf) {
QZSTD_LOG(1, "Failed to allocate memory");
Expand All @@ -1238,7 +1242,7 @@ size_t qatSequenceProducer(

gProcess.qzstdInst[i].srcBuffer->pBuffers->dataLenInBytes = srcSize;
gProcess.qzstdInst[i].destBuffer->pBuffers->dataLenInBytes =
INTERMEDIATE_BUFFER_SZ;
intermediateBufLen;

memset(&opData, 0, sizeof(CpaDcOpData));
opData.inputSkipData.skipMode = CPA_DC_SKIP_DISABLED;
Expand Down Expand Up @@ -1300,7 +1304,7 @@ size_t qatSequenceProducer(

if (gProcess.qzstdInst[i].res.consumed < srcSize ||
gProcess.qzstdInst[i].res.produced == 0 ||
gProcess.qzstdInst[i].res.produced > INTERMEDIATE_BUFFER_SZ ||
gProcess.qzstdInst[i].res.produced > intermediateBufLen ||
CPA_STATUS_SUCCESS != gProcess.qzstdInst[i].res.status) {
QZSTD_LOG(1,
"QAT result error, srcSize: %lu, consumed: %d, produced: %d, res.status:%d\n",
Expand Down

0 comments on commit 0d92ab3

Please sign in to comment.