From patchwork Wed May 8 22:17:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Carrillo, Erik G" X-Patchwork-Id: 53333 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2DAB534F0; Thu, 9 May 2019 00:19:18 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 398F02082 for ; Thu, 9 May 2019 00:19:16 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2019 15:19:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,447,1549958400"; d="scan'208";a="169779023" Received: from txasoft-yocto.an.intel.com ([10.123.72.192]) by fmsmga002.fm.intel.com with ESMTP; 08 May 2019 15:19:13 -0700 From: Erik Gabriel Carrillo To: rsanford@akamai.com, thomas@monjalon.net Cc: anatoly.burakov@intel.com, dev@dpdk.org Date: Wed, 8 May 2019 17:17:41 -0500 Message-Id: <1557353861-31997-1-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 Subject: [dpdk-dev] [PATCH] timer: allow first subsystem init from secondary 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Since memzones can be reserved from secondary processes as well as primary processes, if the first call to the timer subsystem init function occurs in a secondary process, we should allow it to succeed. Fixes: c0749f7096c7 ("timer: allow management in shared memory") Signed-off-by: Erik Gabriel Carrillo --- lib/librte_timer/rte_timer.c | 52 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 9f2e921..c0f5b87 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "rte_timer.h" @@ -155,40 +156,41 @@ rte_timer_subsystem_init_v1905(void) struct rte_timer_data *data; int i, lcore_id; static const char *mz_name = "rte_timer_mz"; + const size_t data_arr_size = + RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr); + bool do_full_init; if (rte_timer_subsystem_initialized) return -EALREADY; - if (rte_eal_process_type() != RTE_PROC_PRIMARY) { - mz = rte_memzone_lookup(mz_name); - if (mz == NULL) - return -EEXIST; +lookup: + mz = rte_memzone_lookup(mz_name); + if (mz == NULL) { + mz = rte_memzone_reserve_aligned(mz_name, data_arr_size, + SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE); + if (mz == NULL) { + if (rte_errno == EEXIST) + goto lookup; - rte_timer_data_arr = mz->addr; - - rte_timer_data_arr[default_data_id].internal_flags |= - FL_ALLOCATED; - - rte_timer_subsystem_initialized = 1; + return -ENOMEM; + } - return 0; + do_full_init = true; } - mz = rte_memzone_reserve_aligned(mz_name, - RTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr), - SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE); - if (mz == NULL) - return -ENOMEM; - rte_timer_data_arr = mz->addr; - for (i = 0; i < RTE_MAX_DATA_ELS; i++) { - data = &rte_timer_data_arr[i]; + if (do_full_init) { + for (i = 0; i < RTE_MAX_DATA_ELS; i++) { + data = &rte_timer_data_arr[i]; - for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { - rte_spinlock_init( - &data->priv_timer[lcore_id].list_lock); - data->priv_timer[lcore_id].prev_lcore = lcore_id; + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; + lcore_id++) { + rte_spinlock_init( + &data->priv_timer[lcore_id].list_lock); + data->priv_timer[lcore_id].prev_lcore = + lcore_id; + } } } @@ -205,8 +207,8 @@ BIND_DEFAULT_SYMBOL(rte_timer_subsystem_init, _v1905, 19.05); void __rte_experimental rte_timer_subsystem_finalize(void) { - if (rte_timer_data_arr) - rte_free(rte_timer_data_arr); + if (!rte_timer_subsystem_initialized) + return; rte_timer_subsystem_initialized = 0; }