[02/17] telemetry: use previous value atomic fetch operations

Message ID 1677718068-2412-3-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>
---
 lib/telemetry/telemetry.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Bruce Richardson March 2, 2023, 9:34 a.m. UTC | #1
On Wed, Mar 01, 2023 at 04:47:33PM -0800, Tyler Retzlaff wrote:
> 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>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 7bceadc..deba7f3 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -391,7 +391,7 @@  struct socket {
 		bytes = read(s, buffer, sizeof(buffer) - 1);
 	}
 	close(s);
-	__atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED);
+	__atomic_fetch_sub(&v2_clients, 1, __ATOMIC_RELAXED);
 	return NULL;
 }
 
@@ -414,7 +414,7 @@  struct socket {
 				close(s_accepted);
 				continue;
 			}
-			__atomic_add_fetch(s->num_clients, 1,
+			__atomic_fetch_add(s->num_clients, 1,
 					__ATOMIC_RELAXED);
 		}
 		rc = pthread_create(&th, NULL, s->fn,
@@ -424,7 +424,7 @@  struct socket {
 				 strerror(rc));
 			close(s_accepted);
 			if (s->num_clients != NULL)
-				__atomic_sub_fetch(s->num_clients, 1,
+				__atomic_fetch_sub(s->num_clients, 1,
 						   __ATOMIC_RELAXED);
 			continue;
 		}