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 12E99A0613 for ; Mon, 23 Sep 2019 10:31:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CFD481BE82; Mon, 23 Sep 2019 10:31:46 +0200 (CEST) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id A8B4E4CE4 for ; Mon, 23 Sep 2019 10:31:45 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id r3so12875834wrj.6 for ; Mon, 23 Sep 2019 01:31:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=AXDiPIiTRtIc5vvfcru02iGVh7hVVNQcjRvGmjCpV9k=; b=TZwD/qqBDLOGr7QIwErr/RHVqghME+x9zvs9rS+1mKj65Hld4o+0uB0/v2xu43U/2O hF4F/9f/PKEvekdnX8HQ+89etXAUEI64RRJZaq56Q6MNhSjocqT2nLS3lOyyY2QH+Erl ecYnVZVVNKZAZugcIev/1fusbIQNLWOzfTtLb9niQKvgBuCpT9DVJEGsLOBzkSXbIDpy kHv1aOrd15Q9kEr4c2d/rjN8nSmL5/HJHNEdFr9ApIK7WDY2bNT7OLlCh0PkMDw1ZBIa VvTK8pULDOewoehuCSMtocFYL+TEFJ3YsJoCRrZ8UbN01xYjB9GvDtdA1Qb9sk+X3x+O RRZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=AXDiPIiTRtIc5vvfcru02iGVh7hVVNQcjRvGmjCpV9k=; b=dMLkp+8ORW4u6J6tw09w60fx/nOgZbsC6RJFYgwA3+2KHJZsSuOmRBi7Zf2Y+7GOiJ Mnl78hOJlZTQjc5XBmN/QZTKfKoc4yzQ6b9111nk/bA6bg9/ke5+PoAksD2b2e9bqfmp Lfs+78VI3Ls3C9T4/3yiVrRcAR9NIYcitT/amuTF4fLHsYRB9HD5HM+ruSpP0C0jfSOv GHMepcYosc6Xp/H7+GPN3h65KkUITqfW4T4hl4aHnjZOxEtMlMu8aha3DIRWp0No2RQW NVMys9nmPH6HPYJyCGLN/cnFXoaPH768SS3ZCCLnQsJIEm0tmZPUqVaSdYECmEZRAE1C cpFg== X-Gm-Message-State: APjAAAU2Q2+MwVwxRyvMF9xjHjEX4fgmUqHFY8s5g96litH+QblntlBi n5MRmIMD4fja5O7B3Zx56xovYQ== X-Google-Smtp-Source: APXvYqwfp+3W58tWoJ3PDZhMaDXQJrBBUfaMXRryA0Uy2YTugUorBIfGiQmDoRWi9LPhUSJhYeb4+g== X-Received: by 2002:adf:e390:: with SMTP id e16mr20871948wrm.29.1569227505147; Mon, 23 Sep 2019 01:31:45 -0700 (PDT) Received: from 6wind.com (2a01cb0c0005a6000226b0fffeed02fc.ipv6.abo.wanadoo.fr. [2a01:cb0c:5:a600:226:b0ff:feed:2fc]) by smtp.gmail.com with ESMTPSA id 207sm19576360wme.17.2019.09.23.01.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 01:31:44 -0700 (PDT) Date: Mon, 23 Sep 2019 10:31:43 +0200 From: Olivier Matz To: "Wang, Haiyue" Cc: "dev@dpdk.org" , Thomas Monjalon , Stephen Hemminger , Andrew Rybchenko , "Wiles, Keith" , Jerin Jacob Kollanukkaran Message-ID: <20190923083143.ml3jkipy7wdvzwg6@platinum> References: <20190710092907.5565-1-olivier.matz@6wind.com> <20190918165448.22409-1-olivier.matz@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Subject: Re: [dpdk-dev] [PATCH] 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, On Sat, Sep 21, 2019 at 04:54:39AM +0000, Wang, Haiyue wrote: > > -----Original Message----- > > From: Olivier Matz [mailto:olivier.matz@6wind.com] > > Sent: Thursday, September 19, 2019 00:55 > > To: dev@dpdk.org > > Cc: Thomas Monjalon ; Wang, Haiyue ; Stephen Hemminger > > ; Andrew Rybchenko ; Wiles, Keith > > ; Jerin Jacob Kollanukkaran > > Subject: [PATCH] mbuf: support 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 commit addresses these issues, 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 (>= 1 byte) and alignment constraint. > > - a dynamic flag is a named bit in the rte_mbuf structure. > > > > 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 mbuf is limited, the space should only be reserved if it > > is going to be used (i.e when the application explicitly asks for it). > > > > The registration can be done at any moment, but it is not possible > > to unregister fields or flags for now. > > > > Signed-off-by: Olivier Matz > > Acked-by: Thomas Monjalon > > --- > > > > rfc -> v1 > > > > * 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. > > > > app/test/test_mbuf.c | 114 ++++++- > > 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 | 25 +- > > lib/librte_mbuf/rte_mbuf_dyn.c | 408 +++++++++++++++++++++++++ > > lib/librte_mbuf/rte_mbuf_dyn.h | 163 ++++++++++ > > lib/librte_mbuf/rte_mbuf_version.map | 4 + > > 8 files changed, 724 insertions(+), 5 deletions(-) > > create mode 100644 lib/librte_mbuf/rte_mbuf_dyn.c > > create mode 100644 lib/librte_mbuf/rte_mbuf_dyn.h > > > > [snip] > > > +/** > > + * Helper macro to access to a dynamic field. > > + */ > > +#define RTE_MBUF_DYNFIELD(m, offset, type) ((type)((uintptr_t)(m) + (offset))) > > How about to change it as: ? > #define RTE_MBUF_DYNFIELD(m, offset, type) ((type *)((uintptr_t)(m) + (offset))) > ^ > Then, > *RTE_MBUF_DYNFIELD(mb, xxx, uint32_t) = yyy; > > Since we use 'type' like: sizeof(type), __alignof__(type), this makes 'type' be > more consistent, not have to force cast 'type *' when using it. > > const struct rte_mbuf_dynfield dynfield2 = { > .name = "test-dynfield2", > .size = sizeof(uint16_t), > .align = __alignof__(uint16_t), > .flags = 0, > }; Yes, I don't see use cases where the '*' is omitted, so it could be in the macro. On the other hand, doing like in the patch is more consistent with similar macros like rte_pktmbuf_mtod(), so I'll tend to keep it as is. This is maybe not that important, because this macro will often be hidden in a wrapper, like below: static inline uint64_t rte_mbuf_dyn_timestamp_get(const struct rte_mbuf *m) { return *RTE_MBUF_DYNFIELD(m, rte_mbuf_dynfield_timestamp_offset, uint64_t *); } > And also, when I'm trying to use the dynamic flag, found a macro will be better > for making code align with dynamic field. Just a small suggestion. ;-) > mb->ol_flags |= RTE_MBUF_DYNFLAG(ol_offset); > > /** > * Helper macro to access to a dynamic flag. > */ > #define RTE_MBUF_DYNFLAG(offset) (1ULL << (offset)) OK, I will add it in next version. Thank you for the feedback! Olivier