[v3,2/4] bbdev: use C11 atomic builtins for device processing counter
Checks
Commit Message
Since rte_atomicXX APIs are not allowed to be used, use C11 atomic builtins
for device processing counter.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
---
lib/librte_bbdev/rte_bbdev.c | 5 +++--
lib/librte_bbdev/rte_bbdev.h | 4 +---
2 files changed, 4 insertions(+), 5 deletions(-)
Comments
Hi Phil,
Naïve question but the deprecation document was stating that "DPDK will adopt C11 atomic operations semantics and provide wrappers using C11 atomic built-ins."
Here you are using directly the C11 atomic built-ins and not providing and using a DPDK wrapper.
Wasn't the intent to have a new rte_... wrapper here? Ie. the same way as the __sync_fetch_and_add() were called before behind the rte_atomicNN_XX wrapper.
Thanks
Nic
> -----Original Message-----
> From: Phil Yang <phil.yang@arm.com>
> Sent: Wednesday, September 23, 2020 10:39 PM
> To: dev@dpdk.org; david.marchand@redhat.com; Chautru, Nicolas
> <nicolas.chautru@intel.com>; Hunt, David <david.hunt@intel.com>
> Cc: Ruifeng.Wang@arm.com; Honnappa.Nagarahalli@arm.com;
> nd@arm.com
> Subject: [PATCH v3 2/4] bbdev: use C11 atomic builtins for device processing
> counter
>
> Since rte_atomicXX APIs are not allowed to be used, use C11 atomic builtins
> for device processing counter.
>
> Signed-off-by: Phil Yang <phil.yang@arm.com>
> Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> ---
> lib/librte_bbdev/rte_bbdev.c | 5 +++--
> lib/librte_bbdev/rte_bbdev.h | 4 +---
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/lib/librte_bbdev/rte_bbdev.c b/lib/librte_bbdev/rte_bbdev.c
> index a4fdb69..5ba891c 100644
> --- a/lib/librte_bbdev/rte_bbdev.c
> +++ b/lib/librte_bbdev/rte_bbdev.c
> @@ -210,7 +210,7 @@ rte_bbdev_allocate(const char *name)
> return NULL;
> }
>
> - rte_atomic16_inc(&bbdev->data->process_cnt);
> + __atomic_add_fetch(&bbdev->data->process_cnt, 1,
> __ATOMIC_RELAXED);
> bbdev->data->dev_id = dev_id;
> bbdev->state = RTE_BBDEV_INITIALIZED;
>
> @@ -252,7 +252,8 @@ rte_bbdev_release(struct rte_bbdev *bbdev)
> }
>
> /* clear shared BBDev Data if no process is using the device anymore
> */
> - if (rte_atomic16_dec_and_test(&bbdev->data->process_cnt))
> + if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
> + __ATOMIC_RELAXED) == 0)
> memset(bbdev->data, 0, sizeof(*bbdev->data));
>
> memset(bbdev, 0, sizeof(*bbdev));
> diff --git a/lib/librte_bbdev/rte_bbdev.h b/lib/librte_bbdev/rte_bbdev.h
> index 5729137..7017124 100644
> --- a/lib/librte_bbdev/rte_bbdev.h
> +++ b/lib/librte_bbdev/rte_bbdev.h
> @@ -33,7 +33,6 @@ extern "C" {
> #include <string.h>
>
> #include <rte_compat.h>
> -#include <rte_atomic.h>
> #include <rte_bus.h>
> #include <rte_cpuflags.h>
> #include <rte_memory.h>
> @@ -426,8 +425,7 @@ struct rte_bbdev_data {
> uint16_t dev_id; /**< Device ID */
> int socket_id; /**< NUMA socket that device is on */
> bool started; /**< Device run-time state */
> - /** Counter of processes using the device */
> - rte_atomic16_t process_cnt;
> + uint16_t process_cnt; /** Counter of processes using the device */
> };
>
> /* Forward declarations */
> --
> 2.7.4
<snip>
>
> Hi Phil,
> Naïve question but the deprecation document was stating that "DPDK will
> adopt C11 atomic operations semantics and provide wrappers using C11
> atomic built-ins."
At the time of writing the deprecation notice, that was the thinking. However, through further discussions [1] in the community, it was decided to use atomic built-ins.
[1] http://mails.dpdk.org/archives/dev/2020-May/167416.html
> Here you are using directly the C11 atomic built-ins and not providing and
> using a DPDK wrapper.
> Wasn't the intent to have a new rte_... wrapper here? Ie. the same way as
> the __sync_fetch_and_add() were called before behind the rte_atomicNN_XX
> wrapper.
>
> Thanks
> Nic
>
>
> > -----Original Message-----
> > From: Phil Yang <phil.yang@arm.com>
> > Sent: Wednesday, September 23, 2020 10:39 PM
> > To: dev@dpdk.org; david.marchand@redhat.com; Chautru, Nicolas
> > <nicolas.chautru@intel.com>; Hunt, David <david.hunt@intel.com>
> > Cc: Ruifeng.Wang@arm.com; Honnappa.Nagarahalli@arm.com;
> nd@arm.com
> > Subject: [PATCH v3 2/4] bbdev: use C11 atomic builtins for device
> > processing counter
> >
> > Since rte_atomicXX APIs are not allowed to be used, use C11 atomic
> > builtins for device processing counter.
> >
> > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > ---
> > lib/librte_bbdev/rte_bbdev.c | 5 +++-- lib/librte_bbdev/rte_bbdev.h
> > | 4 +---
> > 2 files changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/librte_bbdev/rte_bbdev.c
> > b/lib/librte_bbdev/rte_bbdev.c index a4fdb69..5ba891c 100644
> > --- a/lib/librte_bbdev/rte_bbdev.c
> > +++ b/lib/librte_bbdev/rte_bbdev.c
> > @@ -210,7 +210,7 @@ rte_bbdev_allocate(const char *name)
> > return NULL;
> > }
> >
> > - rte_atomic16_inc(&bbdev->data->process_cnt);
> > + __atomic_add_fetch(&bbdev->data->process_cnt, 1,
> > __ATOMIC_RELAXED);
> > bbdev->data->dev_id = dev_id;
> > bbdev->state = RTE_BBDEV_INITIALIZED;
> >
> > @@ -252,7 +252,8 @@ rte_bbdev_release(struct rte_bbdev *bbdev)
> > }
> >
> > /* clear shared BBDev Data if no process is using the device anymore
> > */
> > - if (rte_atomic16_dec_and_test(&bbdev->data->process_cnt))
> > + if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
> > + __ATOMIC_RELAXED) == 0)
> > memset(bbdev->data, 0, sizeof(*bbdev->data));
> >
> > memset(bbdev, 0, sizeof(*bbdev));
> > diff --git a/lib/librte_bbdev/rte_bbdev.h
> > b/lib/librte_bbdev/rte_bbdev.h index 5729137..7017124 100644
> > --- a/lib/librte_bbdev/rte_bbdev.h
> > +++ b/lib/librte_bbdev/rte_bbdev.h
> > @@ -33,7 +33,6 @@ extern "C" {
> > #include <string.h>
> >
> > #include <rte_compat.h>
> > -#include <rte_atomic.h>
> > #include <rte_bus.h>
> > #include <rte_cpuflags.h>
> > #include <rte_memory.h>
> > @@ -426,8 +425,7 @@ struct rte_bbdev_data {
> > uint16_t dev_id; /**< Device ID */
> > int socket_id; /**< NUMA socket that device is on */
> > bool started; /**< Device run-time state */
> > - /** Counter of processes using the device */
> > - rte_atomic16_t process_cnt;
> > + uint16_t process_cnt; /** Counter of processes using the device */
> > };
> >
> > /* Forward declarations */
> > --
> > 2.7.4
Thanks Honnappa,
Acked-By: Nicolas Chautru <nicolas.chautru@intel.com>
> -----Original Message-----
> From: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
> Sent: Thursday, September 24, 2020 3:45 PM
> To: Chautru, Nicolas <nicolas.chautru@intel.com>; Phil Yang
> <Phil.Yang@arm.com>; dev@dpdk.org; david.marchand@redhat.com; Hunt,
> David <david.hunt@intel.com>
> Cc: Ruifeng Wang <Ruifeng.Wang@arm.com>; nd <nd@arm.com>;
> Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; nd
> <nd@arm.com>
> Subject: RE: [PATCH v3 2/4] bbdev: use C11 atomic builtins for device
> processing counter
>
> <snip>
>
> >
> > Hi Phil,
> > Naïve question but the deprecation document was stating that "DPDK
> > will adopt C11 atomic operations semantics and provide wrappers using
> > C11 atomic built-ins."
> At the time of writing the deprecation notice, that was the thinking.
> However, through further discussions [1] in the community, it was decided
> to use atomic built-ins.
>
> [1] http://mails.dpdk.org/archives/dev/2020-May/167416.html
>
> > Here you are using directly the C11 atomic built-ins and not providing
> > and using a DPDK wrapper.
> > Wasn't the intent to have a new rte_... wrapper here? Ie. the same way
> > as the __sync_fetch_and_add() were called before behind the
> > rte_atomicNN_XX wrapper.
> >
> > Thanks
> > Nic
> >
> >
> > > -----Original Message-----
> > > From: Phil Yang <phil.yang@arm.com>
> > > Sent: Wednesday, September 23, 2020 10:39 PM
> > > To: dev@dpdk.org; david.marchand@redhat.com; Chautru, Nicolas
> > > <nicolas.chautru@intel.com>; Hunt, David <david.hunt@intel.com>
> > > Cc: Ruifeng.Wang@arm.com; Honnappa.Nagarahalli@arm.com;
> > nd@arm.com
> > > Subject: [PATCH v3 2/4] bbdev: use C11 atomic builtins for device
> > > processing counter
> > >
> > > Since rte_atomicXX APIs are not allowed to be used, use C11 atomic
> > > builtins for device processing counter.
> > >
> > > Signed-off-by: Phil Yang <phil.yang@arm.com>
> > > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > > Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> > > ---
> > > lib/librte_bbdev/rte_bbdev.c | 5 +++--
> > > lib/librte_bbdev/rte_bbdev.h
> > > | 4 +---
> > > 2 files changed, 4 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/lib/librte_bbdev/rte_bbdev.c
> > > b/lib/librte_bbdev/rte_bbdev.c index a4fdb69..5ba891c 100644
> > > --- a/lib/librte_bbdev/rte_bbdev.c
> > > +++ b/lib/librte_bbdev/rte_bbdev.c
> > > @@ -210,7 +210,7 @@ rte_bbdev_allocate(const char *name)
> > > return NULL;
> > > }
> > >
> > > - rte_atomic16_inc(&bbdev->data->process_cnt);
> > > + __atomic_add_fetch(&bbdev->data->process_cnt, 1,
> > > __ATOMIC_RELAXED);
> > > bbdev->data->dev_id = dev_id;
> > > bbdev->state = RTE_BBDEV_INITIALIZED;
> > >
> > > @@ -252,7 +252,8 @@ rte_bbdev_release(struct rte_bbdev *bbdev)
> > > }
> > >
> > > /* clear shared BBDev Data if no process is using the device
> > > anymore */
> > > - if (rte_atomic16_dec_and_test(&bbdev->data->process_cnt))
> > > + if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
> > > + __ATOMIC_RELAXED) == 0)
> > > memset(bbdev->data, 0, sizeof(*bbdev->data));
> > >
> > > memset(bbdev, 0, sizeof(*bbdev));
> > > diff --git a/lib/librte_bbdev/rte_bbdev.h
> > > b/lib/librte_bbdev/rte_bbdev.h index 5729137..7017124 100644
> > > --- a/lib/librte_bbdev/rte_bbdev.h
> > > +++ b/lib/librte_bbdev/rte_bbdev.h
> > > @@ -33,7 +33,6 @@ extern "C" {
> > > #include <string.h>
> > >
> > > #include <rte_compat.h>
> > > -#include <rte_atomic.h>
> > > #include <rte_bus.h>
> > > #include <rte_cpuflags.h>
> > > #include <rte_memory.h>
> > > @@ -426,8 +425,7 @@ struct rte_bbdev_data {
> > > uint16_t dev_id; /**< Device ID */
> > > int socket_id; /**< NUMA socket that device is on */
> > > bool started; /**< Device run-time state */
> > > - /** Counter of processes using the device */
> > > - rte_atomic16_t process_cnt;
> > > + uint16_t process_cnt; /** Counter of processes using the device
> > > +*/
> > > };
> > >
> > > /* Forward declarations */
> > > --
> > > 2.7.4
@@ -210,7 +210,7 @@ rte_bbdev_allocate(const char *name)
return NULL;
}
- rte_atomic16_inc(&bbdev->data->process_cnt);
+ __atomic_add_fetch(&bbdev->data->process_cnt, 1, __ATOMIC_RELAXED);
bbdev->data->dev_id = dev_id;
bbdev->state = RTE_BBDEV_INITIALIZED;
@@ -252,7 +252,8 @@ rte_bbdev_release(struct rte_bbdev *bbdev)
}
/* clear shared BBDev Data if no process is using the device anymore */
- if (rte_atomic16_dec_and_test(&bbdev->data->process_cnt))
+ if (__atomic_sub_fetch(&bbdev->data->process_cnt, 1,
+ __ATOMIC_RELAXED) == 0)
memset(bbdev->data, 0, sizeof(*bbdev->data));
memset(bbdev, 0, sizeof(*bbdev));
@@ -33,7 +33,6 @@ extern "C" {
#include <string.h>
#include <rte_compat.h>
-#include <rte_atomic.h>
#include <rte_bus.h>
#include <rte_cpuflags.h>
#include <rte_memory.h>
@@ -426,8 +425,7 @@ struct rte_bbdev_data {
uint16_t dev_id; /**< Device ID */
int socket_id; /**< NUMA socket that device is on */
bool started; /**< Device run-time state */
- /** Counter of processes using the device */
- rte_atomic16_t process_cnt;
+ uint16_t process_cnt; /** Counter of processes using the device */
};
/* Forward declarations */