The __rte_cache_aligned was applied to the whole array,
not the array elements. This leads to a false sharing between
the monitored cores.

Fixes: e70a61ad50ab ("keepalive: export states")
Cc: remy.hor...@intel.com
Signed-off-by: Andriy Berestovskyy <a...@semihalf.com>
---
 lib/librte_eal/common/rte_keepalive.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lib/librte_eal/common/rte_keepalive.c 
b/lib/librte_eal/common/rte_keepalive.c
index 7ddf201..a586e03 100644
--- a/lib/librte_eal/common/rte_keepalive.c
+++ b/lib/librte_eal/common/rte_keepalive.c
@@ -13,8 +13,13 @@
 
 struct rte_keepalive {
        /** Core Liveness. */
-       enum rte_keepalive_state __rte_cache_aligned state_flags[
-               RTE_KEEPALIVE_MAXCORES];
+       struct {
+               /*
+                * Each element of the state_flags table must be cache aligned
+                * to prevent false sharing.
+                */
+               enum rte_keepalive_state s __rte_cache_aligned;
+       } state_flags[RTE_KEEPALIVE_MAXCORES];
 
        /** Last-seen-alive timestamps */
        uint64_t last_alive[RTE_KEEPALIVE_MAXCORES];
@@ -67,19 +72,19 @@ rte_keepalive_dispatch_pings(__rte_unused void *ptr_timer,
                if (keepcfg->active_cores[idx_core] == 0)
                        continue;
 
-               switch (keepcfg->state_flags[idx_core]) {
+               switch (keepcfg->state_flags[idx_core].s) {
                case RTE_KA_STATE_UNUSED:
                        break;
                case RTE_KA_STATE_ALIVE: /* Alive */
-                       keepcfg->state_flags[idx_core] = RTE_KA_STATE_MISSING;
+                       keepcfg->state_flags[idx_core].s = RTE_KA_STATE_MISSING;
                        keepcfg->last_alive[idx_core] = rte_rdtsc();
                        break;
                case RTE_KA_STATE_MISSING: /* MIA */
                        print_trace("Core MIA. ", keepcfg, idx_core);
-                       keepcfg->state_flags[idx_core] = RTE_KA_STATE_DEAD;
+                       keepcfg->state_flags[idx_core].s = RTE_KA_STATE_DEAD;
                        break;
                case RTE_KA_STATE_DEAD: /* Dead */
-                       keepcfg->state_flags[idx_core] = RTE_KA_STATE_GONE;
+                       keepcfg->state_flags[idx_core].s = RTE_KA_STATE_GONE;
                        print_trace("Core died. ", keepcfg, idx_core);
                        if (keepcfg->callback)
                                keepcfg->callback(
@@ -90,7 +95,7 @@ rte_keepalive_dispatch_pings(__rte_unused void *ptr_timer,
                case RTE_KA_STATE_GONE: /* Buried */
                        break;
                case RTE_KA_STATE_DOZING: /* Core going idle */
-                       keepcfg->state_flags[idx_core] = RTE_KA_STATE_SLEEP;
+                       keepcfg->state_flags[idx_core].s = RTE_KA_STATE_SLEEP;
                        keepcfg->last_alive[idx_core] = rte_rdtsc();
                        break;
                case RTE_KA_STATE_SLEEP: /* Idled core */
@@ -100,7 +105,7 @@ rte_keepalive_dispatch_pings(__rte_unused void *ptr_timer,
                        keepcfg->relay_callback(
                                keepcfg->relay_callback_data,
                                idx_core,
-                               keepcfg->state_flags[idx_core],
+                               keepcfg->state_flags[idx_core].s,
                                keepcfg->last_alive[idx_core]
                                );
        }
@@ -144,11 +149,11 @@ rte_keepalive_register_core(struct rte_keepalive 
*keepcfg, const int id_core)
 void
 rte_keepalive_mark_alive(struct rte_keepalive *keepcfg)
 {
-       keepcfg->state_flags[rte_lcore_id()] = RTE_KA_STATE_ALIVE;
+       keepcfg->state_flags[rte_lcore_id()].s = RTE_KA_STATE_ALIVE;
 }
 
 void
 rte_keepalive_mark_sleep(struct rte_keepalive *keepcfg)
 {
-       keepcfg->state_flags[rte_lcore_id()] = RTE_KA_STATE_DOZING;
+       keepcfg->state_flags[rte_lcore_id()].s = RTE_KA_STATE_DOZING;
 }
-- 
2.7.4

Reply via email to