From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 225F9493D for ; Thu, 9 May 2019 21:41:21 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2019 12:41:21 -0700 X-ExtLoop1: 1 Received: from txasoft-yocto.an.intel.com ([10.123.72.192]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2019 12:41:20 -0700 From: Erik Gabriel Carrillo To: thomas@monjalon.net, anatoly.burakov@intel.com, rsanford@akamai.com Cc: dev@dpdk.org Date: Thu, 9 May 2019 14:39:36 -0500 Message-Id: <1557430776-16355-1-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1557353861-31997-1-git-send-email-erik.g.carrillo@intel.com> References: <1557353861-31997-1-git-send-email-erik.g.carrillo@intel.com> Subject: [dpdk-dev] [PATCH v2] 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: , X-List-Received-Date: Thu, 09 May 2019 19:41:22 -0000 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 --- changes in v2: - Try to do reserve first, then do lookup on EEXIST (Anatoly) - Fix uninitialized variable from first version lib/librte_timer/rte_timer.c | 56 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 9f2e921..dd79539 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 = true; 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; - - rte_timer_data_arr = mz->addr; - - rte_timer_data_arr[default_data_id].internal_flags |= - FL_ALLOCATED; - - rte_timer_subsystem_initialized = 1; - - return 0; +reserve: + rte_errno = 0; + 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) { + mz = rte_memzone_lookup(mz_name); + if (mz == NULL) + goto reserve; + + do_full_init = false; + } else + return -ENOMEM; } - 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; } -- 2.6.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id C4329A0096 for ; Thu, 9 May 2019 21:41:24 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BC9F649DF; Thu, 9 May 2019 21:41:23 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 225F9493D for ; Thu, 9 May 2019 21:41:21 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2019 12:41:21 -0700 X-ExtLoop1: 1 Received: from txasoft-yocto.an.intel.com ([10.123.72.192]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2019 12:41:20 -0700 From: Erik Gabriel Carrillo To: thomas@monjalon.net, anatoly.burakov@intel.com, rsanford@akamai.com Cc: dev@dpdk.org Date: Thu, 9 May 2019 14:39:36 -0500 Message-Id: <1557430776-16355-1-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1557353861-31997-1-git-send-email-erik.g.carrillo@intel.com> References: <1557353861-31997-1-git-send-email-erik.g.carrillo@intel.com> Subject: [dpdk-dev] [PATCH v2] 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190509193936.TXOxT_QdKX0j9XpCAc1rQeHHJFeABJpOjquKl7QB2T4@z> 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 --- changes in v2: - Try to do reserve first, then do lookup on EEXIST (Anatoly) - Fix uninitialized variable from first version lib/librte_timer/rte_timer.c | 56 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 9f2e921..dd79539 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 = true; 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; - - rte_timer_data_arr = mz->addr; - - rte_timer_data_arr[default_data_id].internal_flags |= - FL_ALLOCATED; - - rte_timer_subsystem_initialized = 1; - - return 0; +reserve: + rte_errno = 0; + 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) { + mz = rte_memzone_lookup(mz_name); + if (mz == NULL) + goto reserve; + + do_full_init = false; + } else + return -ENOMEM; } - 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; } -- 2.6.4