This patch adds a function that exposes keepalive statistics using a rte_keepalive_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 at intel.com> --- doc/guides/rel_notes/release_16_04.rst | 7 ++++ doc/guides/sample_app_ug/keep_alive.rst | 11 ++++++ examples/l2fwd-keepalive/main.c | 22 ++++++++++-- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/include/rte_keepalive.h | 31 ++++++++++++++++- lib/librte_eal/common/rte_keepalive.c | 46 ++++++++++++++++++++++++- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 + 7 files changed, 114 insertions(+), 5 deletions(-) diff --git a/doc/guides/rel_notes/release_16_04.rst b/doc/guides/rel_notes/release_16_04.rst index 5786f74..08b2785 100644 --- a/doc/guides/rel_notes/release_16_04.rst +++ b/doc/guides/rel_notes/release_16_04.rst @@ -46,6 +46,13 @@ This section should contain new features added in this release. Sample format: * **Added vhost-user live migration support.** +* **Keepalive extended stats.** + + A function ``rte_keepalive_xstats_get()`` 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..7c2d2a4 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. + +.. code-block:: c + + nstats = rte_keepalive_xstats_get(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..80307f8 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 = 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"); + unsigned nstats = rte_keepalive_xstats_get(rte_global_keepalive_info, + 0, 0); + struct rte_keepalive_xstats *xstats = + rte_zmalloc("RTE_KEEPALIVE_XSTATS", + sizeof(struct rte_keepalive_xstats) * nstats, + RTE_CACHE_LINE_SIZE); + + nstats = rte_keepalive_xstats_get(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 4f93ab7..b6eaeb3 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -146,5 +146,6 @@ DPDK_2.3 { rte_eal_pci_ioport_write; rte_eal_pci_map_device; rte_eal_pci_unmap_device; + rte_keepalive_xstats_get; } DPDK_2.2; diff --git a/lib/librte_eal/common/include/rte_keepalive.h b/lib/librte_eal/common/include/rte_keepalive.h index f4cec04..bd19855 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,20 @@ #define RTE_KEEPALIVE_MAXCORES RTE_MAX_LCORE #endif +#define RTE_KEEPALIVE_XSTATS_NAME_LEN 64 + +/** + * Keepalive extended statistic structure + * + * This structure is used by rte_keepalive_xstats_get() to provide + * statistics that are not provided in the generic rte_eth_stats + * structure. + */ +struct rte_keepalive_xstats { + char name[RTE_KEEPALIVE_XSTATS_NAME_LEN]; + uint64_t value; +}; + /** * Keepalive failure callback. @@ -99,6 +113,21 @@ 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_get(struct rte_keepalive *keepcfg, + struct rte_keepalive_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 be9e30d..77b3622 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 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 @@ -40,6 +40,8 @@ #include <rte_malloc.h> #include <rte_cycles.h> +#define RTE_KEEPALIVE_NSTATS 2 + struct rte_keepalive { /** Core Liveness. */ enum rte_keepalive_state { @@ -81,6 +83,48 @@ print_trace(const char *msg, struct rte_keepalive *keepcfg, int idx_core) ); } +int +rte_keepalive_xstats_get(struct rte_keepalive *ka, + struct rte_keepalive_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_KEEPALIVE_XSTATS_NAME_LEN, + "%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_KEEPALIVE_XSTATS_NAME_LEN, + "%s%u%s\t", "keepalive_core", + c, "_status"); + xstats[i].value = (uint32_t)ka->state_flags[c]; + i++; + } + } + + return nstats; +} void rte_keepalive_dispatch_pings(__rte_unused void *ptr_timer, diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index e8d8660..b26a79c 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -149,5 +149,6 @@ DPDK_2.3 { rte_eal_pci_ioport_write; rte_eal_pci_map_device; rte_eal_pci_unmap_device; + rte_keepalive_xstats_get; } DPDK_2.2; -- 2.5.0