From: Mathieu Desnoyers Date: Fri, 2 Sep 2022 20:19:06 +0000 (-0400) Subject: __lttng_counter_add: skip effect-less code when global_sum_step=0 X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=bf59e80cf46469333f2b7ad74f294640742baaf5;p=lttng-modules.git __lttng_counter_add: skip effect-less code when global_sum_step=0 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 Change-Id: I62e8d163143780e64d7130051b1013470fef48fe --- diff --git a/include/counter/counter-api.h b/include/counter/counter-api.h index be372f45..ffc5ff7d 100644 --- a/include/counter/counter-api.h +++ b/include/counter/counter-api.h @@ -63,11 +63,13 @@ static __always_inline int __lttng_counter_add(const struct lib_counter_config * move_sum = 0; old = res; n = (int8_t) ((uint8_t) old + (uint8_t) v); - if (unlikely(n > (int8_t) global_sum_step)) - move_sum = (int8_t) global_sum_step / 2; - else if (unlikely(n < -(int8_t) global_sum_step)) - move_sum = -((int8_t) global_sum_step / 2); - n -= move_sum; + if (unlikely(global_sum_step)) { + if (unlikely(n > (int8_t) global_sum_step)) + move_sum = (int8_t) global_sum_step / 2; + else if (unlikely(n < -(int8_t) global_sum_step)) + move_sum = -((int8_t) global_sum_step / 2); + n -= move_sum; + } res = cmpxchg_local(int_p, old, n); } while (old != res); break; @@ -104,11 +106,13 @@ static __always_inline int __lttng_counter_add(const struct lib_counter_config * move_sum = 0; old = res; n = (int16_t) ((uint16_t) old + (uint16_t) v); - if (unlikely(n > (int16_t) global_sum_step)) - move_sum = (int16_t) global_sum_step / 2; - else if (unlikely(n < -(int16_t) global_sum_step)) - move_sum = -((int16_t) global_sum_step / 2); - n -= move_sum; + if (unlikely(global_sum_step)) { + if (unlikely(n > (int16_t) global_sum_step)) + move_sum = (int16_t) global_sum_step / 2; + else if (unlikely(n < -(int16_t) global_sum_step)) + move_sum = -((int16_t) global_sum_step / 2); + n -= move_sum; + } res = cmpxchg_local(int_p, old, n); } while (old != res); break; @@ -145,11 +149,13 @@ static __always_inline int __lttng_counter_add(const struct lib_counter_config * move_sum = 0; old = res; n = (int32_t) ((uint32_t) old + (uint32_t) v); - if (unlikely(n > (int32_t) global_sum_step)) - move_sum = (int32_t) global_sum_step / 2; - else if (unlikely(n < -(int32_t) global_sum_step)) - move_sum = -((int32_t) global_sum_step / 2); - n -= move_sum; + if (unlikely(global_sum_step)) { + if (unlikely(n > (int32_t) global_sum_step)) + move_sum = (int32_t) global_sum_step / 2; + else if (unlikely(n < -(int32_t) global_sum_step)) + move_sum = -((int32_t) global_sum_step / 2); + n -= move_sum; + } res = cmpxchg_local(int_p, old, n); } while (old != res); break; @@ -187,11 +193,13 @@ static __always_inline int __lttng_counter_add(const struct lib_counter_config * move_sum = 0; old = res; n = (int64_t) ((uint64_t) old + (uint64_t) v); - if (unlikely(n > (int64_t) global_sum_step)) - move_sum = (int64_t) global_sum_step / 2; - else if (unlikely(n < -(int64_t) global_sum_step)) - move_sum = -((int64_t) global_sum_step / 2); - n -= move_sum; + if (unlikely(global_sum_step)) { + if (unlikely(n > (int64_t) global_sum_step)) + move_sum = (int64_t) global_sum_step / 2; + else if (unlikely(n < -(int64_t) global_sum_step)) + move_sum = -((int64_t) global_sum_step / 2); + n -= move_sum; + } res = cmpxchg_local(int_p, old, n); } while (old != res); break;