From: Harry van Haaren Date: Mon, 21 Aug 2017 12:58:03 +0000 (+0100) Subject: service: use id in lcore to service map functions X-Git-Tag: spdx-start~2168 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=519d2e3b3d99e2226084145a134828f7eb2b29ae;p=dpdk.git service: use id in lcore to service map functions This commit updates the APIs exposed to map service cores and services. The previous APIs required a pointer to a service, and used two separate functions for enable and disable. The new API uses an integer ID for the service and has a parameter for map or unmap. Unit tests are updated and passing, and the map file is updated to the new function names. Signed-off-by: Harry van Haaren Acked-by: Pavan Nikhilesh --- diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 79e7d3197e..6668e0278b 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -212,13 +212,10 @@ EXPERIMENTAL { rte_eal_devargs_remove; rte_eal_hotplug_add; rte_eal_hotplug_remove; - rte_service_disable_on_lcore; rte_service_dump; - rte_service_enable_on_lcore; rte_service_get_by_id; rte_service_get_by_name; rte_service_get_count; - rte_service_get_enabled_on_lcore; rte_service_is_running; rte_service_lcore_add; rte_service_lcore_count; @@ -228,6 +225,8 @@ EXPERIMENTAL { rte_service_lcore_reset_all; rte_service_lcore_start; rte_service_lcore_stop; + rte_service_map_lcore_get; + rte_service_map_lcore_set; rte_service_probe_capability; rte_service_register; rte_service_reset; diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h index 74b828a9b2..2237d1ea92 100644 --- a/lib/librte_eal/common/include/rte_service.h +++ b/lib/librte_eal/common/include/rte_service.h @@ -152,10 +152,10 @@ int32_t rte_service_probe_capability(uint32_t id, uint32_t capability); * @warning * @b EXPERIMENTAL: this API may change without prior notice * - * Enable a core to run a service. + * Map or unmap a lcore to a service. * - * Each core can be added or removed from running specific services. This - * functions adds *lcore* to the set of cores that will run *service*. + * Each core can be added or removed from running a specific service. This + * function enables or disables *lcore* to run *service_id*. * * If multiple cores are enabled on a service, an atomic is used to ensure that * only one cores runs the service at a time. The exception to this is when @@ -163,43 +163,30 @@ int32_t rte_service_probe_capability(uint32_t id, uint32_t capability); * called RTE_SERVICE_CAP_MT_SAFE. With the multi-thread safe capability set, * the service function can be run on multiple threads at the same time. * - * @retval 0 lcore added successfully - * @retval -EINVAL An invalid service or lcore was provided. - */ -int32_t rte_service_enable_on_lcore(struct rte_service_spec *service, - uint32_t lcore); - -/** - * @warning - * @b EXPERIMENTAL: this API may change without prior notice - * - * Disable a core to run a service. + * @param service_id the service to apply the lcore to + * @param lcore The lcore that will be mapped to service + * @param enable Zero to unmap or disable the core, non-zero to enable * - * Each core can be added or removed from running specific services. This - * functions removes *lcore* to the set of cores that will run *service*. - * - * @retval 0 Lcore removed successfully + * @retval 0 lcore map updated successfully * @retval -EINVAL An invalid service or lcore was provided. */ -int32_t rte_service_disable_on_lcore(struct rte_service_spec *service, - uint32_t lcore); +int32_t rte_service_map_lcore_set(uint32_t service_id, uint32_t lcore, + uint32_t enable); /** * @warning * @b EXPERIMENTAL: this API may change without prior notice * - * Return if an lcore is enabled for the service. + * Retrieve the mapping of an lcore to a service. * - * This function allows the application to query if *lcore* is currently set to - * run *service*. + * @param service_id the service to apply the lcore to + * @param lcore The lcore that will be mapped to service * - * @retval 1 Lcore enabled on this lcore - * @retval 0 Lcore disabled on this lcore + * @retval 1 lcore is mapped to service + * @retval 0 lcore is not mapped to service * @retval -EINVAL An invalid service or lcore was provided. */ -int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service, - uint32_t lcore); - +int32_t rte_service_map_lcore_get(uint32_t service_id, uint32_t lcore); /** * @warning diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index f7aa3e91e1..1bf221ddc8 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -449,7 +449,7 @@ rte_service_start_with_defaults(void) * should multiplex to a single core, or 1:1 if there are the * same amount of services as service-cores */ - ret = rte_service_enable_on_lcore(s, ids[lcore_iter]); + ret = rte_service_map_lcore_set(i, ids[lcore_iter], 1); if (ret) return -ENODEV; @@ -505,28 +505,25 @@ service_update(struct rte_service_spec *service, uint32_t lcore, return 0; } -int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service, - uint32_t lcore) -{ - uint32_t enabled; - int ret = service_update(service, lcore, 0, &enabled); - if (ret == 0) - return enabled; - return -EINVAL; -} - int32_t -rte_service_enable_on_lcore(struct rte_service_spec *service, uint32_t lcore) +rte_service_map_lcore_set(uint32_t id, uint32_t lcore, uint32_t enabled) { - uint32_t on = 1; - return service_update(service, lcore, &on, 0); + struct rte_service_spec_impl *s; + SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); + uint32_t on = enabled > 0; + return service_update(&s->spec, lcore, &on, 0); } int32_t -rte_service_disable_on_lcore(struct rte_service_spec *service, uint32_t lcore) +rte_service_map_lcore_get(uint32_t id, uint32_t lcore) { - uint32_t off = 0; - return service_update(service, lcore, &off, 0); + struct rte_service_spec_impl *s; + SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); + uint32_t enabled; + int ret = service_update(&s->spec, lcore, 0, &enabled); + if (ret == 0) + return enabled; + return ret; } int32_t rte_service_lcore_reset_all(void) diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 468c706ab3..054feb4ed5 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -217,13 +217,10 @@ EXPERIMENTAL { rte_eal_devargs_remove; rte_eal_hotplug_add; rte_eal_hotplug_remove; - rte_service_disable_on_lcore; rte_service_dump; - rte_service_enable_on_lcore; rte_service_get_by_id; rte_service_get_by_name; rte_service_get_count; - rte_service_get_enabled_on_lcore; rte_service_is_running; rte_service_lcore_add; rte_service_lcore_count; @@ -233,6 +230,8 @@ EXPERIMENTAL { rte_service_lcore_reset_all; rte_service_lcore_start; rte_service_lcore_stop; + rte_service_map_lcore_get; + rte_service_map_lcore_set; rte_service_probe_capability; rte_service_register; rte_service_reset; diff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c index 940bc62cec..fd63efdc05 100644 --- a/test/test/test_service_cores.c +++ b/test/test/test_service_cores.c @@ -273,12 +273,13 @@ service_dump(void) static int service_start_stop(void) { + const uint32_t sid = 0; struct rte_service_spec *service = rte_service_get_by_id(0); /* is_running() 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_enable_on_lcore(service, slcore_id); + int ret = rte_service_map_lcore_set(sid, slcore_id, 1); TEST_ASSERT_EQUAL(0, ret, "Enabling service core, expected 0 got %d", ret); @@ -313,12 +314,12 @@ service_remote_launch_func(void *arg) static int service_lcore_en_dis_able(void) { - struct rte_service_spec *s = rte_service_get_by_id(0); + const uint32_t sid = 0; /* expected failure cases */ - TEST_ASSERT_EQUAL(-EINVAL, rte_service_enable_on_lcore(s, 100000), + TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, 100000, 1), "Enable on invalid core did not fail"); - TEST_ASSERT_EQUAL(-EINVAL, rte_service_disable_on_lcore(s, 100000), + TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, 100000, 0), "Disable on invalid core did not fail"); /* add service core to allow enabling */ @@ -326,15 +327,15 @@ service_lcore_en_dis_able(void) "Add service core failed when not in use before"); /* valid enable */ - TEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 1), "Enabling valid service and core failed"); - TEST_ASSERT_EQUAL(1, rte_service_get_enabled_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(1, rte_service_map_lcore_get(sid, slcore_id), "Enabled core returned not-enabled"); /* valid disable */ - TEST_ASSERT_EQUAL(0, rte_service_disable_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 0), "Disabling valid service and lcore failed"); - TEST_ASSERT_EQUAL(0, rte_service_get_enabled_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_get(sid, slcore_id), "Disabled core returned enabled"); /* call remote_launch to verify that app can launch ex-service lcore */ @@ -474,11 +475,12 @@ service_threaded_test(int mt_safe) "Register of MT SAFE service failed"); struct rte_service_spec *s = rte_service_get_by_id(0); + const uint32_t sid = 0; TEST_ASSERT_EQUAL(0, rte_service_start(s), "Starting valid service failed"); - TEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_1), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_1, 1), "Failed to enable lcore 1 on mt safe service"); - TEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_2), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_2, 1), "Failed to enable lcore 2 on mt safe service"); rte_service_lcore_start(slcore_1); rte_service_lcore_start(slcore_2); @@ -529,10 +531,11 @@ static int service_lcore_start_stop(void) { /* start service core and service, create mapping so tick() runs */ + const uint32_t sid = 0; struct rte_service_spec *s = rte_service_get_by_id(0); TEST_ASSERT_EQUAL(0, rte_service_start(s), "Starting valid service failed"); - TEST_ASSERT_EQUAL(-EINVAL, rte_service_enable_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(-EINVAL, rte_service_map_lcore_set(sid, slcore_id, 1), "Enabling valid service on non-service core must fail"); /* core start */ @@ -540,7 +543,7 @@ service_lcore_start_stop(void) "Service core start without add should return EINVAL"); TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id), "Service core add did not return zero"); - TEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_id), + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(sid, slcore_id, 1), "Enabling valid service on valid core failed"); TEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore_id), "Service core start after add failed");