From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 7D170A493 for ; Tue, 23 Jan 2018 16:43:36 +0100 (CET) Received: by mail-wm0-f66.google.com with SMTP id 141so2761805wme.3 for ; Tue, 23 Jan 2018 07:43:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ShJcU065WfuPdBwvd0HoPWscAUca7HfPg4jnNqh+q+I=; b=leucNhGCpXfjMaEdTOYrUdIMlyAMJZPGP71rx94zjLG/v4VMPfVBWQJNJkb79wKkgg yOADejGSb9BTTs7RaS/EtEJnMRBwZ0/EiWA2tfhTwkhL82vZQC2D7LbyRh3RyJ9UNuRP BW7iIjw8Y3Jm+e/0fdH4ZRdHjYnFH1FnrHKZp7dKU3n4l1R9g3t6F5Zh6RCaVYfXPjcc VVZVmdvanY4CvDdzWXnhUbRV8FqJzb+eyVlrQ/IjilVgbYs2o08mtVRWnlZad84oJRfu E0CMuolLtER0RKSCqYk7VN30+/q6l0er83MYX+l9LIWqfbu2SHPPh0MCe89c+bTZKoS+ 4Xig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ShJcU065WfuPdBwvd0HoPWscAUca7HfPg4jnNqh+q+I=; b=q2eDPu7QiWEZdL/nLGmr+O5wLd/S6xCeFFBBuYlZkvkcWLPJACjfMVyeq4vrImBTcF 7eGszt8i2hbucIrzaeYX5/vF81J0kMUIU8LssqHeyb+A3Xzqn8P1FlXGnK3aQVqMM+UK V8nd0SfazW5a4qV+4lXgyHLFHeg4jAOrg/kS+2baIknY8QLjkWthPqlwBFMcfDnyRUjz HroC2RIYQE6yoHfDLYrpzSmnONDi9zw6FoKlJwZN9KEuY9U/MtWfzQFnAU6Phq4sqjwz Y23ME9RfcEQXuTx+e6ZujKg0SWqvIOLKoa8YNBXMWkQQDflBjN1rKkwaPYvQKyROUEIW oHfg== X-Gm-Message-State: AKwxytdQXeyP94it9oN29ZUK1XT6/woyI2zeGBkDOn5wqNwHrJ1hHv5T d34zjrlZ9AGVhbU5ts0vmLZONQ9ct50= X-Google-Smtp-Source: AH8x225jAgdQr46KST/Smus5qssx3H0X06iDy/3FRAQbMF0GOyaC1RrDzPIS6xAOgIWxmqjagcocnw== X-Received: by 10.80.167.161 with SMTP id i30mr19788404edc.26.1516722215678; Tue, 23 Jan 2018 07:43:35 -0800 (PST) Received: from b.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id r4sm12103991edd.80.2018.01.23.07.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 07:43:35 -0800 (PST) From: Andriy Berestovskyy To: dev@dpdk.org Cc: remy.horton@intel.com Date: Tue, 23 Jan 2018 16:43:16 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: <16d055c21f6c9e3788fff1a9ecef12d1449d7305.1516373207.git.aber@semihalf.com> References: <16d055c21f6c9e3788fff1a9ecef12d1449d7305.1516373207.git.aber@semihalf.com> Subject: [dpdk-dev] [PATCH v2] keepalive: fix keepalive state alignment X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jan 2018 15:43:36 -0000 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.horton@intel.com Signed-off-by: Andriy Berestovskyy --- Notes (changelog): V2 Changes: - fixed struct name - fixed documentation doc/guides/sample_app_ug/keep_alive.rst | 2 +- lib/librte_eal/common/rte_keepalive.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/doc/guides/sample_app_ug/keep_alive.rst b/doc/guides/sample_app_ug/keep_alive.rst index 38856d2..27ed2a8 100644 --- a/doc/guides/sample_app_ug/keep_alive.rst +++ b/doc/guides/sample_app_ug/keep_alive.rst @@ -168,5 +168,5 @@ The rte_keepalive_mark_alive function simply sets the core state to alive. static inline void rte_keepalive_mark_alive(struct rte_keepalive *keepcfg) { - keepcfg->state_flags[rte_lcore_id()] = ALIVE; + keepcfg->live_data[rte_lcore_id()].core_state = RTE_KA_STATE_ALIVE; } diff --git a/lib/librte_eal/common/rte_keepalive.c b/lib/librte_eal/common/rte_keepalive.c index 7ddf201..e0494b2 100644 --- a/lib/librte_eal/common/rte_keepalive.c +++ b/lib/librte_eal/common/rte_keepalive.c @@ -13,8 +13,12 @@ struct rte_keepalive { /** Core Liveness. */ - enum rte_keepalive_state __rte_cache_aligned state_flags[ - RTE_KEEPALIVE_MAXCORES]; + struct { + /* + * Each element must be cache aligned to prevent false sharing. + */ + enum rte_keepalive_state core_state __rte_cache_aligned; + } live_data[RTE_KEEPALIVE_MAXCORES]; /** Last-seen-alive timestamps */ uint64_t last_alive[RTE_KEEPALIVE_MAXCORES]; @@ -67,19 +71,22 @@ 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->live_data[idx_core].core_state) { case RTE_KA_STATE_UNUSED: break; case RTE_KA_STATE_ALIVE: /* Alive */ - keepcfg->state_flags[idx_core] = RTE_KA_STATE_MISSING; + keepcfg->live_data[idx_core].core_state = + 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->live_data[idx_core].core_state = + RTE_KA_STATE_DEAD; break; case RTE_KA_STATE_DEAD: /* Dead */ - keepcfg->state_flags[idx_core] = RTE_KA_STATE_GONE; + keepcfg->live_data[idx_core].core_state = + RTE_KA_STATE_GONE; print_trace("Core died. ", keepcfg, idx_core); if (keepcfg->callback) keepcfg->callback( @@ -90,7 +97,8 @@ 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->live_data[idx_core].core_state = + RTE_KA_STATE_SLEEP; keepcfg->last_alive[idx_core] = rte_rdtsc(); break; case RTE_KA_STATE_SLEEP: /* Idled core */ @@ -100,7 +108,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->live_data[idx_core].core_state, keepcfg->last_alive[idx_core] ); } @@ -144,11 +152,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->live_data[rte_lcore_id()].core_state = RTE_KA_STATE_ALIVE; } void rte_keepalive_mark_sleep(struct rte_keepalive *keepcfg) { - keepcfg->state_flags[rte_lcore_id()] = RTE_KA_STATE_DOZING; + keepcfg->live_data[rte_lcore_id()].core_state = RTE_KA_STATE_DOZING; } -- 2.7.4