telemetry: introduce infrastructure
authorCiara Power <ciara.power@intel.com>
Sat, 27 Oct 2018 09:17:41 +0000 (10:17 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Sat, 27 Oct 2018 13:18:20 +0000 (15:18 +0200)
This patch adds the infrastructure and initial code for the telemetry
library.

The telemetry init is registered with eal_init(). We can then check to see
if --telemetry was passed as an eal option. If --telemetry was parsed, then
we call telemetry init at the end of eal init.

Control threads are used to get CPU cycles for telemetry, which are
configured in this patch also.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Signed-off-by: Brian Archbold <brian.archbold@intel.com>
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
13 files changed:
MAINTAINERS
config/common_base
doc/api/doxy-api-index.md
doc/api/doxy-api.conf.in
lib/Makefile
lib/librte_telemetry/Makefile [new file with mode: 0644]
lib/librte_telemetry/meson.build [new file with mode: 0644]
lib/librte_telemetry/rte_telemetry.c [new file with mode: 0644]
lib/librte_telemetry/rte_telemetry.h [new file with mode: 0644]
lib/librte_telemetry/rte_telemetry_internal.h [new file with mode: 0644]
lib/librte_telemetry/rte_telemetry_version.map [new file with mode: 0644]
lib/meson.build
mk/rte.app.mk

index 17ee5b9..58956a3 100644 (file)
@@ -1201,6 +1201,10 @@ Latency statistics
 M: Reshma Pattan <reshma.pattan@intel.com>
 F: lib/librte_latencystats/
 
+Telemetry - EXPERIMENTAL
+M: Kevin Laatz <kevin.laatz@intel.com>
+F: lib/librte_telemetry/
+
 BPF - EXPERIMENTAL
 M: Konstantin Ananyev <konstantin.ananyev@intel.com>
 F: lib/librte_bpf/
index b68278b..d12ae98 100644 (file)
@@ -787,6 +787,11 @@ CONFIG_RTE_LIBRTE_BITRATE=y
 #
 CONFIG_RTE_LIBRTE_LATENCY_STATS=y
 
+#
+# Compile librte_telemetry
+#
+CONFIG_RTE_LIBRTE_TELEMETRY=n
+
 #
 # Compile librte_lpm
 #
index a3039d1..e27874c 100644 (file)
@@ -155,6 +155,7 @@ The public API headers are grouped by topics:
 
 - **debug**:
   [jobstats]           (@ref rte_jobstats.h),
+  [telemetry]          (@ref rte_telemetry.h),
   [pdump]              (@ref rte_pdump.h),
   [hexdump]            (@ref rte_hexdump.h),
   [debug]              (@ref rte_debug.h),
index 3b652ac..77ba327 100644 (file)
@@ -56,6 +56,7 @@ INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \
                           @TOPDIR@/lib/librte_sched \
                           @TOPDIR@/lib/librte_security \
                           @TOPDIR@/lib/librte_table \
+                          @TOPDIR@/lib/librte_telemetry \
                           @TOPDIR@/lib/librte_timer \
                           @TOPDIR@/lib/librte_vhost
 INPUT                   += @API_EXAMPLES@
index 062cbdf..b7370ef 100644 (file)
@@ -106,6 +106,8 @@ DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ethdev librte_net
 DEPDIRS-librte_gso += librte_mempool
 DIRS-$(CONFIG_RTE_LIBRTE_BPF) += librte_bpf
 DEPDIRS-librte_bpf := librte_eal librte_mempool librte_mbuf librte_ethdev
+DIRS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += librte_telemetry
+DEPDIRS-librte_telemetry := librte_eal librte_metrics librte_ethdev
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
diff --git a/lib/librte_telemetry/Makefile b/lib/librte_telemetry/Makefile
new file mode 100644 (file)
index 0000000..a2d4ff1
--- /dev/null
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_telemetry.a
+
+CFLAGS += -O3
+CFLAGS += -I$(SRCDIR)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
+LDLIBS += -lrte_eal -lrte_ethdev
+LDLIBS += -lrte_metrics
+LDLIBS += -lpthread
+
+EXPORT_MAP := rte_telemetry_version.map
+
+LIBABIVER := 1
+
+# library source files
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
+
+# export include files
+SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_telemetry/meson.build b/lib/librte_telemetry/meson.build
new file mode 100644 (file)
index 0000000..7716076
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+sources = files('rte_telemetry.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
+deps += ['metrics', 'ethdev']
+cflags += '-DALLOW_EXPERIMENTAL_API'
diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c
new file mode 100644 (file)
index 0000000..88c4264
--- /dev/null
@@ -0,0 +1,121 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <unistd.h>
+#include <pthread.h>
+
+#include <rte_eal.h>
+#include <rte_ethdev.h>
+#include <rte_metrics.h>
+#include <rte_option.h>
+
+#include "rte_telemetry.h"
+#include "rte_telemetry_internal.h"
+
+#define SLEEP_TIME 10
+
+static telemetry_impl *static_telemetry;
+
+static int32_t
+rte_telemetry_run(void *userdata)
+{
+       struct telemetry_impl *telemetry = userdata;
+
+       if (telemetry == NULL) {
+               TELEMETRY_LOG_WARN("TELEMETRY could not be initialised");
+               return -1;
+       }
+
+       return 0;
+}
+
+static void
+*rte_telemetry_run_thread_func(void *userdata)
+{
+       int ret;
+       struct telemetry_impl *telemetry = userdata;
+
+       if (telemetry == NULL) {
+               TELEMETRY_LOG_ERR("%s passed a NULL instance", __func__);
+               pthread_exit(0);
+       }
+
+       while (telemetry->thread_status) {
+               rte_telemetry_run(telemetry);
+               ret = usleep(SLEEP_TIME);
+               if (ret < 0)
+                       TELEMETRY_LOG_ERR("Calling thread could not be put to sleep");
+       }
+       pthread_exit(0);
+}
+
+int32_t __rte_experimental
+rte_telemetry_init()
+{
+       int ret;
+       pthread_attr_t attr;
+       const char *telemetry_ctrl_thread = "telemetry";
+
+       if (static_telemetry) {
+               TELEMETRY_LOG_WARN("TELEMETRY structure already initialised");
+               return -EALREADY;
+       }
+
+       static_telemetry = calloc(1, sizeof(struct telemetry_impl));
+       if (static_telemetry == NULL) {
+               TELEMETRY_LOG_ERR("Memory could not be allocated");
+               return -ENOMEM;
+       }
+
+       static_telemetry->socket_id = rte_socket_id();
+       rte_metrics_init(static_telemetry->socket_id);
+
+       ret = pthread_attr_init(&attr);
+       if (ret != 0) {
+               TELEMETRY_LOG_ERR("Pthread attribute init failed");
+               return -EPERM;
+       }
+
+       ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
+               telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
+               (void *)static_telemetry);
+       static_telemetry->thread_status = 1;
+
+       if (ret < 0) {
+               ret = rte_telemetry_cleanup();
+               if (ret < 0)
+                       TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+               return -EPERM;
+       }
+
+       return 0;
+}
+
+int32_t __rte_experimental
+rte_telemetry_cleanup(void)
+{
+       struct telemetry_impl *telemetry = static_telemetry;
+       telemetry->thread_status = 0;
+       pthread_join(telemetry->thread_id, NULL);
+       free(telemetry);
+       static_telemetry = NULL;
+       return 0;
+}
+
+int telemetry_log_level;
+
+static struct rte_option option = {
+       .opt_str = "--telemetry",
+       .cb = &rte_telemetry_init,
+       .enabled = 0
+};
+
+RTE_INIT(rte_telemetry_register)
+{
+       telemetry_log_level = rte_log_register("lib.telemetry");
+       if (telemetry_log_level >= 0)
+               rte_log_set_level(telemetry_log_level, RTE_LOG_ERR);
+
+       rte_option_register(&option);
+}
diff --git a/lib/librte_telemetry/rte_telemetry.h b/lib/librte_telemetry/rte_telemetry.h
new file mode 100644 (file)
index 0000000..97674ae
--- /dev/null
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdint.h>
+
+#ifndef _RTE_TELEMETRY_H_
+#define _RTE_TELEMETRY_H_
+
+/**
+ * @file
+ * RTE Telemetry
+ *
+ * The telemetry library provides a method to retrieve statistics from
+ * DPDK by sending a JSON encoded message over a socket. DPDK will send
+ * a JSON encoded response containing telemetry data.
+ ***/
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Initialize Telemetry
+ *
+ * @return
+ *  0 on successful initialisation.
+ * @return
+ *  -ENOMEM on memory allocation error
+ * @return
+ *  -EPERM on unknown error failure
+ * @return
+ *  -EALREADY if Telemetry is already initialised.
+ */
+int32_t __rte_experimental
+rte_telemetry_init(void);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Clean up and free memory.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -EPERM on failure
+ */
+int32_t __rte_experimental
+rte_telemetry_cleanup(void);
+
+#endif
diff --git a/lib/librte_telemetry/rte_telemetry_internal.h b/lib/librte_telemetry/rte_telemetry_internal.h
new file mode 100644 (file)
index 0000000..4e810a8
--- /dev/null
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <rte_log.h>
+
+#ifndef _RTE_TELEMETRY_INTERNAL_H_
+#define _RTE_TELEMETRY_INTERNAL_H_
+
+/* Logging Macros */
+extern int telemetry_log_level;
+
+#define TELEMETRY_LOG(level, fmt, args...) \
+       rte_log(RTE_LOG_ ##level, telemetry_log_level, "%s(): "fmt "\n", \
+               __func__, ##args)
+
+#define TELEMETRY_LOG_ERR(fmt, args...) \
+       TELEMETRY_LOG(ERR, fmt, ## args)
+
+#define TELEMETRY_LOG_WARN(fmt, args...) \
+       TELEMETRY_LOG(WARNING, fmt, ## args)
+
+#define TELEMETRY_LOG_INFO(fmt, args...) \
+       TELEMETRY_LOG(INFO, fmt, ## args)
+
+typedef struct telemetry_impl {
+       pthread_t thread_id;
+       int thread_status;
+       uint32_t socket_id;
+} telemetry_impl;
+
+#endif
diff --git a/lib/librte_telemetry/rte_telemetry_version.map b/lib/librte_telemetry/rte_telemetry_version.map
new file mode 100644 (file)
index 0000000..bbcd9a7
--- /dev/null
@@ -0,0 +1,8 @@
+EXPERIMENTAL {
+       global:
+
+       rte_telemetry_cleanup;
+       rte_telemetry_init;
+
+       local: *;
+};
index 2b903fa..9d1f353 100644 (file)
@@ -25,7 +25,7 @@ libraries = [ 'compat', # just a header, used for versioning
        # add pkt framework libs which use other libs from above
        'port', 'table', 'pipeline',
        # flow_classify lib depends on pkt framework table lib
-       'flow_classify', 'bpf']
+       'flow_classify', 'bpf', 'telemetry']
 
 default_cflags = machine_args
 if cc.has_argument('-Wno-format-truncation')
index c0036da..39969f4 100644 (file)
@@ -50,6 +50,9 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ACL)            += --whole-archive
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ACL)            += -lrte_acl
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ACL)            += --no-whole-archive
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += --whole-archive
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += --no-whole-archive
 _LDLIBS-$(CONFIG_RTE_LIBRTE_JOBSTATS)       += -lrte_jobstats
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METRICS)        += -lrte_metrics
 _LDLIBS-$(CONFIG_RTE_LIBRTE_BITRATE)        += -lrte_bitratestats