DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harry van Haaren <harry.van.haaren@intel.com>
To: dev@dpdk.org
Cc: Harry van Haaren <harry.van.haaren@intel.com>
Subject: [dpdk-dev] [PATCH 1/3] service: add attribute get function
Date: Wed,  4 Oct 2017 11:54:49 +0100	[thread overview]
Message-ID: <1507114491-144338-2-git-send-email-harry.van.haaren@intel.com> (raw)
In-Reply-To: <1507114491-144338-1-git-send-email-harry.van.haaren@intel.com>

This commit adds a new function to the service API to allow
the application to retrieve items about each individual service
in the system. A unit test checks the return values of a variety
of invalid and valid calls.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/include/rte_service.h     | 17 +++++++
 lib/librte_eal/common/rte_service.c             | 18 ++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 test/test/test_service_cores.c                  | 61 +++++++++++++++++++++++++
 5 files changed, 98 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 47a09ea..8c9c5f6 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_attr_get;
 	rte_service_component_register;
 	rte_service_component_unregister;
 	rte_service_component_runstate_set;
diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 21da739..9267a0e 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -360,6 +360,23 @@ int32_t rte_service_lcore_count_services(uint32_t lcore);
  */
 int32_t rte_service_dump(FILE *f, uint32_t id);
 
+/**
+ * Returns the number of cycles that this service has consumed
+ */
+#define RTE_SERVICE_ATTR_CYCLES 0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Get an attribute from a service.
+ *
+ * @retval 0 Success, the attribute value has been written to *attr_value*.
+ *         -EINVAL Invalid id, attr_id or attr_value was NULL.
+ */
+int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
+			     uint32_t *attr_value);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c
index e598e16..4935804 100644
--- a/lib/librte_eal/common/rte_service.c
+++ b/lib/librte_eal/common/rte_service.c
@@ -644,6 +644,24 @@ rte_service_lcore_stop(uint32_t lcore)
 	return 0;
 }
 
+int32_t
+rte_service_attr_get(uint32_t id, uint32_t attr_id, uint32_t *attr_value)
+{
+	struct rte_service_spec_impl *s;
+	SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL);
+
+	if (!attr_value)
+		return -EINVAL;
+
+	switch (attr_id) {
+	case RTE_SERVICE_ATTR_CYCLES:
+		*attr_value = s->cycles_spent;
+		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)
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 8c08b8d..c2fad10 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_attr_get;
 	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 ee8313e..7d2e42d 100644
--- a/test/test/test_service_cores.c
+++ b/test/test/test_service_cores.c
@@ -266,6 +266,66 @@ service_name(void)
 	return unregister_all();
 }
 
+/* verify service attr get */
+static int
+service_attr_get(void)
+{
+	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);
+
+	uint32_t attr_id = UINT32_MAX;
+	uint32_t attr_value = 0xdead;
+	/* check error return values */
+	TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(id, attr_id,
+							&attr_value),
+			"Invalid attr_id didn't return -EINVAL");
+
+	attr_id = RTE_SERVICE_ATTR_CYCLES;
+	TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(UINT32_MAX, attr_id,
+							&attr_value),
+			"Invalid service id didn't return -EINVAL");
+
+	TEST_ASSERT_EQUAL(-EINVAL, rte_service_attr_get(id, attr_id, NULL),
+			"Invalid attr_value pointer id didn't return -EINVAL");
+
+	/* check correct (zero) return value and correct value (zero) */
+	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)");
+
+	/* Call service to increment cycle 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);
+
+	TEST_ASSERT_EQUAL(0, rte_service_attr_get(id, attr_id, &attr_value),
+			"Valid attr_get() call didn't return success");
+	int cycles_gt_zero = attr_value > 0;
+	TEST_ASSERT_EQUAL(1, cycles_gt_zero,
+			"attr_get() failed to get cycles (expected > zero)");
+
+	rte_service_lcore_stop(slcore_id);
+
+	return unregister_all();
+}
+
 /* verify service dump */
 static int
 service_dump(void)
@@ -606,6 +666,7 @@ static struct unit_test_suite service_tests  = {
 		TEST_CASE_ST(dummy_register, NULL, service_name),
 		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_probe_capability),
 		TEST_CASE_ST(dummy_register, NULL, service_start_stop),
 		TEST_CASE_ST(dummy_register, NULL, service_lcore_add_del),
-- 
2.7.4

  reply	other threads:[~2017-10-04 10:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 10:54 [dpdk-dev] [PATCH 0/3] service: add attribute get and reset Harry van Haaren
2017-10-04 10:54 ` Harry van Haaren [this message]
2018-01-12 10:27   ` [dpdk-dev] [PATCH v2 1/3] service: add attribute get function Harry van Haaren
2018-01-12 10:27     ` [dpdk-dev] [PATCH v2 2/3] service: add reset all attributes for service Harry van Haaren
2018-01-12 10:27     ` [dpdk-dev] [PATCH v2 3/3] service: add attribute for number of invocations Harry van Haaren
2018-01-12 11:49     ` [dpdk-dev] [PATCH v2 1/3] service: add attribute get function Thomas Monjalon
2017-10-04 10:54 ` [dpdk-dev] [PATCH 2/3] service: add reset all attributes for service Harry van Haaren
2017-10-04 10:54 ` [dpdk-dev] [PATCH 3/3] service: add attribute for number of invokations Harry van Haaren
2018-01-11 22:42 ` [dpdk-dev] [PATCH 0/3] service: add attribute get and reset Thomas Monjalon
2018-01-12 10:01   ` Van Haaren, Harry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507114491-144338-2-git-send-email-harry.van.haaren@intel.com \
    --to=harry.van.haaren@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).