From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 3FA907D10 for ; Tue, 15 Aug 2017 14:32:58 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Aug 2017 05:32:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,377,1498546800"; d="scan'208";a="139790205" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by fmsmga005.fm.intel.com with ESMTP; 15 Aug 2017 05:32:57 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren Date: Tue, 15 Aug 2017 13:32:39 +0100 Message-Id: <1502800360-15782-8-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502800360-15782-1-git-send-email-harry.van.haaren@intel.com> References: <1502800360-15782-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH 7/8] service: rework get by name function to use id 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, 15 Aug 2017 12:32:59 -0000 This commit reworks the service_get_by_name() function to accept an integer, and removes the service_get_by_id() function. All functions now accept an integer argument representing the service, so it is no longer required to expose the service_spec pointers to the application. Signed-off-by: Harry van Haaren --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/include/rte_service.h | 45 ++++++++++--------------- lib/librte_eal/common/rte_service.c | 24 ++++--------- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + test/test/test_service_cores.c | 30 ++++++++++------- 5 files changed, 43 insertions(+), 58 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index f76d1ea..97113e2 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -216,6 +216,7 @@ EXPERIMENTAL { rte_service_get_by_id; rte_service_get_by_name; rte_service_get_count; + rte_service_get_name; rte_service_lcore_add; rte_service_lcore_count; rte_service_lcore_del; diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h index afa6c0bf..e06b075 100644 --- a/lib/librte_eal/common/include/rte_service.h +++ b/lib/librte_eal/common/include/rte_service.h @@ -61,9 +61,6 @@ extern "C" { #include -/* forward declaration only. Definition in rte_service_private.h */ -struct rte_service_spec; - #define RTE_SERVICE_NAME_MAX 32 /* Capabilities of a service. @@ -89,40 +86,32 @@ struct rte_service_spec; */ uint32_t rte_service_get_count(void); - /** * @warning * @b EXPERIMENTAL: this API may change without prior notice * - * Return the specification of a service by integer id. - * - * This function provides the specification of a service. This can be used by - * the application to understand what the service represents. The service - * must not be modified by the application directly, only passed to the various - * rte_service_* functions. - * - * @param id The integer id of the service to retrieve - * @retval non-zero A valid pointer to the service_spec - * @retval NULL Invalid *id* provided. - */ -struct rte_service_spec *rte_service_get_by_id(uint32_t id); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice + * Return the id of a service by name. * - * Return the specification of a service by name. + * This function provides the id of the service using the service name as + * lookup key. The service id is to be passed to other functions in the + * rte_service_* API. * - * This function provides the specification of a service using the service name - * as lookup key. This can be used by the application to understand what the - * service represents. The service must not be modified by the application - * directly, only passed to the various rte_service_* functions. + * Example usage: + * @code + * uint32_t service_id; + * int32_t ret = rte_service_get_by_name("service_X", &service_id); + * if (ret) { + * // handle error + * } + * @endcode * * @param name The name of the service to retrieve - * @retval non-zero A valid pointer to the service_spec - * @retval NULL Invalid *name* provided. + * @param[out] service_id A pointer to a uint32_t, to be filled in with the id. + * @retval 0 Success. The service id is provided in *service_id*. + * @retval -EINVAL Null *service_id* pointer provided + * @retval -ENODEV No such service registered */ -struct rte_service_spec *rte_service_get_by_name(const char *name); +int32_t rte_service_get_by_name(const char *name, uint32_t *service_id); /** * @warning diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index 7299514..7a825b7 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -185,29 +185,21 @@ rte_service_get_count(void) return rte_service_count; } -struct rte_service_spec * -rte_service_get_by_id(uint32_t id) +int32_t rte_service_get_by_name(const char *name, uint32_t *service_id) { - struct rte_service_spec *service = NULL; - if (id < rte_service_count) - service = (struct rte_service_spec *)&rte_services[id]; - - return service; -} + if (!service_id) + return -EINVAL; -struct rte_service_spec *rte_service_get_by_name(const char *name) -{ - struct rte_service_spec *service = NULL; int i; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { if (service_valid(i) && strcmp(name, rte_services[i].spec.name) == 0) { - service = (struct rte_service_spec *)&rte_services[i]; - break; + *service_id = i; + return 0; } } - return service; + return -ENODEV; } const char * @@ -406,10 +398,6 @@ rte_service_start_with_defaults(void) rte_service_lcore_start(ids[i]); for (i = 0; i < count; i++) { - struct rte_service_spec *s = rte_service_get_by_id(i); - if (!s) - return -EINVAL; - /* do 1:1 core mapping here, with each service getting * assigned a single core by default. Adding multiple services * should multiplex to a single core, or 1:1 if there are the diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 557b5e7..d179fa5 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -221,6 +221,7 @@ EXPERIMENTAL { rte_service_get_by_id; rte_service_get_by_name; rte_service_get_count; + rte_service_get_name; rte_service_lcore_add; rte_service_lcore_count; rte_service_lcore_del; diff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c index 43ad027..ff8dcb1 100644 --- a/test/test/test_service_cores.c +++ b/test/test/test_service_cores.c @@ -176,9 +176,13 @@ service_get_by_name(void) { unregister_all(); - /* ensure with no services registered returns NULL */ - TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME), - "Service get by name should return NULL"); + uint32_t sid; + TEST_ASSERT_EQUAL(-ENODEV, + rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid), + "get by name with invalid name should return -ENODEV"); + TEST_ASSERT_EQUAL(-EINVAL, + rte_service_get_by_name(DUMMY_SERVICE_NAME, 0x0), + "get by name with NULL ptr should return -ENODEV"); /* register service */ struct rte_service_spec service; @@ -192,16 +196,19 @@ service_get_by_name(void) TEST_ASSERT_EQUAL(0, rte_service_register(&service, NULL), "Failed to register valid service"); - /* ensure with dummy services registered returns same ptr as ID */ - struct rte_service_spec *s_by_id = rte_service_get_by_id(0); - TEST_ASSERT_EQUAL(s_by_id, rte_service_get_by_name(DUMMY_SERVICE_NAME), - "Service get_by_name should equal get_by_id()"); + /* we unregistered all service, now registering 1, should be id 0 */ + uint32_t service_id_as_expected = 0; + TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid), + "Service get_by_name should return 0 on valid inputs"); + TEST_ASSERT_EQUAL(service_id_as_expected, sid, + "Service get_by_name should equal expected id"); unregister_all(); /* ensure after unregister, get_by_name returns NULL */ - TEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME), - "get by name should return NULL after unregister"); + TEST_ASSERT_EQUAL(-ENODEV, + rte_service_get_by_name(DUMMY_SERVICE_NAME, &sid), + "get by name should return -ENODEV after unregister"); return TEST_SUCCESS; } @@ -245,9 +252,8 @@ service_probe_capability(void) static int service_name(void) { - struct rte_service_spec *service = rte_service_get_by_id(0); - - int equal = strcmp(service->name, DUMMY_SERVICE_NAME); + const char *name = rte_service_get_name(0); + int equal = strcmp(name, DUMMY_SERVICE_NAME); TEST_ASSERT_EQUAL(0, equal, "Error: Service name not correct"); return unregister_all(); -- 2.7.4