From patchwork Fri Jan 12 10:27:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 33653 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 [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 18B8BA494; Fri, 12 Jan 2018 11:27:49 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C98A73250 for ; Fri, 12 Jan 2018 11:27:46 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jan 2018 02:27:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,348,1511856000"; d="scan'208";a="26590544" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by orsmga002.jf.intel.com with ESMTP; 12 Jan 2018 02:27:45 -0800 From: Harry van Haaren To: dev@dpdk.org Cc: thomas@monjalon.net, Harry van Haaren Date: Fri, 12 Jan 2018 10:27:17 +0000 Message-Id: <1515752838-56067-2-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515752838-56067-1-git-send-email-harry.van.haaren@intel.com> References: <1507114491-144338-2-git-send-email-harry.van.haaren@intel.com> <1515752838-56067-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH v2 2/3] service: add reset all attributes for service 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 introduces a new API, allowing the application to reset attributes of a service like the cycle count. Given this functionality is now exposed to the user, remove the resetting of stats during a dump() call. Signed-off-by: Harry van Haaren --- v2: - Improve doxygen with @param value --- lib/librte_eal/common/include/rte_service.h | 12 ++++++++++++ lib/librte_eal/common/rte_service.c | 24 ++++++++++++++++++------ lib/librte_eal/rte_eal_version.map | 1 + test/test/test_service_cores.c | 11 +++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h index 4898e76..460dbbf 100644 --- a/lib/librte_eal/common/include/rte_service.h +++ b/lib/librte_eal/common/include/rte_service.h @@ -411,6 +411,18 @@ int32_t rte_service_dump(FILE *f, uint32_t id); int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id, uint32_t *attr_value); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Reset all attribute values of a service. + * + * @param id The service to reset all statistics of + * @retval 0 Successfully reset attributes + * -EINVAL Invalid service id provided + */ +int32_t rte_service_attr_reset_all(uint32_t id); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index 63db475..1b54b7e 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -712,15 +712,27 @@ rte_service_dump_one(FILE *f, struct rte_service_spec_impl *s, if (s->calls != 0) calls = s->calls; + if (reset) { + s->cycles_spent = 0; + s->calls = 0; + return; + } + fprintf(f, " %s: stats %d\tcalls %"PRIu64"\tcycles %" PRIu64"\tavg: %"PRIu64"\n", s->spec.name, service_stats_enabled(s), s->calls, s->cycles_spent, s->cycles_spent / calls); +} - if (reset) { - s->cycles_spent = 0; - s->calls = 0; - } +int32_t +rte_service_attr_reset_all(uint32_t id) +{ + struct rte_service_spec_impl *s; + SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); + + int reset = 1; + rte_service_dump_one(NULL, s, 0, reset); + return 0; } static void @@ -768,7 +780,7 @@ int32_t rte_service_dump(FILE *f, uint32_t id) for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { if (!service_valid(i)) continue; - uint32_t reset = 1; + uint32_t reset = 0; rte_service_dump_one(f, &rte_services[i], total_cycles, reset); } @@ -777,7 +789,7 @@ int32_t rte_service_dump(FILE *f, uint32_t id) if (lcore_config[i].core_role != ROLE_SERVICE) continue; - uint32_t reset = 1; + uint32_t reset = 0; service_dump_calls_per_lcore(f, i, reset); } diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 744de04..3fa1e13 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -217,6 +217,7 @@ EXPERIMENTAL { rte_eal_hotplug_add; rte_eal_hotplug_remove; rte_service_attr_get; + rte_service_attr_reset_all; rte_service_component_register; rte_service_component_unregister; rte_service_component_runstate_set; diff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c index a0768c9..e510643 100644 --- a/test/test/test_service_cores.c +++ b/test/test/test_service_cores.c @@ -242,6 +242,9 @@ service_name(void) static int service_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; @@ -295,6 +298,14 @@ service_attr_get(void) rte_service_lcore_stop(slcore_id); + TEST_ASSERT_EQUAL(0, rte_service_attr_reset_all(id), + "Valid attr_reset_all() return success"); + + TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_id, &attr_value), + "Valid attr_get() call didn't return success"); + TEST_ASSERT_EQUAL(0, attr_value, + "attr_get() call didn't set correct cycles (zero)"); + return unregister_all(); }