[dpdk-dev] [PATCH v2 6/8] examples/vm_power_manager: use compiler atomics for sync

Joyce Kong joyce.kong at arm.com
Mon Aug 23 07:49:50 CEST 2021


Convert rte_atomic32_cmpset to compiler atomic CAS
operation for channel status sync.

Signed-off-by: Joyce Kong <joyce.kong at arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang at arm.com>
---
 examples/vm_power_manager/channel_monitor.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 99f81544d7..3c20406f7c 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -25,7 +25,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_malloc.h>
-#include <rte_atomic.h>
 #include <rte_cycles.h>
 #include <rte_ethdev.h>
 #ifdef RTE_NET_I40E
@@ -829,8 +828,9 @@ process_request(struct rte_power_channel_packet *pkt,
 	if (chan_info == NULL)
 		return -1;
 
-	if (rte_atomic32_cmpset(&(chan_info->status), CHANNEL_MGR_CHANNEL_CONNECTED,
-			CHANNEL_MGR_CHANNEL_PROCESSING) == 0)
+	uint32_t channel_connected = CHANNEL_MGR_CHANNEL_CONNECTED;
+	if (__atomic_compare_exchange_n(&(chan_info->status), &channel_connected,
+		CHANNEL_MGR_CHANNEL_PROCESSING, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED) == 0)
 		return -1;
 
 	if (pkt->command == RTE_POWER_CPU_POWER) {
@@ -934,8 +934,9 @@ process_request(struct rte_power_channel_packet *pkt,
 	 * Return is not checked as channel status may have been set to DISABLED
 	 * from management thread
 	 */
-	rte_atomic32_cmpset(&(chan_info->status), CHANNEL_MGR_CHANNEL_PROCESSING,
-			CHANNEL_MGR_CHANNEL_CONNECTED);
+	uint32_t channel_processing = CHANNEL_MGR_CHANNEL_PROCESSING;
+	__atomic_compare_exchange_n(&(chan_info->status), &channel_processing,
+		CHANNEL_MGR_CHANNEL_CONNECTED, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
 	return 0;
 
 }
-- 
2.17.1



More information about the dev mailing list