From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 4993F58D6 for ; Mon, 22 Feb 2016 12:27:18 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP; 22 Feb 2016 03:26:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,484,1449561600"; d="scan'208";a="52390903" Received: from sie-lab-212-120.ir.intel.com (HELO silpixa00394367.ir.intel.com) ([10.237.212.120]) by fmsmga004.fm.intel.com with ESMTP; 22 Feb 2016 03:26:54 -0800 From: Harry van Haaren To: remy.horton@intel.com Date: Mon, 22 Feb 2016 11:26:02 +0000 Message-Id: <1456140362-3771-4-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456140362-3771-1-git-send-email-harry.van.haaren@intel.com> References: <1453374327-26635-1-git-send-email-harry.van.haaren@intel.com> <1456140362-3771-1-git-send-email-harry.van.haaren@intel.com> Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH v3 3/3] keepalive: add rte_keepalive_xstats_get() 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: , X-List-Received-Date: Mon, 22 Feb 2016 11:27:18 -0000 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 --- 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 #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 = 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 #include +#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