From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0054.outbound.protection.outlook.com [104.47.33.54]) by dpdk.org (Postfix) with ESMTP id 7D6491B989 for ; Tue, 15 May 2018 12:33:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=z/Ugr5BVjvIS0ixmxP4ZzvL5ZAgkiD3Fv3i4jDgUKTQ=; b=fyOWO7PuXskny5CHFWvE/MQ7pTnpl2Z6H9lQ2qjWZdbe+E030oqzGqgOgBQEOfCjCV4t9JTvdswKHs9pYgnu7Dp16kH4TiSib2sFxUojekRLbPFsZjI6XliN7gOKQVA6WsqBxY0J/P1mOZqGdkddy19XZjVkV8bq8qzwuBZFw5g= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by SN4PR0701MB3646.namprd07.prod.outlook.com (2603:10b6:803:4d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Tue, 15 May 2018 10:33:04 +0000 From: Shally Verma To: pablo.de.lara.guarch@intel.com Cc: fiona.trahe@intel.com, dev@dpdk.org, pathreay@caviumnetworks.com, Sunila Sahu , Ashish Gupta Date: Tue, 15 May 2018 16:02:24 +0530 Message-Id: <1526380346-7386-5-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526380346-7386-1-git-send-email-shally.verma@caviumnetworks.com> References: <1526380346-7386-1-git-send-email-shally.verma@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BMXPR01CA0033.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::19) To SN4PR0701MB3646.namprd07.prod.outlook.com (2603:10b6:803:4d::12) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:SN4PR0701MB3646; X-Microsoft-Exchange-Diagnostics: 1; SN4PR0701MB3646; 3:We4Xk3ujmxAJCM9ippApK7giVv79ViLPFL0ZVT28br6AeLvcirR/AYndmyJhgensgvW4RmK9iLL379BNpl4d0JdlBD/fKSBgjc4qIuy7ZmCeTOGYk+CO/dZ0X7BGLxQwt+ZMZfQIYZf/URl/zCVoM1gW94UOav6pPrIzK1kWD0oVJjNj98CTU3N838YseBejbZfFOgR4LZeu7px2GSRbZqdXxEDQPzormjMNenFeucfUYZ+JBfQ0iXBFrmQBwaMf; 25:CQsUTaNFFdYBC5+wcPdW6IlHKUgD+ukItrf+ezI6cTAeKjJ2h4HPXTJPG/k7xSbH7m1REXMDpNqbLGLo9Z+SgctctMQXFvdpjlo8zBaXBxEeqIENL8ZrmrJ9J92i6bWLKVtxR8dWG38Ulylw5+DPLAqVTRuYepjastgv/t8Drfo1d9WLBglpIYNeTNeEQ1bC5P2CT458wVA6qWqzs1+WUlEvHDk5PUmYu+Q2h6aAeaKCkRsiNpH0gdcyWxwwe3URQ9A6fDqu8aAVDb+o+ZTwJ+8uwz9zixEO1q7JK80/r7DvQ74CjIaniiZ9xkZm7QkOJr2CmD+AYbxgZQ68awyNMg==; 31:+7DFUxaTSSEY6//XEPtLT+oNc+zk4XfYNGZ+cLIn+n8aWznZD0IraGIP4NPJvuHBjMqT/e5hTUc4KMpLWOujCq2t3Dnse2sRNQoh81mMAUxMhqW77QYp9Jml4GyL+3CUEd/gxNCvG130OmYyq5UyDmQEG0RNy9sdRcV5jvK+JTs1ev/EXtnvuDzQd+0ZIgFVAADVulOamaKJTmU9EYi6rjHEqAsN2tkVswNF5O/+TIA= X-MS-TrafficTypeDiagnostic: SN4PR0701MB3646: X-Microsoft-Exchange-Diagnostics: 1; SN4PR0701MB3646; 20:YPzUa6KcyzT2p8f+baOvALX6Lx4f4SFiwP/I2XwzP/YnOZUUsXDg70a5c3dJDKlk2Ms+sMs0HFM7sE1M3MBaXo6FCVfB3Ovnvg/r8UO20E3x/3A/IGvSqZaQr0cYJdaPyxyF4cPGwvBNWgPZOHajd1pJf7koS8BzHwO06WwnpGVGWS4TVrAiW7JtwPOj6zeRckas3Hfcn/qvvkh69a+LOmxBG4pL1W7k+H1O2wWVwcsAqD82mncDW9n1ghAzw0Q/09S/tz6k8f8mpQ/wiYunDPJ6NCo2NA1OJv6d4sLF71qKMuCttv7Cj+01vRxXmyYK1nKpTuIywCW34Bwv4lgi8Yms26aHCfzu93vM8P4VMhsx6K3pA6L/OKRvxJAnssZ1PX1wth2yJwLesz7kb9luGB+v/i/rozbSkvfqU8OowfGjMrgbQTbbA8hUs8uBmz3VQ3lvOxrvPC00zYJuNfgkImEkygNS2ezfxMKH8H4YA2U4wwyUdMdL0I8RfaS5VkvT3P48Zdf6bTu8P3Rvf25uC02ZPodsAC7rb6NkVgnNbnAxumOaSyXHnNyjaUDvKJXCpUhzCbJ/4A0tAfrLz74x7+enROx083p9SyizBVlMJTk=; 4:/+S1TtWdTjPwJhlLYBNFAC9nkpAWVUQqfILT6Ie8wPEWaKUmt80uogDBTEcKnNgVMpev0D96prHdPApf7mBUuLy3S0I9Ph4gcVyV0uGxoWnrEvAHEDd1ilW9vLIksoz9G+65sejQFlyi631+XMaV3d2BnzPY6Fw8P7+SGn5aOnggMutJEJ4mL4zzNwpiecuedkeYQ59chiawn3/mD4yWPD+w76IN1bpQlX8ONdN6BG9VIKZRWu8SC1tl+LP7flrEyFu8goL3g7JVVGIPuBn4yQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011); SRVR:SN4PR0701MB3646; BCL:0; PCL:0; RULEID:; SRVR:SN4PR0701MB3646; X-Forefront-PRVS: 0673F5BE31 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(376002)(366004)(396003)(346002)(189003)(199004)(478600001)(486006)(55236004)(44832011)(16586007)(54906003)(316002)(47776003)(2906002)(59450400001)(6506007)(386003)(8936002)(66066001)(6486002)(72206003)(6116002)(3846002)(25786009)(97736004)(5660300001)(42882007)(50226002)(36756003)(8676002)(48376002)(53416004)(52116002)(107886003)(26005)(50466002)(2616005)(81156014)(105586002)(81166006)(2361001)(53936002)(6666003)(6916009)(4326008)(16526019)(68736007)(476003)(446003)(956004)(106356001)(76176011)(186003)(7736002)(2351001)(69596002)(6512007)(305945005)(51416003)(11346002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN4PR0701MB3646; H:hyd1sverma-dt.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN4PR0701MB3646; 23:S9Tuuz6T4zZHWVU9BtbUp1XuKF+DlxBVkIRXEoL?= =?us-ascii?Q?14fmZs2il4lGMta2esECik82khqHkVFY2f1hjRdQGktTSQHbZU7naqF2+jNi?= =?us-ascii?Q?Ro2wAXteivLIoL4LIfG7AHFT1YWm2+1fGcuekFR+YQWQD9Mp6heeHsPcw/Fo?= =?us-ascii?Q?OP+dfWcD8HDRun9VZCKGsWWlahbvcR9IUSPkAgn7q6wqYtApbBES/ZfIbuDe?= =?us-ascii?Q?kHZ0zgQTn5f/VcC1JNiHACG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SVcKRts+KFweezNmnN2Snch78VdwWBxpXeHNuzuIwFgQ+Ii+gbls1XsZCXm5L5HSXivnZkNogAjku/lvarm+59DfIsWjfvUd77aJga10D8tahu8D3qlmu5wlk7nr0r9Dyfze/PZzbtu9zNU/0Eqy8mtJQgiOf0hxbkLIQ=; 24:XoZmv8UeWG0MhJSvzBNJf4LALgfK+XhDtedCnmobbjRNaIWlkPqO8H88FVpxBbNZkCiRQECRS9+OOgTUC5xt2yumk6dqIyPZu2tudTdcmZA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN4PR0701MB3646; 7:m8gGTkR4jmEr7nubaUSTGpoEB4cFkMUgsA760oiFfYJZiugjqBb+E6x1sZ4qmp2Tan+WmItvMzq/IyIxYGftxUqplLpXxTcngsPe8Xwq+CZRpC/6gFuDQqxb7fkMchSsJKkxI1Tkou+2l8CEJOQh0j0aIUvs6q3qAQkWYs+e3rThLkz9n6kj2WS04YtdKTJxdf8gNqUsoE4jFvuf6408QevVLc8zUMIV9mbWWF8u+LlmaN3Q3JFwzxVrwG1V5Y2S X-MS-Office365-Filtering-Correlation-Id: 5c5fc757-d39a-4658-1b0c-08d5ba4f3f61 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2018 10:33:04.7866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c5fc757-d39a-4658-1b0c-08d5ba4f3f61 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR0701MB3646 Subject: [dpdk-dev] [PATCH v1 4/6] compress/zlib: add enq deq apis X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 May 2018 10:33:09 -0000 implement enqueue and dequeue apis Signed-off-by: Sunila Sahu Signed-off-by: Shally Verma Signed-off-by: Ashish Gupta --- drivers/compress/meson.build | 2 +- drivers/compress/zlib/meson.build | 11 ++ drivers/compress/zlib/zlib_pmd.c | 275 +++++++++++++++++++++++++++++++++++++- 3 files changed, 286 insertions(+), 2 deletions(-) diff --git a/drivers/compress/meson.build b/drivers/compress/meson.build index fb136e1..e4d5e5c 100644 --- a/drivers/compress/meson.build +++ b/drivers/compress/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Intel Corporation -drivers = ['isal'] +drivers = ['isal','zlib'] std_deps = ['compressdev'] # compressdev pulls in all other needed deps config_flag_fmt = 'RTE_LIBRTE_@0@_PMD' diff --git a/drivers/compress/zlib/meson.build b/drivers/compress/zlib/meson.build new file mode 100644 index 0000000..d66de95 --- /dev/null +++ b/drivers/compress/zlib/meson.build @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2018 Cavium Networks + +dep = dependency('zlib', required: false) +if not dep.found() + build = false +endif +deps += 'bus_vdev' +sources = files('zlib_pmd.c', 'zlib_pmd_ops.c') +ext_deps += dep +pkgconfig_extra_libs += '-lz' diff --git a/drivers/compress/zlib/zlib_pmd.c b/drivers/compress/zlib/zlib_pmd.c index 3dc71ec..e2681a7 100644 --- a/drivers/compress/zlib/zlib_pmd.c +++ b/drivers/compress/zlib/zlib_pmd.c @@ -17,7 +17,239 @@ #include "zlib_pmd_private.h" static uint8_t compressdev_driver_id; -int zlib_logtype_driver; + +/** compute the next mbuf in list and assign dst buffer and dlen, + * set op->status to appropriate flag if we run out of mbuf + */ +#define COMPUTE_DST_BUF(mbuf, dst, dlen) \ + ((mbuf = mbuf->next) ? \ + (dst = rte_pktmbuf_mtod(mbuf, uint8_t *)), \ + dlen = rte_pktmbuf_data_len(mbuf) : \ + !(op->status = \ + ((op->op_type == RTE_COMP_OP_STATELESS) ? \ + RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED : \ + RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE))) + +static void +process_zlib_deflate(struct rte_comp_op *op, z_stream *strm) +{ + int ret, flush, fin_flush; + uint8_t *src, *dst; + uint32_t sl, dl, have; + struct rte_mbuf *mbuf_src = op->m_src; + struct rte_mbuf *mbuf_dst = op->m_dst; + + src = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *, op->src.offset); + + sl = rte_pktmbuf_data_len(mbuf_src) - op->src.offset; + + dst = rte_pktmbuf_mtod_offset(mbuf_dst, unsigned char *, + op->dst.offset); + + dl = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset; + + if (unlikely(!src || !dst || !strm)) { + op->status = RTE_COMP_OP_STATUS_INVALID_ARGS; + ZLIB_LOG_ERR("\nInvalid source or destination buffers"); + return; + } + switch (op->flush_flag) { + case RTE_COMP_FLUSH_NONE: + fin_flush = Z_NO_FLUSH; + break; + case RTE_COMP_FLUSH_SYNC: + fin_flush = Z_SYNC_FLUSH; + break; + case RTE_COMP_FLUSH_FULL: + fin_flush = Z_FULL_FLUSH; + break; + case RTE_COMP_FLUSH_FINAL: + fin_flush = Z_FINISH; + break; + default: + op->status = RTE_COMP_OP_STATUS_ERROR; + goto def_end; + } + if (op->src.length <= sl) { + sl = op->src.length; + flush = fin_flush; + } else { + /* if there're more than one mbufs in input, + * process intermediate with NO_FLUSH + */ + flush = Z_NO_FLUSH; + } + /* initialize status to SUCCESS */ + op->status = RTE_COMP_OP_STATUS_SUCCESS; + + do { + /* Update z_stream with the inputs provided by application */ + strm->next_in = src; + strm->avail_in = sl; + + do { + strm->avail_out = dl; + strm->next_out = dst; + ret = deflate(strm, flush); + if (unlikely(ret == Z_STREAM_ERROR)) { + /* error return, do not process further */ + op->status = RTE_COMP_OP_STATUS_ERROR; + goto def_end; + } + /* Update op stats */ + op->produced += dl - strm->avail_out; + op->consumed += sl - strm->avail_in; + /* Break if Z_STREAM_END is encountered or dst mbuf gets over */ + } while (!(ret == Z_STREAM_END) && (strm->avail_out == 0) && + COMPUTE_DST_BUF(mbuf_dst, dst, dl)); + + /** Compress till the end of compressed blocks provided + * or till Z_FINISH + * Exit if op->status is not SUCCESS. + */ + if ((op->status != RTE_COMP_OP_STATUS_SUCCESS) || + (ret == Z_STREAM_END) || + op->consumed == op->src.length) + goto def_end; + + /** Update last output buffer with respect to availed space */ + have = dl - strm->avail_out; + dst += have; + dl = strm->avail_out; + /** Update source buffer to next mbuf*/ + mbuf_src = mbuf_src->next; + src = rte_pktmbuf_mtod(mbuf_src, uint8_t *); + sl = rte_pktmbuf_data_len(mbuf_src); + + /** Last block to be compressed + * Update flush with value provided by app for last block, + * For stateless flush should be always Z_FINISH + */ + + if ((op->src.length - op->consumed) <= sl) { + sl = (op->src.length - op->consumed); + flush = fin_flush; + } + + } while (1); +def_end: + if (op->op_type == RTE_COMP_OP_STATELESS) + deflateReset(strm); +} + +static void +process_zlib_inflate(struct rte_comp_op *op, z_stream *strm) +{ + int ret, flush; + uint8_t *src, *dst; + uint32_t sl, dl, have; + struct rte_mbuf *mbuf_src = op->m_src; + struct rte_mbuf *mbuf_dst = op->m_dst; + + src = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *, op->src.offset); + + sl = rte_pktmbuf_data_len(mbuf_src) - op->src.offset; + + dst = rte_pktmbuf_mtod_offset(mbuf_dst, unsigned char *, + op->dst.offset); + + dl = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset; + + if (unlikely(!src || !dst || !strm)) { + op->status = RTE_COMP_OP_STATUS_INVALID_ARGS; + ZLIB_LOG_ERR("\nInvalid source or destination buffers"); + return; + } + if (op->src.length <= sl) + sl = op->src.length; + + /** Ignoring flush value provided from application for decompression */ + flush = Z_NO_FLUSH; + /* initialize status to SUCCESS */ + op->status = RTE_COMP_OP_STATUS_SUCCESS; + + do { + /** Update z_stream with the inputs provided by application */ + strm->avail_in = sl; + strm->next_in = src; + do { + strm->avail_out = dl; + strm->next_out = dst; + + ret = inflate(strm, flush); + + switch (ret) { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; /* and fall through */ + case Z_DATA_ERROR: + case Z_MEM_ERROR: + case Z_STREAM_ERROR: + op->status = RTE_COMP_OP_STATUS_ERROR; + goto inf_end; + default: + /** Update op stats */ + op->produced += dl - strm->avail_out; + op->consumed += sl - strm->avail_in; + + } + /* Break if Z_STREAM_END is encountered or dst mbuf gets over */ + } while (!(ret == Z_STREAM_END) && (strm->avail_out == 0) && + COMPUTE_DST_BUF(mbuf_dst, dst, dl)); + + /** Compress till the end of compressed blocks provided + * or till Z_STREAM_END. + * Exit if op->status is not SUCCESS. + */ + if ((op->status != RTE_COMP_OP_STATUS_SUCCESS) || + (ret == Z_STREAM_END) || + op->consumed == op->src.length) { + goto inf_end; + } + /** Adjust previous output buffer with respect to avail_out */ + have = dl - strm->avail_out; + dst += have; + dl = strm->avail_out; + /** Read next input buffer to be processed */ + mbuf_src = mbuf_src->next; + src = rte_pktmbuf_mtod(mbuf_src, uint8_t *); + sl = rte_pktmbuf_data_len(mbuf_src); + if ((op->src.length - op->consumed) < sl) + sl = (op->src.length - op->consumed); + } while (1); +inf_end: + if (op->op_type == RTE_COMP_OP_STATELESS) + inflateReset(strm); +} + +/** Process comp operation for mbuf */ +static inline int +process_zlib_op(struct zlib_qp *qp, struct rte_comp_op *op) +{ + struct zlib_stream *stream; + + if (op->src.offset > rte_pktmbuf_data_len(op->m_src) || + op->dst.offset > rte_pktmbuf_data_len(op->m_dst)) { + op->status = RTE_COMP_OP_STATUS_INVALID_ARGS; + ZLIB_LOG_ERR("\nInvalid source or destination buffers"); + goto comp_err; + } + + if (op->op_type == RTE_COMP_OP_STATELESS) + stream = &((struct zlib_priv_xform *)op->private_xform)->stream; + else if (op->op_type == RTE_COMP_OP_STATEFUL) + stream = (struct zlib_stream *)op->stream; + else { + op->status = RTE_COMP_OP_STATUS_INVALID_ARGS; + ZLIB_LOG_ERR("\nInvalid operation type"); + goto comp_err; + } + stream->comp(op, &stream->strm); +comp_err: + /* whatever is out of op, put it into completion queue with + * its status + */ + return rte_ring_enqueue(qp->processed_pkts, (void *)op); +} /** Parse comp xform and set private xform/Stream parameters */ int @@ -118,6 +350,43 @@ zlib_set_stream_parameters(const struct rte_comp_xform *xform, return 0; } +static uint16_t +zlib_pmd_enqueue_burst(void *queue_pair, + struct rte_comp_op **ops, uint16_t nb_ops) +{ + struct zlib_qp *qp = queue_pair; + int ret, i; + int enqd = 0; + for (i = 0; i < nb_ops; i++) { + ret = process_zlib_op(qp, ops[i]); + if (unlikely(ret < 0)) { + /* increment count if failed to push to completion + * queue + */ + qp->qp_stats.enqueue_err_count++; + } else { + qp->qp_stats.enqueued_count++; + enqd++; + } + } + return enqd; +} + +static uint16_t +zlib_pmd_dequeue_burst(void *queue_pair, + struct rte_comp_op **ops, uint16_t nb_ops) +{ + struct zlib_qp *qp = queue_pair; + + unsigned int nb_dequeued = 0; + + nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts, + (void **)ops, nb_ops, NULL); + qp->qp_stats.dequeued_count += nb_dequeued; + + return nb_dequeued; +} + static int zlib_remove(struct rte_vdev_device *vdev); static int @@ -138,6 +407,10 @@ zlib_create(const char *name, dev->driver_id = compressdev_driver_id; dev->dev_ops = rte_zlib_pmd_ops; + /* register rx/tx burst functions for data path */ + dev->dequeue_burst = zlib_pmd_dequeue_burst; + dev->enqueue_burst = zlib_pmd_enqueue_burst; + dev->feature_flags = 0; dev->feature_flags |= RTE_COMP_FF_SHAREABLE_PRIV_XFORM | RTE_COMP_FF_NONCOMPRESSED_BLOCKS | -- 2.9.5