From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0087.outbound.protection.outlook.com [104.47.1.87]) by dpdk.org (Postfix) with ESMTP id 227315F2F for ; Sat, 10 Mar 2018 02:25:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RrInTk2xAEYNbbiobq+rgbkdsp6CkbEuzNe9RGWd1Y0=; b=K1EwIaq2FtSjRRhxyn6QO2jmPFyFeu/dRNubBL2zdA53ht2uqJ8IhxD3px8w4U8doFZ9zV54+FqfZZiq+Uy7xiFJuwKuTrFT0m4MS+MzmgtX3e/F5oW/s2bkdmOqyFq5lUR8r/vFI6VVlO8cl+HyftUYSqvXCIHjDVrtrCusLSA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=yskoh@mellanox.com; Received: from mellanox.com (209.116.155.178) by VI1PR0501MB2045.eurprd05.prod.outlook.com (2603:10a6:800:36::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Sat, 10 Mar 2018 01:25:48 +0000 From: Yongseok Koh To: wenzhuo.lu@intel.com, jingjing.wu@intel.com, adrien.mazarguil@6wind.com, nelio.laranjeiro@6wind.com, olivier.matz@6wind.com Cc: dev@dpdk.org, Yongseok Koh Date: Fri, 9 Mar 2018 17:25:27 -0800 Message-Id: <20180310012532.15809-2-yskoh@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180310012532.15809-1-yskoh@mellanox.com> References: <20180310012532.15809-1-yskoh@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [209.116.155.178] X-ClientProxiedBy: CO2PR07CA0068.namprd07.prod.outlook.com (2603:10b6:100::36) To VI1PR0501MB2045.eurprd05.prod.outlook.com (2603:10a6:800:36::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9efa9e39-1518-4076-314e-08d58625dbff X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2045; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2045; 3:hkSvn9QWo2SwKGam8udk8tzFn2rCavmgRRi5GHK6TzWCgZfr7PwyW3nV+7UbkGpfBk+4m65ZkPXJCPCd0oz7jJsNJLYgOM4HeJpH9Pz1YDkRo4cW9El1S4IqSuPJ0gOqXEhA85Jhmr494UoJ+A9eplRvyj5Nj4yxTosrnf3bGRPQacwd3KHoq55aZqL8y5zNJBn9GIPcSdq8K2uEJNGY2mCJV8lZUSS/FUG2XtBq0JTAn1gsxiHyNIlePXFBH/uT; 25:NOQGbfvospD2csvZNdbfsFULRjKx2fEkiqAJvJC+rY8u4qCZZqUENuSFWOmxm3wKHQm/mF4XtGpkQZ9YuhQhb52Velv3Qts/fNRvLyMe6GEhjbXH6k+BFj0P/91Pzz9IXTBFmeG4fJoQRH16dYneLOnWBypEZ1J5BCRPYfslQu/gp6STybiEqQz6wJdw9jyu/gDpKDjXpWAd5ocoe0Vnvx3L6ARFEIo5ic5Oq6vs2HtiH3CRzoB/5RqUvy8/C+gVjd9uPmoKsM3nslOWPlwRlTMxA957Gic+zPkxOR1SSlqDSyZ7NLptT1TsmH3bRp3JIG8tE3Rlf2KKeomRSqsyCw==; 31:X0h/xbs2qB20z6wbxdZ7iDZSg1l8ssyAg1TeJWBFvOOBDUtwwKii2kko5C1vxtbutPooLfsZDXAy9KeM08J3NbigbVeEwmb5Y7TE7QZEEsdC/7cqTtV1gO7emvcHpYKBM/mHv5u1Qmy5gYzTa0i1c76uQ+rYG73+k8GOfto2Fiez6ogBTmL9LXTnkAxK073+Op2HUnrEVCL73iDTUO/W1xfOt8xhLi6v9z34bwtuymo= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2045: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2045; 20:3n3RxMSE2vLuuqpefI9n60ZLlgbUCS6lvgdhAxFCLuORIRRB02LDQubo+nkPXKhog5jGZqW3RdzxVOntwTrz20e60csoEO8TNZ90KAm9FxVG4gv2Vf4GDh11yF1RYR/cXTqT+qWarwZM3RKhXOOAXeAhVzNydvqT0Nkhxb9V27c8KxlYRNm5FJQQOrVmbyMght1/ytPEvqcrXztIU9iXF0so/3U9pgi+rcOqDZ8xoqWpBLkIaOox6/FHJej1DXUIGP60LPW2PFWw4I8H4ut/NLVCCqL1lNGmeHssIziyaS3R16x1xc8+aIDN1ZO8kdGNZF4v3GPUTP54/pbXFa0Q2GrYuKpU1S1YJr/pDbJxC71g0vjuKKDrEMyjDP4HPeoAgqCB54ho7qBr4w9Q7TIWi29Wx2szGSdWGj9Dip2mWu7qXqKSU47jIBQb5zMxqA0Imz+WXD7LhALKBo5kD216/Z9NdK+Q1BHylsRqNZPjdYonY5yCK+3eIxCwvOaUexYC; 4:HciRLX/hewsLcyJ9HWe42c0oJIJLk2YoBGnAX6pVU94kfjtlLTheprkON3zcUOjaTvGC1R2w+ZA/oH4Kw6SlfBNXGrs9rU8Q2ueo0uLU8iD6U0043fhxOX8O9VPqei347tBBHlzmb+6QMv2GADWuSyJ2y73vhhQI7RkPJXrZz6OpAYR1kGAJHM5L9FYA6Y/9dQnwFEI/eIYI6dq1lCG/cAmyJnpFxhhcXcOS+5Nb0WbCrIlVaH5cQqan7ZYFfsW9d9NfEO8XP2hoEQ9g3oVxew== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231220)(944501244)(52105095)(6055026)(6041310)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR0501MB2045; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2045; X-Forefront-PRVS: 06070568C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(346002)(396003)(376002)(366004)(39860400002)(189003)(199004)(7736002)(5660300001)(97736004)(7696005)(51416003)(36756003)(6666003)(478600001)(76176011)(107886003)(86362001)(8676002)(48376002)(55016002)(50466002)(59450400001)(52116002)(53936002)(4326008)(69596002)(25786009)(21086003)(105586002)(6116002)(3846002)(66066001)(386003)(2906002)(16586007)(186003)(50226002)(47776003)(68736007)(305945005)(5890100001)(8936002)(316002)(106356001)(26005)(1076002)(2950100002)(81156014)(16526019)(81166006); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2045; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2045; 23:HPAD3Cip0KWe6X7XuhJUyzXUby0v+48U53jYow4?= =?us-ascii?Q?Ao38Wlm+GNcV6xILCFZnO2tJ4ew+NAUoHooXYQIg8M6glDlQoKa7PEq0rhV0?= =?us-ascii?Q?dOI/uwr/OrqYa1uqm/nvSs005xYfKabk1USe+oWPe2PLrPIV5MkllMTwgxv3?= =?us-ascii?Q?J3pRdpkDBfr/1mCpxsJb1MI+MkBs099balJIEW6KOcQsD4D8h29tKlCVpAZR?= =?us-ascii?Q?A21tTeqSdiC/AgHtmizeuv9D7K0abkLZxQ+HfUkC/bYH69NuAWFQvl9FuPH6?= =?us-ascii?Q?AmSfCMMsMoX5ta7Luqn0X8ARnbNm9bpJh5ETwb1RebCnWnhQuO/prnIafXDs?= =?us-ascii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ft+DWA4xGmfZMYQTqwT2/puGItj4tqa7GPgvHV/bGdYHuOryVj8zXJGL/V7c7umAIUMncbJJfRCHRyysqiXBDhN7mUGM4b6u12MxSNaZBwJKp SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2018 01:25:48.9232 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9efa9e39-1518-4076-314e-08d58625dbff X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2045 Subject: [dpdk-dev] [PATCH v1 1/6] mbuf: add buffer offset field for flexible indirection 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: Sat, 10 Mar 2018 01:25:52 -0000 When attaching a mbuf, indirect mbuf has to point to start of buffer of direct mbuf. By adding buf_off field to rte_mbuf, this becomes more flexible. Indirect mbuf can point to any part of direct mbuf by calling rte_pktmbuf_attach_at(). Possible use-cases could be: - If a packet has multiple layers of encapsulation, multiple indirect buffers can reference different layers of the encapsulated packet. - A large direct mbuf can even contain multiple packets in series and each packet can be referenced by multiple mbuf indirections. Signed-off-by: Yongseok Koh --- lib/librte_mbuf/rte_mbuf.h | 158 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 62740254d..053db32d0 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -559,6 +559,11 @@ struct rte_mbuf { }; }; + /** Buffer offset of direct mbuf if attached. Indirect mbuf can point to + * any part of direct mbuf. + */ + uint16_t buf_off; + /** Size of the application private data. In case of an indirect * mbuf, it stores the direct mbuf private data size. */ uint16_t priv_size; @@ -671,7 +676,9 @@ rte_mbuf_data_dma_addr_default(const struct rte_mbuf *mb) static inline struct rte_mbuf * rte_mbuf_from_indirect(struct rte_mbuf *mi) { - return (struct rte_mbuf *)RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size); + return (struct rte_mbuf *) + RTE_PTR_SUB(mi->buf_addr, + sizeof(*mi) + mi->priv_size + mi->buf_off); } /** @@ -1281,6 +1288,98 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool, } /** + * Adjust tailroom of indirect mbuf. If offset is positive, enlarge the + * tailroom of the mbuf. If negative, shrink the tailroom. + * + * If length is out of range, then the function will fail and return -1, + * without modifying the indirect mbuf. + * + * @param mi + * The indirect packet mbuf. + * @param len + * The amount of length to adjust (in bytes). + * @return + * - 0: On success. + * - -1: On error. + */ +static inline int rte_pktmbuf_adj_indirect_tail(struct rte_mbuf *mi, int len) +{ + struct rte_mbuf *md; + uint16_t tailroom; + int delta; + + RTE_ASSERT(RTE_MBUF_INDIRECT(mi)); + + md = rte_mbuf_from_indirect(mi); + if (unlikely(mi->buf_len + len <= 0 || + mi->buf_off + mi->buf_len + len >= md->buf_len)) + return -1; + + mi->buf_len += len; + + tailroom = mi->buf_len - mi->data_off - mi->data_len; + delta = tailroom + len; + if (delta > 0) { + /* Adjust tailroom */ + delta = 0; + } else if (delta + mi->data_len < 0) { + /* No data */ + mi->data_off += delta + mi->data_len; + delta = mi->data_len; + } + mi->data_len += delta; + mi->pkt_len += delta; + return 0; +} + +/** + * Shift buffer reference of indirect mbuf. If offset is positive, push + * the offset of the mbuf. If negative, pull the offset. + * + * Returns a pointer to the start address of the new data area. If offset + * is out of range, then the function will fail and return NULL, without + * modifying the indirect mbuf. + * + * @param mi + * The indirect packet mbuf. + * @param off + * The amount of offset to adjust (in bytes). + * @return + * A pointer to the new start of the data. + */ +static inline char *rte_pktmbuf_adj_indirect_head(struct rte_mbuf *mi, int off) +{ + int delta; + + RTE_ASSERT(RTE_MBUF_INDIRECT(mi)); + + if (unlikely(off >= mi->buf_len || mi->buf_off + off < 0)) + return NULL; + + mi->buf_iova += off; + mi->buf_addr = (char *)mi->buf_addr + off; + mi->buf_len -= off; + mi->buf_off += off; + + delta = off - mi->data_off; + if (delta < 0) { + /* Adjust headroom */ + mi->data_off -= off; + delta = 0; + } else if (delta < mi->data_len) { + /* No headroom */ + mi->data_off = 0; + } else { + /* No data */ + mi->data_off = 0; + delta = mi->data_len; + } + mi->data_len -= delta; + mi->pkt_len -= delta; + return (char *)mi->buf_addr + mi->data_off; +} + +/** * Attach packet mbuf to another packet mbuf. * * After attachment we refer the mbuf we attached as 'indirect', @@ -1315,6 +1414,7 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) mi->buf_iova = m->buf_iova; mi->buf_addr = m->buf_addr; mi->buf_len = m->buf_len; + mi->buf_off = 0; mi->data_off = m->data_off; mi->data_len = m->data_len; @@ -1336,6 +1436,62 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) } /** + * Attach packet mbuf to another packet mbuf pointing by given offset. + * + * After attachment we refer the mbuf we attached as 'indirect', + * while mbuf we attached to as 'direct'. + * + * The indirect mbuf can reference to anywhere in the buffer of the direct + * mbuf by the given offset. And the indirect mbuf is also be trimmed by + * the given buffer length. + * + * As a result, if a direct mbuf has multiple layers of encapsulation, + * multiple indirect buffers can reference different layers of the packet. + * Or, a large direct mbuf can even contain multiple packets in series and + * each packet can be referenced by multiple mbuf indirections. + * + * Returns a pointer to the start address of the new data area. If offset + * or buffer length is out of range, then the function will fail and return + * NULL, without attaching the mbuf. + * + * @param mi + * The indirect packet mbuf. + * @param m + * The packet mbuf we're attaching to. + * @param off + * The amount of offset to push (in bytes). + * @param buf_len + * The buffer length of the indirect mbuf (in bytes). + * @return + * A pointer to the new start of the data. + */ +static inline char *rte_pktmbuf_attach_at(struct rte_mbuf *mi, + struct rte_mbuf *m, uint16_t off, uint16_t buf_len) +{ + struct rte_mbuf *md; + char *ret; + + if (RTE_MBUF_DIRECT(m)) + md = m; + else + md = rte_mbuf_from_indirect(m); + + if (off + buf_len > md->buf_len) + return NULL; + + rte_pktmbuf_attach(mi, m); + + /* Push reference of indirect mbuf */ + ret = rte_pktmbuf_adj_indirect_head(mi, off); + RTE_ASSERT(ret != NULL); + + /* Trim reference of indirect mbuf */ + rte_pktmbuf_adj_indirect_tail(mi, off + buf_len - md->buf_len); + + return ret; +} + +/** * Detach an indirect packet mbuf. * * - restore original mbuf address and length values. -- 2.11.0