From patchwork Mon Aug 21 12:58:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 27686 X-Patchwork-Delegate: thomas@monjalon.net 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 588B97D3B; Mon, 21 Aug 2017 14:58:32 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id D93617D12 for ; Mon, 21 Aug 2017 14:58:29 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP; 21 Aug 2017 05:58:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,409,1498546800"; d="scan'208"; a="1208383273" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by fmsmga002.fm.intel.com with ESMTP; 21 Aug 2017 05:58:28 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren Date: Mon, 21 Aug 2017 13:58:04 +0100 Message-Id: <1503320296-51122-4-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503320296-51122-1-git-send-email-harry.van.haaren@intel.com> References: <1502800360-15782-1-git-send-email-harry.van.haaren@intel.com> <1503320296-51122-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH v2 03/15] service: rework register to return service 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit reworks the service register function to accept an extra parameter. The parameter is a uint32_t *, which when provided will be set to the integer service_id that the newly registered service is represented by. This is useful for services that wish to validate settings at a later point in time - they need to know their own service id. This commit updates the eventdev sw pmd, as well as unit tests to use the new register API. Signed-off-by: Harry van Haaren --- v2: - Rename rte_service_register to rte_service_component_register This makes it clearer which APIs apply to components vs services. --- drivers/event/sw/sw_evdev.c | 4 +-- drivers/event/sw/sw_evdev.h | 1 + lib/librte_eal/bsdapp/eal/rte_eal_version.map | 2 +- .../common/include/rte_service_component.h | 6 +++- lib/librte_eal/common/rte_service.c | 6 +++- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 2 +- test/test/test_service_cores.c | 36 ++++++++++++---------- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c index 9c534b7..9cc63a0 100644 --- a/drivers/event/sw/sw_evdev.c +++ b/drivers/event/sw/sw_evdev.c @@ -620,7 +620,7 @@ sw_start(struct rte_eventdev *dev) struct rte_service_spec *s = rte_service_get_by_name(sw->service_name); if (!rte_service_is_running(s)) SW_LOG_ERR("Warning: No Service core enabled on service %s\n", - s->name); + sw->service_name); /* check all ports are set up */ for (i = 0; i < sw->port_count; i++) @@ -855,7 +855,7 @@ sw_probe(struct rte_vdev_device *vdev) service.callback = sw_sched_service_func; service.callback_userdata = (void *)dev; - int32_t ret = rte_service_register(&service); + int32_t ret = rte_service_component_register(&service, &sw->service_id); if (ret) { SW_LOG_ERR("service register() failed"); return -ENOEXEC; diff --git a/drivers/event/sw/sw_evdev.h b/drivers/event/sw/sw_evdev.h index 71de3c1..e0dec91 100644 --- a/drivers/event/sw/sw_evdev.h +++ b/drivers/event/sw/sw_evdev.h @@ -278,6 +278,7 @@ struct sw_evdev { uint16_t xstats_count_per_qid[RTE_EVENT_MAX_QUEUES_PER_DEV]; uint16_t xstats_offset_for_qid[RTE_EVENT_MAX_QUEUES_PER_DEV]; + uint32_t service_id; char service_name[SW_PMD_NAME_MAX]; }; diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index f626a6f..2b1089d 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -212,6 +212,7 @@ EXPERIMENTAL { rte_eal_devargs_remove; rte_eal_hotplug_add; rte_eal_hotplug_remove; + rte_service_component_register; rte_service_dump; rte_service_get_by_id; rte_service_get_by_name; @@ -227,7 +228,6 @@ EXPERIMENTAL { rte_service_map_lcore_get; rte_service_map_lcore_set; rte_service_probe_capability; - rte_service_register; rte_service_reset; rte_service_set_stats_enable; rte_service_start; diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h index 7a946a1..6ef3ee4 100644 --- a/lib/librte_eal/common/include/rte_service_component.h +++ b/lib/librte_eal/common/include/rte_service_component.h @@ -89,11 +89,15 @@ struct rte_service_spec { * *rte_service_set_coremask*. * * @param spec The specification of the service to register + * @param[out] service_id A pointer to a uint32_t, which will be filled in + * during registration of the service. It is set to the integers + * service number given to the service. This parameter may be NULL. * @retval 0 Successfully registered the service. * -EINVAL Attempted to register an invalid service (eg, no callback * set) */ -int32_t rte_service_register(const struct rte_service_spec *spec); +int32_t rte_service_component_register(const struct rte_service_spec *spec, + uint32_t *service_id); /** * @warning diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index c5a8d0d..152eafe 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -242,7 +242,8 @@ rte_service_is_running(const struct rte_service_spec *spec) } int32_t -rte_service_register(const struct rte_service_spec *spec) +rte_service_component_register(const struct rte_service_spec *spec, + uint32_t *id_ptr) { uint32_t i; int32_t free_slot = -1; @@ -267,6 +268,9 @@ rte_service_register(const struct rte_service_spec *spec) rte_smp_wmb(); rte_service_count++; + if (id_ptr) + *id_ptr = free_slot; + return 0; } diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 452ae1c..336e40e 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -217,6 +217,7 @@ EXPERIMENTAL { rte_eal_devargs_remove; rte_eal_hotplug_add; rte_eal_hotplug_remove; + rte_service_component_register; rte_service_dump; rte_service_get_by_id; rte_service_get_by_name; @@ -232,7 +233,6 @@ EXPERIMENTAL { rte_service_map_lcore_get; rte_service_map_lcore_set; rte_service_probe_capability; - rte_service_register; rte_service_reset; rte_service_set_stats_enable; rte_service_start; diff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c index fd63efd..7767fa2 100644 --- a/test/test/test_service_cores.c +++ b/test/test/test_service_cores.c @@ -160,15 +160,17 @@ dummy_register(void) struct rte_service_spec service; memset(&service, 0, sizeof(struct rte_service_spec)); - TEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service), + TEST_ASSERT_EQUAL(-EINVAL, + rte_service_component_register(&service, NULL), "Invalid callback"); service.callback = dummy_cb; - TEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service), + TEST_ASSERT_EQUAL(-EINVAL, + rte_service_component_register(&service, NULL), "Invalid name"); snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME); - TEST_ASSERT_EQUAL(0, rte_service_register(&service), + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL), "Failed to register valid service"); return TEST_SUCCESS; @@ -187,13 +189,15 @@ service_get_by_name(void) /* register service */ struct rte_service_spec service; memset(&service, 0, sizeof(struct rte_service_spec)); - TEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service), + TEST_ASSERT_EQUAL(-EINVAL, + rte_service_component_register(&service, NULL), "Invalid callback"); service.callback = dummy_cb; - TEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service), + TEST_ASSERT_EQUAL(-EINVAL, + rte_service_component_register(&service, NULL), "Invalid name"); snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME); - TEST_ASSERT_EQUAL(0, rte_service_register(&service), + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL), "Failed to register valid service"); /* ensure with dummy services registered returns same ptr as ID */ @@ -221,7 +225,7 @@ service_probe_capability(void) service.callback = dummy_cb; snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME); service.capabilities |= RTE_SERVICE_CAP_MT_SAFE; - TEST_ASSERT_EQUAL(0, rte_service_register(&service), + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL), "Register of MT SAFE service failed"); /* verify flag is enabled */ @@ -235,7 +239,7 @@ service_probe_capability(void) memset(&service, 0, sizeof(struct rte_service_spec)); service.callback = dummy_cb; snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME); - TEST_ASSERT_EQUAL(0, rte_service_register(&service), + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL), "Register of non-MT safe service failed"); /* verify flag is enabled */ @@ -274,28 +278,28 @@ static int service_start_stop(void) { const uint32_t sid = 0; - struct rte_service_spec *service = rte_service_get_by_id(0); + struct rte_service_spec *s = rte_service_get_by_id(0); - /* is_running() returns if service is running and slcore is mapped */ + /* runstate_get() returns if service is running and slcore is mapped */ TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id), "Service core add did not return zero"); int ret = rte_service_map_lcore_set(sid, slcore_id, 1); TEST_ASSERT_EQUAL(0, ret, "Enabling service core, expected 0 got %d", ret); - TEST_ASSERT_EQUAL(0, rte_service_is_running(service), + TEST_ASSERT_EQUAL(0, rte_service_is_running(s), "Error: Service should be stopped"); - TEST_ASSERT_EQUAL(0, rte_service_stop(service), + TEST_ASSERT_EQUAL(0, rte_service_stop(s), "Error: Service stopped returned non-zero"); - TEST_ASSERT_EQUAL(0, rte_service_is_running(service), + TEST_ASSERT_EQUAL(0, rte_service_is_running(s), "Error: Service is running - should be stopped"); - TEST_ASSERT_EQUAL(0, rte_service_start(service), + TEST_ASSERT_EQUAL(0, rte_service_start(s), "Error: Service start returned non-zero"); - TEST_ASSERT_EQUAL(1, rte_service_is_running(service), + TEST_ASSERT_EQUAL(1, rte_service_is_running(s), "Error: Service is not running"); return unregister_all(); @@ -471,7 +475,7 @@ service_threaded_test(int mt_safe) service.callback = dummy_mt_unsafe_cb; } - TEST_ASSERT_EQUAL(0, rte_service_register(&service), + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, NULL), "Register of MT SAFE service failed"); struct rte_service_spec *s = rte_service_get_by_id(0);