[v3,04/16] drivers/event: use previous value atomic fetch operations

Message ID 1679338836-21321-5-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series replace __atomic operations returning new value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 20, 2023, 7 p.m. UTC
  Use __atomic_fetch_{add,and,or,sub,xor} instead of
__atomic_{add,and,or,sub,xor}_fetch adding the necessary code to
allow consumption of the resulting value.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
 drivers/event/cnxk/cnxk_tim_worker.h  | 2 +-
 drivers/event/dsw/dsw_event.c         | 4 ++--
 drivers/event/octeontx/timvf_worker.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/event/cnxk/cnxk_tim_worker.h b/drivers/event/cnxk/cnxk_tim_worker.h
index a326d55..0bd66ec 100644
--- a/drivers/event/cnxk/cnxk_tim_worker.h
+++ b/drivers/event/cnxk/cnxk_tim_worker.h
@@ -123,7 +123,7 @@ 
 	const uint64_t v =
 		~(TIM_BUCKET_W1_M_NUM_ENTRIES << TIM_BUCKET_W1_S_NUM_ENTRIES);
 
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline uint64_t
diff --git a/drivers/event/dsw/dsw_event.c b/drivers/event/dsw/dsw_event.c
index 9932caf..cbdc03f 100644
--- a/drivers/event/dsw/dsw_event.c
+++ b/drivers/event/dsw/dsw_event.c
@@ -45,8 +45,8 @@ 
 	 * allocation.
 	 */
 	new_total_on_loan =
-	    __atomic_add_fetch(&dsw->credits_on_loan, acquired_credits,
-			       __ATOMIC_RELAXED);
+	    __atomic_fetch_add(&dsw->credits_on_loan, acquired_credits,
+			       __ATOMIC_RELAXED) + acquired_credits;
 
 	if (unlikely(new_total_on_loan > dsw->max_inflight)) {
 		/* Some other port took the last credits */
diff --git a/drivers/event/octeontx/timvf_worker.h b/drivers/event/octeontx/timvf_worker.h
index 3f1e77f..aa729f8 100644
--- a/drivers/event/octeontx/timvf_worker.h
+++ b/drivers/event/octeontx/timvf_worker.h
@@ -135,7 +135,7 @@ 
 {
 	const uint64_t v = ~(TIM_BUCKET_W1_M_NUM_ENTRIES <<
 			TIM_BUCKET_W1_S_NUM_ENTRIES);
-	return __atomic_and_fetch(&bktp->w1, v, __ATOMIC_ACQ_REL);
+	return __atomic_fetch_and(&bktp->w1, v, __ATOMIC_ACQ_REL) & v;
 }
 
 static inline struct tim_mem_entry *