DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harry van Haaren <harry.van.haaren@intel.com>
To: remy.horton@intel.com
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 3/3] keepalive: add rte_keepalive_xstats() and example
Date: Wed, 20 Jan 2016 15:53:41 +0000	[thread overview]
Message-ID: <1453305221-11125-4-git-send-email-harry.van.haaren@intel.com> (raw)
In-Reply-To: <1453305221-11125-1-git-send-email-harry.van.haaren@intel.com>

This patch adds a function that exposes keepalive statistics
re-using the existing rte_eth_xstats struct. The function provides
the client API the opportunity to read last-seen and status of
each core.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 doc/guides/rel_notes/release_2_3.rst            |  6 ++++
 doc/guides/sample_app_ug/keep_alive.rst         | 11 ++++++
 examples/l2fwd-keepalive/main.c                 | 22 ++++++++++--
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 ++++
 lib/librte_eal/common/include/rte_keepalive.h   | 17 ++++++++-
 lib/librte_eal/common/rte_keepalive.c           | 48 ++++++++++++++++++++++++-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 ++++
 7 files changed, 113 insertions(+), 5 deletions(-)

diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst
index 99de186..9e33aa2 100644
--- a/doc/guides/rel_notes/release_2_3.rst
+++ b/doc/guides/rel_notes/release_2_3.rst
@@ -4,6 +4,12 @@ DPDK Release 2.3
 New Features
 ------------
 
+* **Keep Alive xstats**
+
+  A function ``rte_keepalive_xstats()`` has been added to the
+  keepalive header, allowing the retrieval of keepalive statistics
+  such as last-alive-time and the status of each core registered
+  for monitoring. The API reflects that of the existing xstats API.
 
 Resolved Issues
 ---------------
diff --git a/doc/guides/sample_app_ug/keep_alive.rst b/doc/guides/sample_app_ug/keep_alive.rst
index 1478faf..839e29c 100644
--- a/doc/guides/sample_app_ug/keep_alive.rst
+++ b/doc/guides/sample_app_ug/keep_alive.rst
@@ -190,3 +190,14 @@ The rte_keepalive_mark_alive function simply sets the core state to alive.
     {
         keepcfg->state_flags[rte_lcore_id()] = ALIVE;
     }
+
+Keepalive exposes its statistics using an API very similar to the xstats API.
+This allows client code to call the function and retrieve the current status
+of keepalive, providing information like last-alive time and status per-core
+that has keepalive enabled.
+
+.. code-block:: c
+
+    nstats = rte_keepalive_xstats(rte_global_keepalive_info, xstats, nstats);
+    for (i = 0; i < nstats; i++)
+        printf("%s : %lu\n", xstats[i].name, xstats[i].value);
diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index f4d52f2..a8f2ba4 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -66,6 +66,7 @@
 #include <rte_ether.h>
 #include <rte_ethdev.h>
 #include <rte_ring.h>
+#include <rte_malloc.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
 #include <rte_timer.h>
@@ -139,7 +140,7 @@ struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS];
 /* A tsc-based timer responsible for triggering statistics printout */
 #define TIMER_MILLISECOND 1
 #define MAX_TIMER_PERIOD 86400 /* 1 day max */
-static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* 10 seconds */
+static int64_t timer_period = 1 * TIMER_MILLISECOND * 1000; /* 1 second */
 static int64_t check_period = 5; /* default check cycle is 5ms */
 
 /* Keepalive structure */
@@ -189,7 +190,22 @@ print_stats(__attribute__((unused)) struct rte_timer *ptr_timer,
 		   total_packets_tx,
 		   total_packets_rx,
 		   total_packets_dropped);
-	printf("\n====================================================\n");
+	printf("\nKeep Alive xstats ==================================\n");
+
+	/* Keepalive Xstats */
+	unsigned nstats = rte_keepalive_xstats(rte_global_keepalive_info, 0, 0);
+	struct rte_eth_xstats *xstats = rte_zmalloc( "RTE_KEEPALIVE_XSTATS",
+					sizeof( struct rte_eth_xstats) * nstats,
+					RTE_CACHE_LINE_SIZE);
+
+	nstats = rte_keepalive_xstats(rte_global_keepalive_info, xstats,
+				      nstats);
+	unsigned i;
+	for (i = 0; i < nstats; i++)
+		printf("%s\t%lu\n", xstats[i].name,
+				xstats[i].value);
+	printf("====================================================\n");
+	rte_free(xstats);
 }
 
 /* Send the burst of packets on an output interface */
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 9d7adf1..f5e16a7 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -135,3 +135,10 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_keepalive_xstats;
+
+} DPDK_2.2;
diff --git a/lib/librte_eal/common/include/rte_keepalive.h b/lib/librte_eal/common/include/rte_keepalive.h
index 02472c0..352dd17 100644
--- a/lib/librte_eal/common/include/rte_keepalive.h
+++ b/lib/librte_eal/common/include/rte_keepalive.h
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright 2015 Intel Shannon Ltd. All rights reserved.
+ *   Copyright 2015-2016 Intel Shannon Ltd. All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
@@ -48,6 +48,8 @@
 #define RTE_KEEPALIVE_MAXCORES RTE_MAX_LCORE
 #endif
 
+struct rte_eth_xstats;
+
 
 /**
  * Keepalive failure callback.
@@ -127,6 +129,19 @@ void rte_keepalive_dispatch_pings(void *ptr_timer, void *ptr_data);
 void rte_keepalive_register_core(struct rte_keepalive *keepcfg,
 	const int id_core);
 
+/**
+ * Get statistics of the keepalive state. If xstats NULL or n is zero, the
+ * function returns the number of xstats available. If xstats is a pointer to
+ * array of size n, n items will be filled in, and then returned.
+ * @param *keepcfg
+ *   Keepalive structure pointer
+ * @param *xstats
+ *   An array of rte_eth_xstats, or NULL.
+ * @param n
+ *   Size of the array of xstats being passed in
+ */
+int rte_keepalive_xstats(struct rte_keepalive *keepcfg,
+			 struct rte_eth_xstats *xstats, unsigned n);
 
 /**
  * Per-core keepalive check.
diff --git a/lib/librte_eal/common/rte_keepalive.c b/lib/librte_eal/common/rte_keepalive.c
index 5358322..5952bac 100644
--- a/lib/librte_eal/common/rte_keepalive.c
+++ b/lib/librte_eal/common/rte_keepalive.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright 2015 Intel Shannon Ltd. All rights reserved.
+ *   Copyright 2015-2016 Intel Shannon Ltd. All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
@@ -39,6 +39,9 @@
 #include <rte_keepalive.h>
 #include <rte_malloc.h>
 #include <rte_cycles.h>
+#include <rte_ethdev.h>
+
+#define RTE_KEEPALIVE_NSTATS 2
 
 static void
 print_trace(const char *msg, struct rte_keepalive *keepcfg, int idx_core)
@@ -114,3 +117,46 @@ rte_keepalive_register_core(struct rte_keepalive *keepcfg, const int id_core)
 		keepcfg->last_alive[id_core] = rte_rdtsc();
 	}
 }
+
+int
+rte_keepalive_xstats(struct rte_keepalive *ka, struct rte_eth_xstats *xstats,
+		     unsigned n)
+{
+	unsigned i, c, active = 0;
+	for (i = 0; i < RTE_KEEPALIVE_MAXCORES; i++) {
+		if (ka->active_cores[i])
+			active++;
+	}
+
+	const unsigned nstats = active * RTE_KEEPALIVE_NSTATS;
+
+	/* Indicate number of ka-xstats */
+	if (n < nstats)
+		return nstats;
+
+	if (xstats == NULL)
+		return nstats;
+
+	uint64_t tsc = rte_rdtsc();
+	i = 0;
+	for (c = 0; c < RTE_KEEPALIVE_MAXCORES; c++) {
+		if (ka->active_cores[c]) {
+			snprintf(xstats[i].name,
+					RTE_ETH_XSTATS_NAME_SIZE,
+					"%s%u%s", "keepalive_core",
+					c, "_last_time");
+			xstats[i].value = ((tsc - ka->last_alive[c])*1000) /
+				rte_get_tsc_hz();
+			i++;
+
+			snprintf(xstats[i].name,
+					RTE_ETH_XSTATS_NAME_SIZE,
+					"%s%u%s\t", "keepalive_core",
+					c, "_status");
+			xstats[i].value = (uint32_t)ka->state_flags[c];
+			i++;
+		}
+	}
+
+	return nstats;
+}
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index cbe175f..2979df3 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -138,3 +138,10 @@ DPDK_2.2 {
 	rte_xen_dom0_supported;
 
 } DPDK_2.1;
+
+DPDK_2.3 {
+	global:
+
+	rte_keepalive_xstats;
+
+} DPDK_2.2;
-- 
2.5.0

  parent reply	other threads:[~2016-01-20 15:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20 15:53 [dpdk-dev] [PATCH 0/3] Keep-alive stats and doc fixes Harry van Haaren
2016-01-20 15:53 ` [dpdk-dev] [PATCH 1/3] doc: fix keepalive sample app guide Harry van Haaren
2016-01-20 15:53 ` [dpdk-dev] [PATCH 2/3] eal: add keepalive core register timestamp Harry van Haaren
2016-01-20 15:53 ` Harry van Haaren [this message]
2016-01-21  9:57   ` [dpdk-dev] [PATCH 3/3] keepalive: add rte_keepalive_xstats() and example Remy Horton
2016-01-21 11:05 ` [dpdk-dev] [PATCH v2 0/3] Keep-alive stats and doc fixes Harry van Haaren
2016-01-21 11:05   ` [dpdk-dev] [PATCH v2 1/3] doc: fix keepalive sample app guide Harry van Haaren
2016-02-19 17:28     ` Mcnamara, John
2016-01-21 11:05   ` [dpdk-dev] [PATCH v2 2/3] eal: add keepalive core register timestamp Harry van Haaren
2016-01-21 11:05   ` [dpdk-dev] [PATCH v2 3/3] keepalive: add rte_keepalive_xstats_get() and example Harry van Haaren
2016-01-21 12:12   ` [dpdk-dev] [PATCH v2 0/3] Keep-alive stats and doc fixes Remy Horton
2016-02-22 11:25   ` [dpdk-dev] [PATCH v3 0/3] Keepalive stats function " Harry van Haaren
2016-02-22 11:26     ` [dpdk-dev] [PATCH v3 1/3] doc: fix keepalive sample app guide Harry van Haaren
2016-02-22 16:54       ` Mcnamara, John
2016-02-22 11:26     ` [dpdk-dev] [PATCH v3 2/3] eal: add keepalive core register timestamp Harry van Haaren
2016-02-22 11:26     ` [dpdk-dev] [PATCH v3 3/3] keepalive: add rte_keepalive_xstats_get() Harry van Haaren
2016-02-29  9:19       ` Thomas Monjalon
2016-02-22 13:12     ` [dpdk-dev] [PATCH v3 0/3] Keepalive stats function and doc fixes Remy Horton
2016-03-08 10:50     ` [dpdk-dev] [PATCH v4 0/3] Keepalive register timestamp and doc update Harry van Haaren
2016-03-08 10:50       ` [dpdk-dev] [PATCH v4 1/3] doc: fix keepalive sample app guide Harry van Haaren
2016-03-08 10:50       ` [dpdk-dev] [PATCH v4 2/3] eal: add keepalive core register timestamp Harry van Haaren
2016-03-08 10:50       ` [dpdk-dev] [PATCH v4 3/3] keepalive: fix whitespace, removes double newlines Harry van Haaren
2016-03-08 10:58       ` [dpdk-dev] [PATCH v4 0/3] Keepalive register timestamp and doc update Thomas Monjalon

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=1453305221-11125-4-git-send-email-harry.van.haaren@intel.com \
    --to=harry.van.haaren@intel.com \
    --cc=dev@dpdk.org \
    --cc=remy.horton@intel.com \
    /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).