From patchwork Wed Jan 20 13:25:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 9999 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id A20698E59; Wed, 20 Jan 2016 14:25:44 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 3238C8DAF for ; Wed, 20 Jan 2016 14:25:43 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP; 20 Jan 2016 05:25:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,321,1449561600"; d="scan'208";a="636930562" Received: from sie-lab-212-120.ir.intel.com (HELO silpixa00394367.ir.intel.com) ([10.237.212.120]) by FMSMGA003.fm.intel.com with ESMTP; 20 Jan 2016 05:25:41 -0800 From: Harry van Haaren To: david.marchand@6wind.com Date: Wed, 20 Jan 2016 13:25:22 +0000 Message-Id: <1453296322-1210-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.5.0 Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH] eal: add function to check if primary proc alive X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds a new function to the EAL API: int rte_eal_primary_proc_alive(const char *path); The function indicates if a primary process is alive right now. This functionality is implemented by testing for a write- lock on the config file, and the function tests for a lock. The use case for this functionality is that a secondary process can wait until a primary process starts by polling the function and waiting. When the primary is running, the secondary continues to poll to detect if the primary process has quit unexpectedly, the secondary process can detect this. The RTE_MAGIC number is written to the shared config by the primary process, this is the signal to the secondary process that the EAL is set up, and ready to be used. The function rte_eal_mcfg_complete() writes RTE_MAGIC. This has been delayed in the EAL init proceedure, as the PCI probing in the primary process can interfere with the secondary running. Signed-off-by: Harry van Haaren --- doc/guides/rel_notes/release_2_3.rst | 7 +++++++ lib/librte_eal/bsdapp/eal/rte_eal_version.map | 8 ++++++++ lib/librte_eal/common/include/rte_eal.h | 19 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 18 ++++++++++++++++-- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 7 +++++++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst index 99de186..14b5b06 100644 --- a/doc/guides/rel_notes/release_2_3.rst +++ b/doc/guides/rel_notes/release_2_3.rst @@ -11,6 +11,13 @@ Resolved Issues EAL ~~~ +* **Added rte_eal_primary_proc_alive() function** + + A new function ``rte_eal_primary_proc_alive()`` has been added + to allow the user to detect if a primary process is running. + Use cases for this feature include fault detection, and monitoring + using secondary processes. + Drivers ~~~~~~~ diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 9d7adf1..0e28017 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -135,3 +135,11 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + + +DPDK_2.3 { + global: + + rte_eal_primary_proc_alive; + +} DPDK_2.2; diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h index d2816a8..6eb65f9 100644 --- a/lib/librte_eal/common/include/rte_eal.h +++ b/lib/librte_eal/common/include/rte_eal.h @@ -156,6 +156,25 @@ int rte_eal_iopl_init(void); * - On failure, a negative error value. */ int rte_eal_init(int argc, char **argv); + +/** + * Check if a primary process is currently alive + * + * This function returns true when a primary process is currently + * active. + * + * @param config_file_path + * The config_file_path argument provided should point at the location + * that the primary process will create its config file. By default, + * /var/run/.rte_config is used. This path can be customized when starting + * a primary process using --file-prefix=custom_path + * + * @return + * - If alive, returns one. + * - If dead, returns zero. + */ +int rte_eal_primary_proc_alive(const char *config_file_path); + /** * Usage function typedef used by the application usage function. * diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 635ec36..b419066 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -818,8 +818,6 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - rte_eal_mcfg_complete(); - if (eal_plugins_init() < 0) rte_panic("Cannot init plugins\n"); @@ -877,9 +875,25 @@ rte_eal_init(int argc, char **argv) if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); + rte_eal_mcfg_complete(); + return fctret; } +int +rte_eal_primary_proc_alive(const char *config_file_path) +{ + int config_fd; + config_fd = open(config_file_path, O_RDONLY); + if (config_fd < 0) + return 0; + + int ret = lockf(config_fd, F_TEST, 0); + close(config_fd); + + return !!ret; +} + /* get core role */ enum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id) diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index cbe175f..7a8c530 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -138,3 +138,10 @@ DPDK_2.2 { rte_xen_dom0_supported; } DPDK_2.1; + +DPDK_2.3 { + global: + + rte_eal_primary_proc_alive; + +} DPDK_2.2;