From patchwork Wed Jan 20 15:53:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 10003 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 7D78D8E93; Wed, 20 Jan 2016 16:54:04 +0100 (CET) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 015EE8E8A for ; Wed, 20 Jan 2016 16:54:01 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 20 Jan 2016 07:54:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,321,1449561600"; d="scan'208";a="731134506" Received: from sie-lab-212-120.ir.intel.com (HELO silpixa00394367.ir.intel.com) ([10.237.212.120]) by orsmga003.jf.intel.com with ESMTP; 20 Jan 2016 07:53:59 -0800 From: Harry van Haaren To: remy.horton@intel.com Date: Wed, 20 Jan 2016 15:53:41 +0000 Message-Id: <1453305221-11125-4-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453305221-11125-1-git-send-email-harry.van.haaren@intel.com> References: <1453305221-11125-1-git-send-email-harry.van.haaren@intel.com> Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH 3/3] keepalive: add rte_keepalive_xstats() and example X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 #include #include +#include #include #include #include @@ -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 #include #include +#include + +#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;