Skip to content

Commit 7247a9d

Browse files
committed
TEST COMMIT FOR INTEL
1 parent 9b2d4b5 commit 7247a9d

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

include/linux/zstd.h

+32
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ typedef ZSTD_CCtx zstd_cctx;
153153
*/
154154
size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters);
155155

156+
/**
157+
* zstd_cctx_workspace_bound_with_ext_seq_prod() - max memory needed to
158+
* initialize a zstd_cctx when using the block-level external sequence
159+
* producer API.
160+
* @parameters: The compression parameters to be used.
161+
*
162+
* If multiple parameters might be used, the caller must call this function
163+
* for each set of parameters and use the maximum bound.
164+
*
165+
* Return: A lower bound on the size of the workspace that is passed to
166+
* zstd_init_cctx().
167+
*/
168+
size_t zstd_cctx_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *parameters);
169+
156170
/**
157171
* zstd_init_cctx() - initialize a zstd compression context
158172
* @workspace: The workspace to emplace the context into. It must outlive
@@ -257,6 +271,16 @@ typedef ZSTD_CStream zstd_cstream;
257271
*/
258272
size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams);
259273

274+
/**
275+
* zstd_cstream_workspace_bound_with_ext_seq_prod() - memory needed to initialize
276+
* a zstd_cstream when using the block-level external sequence producer API.
277+
* @cparams: The compression parameters to be used for compression.
278+
*
279+
* Return: A lower bound on the size of the workspace that is passed to
280+
* zstd_init_cstream().
281+
*/
282+
size_t zstd_cstream_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *cparams);
283+
260284
/**
261285
* zstd_init_cstream() - initialize a zstd streaming compression context
262286
* @parameters The zstd parameters to use for compression.
@@ -416,6 +440,14 @@ size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
416440
*/
417441
size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
418442

443+
/* TODO add docs after Intel tests the code */
444+
typedef ZSTD_sequenceProducer_F zstd_sequence_producer_f;
445+
void zstd_register_sequence_producer(
446+
zstd_cctx *cctx,
447+
void* sequence_producer_state,
448+
zstd_sequence_producer_f sequence_producer
449+
);
450+
419451
/**
420452
* struct zstd_frame_params - zstd frame parameters stored in the frame header
421453
* @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not

lib/zstd/zstd_compress_module.c

+56
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "common/zstd_deps.h"
1818
#include "common/zstd_internal.h"
19+
#include "compress/zstd_compress_internal.h"
1920

2021
#define ZSTD_FORWARD_IF_ERR(ret) \
2122
do { \
@@ -85,6 +86,52 @@ size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *cparams)
8586
}
8687
EXPORT_SYMBOL(zstd_cctx_workspace_bound);
8788

89+
// Used by zstd_cctx_workspace_bound_with_ext_seq_prod()
90+
static size_t dummy_external_sequence_producer(
91+
void *sequenceProducerState,
92+
ZSTD_Sequence *outSeqs, size_t outSeqsCapacity,
93+
const void *src, size_t srcSize,
94+
const void *dict, size_t dictSize,
95+
int compressionLevel,
96+
size_t windowSize)
97+
{
98+
(void)sequenceProducerState;
99+
(void)outSeqs; (void)outSeqsCapacity;
100+
(void)src; (void)srcSize;
101+
(void)dict; (void)dictSize;
102+
(void)compressionLevel;
103+
(void)windowSize;
104+
return ZSTD_SEQUENCE_PRODUCER_ERROR;
105+
}
106+
107+
static void init_cctx_params_from_compress_params(
108+
ZSTD_CCtx_params *cctx_params,
109+
const zstd_compression_parameters *compress_params)
110+
{
111+
ZSTD_parameters zstd_params;
112+
memset(&zstd_params, 0, sizeof(zstd_params));
113+
zstd_params.cParams = *compress_params;
114+
ZSTD_CCtxParams_init_advanced(&cctx_params, zstd_params);
115+
}
116+
117+
size_t zstd_cctx_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *compress_params)
118+
{
119+
ZSTD_CCtx_params cctx_params;
120+
init_cctx_params_from_compress_params(&cctx_params, compress_params);
121+
ZSTD_CCtxParams_registerSequenceProducer(&cctx_params, NULL, dummy_external_sequence_producer);
122+
return ZSTD_estimateCCtxSize_usingCCtxParams(&cctx_params);
123+
}
124+
EXPORT_SYMBOL(zstd_cctx_workspace_bound_with_ext_seq_prod);
125+
126+
size_t zstd_cstream_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *compress_params)
127+
{
128+
ZSTD_CCtx_params cctx_params;
129+
init_cctx_params_from_compress_params(&cctx_params, compress_params);
130+
ZSTD_CCtxParams_registerSequenceProducer(&cctx_params, NULL, dummy_external_sequence_producer);
131+
return ZSTD_estimateCStreamSize_usingCCtxParams(&cctx_params);
132+
}
133+
EXPORT_SYMBOL(zstd_cstream_workspace_bound_with_ext_seq_prod);
134+
88135
zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size)
89136
{
90137
if (workspace == NULL)
@@ -160,5 +207,14 @@ size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output)
160207
}
161208
EXPORT_SYMBOL(zstd_end_stream);
162209

210+
void zstd_register_sequence_producer(
211+
zstd_cctx *cctx,
212+
void* sequence_producer_state,
213+
zstd_sequence_producer_f sequence_producer
214+
) {
215+
ZSTD_registerSequenceProducer(cctx, sequence_producer_state, sequence_producer);
216+
}
217+
EXPORT_SYMBOL(zstd_register_sequence_producer);
218+
163219
MODULE_LICENSE("Dual BSD/GPL");
164220
MODULE_DESCRIPTION("Zstd Compressor");

0 commit comments

Comments
 (0)