From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0BF18A32A1 for ; Thu, 24 Oct 2019 09:38:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CF4411D16C; Thu, 24 Oct 2019 09:38:18 +0200 (CEST) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150050.outbound.protection.outlook.com [40.107.15.50]) by dpdk.org (Postfix) with ESMTP id F38111D153 for ; Thu, 24 Oct 2019 09:38:16 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H2vPjqPR8Byemls4FDXw2MXougyGzbdX0hQVVdp6SKLUZrAaz6n6M4uI7nTp601QvAM/SQKH1hqw5mUoazp4lgN6KNljBCJGjDt1TyHbF17ksGTJCb58dGUVNV7lxHIwtzXPJAQNV1psWgPD8ZMKUKsHhrgbfFPK63wKgwHYmB5QZY7Lwq3jh74FjQjXQPWms+yn90TbZmAr7xdlph2+E19qYEMVTLsBLQTKvAAMRBUOOcofbrMS382BTLrJled/rw4U8ZP1b2yQfDDVheuT9kFMXIkKBNDx3/9yBs7heEGSQJJpigfqxlHiMW3HUb9jF2kFvv/niEHUZvsKc094RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1BxqJVJYYbIukglEHX7VAQeXO5Plp2dfCRTWbm3uBE=; b=XzQyB3Qpo5LJuRzaFbnRtHT9BLWfyidrz69hAIdviEWizj7hU31atxYDCIX6BBCejWw8SQw14fKidK7gSfyjEpTmgmhxf5yXs6l4+0dbV8j7jO4cMFelUdTukHev+tMxQ+8xdnJQgptrsMf0IRgtAYxaDPIOZmeh0jzLAy9V/wOItIITzROKHVfDImGBIUabOmLJ3vst6xwGaRGN/LTpwOgeBLgQoaxFxvi4GSDeohSTTESAO4K1g5VwySV+1XxlVtx2ZCdh98OPnHbwLUXNfCzVSFLm9WlEg0fI8/tBo4N2vgd5bvmWcdlKBdJ0dgR0nmUttgjtx6qSeS83z5e0mQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1BxqJVJYYbIukglEHX7VAQeXO5Plp2dfCRTWbm3uBE=; b=TyApJkeLg8PusLHiOKm5u9JU/EnrpxsVXZmXyuQ4t4Xm/M6hvFYBwxS/sAkwOwgsYl7V2NTeaeABbfbSpXXvAuI6UerBAENUzbgWpr5XRKQV4yQ9Rip5rc3UIo/00uMPjaILSIn6n0vlAgrPW9CEva38QjXgQy18DVyhZaiYGDE= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3346.eurprd05.prod.outlook.com (10.171.189.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Thu, 24 Oct 2019 07:38:15 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::edab:529f:d14e:d3b]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::edab:529f:d14e:d3b%7]) with mapi id 15.20.2387.021; Thu, 24 Oct 2019 07:38:15 +0000 From: Slava Ovsiienko To: Olivier Matz , "dev@dpdk.org" CC: Andrew Rybchenko , Bruce Richardson , "Wang, Haiyue" , Jerin Jacob Kollanukkaran , "Wiles, Keith" , "Ananyev, Konstantin" , =?iso-8859-1?Q?Morten_Br=F8rup?= , Stephen Hemminger , Thomas Monjalon Thread-Topic: [dpdk-dev] [PATCH v2] mbuf: support dynamic fields and flags Thread-Index: AQHVhPkkoXxWydYmLkOCWz98AcTfUqdpcPiQ Date: Thu, 24 Oct 2019 07:38:15 +0000 Message-ID: References: <20190710092907.5565-1-olivier.matz@6wind.com> <20191017144219.32708-1-olivier.matz@6wind.com> In-Reply-To: <20191017144219.32708-1-olivier.matz@6wind.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-originating-ip: [95.67.35.250] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b1d2f7a1-ec31-4df6-0dbd-08d7585521aa x-ms-traffictypediagnostic: AM4PR05MB3346: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:205; x-forefront-prvs: 0200DDA8BE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39860400002)(376002)(346002)(136003)(366004)(189003)(199004)(13464003)(6246003)(71200400001)(4326008)(71190400001)(478600001)(316002)(76176011)(9686003)(86362001)(229853002)(55016002)(6436002)(14454004)(30864003)(26005)(81156014)(33656002)(5660300002)(81166006)(52536014)(102836004)(99286004)(110136005)(8936002)(7696005)(54906003)(2501003)(53546011)(6506007)(66066001)(64756008)(66556008)(66476007)(66446008)(305945005)(186003)(7416002)(486006)(256004)(66946007)(2906002)(8676002)(74316002)(5024004)(25786009)(11346002)(3846002)(6116002)(66574012)(76116006)(446003)(7736002)(476003)(14444005)(569006); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3346; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: m03gMBpHY95Jq5dUG7IVocNefhzYNgjUpC69FF0/752Xr7l/YP0NdRTiS6GcGfci3m8ZoiHPrzjaTzt2ad7R9C4TXXSbbRQTBHQ4rRrDX1VmeJn+DdV4whprEfCD3PeDr3ju7q6tNWA2feGoCiv6R4dNFy6THMokml2CYiwtw+WI/n/XJD5W+289WMfqKGxf4U3uGS1P1ODBSgiMAYCkaMx6ixYoVywmmu57egcrI7Cp/z3HQBdBKPtIdzgvsX1BK4Dq/I6Haw7w7Y9a3klgjjkAg2+v3Ag8JIjTyHVYkdwQAWYM2DU4QhDTUgb929fmfn8HmXJSoV3knqkskbnFBksZUegXx+y1ALKCVUhJoq2qQ/rjZqtGP7Q/AV/5do5DcL7SX3NvT8l423eQYG11ufLBUcMiywj0KalwGk76+/BIc7exPQXzFSBq/4EAOjPy x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1d2f7a1-ec31-4df6-0dbd-08d7585521aa X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Oct 2019 07:38:15.4912 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VHL0OxEkIrakCrIhsVgncvFdIhqESRnbEp42CMt/nGVB1Bi7OcyRI9BselOK3ThqZBWSgBxjLSIQqObXeOQiBdD1YylQMJywx2ydx8gUKoY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3346 Subject: Re: [dpdk-dev] [PATCH v2] mbuf: support dynamic fields and flags 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi, Doc building failed, it seems the rte_mbuf_dynfield_copy() description shou= ld be fixed: ./lib/librte_mbuf/rte_mbuf.h:1694: warning: argument 'm_dst' of command @pa= ram is not found in the argument list of rte_mbuf_dynfield_copy(struct rte_= mbuf *mdst, const struct rte_mbuf *msrc) ./lib/librte_mbuf/rte_mbuf.h:1694: warning: argument 'm_src' of command @pa= ram is not found in the argument list of rte_mbuf_dynfield_copy(struct rte_= mbuf *mdst, const struct rte_mbuf *msrc) ./lib/librte_mbuf/rte_mbuf.h:1694: warning: The following parameters of rte= _mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc) are= not documented With best regards, Slava > -----Original Message----- > From: dev On Behalf Of Olivier Matz > Sent: Thursday, October 17, 2019 17:42 > To: dev@dpdk.org > Cc: Andrew Rybchenko ; Bruce Richardson > ; Wang, Haiyue ; > Jerin Jacob Kollanukkaran ; Wiles, Keith > ; Ananyev, Konstantin > ; Morten Br=F8rup > ; Stephen Hemminger > ; Thomas Monjalon > > Subject: [dpdk-dev] [PATCH v2] mbuf: support dynamic fields and flags >=20 > Many features require to store data inside the mbuf. As the room in mbuf > structure is limited, it is not possible to have a field for each feature= . Also, > changing fields in the mbuf structure can break the API or ABI. >=20 > This commit addresses these issues, by enabling the dynamic registration = of > fields or flags: >=20 > - a dynamic field is a named area in the rte_mbuf structure, with a > given size (>=3D 1 byte) and alignment constraint. > - a dynamic flag is a named bit in the rte_mbuf structure. >=20 > The typical use case is a PMD that registers space for an offload feature= , > when the application requests to enable this feature. As the space in mb= uf is > limited, the space should only be reserved if it is going to be used (i.e= when > the application explicitly asks for it). >=20 > The registration can be done at any moment, but it is not possible to > unregister fields or flags for now. >=20 > Signed-off-by: Olivier Matz > Acked-by: Thomas Monjalon > --- >=20 > v2 >=20 > * Rebase on top of master: solve conflict with Stephen's patchset > (packet copy) > * Add new apis to register a dynamic field/flag at a specific place > * Add a dump function (sugg by David) > * Enhance field registration function to select the best offset, keeping > large aligned zones as much as possible (sugg by Konstantin) > * Use a size_t and unsigned int instead of int when relevant > (sugg by Konstantin) > * Use "uint64_t dynfield1[2]" in mbuf instead of 2 uint64_t fields > (sugg by Konstantin) > * Remove unused argument in private function (sugg by Konstantin) > * Fix and simplify locking (sugg by Konstantin) > * Fix minor typo >=20 > rfc -> v1 >=20 > * Rebase on top of master > * Change registration API to use a structure instead of > variables, getting rid of #defines (Stephen's comment) > * Update flag registration to use a similar API as fields. > * Change max name length from 32 to 64 (sugg. by Thomas) > * Enhance API documentation (Haiyue's and Andrew's comments) > * Add a debug log at registration > * Add some words in release note > * Did some performance tests (sugg. by Andrew): > On my platform, reading a dynamic field takes ~3 cycles more > than a static field, and ~2 cycles more for writing. >=20 > app/test/test_mbuf.c | 145 ++++++- > doc/guides/rel_notes/release_19_11.rst | 7 + > lib/librte_mbuf/Makefile | 2 + > lib/librte_mbuf/meson.build | 6 +- > lib/librte_mbuf/rte_mbuf.h | 23 +- > lib/librte_mbuf/rte_mbuf_dyn.c | 548 +++++++++++++++++++++++++ > lib/librte_mbuf/rte_mbuf_dyn.h | 226 ++++++++++ > lib/librte_mbuf/rte_mbuf_version.map | 7 + > 8 files changed, 959 insertions(+), 5 deletions(-) create mode 100644 > lib/librte_mbuf/rte_mbuf_dyn.c create mode 100644 > lib/librte_mbuf/rte_mbuf_dyn.h >=20 > diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index > b9c2b2500..01cafad59 100644 > --- a/app/test/test_mbuf.c > +++ b/app/test/test_mbuf.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include >=20 > #include "test.h" >=20 > @@ -657,7 +658,6 @@ test_attach_from_different_pool(struct > rte_mempool *pktmbuf_pool, > rte_pktmbuf_free(clone2); > return -1; > } > -#undef GOTO_FAIL >=20 > /* > * test allocation and free of mbufs > @@ -1276,6 +1276,143 @@ test_tx_offload(void) > return (v1 =3D=3D v2) ? 0 : -EINVAL; > } >=20 > +static int > +test_mbuf_dyn(struct rte_mempool *pktmbuf_pool) { > + const struct rte_mbuf_dynfield dynfield =3D { > + .name =3D "test-dynfield", > + .size =3D sizeof(uint8_t), > + .align =3D __alignof__(uint8_t), > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynfield dynfield2 =3D { > + .name =3D "test-dynfield2", > + .size =3D sizeof(uint16_t), > + .align =3D __alignof__(uint16_t), > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynfield dynfield3 =3D { > + .name =3D "test-dynfield3", > + .size =3D sizeof(uint8_t), > + .align =3D __alignof__(uint8_t), > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynfield dynfield_fail_big =3D { > + .name =3D "test-dynfield-fail-big", > + .size =3D 256, > + .align =3D 1, > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynfield dynfield_fail_align =3D { > + .name =3D "test-dynfield-fail-align", > + .size =3D 1, > + .align =3D 3, > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynflag dynflag =3D { > + .name =3D "test-dynflag", > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynflag dynflag2 =3D { > + .name =3D "test-dynflag2", > + .flags =3D 0, > + }; > + const struct rte_mbuf_dynflag dynflag3 =3D { > + .name =3D "test-dynflag3", > + .flags =3D 0, > + }; > + struct rte_mbuf *m =3D NULL; > + int offset, offset2, offset3; > + int flag, flag2, flag3; > + int ret; > + > + printf("Test mbuf dynamic fields and flags\n"); > + rte_mbuf_dyn_dump(stdout); > + > + offset =3D rte_mbuf_dynfield_register(&dynfield); > + if (offset =3D=3D -1) > + GOTO_FAIL("failed to register dynamic field, offset=3D%d: %s", > + offset, strerror(errno)); > + > + ret =3D rte_mbuf_dynfield_register(&dynfield); > + if (ret !=3D offset) > + GOTO_FAIL("failed to lookup dynamic field, ret=3D%d: %s", > + ret, strerror(errno)); > + > + offset2 =3D rte_mbuf_dynfield_register(&dynfield2); > + if (offset2 =3D=3D -1 || offset2 =3D=3D offset || (offset2 & 1)) > + GOTO_FAIL("failed to register dynamic field 2, offset2=3D%d: > %s", > + offset2, strerror(errno)); > + > + offset3 =3D rte_mbuf_dynfield_register_offset(&dynfield3, > + offsetof(struct rte_mbuf, dynfield1[1])); > + if (offset3 !=3D offsetof(struct rte_mbuf, dynfield1[1])) > + GOTO_FAIL("failed to register dynamic field 3, offset=3D%d: > %s", > + offset3, strerror(errno)); > + > + printf("dynfield: offset=3D%d, offset2=3D%d, offset3=3D%d\n", > + offset, offset2, offset3); > + > + ret =3D rte_mbuf_dynfield_register(&dynfield_fail_big); > + if (ret !=3D -1) > + GOTO_FAIL("dynamic field creation should fail (too big)"); > + > + ret =3D rte_mbuf_dynfield_register(&dynfield_fail_align); > + if (ret !=3D -1) > + GOTO_FAIL("dynamic field creation should fail (bad > alignment)"); > + > + ret =3D rte_mbuf_dynfield_register_offset(&dynfield_fail_align, > + offsetof(struct rte_mbuf, ol_flags)); > + if (ret !=3D -1) > + GOTO_FAIL("dynamic field creation should fail (not avail)"); > + > + flag =3D rte_mbuf_dynflag_register(&dynflag); > + if (flag =3D=3D -1) > + GOTO_FAIL("failed to register dynamic flag, flag=3D%d: %s", > + flag, strerror(errno)); > + > + ret =3D rte_mbuf_dynflag_register(&dynflag); > + if (ret !=3D flag) > + GOTO_FAIL("failed to lookup dynamic flag, ret=3D%d: %s", > + ret, strerror(errno)); > + > + flag2 =3D rte_mbuf_dynflag_register(&dynflag2); > + if (flag2 =3D=3D -1 || flag2 =3D=3D flag) > + GOTO_FAIL("failed to register dynamic flag 2, flag2=3D%d: %s", > + flag2, strerror(errno)); > + > + flag3 =3D rte_mbuf_dynflag_register_bitnum(&dynflag3, > + rte_bsf64(PKT_LAST_FREE)); > + if (flag3 !=3D rte_bsf64(PKT_LAST_FREE)) > + GOTO_FAIL("failed to register dynamic flag 3, flag2=3D%d: %s", > + flag3, strerror(errno)); > + > + printf("dynflag: flag=3D%d, flag2=3D%d, flag3=3D%d\n", flag, flag2, fla= g3); > + > + /* set, get dynamic field */ > + m =3D rte_pktmbuf_alloc(pktmbuf_pool); > + if (m =3D=3D NULL) > + GOTO_FAIL("Cannot allocate mbuf"); > + > + *RTE_MBUF_DYNFIELD(m, offset, uint8_t *) =3D 1; > + if (*RTE_MBUF_DYNFIELD(m, offset, uint8_t *) !=3D 1) > + GOTO_FAIL("failed to read dynamic field"); > + *RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) =3D 1000; > + if (*RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) !=3D 1000) > + GOTO_FAIL("failed to read dynamic field"); > + > + /* set a dynamic flag */ > + m->ol_flags |=3D (1ULL << flag); > + > + rte_mbuf_dyn_dump(stdout); > + rte_pktmbuf_free(m); > + return 0; > +fail: > + rte_pktmbuf_free(m); > + return -1; > +} > +#undef GOTO_FAIL > + > static int > test_mbuf(void) > { > @@ -1295,6 +1432,12 @@ test_mbuf(void) > goto err; > } >=20 > + /* test registration of dynamic fields and flags */ > + if (test_mbuf_dyn(pktmbuf_pool) < 0) { > + printf("mbuf dynflag test failed\n"); > + goto err; > + } > + > /* create a specific pktmbuf pool with a priv_size !=3D 0 and no data > * room size */ > pktmbuf_pool2 =3D rte_pktmbuf_pool_create("test_pktmbuf_pool2", > diff --git a/doc/guides/rel_notes/release_19_11.rst > b/doc/guides/rel_notes/release_19_11.rst > index 85953b962..9e9c94554 100644 > --- a/doc/guides/rel_notes/release_19_11.rst > +++ b/doc/guides/rel_notes/release_19_11.rst > @@ -21,6 +21,13 @@ DPDK Release 19.11 >=20 > xdg-open build/doc/html/guides/rel_notes/release_19_11.html >=20 > +* **Add support of support dynamic fields and flags in mbuf.** > + > + This new feature adds the ability to dynamically register some room > + for a field or a flag in the mbuf structure. This is typically used > + for specific offload features, where adding a static field or flag in > + the mbuf is not justified. > + >=20 > New Features > ------------ > diff --git a/lib/librte_mbuf/Makefile b/lib/librte_mbuf/Makefile index > c8f6d2689..5a9bcee73 100644 > --- a/lib/librte_mbuf/Makefile > +++ b/lib/librte_mbuf/Makefile > @@ -17,8 +17,10 @@ LIBABIVER :=3D 5 >=20 > # all source are stored in SRCS-y > SRCS-$(CONFIG_RTE_LIBRTE_MBUF) :=3D rte_mbuf.c rte_mbuf_ptype.c > rte_mbuf_pool_ops.c > +SRCS-$(CONFIG_RTE_LIBRTE_MBUF) +=3D rte_mbuf_dyn.c >=20 > # install includes > SYMLINK-$(CONFIG_RTE_LIBRTE_MBUF)-include :=3D rte_mbuf.h > rte_mbuf_ptype.h rte_mbuf_pool_ops.h > +SYMLINK-$(CONFIG_RTE_LIBRTE_MBUF)-include +=3D rte_mbuf_dyn.h >=20 > include $(RTE_SDK)/mk/rte.lib.mk > diff --git a/lib/librte_mbuf/meson.build b/lib/librte_mbuf/meson.build in= dex > 6cc11ebb4..9137e8f26 100644 > --- a/lib/librte_mbuf/meson.build > +++ b/lib/librte_mbuf/meson.build > @@ -2,8 +2,10 @@ > # Copyright(c) 2017 Intel Corporation >=20 > version =3D 5 > -sources =3D files('rte_mbuf.c', 'rte_mbuf_ptype.c', 'rte_mbuf_pool_ops.c= ') - > headers =3D files('rte_mbuf.h', 'rte_mbuf_ptype.h', 'rte_mbuf_pool_ops.h'= ) > +sources =3D files('rte_mbuf.c', 'rte_mbuf_ptype.c', 'rte_mbuf_pool_ops.c= ', > + 'rte_mbuf_dyn.c') > +headers =3D files('rte_mbuf.h', 'rte_mbuf_ptype.h', 'rte_mbuf_pool_ops.h= ', > + 'rte_mbuf_dyn.h') > deps +=3D ['mempool'] >=20 > allow_experimental_apis =3D true > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h inde= x > fb0849ac1..5740b1e93 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -198,9 +198,12 @@ extern "C" { > #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22) > #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22)) >=20 > -/* add new RX flags here */ > +/* add new RX flags here, don't forget to update PKT_FIRST_FREE */ >=20 > -/* add new TX flags here */ > +#define PKT_FIRST_FREE (1ULL << 23) > +#define PKT_LAST_FREE (1ULL << 39) > + > +/* add new TX flags here, don't forget to update PKT_LAST_FREE */ >=20 > /** > * Indicate that the metadata field in the mbuf is in use. > @@ -738,6 +741,7 @@ struct rte_mbuf { > */ > struct rte_mbuf_ext_shared_info *shinfo; >=20 > + uint64_t dynfield1[2]; /**< Reserved for dynamic fields. */ > } __rte_cache_aligned; >=20 > /** > @@ -1684,6 +1688,20 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, > void *buf_addr, > */ > #define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m) >=20 > +/** > + * Copy dynamic fields from m_src to m_dst. > + * > + * @param m_dst > + * The destination mbuf. > + * @param m_src > + * The source mbuf. > + */ > +static inline void > +rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf > +*msrc) { > + memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst- > >dynfield1)); } > + > /* internal */ > static inline void > __rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf > *msrc) @@ -1695,6 +1713,7 @@ __rte_pktmbuf_copy_hdr(struct rte_mbuf > *mdst, const struct rte_mbuf *msrc) > mdst->hash =3D msrc->hash; > mdst->packet_type =3D msrc->packet_type; > mdst->timestamp =3D msrc->timestamp; > + rte_mbuf_dynfield_copy(mdst, msrc); > } >=20 > /** > diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c > b/lib/librte_mbuf/rte_mbuf_dyn.c new file mode 100644 index > 000000000..9ef235483 > --- /dev/null > +++ b/lib/librte_mbuf/rte_mbuf_dyn.c > @@ -0,0 +1,548 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright 2019 6WIND S.A. > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define RTE_MBUF_DYN_MZNAME "rte_mbuf_dyn" > + > +struct mbuf_dynfield_elt { > + TAILQ_ENTRY(mbuf_dynfield_elt) next; > + struct rte_mbuf_dynfield params; > + size_t offset; > +}; > +TAILQ_HEAD(mbuf_dynfield_list, rte_tailq_entry); > + > +static struct rte_tailq_elem mbuf_dynfield_tailq =3D { > + .name =3D "RTE_MBUF_DYNFIELD", > +}; > +EAL_REGISTER_TAILQ(mbuf_dynfield_tailq); > + > +struct mbuf_dynflag_elt { > + TAILQ_ENTRY(mbuf_dynflag_elt) next; > + struct rte_mbuf_dynflag params; > + unsigned int bitnum; > +}; > +TAILQ_HEAD(mbuf_dynflag_list, rte_tailq_entry); > + > +static struct rte_tailq_elem mbuf_dynflag_tailq =3D { > + .name =3D "RTE_MBUF_DYNFLAG", > +}; > +EAL_REGISTER_TAILQ(mbuf_dynflag_tailq); > + > +struct mbuf_dyn_shm { > + /** > + * For each mbuf byte, free_space[i] !=3D 0 if space is free. > + * The value is the size of the biggest aligned element that > + * can fit in the zone. > + */ > + uint8_t free_space[sizeof(struct rte_mbuf)]; > + /** Bitfield of available flags. */ > + uint64_t free_flags; > +}; > +static struct mbuf_dyn_shm *shm; > + > +/* Set the value of free_space[] according to the size and alignment of > + * the free areas. This helps to select the best place when reserving a > + * dynamic field. Assume tailq is locked. > + */ > +static void > +process_score(void) > +{ > + size_t off, align, size, i; > + > + /* first, erase previous info */ > + for (i =3D 0; i < sizeof(struct rte_mbuf); i++) { > + if (shm->free_space[i]) > + shm->free_space[i] =3D 1; > + } > + > + for (off =3D 0; off < sizeof(struct rte_mbuf); off++) { > + /* get the size of the free zone */ > + for (size =3D 0; shm->free_space[off + size]; size++) > + ; > + if (size =3D=3D 0) > + continue; > + > + /* get the alignment of biggest object that can fit in > + * the zone at this offset. > + */ > + for (align =3D 1; > + (off % (align << 1)) =3D=3D 0 && (align << 1) <=3D size; > + align <<=3D 1) > + ; > + > + /* save it in free_space[] */ > + for (i =3D off; i < off + size; i++) > + shm->free_space[i] =3D RTE_MAX(align, shm- > >free_space[i]); > + } > +} > + > +/* Allocate and initialize the shared memory. Assume tailq is locked */ > +static int > +init_shared_mem(void) > +{ > + const struct rte_memzone *mz; > + uint64_t mask; > + > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { > + mz =3D > rte_memzone_reserve_aligned(RTE_MBUF_DYN_MZNAME, > + sizeof(struct > mbuf_dyn_shm), > + SOCKET_ID_ANY, 0, > + RTE_CACHE_LINE_SIZE); > + } else { > + mz =3D rte_memzone_lookup(RTE_MBUF_DYN_MZNAME); > + } > + if (mz =3D=3D NULL) > + return -1; > + > + shm =3D mz->addr; > + > +#define mark_free(field) \ > + memset(&shm->free_space[offsetof(struct rte_mbuf, field)], \ > + 1, sizeof(((struct rte_mbuf *)0)->field)) > + > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { > + /* init free_space, keep it sync'd with > + * rte_mbuf_dynfield_copy(). > + */ > + memset(shm, 0, sizeof(*shm)); > + mark_free(dynfield1); > + > + /* init free_flags */ > + for (mask =3D PKT_FIRST_FREE; mask <=3D PKT_LAST_FREE; mask > <<=3D 1) > + shm->free_flags |=3D mask; > + > + process_score(); > + } > +#undef mark_free > + > + return 0; > +} > + > +/* check if this offset can be used */ > +static int > +check_offset(size_t offset, size_t size, size_t align) { > + size_t i; > + > + if ((offset & (align - 1)) !=3D 0) > + return -1; > + if (offset + size > sizeof(struct rte_mbuf)) > + return -1; > + > + for (i =3D 0; i < size; i++) { > + if (!shm->free_space[i + offset]) > + return -1; > + } > + > + return 0; > +} > + > +/* assume tailq is locked */ > +static struct mbuf_dynfield_elt * > +__mbuf_dynfield_lookup(const char *name) { > + struct mbuf_dynfield_list *mbuf_dynfield_list; > + struct mbuf_dynfield_elt *mbuf_dynfield; > + struct rte_tailq_entry *te; > + > + mbuf_dynfield_list =3D RTE_TAILQ_CAST( > + mbuf_dynfield_tailq.head, mbuf_dynfield_list); > + > + TAILQ_FOREACH(te, mbuf_dynfield_list, next) { > + mbuf_dynfield =3D (struct mbuf_dynfield_elt *)te->data; > + if (strcmp(name, mbuf_dynfield->params.name) =3D=3D 0) > + break; > + } > + > + if (te =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return NULL; > + } > + > + return mbuf_dynfield; > +} > + > +int > +rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield > +*params) { > + struct mbuf_dynfield_elt *mbuf_dynfield; > + > + if (shm =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return -1; > + } > + > + rte_mcfg_tailq_read_lock(); > + mbuf_dynfield =3D __mbuf_dynfield_lookup(name); > + rte_mcfg_tailq_read_unlock(); > + > + if (mbuf_dynfield =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return -1; > + } > + > + if (params !=3D NULL) > + memcpy(params, &mbuf_dynfield->params, > sizeof(*params)); > + > + return mbuf_dynfield->offset; > +} > + > +static int mbuf_dynfield_cmp(const struct rte_mbuf_dynfield *params1, > + const struct rte_mbuf_dynfield *params2) { > + if (strcmp(params1->name, params2->name)) > + return -1; > + if (params1->size !=3D params2->size) > + return -1; > + if (params1->align !=3D params2->align) > + return -1; > + if (params1->flags !=3D params2->flags) > + return -1; > + return 0; > +} > + > +/* assume tailq is locked */ > +static int > +__rte_mbuf_dynfield_register_offset(const struct rte_mbuf_dynfield > *params, > + size_t req) > +{ > + struct mbuf_dynfield_list *mbuf_dynfield_list; > + struct mbuf_dynfield_elt *mbuf_dynfield =3D NULL; > + struct rte_tailq_entry *te =3D NULL; > + unsigned int best_zone =3D UINT_MAX; > + size_t i, offset; > + int ret; > + > + if (shm =3D=3D NULL && init_shared_mem() < 0) > + return -1; > + > + mbuf_dynfield =3D __mbuf_dynfield_lookup(params->name); > + if (mbuf_dynfield !=3D NULL) { > + if (req !=3D SIZE_MAX && req !=3D mbuf_dynfield->offset) { > + rte_errno =3D EEXIST; > + return -1; > + } > + if (mbuf_dynfield_cmp(params, &mbuf_dynfield->params) < > 0) { > + rte_errno =3D EEXIST; > + return -1; > + } > + return mbuf_dynfield->offset; > + } > + > + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) { > + rte_errno =3D EPERM; > + return -1; > + } > + > + if (req =3D=3D SIZE_MAX) { > + for (offset =3D 0; > + offset < sizeof(struct rte_mbuf); > + offset++) { > + if (check_offset(offset, params->size, > + params->align) =3D=3D 0 && > + shm->free_space[offset] < > best_zone) { > + best_zone =3D shm->free_space[offset]; > + req =3D offset; > + } > + } > + if (req =3D=3D SIZE_MAX) { > + rte_errno =3D ENOENT; > + return -1; > + } > + } else { > + if (check_offset(req, params->size, params->align) < 0) { > + rte_errno =3D EBUSY; > + return -1; > + } > + } > + > + offset =3D req; > + mbuf_dynfield_list =3D RTE_TAILQ_CAST( > + mbuf_dynfield_tailq.head, mbuf_dynfield_list); > + > + te =3D rte_zmalloc("MBUF_DYNFIELD_TAILQ_ENTRY", sizeof(*te), 0); > + if (te =3D=3D NULL) > + return -1; > + > + mbuf_dynfield =3D rte_zmalloc("mbuf_dynfield", > sizeof(*mbuf_dynfield), 0); > + if (mbuf_dynfield =3D=3D NULL) { > + rte_free(te); > + return -1; > + } > + > + ret =3D strlcpy(mbuf_dynfield->params.name, params->name, > + sizeof(mbuf_dynfield->params.name)); > + if (ret < 0 || ret >=3D (int)sizeof(mbuf_dynfield->params.name)) { > + rte_errno =3D ENAMETOOLONG; > + rte_free(mbuf_dynfield); > + rte_free(te); > + return -1; > + } > + memcpy(&mbuf_dynfield->params, params, sizeof(mbuf_dynfield- > >params)); > + mbuf_dynfield->offset =3D offset; > + te->data =3D mbuf_dynfield; > + > + TAILQ_INSERT_TAIL(mbuf_dynfield_list, te, next); > + > + for (i =3D offset; i < offset + params->size; i++) > + shm->free_space[i] =3D 0; > + process_score(); > + > + RTE_LOG(DEBUG, MBUF, "Registered dynamic field %s (sz=3D%zu, > al=3D%zu, fl=3D0x%x) -> %zd\n", > + params->name, params->size, params->align, params->flags, > + offset); > + > + return offset; > +} > + > +int > +rte_mbuf_dynfield_register_offset(const struct rte_mbuf_dynfield > *params, > + size_t req) > +{ > + int ret; > + > + if (params->size >=3D sizeof(struct rte_mbuf)) { > + rte_errno =3D EINVAL; > + return -1; > + } > + if (!rte_is_power_of_2(params->align)) { > + rte_errno =3D EINVAL; > + return -1; > + } > + if (params->flags !=3D 0) { > + rte_errno =3D EINVAL; > + return -1; > + } > + > + rte_mcfg_tailq_write_lock(); > + ret =3D __rte_mbuf_dynfield_register_offset(params, req); > + rte_mcfg_tailq_write_unlock(); > + > + return ret; > +} > + > +int > +rte_mbuf_dynfield_register(const struct rte_mbuf_dynfield *params) { > + return rte_mbuf_dynfield_register_offset(params, SIZE_MAX); } > + > +/* assume tailq is locked */ > +static struct mbuf_dynflag_elt * > +__mbuf_dynflag_lookup(const char *name) { > + struct mbuf_dynflag_list *mbuf_dynflag_list; > + struct mbuf_dynflag_elt *mbuf_dynflag; > + struct rte_tailq_entry *te; > + > + mbuf_dynflag_list =3D RTE_TAILQ_CAST( > + mbuf_dynflag_tailq.head, mbuf_dynflag_list); > + > + TAILQ_FOREACH(te, mbuf_dynflag_list, next) { > + mbuf_dynflag =3D (struct mbuf_dynflag_elt *)te->data; > + if (strncmp(name, mbuf_dynflag->params.name, > + RTE_MBUF_DYN_NAMESIZE) =3D=3D 0) > + break; > + } > + > + if (te =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return NULL; > + } > + > + return mbuf_dynflag; > +} > + > +int > +rte_mbuf_dynflag_lookup(const char *name, > + struct rte_mbuf_dynflag *params) > +{ > + struct mbuf_dynflag_elt *mbuf_dynflag; > + > + if (shm =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return -1; > + } > + > + rte_mcfg_tailq_read_lock(); > + mbuf_dynflag =3D __mbuf_dynflag_lookup(name); > + rte_mcfg_tailq_read_unlock(); > + > + if (mbuf_dynflag =3D=3D NULL) { > + rte_errno =3D ENOENT; > + return -1; > + } > + > + if (params !=3D NULL) > + memcpy(params, &mbuf_dynflag->params, sizeof(*params)); > + > + return mbuf_dynflag->bitnum; > +} > + > +static int mbuf_dynflag_cmp(const struct rte_mbuf_dynflag *params1, > + const struct rte_mbuf_dynflag *params2) { > + if (strcmp(params1->name, params2->name)) > + return -1; > + if (params1->flags !=3D params2->flags) > + return -1; > + return 0; > +} > + > +/* assume tailq is locked */ > +static int > +__rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag > *params, > + unsigned int req) > +{ > + struct mbuf_dynflag_list *mbuf_dynflag_list; > + struct mbuf_dynflag_elt *mbuf_dynflag =3D NULL; > + struct rte_tailq_entry *te =3D NULL; > + unsigned int bitnum; > + int ret; > + > + if (shm =3D=3D NULL && init_shared_mem() < 0) > + return -1; > + > + mbuf_dynflag =3D __mbuf_dynflag_lookup(params->name); > + if (mbuf_dynflag !=3D NULL) { > + if (req !=3D UINT_MAX && req !=3D mbuf_dynflag->bitnum) { > + rte_errno =3D EEXIST; > + return -1; > + } > + if (mbuf_dynflag_cmp(params, &mbuf_dynflag->params) < 0) > { > + rte_errno =3D EEXIST; > + return -1; > + } > + return mbuf_dynflag->bitnum; > + } > + > + if (rte_eal_process_type() !=3D RTE_PROC_PRIMARY) { > + rte_errno =3D EPERM; > + return -1; > + } > + > + if (req =3D=3D UINT_MAX) { > + if (shm->free_flags =3D=3D 0) { > + rte_errno =3D ENOENT; > + return -1; > + } > + bitnum =3D rte_bsf64(shm->free_flags); > + } else { > + if ((shm->free_flags & (1ULL << req)) =3D=3D 0) { > + rte_errno =3D EBUSY; > + return -1; > + } > + bitnum =3D req; > + } > + > + mbuf_dynflag_list =3D RTE_TAILQ_CAST( > + mbuf_dynflag_tailq.head, mbuf_dynflag_list); > + > + te =3D rte_zmalloc("MBUF_DYNFLAG_TAILQ_ENTRY", sizeof(*te), 0); > + if (te =3D=3D NULL) > + return -1; > + > + mbuf_dynflag =3D rte_zmalloc("mbuf_dynflag", sizeof(*mbuf_dynflag), > 0); > + if (mbuf_dynflag =3D=3D NULL) { > + rte_free(te); > + return -1; > + } > + > + ret =3D strlcpy(mbuf_dynflag->params.name, params->name, > + sizeof(mbuf_dynflag->params.name)); > + if (ret < 0 || ret >=3D (int)sizeof(mbuf_dynflag->params.name)) { > + rte_free(mbuf_dynflag); > + rte_free(te); > + rte_errno =3D ENAMETOOLONG; > + return -1; > + } > + mbuf_dynflag->bitnum =3D bitnum; > + te->data =3D mbuf_dynflag; > + > + TAILQ_INSERT_TAIL(mbuf_dynflag_list, te, next); > + > + shm->free_flags &=3D ~(1ULL << bitnum); > + > + RTE_LOG(DEBUG, MBUF, "Registered dynamic flag %s (fl=3D0x%x) -> > %u\n", > + params->name, params->flags, bitnum); > + > + return bitnum; > +} > + > +int > +rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag *params, > + unsigned int req) > +{ > + int ret; > + > + if (req !=3D UINT_MAX && req >=3D 64) { > + rte_errno =3D EINVAL; > + return -1; > + } > + > + rte_mcfg_tailq_write_lock(); > + ret =3D __rte_mbuf_dynflag_register_bitnum(params, req); > + rte_mcfg_tailq_write_unlock(); > + > + return ret; > +} > + > +int > +rte_mbuf_dynflag_register(const struct rte_mbuf_dynflag *params) { > + return rte_mbuf_dynflag_register_bitnum(params, UINT_MAX); } > + > +void rte_mbuf_dyn_dump(FILE *out) > +{ > + struct mbuf_dynfield_list *mbuf_dynfield_list; > + struct mbuf_dynfield_elt *dynfield; > + struct mbuf_dynflag_list *mbuf_dynflag_list; > + struct mbuf_dynflag_elt *dynflag; > + struct rte_tailq_entry *te; > + size_t i; > + > + rte_mcfg_tailq_write_lock(); > + init_shared_mem(); > + fprintf(out, "Reserved fields:\n"); > + mbuf_dynfield_list =3D RTE_TAILQ_CAST( > + mbuf_dynfield_tailq.head, mbuf_dynfield_list); > + TAILQ_FOREACH(te, mbuf_dynfield_list, next) { > + dynfield =3D (struct mbuf_dynfield_elt *)te->data; > + fprintf(out, " name=3D%s offset=3D%zd size=3D%zd align=3D%zd > flags=3D%x\n", > + dynfield->params.name, dynfield->offset, > + dynfield->params.size, dynfield->params.align, > + dynfield->params.flags); > + } > + fprintf(out, "Reserved flags:\n"); > + mbuf_dynflag_list =3D RTE_TAILQ_CAST( > + mbuf_dynflag_tailq.head, mbuf_dynflag_list); > + TAILQ_FOREACH(te, mbuf_dynflag_list, next) { > + dynflag =3D (struct mbuf_dynflag_elt *)te->data; > + fprintf(out, " name=3D%s bitnum=3D%u flags=3D%x\n", > + dynflag->params.name, dynflag->bitnum, > + dynflag->params.flags); > + } > + fprintf(out, "Free space in mbuf (0 =3D free, value =3D zone > alignment):\n"); > + for (i =3D 0; i < sizeof(struct rte_mbuf); i++) { > + if ((i % 8) =3D=3D 0) > + fprintf(out, " %4.4zx: ", i); > + fprintf(out, "%2.2x%s", shm->free_space[i], > + (i % 8 !=3D 7) ? " " : "\n"); > + } > + rte_mcfg_tailq_write_unlock(); > +} > diff --git a/lib/librte_mbuf/rte_mbuf_dyn.h > b/lib/librte_mbuf/rte_mbuf_dyn.h new file mode 100644 index > 000000000..307613c96 > --- /dev/null > +++ b/lib/librte_mbuf/rte_mbuf_dyn.h > @@ -0,0 +1,226 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright 2019 6WIND S.A. > + */ > + > +#ifndef _RTE_MBUF_DYN_H_ > +#define _RTE_MBUF_DYN_H_ > + > +/** > + * @file > + * RTE Mbuf dynamic fields and flags > + * > + * Many features require to store data inside the mbuf. As the room in > + * mbuf structure is limited, it is not possible to have a field for > + * each feature. Also, changing fields in the mbuf structure can break > + * the API or ABI. > + * > + * This module addresses this issue, by enabling the dynamic > + * registration of fields or flags: > + * > + * - a dynamic field is a named area in the rte_mbuf structure, with a > + * given size (>=3D 1 byte) and alignment constraint. > + * - a dynamic flag is a named bit in the rte_mbuf structure, stored > + * in mbuf->ol_flags. > + * > + * The typical use case is when a specific offload feature requires to > + * register a dedicated offload field in the mbuf structure, and adding > + * a static field or flag is not justified. > + * > + * Example of use: > + * > + * - A rte_mbuf_dynfield structure is defined, containing the parameters > + * of the dynamic field to be registered: > + * const struct rte_mbuf_dynfield rte_dynfield_my_feature =3D { ... }; > + * - The application initializes the PMD, and asks for this feature > + * at port initialization by passing DEV_RX_OFFLOAD_MY_FEATURE in > + * rxconf. This will make the PMD to register the field by calling > + * rte_mbuf_dynfield_register(&rte_dynfield_my_feature). The PMD > + * stores the returned offset. > + * - The application that uses the offload feature also registers > + * the field to retrieve the same offset. > + * - When the PMD receives a packet, it can set the field: > + * *RTE_MBUF_DYNFIELD(m, offset, ) =3D value; > + * - In the main loop, the application can retrieve the value with > + * the same macro. > + * > + * To avoid wasting space, the dynamic fields or flags must only be > + * reserved on demand, when an application asks for the related feature. > + * > + * The registration can be done at any moment, but it is not possible > + * to unregister fields or flags for now. > + * > + * A dynamic field can be reserved and used by an application only. > + * It can for instance be a packet mark. > + */ > + > +#include > +/** > + * Maximum length of the dynamic field or flag string. > + */ > +#define RTE_MBUF_DYN_NAMESIZE 64 > + > +/** > + * Structure describing the parameters of a mbuf dynamic field. > + */ > +struct rte_mbuf_dynfield { > + char name[RTE_MBUF_DYN_NAMESIZE]; /**< Name of the field. */ > + size_t size; /**< The number of bytes to reserve. */ > + size_t align; /**< The alignment constraint (power of 2). */ > + unsigned int flags; /**< Reserved for future use, must be 0. */ }; > + > +/** > + * Structure describing the parameters of a mbuf dynamic flag. > + */ > +struct rte_mbuf_dynflag { > + char name[RTE_MBUF_DYN_NAMESIZE]; /**< Name of the dynamic > flag. */ > + unsigned int flags; /**< Reserved for future use, must be 0. */ }; > + > +/** > + * Register space for a dynamic field in the mbuf structure. > + * > + * If the field is already registered (same name and parameters), its > + * offset is returned. > + * > + * @param params > + * A structure containing the requested parameters (name, size, > + * alignment constraint and flags). > + * @return > + * The offset in the mbuf structure, or -1 on error. > + * Possible values for rte_errno: > + * - EINVAL: invalid parameters (size, align, or flags). > + * - EEXIST: this name is already register with different parameters. > + * - EPERM: called from a secondary process. > + * - ENOENT: not enough room in mbuf. > + * - ENOMEM: allocation failure. > + * - ENAMETOOLONG: name does not ends with \0. > + */ > +__rte_experimental > +int rte_mbuf_dynfield_register(const struct rte_mbuf_dynfield *params); > + > +/** > + * Register space for a dynamic field in the mbuf structure at offset. > + * > + * If the field is already registered (same name, parameters and > +offset), > + * the offset is returned. > + * > + * @param params > + * A structure containing the requested parameters (name, size, > + * alignment constraint and flags). > + * @param offset > + * The requested offset. Ignored if SIZE_MAX is passed. > + * @return > + * The offset in the mbuf structure, or -1 on error. > + * Possible values for rte_errno: > + * - EINVAL: invalid parameters (size, align, flags, or offset). > + * - EEXIST: this name is already register with different parameters. > + * - EBUSY: the requested offset cannot be used. > + * - EPERM: called from a secondary process. > + * - ENOENT: not enough room in mbuf. > + * - ENOMEM: allocation failure. > + * - ENAMETOOLONG: name does not ends with \0. > + */ > +__rte_experimental > +int rte_mbuf_dynfield_register_offset(const struct rte_mbuf_dynfield > *params, > + size_t offset); > + > +/** > + * Lookup for a registered dynamic mbuf field. > + * > + * @param name > + * A string identifying the dynamic field. > + * @param params > + * If not NULL, and if the lookup is successful, the structure is > + * filled with the parameters of the dynamic field. > + * @return > + * The offset of this field in the mbuf structure, or -1 on error. > + * Possible values for rte_errno: > + * - ENOENT: no dynamic field matches this name. > + */ > +__rte_experimental > +int rte_mbuf_dynfield_lookup(const char *name, > + struct rte_mbuf_dynfield *params); > + > +/** > + * Register a dynamic flag in the mbuf structure. > + * > + * If the flag is already registered (same name and parameters), its > + * bitnum is returned. > + * > + * @param params > + * A structure containing the requested parameters of the dynamic > + * flag (name and options). > + * @return > + * The number of the reserved bit, or -1 on error. > + * Possible values for rte_errno: > + * - EINVAL: invalid parameters (size, align, or flags). > + * - EEXIST: this name is already register with different parameters. > + * - EPERM: called from a secondary process. > + * - ENOENT: no more flag available. > + * - ENOMEM: allocation failure. > + * - ENAMETOOLONG: name is longer than RTE_MBUF_DYN_NAMESIZE - > 1. > + */ > +__rte_experimental > +int rte_mbuf_dynflag_register(const struct rte_mbuf_dynflag *params); > + > +/** > + * Register a dynamic flag in the mbuf structure specifying bitnum. > + * > + * If the flag is already registered (same name, parameters and > +bitnum), > + * the bitnum is returned. > + * > + * @param params > + * A structure containing the requested parameters of the dynamic > + * flag (name and options). > + * @param bitnum > + * The requested bitnum. Ignored if UINT_MAX is passed. > + * @return > + * The number of the reserved bit, or -1 on error. > + * Possible values for rte_errno: > + * - EINVAL: invalid parameters (size, align, or flags). > + * - EEXIST: this name is already register with different parameters. > + * - EBUSY: the requested bitnum cannot be used. > + * - EPERM: called from a secondary process. > + * - ENOENT: no more flag available. > + * - ENOMEM: allocation failure. > + * - ENAMETOOLONG: name is longer than RTE_MBUF_DYN_NAMESIZE - > 1. > + */ > +__rte_experimental > +int rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag > *params, > + unsigned int bitnum); > + > +/** > + * Lookup for a registered dynamic mbuf flag. > + * > + * @param name > + * A string identifying the dynamic flag. > + * @param params > + * If not NULL, and if the lookup is successful, the structure is > + * filled with the parameters of the dynamic flag. > + * @return > + * The offset of this flag in the mbuf structure, or -1 on error. > + * Possible values for rte_errno: > + * - ENOENT: no dynamic flag matches this name. > + */ > +__rte_experimental > +int rte_mbuf_dynflag_lookup(const char *name, > + struct rte_mbuf_dynflag *params); > + > +/** > + * Helper macro to access to a dynamic field. > + */ > +#define RTE_MBUF_DYNFIELD(m, offset, type) ((type)((uintptr_t)(m) + > +(offset))) > + > +/** > + * Dump the status of dynamic fields and flags. > + * > + * @param out > + * The stream where the status is displayed. > + */ > +__rte_experimental > +void rte_mbuf_dyn_dump(FILE *out); > + > +/* Placeholder for dynamic fields and flags declarations. */ > + > +#endif > diff --git a/lib/librte_mbuf/rte_mbuf_version.map > b/lib/librte_mbuf/rte_mbuf_version.map > index 519fead35..9bf5ca37a 100644 > --- a/lib/librte_mbuf/rte_mbuf_version.map > +++ b/lib/librte_mbuf/rte_mbuf_version.map > @@ -58,6 +58,13 @@ EXPERIMENTAL { > global: >=20 > rte_mbuf_check; > + rte_mbuf_dynfield_lookup; > + rte_mbuf_dynfield_register; > + rte_mbuf_dynfield_register_offset; > + rte_mbuf_dynflag_lookup; > + rte_mbuf_dynflag_register; > + rte_mbuf_dynflag_register_bitnum; > + rte_mbuf_dyn_dump; > rte_pktmbuf_copy; >=20 > } DPDK_18.08; > -- > 2.20.1