From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id EBF152BAA for ; Fri, 4 May 2018 22:16:39 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 May 2018 13:16:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,363,1520924400"; d="scan'208";a="52504107" Received: from txasoft-yocto.an.intel.com (HELO txasoft-yocto.an.intel.com.) ([10.123.72.192]) by fmsmga001.fm.intel.com with ESMTP; 04 May 2018 13:16:38 -0700 From: Erik Gabriel Carrillo To: harry.van.haaren@intel.com Cc: jerin.jacob@caviumnetworks.com, narender.vangati@intel.com, gage.eads@intel.com, dev@dpdk.org Date: Fri, 4 May 2018 15:16:04 -0500 Message-Id: <1525464964-5342-2-git-send-email-erik.g.carrillo@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1525464964-5342-1-git-send-email-erik.g.carrillo@intel.com> References: <1525464964-5342-1-git-send-email-erik.g.carrillo@intel.com> Subject: [dpdk-dev] [PATCH v1 1/1] service: Add service lcore attr APIs 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: Fri, 04 May 2018 20:16:40 -0000 Add a counter that gets bumped each time the service runner loop goes around, and APIs to query and reset the attribute values. Signed-off-by: Erik Gabriel Carrillo --- lib/librte_eal/common/include/rte_service.h | 30 ++++++++++++ lib/librte_eal/common/rte_service.c | 43 ++++++++++++++++- lib/librte_eal/rte_eal_version.map | 2 + test/test/test_service_cores.c | 73 +++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h index aea4d91..05d51a2 100644 --- a/lib/librte_eal/common/include/rte_service.h +++ b/lib/librte_eal/common/include/rte_service.h @@ -363,6 +363,36 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id, */ int32_t rte_service_attr_reset_all(uint32_t id); +/** + * Returns the number of times the service runner has looped. + */ +#define RTE_SERVICE_LCORE_ATTR_LOOPS 0 + +/** + * Get an attribute from a service core. + * + * @param lcore Id of the service core. + * @param attr_id Id of the attribute to be retrieved. + * @param [out] attr_value Pointer to storage in which to write retrieved value. + * @retval 0 Success, the attribute value has been written to *attr_value*. + * -EINVAL Invalid lcore, attr_id or attr_value was NULL. + * -ENOTSUP lcore is not a service core. + */ +int32_t __rte_experimental +rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, + uint64_t *attr_value); + +/** + * Reset all attribute values of a service core. + * + * @param lcore The service core to reset all the statistics of + * @retval 0 Successfully reset attributes + * -EINVAL Invalid service id provided + * -ENOTSUP lcore is not a service core. + */ +int32_t __rte_experimental +rte_service_lcore_attr_reset_all(uint32_t lcore); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index 73507aa..fa15f66 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -61,7 +61,7 @@ struct core_state { uint8_t runstate; /* running or stopped */ uint8_t is_service_core; /* set if core is currently a service core */ - /* extreme statistics */ + uint64_t loops; uint64_t calls_per_service[RTE_SERVICE_NUM_MAX]; } __rte_cache_aligned; @@ -422,6 +422,8 @@ rte_service_runner_func(void *arg) service_run(i, cs, service_mask); } + cs->loops++; + rte_smp_rmb(); } @@ -729,6 +731,28 @@ rte_service_attr_get(uint32_t id, uint32_t attr_id, uint32_t *attr_value) } } +int32_t __rte_experimental +rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, + uint64_t *attr_value) +{ + struct core_state *cs; + + if (lcore >= RTE_MAX_LCORE || !attr_value) + return -EINVAL; + + cs = &lcore_states[lcore]; + if (!cs->is_service_core) + return -ENOTSUP; + + switch (attr_id) { + case RTE_SERVICE_LCORE_ATTR_LOOPS: + *attr_value = cs->loops; + return 0; + default: + return -EINVAL; + } +} + static void rte_service_dump_one(FILE *f, struct rte_service_spec_impl *s, uint64_t all_cycles, uint32_t reset) @@ -764,6 +788,23 @@ rte_service_attr_reset_all(uint32_t id) return 0; } +int32_t __rte_experimental +rte_service_lcore_attr_reset_all(uint32_t lcore) +{ + struct core_state *cs; + + if (lcore >= RTE_MAX_LCORE) + return -EINVAL; + + cs = &lcore_states[lcore]; + if (!cs->is_service_core) + return -ENOTSUP; + + cs->loops = 0; + + return 0; +} + static void service_dump_calls_per_lcore(FILE *f, uint32_t lcore, uint32_t reset) { diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 8597239..5af7233 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -297,6 +297,8 @@ EXPERIMENTAL { rte_mp_request_sync; rte_mp_request_async; rte_mp_sendmsg; + rte_service_lcore_attr_get; + rte_service_lcore_attr_reset_all; rte_socket_count; rte_socket_id_by_idx; rte_vfio_dma_map; diff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c index 86b4073..9f21d59 100644 --- a/test/test/test_service_cores.c +++ b/test/test/test_service_cores.c @@ -325,6 +325,78 @@ service_attr_get(void) return unregister_all(); } +/* verify service lcore attr get */ +static int +service_lcore_attr_get(void) +{ + /* ensure all services unregistered so cycle counts are zero */ + unregister_all(); + + struct rte_service_spec service; + memset(&service, 0, sizeof(struct rte_service_spec)); + service.callback = dummy_cb; + snprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME); + service.capabilities |= RTE_SERVICE_CAP_MT_SAFE; + uint32_t id; + TEST_ASSERT_EQUAL(0, rte_service_component_register(&service, &id), + "Register of service failed"); + rte_service_component_runstate_set(id, 1); + TEST_ASSERT_EQUAL(0, rte_service_runstate_set(id, 1), + "Error: Service start returned non-zero"); + rte_service_set_stats_enable(id, 1); + + uint64_t lcore_attr_value = 0xdead; + uint32_t lcore_attr_id = UINT32_MAX; + + /* check error return values */ + TEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_attr_get(UINT32_MAX, + lcore_attr_id, &lcore_attr_value), + "Invalid lcore_id didn't return -EINVAL"); + TEST_ASSERT_EQUAL(-ENOTSUP, rte_service_lcore_attr_get(rte_lcore_id(), + lcore_attr_id, &lcore_attr_value), + "Non-service core didn't return -ENOTSUP"); + + /* Start service core to increment loop count */ + TEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id), + "Service core add did not return zero"); + TEST_ASSERT_EQUAL(0, rte_service_map_lcore_set(id, slcore_id, 1), + "Enabling valid service and core failed"); + TEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore_id), + "Starting service core failed"); + + /* wait for the service lcore to run */ + rte_delay_ms(200); + + lcore_attr_id = RTE_SERVICE_LCORE_ATTR_LOOPS; + TEST_ASSERT_EQUAL(0, rte_service_lcore_attr_get(slcore_id, + lcore_attr_id, &lcore_attr_value), + "Valid lcore_attr_get() call didn't return success"); + int loops_gt_zero = lcore_attr_value > 0; + TEST_ASSERT_EQUAL(1, loops_gt_zero, + "lcore_attr_get() failed to get loops " + "(expected > zero)"); + + lcore_attr_id++; // invalid lcore attr id + TEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_attr_get(slcore_id, + lcore_attr_id, &lcore_attr_value), + "Invalid lcore attr didn't return -EINVAL"); + + rte_service_lcore_stop(slcore_id); + + TEST_ASSERT_EQUAL(0, rte_service_lcore_attr_reset_all(slcore_id), + "Valid lcore_attr_reset_all() didn't return success"); + + lcore_attr_id = RTE_SERVICE_LCORE_ATTR_LOOPS; + TEST_ASSERT_EQUAL(0, rte_service_lcore_attr_get(slcore_id, + lcore_attr_id, &lcore_attr_value), + "Valid lcore_attr_get() call didn't return success"); + TEST_ASSERT_EQUAL(0, lcore_attr_value, + "lcore_attr_get() didn't get correct loop count " + "(zero)"); + + return unregister_all(); +} + /* verify service dump */ static int service_dump(void) @@ -781,6 +853,7 @@ static struct unit_test_suite service_tests = { TEST_CASE_ST(dummy_register, NULL, service_get_by_name), TEST_CASE_ST(dummy_register, NULL, service_dump), TEST_CASE_ST(dummy_register, NULL, service_attr_get), + TEST_CASE_ST(dummy_register, NULL, service_lcore_attr_get), TEST_CASE_ST(dummy_register, NULL, service_probe_capability), TEST_CASE_ST(dummy_register, NULL, service_start_stop), TEST_CASE_ST(dummy_register, NULL, service_lcore_add_del), -- 2.6.4