[11/17] net/iavf: use previous value atomic fetch operations

Message ID 1677718068-2412-12-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series use __atomic operations returning previous value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 2, 2023, 12:47 a.m. UTC
  Use __atomic_fetch_{add,and,or,sub,xor} instead of
__atomic_{add,and,or,sub,xor}_fetch when we have no interest in the
result of the operation.

Reduces unnecessary codegen that provided the result of the atomic
operation that was not used.

Change brings closer alignment with atomics available in C11 standard
and will reduce review effort when they are integrated.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/net/iavf/iavf_vchnl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Ruifeng Wang March 2, 2023, 9:28 a.m. UTC | #1
> -----Original Message-----
> From: Tyler Retzlaff <roretzla@linux.microsoft.com>
> Sent: Thursday, March 2, 2023 8:48 AM
> To: dev@dpdk.org
> Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; thomas@monjalon.net; Tyler
> Retzlaff <roretzla@linux.microsoft.com>
> Subject: [PATCH 11/17] net/iavf: use previous value atomic fetch operations
> 
> Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch
> when we have no interest in the result of the operation.
> 
> Reduces unnecessary codegen that provided the result of the atomic operation that was not
> used.
> 
> Change brings closer alignment with atomics available in C11 standard and will reduce
> review effort when they are integrated.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  drivers/net/iavf/iavf_vchnl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index
> 9adaadb..73875d7 100644
> --- a/drivers/net/iavf/iavf_vchnl.c
> +++ b/drivers/net/iavf/iavf_vchnl.c
> @@ -128,7 +128,7 @@ struct iavf_event_handler {
>  	int err = pipe(handler->fd);
>  #endif
>  	if (err != 0) {
> -		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
> +		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
>  		return -1;
>  	}
> 
> @@ -137,7 +137,7 @@ struct iavf_event_handler {
> 
>  	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
>  				NULL, iavf_dev_event_handle, NULL)) {
> -		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
> +		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
>  		return -1;
>  	}
> 
> @@ -533,7 +533,7 @@ struct iavf_event_handler {
>  				/* read message and it's expected one */
>  				if (msg_opc == vf->pend_cmd) {
>  					uint32_t cmd_count =
> -					__atomic_sub_fetch(&vf->pend_cmd_count,
> +					__atomic_fetch_sub(&vf->pend_cmd_count,

It doesn't apply here. The return value is used.
The rest of the series looks good to me.

>  							1, __ATOMIC_RELAXED);
>  					if (cmd_count == 0)
>  						_notify_cmd(vf, msg_ret);
> --
> 1.8.3.1
  
Tyler Retzlaff March 2, 2023, 3:50 p.m. UTC | #2
On Thu, Mar 02, 2023 at 09:28:09AM +0000, Ruifeng Wang wrote:
> > -----Original Message-----
> > From: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > Sent: Thursday, March 2, 2023 8:48 AM
> > To: dev@dpdk.org
> > Cc: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>; thomas@monjalon.net; Tyler
> > Retzlaff <roretzla@linux.microsoft.com>
> > Subject: [PATCH 11/17] net/iavf: use previous value atomic fetch operations
> > 
> > Use __atomic_fetch_{add,and,or,sub,xor} instead of __atomic_{add,and,or,sub,xor}_fetch
> > when we have no interest in the result of the operation.
> > 
> > Reduces unnecessary codegen that provided the result of the atomic operation that was not
> > used.
> > 
> > Change brings closer alignment with atomics available in C11 standard and will reduce
> > review effort when they are integrated.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > ---
> >  drivers/net/iavf/iavf_vchnl.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index
> > 9adaadb..73875d7 100644
> > --- a/drivers/net/iavf/iavf_vchnl.c
> > +++ b/drivers/net/iavf/iavf_vchnl.c
> > @@ -128,7 +128,7 @@ struct iavf_event_handler {
> >  	int err = pipe(handler->fd);
> >  #endif
> >  	if (err != 0) {
> > -		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
> > +		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
> >  		return -1;
> >  	}
> > 
> > @@ -137,7 +137,7 @@ struct iavf_event_handler {
> > 
> >  	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
> >  				NULL, iavf_dev_event_handle, NULL)) {
> > -		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
> > +		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
> >  		return -1;
> >  	}
> > 
> > @@ -533,7 +533,7 @@ struct iavf_event_handler {
> >  				/* read message and it's expected one */
> >  				if (msg_opc == vf->pend_cmd) {
> >  					uint32_t cmd_count =
> > -					__atomic_sub_fetch(&vf->pend_cmd_count,
> > +					__atomic_fetch_sub(&vf->pend_cmd_count,
> 
> It doesn't apply here. The return value is used.
> The rest of the series looks good to me.

oh, i was blind to the line wrapping. definitely not correct.

thanks for catching this, will submit v2 with it reverted.

> 
> >  							1, __ATOMIC_RELAXED);
> >  					if (cmd_count == 0)
> >  						_notify_cmd(vf, msg_ret);
> > --
> > 1.8.3.1
  

Patch

diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index 9adaadb..73875d7 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -128,7 +128,7 @@  struct iavf_event_handler {
 	int err = pipe(handler->fd);
 #endif
 	if (err != 0) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -137,7 +137,7 @@  struct iavf_event_handler {
 
 	if (rte_ctrl_thread_create(&handler->tid, "iavf-event-thread",
 				NULL, iavf_dev_event_handle, NULL)) {
-		__atomic_sub_fetch(&handler->ndev, 1, __ATOMIC_RELAXED);
+		__atomic_fetch_sub(&handler->ndev, 1, __ATOMIC_RELAXED);
 		return -1;
 	}
 
@@ -533,7 +533,7 @@  struct iavf_event_handler {
 				/* read message and it's expected one */
 				if (msg_opc == vf->pend_cmd) {
 					uint32_t cmd_count =
-					__atomic_sub_fetch(&vf->pend_cmd_count,
+					__atomic_fetch_sub(&vf->pend_cmd_count,
 							1, __ATOMIC_RELAXED);
 					if (cmd_count == 0)
 						_notify_cmd(vf, msg_ret);