[v2,3/5] compress/zlib: add xform and stream create support

Message ID 1530550631-22841-4-git-send-email-shally.verma@caviumnetworks.com (mailing list archive)
State Changes Requested, archived
Delegated to: Pablo de Lara Guarch
Headers
Series compress: add ZLIB compression PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Shally Verma July 2, 2018, 4:57 p.m. UTC
  From: Sunila Sahu <ssahu@caviumnetworks.com>

Implement private xform and stream create ops

Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
---
 drivers/compress/zlib/zlib_pmd.c         | 93 ++++++++++++++++++++++++++++++++
 drivers/compress/zlib/zlib_pmd_ops.c     | 83 ++++++++++++++++++++++++++--
 drivers/compress/zlib/zlib_pmd_private.h |  4 ++
 3 files changed, 176 insertions(+), 4 deletions(-)
  

Comments

De Lara Guarch, Pablo July 11, 2018, 12:26 p.m. UTC | #1
> -----Original Message-----
> From: Shally Verma [mailto:shally.verma@caviumnetworks.com]
> Sent: Monday, July 2, 2018 5:57 PM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; pathreya@caviumnetworks.com;
> mchalla@caviumnetworks.com; Sunila Sahu <ssahu@caviumnetworks.com>;
> Sunila Sahu <sunila.sahu@caviumnetworks.com>; Ashish Gupta
> <ashish.gupta@caviumnetworks.com>
> Subject: [PATCH v2 3/5] compress/zlib: add xform and stream create support

Retitle to "compress/zlib: support xform and stream creation"

About stateful, since it looks like it is not supported for the moment,
I think stream_create/stream_free functions should fail or should not be implemented.

More comments inline.

> 
> From: Sunila Sahu <ssahu@caviumnetworks.com>
> 
> Implement private xform and stream create ops
> 
> Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
> Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
> Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
> ---
>  drivers/compress/zlib/zlib_pmd.c         | 93
> ++++++++++++++++++++++++++++++++
>  drivers/compress/zlib/zlib_pmd_ops.c     | 83 ++++++++++++++++++++++++++--
>  drivers/compress/zlib/zlib_pmd_private.h |  4 ++
>  3 files changed, 176 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/compress/zlib/zlib_pmd.c b/drivers/compress/zlib/zlib_pmd.c
> index c4f67bb..7c2614e 100644
> --- a/drivers/compress/zlib/zlib_pmd.c
> +++ b/drivers/compress/zlib/zlib_pmd.c

...

> +		case RTE_COMP_HUFFMAN_DYNAMIC:
> +			strategy = Z_HUFFMAN_ONLY;

I don't think this is the suitable value for dynamic compression.
Z_HUFFMAN_ONLY does not do LZ77. I think the strategy for this case is Z_DEFAULT_STRATEGY.

> +			break;
> +		default:
> +			ZLIB_PMD_ERR("Compression strategy not
> supported\n");
> +			return -1;
> +		}

...

> +++ b/drivers/compress/zlib/zlib_pmd_ops.c

...

> +	struct rte_mempool *mp = rte_mempool_lookup(internals->mp_name);

As said in other email, you can directly get the mempool pointer from internals.

> +	if (rte_mempool_get(mp, zstream)) {
> +		ZLIB_PMD_ERR(
> +				"Couldn't get object from session mempool");

This can be in the same line.

...

> +/** Configure private xform */
> +static int
> +zlib_pmd_private_xform_create(struct rte_compressdev *dev,
> +		const struct rte_comp_xform *xform,
> +		void **private_xform)
> +{
> +	int ret = 0;
> +
> +	ret = zlib_pmd_stream_create(dev, xform, private_xform);
> +	return ret;

This can be written like "return zlib_pmd_stream_create(...);

...

> +		.private_xform_create	= zlib_pmd_private_xform_create,
> +		.private_xform_free		=
> zlib_pmd_private_xform_free,

Fix indentation here.

> 
> -		.stream_create	= NULL,
> -		.stream_free	= NULL
> +		.stream_create	= zlib_pmd_stream_create,
> +		.stream_free	= zlib_pmd_stream_free
>  };
  
Verma, Shally July 11, 2018, 2:01 p.m. UTC | #2
>-----Original Message-----
>From: De Lara Guarch, Pablo [mailto:pablo.de.lara.guarch@intel.com]
>Sent: 11 July 2018 17:57
>To: Verma, Shally <Shally.Verma@cavium.com>
>Cc: dev@dpdk.org; Athreya, Narayana Prasad <NarayanaPrasad.Athreya@cavium.com>; Challa, Mahipal
><Mahipal.Challa@cavium.com>; Sahu, Sunila <Sunila.Sahu@cavium.com>; Sahu, Sunila <Sunila.Sahu@cavium.com>; Gupta, Ashish
><Ashish.Gupta@cavium.com>
>Subject: RE: [PATCH v2 3/5] compress/zlib: add xform and stream create support
>
>External Email
>
>> -----Original Message-----
>> From: Shally Verma [mailto:shally.verma@caviumnetworks.com]
>> Sent: Monday, July 2, 2018 5:57 PM
>> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>> Cc: dev@dpdk.org; pathreya@caviumnetworks.com;
>> mchalla@caviumnetworks.com; Sunila Sahu <ssahu@caviumnetworks.com>;
>> Sunila Sahu <sunila.sahu@caviumnetworks.com>; Ashish Gupta
>> <ashish.gupta@caviumnetworks.com>
>> Subject: [PATCH v2 3/5] compress/zlib: add xform and stream create support
>
>Retitle to "compress/zlib: support xform and stream creation"
>
>About stateful, since it looks like it is not supported for the moment,
>I think stream_create/stream_free functions should fail or should not be implemented.
>
>More comments inline.
>
>>
>> From: Sunila Sahu <ssahu@caviumnetworks.com>
>>
>> Implement private xform and stream create ops
>>
>> Signed-off-by: Sunila Sahu <sunila.sahu@caviumnetworks.com>
>> Signed-off-by: Shally Verma <shally.verma@caviumnetworks.com>
>> Signed-off-by: Ashish Gupta <ashish.gupta@caviumnetworks.com>
>> ---
>>  drivers/compress/zlib/zlib_pmd.c         | 93
>> ++++++++++++++++++++++++++++++++
>>  drivers/compress/zlib/zlib_pmd_ops.c     | 83 ++++++++++++++++++++++++++--
>>  drivers/compress/zlib/zlib_pmd_private.h |  4 ++
>>  3 files changed, 176 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/compress/zlib/zlib_pmd.c b/drivers/compress/zlib/zlib_pmd.c
>> index c4f67bb..7c2614e 100644
>> --- a/drivers/compress/zlib/zlib_pmd.c
>> +++ b/drivers/compress/zlib/zlib_pmd.c
>
>...
>
>> +             case RTE_COMP_HUFFMAN_DYNAMIC:
>> +                     strategy = Z_HUFFMAN_ONLY;
>
>I don't think this is the suitable value for dynamic compression.
>Z_HUFFMAN_ONLY does not do LZ77. I think the strategy for this case is Z_DEFAULT_STRATEGY.
Ya. you right. It will be changed to DEFAULT_STRATEGY.

Thanks
Shally

>
>> +                     break;
>> +             default:
>> +                     ZLIB_PMD_ERR("Compression strategy not
>> supported\n");
>> +                     return -1;
>> +             }
>
>...
>
>> +++ b/drivers/compress/zlib/zlib_pmd_ops.c
>
>...
>
>> +     struct rte_mempool *mp = rte_mempool_lookup(internals->mp_name);
>
>As said in other email, you can directly get the mempool pointer from internals.
>
>> +     if (rte_mempool_get(mp, zstream)) {
>> +             ZLIB_PMD_ERR(
>> +                             "Couldn't get object from session mempool");
>
>This can be in the same line.
>
>...
>
>> +/** Configure private xform */
>> +static int
>> +zlib_pmd_private_xform_create(struct rte_compressdev *dev,
>> +             const struct rte_comp_xform *xform,
>> +             void **private_xform)
>> +{
>> +     int ret = 0;
>> +
>> +     ret = zlib_pmd_stream_create(dev, xform, private_xform);
>> +     return ret;
>
>This can be written like "return zlib_pmd_stream_create(...);
>
>...
>
>> +             .private_xform_create   = zlib_pmd_private_xform_create,
>> +             .private_xform_free             =
>> zlib_pmd_private_xform_free,
>
>Fix indentation here.
>
>>
>> -             .stream_create  = NULL,
>> -             .stream_free    = NULL
>> +             .stream_create  = zlib_pmd_stream_create,
>> +             .stream_free    = zlib_pmd_stream_free
>>  };
  

Patch

diff --git a/drivers/compress/zlib/zlib_pmd.c b/drivers/compress/zlib/zlib_pmd.c
index c4f67bb..7c2614e 100644
--- a/drivers/compress/zlib/zlib_pmd.c
+++ b/drivers/compress/zlib/zlib_pmd.c
@@ -6,6 +6,99 @@ 
 #include <rte_common.h>
 #include "zlib_pmd_private.h"
 
+/** Parse comp xform and set private xform/stream parameters */
+int
+zlib_set_stream_parameters(const struct rte_comp_xform *xform,
+		struct zlib_stream *stream)
+{
+	int strategy, level, wbits;
+	z_stream *strm = &stream->strm;
+
+	/* allocate deflate state */
+	strm->zalloc = Z_NULL;
+	strm->zfree = Z_NULL;
+	strm->opaque = Z_NULL;
+
+	switch (xform->type) {
+	case RTE_COMP_COMPRESS:
+		/** Compression window bits */
+		switch (xform->compress.algo) {
+		case RTE_COMP_ALGO_DEFLATE:
+			wbits = -(xform->compress.window_size);
+			break;
+		default:
+			ZLIB_PMD_ERR("Compression algorithm not supported\n");
+			return -1;
+		}
+		/** Compression Level */
+		switch (xform->compress.level) {
+		case RTE_COMP_LEVEL_PMD_DEFAULT:
+			level = Z_DEFAULT_COMPRESSION;
+			break;
+		case RTE_COMP_LEVEL_NONE:
+			level = Z_NO_COMPRESSION;
+			break;
+		case RTE_COMP_LEVEL_MIN:
+			level = Z_BEST_SPEED;
+			break;
+		case RTE_COMP_LEVEL_MAX:
+			level = Z_BEST_COMPRESSION;
+			break;
+		default:
+			level = xform->compress.level;
+			if (level < RTE_COMP_LEVEL_MIN ||
+					level > RTE_COMP_LEVEL_MAX) {
+				ZLIB_PMD_ERR("Compression level %d "
+						"not supported\n",
+						level);
+				return -1;
+			}
+		}
+		/** Compression strategy */
+		switch (xform->compress.deflate.huffman) {
+		case RTE_COMP_HUFFMAN_DEFAULT:
+			strategy = Z_DEFAULT_STRATEGY;
+			break;
+		case RTE_COMP_HUFFMAN_FIXED:
+			strategy = Z_FIXED;
+			break;
+		case RTE_COMP_HUFFMAN_DYNAMIC:
+			strategy = Z_HUFFMAN_ONLY;
+			break;
+		default:
+			ZLIB_PMD_ERR("Compression strategy not supported\n");
+			return -1;
+		}
+		if (deflateInit2(strm, level,
+					Z_DEFLATED, wbits,
+					DEF_MEM_LEVEL, strategy) != Z_OK) {
+			ZLIB_PMD_ERR("Deflate init failed\n");
+			return -1;
+		}
+	break;
+
+	case RTE_COMP_DECOMPRESS:
+		/** window bits */
+		switch (xform->decompress.algo) {
+		case RTE_COMP_ALGO_DEFLATE:
+			wbits = -(xform->decompress.window_size);
+			break;
+		default:
+			ZLIB_PMD_ERR("Compression algorithm not supported\n");
+			return -1;
+		}
+
+		if (inflateInit2(strm, wbits) != Z_OK) {
+			ZLIB_PMD_ERR("Inflate init failed\n");
+			return -1;
+		}
+		break;
+	default:
+		return -1;
+	}
+	return 0;
+}
+
 static int
 zlib_create(const char *name,
 		struct rte_vdev_device *vdev,
diff --git a/drivers/compress/zlib/zlib_pmd_ops.c b/drivers/compress/zlib/zlib_pmd_ops.c
index 03b6da5..812406b 100644
--- a/drivers/compress/zlib/zlib_pmd_ops.c
+++ b/drivers/compress/zlib/zlib_pmd_ops.c
@@ -212,6 +212,81 @@  zlib_pmd_qp_setup(struct rte_compressdev *dev, uint16_t qp_id,
 	return -1;
 }
 
+/** Configure stream */
+static int
+zlib_pmd_stream_create(struct rte_compressdev *dev,
+		const struct rte_comp_xform *xform,
+		void **zstream)
+{
+	int ret = 0;
+	struct zlib_stream *stream;
+	struct zlib_private *internals = dev->data->dev_private;
+
+	if (xform == NULL) {
+		ZLIB_PMD_ERR("invalid xform struct");
+		return -EINVAL;
+	}
+
+	struct rte_mempool *mp = rte_mempool_lookup(internals->mp_name);
+	if (rte_mempool_get(mp, zstream)) {
+		ZLIB_PMD_ERR(
+				"Couldn't get object from session mempool");
+		return -ENOMEM;
+	}
+	stream = *((struct zlib_stream **)zstream);
+
+	ret = zlib_set_stream_parameters(xform, stream);
+
+	if (ret < 0) {
+		ZLIB_PMD_ERR("failed configure session parameters");
+
+		memset(stream, 0, sizeof(struct zlib_stream));
+		/* Return session to mempool */
+		rte_mempool_put(mp, stream);
+		return ret;
+	}
+
+	return 0;
+}
+
+/** Configure private xform */
+static int
+zlib_pmd_private_xform_create(struct rte_compressdev *dev,
+		const struct rte_comp_xform *xform,
+		void **private_xform)
+{
+	int ret = 0;
+
+	ret = zlib_pmd_stream_create(dev, xform, private_xform);
+	return ret;
+}
+
+/** Clear the memory of stream so it doesn't leave key material behind */
+static int
+zlib_pmd_stream_free(__rte_unused struct rte_compressdev *dev,
+		void *zstream)
+{
+	struct zlib_stream *stream = (struct zlib_stream *)zstream;
+	if (!stream)
+		return -EINVAL;
+
+	stream->free(&stream->strm);
+	/* Zero out the whole structure */
+	memset(stream, 0, sizeof(struct zlib_stream));
+	struct rte_mempool *mp = rte_mempool_from_obj(stream);
+	rte_mempool_put(mp, stream);
+
+	return 0;
+}
+
+/** Clear the memory of stream so it doesn't leave key material behind */
+static int
+zlib_pmd_private_xform_free(struct rte_compressdev *dev,
+		void *private_xform)
+{
+	return zlib_pmd_stream_free(dev, private_xform);
+}
+
 struct rte_compressdev_ops zlib_pmd_ops = {
 		.dev_configure		= zlib_pmd_config,
 		.dev_start		= zlib_pmd_start,
@@ -226,11 +301,11 @@  struct rte_compressdev_ops zlib_pmd_ops = {
 		.queue_pair_setup	= zlib_pmd_qp_setup,
 		.queue_pair_release	= zlib_pmd_qp_release,
 
-		.private_xform_create	= NULL,
-		.private_xform_free		= NULL,
+		.private_xform_create	= zlib_pmd_private_xform_create,
+		.private_xform_free		= zlib_pmd_private_xform_free,
 
-		.stream_create	= NULL,
-		.stream_free	= NULL
+		.stream_create	= zlib_pmd_stream_create,
+		.stream_free	= zlib_pmd_stream_free
 };
 
 struct rte_compressdev_ops *rte_zlib_pmd_ops = &zlib_pmd_ops;
diff --git a/drivers/compress/zlib/zlib_pmd_private.h b/drivers/compress/zlib/zlib_pmd_private.h
index dc83464..cdfa866 100644
--- a/drivers/compress/zlib/zlib_pmd_private.h
+++ b/drivers/compress/zlib/zlib_pmd_private.h
@@ -61,6 +61,10 @@  struct zlib_priv_xform {
 	struct zlib_stream stream;
 } __rte_cache_aligned;
 
+int
+zlib_set_stream_parameters(const struct rte_comp_xform *xform,
+		struct zlib_stream *stream);
+
 /** Device specific operations function pointer structure */
 extern struct rte_compressdev_ops *rte_zlib_pmd_ops;