__lttng_counter_add: skip effect-less code when global_sum_step=0
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Sep 2022 20:18:43 +0000 (16:18 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 12 Jul 2024 15:39:51 +0000 (11:39 -0400)
Skip effect-less code in the common case where global_sum_step=0.
This saves about 1.5ns on x86-64.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0dacb9f189c0d47dd608dbef6f4aba969a6b0a4a

src/common/counter/counter-api.h

index 7b341d974d633ec397737495aa2345147be9316c..39f2d5d3e74b3cedbf2df41594fb2bf4c1338377 100644 (file)
@@ -66,11 +66,13 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config,
                                move_sum = 0;
                                old = res;
                                n = (int8_t) ((uint8_t) old + (uint8_t) v);
-                               if (caa_unlikely(n > (int8_t) global_sum_step))
-                                       move_sum = (int8_t) global_sum_step / 2;
-                               else if (caa_unlikely(n < -(int8_t) global_sum_step))
-                                       move_sum = -((int8_t) global_sum_step / 2);
-                               n -= move_sum;
+                               if (caa_unlikely(global_sum_step)) {
+                                       if (caa_unlikely(n > (int8_t) global_sum_step))
+                                               move_sum = (int8_t) global_sum_step / 2;
+                                       else if (caa_unlikely(n < -(int8_t) global_sum_step))
+                                               move_sum = -((int8_t) global_sum_step / 2);
+                                       n -= move_sum;
+                               }
                                res = uatomic_cmpxchg(int_p, old, n);
                        } while (old != res);
                        break;
@@ -107,11 +109,13 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config,
                                move_sum = 0;
                                old = res;
                                n = (int16_t) ((uint16_t) old + (uint16_t) v);
-                               if (caa_unlikely(n > (int16_t) global_sum_step))
-                                       move_sum = (int16_t) global_sum_step / 2;
-                               else if (caa_unlikely(n < -(int16_t) global_sum_step))
-                                       move_sum = -((int16_t) global_sum_step / 2);
-                               n -= move_sum;
+                               if (caa_unlikely(global_sum_step)) {
+                                       if (caa_unlikely(n > (int16_t) global_sum_step))
+                                               move_sum = (int16_t) global_sum_step / 2;
+                                       else if (caa_unlikely(n < -(int16_t) global_sum_step))
+                                               move_sum = -((int16_t) global_sum_step / 2);
+                                       n -= move_sum;
+                               }
                                res = uatomic_cmpxchg(int_p, old, n);
                        } while (old != res);
                        break;
@@ -148,11 +152,13 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config,
                                move_sum = 0;
                                old = res;
                                n = (int32_t) ((uint32_t) old + (uint32_t) v);
-                               if (caa_unlikely(n > (int32_t) global_sum_step))
-                                       move_sum = (int32_t) global_sum_step / 2;
-                               else if (caa_unlikely(n < -(int32_t) global_sum_step))
-                                       move_sum = -((int32_t) global_sum_step / 2);
-                               n -= move_sum;
+                               if (caa_unlikely(global_sum_step)) {
+                                       if (caa_unlikely(n > (int32_t) global_sum_step))
+                                               move_sum = (int32_t) global_sum_step / 2;
+                                       else if (caa_unlikely(n < -(int32_t) global_sum_step))
+                                               move_sum = -((int32_t) global_sum_step / 2);
+                                       n -= move_sum;
+                               }
                                res = uatomic_cmpxchg(int_p, old, n);
                        } while (old != res);
                        break;
@@ -190,11 +196,13 @@ static inline int __lttng_counter_add(const struct lib_counter_config *config,
                                move_sum = 0;
                                old = res;
                                n = (int64_t) ((uint64_t) old + (uint64_t) v);
-                               if (caa_unlikely(n > (int64_t) global_sum_step))
-                                       move_sum = (int64_t) global_sum_step / 2;
-                               else if (caa_unlikely(n < -(int64_t) global_sum_step))
-                                       move_sum = -((int64_t) global_sum_step / 2);
-                               n -= move_sum;
+                               if (caa_unlikely(global_sum_step)) {
+                                       if (caa_unlikely(n > (int64_t) global_sum_step))
+                                               move_sum = (int64_t) global_sum_step / 2;
+                                       else if (caa_unlikely(n < -(int64_t) global_sum_step))
+                                               move_sum = -((int64_t) global_sum_step / 2);
+                                       n -= move_sum;
+                               }
                                res = uatomic_cmpxchg(int_p, old, n);
                        } while (old != res);
                        break;
This page took 0.025935 seconds and 4 git commands to generate.