Skip to contentSkip to conversation

introduce telemetry library

PATCH In review Ciara Power 13 participants 220 messages Aug 23, 2018 – Oct 27, 2018 Page 2 of 3

Subsystems (2)
lore
Share & tools
lore
#94 lore raw

PATCH v4 9/13 telemetry: add tests for telemetry api

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

---
 lib/librte_telemetry/Makefile                     |   1 +
 lib/librte_telemetry/meson.build                  |   4 +-
 lib/librte_telemetry/rte_telemetry.c              | 653 ++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |  12 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   3 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  | 534 ++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |  39 ++
 lib/librte_telemetry/rte_telemetry_socket_tests.h |  36 ++
 lib/librte_telemetry/rte_telemetry_version.map    |   1 +
 9 files changed, 1281 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
lib/librte_telemetry/Makefile +1 -0
index 95c7296..1a05069 100644
@@ -22,6 +22,7 @@ LIBABIVER := 1
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 7450f96..57dd83d 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
-sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h', 'rte_telemetry_parser_test.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +653 -0

684 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h +12 -0
index d3b0d8d..958723b 100644
@@ -33,4 +33,16 @@ rte_telemetry_init(void);
 int32_t
 rte_telemetry_cleanup(void);
 
+/**
+ * Runs various tests to ensure telemetry initialisation and register/unregister
+ * functions are working correctly.
+ *
+ * @return
+ *  0 on success when all tests have passed
+ * @return
+ *  -1 on failure when the test has failed
+ */
+int32_t
+rte_telemetry_selftest(void);
+
 #endif
lib/librte_telemetry/rte_telemetry_internal.h +3 -0
index 0082cb2..de7afda 100644
@@ -75,4 +75,7 @@ int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
 
+int32_t
+rte_telemetry_socket_messaging_testing(int index, int socket);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser_test.c new file +534 -0

534 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser_test.h new file +39 -0
new file mode 100644
index 0000000..6ada852
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_TELEMETRY_PARSER_TEST_H_
+#define _RTE_TELEMETRY_PARSER_TEST_H_
+
+int32_t
+rte_telemetry_parser_test(struct telemetry_impl *telemetry);
+
+int32_t
+rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, json_t **data);
+
+int32_t
+rte_telemetry_create_json_request(int action, char *command,
+	const char *client_path, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, char **request,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
+	int action_choice, char *command_choice, int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
+	int action_choice, int *port_ids, int num_port_ids, int inv_choice);
+
+int32_t
+rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
+	*telemetry, int action_choice, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_unreg_request(int action_choice, const char *client_path,
+	int inv_choice);
+
+#endif
lib/librte_telemetry/rte_telemetry_socket_tests.h new file +36 -0
new file mode 100644
index 0000000..db9167c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdbool.h>
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
+#define _RTE_TELEMETRY_SOCKET_TESTING_H_
+
+int32_t
+rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
+	int fd);
+
+int32_t
+rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
+	int send_fd, int recv_fd);
+
+int32_t
+rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
+	int *recv_fd);
+
+#endif
lib/librte_telemetry/rte_telemetry_version.map +1 -0
index 992d227..98459fc 100644
@@ -2,5 +2,6 @@ DPDK_18.11 {
 	global:
 
 	rte_telemetry_init;
+	rte_telemetry_selftest;
 	local: *;
 };
Signature · 1 line
2.9.5
Acked-by on v4 9/13
#95 lore raw

Re: [PATCH v4 09/13] telemetry: add tests for telemetry api

Quoted 25 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, October 11, 2018 9:59 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Ciara Power <[email protected]>; Brian Archbold <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [PATCH v4 09/13] telemetry: add tests for telemetry api

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

Quoted 4 lines

---

#96 lore raw

PATCH v4 10/13 telemetry: add ability to disable selftest

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

---
 lib/librte_telemetry/rte_telemetry.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/librte_telemetry/rte_telemetry.c +13 -10
index 4fdd1d7..0e29a76 100644
@@ -660,6 +660,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
 	uint16_t pid;
 	int ret;
+	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
@@ -672,18 +673,20 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 	}
 
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (selftest) {
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+				telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Parser Tests Failed");
-		return -1;
-	}
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Parser Tests Failed");
+			return -1;
+		}
 
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+	}
 
 	return 0;
 }
Signature · 1 line
2.9.5
Acked-by on v4 10/13
#97 lore raw

Re: [PATCH v4 10/13] telemetry: add ability to disable selftest

Quoted 20 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, October 11, 2018 9:59 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Ciara Power <[email protected]>; Brian Archbold <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [PATCH v4 10/13] telemetry: add ability to disable selftest

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

Quoted 4 lines

---

#98 lore raw

PATCH v4 11/13 doc: add telemetry documentation

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry for telemetry.

---
 MAINTAINERS                    |  5 +++
 doc/guides/howto/index.rst     |  1 +
 doc/guides/howto/telemetry.rst | 85 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)
 create mode 100644 doc/guides/howto/telemetry.rst
MAINTAINERS +5 -0
index 84b9ff7..e695a68 100644
@@ -1168,6 +1168,11 @@ F: test/bpf/
 F: test/test/test_bpf.c
 F: doc/guides/prog_guide/bpf_lib.rst
 
+Telemetry
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst
 
 Test Applications
 -----------------
doc/guides/howto/index.rst +1 -0
index e13a090..a642a2b 100644
@@ -17,3 +17,4 @@ HowTo Guides
     virtio_user_for_container_networking
     virtio_user_as_exceptional_path
     packet_capture_framework
+    telemetry
doc/guides/howto/telemetry.rst new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.9.5
Acked-by on v4 11/13
#99 lore raw

Re: [PATCH v4 11/13] doc: add telemetry documentation

Quoted 18 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, October 11, 2018 9:59 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Ciara Power <[email protected]>; Brian Archbold <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [PATCH v4 11/13] doc: add telemetry documentation

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

Quoted 6 lines

It also adds the MAINTAINERS file entry for telemetry.

---

#100 lore raw

PATCH v4 12/13 usertools: add client python script for telemetry

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds a python script which can be used as a demo client. The script is interactive and will allow the user to register, request statistics, and unregister.

To run the script, an argument for the client file path must be passed in: "python telemetry_client.py <file_path>".

This script is useful to see how the Telemetry API for DPDK is used, and how to make the initial connection.

---
 usertools/dpdk-telemetry-client.py | 116 +++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 usertools/dpdk-telemetry-client.py
usertools/dpdk-telemetry-client.py new file +116 -0
new file mode 100644
index 0000000..71c6be7
@@ -0,0 +1,116 @@
+# SPDK-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+import socket
+import os
+import sys
+import time
+
+BUFFER_SIZE = 200000
+
+METRICS_REQ = "{\"action\":0,\"command\":\"ports_all_stat_values\",\"data\":null}"
+API_REG = "{\"action\":1,\"command\":\"clients\",\"data\":{\"client_path\":\""
+API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
+DEFAULT_FP = "/var/run/dpdk/default_client"
+
+class Socket:
+
+    def __init__(self):
+        self.send_fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.recv_fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.client_fd = None
+
+    def __del__(self):
+        try:
+            self.send_fd.close()
+            self.recv_fd.close()
+            self.client_fd.close()
+        except:
+            print("Error - Sockets could not be closed")
+
+class Client:
+
+    def __init__(self): # Creates a client instance
+        self.socket = Socket()
+        self.file_path = None
+        self.choice = None
+        self.unregistered = 0
+
+    def __del__(self):
+        try:
+            if self.unregistered == 0:
+                self.unregister();
+        except:
+            print("Error - Client could not be destroyed")
+
+    def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client
+        self.file_path = file_path
+
+    def register(self): # Connects a client to DPDK-instance
+        if os.path.exists(self.file_path):
+            os.unlink(self.file_path)
+        try:
+            self.socket.recv_fd.bind(self.file_path)
+        except socket.error as msg:
+            print ("Error - Socket binding error: " + str(msg) + "\n")
+        self.socket.recv_fd.settimeout(2)
+        self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry")
+        JSON = (API_REG + self.file_path + "\"}}")
+        self.socket.send_fd.sendall(JSON)
+        self.socket.recv_fd.listen(1)
+        self.socket.client_fd = self.socket.recv_fd.accept()[0]
+
+    def unregister(self): # Unregister a given client
+        self.socket.client_fd.send(API_UNREG + self.file_path + "\"}}")
+        self.socket.client_fd.close()
+
+    def requestMetrics(self): # Requests metrics for given client
+        self.socket.client_fd.send(METRICS_REQ)
+        data = self.socket.client_fd.recv(BUFFER_SIZE)
+        print "\nResponse: \n", str(data)
+
+    def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
+        print("\nPlease enter the number of times you'd like to continuously request Metrics:")
+        n_requests = int(input("\n:"))
+        print("\033[F") #Removes the user input from screen, cleans it up
+        print("\033[K")
+        for i in range(n_requests):
+            self.requestMetrics()
+            time.sleep(sleep_time)
+
+    def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script
+        while self.choice != 3:
+            print("\nOptions Menu")
+            print("[1] Send for Metrics for all ports")
+            print("[2] Send for Metrics for all ports recursively")
+            print("[3] Unregister client")
+
+            try:
+                self.choice = int(input("\n:"))
+                print("\033[F") #Removes the user input for screen, cleans it up
+                print("\033[K")
+                if self.choice == 1:
+                    self.requestMetrics()
+                elif self.choice == 2:
+                    self.repeatedlyRequestMetrics(sleep_time)
+                elif self.choice == 3:
+                    self.unregister()
+                    self.unregistered = 1
+                else:
+                    print("Error - Invalid request choice")
+            except:
+                pass
+
+if __name__ == "__main__":
+
+    sleep_time = 1
+    file_path = ""
+    if (len(sys.argv) == 2):
+	file_path = sys.argv[1]
+    else:
+        print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")
+	file_path = DEFAULT_FP
+    client = Client()
+    client.getFilepath(file_path)
+    client.register()
+    client.interactiveMenu(sleep_time)
Signature · 1 line
2.9.5
Acked-by on v4 12/13
#101 lore raw

Re: [PATCH v4 12/13] usertools: add client python script for telemetry

Quoted 20 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, October 11, 2018 9:59 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Ciara Power <[email protected]>; Brian Archbold <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [PATCH v4 12/13] usertools: add client python script for telemetry

From: Ciara Power <[email protected]>

This patch adds a python script which can be used as a demo client. The script is interactive and will allow the user to register, request statistics, and unregister.

To run the script, an argument for the client file path must be passed in: "python telemetry_client.py <file_path>".

Quoted 7 lines

This script is useful to see how the Telemetry API for DPDK is used, and how to make the initial connection.

---

#102 lore raw

PATCH v4 13/13 build: add dependency on telemetry to apps in meson

In reply to Kevin Laatz

This patch adds telemetry as a dependecy to all applications. Without these changes, the --telemetry flag will not be recognised and applications will fail to run if they want to enable telemetry.

---
 app/meson.build                  | 4 ++--
 app/pdump/meson.build            | 2 +-
 app/proc-info/meson.build        | 2 +-
 app/test-bbdev/meson.build       | 2 +-
 app/test-crypto-perf/meson.build | 2 +-
 app/test-pmd/meson.build         | 2 +-
 config/meson.build               | 3 +++
 lib/meson.build                  | 1 +
 meson.build                      | 1 +
 9 files changed, 12 insertions(+), 7 deletions(-)
app/meson.build +2 -2
index 99e0b93..8e716bf 100644
@@ -24,7 +24,7 @@ foreach app:apps
 	# use "deps" for internal DPDK dependencies, and "ext_deps" for
 	# external package/library requirements
 	ext_deps = []
-	deps = []
+	deps = ['telemetry']
 
 	subdir(name)
 
@@ -38,7 +38,7 @@ foreach app:apps
 
 		link_libs = []
 		if get_option('default_library') == 'static'
-			link_libs = dpdk_drivers
+			link_libs = dpdk_static_libraries + dpdk_drivers
 		endif
 
 		if allow_experimental_apis
app/pdump/meson.build +1 -1
index 988cb4e..116c27f 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'kvargs', 'pdump']
+deps += ['ethdev', 'kvargs', 'pdump']
app/proc-info/meson.build +1 -1
index 9c148e3..a52b2ee 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'metrics']
+deps += ['ethdev', 'metrics']
app/test-bbdev/meson.build +1 -1
index 653907d..eb8cc04 100644
@@ -6,4 +6,4 @@ sources = files('main.c',
 		'test_bbdev_perf.c',
 		'test_bbdev_vector.c')
 allow_experimental_apis = true
-deps = ['bbdev', 'bus_vdev']
+deps += ['bbdev', 'bus_vdev']
app/test-crypto-perf/meson.build +1 -1
index eacd7a0..d735b18 100644
@@ -12,4 +12,4 @@ sources = files('cperf_ops.c',
 		'cperf_test_vectors.c',
 		'cperf_test_verify.c',
 		'main.c')
-deps = ['cryptodev']
+deps += ['cryptodev']
app/test-pmd/meson.build +1 -1
index a0b3be0..c24f75f 100644
@@ -22,7 +22,7 @@ sources = files('cmdline.c',
 	'testpmd.c',
 	'txonly.c')
 
-deps = ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
+deps += ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
 if dpdk_conf.has('RTE_LIBRTE_PDUMP')
 	deps += 'pdump'
 endif
config/meson.build +3 -0
index 6f9228c..275f00b 100644
@@ -21,6 +21,9 @@ toolchain = cc.get_id()
 dpdk_conf.set_quoted('RTE_TOOLCHAIN', toolchain)
 dpdk_conf.set('RTE_TOOLCHAIN_' + toolchain.to_upper(), 1)
 
+add_project_link_arguments('-Wl,--no-as-needed', language: 'c')
+dpdk_extra_ldflags += '-Wl,--no-as-needed'
+
 # use pthreads
 add_project_link_arguments('-pthread', language: 'c')
 dpdk_extra_ldflags += '-pthread'
lib/meson.build +1 -0
index b5612ad..ef3f3a6 100644
@@ -127,6 +127,7 @@ foreach l:libraries
 					dependencies: shared_deps)
 
 			dpdk_libraries = [shared_lib] + dpdk_libraries
+			dpdk_static_libraries = [static_lib] + dpdk_static_libraries
 		endif # sources.length() > 0
 
 		set_variable('shared_' + libname, shared_dep)
meson.build +1 -0
index c9af335..f3bddb2 100644
@@ -12,6 +12,7 @@ project('DPDK', 'C',
 cc = meson.get_compiler('c')
 dpdk_conf = configuration_data()
 dpdk_libraries = []
+dpdk_static_libraries = []
 dpdk_drivers = []
 dpdk_extra_ldflags = []
 
Signature · 1 line
2.9.5
Acked-by on v4 13/13
#103 lore raw

Re: [PATCH v4 13/13] build: add dependency on telemetry to apps in meson

Quoted 10 lines

-----Original Message-----
From: Laatz, Kevin
Sent: Thursday, October 11, 2018 9:59 AM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [PATCH v4 13/13] build: add dependency on telemetry to apps in meson

Quoted 7 lines

This patch adds telemetry as a dependecy to all applications. Without these changes, the --telemetry flag will not be recognised and applications will fail to run if they want to enable telemetry.

---

#104 lore raw

v5 cover introduce telemetry library

In reply to Kevin Laatz

This patchset introduces a Telemetry library for DPDK Service Assurance. This library provides an easy way to query DPDK Ethdev metrics.

The telemetry library provides a method for a service assurance component to retrieve metrics from a DPDK packet forwarding application. Communicating from the service assurance component to DPDK is done using a UNIX domain socket, passing a JSON formatted string. A reply is sent (again a JSON formatted string) of the current DPDK metrics.

The telemetry component makes use of the existing rte_metrics library to query values. The values to be transmitted via the telemetry infrastructure must be present in the Metrics library. Currently the ethdev values are pushed to the metrics library, and the queried from there there is an open question on how applications would like this to occur. Currently only ethdev to metrics functionality is implemented, however other subsystems like crypto, eventdev, keepalive etc can use similar mechanisms.

Exposing DPDK Telemetry via a socket interface enables service assurance agents like collectd to consume data from DPDK. This is vital for monitoring, fault-detection, and error reporting. A collectd plugin has been created to interact with the DPDK Telemetry component, showing how it can be used in practice. The collectd plugin will be upstreamed to collectd at a later stage. A small python script is provided in ./usertools/telemetry_client.py to quick-start using DPDK Telemetry.

Note: Despite opterr being set to 0, --telemetry said to be 'unrecognized' as a startup print. This is a cosmetic issue and will be addressed in the future.

---
v2:
- Reworked telemetry as part of EAL instead of using vdev (Gaetan)
- Refactored rte_telemetry_command (Gaetan)
- Added MAINTAINERS file entry (Stephen)
- Updated docs to reflect vdev to eal rework
- Removed collectd patch from patchset (Thomas)
- General code clean up from v1 feedback

v3:
- Reworked registering with eal and moved to rte_param (Gaetan)
- Added BSD implementation for rte_param (Gaetan)
- Updated the paths to align with the new runtime file location (Mattias)
- Fixed pointer checks to align with the coding style 1.8.1 (Mattias)
- Added missing decref's and close's (Mattias)
- Fixed runtime issue in Meson (was not recognising flag due to linking)
- More general clean up

v4:
- Added Doxygen comments for rte_param.h (Thomas)
- Made eal_get_runtime_dir a public function to use outside of EAL (Thomas)
- Reworked telemetry to get path using rte_eal_get_runtime_dir (Thomas)
- Fixed checkpatch coding style error

v5:
- Moved the BUF_SIZE define to fix build (Harry)
- Set default config for telemetry to 'n' (Harry)
- Improved Doxygen comments (Thomas)
- Cleaned up rte_param struct (Thomas)

Ciara Power, Brian Archbold and Kevin Laatz (10):
telemetry: initial telemetry infrastructure
telemetry: add initial connection socket
telemetry: add client feature and sockets
telemetry: add parser for client socket messages
telemetry: update metrics before sending stats
telemetry: format json response when sending stats
telemetry: add tests for telemetry api
telemetry: add ability to disable selftest
doc: add telemetry documentation
usertools: add client python script for telemetry

Kevin Laatz (3):
eal: add param register infrastructure
eal: make get runtime dir function public
build: add dependency on telemetry to apps in meson

 MAINTAINERS                                       |    5 +
 app/meson.build                                   |    4 +-
 app/pdump/meson.build                             |    2 +-
 app/proc-info/meson.build                         |    2 +-
 app/test-bbdev/meson.build                        |    2 +-
 app/test-crypto-perf/meson.build                  |    2 +-
 app/test-pmd/meson.build                          |    2 +-
 config/common_base                                |    5 +
 config/meson.build                                |    3 +
 doc/guides/howto/index.rst                        |    1 +
 doc/guides/howto/telemetry.rst                    |   85 +
 lib/Makefile                                      |    2 +
 lib/librte_eal/bsdapp/eal/Makefile                |    1 +
 lib/librte_eal/bsdapp/eal/eal.c                   |   20 +-
 lib/librte_eal/common/Makefile                    |    1 +
 lib/librte_eal/common/eal_filesystem.h            |   14 +-
 lib/librte_eal/common/include/rte_eal.h           |    9 +
 lib/librte_eal/common/include/rte_param.h         |   91 ++
 lib/librte_eal/common/meson.build                 |    2 +
 lib/librte_eal/common/rte_param.c                 |   47 +
 lib/librte_eal/linuxapp/eal/Makefile              |    1 +
 lib/librte_eal/linuxapp/eal/eal.c                 |   20 +-
 lib/librte_eal/rte_eal_version.map                |    2 +
 lib/librte_telemetry/Makefile                     |   30 +
 lib/librte_telemetry/meson.build                  |    9 +
 lib/librte_telemetry/rte_telemetry.c              | 1810 +++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |   48 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   81 +
 lib/librte_telemetry/rte_telemetry_parser.c       |  586 +++++++
 lib/librte_telemetry/rte_telemetry_parser.h       |   13 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  |  534 ++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |   39 +
 lib/librte_telemetry/rte_telemetry_socket_tests.h |   36 +
 lib/librte_telemetry/rte_telemetry_version.map    |    7 +
 lib/meson.build                                   |    3 +-
 meson.build                                       |    1 +
 mk/rte.app.mk                                     |    1 +
 usertools/dpdk-telemetry-client.py                |  116 ++
 38 files changed, 3618 insertions(+), 19 deletions(-)
 create mode 100644 doc/guides/howto/telemetry.rst
 create mode 100644 lib/librte_eal/common/include/rte_param.h
 create mode 100644 lib/librte_eal/common/rte_param.c
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
 create mode 100644 usertools/dpdk-telemetry-client.py
Signature · 1 line
2.9.5
#105 lore raw

PATCH v5 1/13 eal: add param register infrastructure

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

---
 lib/librte_eal/bsdapp/eal/Makefile        |  1 +
 lib/librte_eal/bsdapp/eal/eal.c           | 18 +++++-
 lib/librte_eal/common/Makefile            |  1 +
 lib/librte_eal/common/include/rte_param.h | 91 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/meson.build         |  2 +
 lib/librte_eal/common/rte_param.c         | 47 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile      |  1 +
 lib/librte_eal/linuxapp/eal/eal.c         | 18 +++++-
 lib/librte_eal/rte_eal_version.map        |  1 +
 9 files changed, 178 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_param.h
 create mode 100644 lib/librte_eal/common/rte_param.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d27da3d..7f4fa7e 100644
@@ -66,6 +66,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_param.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
 
lib/librte_eal/bsdapp/eal/eal.c +17 -1
index d7ae9d6..27b7afc 100644
@@ -42,6 +42,7 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_param.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 
@@ -414,12 +415,20 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_param_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -788,6 +797,13 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	ret = rte_param_init();
+	if (ret < 0) {
+		rte_eal_init_alert("Callback failed\n");
+		return -1;
+	}
+
 	return fctret;
 }
 
lib/librte_eal/common/Makefile +1 -0
index cca6882..8def95a 100644
@@ -12,6 +12,7 @@ INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h
+INC += rte_param.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
lib/librte_eal/common/include/rte_param.h new file +91 -0

91 lines not on this page · raw message

lib/librte_eal/common/meson.build +2 -0
index b7fc984..4069e49 100644
@@ -33,6 +33,7 @@ common_sources = files(
 	'malloc_mp.c',
 	'rte_keepalive.c',
 	'rte_malloc.c',
+	'rte_param.c',
 	'rte_reciprocal.c',
 	'rte_service.c'
 )
@@ -70,6 +71,7 @@ common_headers = files(
 	'include/rte_malloc_heap.h',
 	'include/rte_memory.h',
 	'include/rte_memzone.h',
+	'include/rte_param.h',
 	'include/rte_pci_dev_feature_defs.h',
 	'include/rte_pci_dev_features.h',
 	'include/rte_per_lcore.h',
lib/librte_eal/common/rte_param.c new file +47 -0

47 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 5c16bc4..2bf8b24 100644
@@ -74,6 +74,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_param.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
 
lib/librte_eal/linuxapp/eal/eal.c +17 -1
index 4a55d3b..e28562b 100644
@@ -48,6 +48,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_param.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
@@ -600,12 +601,20 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_param_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -1071,6 +1080,13 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	ret = rte_param_init();
+	if (ret < 0) {
+		rte_eal_init_alert("Callback failed\n");
+		return -1;
+	}
+
 	return fctret;
 }
 
lib/librte_eal/rte_eal_version.map +1 -0
index 73282bb..ccfb8a2 100644
@@ -341,6 +341,7 @@ EXPERIMENTAL {
 	rte_mp_request_sync;
 	rte_mp_request_async;
 	rte_mp_sendmsg;
+	rte_param_register;
 	rte_service_lcore_attr_get;
 	rte_service_lcore_attr_reset_all;
 	rte_service_may_be_active;
Signature · 1 line
2.9.5
#106 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

16/10/2018 17:57, Kevin Laatz:

Quoted 94 lines
lib/librte_eal/common/include/rte_param.h new file +91 -0
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#ifndef __INCLUDE_RTE_PARAM_H__
+#define __INCLUDE_RTE_PARAM_H__
+
+/**
+ * @file
+ *
+ * This API introduces the ability to register callbacks with EAL. When
+ * registering a callback, the application also provides an option as part
+ * of the struct used to register. If the option is passed to EAL when
+ * running a DPDK application, the relevant callback will be called at the
+ * end of EAL init.  For example, passing --telemetry will make the
+ * telemetry init be called at the end of EAL init.
+ *
+ * The register API can be used to resolve circular dependency issues
+ * between EAL and the library. The library uses EAL but is also initialized by
+ * EAL. Hence, EAL depends on the init function of the library. The API
+ * introduced in rte_param allows us to register the library init with EAL
+ * (passing a function pointer) and avoid the circular dependency.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef int (*rte_param_cb)(void);
+
+/*
+ * Structure containing parameters relating to the function being registered
+ * with EAL.
+ */
+struct rte_param {
+	TAILQ_ENTRY(rte_param) next; /** The next entry in the TAILQ*/
+	char *eal_option;            /** The EAL option */
+	rte_param_cb cb;             /** Function pointer of the callback */
+
+	/**
+	 * Enabled flag, should be 0 by default. This is set when the option
+	 * for the callback is passed to EAL and determines if the callback is
+	 * called or not.
+	 */
+	int enabled;
+};
+
+/**
+ * @internal Check if the passed option is valid
+ *
+ * @param option
+ *  The option to be parsed
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_param_parse(char *option);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Register a function with EAL. Registering the function will enable the
+ * function to be called at the end of EAL init.
+ *
+ * @param reg_param
+ *  Structure containing various params used to register the function.
+ */
+void __rte_experimental
+rte_param_register(struct rte_param *reg_param);
+
+/**
+ * @internal Iterate through the registered params and call the callback for
+ * the enabled ones.
+ *
+ * @return
+ *  0  on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_param_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

[...]

Quoted 50 lines
lib/librte_eal/common/rte_param.c new file +47 -0
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#include <unistd.h>
+#include <string.h>
+
+#include <rte_eal.h>
+#include <rte_param.h>
+
+TAILQ_HEAD(rte_param_list, rte_param);
+
+struct rte_param_list rte_param_list =
+	TAILQ_HEAD_INITIALIZER(rte_param_list);
+
+static struct rte_param *param;
+
+int
+rte_param_parse(char *option)
+{
+	/* Check if the option is in the registered inits */
+	TAILQ_FOREACH(param, &rte_param_list, next) {
+		if (strcmp(option, param->eal_option) == 0) {
+			param->enabled = 1;
+			return 0;
+		}
+	}
+
+	return -1;
+}
+
+void __rte_experimental
+rte_param_register(struct rte_param *reg_param)
+{
+	TAILQ_INSERT_HEAD(&rte_param_list, reg_param, next);
+}
+
+int
+rte_param_init(void)
+{
+	TAILQ_FOREACH(param, &rte_param_list, next) {
+		if (param->enabled)
+			param->cb();
+	}
+
+	return 0;
+}
#107 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

Hi Thomas,

Quoted 5 lines · Thomas Monjalon

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

I suggested the name rte_param, I think the original proposal was rte_lib_init, which to me unduly diminished the intent of these structures.

I think rte_param seems proper, this is a generic parameter object description. The integer "enabled" is described as a flag in the structure, as it is used to flag the init routine down the road to trigger the init callback associated with this parameter.

eal_option is reminiscent of optarg / optind of getopt() family, which seems fitting.

I don't mean to overstep Kevin's role defending his work, but given that I proposed some of this naming and pushed for this direction to be taken in the first place, I feel I should help explain my propositions.

rte_param could become rte_parameter or rte_option instead, eal_option could become opt_string or opt_str, and so on, do you have specific ideas about proper names?

Quoted 14 lines

16/10/2018 17:57, Kevin Laatz:

Quoted 12 lines
lib/librte_eal/common/include/rte_param.h new file +9 -0
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#ifndef __INCLUDE_RTE_PARAM_H__
+#define __INCLUDE_RTE_PARAM_H__
+
+/**
+ * @file
Quoted 8 lines

lib/librte_eal/common/include/rte_param.h line 17

Quoted 8 lines
lib/librte_eal/common/include/rte_param.h new file +8 -0
+ *
+ * This API introduces the ability to register callbacks with EAL. When
+ * registering a callback, the application also provides an option as part
+ * of the struct used to register. If the option is passed to EAL when
+ * running a DPDK application, the relevant callback will be called at the
+ * end of EAL init.  For example, passing --telemetry will make the
+ * telemetry init be called at the end of EAL init.
+ *

Citing --telemetry here is a bad idea, this file is lib-agnostic, --telemetry is not assured to be relevant.

Quoted 6 lines
Quoted 6 lines
lib/librte_eal/common/include/rte_param.h new file +6 -0
+ * The register API can be used to resolve circular dependency issues
+ * between EAL and the library. The library uses EAL but is also initialized by
+ * EAL. Hence, EAL depends on the init function of the library. The API
+ * introduced in rte_param allows us to register the library init with EAL
+ * (passing a function pointer) and avoid the circular dependency.
+ */
Signature · 2 lines
Gaëtan Rivet
6WIND
#108 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

17/10/2018 13:45, Gaëtan Rivet:

Quoted 11 lines

Hi Thomas,

Quoted 5 lines · Thomas Monjalon

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

I suggested the name rte_param, I think the original proposal was rte_lib_init, which to me unduly diminished the intent of these structures.

I think the right word is "run-time option".
An option can have a parameter.
If this API is not supporting options with parameters, the name is really misleading.

Quoted 4 lines

I think rte_param seems proper, this is a generic parameter object description. The integer "enabled" is described as a flag in the structure, as it is used to flag the init routine down the road to trigger the init callback associated with this parameter.

"enabled" can be documented as the result of the option parsing. If the option is given to rte_eal_init, it becomes enabled.

Quoted 10 lines

eal_option is reminiscent of optarg / optind of getopt() family, which seems fitting.

I don't mean to overstep Kevin's role defending his work, but given that I proposed some of this naming and pushed for this direction to be taken in the first place, I feel I should help explain my propositions.

rte_param could become rte_parameter or rte_option instead, eal_option could become opt_string or opt_str, and so on, do you have specific ideas about proper names?

rte_option looks OK.

The global picture may be better explained I think. Any help with wording and documentation is appreciated, thanks.

Quoted 33 lines
Quoted 13 lines

16/10/2018 17:57, Kevin Laatz:

Quoted 12 lines
lib/librte_eal/common/include/rte_param.h new file +9 -0
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#ifndef __INCLUDE_RTE_PARAM_H__
+#define __INCLUDE_RTE_PARAM_H__
+
+/**
+ * @file
Quoted 8 lines

lib/librte_eal/common/include/rte_param.h line 17

Quoted 8 lines
lib/librte_eal/common/include/rte_param.h new file +8 -0
+ *
+ * This API introduces the ability to register callbacks with EAL. When
+ * registering a callback, the application also provides an option as part
+ * of the struct used to register. If the option is passed to EAL when
+ * running a DPDK application, the relevant callback will be called at the
+ * end of EAL init.  For example, passing --telemetry will make the
+ * telemetry init be called at the end of EAL init.
+ *

Citing --telemetry here is a bad idea, this file is lib-agnostic, --telemetry is not assured to be relevant.

Quoted 6 lines
Quoted 6 lines
lib/librte_eal/common/include/rte_param.h new file +6 -0
+ * The register API can be used to resolve circular dependency issues
+ * between EAL and the library. The library uses EAL but is also initialized by
+ * EAL. Hence, EAL depends on the init function of the library. The API
+ * introduced in rte_param allows us to register the library init with EAL
+ * (passing a function pointer) and avoid the circular dependency.
+ */
#109 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

Hi Thomas,

Quoted 9 lines · Thomas Monjalon

17/10/2018 13:45, Gaëtan Rivet:

Quoted 8 lines

Hi Thomas,

Quoted 5 lines · Thomas Monjalon

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

Quoted 6 lines
Quoted 2 lines

I suggested the name rte_param, I think the original proposal was rte_lib_init, which to me unduly diminished the intent of these structures.

I think the right word is "run-time option".
An option can have a parameter.
If this API is not supporting options with parameters, the name is really misleading.

The option will be passed like any other EAL option. Right now it doesn't support any parameters but in future we could add functionality like we had with the --vdev solution where we can pass selftest=1 with the telemetry option.

Quoted 7 lines
Quoted 5 lines

I think rte_param seems proper, this is a generic parameter object description. The integer "enabled" is described as a flag in the structure, as it is used to flag the init routine down the road to trigger the init callback associated with this parameter.

"enabled" can be documented as the result of the option parsing. If the option is given to rte_eal_init, it becomes enabled.

The Doxygen comments mention that the flag should initially be set to 0 and will be set to 1 if the option for the relevant callback is passed to EAL when running your application.

Quoted 4 lines
Quoted 4 lines

eal_option is reminiscent of optarg / optind of getopt() family, which seems fitting.

Quoted 8 lines
Quoted 7 lines

I don't mean to overstep Kevin's role defending his work, but given that I proposed some of this naming and pushed for this direction to be taken in the first place, I feel I should help explain my propositions.

rte_param could become rte_parameter or rte_option instead, eal_option could become opt_string or opt_str, and so on, do you have specific ideas about proper names?

rte_option looks OK.

I'm happy to change it to rte_option if we have consensus on it :)

Quoted 3 lines

The global picture may be better explained I think. Any help with wording and documentation is appreciated, thanks.

Thanks,
Kevin

#110 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

17/10/2018 16:09, Laatz, Kevin:

Quoted 28 lines

Hi Thomas,

Quoted 9 lines · Thomas Monjalon

17/10/2018 13:45, Gaëtan Rivet:

Quoted 8 lines

Hi Thomas,

Quoted 5 lines · Thomas Monjalon

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

Quoted 6 lines
Quoted 2 lines

I suggested the name rte_param, I think the original proposal was rte_lib_init, which to me unduly diminished the intent of these structures.

I think the right word is "run-time option".
An option can have a parameter.
If this API is not supporting options with parameters, the name is really misleading.

The option will be passed like any other EAL option. Right now it doesn't support any parameters but in future we could add functionality like we had with the --vdev solution where we can pass selftest=1 with the telemetry option.

Quoted 5 lines
Quoted 5 lines

I think rte_param seems proper, this is a generic parameter object description. The integer "enabled" is described as a flag in the structure, as it is used to flag the init routine down the road to trigger the init callback associated with this parameter.

Quoted 5 lines
Quoted 2 lines

"enabled" can be documented as the result of the option parsing. If the option is given to rte_eal_init, it becomes enabled.

The Doxygen comments mention that the flag should initially be set to 0 and will be set to 1 if the option for the relevant callback is passed to EAL when running your application.

Saying "passed to EAL" is too vague.
You need to differentiate the option parsing and the init. Both are done in EAL, that's why you need to be more specific.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

eal_option is reminiscent of optarg / optind of getopt() family, which seems fitting.

I don't mean to overstep Kevin's role defending his work, but given that I proposed some of this naming and pushed for this direction to be taken in the first place, I feel I should help explain my propositions.

Quoted 5 lines
Quoted 4 lines
Quoted 3 lines

rte_param could become rte_parameter or rte_option instead, eal_option could become opt_string or opt_str, and so on, do you have specific ideas about proper names?

rte_option looks OK.

I'm happy to change it to rte_option if we have consensus on it :)

OK, thanks

Quoted 7 lines
Quoted 2 lines

The global picture may be better explained I think. Any help with wording and documentation is appreciated, thanks.

Thanks,
Kevin

#111 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

In reply to Gaëtan Rivet

Hi Thomas,

Quoted 7 lines · Gaëtan Rivet

Hi Thomas,

Quoted 4 lines · Thomas Monjalon

I still think all the wording is incorrect.
Please start by describing what is "param", "flag" and "option" in your mind. They are all mentioned in this file.
Are you sure rte_param is the right name?

Quoted 7 lines

I suggested the name rte_param, I think the original proposal was rte_lib_init, which to me unduly diminished the intent of these structures.

I think rte_param seems proper, this is a generic parameter object description. The integer "enabled" is described as a flag in the structure, as it is used to flag the init routine down the road to trigger the init callback associated with this parameter.

The purpose of "enabled" is to avoid redundantly calling all of the callbacks in rte_param_list. Enabled should always be initialized to 0 by the library (as described in the Doxygen comment) and it will be set if the 'option' for the callback is passed to EAL when running the application (this is done in rte_param_parse). To avoid confusion, I have renamed eal_flag to eal_option in the param struct and reworded the Doxygen comments accordingly. The only place flag is mentioned now is for "enabled".

Quoted 11 lines

eal_option is reminiscent of optarg / optind of getopt() family, which seems fitting.

I don't mean to overstep Kevin's role defending his work, but given that I proposed some of this naming and pushed for this direction to be taken in the first place, I feel I should help explain my propositions.

rte_param could become rte_parameter or rte_option instead, eal_option could become opt_string or opt_str, and so on, do you have specific ideas about proper names?

I think rte_param was an improvement on rte_lib_init, for reasons mentioned by Gaetan. I am open to renaming it if you have any better, more descriptive name in mind?

 <snip>

Thanks,
Kevin

#112 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

In reply to Kevin Laatz

Some suggestions,

Quoted 113 lines · Kevin Laatz

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

---
 lib/librte_eal/bsdapp/eal/Makefile        |  1 +
 lib/librte_eal/bsdapp/eal/eal.c           | 18 +++++-
 lib/librte_eal/common/Makefile            |  1 +
 lib/librte_eal/common/include/rte_param.h | 91 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/meson.build         |  2 +
 lib/librte_eal/common/rte_param.c         | 47 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile      |  1 +
 lib/librte_eal/linuxapp/eal/eal.c         | 18 +++++-
 lib/librte_eal/rte_eal_version.map        |  1 +
 9 files changed, 178 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_param.h
 create mode 100644 lib/librte_eal/common/rte_param.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d27da3d..7f4fa7e 100644
@@ -66,6 +66,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_param.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
 
lib/librte_eal/bsdapp/eal/eal.c +17 -1
index d7ae9d6..27b7afc 100644
@@ -42,6 +42,7 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_param.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 
@@ -414,12 +415,20 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_param_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -788,6 +797,13 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	ret = rte_param_init();
+	if (ret < 0) {
+		rte_eal_init_alert("Callback failed\n");
+		return -1;
+	}
+
 	return fctret;
 }
 
lib/librte_eal/common/Makefile +1 -0
index cca6882..8def95a 100644
@@ -12,6 +12,7 @@ INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h
+INC += rte_param.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
lib/librte_eal/common/include/rte_param.h new file +12 -0
new file mode 100644
index 0000000..a0635f7
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#ifndef __INCLUDE_RTE_PARAM_H__
+#define __INCLUDE_RTE_PARAM_H__
+
+/**
+ * @file
+ *
+ * This API introduces the ability to register callbacks with EAL. When
+ * registering a callback, the application also provides an option as part

lib/librte_eal/common/include/rte_param.h line 22

Quoted 10 lines
lib/librte_eal/common/include/rte_param.h new file +10 -0
+ * of the struct used to register. If the option is passed to EAL when
+ * running a DPDK application, the relevant callback will be called at the
+ * end of EAL init.  For example, passing --telemetry will make the
+ * telemetry init be called at the end of EAL init.
+ *
+ * The register API can be used to resolve circular dependency issues
+ * between EAL and the library. The library uses EAL but is also initialized by
+ * EAL. Hence, EAL depends on the init function of the library. The API
+ * introduced in rte_param allows us to register the library init with EAL
+ * (passing a function pointer) and avoid the circular dependency.

This API offers the ability to register options to the EAL command line and map those options to functions, that will be executed at the end of EAL initialization. These options will be available as part of the EAL command line of applications and are dynamically managed.

This is used primarily by DPDK libraries offering command line options. Currently, this API is limited to registering options without argument.

lib/librte_eal/common/include/rte_param.h line 31

Quoted 9 lines
lib/librte_eal/common/include/rte_param.h new file +9 -0
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef int (*rte_param_cb)(void);
+
+/*

/**

lib/librte_eal/common/include/rte_param.h line 33

Quoted 2 lines
lib/librte_eal/common/include/rte_param.h new file +2 -0
+ * Structure containing parameters relating to the function being registered
+ * with EAL.

Structure describing the EAL command line option being registered.

lib/librte_eal/common/include/rte_param.h line 35

Quoted 2 lines
lib/librte_eal/common/include/rte_param.h new file +2 -0
+ */
+struct rte_param {

As said earlier, rte_option instead.

lib/librte_eal/common/include/rte_param.h line 36

Quoted 1 line
lib/librte_eal/common/include/rte_param.h new file +1 -0
+	TAILQ_ENTRY(rte_param) next; /** The next entry in the TAILQ*/

^ missing a '<' here for doxygen, and a space after TAILQ.

/**< Next entry. */
or
/**< Next entry in the list. */

Also reads better, TAILQ is implementation detail, not too useful in API doc.
Also missing a period.

lib/librte_eal/common/include/rte_param.h line 37

Quoted 1 line
lib/librte_eal/common/include/rte_param.h new file +1 -0
+	char *eal_option;            /** The EAL option */
         *opt_str; /**< The option name. */

lib/librte_eal/common/include/rte_param.h line 38

Quoted 1 line
lib/librte_eal/common/include/rte_param.h new file +1 -0
+	rte_param_cb cb;             /** Function pointer of the callback */

cb; /**< Function called when the option is used. */

lib/librte_eal/common/include/rte_param.h line 45

Quoted 7 lines
lib/librte_eal/common/include/rte_param.h new file +7 -0
+
+	/**
+	 * Enabled flag, should be 0 by default. This is set when the option
+	 * for the callback is passed to EAL and determines if the callback is
+	 * called or not.
+	 */
+	int enabled;
                 /**< Set when the option is used. */

lib/librte_eal/common/include/rte_param.h line 49

Quoted 4 lines
lib/librte_eal/common/include/rte_param.h new file +4 -0
+};
+
+/**
+ * @internal Check if the passed option is valid

Check if option is registered.

lib/librte_eal/common/include/rte_param.h line 60

Quoted 11 lines
lib/librte_eal/common/include/rte_param.h new file +11 -0
+ *
+ * @param option
+ *  The option to be parsed
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_param_parse(char *option);

This should probably be a const char *.
Also, internal functions must not be part of public headers. Move the prototype to eal_private.h instead.

lib/librte_eal/common/include/rte_param.h line 71

Quoted 11 lines
lib/librte_eal/common/include/rte_param.h new file +11 -0
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Register a function with EAL. Registering the function will enable the
+ * function to be called at the end of EAL init.
+ *
+ * @param reg_param
+ *  Structure containing various params used to register the function.
+ */

Register an option to the EAL command line.
When recognized, the associated function will
be executed at the end of EAL initialization.

The associated structure must be available the whole time this option is registered (i.e. not stack memory)

@param option
Structure describing the option to parse.

lib/librte_eal/common/include/rte_param.h line 77

Quoted 6 lines
lib/librte_eal/common/include/rte_param.h new file +6 -0
+void __rte_experimental
+rte_param_register(struct rte_param *reg_param);
+
+/**
+ * @internal Iterate through the registered params and call the callback for
+ * the enabled ones.

Iterate through registered options and execute the associated callback if enabled.

lib/librte_eal/common/include/rte_param.h line 85

Quoted 8 lines
lib/librte_eal/common/include/rte_param.h new file +8 -0
+ *
+ * @return
+ *  0  on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_param_init(void);

This function prototype should be added to eal_private.h instead.

Maybe missing: rte_option_unregister, to be executed in .FINI, if a plugin is unloaded.

Quoted 57 lines
lib/librte_eal/common/include/rte_param.h new file +6 -0
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
lib/librte_eal/common/meson.build +2 -0
index b7fc984..4069e49 100644
@@ -33,6 +33,7 @@ common_sources = files(
 	'malloc_mp.c',
 	'rte_keepalive.c',
 	'rte_malloc.c',
+	'rte_param.c',
 	'rte_reciprocal.c',
 	'rte_service.c'
 )
@@ -70,6 +71,7 @@ common_headers = files(
 	'include/rte_malloc_heap.h',
 	'include/rte_memory.h',
 	'include/rte_memzone.h',
+	'include/rte_param.h',
 	'include/rte_pci_dev_feature_defs.h',
 	'include/rte_pci_dev_features.h',
 	'include/rte_per_lcore.h',
lib/librte_eal/common/rte_param.c new file +25 -0
new file mode 100644
index 0000000..317e371
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation.
+ */
+
+#include <unistd.h>
+#include <string.h>
+
+#include <rte_eal.h>
+#include <rte_param.h>
+
+TAILQ_HEAD(rte_param_list, rte_param);
+
+struct rte_param_list rte_param_list =
+	TAILQ_HEAD_INITIALIZER(rte_param_list);
+
+static struct rte_param *param;
+
+int
+rte_param_parse(char *option)
+{
+	/* Check if the option is in the registered inits */
+	TAILQ_FOREACH(param, &rte_param_list, next) {
+		if (strcmp(option, param->eal_option) == 0) {
+			param->enabled = 1;
+			return 0;

lib/librte_eal/common/rte_param.c line 35

Quoted 10 lines
lib/librte_eal/common/rte_param.c new file +10 -0
+		}
+	}
+
+	return -1;
+}
+
+void __rte_experimental
+rte_param_register(struct rte_param *reg_param)
+{
+	TAILQ_INSERT_HEAD(&rte_param_list, reg_param, next);

What happens when an option already exists in the list?

Quoted 59 lines
lib/librte_eal/common/rte_param.c new file +12 -0
+}
+
+int
+rte_param_init(void)
+{
+	TAILQ_FOREACH(param, &rte_param_list, next) {
+		if (param->enabled)
+			param->cb();
+	}
+
+	return 0;
+}
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 5c16bc4..2bf8b24 100644
@@ -74,6 +74,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_param.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
 
lib/librte_eal/linuxapp/eal/eal.c +10 -1
index 4a55d3b..e28562b 100644
@@ -48,6 +48,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_param.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
@@ -600,12 +601,20 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_param_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;

lib/librte_eal/linuxapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 1086

Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal.c +4 -0
@@ -1071,6 +1080,13 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	ret = rte_param_init();
+	if (ret < 0) {
+		rte_eal_init_alert("Callback failed\n");

It would be better to be able to know which function failed and why. "Callback failed" is not helpful to the user.
Maybe rte_option_init() return value should be expanded to allow for error string, error value to be passed, that could come from the library itself, or simply printing the option name that is the source of the error.

Quoted 21 lines
lib/librte_eal/linuxapp/eal/eal.c +3 -0
+		return -1;
+	}
+
 	return fctret;
 }
 
lib/librte_eal/rte_eal_version.map +1 -0
index 73282bb..ccfb8a2 100644
@@ -341,6 +341,7 @@ EXPERIMENTAL {
 	rte_mp_request_sync;
 	rte_mp_request_async;
 	rte_mp_sendmsg;
+	rte_param_register;
 	rte_service_lcore_attr_get;
 	rte_service_lcore_attr_reset_all;
 	rte_service_may_be_active;
Signature · 1 line
2.9.5

Best regards,

Signature · 2 lines
Gaëtan Rivet
6WIND
#113 lore raw

Re: [PATCH v5 01/13] eal: add param register infrastructure

Hi Gaetan,

Thanks for reviewing and providing suggestions.

Quoted 12 lines · Gaëtan Rivet
Quoted 12 lines
lib/librte_eal/common/rte_param.c new file +12 -0
+
+int
+rte_param_parse(char *option)
+{
+	/* Check if the option is in the registered inits */
+	TAILQ_FOREACH(param, &rte_param_list, next) {
+		if (strcmp(option, param->eal_option) == 0) {
+			param->enabled = 1;
+			return 0;
+		}
+	}
+
Quoted 8 lines

lib/librte_eal/common/rte_param.c line 35

Quoted 7 lines
lib/librte_eal/common/rte_param.c new file +7 -0
+	return -1;
+}
+
+void __rte_experimental
+rte_param_register(struct rte_param *reg_param)
+{
+	TAILQ_INSERT_HEAD(&rte_param_list, reg_param, next);

What happens when an option already exists in the list?

Will add a check to avoid option duplication, good spot. Thanks

Quoted 4 lines
Quoted 4 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -0
@@ -1071,6 +1080,13 @@ rte_eal_init(int argc, char **argv)
 
  	rte_eal_mcfg_complete();
 
Quoted 10 lines

lib/librte_eal/bsdapp/eal/eal.c rte_eal_init(int argc, char **argv) · line 803

Quoted 4 lines
lib/librte_eal/bsdapp/eal/eal.c +4 -0
+	/* Call each registered callback, if enabled */
+	ret = rte_param_init();
+	if (ret < 0) {
+		rte_eal_init_alert("Callback failed\n");

It would be better to be able to know which function failed and why. "Callback failed" is not helpful to the user.
Maybe rte_option_init() return value should be expanded to allow for error string, error value to be passed, that could come from the library itself, or simply printing the option name that is the source of the error.

I agree that the error message is not helpful. Expanding the return value to pass the option name or more would be difficult however as we would need to check for success/fail of the execution of the callback in rte_option_init(). Since the we don't know what the return type of a given registered callback is, it is difficult to do the error checking here. With that in mind, I think it might be best to leave the library's function do the error checking itself, and changing the return type of rte_option_init() to void. This way we could get library specific errors using RTE_LOG, for example. Thoughts?

Best regards,
Kevin

#114 lore raw

PATCH v5 2/13 eal: make get runtime dir function public

In reply to Kevin Laatz

This patch makes the eal_get_runtime_dir() API public so it can be used from outside EAL.

---
Note: I have added rte_eal_get_runtime_dir() to the 18.11 version in the .map file instead of the EXPERIMENTAL section as the function already existed, we just renamed it and made it public.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  2 +-
 lib/librte_eal/common/eal_filesystem.h  | 14 +++++++-------
 lib/librte_eal/common/include/rte_eal.h |  9 +++++++++
 lib/librte_eal/linuxapp/eal/eal.c       |  2 +-
 lib/librte_eal/rte_eal_version.map      |  1 +
 5 files changed, 19 insertions(+), 9 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +1 -1
index 27b7afc..ee94bc1 100644
@@ -142,7 +142,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/common/eal_filesystem.h +7 -7
index de05feb..f82b4fe 100644
@@ -27,7 +27,7 @@ eal_create_runtime_dir(void);
 
 /* returns runtime dir */
 const char *
-eal_get_runtime_dir(void);
+rte_eal_get_runtime_dir(void);
 
 #define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
@@ -35,7 +35,7 @@ eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
@@ -47,7 +47,7 @@ eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
 	return buffer;
 }
@@ -55,7 +55,7 @@ eal_mp_socket_path(void)
 #define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(), name);
 	return buffer;
 }
 
@@ -66,7 +66,7 @@ eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
@@ -78,7 +78,7 @@ eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
@@ -99,7 +99,7 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, rte_eal_get_runtime_dir(),
 			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
lib/librte_eal/common/include/rte_eal.h +9 -0
index e114dcb..e19f74e 100644
@@ -498,6 +498,15 @@ enum rte_iova_mode rte_eal_iova_mode(void);
 const char *
 rte_eal_mbuf_user_pool_ops(void);
 
+/**
+ * Get the runtime directory of DPDK
+ *
+ * @return
+ *  The runtime directory path of DPDK
+ */
+const char *
+rte_eal_get_runtime_dir(void);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/linuxapp/eal/eal.c +1 -1
index e28562b..e926f67 100644
@@ -150,7 +150,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/rte_eal_version.map +1 -0
index ccfb8a2..2de7197 100644
@@ -265,6 +265,7 @@ DPDK_18.08 {
 DPDK_18.11 {
 	global:
 
+	rte_eal_get_runtime_dir;
 	rte_strscpy;
 
 } DPDK_18.08;
Signature · 1 line
2.9.5
#115 lore raw

PATCH v5 3/13 telemetry: initial telemetry infrastructure

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

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.

---
 config/common_base                             |   5 ++
 lib/Makefile                                   |   2 +
 lib/librte_telemetry/Makefile                  |  28 ++++++
 lib/librte_telemetry/meson.build               |   7 ++
 lib/librte_telemetry/rte_telemetry.c           | 117 +++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h           |  36 ++++++++
 lib/librte_telemetry/rte_telemetry_internal.h  |  32 +++++++
 lib/librte_telemetry/rte_telemetry_version.map |   6 ++
 lib/meson.build                                |   2 +-
 mk/rte.app.mk                                  |   1 +
 10 files changed, 235 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
config/common_base +5 -0
index acc5211..f561eb4 100644
@@ -722,6 +722,11 @@ CONFIG_RTE_LIBRTE_HASH=y
 CONFIG_RTE_LIBRTE_HASH_DEBUG=n
 
 #
+# Compile librte_telemetry
+#
+CONFIG_RTE_LIBRTE_TELEMETRY=n
+
+#
 # Compile librte_efd
 #
 CONFIG_RTE_LIBRTE_EFD=y
lib/Makefile +2 -0
index 8c83942..2b446c6 100644
@@ -105,6 +105,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
lib/librte_telemetry/Makefile new file +28 -0
new file mode 100644
index 0000000..0d61361
@@ -0,0 +1,28 @@
+# 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
+LDLIBS += -ljansson
+
+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
lib/librte_telemetry/meson.build new file +7 -0
new file mode 100644
index 0000000..7716076
@@ -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'
lib/librte_telemetry/rte_telemetry.c new file +117 -0

117 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h new file +36 -0
new file mode 100644
index 0000000..d3b0d8d
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdint.h>
+
+#ifndef _RTE_TELEMETRY_H_
+#define _RTE_TELEMETRY_H_
+
+/**
+ * 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_telemetry_init(void);
+
+/**
+ * Clean up and free memory.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -EPERM on failure
+ */
+int32_t
+rte_telemetry_cleanup(void);
+
+#endif
lib/librte_telemetry/rte_telemetry_internal.h new file +32 -0
new file mode 100644
index 0000000..4e810a8
@@ -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
lib/librte_telemetry/rte_telemetry_version.map new file +6 -0
new file mode 100644
index 0000000..992d227
@@ -0,0 +1,6 @@
+DPDK_18.11 {
+	global:
+
+	rte_telemetry_init;
+	local: *;
+};
lib/meson.build +1 -1
index 3acc67e..b5612ad 100644
@@ -24,7 +24,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')
mk/rte.app.mk +1 -0
index 32579e4..35594b9 100644
@@ -80,6 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#116 lore raw

PATCH v5 4/13 telemetry: add initial connection socket

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the telemetry UNIX socket. It is used to allow connections from external clients.

On the initial connection from a client, ethdev stats are registered in the metrics library, to allow for their retrieval at a later stage.

---
 lib/librte_telemetry/rte_telemetry.c          | 226 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 2 files changed, 230 insertions(+)
lib/librte_telemetry/rte_telemetry.c +226 -0
index b31b57d..8d5754e 100644
@@ -3,23 +3,163 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include <pthread.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #include <rte_eal.h>
 #include <rte_ethdev.h>
 #include <rte_metrics.h>
 #include <rte_param.h>
+#include <rte_string_fns.h>
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
 
+#define BUF_SIZE 1024
 #define SLEEP_TIME 10
 
 static telemetry_impl *static_telemetry;
 
+static void
+rte_telemetry_get_runtime_dir(char *socket_path, size_t size)
+{
+	snprintf(socket_path, size, "%s/telemetry", rte_eal_get_runtime_dir());
+}
+
+int32_t
+rte_telemetry_is_port_active(int port_id)
+{
+	int ret;
+
+	ret = rte_eth_find_next(port_id);
+	if (ret == port_id)
+		return 1;
+
+	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
+		port_id);
+	return 0;
+}
+
+static int32_t
+rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
+{
+	int ret, num_xstats, ret_val, i;
+	struct rte_eth_xstat *eth_xstats = NULL;
+	struct rte_eth_xstat_name *eth_xstats_names = NULL;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		return -EINVAL;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d",
+				port_id, num_xstats);
+		return -EPERM;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		return -ENOMEM;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	const char *xstats_names[num_xstats];
+	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	if (eth_xstats_names == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats_names");
+		ret_val = -ENOMEM;
+		goto free_xstats;
+	}
+
+	ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	for (i = 0; i < num_xstats; i++)
+		xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name;
+
+	ret_val = rte_metrics_reg_names(xstats_names, num_xstats);
+	if (ret_val < 0) {
+		TELEMETRY_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
+		ret_val = -1;
+		goto free_xstats;
+	}
+
+	goto free_xstats;
+
+free_xstats:
+	free(eth_xstats);
+	free(eth_xstats_names);
+	return ret_val;
+}
+
+static int32_t
+rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
+{
+	uint16_t pid;
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		telemetry->reg_index =
+			rte_telemetry_reg_ethdev_to_metrics(pid);
+		break;
+	}
+
+	if (telemetry->reg_index < 0) {
+		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+		return -1;
+	}
+
+	telemetry->metrics_register_done = 1;
+
+	return 0;
+}
+
+static int32_t
+rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
+{
+	int ret;
+
+	if (telemetry->accept_fd == 0 || telemetry->accept_fd == -1) {
+		ret = listen(telemetry->server_fd, 1);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Listening error with server fd");
+			return -1;
+		}
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
+
+		if (telemetry->accept_fd > 0 &&
+			telemetry->metrics_register_done == 0) {
+			ret = rte_telemetry_initial_accept(telemetry);
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Failed to run initial configurations/tests");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int32_t
 rte_telemetry_run(void *userdata)
 {
+	int ret;
 	struct telemetry_impl *telemetry = userdata;
 
 	if (telemetry == NULL) {
@@ -27,6 +167,12 @@ rte_telemetry_run(void *userdata)
 		return -1;
 	}
 
+	ret = rte_telemetry_accept_new_client(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Accept and read new client failed");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -50,6 +196,68 @@ static void
 	pthread_exit(0);
 }
 
+static int32_t
+rte_telemetry_set_socket_nonblock(int fd)
+{
+	int flags;
+
+	if (fd < 0) {
+		TELEMETRY_LOG_ERR("Invalid fd provided");
+		return -1;
+	}
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0)
+		flags = 0;
+
+	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+static int32_t
+rte_telemetry_create_socket(struct telemetry_impl *telemetry)
+{
+	int ret;
+	struct sockaddr_un addr = {0};
+	char socket_path[BUF_SIZE];
+
+	if (telemetry == NULL)
+		return -1;
+
+	telemetry->server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (telemetry->server_fd == -1) {
+		TELEMETRY_LOG_ERR("Failed to open socket");
+		return -1;
+	}
+
+	ret  = rte_telemetry_set_socket_nonblock(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		goto close_socket;
+	}
+
+	addr.sun_family = AF_UNIX;
+	rte_telemetry_get_runtime_dir(socket_path, sizeof(socket_path));
+	strlcpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
+	unlink(socket_path);
+
+	if (bind(telemetry->server_fd, (struct sockaddr *)&addr,
+		sizeof(addr)) < 0) {
+		TELEMETRY_LOG_ERR("Socket binding error");
+		goto close_socket;
+	}
+
+	return 0;
+
+close_socket:
+	if (close(telemetry->server_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
+	return -1;
+}
+
 int32_t
 rte_telemetry_init()
 {
@@ -70,6 +278,14 @@ rte_telemetry_init()
 
 	static_telemetry->socket_id = rte_socket_id();
 	rte_metrics_init(static_telemetry->socket_id);
+	ret = rte_telemetry_create_socket(static_telemetry);
+	if (ret < 0) {
+		ret = rte_telemetry_cleanup();
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+		return -EPERM;
+	}
+
 	pthread_attr_init(&attr);
 	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
 		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
@@ -89,11 +305,21 @@ rte_telemetry_init()
 int32_t
 rte_telemetry_cleanup(void)
 {
+	int ret;
 	struct telemetry_impl *telemetry = static_telemetry;
+
+	ret = close(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
 	telemetry->thread_status = 0;
 	pthread_join(telemetry->thread_id, NULL);
 	free(telemetry);
 	static_telemetry = NULL;
+
 	return 0;
 }
 
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 4e810a8..569d56a 100644
@@ -24,9 +24,13 @@ extern int telemetry_log_level;
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
 typedef struct telemetry_impl {
+	int accept_fd;
+	int server_fd;
 	pthread_t thread_id;
 	int thread_status;
 	uint32_t socket_id;
+	int reg_index;
+	int metrics_register_done;
 } telemetry_impl;
 
 #endif
Signature · 1 line
2.9.5
#117 lore raw

PATCH v5 5/13 telemetry: add client feature and sockets

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch introduces clients to the telemetry API.

When a client makes a connection through the initial telemetry socket, they can send a message through the socket to be parsed. Register messages are expected through this socket, to enable clients to register and have a client socket setup for future communications.

A TAILQ is used to store all clients information. Using this, the client sockets are polled for messages, which will later be parsed and dealt with accordingly.

Functionality that make use of the client sockets were introduced in this patch also, such as writing to client sockets, and sending error responses.

---
 lib/librte_telemetry/meson.build              |   2 +
 lib/librte_telemetry/rte_telemetry.c          | 369 +++++++++++++++++++++++++-
 lib/librte_telemetry/rte_telemetry_internal.h |  25 ++
 mk/rte.app.mk                                 |   2 +-
 4 files changed, 394 insertions(+), 4 deletions(-)
lib/librte_telemetry/meson.build +2 -0
index 7716076..0ccfa36 100644
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson
lib/librte_telemetry/rte_telemetry.c +366 -3

441 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_internal.h +25 -0
index 569d56a..e3292cf 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_log.h>
+#include <rte_tailq.h>
 
 #ifndef _RTE_TELEMETRY_INTERNAL_H_
 #define _RTE_TELEMETRY_INTERNAL_H_
@@ -23,6 +24,12 @@ extern int telemetry_log_level;
 #define TELEMETRY_LOG_INFO(fmt, args...) \
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
+typedef struct telemetry_client {
+	char *file_path;
+	int fd;
+	TAILQ_ENTRY(telemetry_client) client_list;
+} telemetry_client;
+
 typedef struct telemetry_impl {
 	int accept_fd;
 	int server_fd;
@@ -31,6 +38,24 @@ typedef struct telemetry_impl {
 	uint32_t socket_id;
 	int reg_index;
 	int metrics_register_done;
+	TAILQ_HEAD(, telemetry_client) client_list_head;
+	struct telemetry_client *request_client;
+	int register_fail_count;
 } telemetry_impl;
 
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type);
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
 #endif
mk/rte.app.mk +1 -1
index 35594b9..b740691 100644
@@ -80,7 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
-_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry -ljansson
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#118 lore raw

PATCH v5 6/13 telemetry: add parser for client socket messages

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the parser file. This is used to parse any messages that are received on any of the client sockets.

Currently, the unregister functionality works using the parser. Functionality relating to getting statistic values for certain ports will be added in a subsequent patch, however the parsing involved for that command is added in this patch.

Some of the parser code included is in preparation for future functionality, that is not implemented yet in this patchset.

---
 lib/librte_telemetry/Makefile                 |   1 +
 lib/librte_telemetry/meson.build              |   4 +-
 lib/librte_telemetry/rte_telemetry.c          |  11 +-
 lib/librte_telemetry/rte_telemetry_internal.h |  13 +
 lib/librte_telemetry/rte_telemetry_parser.c   | 569 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser.h   |  13 +
 6 files changed, 608 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
lib/librte_telemetry/Makefile +1 -0
index 0d61361..95c7296 100644
@@ -21,6 +21,7 @@ LIBABIVER := 1
 
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 0ccfa36..7450f96 100644
@@ -1,8 +1,8 @@
 # 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')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +10 -1
index 9ed8ea6..9af855a 100644
@@ -17,6 +17,7 @@
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
+#include "rte_telemetry_parser.h"
 
 #define BUF_SIZE 1024
 #define ACTION_POST 1
@@ -285,6 +286,7 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
 static int32_t
 rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 {
+	int ret;
 	telemetry_client *client;
 	char client_buf[BUF_SIZE];
 	int bytes;
@@ -293,8 +295,15 @@ rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 		bytes = read(client->fd, client_buf, BUF_SIZE-1);
 		client_buf[bytes] = '\0';
 
-		if (bytes > 0)
+		if (bytes > 0) {
 			telemetry->request_client = client;
+			ret = rte_telemetry_parse(telemetry, client_buf);
+			if (ret < 0) {
+				TELEMETRY_LOG_WARN("Parse socket input failed: %i",
+						ret);
+				return -1;
+			}
+		}
 	}
 
 	return 0;
lib/librte_telemetry/rte_telemetry_internal.h +13 -0
index e3292cf..86a5ba1 100644
@@ -43,6 +43,11 @@ typedef struct telemetry_impl {
 	int register_fail_count;
 } telemetry_impl;
 
+enum rte_telemetry_parser_actions {
+	ACTION_GET = 0,
+	ACTION_DELETE = 2
+};
+
 int32_t
 rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
 
@@ -58,4 +63,12 @@ int32_t
 rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 	const char *client_path);
 
+/**
+ * This is a wrapper for the ethdev api rte_eth_find_next().
+ * If rte_eth_find_next() returns the same port id that we passed it,
+ * then we know that that port is active.
+ */
+int32_t
+rte_telemetry_is_port_active(int port_id);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c new file +569 -0

569 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser.h new file +13 -0
new file mode 100644
index 0000000..63e633d
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_PARSER_H_
+#define _RTE_TELEMETRY_PARSER_H_
+
+int32_t
+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);
+
+#endif
Signature · 1 line
2.9.5
#119 lore raw

PATCH v5 7/13 telemetry: update metrics before sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to update the statistics in the metrics library with values from the ethdev stats.

Values need to be updated before they are encoded into a JSON message and sent to the client that requested them. The JSON encoding will be added in a subsequent patch.

---
 lib/librte_telemetry/rte_telemetry.c          | 134 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 lib/librte_telemetry/rte_telemetry_parser.c   |  17 ++++
 3 files changed, 155 insertions(+)
lib/librte_telemetry/rte_telemetry.c +134 -0
index 9af855a..cd2bd12 100644
@@ -46,6 +46,78 @@ rte_telemetry_is_port_active(int port_id)
 	return 0;
 }
 
+static int32_t
+rte_telemetry_update_metrics_ethdev(struct telemetry_impl *telemetry,
+	uint16_t port_id, int reg_start_index)
+{
+	int ret, num_xstats, i;
+	struct rte_eth_xstat *eth_xstats;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_telemetry_is_port_active(port_id);
+	if (ret < 1) {
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", port_id,
+				num_xstats);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		free(eth_xstats);
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	uint64_t xstats_values[num_xstats];
+	for (i = 0; i < num_xstats; i++)
+		xstats_values[i] = eth_xstats[i].value;
+
+	ret = rte_metrics_update_values(port_id, reg_start_index, xstats_values,
+			num_xstats);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not update metrics values");
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		free(eth_xstats);
+		return -1;
+	}
+
+	free(eth_xstats);
+	return 0;
+}
+
 int32_t
 rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,
 	const char *json_string)
@@ -130,6 +202,68 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
+{
+	int ret, i;
+	char *json_buffer = NULL;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Invalid telemetry argument");
+		return -1;
+	}
+
+	if (metric_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid metric_ids array");
+		goto einval_fail;
+	}
+
+	if (num_metric_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_metric_ids, must be positive");
+		goto einval_fail;
+	}
+
+	if (port_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid port_ids array");
+		goto einval_fail;
+	}
+
+	if (num_port_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_port_ids, must be positive");
+		goto einval_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+
+		ret = rte_telemetry_update_metrics_ethdev(telemetry,
+			port_ids[i], telemetry->reg_index);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
+			return -1;
+		}
+	}
+
+	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not write to socket");
+		return -1;
+	}
+
+	return 0;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+
 static int32_t
 rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
 {
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 86a5ba1..0082cb2 100644
@@ -71,4 +71,8 @@ rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 int32_t
 rte_telemetry_is_port_active(int port_id);
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c +17 -0
index 6bc4c6d..084c160 100644
@@ -258,6 +258,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	int ret, num_metrics, i, p;
 	struct rte_metric_name *names;
 	uint64_t num_port_ids = 0;
+	uint32_t port_ids[RTE_MAX_ETHPORTS];
 
 	if (telemetry == NULL) {
 		TELEMETRY_LOG_ERR("Invalid telemetry argument");
@@ -313,6 +314,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	uint32_t stat_ids[num_metrics];
 
 	RTE_ETH_FOREACH_DEV(p) {
+		port_ids[num_port_ids] = p;
 		num_port_ids++;
 	}
 
@@ -337,6 +339,13 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 		goto fail;
 	}
 
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_metrics,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		goto fail;
+	}
+
 	return 0;
 
 fail:
@@ -428,6 +437,14 @@ rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl
 		TELEMETRY_LOG_ERR("Could not convert stat names to IDs");
 		return -1;
 	}
+
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_stat_names,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		return -1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.9.5
#120 lore raw

PATCH v5 8/13 telemetry: format json response when sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to create a JSON message in order to send it to a client socket.

When stats are requested by a client, they are retrieved from the metrics library and encoded in JSON format.

---
 lib/librte_telemetry/rte_telemetry.c | 309 ++++++++++++++++++++++++++++++++++-
 1 file changed, 307 insertions(+), 2 deletions(-)
lib/librte_telemetry/rte_telemetry.c +307 -2
index cd2bd12..122640a 100644
@@ -190,7 +190,7 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 		return -EPERM;
 	}
 
-	json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_buffer = json_dumps(root, 0);
 	json_decref(root);
 
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
@@ -202,6 +202,304 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+static int
+rte_telemetry_get_metrics(struct telemetry_impl *telemetry, uint32_t port_id,
+	struct rte_metric_value *metrics, struct rte_metric_name *names,
+	int num_metrics)
+{
+	int ret, num_values;
+
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Invalid metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	if (metrics == NULL) {
+		TELEMETRY_LOG_ERR("Metrics must be initialised.");
+		goto einval_fail;
+	}
+
+	if (names == NULL) {
+		TELEMETRY_LOG_ERR("Names must be initialised.");
+		goto einval_fail;
+	}
+
+	ret = rte_metrics_get_names(names, num_metrics);
+	if (ret < 0 || ret > num_metrics) {
+		TELEMETRY_LOG_ERR("Cannot get metrics names");
+		goto eperm_fail;
+	}
+
+	num_values = rte_metrics_get_values(port_id, NULL, 0);
+	ret = rte_metrics_get_values(port_id, metrics, num_values);
+	if (ret < 0 || ret > num_values) {
+		TELEMETRY_LOG_ERR("Cannot get metrics values");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_stat(struct telemetry_impl *telemetry, json_t *stats,
+	const char *metric_name, uint64_t metric_value)
+{
+	int ret;
+	json_t *stat = json_object();
+
+	if (stat == NULL) {
+		TELEMETRY_LOG_ERR("Could not create stat JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "name", json_string(metric_name));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Name field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "value", json_integer(metric_value));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Value field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(stats, stat);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat cannot be added to stats json array");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_port(struct telemetry_impl *telemetry,
+	uint32_t port_id, json_t *ports, uint32_t *metric_ids,
+	uint32_t num_metric_ids)
+{
+	struct rte_metric_value *metrics = 0;
+	struct rte_metric_name *names = 0;
+	int num_metrics, ret, err_ret;
+	json_t *port, *stats;
+	uint32_t i;
+
+	num_metrics = rte_metrics_get_names(NULL, 0);
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Cannot get metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	metrics = malloc(sizeof(struct rte_metric_value) * num_metrics);
+	names = malloc(sizeof(struct rte_metric_name) * num_metrics);
+	if (metrics == NULL || names == NULL) {
+		TELEMETRY_LOG_ERR("Cannot allocate memory");
+		free(metrics);
+		free(names);
+
+		err_ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (err_ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret  = rte_telemetry_get_metrics(telemetry, port_id, metrics, names,
+		num_metrics);
+	if (ret < 0) {
+		free(metrics);
+		free(names);
+		TELEMETRY_LOG_ERR("rte_telemetry_get_metrics failed");
+		return -1;
+	}
+
+	port = json_object();
+	stats = json_array();
+	if (port == NULL || stats == NULL) {
+		TELEMETRY_LOG_ERR("Could not create port/stats JSON objects");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(port, "port", json_integer(port_id));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port field cannot be set");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_metric_ids; i++) {
+		int metric_id = metric_ids[i];
+		int metric_index = -1;
+		int metric_name_key = -1;
+		int32_t j;
+		uint64_t metric_value;
+
+		if (metric_id >= num_metrics) {
+			TELEMETRY_LOG_ERR("Metric_id: %d is not valid",
+					metric_id);
+			goto einval_fail;
+		}
+
+		for (j = 0; j < num_metrics; j++) {
+			if (metrics[j].key == metric_id) {
+				metric_name_key = metrics[j].key;
+				metric_index = j;
+				break;
+			}
+		}
+
+		const char *metric_name = names[metric_name_key].name;
+		metric_value = metrics[metric_index].value;
+
+		if (metric_name_key < 0 || metric_index < 0) {
+			TELEMETRY_LOG_ERR("Could not get metric name/index");
+			goto eperm_fail;
+		}
+
+		ret = rte_telemetry_json_format_stat(telemetry, stats,
+			metric_name, metric_value);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format stat with id: %u failed",
+					metric_id);
+			free(metrics);
+			free(names);
+			return -1;
+		}
+	}
+
+	if (json_array_size(stats) == 0)
+		ret = json_object_set_new(port, "stats", json_null());
+	else
+		ret = json_object_set_new(port, "stats", stats);
+
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stats object cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(ports, port);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port object cannot be added to ports array");
+		goto eperm_fail;
+	}
+
+	free(metrics);
+	free(names);
+	return 0;
+
+eperm_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+static int32_t
+rte_telemetry_encode_json_format(struct telemetry_impl *telemetry,
+	uint32_t *port_ids, uint32_t num_port_ids, uint32_t *metric_ids,
+	uint32_t num_metric_ids, char **json_buffer)
+{
+	int ret;
+	json_t *root, *ports;
+	uint32_t i;
+
+	if (num_port_ids <= 0 || num_metric_ids <= 0) {
+		TELEMETRY_LOG_ERR("Please provide port and metric ids to query");
+		goto einval_fail;
+	}
+
+	ports = json_array();
+	if (ports == NULL) {
+		TELEMETRY_LOG_ERR("Could not create ports JSON array");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		ret = rte_telemetry_json_format_port(telemetry, port_ids[i],
+			ports, metric_ids, num_metric_ids);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format port in JSON failed");
+			return -1;
+		}
+	}
+
+	root = json_object();
+	if (root == NULL) {
+		TELEMETRY_LOG_ERR("Could not create root JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "status_code",
+		json_string("Status OK: 200"));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Status code field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "data", ports);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Data field cannot be set");
+		goto eperm_fail;
+	}
+
+	*json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_decref(root);
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
 int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
@@ -241,13 +539,20 @@ rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 		}
 
 		ret = rte_telemetry_update_metrics_ethdev(telemetry,
-			port_ids[i], telemetry->reg_index);
+				port_ids[i], telemetry->reg_index);
 		if (ret < 0) {
 			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
 			return -1;
 		}
 	}
 
+	ret = rte_telemetry_encode_json_format(telemetry, port_ids,
+		num_port_ids, metric_ids, num_metric_ids, &json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("JSON encode function failed");
+		return -1;
+	}
+
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
 	if (ret < 0) {
 		TELEMETRY_LOG_ERR("Could not write to socket");
Signature · 1 line
2.9.5
#121 lore raw

PATCH v5 9/13 telemetry: add tests for telemetry api

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

---
 lib/librte_telemetry/Makefile                     |   1 +
 lib/librte_telemetry/meson.build                  |   4 +-
 lib/librte_telemetry/rte_telemetry.c              | 653 ++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |  12 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   3 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  | 534 ++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |  39 ++
 lib/librte_telemetry/rte_telemetry_socket_tests.h |  36 ++
 lib/librte_telemetry/rte_telemetry_version.map    |   1 +
 9 files changed, 1281 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
lib/librte_telemetry/Makefile +1 -0
index 95c7296..1a05069 100644
@@ -22,6 +22,7 @@ LIBABIVER := 1
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 7450f96..57dd83d 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
-sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h', 'rte_telemetry_parser_test.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +653 -0

684 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h +12 -0
index d3b0d8d..958723b 100644
@@ -33,4 +33,16 @@ rte_telemetry_init(void);
 int32_t
 rte_telemetry_cleanup(void);
 
+/**
+ * Runs various tests to ensure telemetry initialisation and register/unregister
+ * functions are working correctly.
+ *
+ * @return
+ *  0 on success when all tests have passed
+ * @return
+ *  -1 on failure when the test has failed
+ */
+int32_t
+rte_telemetry_selftest(void);
+
 #endif
lib/librte_telemetry/rte_telemetry_internal.h +3 -0
index 0082cb2..de7afda 100644
@@ -75,4 +75,7 @@ int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
 
+int32_t
+rte_telemetry_socket_messaging_testing(int index, int socket);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser_test.c new file +534 -0

534 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser_test.h new file +39 -0
new file mode 100644
index 0000000..6ada852
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_TELEMETRY_PARSER_TEST_H_
+#define _RTE_TELEMETRY_PARSER_TEST_H_
+
+int32_t
+rte_telemetry_parser_test(struct telemetry_impl *telemetry);
+
+int32_t
+rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, json_t **data);
+
+int32_t
+rte_telemetry_create_json_request(int action, char *command,
+	const char *client_path, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, char **request,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
+	int action_choice, char *command_choice, int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
+	int action_choice, int *port_ids, int num_port_ids, int inv_choice);
+
+int32_t
+rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
+	*telemetry, int action_choice, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_unreg_request(int action_choice, const char *client_path,
+	int inv_choice);
+
+#endif
lib/librte_telemetry/rte_telemetry_socket_tests.h new file +36 -0
new file mode 100644
index 0000000..db9167c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdbool.h>
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
+#define _RTE_TELEMETRY_SOCKET_TESTING_H_
+
+int32_t
+rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
+	int fd);
+
+int32_t
+rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
+	int send_fd, int recv_fd);
+
+int32_t
+rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
+	int *recv_fd);
+
+#endif
lib/librte_telemetry/rte_telemetry_version.map +1 -0
index 992d227..98459fc 100644
@@ -2,5 +2,6 @@ DPDK_18.11 {
 	global:
 
 	rte_telemetry_init;
+	rte_telemetry_selftest;
 	local: *;
 };
Signature · 1 line
2.9.5
#122 lore raw

PATCH v5 10/13 telemetry: add ability to disable selftest

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

---
 lib/librte_telemetry/rte_telemetry.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/librte_telemetry/rte_telemetry.c +13 -10
index 82b46a5..7d97206 100644
@@ -660,6 +660,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
 	uint16_t pid;
 	int ret;
+	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
@@ -672,18 +673,20 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 	}
 
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (selftest) {
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+				telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Parser Tests Failed");
-		return -1;
-	}
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Parser Tests Failed");
+			return -1;
+		}
 
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+	}
 
 	return 0;
 }
Signature · 1 line
2.9.5
#123 lore raw

PATCH v5 11/13 doc: add telemetry documentation

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry for telemetry.

---
 MAINTAINERS                    |  5 +++
 doc/guides/howto/index.rst     |  1 +
 doc/guides/howto/telemetry.rst | 85 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)
 create mode 100644 doc/guides/howto/telemetry.rst
MAINTAINERS +5 -0
index 84b9ff7..e695a68 100644
@@ -1168,6 +1168,11 @@ F: test/bpf/
 F: test/test/test_bpf.c
 F: doc/guides/prog_guide/bpf_lib.rst
 
+Telemetry
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst
 
 Test Applications
 -----------------
doc/guides/howto/index.rst +1 -0
index e13a090..a642a2b 100644
@@ -17,3 +17,4 @@ HowTo Guides
     virtio_user_for_container_networking
     virtio_user_as_exceptional_path
     packet_capture_framework
+    telemetry
doc/guides/howto/telemetry.rst new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.9.5
#124 lore raw

PATCH v5 12/13 usertools: add client python script for telemetry

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds a python script which can be used as a demo client. The script is interactive and will allow the user to register, request statistics, and unregister.

To run the script, an argument for the client file path must be passed in: "python telemetry_client.py <file_path>".

This script is useful to see how the Telemetry API for DPDK is used, and how to make the initial connection.

---
 usertools/dpdk-telemetry-client.py | 116 +++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 usertools/dpdk-telemetry-client.py
usertools/dpdk-telemetry-client.py new file +116 -0
new file mode 100644
index 0000000..71c6be7
@@ -0,0 +1,116 @@
+# SPDK-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+import socket
+import os
+import sys
+import time
+
+BUFFER_SIZE = 200000
+
+METRICS_REQ = "{\"action\":0,\"command\":\"ports_all_stat_values\",\"data\":null}"
+API_REG = "{\"action\":1,\"command\":\"clients\",\"data\":{\"client_path\":\""
+API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
+DEFAULT_FP = "/var/run/dpdk/default_client"
+
+class Socket:
+
+    def __init__(self):
+        self.send_fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.recv_fd = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.client_fd = None
+
+    def __del__(self):
+        try:
+            self.send_fd.close()
+            self.recv_fd.close()
+            self.client_fd.close()
+        except:
+            print("Error - Sockets could not be closed")
+
+class Client:
+
+    def __init__(self): # Creates a client instance
+        self.socket = Socket()
+        self.file_path = None
+        self.choice = None
+        self.unregistered = 0
+
+    def __del__(self):
+        try:
+            if self.unregistered == 0:
+                self.unregister();
+        except:
+            print("Error - Client could not be destroyed")
+
+    def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client
+        self.file_path = file_path
+
+    def register(self): # Connects a client to DPDK-instance
+        if os.path.exists(self.file_path):
+            os.unlink(self.file_path)
+        try:
+            self.socket.recv_fd.bind(self.file_path)
+        except socket.error as msg:
+            print ("Error - Socket binding error: " + str(msg) + "\n")
+        self.socket.recv_fd.settimeout(2)
+        self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry")
+        JSON = (API_REG + self.file_path + "\"}}")
+        self.socket.send_fd.sendall(JSON)
+        self.socket.recv_fd.listen(1)
+        self.socket.client_fd = self.socket.recv_fd.accept()[0]
+
+    def unregister(self): # Unregister a given client
+        self.socket.client_fd.send(API_UNREG + self.file_path + "\"}}")
+        self.socket.client_fd.close()
+
+    def requestMetrics(self): # Requests metrics for given client
+        self.socket.client_fd.send(METRICS_REQ)
+        data = self.socket.client_fd.recv(BUFFER_SIZE)
+        print "\nResponse: \n", str(data)
+
+    def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
+        print("\nPlease enter the number of times you'd like to continuously request Metrics:")
+        n_requests = int(input("\n:"))
+        print("\033[F") #Removes the user input from screen, cleans it up
+        print("\033[K")
+        for i in range(n_requests):
+            self.requestMetrics()
+            time.sleep(sleep_time)
+
+    def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script
+        while self.choice != 3:
+            print("\nOptions Menu")
+            print("[1] Send for Metrics for all ports")
+            print("[2] Send for Metrics for all ports recursively")
+            print("[3] Unregister client")
+
+            try:
+                self.choice = int(input("\n:"))
+                print("\033[F") #Removes the user input for screen, cleans it up
+                print("\033[K")
+                if self.choice == 1:
+                    self.requestMetrics()
+                elif self.choice == 2:
+                    self.repeatedlyRequestMetrics(sleep_time)
+                elif self.choice == 3:
+                    self.unregister()
+                    self.unregistered = 1
+                else:
+                    print("Error - Invalid request choice")
+            except:
+                pass
+
+if __name__ == "__main__":
+
+    sleep_time = 1
+    file_path = ""
+    if (len(sys.argv) == 2):
+	file_path = sys.argv[1]
+    else:
+        print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")
+	file_path = DEFAULT_FP
+    client = Client()
+    client.getFilepath(file_path)
+    client.register()
+    client.interactiveMenu(sleep_time)
Signature · 1 line
2.9.5
#125 lore raw

PATCH v5 13/13 build: add dependency on telemetry to apps in meson

In reply to Kevin Laatz

This patch adds telemetry as a dependecy to all applications. Without these changes, the --telemetry flag will not be recognised and applications will fail to run if they want to enable telemetry.

---
 app/meson.build                  | 4 ++--
 app/pdump/meson.build            | 2 +-
 app/proc-info/meson.build        | 2 +-
 app/test-bbdev/meson.build       | 2 +-
 app/test-crypto-perf/meson.build | 2 +-
 app/test-pmd/meson.build         | 2 +-
 config/meson.build               | 3 +++
 lib/meson.build                  | 1 +
 meson.build                      | 1 +
 9 files changed, 12 insertions(+), 7 deletions(-)
app/meson.build +2 -2
index 99e0b93..8e716bf 100644
@@ -24,7 +24,7 @@ foreach app:apps
 	# use "deps" for internal DPDK dependencies, and "ext_deps" for
 	# external package/library requirements
 	ext_deps = []
-	deps = []
+	deps = ['telemetry']
 
 	subdir(name)
 
@@ -38,7 +38,7 @@ foreach app:apps
 
 		link_libs = []
 		if get_option('default_library') == 'static'
-			link_libs = dpdk_drivers
+			link_libs = dpdk_static_libraries + dpdk_drivers
 		endif
 
 		if allow_experimental_apis
app/pdump/meson.build +1 -1
index 988cb4e..116c27f 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'kvargs', 'pdump']
+deps += ['ethdev', 'kvargs', 'pdump']
app/proc-info/meson.build +1 -1
index 9c148e3..a52b2ee 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'metrics']
+deps += ['ethdev', 'metrics']
app/test-bbdev/meson.build +1 -1
index 653907d..eb8cc04 100644
@@ -6,4 +6,4 @@ sources = files('main.c',
 		'test_bbdev_perf.c',
 		'test_bbdev_vector.c')
 allow_experimental_apis = true
-deps = ['bbdev', 'bus_vdev']
+deps += ['bbdev', 'bus_vdev']
app/test-crypto-perf/meson.build +1 -1
index eacd7a0..d735b18 100644
@@ -12,4 +12,4 @@ sources = files('cperf_ops.c',
 		'cperf_test_vectors.c',
 		'cperf_test_verify.c',
 		'main.c')
-deps = ['cryptodev']
+deps += ['cryptodev']
app/test-pmd/meson.build +1 -1
index a0b3be0..c24f75f 100644
@@ -22,7 +22,7 @@ sources = files('cmdline.c',
 	'testpmd.c',
 	'txonly.c')
 
-deps = ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
+deps += ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
 if dpdk_conf.has('RTE_LIBRTE_PDUMP')
 	deps += 'pdump'
 endif
config/meson.build +3 -0
index 6f9228c..275f00b 100644
@@ -21,6 +21,9 @@ toolchain = cc.get_id()
 dpdk_conf.set_quoted('RTE_TOOLCHAIN', toolchain)
 dpdk_conf.set('RTE_TOOLCHAIN_' + toolchain.to_upper(), 1)
 
+add_project_link_arguments('-Wl,--no-as-needed', language: 'c')
+dpdk_extra_ldflags += '-Wl,--no-as-needed'
+
 # use pthreads
 add_project_link_arguments('-pthread', language: 'c')
 dpdk_extra_ldflags += '-pthread'
lib/meson.build +1 -0
index b5612ad..ef3f3a6 100644
@@ -127,6 +127,7 @@ foreach l:libraries
 					dependencies: shared_deps)
 
 			dpdk_libraries = [shared_lib] + dpdk_libraries
+			dpdk_static_libraries = [static_lib] + dpdk_static_libraries
 		endif # sources.length() > 0
 
 		set_variable('shared_' + libname, shared_dep)
meson.build +1 -0
index c9af335..f3bddb2 100644
@@ -12,6 +12,7 @@ project('DPDK', 'C',
 cc = meson.get_compiler('c')
 dpdk_conf = configuration_data()
 dpdk_libraries = []
+dpdk_static_libraries = []
 dpdk_drivers = []
 dpdk_extra_ldflags = []
 
Signature · 1 line
2.9.5
#126 lore raw
In reply to Kevin Laatz

Most of the issues I pointed out in v2 of this patchset is still here.

Quoted 131 lines · Kevin Laatz

This patchset introduces a Telemetry library for DPDK Service Assurance. This library provides an easy way to query DPDK Ethdev metrics.

The telemetry library provides a method for a service assurance component to retrieve metrics from a DPDK packet forwarding application. Communicating from the service assurance component to DPDK is done using a UNIX domain socket, passing a JSON formatted string. A reply is sent (again a JSON formatted string) of the current DPDK metrics.

The telemetry component makes use of the existing rte_metrics library to query values. The values to be transmitted via the telemetry infrastructure must be present in the Metrics library. Currently the ethdev values are pushed to the metrics library, and the queried from there there is an open question on how applications would like this to occur. Currently only ethdev to metrics functionality is implemented, however other subsystems like crypto, eventdev, keepalive etc can use similar mechanisms.

Exposing DPDK Telemetry via a socket interface enables service assurance agents like collectd to consume data from DPDK. This is vital for monitoring, fault-detection, and error reporting. A collectd plugin has been created to interact with the DPDK Telemetry component, showing how it can be used in practice. The collectd plugin will be upstreamed to collectd at a later stage. A small python script is provided in ./usertools/telemetry_client.py to quick-start using DPDK Telemetry.

Note: Despite opterr being set to 0, --telemetry said to be 'unrecognized' as a startup print. This is a cosmetic issue and will be addressed in the future.

---
v2:
- Reworked telemetry as part of EAL instead of using vdev (Gaetan)
- Refactored rte_telemetry_command (Gaetan)
- Added MAINTAINERS file entry (Stephen)
- Updated docs to reflect vdev to eal rework
- Removed collectd patch from patchset (Thomas)
- General code clean up from v1 feedback

v3:
- Reworked registering with eal and moved to rte_param (Gaetan)
- Added BSD implementation for rte_param (Gaetan)
- Updated the paths to align with the new runtime file location (Mattias)
- Fixed pointer checks to align with the coding style 1.8.1 (Mattias)
- Added missing decref's and close's (Mattias)
- Fixed runtime issue in Meson (was not recognising flag due to linking)
- More general clean up

v4:
- Added Doxygen comments for rte_param.h (Thomas)
- Made eal_get_runtime_dir a public function to use outside of EAL (Thomas)
- Reworked telemetry to get path using rte_eal_get_runtime_dir (Thomas)
- Fixed checkpatch coding style error

v5:
- Moved the BUF_SIZE define to fix build (Harry)
- Set default config for telemetry to 'n' (Harry)
- Improved Doxygen comments (Thomas)
- Cleaned up rte_param struct (Thomas)

Ciara Power, Brian Archbold and Kevin Laatz (10):
telemetry: initial telemetry infrastructure
telemetry: add initial connection socket
telemetry: add client feature and sockets
telemetry: add parser for client socket messages
telemetry: update metrics before sending stats
telemetry: format json response when sending stats
telemetry: add tests for telemetry api
telemetry: add ability to disable selftest
doc: add telemetry documentation
usertools: add client python script for telemetry

Kevin Laatz (3):
eal: add param register infrastructure
eal: make get runtime dir function public
build: add dependency on telemetry to apps in meson

  MAINTAINERS                                       |    5 +
  app/meson.build                                   |    4 +-
  app/pdump/meson.build                             |    2 +-
  app/proc-info/meson.build                         |    2 +-
  app/test-bbdev/meson.build                        |    2 +-
  app/test-crypto-perf/meson.build                  |    2 +-
  app/test-pmd/meson.build                          |    2 +-
  config/common_base                                |    5 +
  config/meson.build                                |    3 +
  doc/guides/howto/index.rst                        |    1 +
  doc/guides/howto/telemetry.rst                    |   85 +
  lib/Makefile                                      |    2 +
  lib/librte_eal/bsdapp/eal/Makefile                |    1 +
  lib/librte_eal/bsdapp/eal/eal.c                   |   20 +-
  lib/librte_eal/common/Makefile                    |    1 +
  lib/librte_eal/common/eal_filesystem.h            |   14 +-
  lib/librte_eal/common/include/rte_eal.h           |    9 +
  lib/librte_eal/common/include/rte_param.h         |   91 ++
  lib/librte_eal/common/meson.build                 |    2 +
  lib/librte_eal/common/rte_param.c                 |   47 +
  lib/librte_eal/linuxapp/eal/Makefile              |    1 +
  lib/librte_eal/linuxapp/eal/eal.c                 |   20 +-
  lib/librte_eal/rte_eal_version.map                |    2 +
  lib/librte_telemetry/Makefile                     |   30 +
  lib/librte_telemetry/meson.build                  |    9 +
  lib/librte_telemetry/rte_telemetry.c              | 1810 +++++++++++++++++++++
  lib/librte_telemetry/rte_telemetry.h              |   48 +
  lib/librte_telemetry/rte_telemetry_internal.h     |   81 +
  lib/librte_telemetry/rte_telemetry_parser.c       |  586 +++++++
  lib/librte_telemetry/rte_telemetry_parser.h       |   13 +
  lib/librte_telemetry/rte_telemetry_parser_test.c  |  534 ++++++
  lib/librte_telemetry/rte_telemetry_parser_test.h  |   39 +
  lib/librte_telemetry/rte_telemetry_socket_tests.h |   36 +
  lib/librte_telemetry/rte_telemetry_version.map    |    7 +
  lib/meson.build                                   |    3 +-
  meson.build                                       |    1 +
  mk/rte.app.mk                                     |    1 +
  usertools/dpdk-telemetry-client.py                |  116 ++
  38 files changed, 3618 insertions(+), 19 deletions(-)

create mode 100644 doc/guides/howto/telemetry.rst
create mode 100644 lib/librte_eal/common/include/rte_param.h create mode 100644 lib/librte_eal/common/rte_param.c create mode 100644 lib/librte_telemetry/Makefile
create mode 100644 lib/librte_telemetry/meson.build create mode 100644 lib/librte_telemetry/rte_telemetry.c create mode 100644 lib/librte_telemetry/rte_telemetry.h create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h create mode 100644 lib/librte_telemetry/rte_telemetry_version.map create mode 100644 usertools/dpdk-telemetry-client.py

#127 lore raw

Hi Mattias,

Quoted 1 line · Mattias Rönnblom

Most of the issues I pointed out in v2 of this patchset is still here.

Will recheck feedback for the next version.

With regards to comments on v2, 3/10, could you please help provide clarification on the below?

<Copy from the v2 feedback>

Quoted 17 lines · Mattias Rönnblom

Review

Quoted 13 lines · Kevin Laatz

From: Ciara Power <[email protected]>

(quoted diff) +12 -0
+
+    if (!telemetry->request_client) {
+        TELEMETRY_LOG_ERR("No client has been chosen to write to");
+        return -1;
+    } > +
+    if (!json_string) {
+        TELEMETRY_LOG_ERR("Invalid JSON string!");
+        return -1;
+    }
+
+    ret = send(telemetry->request_client->fd,
+            json_string, strlen(json_string), 0);

How would this code handle a partial success (as in, for example, half of the string fits the socket buffer)? In not, maybe switching over to a SOCK_SEQPACKET AF_UNIX socket would be the best way around it.

Is the suggestion here simply to use socket(AF_UNIX, SOCK_SEQPACKET) instead of (AF_UNIX, SOCK_STREAM) ?

Quoted 6 lines
Quoted 3 lines

+
+    buffer_read = read(telemetry->accept_fd, buf, BUF_SIZE-1);

This and the below code seem to assume that read() returns one and only one message, but on a SOCK_STREAM, there is no such thing as a message. It's a byte stream, and you need to provide your own framing, or have an application protocol which allows only have one outstanding request. If you do the latter, you still need to allow for "short" (partial) read()s (i.e. re-read() until done).

Will the above solve this part of the problem too?

Best regards,
Kevin

#128 lore raw
Quoted 18 lines · Kevin
Quoted 17 lines · Mattias Rönnblom

Review

Quoted 13 lines · Kevin Laatz

From: Ciara Power <[email protected]>

(quoted diff) +12 -0
+
+    if (!telemetry->request_client) {
+        TELEMETRY_LOG_ERR("No client has been chosen to write to");
+        return -1;
+    } > +
+    if (!json_string) {
+        TELEMETRY_LOG_ERR("Invalid JSON string!");
+        return -1;
+    }
+
+    ret = send(telemetry->request_client->fd,
+            json_string, strlen(json_string), 0);

How would this code handle a partial success (as in, for example, half of the string fits the socket buffer)? In not, maybe switching over to a SOCK_SEQPACKET AF_UNIX socket would be the best way around it.

Quoted 1 line

Is the suggestion here simply to use socket(AF_UNIX, SOCK_SEQPACKET) instead of (AF_UNIX, SOCK_STREAM) ?

That would be the most straight-forward to the problem, I think. Linux' SOCK_SEQPACKET implementation has problems with really large messages (since a per-message linear buffer is allocated), but I'm guessing these messages are not in the hundreds-of-kb range.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+
+    buffer_read = read(telemetry->accept_fd, buf, BUF_SIZE-1);

This and the below code seem to assume that read() returns one and only one message, but on a SOCK_STREAM, there is no such thing as a message. It's a byte stream, and you need to provide your own framing, or have an application protocol which allows only have one outstanding request. If you do the latter, you still need to allow for "short" (partial) read()s (i.e. re-read() until done).

Will the above solve this part of the problem too?

Yes. The kernel will delivered the application (at most) one message, in its entirety.

#129 lore raw

Hi Mattias,

Thanks for the input and clarification. I will include these changes in the v6.

Regards,
Kevin

Quoted 33 lines · Mattias Rönnblom
Quoted 18 lines · Kevin
Quoted 17 lines · Mattias Rönnblom

Review

Quoted 13 lines · Kevin Laatz

From: Ciara Power <[email protected]>

(quoted diff) +12 -0
+
+    if (!telemetry->request_client) {
+        TELEMETRY_LOG_ERR("No client has been chosen to write to");
+        return -1;
+    } > +
+    if (!json_string) {
+        TELEMETRY_LOG_ERR("Invalid JSON string!");
+        return -1;
+    }
+
+    ret = send(telemetry->request_client->fd,
+            json_string, strlen(json_string), 0);

How would this code handle a partial success (as in, for example, half of the string fits the socket buffer)? In not, maybe switching over to a SOCK_SEQPACKET AF_UNIX socket would be the best way around it.

Quoted 1 line

Is the suggestion here simply to use socket(AF_UNIX, SOCK_SEQPACKET) instead of (AF_UNIX, SOCK_STREAM) ?

That would be the most straight-forward to the problem, I think. Linux' SOCK_SEQPACKET implementation has problems with really large messages (since a per-message linear buffer is allocated), but I'm guessing these messages are not in the hundreds-of-kb range.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

+
+    buffer_read = read(telemetry->accept_fd, buf, BUF_SIZE-1);

This and the below code seem to assume that read() returns one and only one message, but on a SOCK_STREAM, there is no such thing as a message. It's a byte stream, and you need to provide your own framing, or have an application protocol which allows only have one outstanding request. If you do the latter, you still need to allow for "short" (partial) read()s (i.e. re-read() until done).

Will the above solve this part of the problem too?

Yes. The kernel will delivered the application (at most) one message, in its entirety.

#130 lore raw

v6 cover introduce telemetry library

In reply to Kevin Laatz

This patchset introduces a Telemetry library for DPDK Service Assurance. This library provides an easy way to query DPDK Ethdev metrics.

The telemetry library provides a method for a service assurance component to retrieve metrics from a DPDK packet forwarding application. Communicating from the service assurance component to DPDK is done using a UNIX domain socket, passing a JSON formatted string. A reply is sent (again a JSON formatted string) of the current DPDK metrics.

The telemetry component makes use of the existing rte_metrics library to query values. The values to be transmitted via the telemetry infrastructure must be present in the Metrics library. Currently the ethdev values are pushed to the metrics library, and the queried from there there is an open question on how applications would like this to occur. Currently only ethdev to metrics functionality is implemented, however other subsystems like crypto, eventdev, keepalive etc can use similar mechanisms.

Exposing DPDK Telemetry via a socket interface enables service assurance agents like collectd to consume data from DPDK. This is vital for monitoring, fault-detection, and error reporting. A collectd plugin has been created to interact with the DPDK Telemetry component, showing how it can be used in practice. The collectd plugin will be upstreamed to collectd at a later stage. A small python script is provided in ./usertools/telemetry_client.py to quick-start using DPDK Telemetry.

Note: Despite opterr being set to 0, --telemetry said to be 'unrecognized' as a startup print. This is a cosmetic issue and will be addressed in the future.

---
v2:
- Reworked telemetry as part of EAL instead of using vdev (Gaetan)
- Refactored rte_telemetry_command (Gaetan)
- Added MAINTAINERS file entry (Stephen)
- Updated docs to reflect vdev to eal rework
- Removed collectd patch from patchset (Thomas)
- General code clean up from v1 feedback

v3:
- Reworked registering with eal and moved to rte_param (Gaetan)
- Added BSD implementation for rte_param (Gaetan)
- Updated the paths to align with the new runtime file location (Mattias)
- Fixed pointer checks to align with the coding style 1.8.1 (Mattias)
- Added missing decref's and close's (Mattias)
- Fixed runtime issue in Meson (was not recognising flag due to linking)
- More general clean up

v4:
- Added Doxygen comments for rte_param.h (Thomas)
- Made eal_get_runtime_dir a public function to use outside of EAL (Thomas)
- Reworked telemetry to get path using rte_eal_get_runtime_dir (Thomas)
- Fixed checkpatch coding style error

v5:
- Moved the BUF_SIZE define to fix build (Harry)
- Set default config for telemetry to 'n' (Harry)
- Improved Doxygen comments (Thomas)
- Cleaned up rte_param struct (Thomas)

v6:
- Renamed rte_param to rte_option (Thomas)
- Moved internal functions to eal_private.h (Gaetan)
- Added fail check for pthread_attr_init() (Mattias)
- Changed socket implementation to SOCK_SEQPACKET (Mattias)
- Added check to avoid option duplicates (Gaetan)
- Removed telemetry specifics from Doxygen comment (Gaetan)
- General Doxygen clean-up (Thomas)
- General code clean-up

Ciara Power, Brian Archbold and Kevin Laatz (10):
telemetry: initial telemetry infrastructure
telemetry: add initial connection socket
telemetry: add client feature and sockets
telemetry: add parser for client socket messages
telemetry: update metrics before sending stats
telemetry: format json response when sending stats
telemetry: add tests for telemetry api
telemetry: add ability to disable selftest
doc: add telemetry documentation
usertools: add client python script for telemetry

Kevin Laatz (3):
eal: add option register infrastructure
eal: make get runtime dir function public
build: add dependency on telemetry to apps in meson

 MAINTAINERS                                       |    5 +
 app/meson.build                                   |    4 +-
 app/pdump/meson.build                             |    2 +-
 app/proc-info/meson.build                         |    2 +-
 app/test-bbdev/meson.build                        |    2 +-
 app/test-crypto-perf/meson.build                  |    2 +-
 app/test-pmd/meson.build                          |    2 +-
 config/common_base                                |    5 +
 config/meson.build                                |    3 +
 doc/guides/howto/index.rst                        |    1 +
 doc/guides/howto/telemetry.rst                    |   85 +
 lib/Makefile                                      |    2 +
 lib/librte_eal/bsdapp/eal/Makefile                |    1 +
 lib/librte_eal/bsdapp/eal/eal.c                   |   16 +-
 lib/librte_eal/common/Makefile                    |    1 +
 lib/librte_eal/common/eal_filesystem.h            |   15 +-
 lib/librte_eal/common/eal_private.h               |   21 +
 lib/librte_eal/common/include/rte_eal.h           |    9 +
 lib/librte_eal/common/include/rte_option.h        |   63 +
 lib/librte_eal/common/meson.build                 |    2 +
 lib/librte_eal/common/rte_option.c                |   54 +
 lib/librte_eal/linuxapp/eal/Makefile              |    1 +
 lib/librte_eal/linuxapp/eal/eal.c                 |   16 +-
 lib/librte_eal/rte_eal_version.map                |    2 +
 lib/librte_telemetry/Makefile                     |   30 +
 lib/librte_telemetry/meson.build                  |    9 +
 lib/librte_telemetry/rte_telemetry.c              | 1816 +++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |   48 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   81 +
 lib/librte_telemetry/rte_telemetry_parser.c       |  586 +++++++
 lib/librte_telemetry/rte_telemetry_parser.h       |   13 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  |  534 ++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |   39 +
 lib/librte_telemetry/rte_telemetry_socket_tests.h |   36 +
 lib/librte_telemetry/rte_telemetry_version.map    |    7 +
 lib/meson.build                                   |    3 +-
 meson.build                                       |    1 +
 mk/rte.app.mk                                     |    1 +
 usertools/dpdk-telemetry-client.py                |  116 ++
 39 files changed, 3617 insertions(+), 19 deletions(-)
 create mode 100644 doc/guides/howto/telemetry.rst
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
 create mode 100644 usertools/dpdk-telemetry-client.py
Signature · 1 line
2.9.5
#131 lore raw

PATCH v6 1/13 eal: add option register infrastructure

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

---
 lib/librte_eal/bsdapp/eal/Makefile         |  1 +
 lib/librte_eal/bsdapp/eal/eal.c            | 14 ++++++-
 lib/librte_eal/common/Makefile             |  1 +
 lib/librte_eal/common/eal_private.h        | 21 ++++++++++
 lib/librte_eal/common/include/rte_option.h | 63 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/meson.build          |  2 +
 lib/librte_eal/common/rte_option.c         | 54 +++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile       |  1 +
 lib/librte_eal/linuxapp/eal/eal.c          | 14 ++++++-
 lib/librte_eal/rte_eal_version.map         |  1 +
 10 files changed, 170 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d27da3d..03ead51 100644
@@ -66,6 +66,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
 
lib/librte_eal/bsdapp/eal/eal.c +13 -1
index d7ae9d6..8904fe3 100644
@@ -42,6 +42,7 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 
@@ -414,12 +415,20 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -788,6 +797,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/common/Makefile +1 -0
index cca6882..87d8c45 100644
@@ -12,6 +12,7 @@ INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h
+INC += rte_option.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
lib/librte_eal/common/eal_private.h +21 -0
index 4f809a8..e633d7d 100644
@@ -304,4 +304,25 @@ int
 rte_devargs_layers_parse(struct rte_devargs *devargs,
 			 const char *devstr);
 
+/**
+ * Check if the option is registered.
+ *
+ * @param option
+ *  The option to be parsed.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_option_parse(const char *opt);
+
+/**
+ * Iterate through the registered options and execute the associated
+ * callback if enabled.
+ */
+void
+rte_option_init(void);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_option.h new file +63 -0

63 lines not on this page · raw message

lib/librte_eal/common/meson.build +2 -0
index b7fc984..f879e65 100644
@@ -33,6 +33,7 @@ common_sources = files(
 	'malloc_mp.c',
 	'rte_keepalive.c',
 	'rte_malloc.c',
+	'rte_option.c',
 	'rte_reciprocal.c',
 	'rte_service.c'
 )
@@ -70,6 +71,7 @@ common_headers = files(
 	'include/rte_malloc_heap.h',
 	'include/rte_memory.h',
 	'include/rte_memzone.h',
+	'include/rte_option.h',
 	'include/rte_pci_dev_feature_defs.h',
 	'include/rte_pci_dev_features.h',
 	'include/rte_per_lcore.h',
lib/librte_eal/common/rte_option.c new file +54 -0

54 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 5c16bc4..d4df958 100644
@@ -74,6 +74,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
 
lib/librte_eal/linuxapp/eal/eal.c +13 -1
index 4a55d3b..f0ad3aa 100644
@@ -48,6 +48,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
@@ -600,12 +601,20 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -1071,6 +1080,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/rte_eal_version.map +1 -0
index 73282bb..09e0816 100644
@@ -341,6 +341,7 @@ EXPERIMENTAL {
 	rte_mp_request_sync;
 	rte_mp_request_async;
 	rte_mp_sendmsg;
+	rte_option_register;
 	rte_service_lcore_attr_get;
 	rte_service_lcore_attr_reset_all;
 	rte_service_may_be_active;
Signature · 1 line
2.9.5
#132 lore raw

PATCH v6 2/13 eal: make get runtime dir function public

In reply to Kevin Laatz

This patch makes the eal_get_runtime_dir() API public so it can be used from outside EAL.

---
Note: I have added rte_eal_get_runtime_dir() to the 18.11 version in the .map file instead of the EXPERIMENTAL section as the function already existed, we just renamed it and made it public.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  2 +-
 lib/librte_eal/common/eal_filesystem.h  | 15 ++++++++-------
 lib/librte_eal/common/include/rte_eal.h |  9 +++++++++
 lib/librte_eal/linuxapp/eal/eal.c       |  2 +-
 lib/librte_eal/rte_eal_version.map      |  1 +
 5 files changed, 20 insertions(+), 9 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +1 -1
index 8904fe3..6101fdc 100644
@@ -142,7 +142,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/common/eal_filesystem.h +8 -7
index de05feb..b3e8ae5 100644
@@ -27,7 +27,7 @@ eal_create_runtime_dir(void);
 
 /* returns runtime dir */
 const char *
-eal_get_runtime_dir(void);
+rte_eal_get_runtime_dir(void);
 
 #define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
@@ -35,7 +35,7 @@ eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
@@ -47,7 +47,7 @@ eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
 	return buffer;
 }
@@ -55,7 +55,8 @@ eal_mp_socket_path(void)
 #define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(),
+			name);
 	return buffer;
 }
 
@@ -66,7 +67,7 @@ eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
@@ -78,7 +79,7 @@ eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
@@ -99,7 +100,7 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, rte_eal_get_runtime_dir(),
 			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
lib/librte_eal/common/include/rte_eal.h +9 -0
index e114dcb..e19f74e 100644
@@ -498,6 +498,15 @@ enum rte_iova_mode rte_eal_iova_mode(void);
 const char *
 rte_eal_mbuf_user_pool_ops(void);
 
+/**
+ * Get the runtime directory of DPDK
+ *
+ * @return
+ *  The runtime directory path of DPDK
+ */
+const char *
+rte_eal_get_runtime_dir(void);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/linuxapp/eal/eal.c +1 -1
index f0ad3aa..1f6522c 100644
@@ -150,7 +150,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/rte_eal_version.map +1 -0
index 09e0816..64f60ec 100644
@@ -265,6 +265,7 @@ DPDK_18.08 {
 DPDK_18.11 {
 	global:
 
+	rte_eal_get_runtime_dir;
 	rte_strscpy;
 
 } DPDK_18.08;
Signature · 1 line
2.9.5
#133 lore raw

PATCH v6 3/13 telemetry: initial telemetry infrastructure

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

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.

---
 config/common_base                             |   5 +
 lib/Makefile                                   |   2 +
 lib/librte_telemetry/Makefile                  |  28 ++++++
 lib/librte_telemetry/meson.build               |   7 ++
 lib/librte_telemetry/rte_telemetry.c           | 123 +++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h           |  36 ++++++++
 lib/librte_telemetry/rte_telemetry_internal.h  |  32 +++++++
 lib/librte_telemetry/rte_telemetry_version.map |   6 ++
 lib/meson.build                                |   2 +-
 mk/rte.app.mk                                  |   1 +
 10 files changed, 241 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
config/common_base +5 -0
index acc5211..f561eb4 100644
@@ -722,6 +722,11 @@ CONFIG_RTE_LIBRTE_HASH=y
 CONFIG_RTE_LIBRTE_HASH_DEBUG=n
 
 #
+# Compile librte_telemetry
+#
+CONFIG_RTE_LIBRTE_TELEMETRY=n
+
+#
 # Compile librte_efd
 #
 CONFIG_RTE_LIBRTE_EFD=y
lib/Makefile +2 -0
index 8c83942..2b446c6 100644
@@ -105,6 +105,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
lib/librte_telemetry/Makefile new file +28 -0
new file mode 100644
index 0000000..0d61361
@@ -0,0 +1,28 @@
+# 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
+LDLIBS += -ljansson
+
+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
lib/librte_telemetry/meson.build new file +7 -0
new file mode 100644
index 0000000..7716076
@@ -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'
lib/librte_telemetry/rte_telemetry.c new file +123 -0

123 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h new file +36 -0
new file mode 100644
index 0000000..d3b0d8d
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdint.h>
+
+#ifndef _RTE_TELEMETRY_H_
+#define _RTE_TELEMETRY_H_
+
+/**
+ * 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_telemetry_init(void);
+
+/**
+ * Clean up and free memory.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -EPERM on failure
+ */
+int32_t
+rte_telemetry_cleanup(void);
+
+#endif
lib/librte_telemetry/rte_telemetry_internal.h new file +32 -0
new file mode 100644
index 0000000..4e810a8
@@ -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
lib/librte_telemetry/rte_telemetry_version.map new file +6 -0
new file mode 100644
index 0000000..992d227
@@ -0,0 +1,6 @@
+DPDK_18.11 {
+	global:
+
+	rte_telemetry_init;
+	local: *;
+};
lib/meson.build +1 -1
index 3acc67e..b5612ad 100644
@@ -24,7 +24,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')
mk/rte.app.mk +1 -0
index 32579e4..35594b9 100644
@@ -80,6 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#134 lore raw

PATCH v6 4/13 telemetry: add initial connection socket

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the telemetry UNIX socket. It is used to allow connections from external clients.

On the initial connection from a client, ethdev stats are registered in the metrics library, to allow for their retrieval at a later stage.

---
 lib/librte_telemetry/rte_telemetry.c          | 226 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 2 files changed, 230 insertions(+)
lib/librte_telemetry/rte_telemetry.c +226 -0
index ee9c90f..10311be 100644
@@ -3,23 +3,163 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include <pthread.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #include <rte_eal.h>
 #include <rte_ethdev.h>
 #include <rte_metrics.h>
 #include <rte_option.h>
+#include <rte_string_fns.h>
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
 
+#define BUF_SIZE 1024
 #define SLEEP_TIME 10
 
 static telemetry_impl *static_telemetry;
 
+static void
+rte_telemetry_get_runtime_dir(char *socket_path, size_t size)
+{
+	snprintf(socket_path, size, "%s/telemetry", rte_eal_get_runtime_dir());
+}
+
+int32_t
+rte_telemetry_is_port_active(int port_id)
+{
+	int ret;
+
+	ret = rte_eth_find_next(port_id);
+	if (ret == port_id)
+		return 1;
+
+	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
+		port_id);
+	return 0;
+}
+
+static int32_t
+rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
+{
+	int ret, num_xstats, ret_val, i;
+	struct rte_eth_xstat *eth_xstats = NULL;
+	struct rte_eth_xstat_name *eth_xstats_names = NULL;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		return -EINVAL;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d",
+				port_id, num_xstats);
+		return -EPERM;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		return -ENOMEM;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	const char *xstats_names[num_xstats];
+	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	if (eth_xstats_names == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats_names");
+		ret_val = -ENOMEM;
+		goto free_xstats;
+	}
+
+	ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	for (i = 0; i < num_xstats; i++)
+		xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name;
+
+	ret_val = rte_metrics_reg_names(xstats_names, num_xstats);
+	if (ret_val < 0) {
+		TELEMETRY_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
+		ret_val = -1;
+		goto free_xstats;
+	}
+
+	goto free_xstats;
+
+free_xstats:
+	free(eth_xstats);
+	free(eth_xstats_names);
+	return ret_val;
+}
+
+static int32_t
+rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
+{
+	uint16_t pid;
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		telemetry->reg_index =
+			rte_telemetry_reg_ethdev_to_metrics(pid);
+		break;
+	}
+
+	if (telemetry->reg_index < 0) {
+		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+		return -1;
+	}
+
+	telemetry->metrics_register_done = 1;
+
+	return 0;
+}
+
+static int32_t
+rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
+{
+	int ret;
+
+	if (telemetry->accept_fd == 0 || telemetry->accept_fd == -1) {
+		ret = listen(telemetry->server_fd, 1);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Listening error with server fd");
+			return -1;
+		}
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
+
+		if (telemetry->accept_fd >= 0 &&
+			telemetry->metrics_register_done == 0) {
+			ret = rte_telemetry_initial_accept(telemetry);
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Failed to run initial configurations/tests");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int32_t
 rte_telemetry_run(void *userdata)
 {
+	int ret;
 	struct telemetry_impl *telemetry = userdata;
 
 	if (telemetry == NULL) {
@@ -27,6 +167,12 @@ rte_telemetry_run(void *userdata)
 		return -1;
 	}
 
+	ret = rte_telemetry_accept_new_client(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Accept and read new client failed");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -50,6 +196,68 @@ static void
 	pthread_exit(0);
 }
 
+static int32_t
+rte_telemetry_set_socket_nonblock(int fd)
+{
+	int flags;
+
+	if (fd < 0) {
+		TELEMETRY_LOG_ERR("Invalid fd provided");
+		return -1;
+	}
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0)
+		flags = 0;
+
+	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+static int32_t
+rte_telemetry_create_socket(struct telemetry_impl *telemetry)
+{
+	int ret;
+	struct sockaddr_un addr;
+	char socket_path[BUF_SIZE];
+
+	if (telemetry == NULL)
+		return -1;
+
+	telemetry->server_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (telemetry->server_fd == -1) {
+		TELEMETRY_LOG_ERR("Failed to open socket");
+		return -1;
+	}
+
+	ret  = rte_telemetry_set_socket_nonblock(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		goto close_socket;
+	}
+
+	addr.sun_family = AF_UNIX;
+	rte_telemetry_get_runtime_dir(socket_path, sizeof(socket_path));
+	strlcpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
+	unlink(socket_path);
+
+	if (bind(telemetry->server_fd, (struct sockaddr *)&addr,
+		sizeof(addr)) < 0) {
+		TELEMETRY_LOG_ERR("Socket binding error");
+		goto close_socket;
+	}
+
+	return 0;
+
+close_socket:
+	if (close(telemetry->server_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
+	return -1;
+}
+
 int32_t
 rte_telemetry_init()
 {
@@ -77,6 +285,14 @@ rte_telemetry_init()
 		return -EPERM;
 	}
 
+	ret = rte_telemetry_create_socket(static_telemetry);
+	if (ret < 0) {
+		ret = rte_telemetry_cleanup();
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+		return -EPERM;
+	}
+
 	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
 		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
 		(void *)static_telemetry);
@@ -95,11 +311,21 @@ rte_telemetry_init()
 int32_t
 rte_telemetry_cleanup(void)
 {
+	int ret;
 	struct telemetry_impl *telemetry = static_telemetry;
+
+	ret = close(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
 	telemetry->thread_status = 0;
 	pthread_join(telemetry->thread_id, NULL);
 	free(telemetry);
 	static_telemetry = NULL;
+
 	return 0;
 }
 
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 4e810a8..569d56a 100644
@@ -24,9 +24,13 @@ extern int telemetry_log_level;
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
 typedef struct telemetry_impl {
+	int accept_fd;
+	int server_fd;
 	pthread_t thread_id;
 	int thread_status;
 	uint32_t socket_id;
+	int reg_index;
+	int metrics_register_done;
 } telemetry_impl;
 
 #endif
Signature · 1 line
2.9.5
#135 lore raw

Re: [PATCH v6 04/13] telemetry: add initial connection socket

Quoted 149 lines · Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the telemetry UNIX socket. It is used to allow connections from external clients.

On the initial connection from a client, ethdev stats are registered in the metrics library, to allow for their retrieval at a later stage.

---
  lib/librte_telemetry/rte_telemetry.c          | 226 ++++++++++++++++++++++++++
  lib/librte_telemetry/rte_telemetry_internal.h |   4 +
  2 files changed, 230 insertions(+)
lib/librte_telemetry/rte_telemetry.c +109 -0
index ee9c90f..10311be 100644
@@ -3,23 +3,163 @@
   */
 
  #include <unistd.h>
+#include <fcntl.h>
  #include <pthread.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
  #include <rte_eal.h>
  #include <rte_ethdev.h>
  #include <rte_metrics.h>
  #include <rte_option.h>
+#include <rte_string_fns.h>
 
  #include "rte_telemetry.h"
  #include "rte_telemetry_internal.h"
 
+#define BUF_SIZE 1024
  #define SLEEP_TIME 10
 
  static telemetry_impl *static_telemetry;
 
+static void
+rte_telemetry_get_runtime_dir(char *socket_path, size_t size)
+{
+	snprintf(socket_path, size, "%s/telemetry", rte_eal_get_runtime_dir());
+}
+
+int32_t
+rte_telemetry_is_port_active(int port_id)
+{
+	int ret;
+
+	ret = rte_eth_find_next(port_id);
+	if (ret == port_id)
+		return 1;
+
+	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
+		port_id);
+	return 0;
+}
+
+static int32_t
+rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
+{
+	int ret, num_xstats, ret_val, i;
+	struct rte_eth_xstat *eth_xstats = NULL;
+	struct rte_eth_xstat_name *eth_xstats_names = NULL;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		return -EINVAL;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d",
+				port_id, num_xstats);
+		return -EPERM;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		return -ENOMEM;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	const char *xstats_names[num_xstats];
+	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	if (eth_xstats_names == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats_names");
+		ret_val = -ENOMEM;
+		goto free_xstats;
+	}
+
+	ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	for (i = 0; i < num_xstats; i++)
+		xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name;
+
+	ret_val = rte_metrics_reg_names(xstats_names, num_xstats);
+	if (ret_val < 0) {
+		TELEMETRY_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
+		ret_val = -1;
+		goto free_xstats;
+	}
+
+	goto free_xstats;
+
+free_xstats:
+	free(eth_xstats);
+	free(eth_xstats_names);
+	return ret_val;
+}
+
+static int32_t
+rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
+{
+	uint16_t pid;
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		telemetry->reg_index =
+			rte_telemetry_reg_ethdev_to_metrics(pid);
+		break;
+	}
+
+	if (telemetry->reg_index < 0) {
+		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+		return -1;
+	}
+
+	telemetry->metrics_register_done = 1;

lib/librte_telemetry/rte_telemetry.c line 138

Quoted 10 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+
+	return 0;
+}
+
+static int32_t
+rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
+{
+	int ret;
+
+	if (telemetry->accept_fd == 0 || telemetry->accept_fd == -1) {

Is this intentional? If so, what's the meaning of "accept_fd == 0", as oppose to when accept_fd is -1.

Quoted 90 lines
lib/librte_telemetry/rte_telemetry.c +73 -0
+		ret = listen(telemetry->server_fd, 1);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Listening error with server fd");
+			return -1;
+		}
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
+
+		if (telemetry->accept_fd >= 0 &&
+			telemetry->metrics_register_done == 0) {
+			ret = rte_telemetry_initial_accept(telemetry);
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Failed to run initial configurations/tests");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
  static int32_t
  rte_telemetry_run(void *userdata)
  {
+	int ret;
  	struct telemetry_impl *telemetry = userdata;
 
  	if (telemetry == NULL) {
@@ -27,6 +167,12 @@ rte_telemetry_run(void *userdata)
  		return -1;
  	}
 
+	ret = rte_telemetry_accept_new_client(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Accept and read new client failed");
+		return -1;
+	}
+
  	return 0;
  }
 
@@ -50,6 +196,68 @@ static void
  	pthread_exit(0);
  }
 
+static int32_t
+rte_telemetry_set_socket_nonblock(int fd)
+{
+	int flags;
+
+	if (fd < 0) {
+		TELEMETRY_LOG_ERR("Invalid fd provided");
+		return -1;
+	}
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0)
+		flags = 0;
+
+	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+static int32_t
+rte_telemetry_create_socket(struct telemetry_impl *telemetry)
+{
+	int ret;
+	struct sockaddr_un addr;
+	char socket_path[BUF_SIZE];
+
+	if (telemetry == NULL)
+		return -1;
+
+	telemetry->server_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (telemetry->server_fd == -1) {
+		TELEMETRY_LOG_ERR("Failed to open socket");
+		return -1;
+	}
+
+	ret  = rte_telemetry_set_socket_nonblock(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		goto close_socket;
+	}
+
+	addr.sun_family = AF_UNIX;
+	rte_telemetry_get_runtime_dir(socket_path, sizeof(socket_path));
+	strlcpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
+	unlink(socket_path);
+
+	if (bind(telemetry->server_fd, (struct sockaddr *)&addr,
+		sizeof(addr)) < 0) {

lib/librte_telemetry/rte_telemetry.c static void · line 254

Quoted 10 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+		TELEMETRY_LOG_ERR("Socket binding error");
+		goto close_socket;
+	}
+
+	return 0;
+
+close_socket:
+	if (close(telemetry->server_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);

This free() needs to go away, or use-after-free and a double-free() will occur in rte_telemetry_init().

Quoted 65 lines
lib/librte_telemetry/rte_telemetry.c +24 -0
+		return -EPERM;
+	}
+
+	return -1;
+}
+
  int32_t
  rte_telemetry_init()
  {
@@ -77,6 +285,14 @@ rte_telemetry_init()
  		return -EPERM;
  	}
 
+	ret = rte_telemetry_create_socket(static_telemetry);
+	if (ret < 0) {
+		ret = rte_telemetry_cleanup();
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+		return -EPERM;
+	}
+
  	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
  		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
  		(void *)static_telemetry);
@@ -95,11 +311,21 @@ rte_telemetry_init()
  int32_t
  rte_telemetry_cleanup(void)
  {
+	int ret;
  	struct telemetry_impl *telemetry = static_telemetry;
+
+	ret = close(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
  	telemetry->thread_status = 0;
  	pthread_join(telemetry->thread_id, NULL);
  	free(telemetry);
  	static_telemetry = NULL;
+
  	return 0;
  }
 
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 4e810a8..569d56a 100644
@@ -24,9 +24,13 @@ extern int telemetry_log_level;
  	TELEMETRY_LOG(INFO, fmt, ## args)
 
  typedef struct telemetry_impl {
+	int accept_fd;
+	int server_fd;
  	pthread_t thread_id;
  	int thread_status;
  	uint32_t socket_id;
+	int reg_index;
+	int metrics_register_done;
  } telemetry_impl;
 
  #endif
#136 lore raw

PATCH v6 5/13 telemetry: add client feature and sockets

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch introduces clients to the telemetry API.

When a client makes a connection through the initial telemetry socket, they can send a message through the socket to be parsed. Register messages are expected through this socket, to enable clients to register and have a client socket setup for future communications.

A TAILQ is used to store all clients information. Using this, the client sockets are polled for messages, which will later be parsed and dealt with accordingly.

Functionality that make use of the client sockets were introduced in this patch also, such as writing to client sockets, and sending error responses.

---
 lib/librte_telemetry/meson.build              |   2 +
 lib/librte_telemetry/rte_telemetry.c          | 369 +++++++++++++++++++++++++-
 lib/librte_telemetry/rte_telemetry_internal.h |  25 ++
 mk/rte.app.mk                                 |   2 +-
 4 files changed, 394 insertions(+), 4 deletions(-)
lib/librte_telemetry/meson.build +2 -0
index 7716076..0ccfa36 100644
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson
lib/librte_telemetry/rte_telemetry.c +366 -3

441 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_internal.h +25 -0
index 569d56a..e3292cf 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_log.h>
+#include <rte_tailq.h>
 
 #ifndef _RTE_TELEMETRY_INTERNAL_H_
 #define _RTE_TELEMETRY_INTERNAL_H_
@@ -23,6 +24,12 @@ extern int telemetry_log_level;
 #define TELEMETRY_LOG_INFO(fmt, args...) \
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
+typedef struct telemetry_client {
+	char *file_path;
+	int fd;
+	TAILQ_ENTRY(telemetry_client) client_list;
+} telemetry_client;
+
 typedef struct telemetry_impl {
 	int accept_fd;
 	int server_fd;
@@ -31,6 +38,24 @@ typedef struct telemetry_impl {
 	uint32_t socket_id;
 	int reg_index;
 	int metrics_register_done;
+	TAILQ_HEAD(, telemetry_client) client_list_head;
+	struct telemetry_client *request_client;
+	int register_fail_count;
 } telemetry_impl;
 
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type);
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
 #endif
mk/rte.app.mk +1 -1
index 35594b9..b740691 100644
@@ -80,7 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
-_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry -ljansson
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#137 lore raw

Re: [PATCH v6 05/13] telemetry: add client feature and sockets

Quoted 162 lines · Kevin Laatz

From: Ciara Power <[email protected]>

This patch introduces clients to the telemetry API.

When a client makes a connection through the initial telemetry socket, they can send a message through the socket to be parsed. Register messages are expected through this socket, to enable clients to register and have a client socket setup for future communications.

A TAILQ is used to store all clients information. Using this, the client sockets are polled for messages, which will later be parsed and dealt with accordingly.

Functionality that make use of the client sockets were introduced in this patch also, such as writing to client sockets, and sending error responses.

---
  lib/librte_telemetry/meson.build              |   2 +
  lib/librte_telemetry/rte_telemetry.c          | 369 +++++++++++++++++++++++++-
  lib/librte_telemetry/rte_telemetry_internal.h |  25 ++
  mk/rte.app.mk                                 |   2 +-
  4 files changed, 394 insertions(+), 4 deletions(-)
lib/librte_telemetry/meson.build +2 -0
index 7716076..0ccfa36 100644
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
  headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
  deps += ['metrics', 'ethdev']
  cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson
lib/librte_telemetry/rte_telemetry.c +88 -2
index 10311be..a3ab3e9 100644
@@ -7,6 +7,7 @@
  #include <pthread.h>
  #include <sys/socket.h>
  #include <sys/un.h>
+#include <jansson.h>
 
  #include <rte_eal.h>
  #include <rte_ethdev.h>
@@ -18,6 +19,7 @@
  #include "rte_telemetry_internal.h"
 
  #define BUF_SIZE 1024
+#define ACTION_POST 1
  #define SLEEP_TIME 10
 
  static telemetry_impl *static_telemetry;
@@ -39,6 +41,91 @@ rte_telemetry_is_port_active(int port_id)
 
  	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
  		port_id);
+
+	return 0;
+}
+
+int32_t
+rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,
+	const char *json_string)
+{
+	int ret;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Could not initialise TELEMETRY_API");
+		return -1;
+	}
+
+	if (telemetry->request_client == NULL) {
+		TELEMETRY_LOG_ERR("No client has been chosen to write to");
+		return -1;
+	}
+
+	if (json_string == NULL) {
+		TELEMETRY_LOG_ERR("Invalid JSON string!");
+		return -1;
+	}
+
+	ret = send(telemetry->request_client->fd,
+			json_string, strlen(json_string), 0);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Failed to write to socket for client: %s",
+				telemetry->request_client->file_path);
+		return -1;
+	}
+
+	return 0;
+}
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type)
+{
+	int ret;
+	const char *status_code, *json_buffer;
+	json_t *root;
+
+	if (error_type == -EPERM)
+		status_code = "Status Error: Unknown";
+	else if (error_type == -EINVAL)
+		status_code = "Status Error: Invalid Argument 404";
+	else if (error_type == -ENOMEM)
+		status_code = "Status Error: Memory Allocation Error";
+	else {
+		TELEMETRY_LOG_ERR("Invalid error type");
+		return -EINVAL;
+	}
+
+	root = json_object();
+
+	if (root == NULL) {
+		TELEMETRY_LOG_ERR("Could not create root JSON object");
+		return -EPERM;
+	}
+
+	ret = json_object_set_new(root, "status_code", json_string(status_code));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Status code field cannot be set");
+		json_decref(root);
+		return -EPERM;
+	}
+
+	ret = json_object_set_new(root, "data", json_null());
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Data field cannot be set");
+		json_decref(root);
+		return -EPERM;
+	}
+
+	json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_decref(root);
+
+	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not write to socket");
+		return -EPERM;
+	}
+
  	return 0;
  }
 
@@ -115,8 +202,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
  	uint16_t pid;
 
  	RTE_ETH_FOREACH_DEV(pid) {
-		telemetry->reg_index =
-			rte_telemetry_reg_ethdev_to_metrics(pid);
+		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
  		break;
  	}
 

lib/librte_telemetry/rte_telemetry.c rte_telemetry_initial_accept(struct telemetry_impl *telemetry) · line 223

Quoted 7 lines
lib/librte_telemetry/rte_telemetry.c +4 -0
@@ -131,6 +217,38 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
  }
 
  static int32_t
+rte_telemetry_read_client(struct telemetry_impl *telemetry)
+{
+	char buf[BUF_SIZE];
+	int ret, buffer_read = 0;

No need to set it to zero.

lib/librte_telemetry/rte_telemetry.c rte_telemetry_initial_accept(struct telemetry_impl *telemetry) · line 232

Quoted 9 lines
lib/librte_telemetry/rte_telemetry.c +9 -0
+
+	buffer_read = read(telemetry->accept_fd, buf, BUF_SIZE-1);
+
+	if (buffer_read == -1) {
+		TELEMETRY_LOG_ERR("Read error");
+		return -1;
+	} else if (buffer_read == 0) {
+		goto close_socket;
+	} else {

I would have moved the 'ret' variable to this scope.

Quoted 47 lines
lib/librte_telemetry/rte_telemetry.c +31 -1
+		buf[buffer_read] = '\0';
+		ret = rte_telemetry_parse_client_message(telemetry, buf);
+		if (ret < 0)
+			TELEMETRY_LOG_WARN("Parse message failed");
+		goto close_socket;
+	}
+
+close_socket:
+	if (close(telemetry->accept_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+	telemetry->accept_fd = 0;
+
+	return 0;
+}
+
+static int32_t
  rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
  {
  	int ret;
@@ -141,8 +259,8 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
  			TELEMETRY_LOG_ERR("Listening error with server fd");
  			return -1;
  		}
-		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
 
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
  		if (telemetry->accept_fd >= 0 &&
  			telemetry->metrics_register_done == 0) {
  			ret = rte_telemetry_initial_accept(telemetry);
@@ -151,6 +269,30 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
  				return -1;
  			}
  		}
+	} else {
+		ret = rte_telemetry_read_client(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to read socket buffer");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+

lib/librte_telemetry/rte_telemetry.c rte_telemetry_accept_new_client(struct telemetry_impl *telemetry) · line 292

Quoted 10 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+static int32_t
+rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
+{
+	telemetry_client *client;
+	char client_buf[BUF_SIZE];
+	int bytes;
+
+	TAILQ_FOREACH(client, &telemetry->client_list_head, client_list) {
+		bytes = read(client->fd, client_buf, BUF_SIZE-1);
+		client_buf[bytes] = '\0';

read() might return -1, and you'll be writing out-of-bounds.

Quoted 240 lines
lib/librte_telemetry/rte_telemetry.c +207 -0
+
+		if (bytes > 0)
+			telemetry->request_client = client;
  	}
 
  	return 0;
@@ -173,6 +315,12 @@ rte_telemetry_run(void *userdata)
  		return -1;
  	}
 
+	ret = rte_telemetry_read_client_sockets(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Client socket read failed");
+		return -1;
+	}
+
  	return 0;
  }
 
@@ -292,6 +440,7 @@ rte_telemetry_init()
  			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
  		return -EPERM;
  	}
+	TAILQ_INIT(&static_telemetry->client_list_head);
 
  	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
  		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
@@ -308,11 +457,39 @@ rte_telemetry_init()
  	return 0;
  }
 
+static int32_t
+rte_telemetry_client_cleanup(struct telemetry_client *client)
+{
+	int ret;
+
+	ret = close(client->fd);
+	free(client->file_path);
+	free(client);
+
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close client socket failed");
+		return -EPERM;
+	}
+
+	return 0;
+}
+
  int32_t
  rte_telemetry_cleanup(void)
  {
  	int ret;
  	struct telemetry_impl *telemetry = static_telemetry;
+	telemetry_client *client, *temp_client;
+
+	TAILQ_FOREACH_SAFE(client, &telemetry->client_list_head, client_list,
+		temp_client) {
+		TAILQ_REMOVE(&telemetry->client_list_head, client, client_list);
+		ret = rte_telemetry_client_cleanup(client);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Client cleanup failed");
+			return -EPERM;
+		}
+	}
 
  	ret = close(telemetry->server_fd);
  	if (ret < 0) {
@@ -329,6 +506,192 @@ rte_telemetry_cleanup(void)
  	return 0;
  }
 
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path)
+{
+	int ret;
+	telemetry_client *client, *temp_client;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_WARN("TELEMETRY is not initialised");
+		return -ENODEV;
+	}
+
+	if (client_path == NULL) {
+		TELEMETRY_LOG_ERR("Invalid client path");
+		goto einval_fail;
+	}
+
+	if (TAILQ_EMPTY(&telemetry->client_list_head)) {
+		TELEMETRY_LOG_ERR("There are no clients currently registered");
+		return -EPERM;
+	}
+
+	TAILQ_FOREACH_SAFE(client, &telemetry->client_list_head, client_list,
+			temp_client) {
+		if (strcmp(client_path, client->file_path) == 0) {
+			TAILQ_REMOVE(&telemetry->client_list_head, client,
+				client_list);
+			ret = rte_telemetry_client_cleanup(client);
+
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Client cleanup failed");
+				return -EPERM;
+			}
+
+			return 0;
+		}
+	}
+
+	TELEMETRY_LOG_WARN("Couldn't find client, possibly not registered yet.");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -EINVAL;
+}
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path)
+{
+	int ret, fd;
+	struct sockaddr_un addrs;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Could not initialize TELEMETRY API");
+		return -ENODEV;
+	}
+
+	if (client_path == NULL) {
+		TELEMETRY_LOG_ERR("Invalid client path");
+		return -EINVAL;
+	}
+
+	telemetry_client *client;
+	TAILQ_FOREACH(client, &telemetry->client_list_head, client_list) {
+		if (strcmp(client_path, client->file_path) == 0) {
+			TELEMETRY_LOG_WARN("'%s' already registered",
+					client_path);
+			return -EINVAL;
+		}
+	}
+
+	fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (fd == -1) {
+		TELEMETRY_LOG_ERR("Client socket error");
+		return -EACCES;
+	}
+
+	ret = rte_telemetry_set_socket_nonblock(fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		return -EPERM;
+	}
+
+	addrs.sun_family = AF_UNIX;
+	strlcpy(addrs.sun_path, client_path, sizeof(addrs.sun_path));
+	telemetry_client *new_client = malloc(sizeof(telemetry_client));
+	new_client->file_path = strdup(client_path);
+	new_client->fd = fd;
+
+	if (connect(fd, (struct sockaddr *)&addrs, sizeof(addrs)) == -1) {
+		TELEMETRY_LOG_ERR("TELEMETRY client connect to %s didn't work",
+				client_path);
+		ret = rte_telemetry_client_cleanup(new_client);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Client cleanup failed");
+			return -EPERM;
+		}
+		return -EINVAL;
+	}
+
+	TAILQ_INSERT_HEAD(&telemetry->client_list_head, new_client, client_list);
+
+	return 0;
+}
+
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf)
+{
+	int ret, action_int;
+	json_error_t error;
+	json_t *root = json_loads(buf, 0, &error);
+
+	if (root == NULL) {
+		TELEMETRY_LOG_WARN("Could not load JSON object from data passed in : %s",
+				error.text);
+		goto fail;
+	} else if (!json_is_object(root)) {
+		TELEMETRY_LOG_WARN("JSON Request is not a JSON object");
+		json_decref(root);
+		goto fail;
+	}
+
+	json_t *action = json_object_get(root, "action");
+	if (action == NULL) {
+		TELEMETRY_LOG_WARN("Request does not have action field");
+		goto fail;
+	} else if (!json_is_integer(action)) {
+		TELEMETRY_LOG_WARN("Action value is not an integer");
+		goto fail;
+	}
+
+	json_t *command = json_object_get(root, "command");
+	if (command == NULL) {
+		TELEMETRY_LOG_WARN("Request does not have command field");
+		goto fail;
+	} else if (!json_is_string(command)) {
+		TELEMETRY_LOG_WARN("Command value is not a string");
+		goto fail;
+	}
+
+	action_int = json_integer_value(action);
+	if (action_int != ACTION_POST) {
+		TELEMETRY_LOG_WARN("Invalid action code");
+		goto fail;
+	}
+
+	if (strcmp(json_string_value(command), "clients") != 0) {
+		TELEMETRY_LOG_WARN("Invalid command");
+		goto fail;
+	}
+
+	json_t *data = json_object_get(root, "data");
+	if (data == NULL) {
+		TELEMETRY_LOG_WARN("Request does not have data field");
+		goto fail;
+	}
+
+	json_t *client_path = json_object_get(data, "client_path");
+	if (client_path == NULL) {
+		TELEMETRY_LOG_WARN("Request does not have client_path field");
+		goto fail;
+	}
+
+	if (!json_is_string(client_path)) {
+		TELEMETRY_LOG_WARN("Client_path value is not a string");
+		goto fail;

lib/librte_telemetry/rte_telemetry.c rte_telemetry_cleanup(void) · line 687

Quoted 10 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+	}
+
+	ret = rte_telemetry_register_client(telemetry,
+			json_string_value(client_path));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not register client");
+		telemetry->register_fail_count++;
+		goto fail;
+	}
+

You're leaking the root object here, but maybe that's fixed in subsequent patches.

Quoted 74 lines
lib/librte_telemetry/rte_telemetry.c +7 -0
+	return 0;
+
+fail:
+	TELEMETRY_LOG_WARN("Client attempted to register with invalid message");
+	return -1;
+}
+
  int telemetry_log_level;
  RTE_INIT(rte_telemetry_register);
 
lib/librte_telemetry/rte_telemetry_internal.h +25 -0
index 569d56a..e3292cf 100644
@@ -3,6 +3,7 @@
   */
 
  #include <rte_log.h>
+#include <rte_tailq.h>
 
  #ifndef _RTE_TELEMETRY_INTERNAL_H_
  #define _RTE_TELEMETRY_INTERNAL_H_
@@ -23,6 +24,12 @@ extern int telemetry_log_level;
  #define TELEMETRY_LOG_INFO(fmt, args...) \
  	TELEMETRY_LOG(INFO, fmt, ## args)
 
+typedef struct telemetry_client {
+	char *file_path;
+	int fd;
+	TAILQ_ENTRY(telemetry_client) client_list;
+} telemetry_client;
+
  typedef struct telemetry_impl {
  	int accept_fd;
  	int server_fd;
@@ -31,6 +38,24 @@ typedef struct telemetry_impl {
  	uint32_t socket_id;
  	int reg_index;
  	int metrics_register_done;
+	TAILQ_HEAD(, telemetry_client) client_list_head;
+	struct telemetry_client *request_client;
+	int register_fail_count;
  } telemetry_impl;
 
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type);
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
  #endif
mk/rte.app.mk +1 -1
index 35594b9..b740691 100644
@@ -80,7 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
  _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
  _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
  _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
-_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_metrics -lrte_telemetry -ljansson
  _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
  _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
  _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
#138 lore raw

Re: [PATCH v6 05/13] telemetry: add client feature and sockets

Thanks for the review Mattias.

Will address the comments both here and in the 4/13 review.

Best regards,

Kevin

Quoted 123 lines · Mattias Rönnblom

lib/librte_telemetry/rte_telemetry.c rte_telemetry_initial_accept(struct telemetry_impl *telemetry) · line 223

Quoted 8 lines · Kevin Laatz

  @@ -131,6 +217,38 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry) }
    static int32_t

lib/librte_telemetry/rte_telemetry.c +4 -0
+rte_telemetry_read_client(struct telemetry_impl *telemetry)
+{
+    char buf[BUF_SIZE];
+    int ret, buffer_read = 0;

No need to set it to zero.

lib/librte_telemetry/rte_telemetry.c rte_telemetry_initial_accept(struct telemetry_impl *telemetry) · line 232

Quoted 9 lines
lib/librte_telemetry/rte_telemetry.c +9 -0
+
+    buffer_read = read(telemetry->accept_fd, buf, BUF_SIZE-1);
+
+    if (buffer_read == -1) {
+        TELEMETRY_LOG_ERR("Read error");
+        return -1;
+    } else if (buffer_read == 0) {
+        goto close_socket;
+    } else {

I would have moved the 'ret' variable to this scope.

lib/librte_telemetry/rte_telemetry.c rte_telemetry_accept_new_client(struct telemetry_impl *telemetry) · line 292

Quoted 11 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+static int32_t
+rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
+{
+    telemetry_client *client;
+    char client_buf[BUF_SIZE];
+    int bytes;
+
+    TAILQ_FOREACH(client, &telemetry->client_list_head, client_list) {
+        bytes = read(client->fd, client_buf, BUF_SIZE-1);
+        client_buf[bytes] = '\0';

read() might return -1, and you'll be writing out-of-bounds.

Quoted 64 lines
(quoted diff) +2 -0
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, 

char *buf)

lib/librte_telemetry/rte_telemetry.c +7 -0
+{
+    int ret, action_int;
+    json_error_t error;
+    json_t *root = json_loads(buf, 0, &error);
+
+    if (root == NULL) {
+        TELEMETRY_LOG_WARN("Could not load JSON object from data 

passed in : %s",
+                error.text);
+        goto fail;
+    } else if (!json_is_object(root)) {
+        TELEMETRY_LOG_WARN("JSON Request is not a JSON object"); +        json_decref(root);
+        goto fail;
+    }

lib/librte_telemetry/rte_telemetry.c +45 -0
+
+    json_t *action = json_object_get(root, "action");
+    if (action == NULL) {
+        TELEMETRY_LOG_WARN("Request does not have action field");
+        goto fail;
+    } else if (!json_is_integer(action)) {
+        TELEMETRY_LOG_WARN("Action value is not an integer");
+        goto fail;
+    }
+
+    json_t *command = json_object_get(root, "command");
+    if (command == NULL) {
+        TELEMETRY_LOG_WARN("Request does not have command field");
+        goto fail;
+    } else if (!json_is_string(command)) {
+        TELEMETRY_LOG_WARN("Command value is not a string");
+        goto fail;
+    }
+
+    action_int = json_integer_value(action);
+    if (action_int != ACTION_POST) {
+        TELEMETRY_LOG_WARN("Invalid action code");
+        goto fail;
+    }
+
+    if (strcmp(json_string_value(command), "clients") != 0) {
+        TELEMETRY_LOG_WARN("Invalid command");
+        goto fail;
+    }
+
+    json_t *data = json_object_get(root, "data");
+    if (data == NULL) {
+        TELEMETRY_LOG_WARN("Request does not have data field");
+        goto fail;
+    }
+
+    json_t *client_path = json_object_get(data, "client_path");
+    if (client_path == NULL) {
+        TELEMETRY_LOG_WARN("Request does not have client_path field");
+        goto fail;
+    }
+
+    if (!json_is_string(client_path)) {
+        TELEMETRY_LOG_WARN("Client_path value is not a string");
+        goto fail;

lib/librte_telemetry/rte_telemetry.c rte_telemetry_cleanup(void) · line 687

Quoted 10 lines
lib/librte_telemetry/rte_telemetry.c +10 -0
+    }
+
+    ret = rte_telemetry_register_client(telemetry,
+            json_string_value(client_path));
+    if (ret < 0) {
+        TELEMETRY_LOG_ERR("Could not register client");
+        telemetry->register_fail_count++;
+        goto fail;
+    }
+

You're leaking the root object here, but maybe that's fixed in subsequent patches.

Quoted 8 lines

+    return 0;

lib/librte_telemetry/rte_telemetry.c +3 -0
+
+fail:
+    TELEMETRY_LOG_WARN("Client attempted to register with invalid 

message");
+    return -1;

(quoted diff) +2 -0
+}
+
#139 lore raw

PATCH v6 6/13 telemetry: add parser for client socket messages

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the parser file. This is used to parse any messages that are received on any of the client sockets.

Currently, the unregister functionality works using the parser. Functionality relating to getting statistic values for certain ports will be added in a subsequent patch, however the parsing involved for that command is added in this patch.

Some of the parser code included is in preparation for future functionality, that is not implemented yet in this patchset.

---
 lib/librte_telemetry/Makefile                 |   1 +
 lib/librte_telemetry/meson.build              |   4 +-
 lib/librte_telemetry/rte_telemetry.c          |  11 +-
 lib/librte_telemetry/rte_telemetry_internal.h |  13 +
 lib/librte_telemetry/rte_telemetry_parser.c   | 569 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser.h   |  13 +
 6 files changed, 608 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
lib/librte_telemetry/Makefile +1 -0
index 0d61361..95c7296 100644
@@ -21,6 +21,7 @@ LIBABIVER := 1
 
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 0ccfa36..7450f96 100644
@@ -1,8 +1,8 @@
 # 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')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +10 -1
index a3ab3e9..76d92e9 100644
@@ -17,6 +17,7 @@
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
+#include "rte_telemetry_parser.h"
 
 #define BUF_SIZE 1024
 #define ACTION_POST 1
@@ -283,6 +284,7 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
 static int32_t
 rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 {
+	int ret;
 	telemetry_client *client;
 	char client_buf[BUF_SIZE];
 	int bytes;
@@ -291,8 +293,15 @@ rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 		bytes = read(client->fd, client_buf, BUF_SIZE-1);
 		client_buf[bytes] = '\0';
 
-		if (bytes > 0)
+		if (bytes > 0) {
 			telemetry->request_client = client;
+			ret = rte_telemetry_parse(telemetry, client_buf);
+			if (ret < 0) {
+				TELEMETRY_LOG_WARN("Parse socket input failed: %i",
+						ret);
+				return -1;
+			}
+		}
 	}
 
 	return 0;
lib/librte_telemetry/rte_telemetry_internal.h +13 -0
index e3292cf..86a5ba1 100644
@@ -43,6 +43,11 @@ typedef struct telemetry_impl {
 	int register_fail_count;
 } telemetry_impl;
 
+enum rte_telemetry_parser_actions {
+	ACTION_GET = 0,
+	ACTION_DELETE = 2
+};
+
 int32_t
 rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
 
@@ -58,4 +63,12 @@ int32_t
 rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 	const char *client_path);
 
+/**
+ * This is a wrapper for the ethdev api rte_eth_find_next().
+ * If rte_eth_find_next() returns the same port id that we passed it,
+ * then we know that that port is active.
+ */
+int32_t
+rte_telemetry_is_port_active(int port_id);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c new file +569 -0

569 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser.h new file +13 -0
new file mode 100644
index 0000000..63e633d
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_PARSER_H_
+#define _RTE_TELEMETRY_PARSER_H_
+
+int32_t
+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);
+
+#endif
Signature · 1 line
2.9.5
#140 lore raw

PATCH v6 7/13 telemetry: update metrics before sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to update the statistics in the metrics library with values from the ethdev stats.

Values need to be updated before they are encoded into a JSON message and sent to the client that requested them. The JSON encoding will be added in a subsequent patch.

---
 lib/librte_telemetry/rte_telemetry.c          | 134 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 lib/librte_telemetry/rte_telemetry_parser.c   |  17 ++++
 3 files changed, 155 insertions(+)
lib/librte_telemetry/rte_telemetry.c +134 -0
index 76d92e9..cd97a6e 100644
@@ -46,6 +46,78 @@ rte_telemetry_is_port_active(int port_id)
 	return 0;
 }
 
+static int32_t
+rte_telemetry_update_metrics_ethdev(struct telemetry_impl *telemetry,
+	uint16_t port_id, int reg_start_index)
+{
+	int ret, num_xstats, i;
+	struct rte_eth_xstat *eth_xstats;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_telemetry_is_port_active(port_id);
+	if (ret < 1) {
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", port_id,
+				num_xstats);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		free(eth_xstats);
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	uint64_t xstats_values[num_xstats];
+	for (i = 0; i < num_xstats; i++)
+		xstats_values[i] = eth_xstats[i].value;
+
+	ret = rte_metrics_update_values(port_id, reg_start_index, xstats_values,
+			num_xstats);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not update metrics values");
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		free(eth_xstats);
+		return -1;
+	}
+
+	free(eth_xstats);
+	return 0;
+}
+
 int32_t
 rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,
 	const char *json_string)
@@ -130,6 +202,68 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
+{
+	int ret, i;
+	char *json_buffer = NULL;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Invalid telemetry argument");
+		return -1;
+	}
+
+	if (metric_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid metric_ids array");
+		goto einval_fail;
+	}
+
+	if (num_metric_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_metric_ids, must be positive");
+		goto einval_fail;
+	}
+
+	if (port_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid port_ids array");
+		goto einval_fail;
+	}
+
+	if (num_port_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_port_ids, must be positive");
+		goto einval_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+
+		ret = rte_telemetry_update_metrics_ethdev(telemetry,
+			port_ids[i], telemetry->reg_index);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
+			return -1;
+		}
+	}
+
+	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not write to socket");
+		return -1;
+	}
+
+	return 0;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+
 static int32_t
 rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
 {
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 86a5ba1..0082cb2 100644
@@ -71,4 +71,8 @@ rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 int32_t
 rte_telemetry_is_port_active(int port_id);
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c +17 -0
index 6bc4c6d..084c160 100644
@@ -258,6 +258,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	int ret, num_metrics, i, p;
 	struct rte_metric_name *names;
 	uint64_t num_port_ids = 0;
+	uint32_t port_ids[RTE_MAX_ETHPORTS];
 
 	if (telemetry == NULL) {
 		TELEMETRY_LOG_ERR("Invalid telemetry argument");
@@ -313,6 +314,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	uint32_t stat_ids[num_metrics];
 
 	RTE_ETH_FOREACH_DEV(p) {
+		port_ids[num_port_ids] = p;
 		num_port_ids++;
 	}
 
@@ -337,6 +339,13 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 		goto fail;
 	}
 
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_metrics,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		goto fail;
+	}
+
 	return 0;
 
 fail:
@@ -428,6 +437,14 @@ rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl
 		TELEMETRY_LOG_ERR("Could not convert stat names to IDs");
 		return -1;
 	}
+
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_stat_names,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		return -1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.9.5
#141 lore raw

PATCH v6 8/13 telemetry: format json response when sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to create a JSON message in order to send it to a client socket.

When stats are requested by a client, they are retrieved from the metrics library and encoded in JSON format.

---
 lib/librte_telemetry/rte_telemetry.c | 309 ++++++++++++++++++++++++++++++++++-
 1 file changed, 307 insertions(+), 2 deletions(-)
lib/librte_telemetry/rte_telemetry.c +307 -2
index cd97a6e..f5c1bad 100644
@@ -190,7 +190,7 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 		return -EPERM;
 	}
 
-	json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_buffer = json_dumps(root, 0);
 	json_decref(root);
 
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
@@ -202,6 +202,304 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+static int
+rte_telemetry_get_metrics(struct telemetry_impl *telemetry, uint32_t port_id,
+	struct rte_metric_value *metrics, struct rte_metric_name *names,
+	int num_metrics)
+{
+	int ret, num_values;
+
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Invalid metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	if (metrics == NULL) {
+		TELEMETRY_LOG_ERR("Metrics must be initialised.");
+		goto einval_fail;
+	}
+
+	if (names == NULL) {
+		TELEMETRY_LOG_ERR("Names must be initialised.");
+		goto einval_fail;
+	}
+
+	ret = rte_metrics_get_names(names, num_metrics);
+	if (ret < 0 || ret > num_metrics) {
+		TELEMETRY_LOG_ERR("Cannot get metrics names");
+		goto eperm_fail;
+	}
+
+	num_values = rte_metrics_get_values(port_id, NULL, 0);
+	ret = rte_metrics_get_values(port_id, metrics, num_values);
+	if (ret < 0 || ret > num_values) {
+		TELEMETRY_LOG_ERR("Cannot get metrics values");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_stat(struct telemetry_impl *telemetry, json_t *stats,
+	const char *metric_name, uint64_t metric_value)
+{
+	int ret;
+	json_t *stat = json_object();
+
+	if (stat == NULL) {
+		TELEMETRY_LOG_ERR("Could not create stat JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "name", json_string(metric_name));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Name field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "value", json_integer(metric_value));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Value field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(stats, stat);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat cannot be added to stats json array");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_port(struct telemetry_impl *telemetry,
+	uint32_t port_id, json_t *ports, uint32_t *metric_ids,
+	uint32_t num_metric_ids)
+{
+	struct rte_metric_value *metrics = 0;
+	struct rte_metric_name *names = 0;
+	int num_metrics, ret, err_ret;
+	json_t *port, *stats;
+	uint32_t i;
+
+	num_metrics = rte_metrics_get_names(NULL, 0);
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Cannot get metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	metrics = malloc(sizeof(struct rte_metric_value) * num_metrics);
+	names = malloc(sizeof(struct rte_metric_name) * num_metrics);
+	if (metrics == NULL || names == NULL) {
+		TELEMETRY_LOG_ERR("Cannot allocate memory");
+		free(metrics);
+		free(names);
+
+		err_ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (err_ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret  = rte_telemetry_get_metrics(telemetry, port_id, metrics, names,
+		num_metrics);
+	if (ret < 0) {
+		free(metrics);
+		free(names);
+		TELEMETRY_LOG_ERR("rte_telemetry_get_metrics failed");
+		return -1;
+	}
+
+	port = json_object();
+	stats = json_array();
+	if (port == NULL || stats == NULL) {
+		TELEMETRY_LOG_ERR("Could not create port/stats JSON objects");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(port, "port", json_integer(port_id));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port field cannot be set");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_metric_ids; i++) {
+		int metric_id = metric_ids[i];
+		int metric_index = -1;
+		int metric_name_key = -1;
+		int32_t j;
+		uint64_t metric_value;
+
+		if (metric_id >= num_metrics) {
+			TELEMETRY_LOG_ERR("Metric_id: %d is not valid",
+					metric_id);
+			goto einval_fail;
+		}
+
+		for (j = 0; j < num_metrics; j++) {
+			if (metrics[j].key == metric_id) {
+				metric_name_key = metrics[j].key;
+				metric_index = j;
+				break;
+			}
+		}
+
+		const char *metric_name = names[metric_name_key].name;
+		metric_value = metrics[metric_index].value;
+
+		if (metric_name_key < 0 || metric_index < 0) {
+			TELEMETRY_LOG_ERR("Could not get metric name/index");
+			goto eperm_fail;
+		}
+
+		ret = rte_telemetry_json_format_stat(telemetry, stats,
+			metric_name, metric_value);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format stat with id: %u failed",
+					metric_id);
+			free(metrics);
+			free(names);
+			return -1;
+		}
+	}
+
+	if (json_array_size(stats) == 0)
+		ret = json_object_set_new(port, "stats", json_null());
+	else
+		ret = json_object_set_new(port, "stats", stats);
+
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stats object cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(ports, port);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port object cannot be added to ports array");
+		goto eperm_fail;
+	}
+
+	free(metrics);
+	free(names);
+	return 0;
+
+eperm_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+static int32_t
+rte_telemetry_encode_json_format(struct telemetry_impl *telemetry,
+	uint32_t *port_ids, uint32_t num_port_ids, uint32_t *metric_ids,
+	uint32_t num_metric_ids, char **json_buffer)
+{
+	int ret;
+	json_t *root, *ports;
+	uint32_t i;
+
+	if (num_port_ids <= 0 || num_metric_ids <= 0) {
+		TELEMETRY_LOG_ERR("Please provide port and metric ids to query");
+		goto einval_fail;
+	}
+
+	ports = json_array();
+	if (ports == NULL) {
+		TELEMETRY_LOG_ERR("Could not create ports JSON array");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		ret = rte_telemetry_json_format_port(telemetry, port_ids[i],
+			ports, metric_ids, num_metric_ids);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format port in JSON failed");
+			return -1;
+		}
+	}
+
+	root = json_object();
+	if (root == NULL) {
+		TELEMETRY_LOG_ERR("Could not create root JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "status_code",
+		json_string("Status OK: 200"));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Status code field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "data", ports);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Data field cannot be set");
+		goto eperm_fail;
+	}
+
+	*json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_decref(root);
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
 int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
@@ -241,13 +539,20 @@ rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 		}
 
 		ret = rte_telemetry_update_metrics_ethdev(telemetry,
-			port_ids[i], telemetry->reg_index);
+				port_ids[i], telemetry->reg_index);
 		if (ret < 0) {
 			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
 			return -1;
 		}
 	}
 
+	ret = rte_telemetry_encode_json_format(telemetry, port_ids,
+		num_port_ids, metric_ids, num_metric_ids, &json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("JSON encode function failed");
+		return -1;
+	}
+
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
 	if (ret < 0) {
 		TELEMETRY_LOG_ERR("Could not write to socket");
Signature · 1 line
2.9.5
#142 lore raw

PATCH v6 9/13 telemetry: add tests for telemetry api

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

---
 lib/librte_telemetry/Makefile                     |   1 +
 lib/librte_telemetry/meson.build                  |   4 +-
 lib/librte_telemetry/rte_telemetry.c              | 653 ++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |  12 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   3 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  | 534 ++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |  39 ++
 lib/librte_telemetry/rte_telemetry_socket_tests.h |  36 ++
 lib/librte_telemetry/rte_telemetry_version.map    |   1 +
 9 files changed, 1281 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
lib/librte_telemetry/Makefile +1 -0
index 95c7296..1a05069 100644
@@ -22,6 +22,7 @@ LIBABIVER := 1
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 7450f96..57dd83d 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
-sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h', 'rte_telemetry_parser_test.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +653 -0

684 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h +12 -0
index d3b0d8d..958723b 100644
@@ -33,4 +33,16 @@ rte_telemetry_init(void);
 int32_t
 rte_telemetry_cleanup(void);
 
+/**
+ * Runs various tests to ensure telemetry initialisation and register/unregister
+ * functions are working correctly.
+ *
+ * @return
+ *  0 on success when all tests have passed
+ * @return
+ *  -1 on failure when the test has failed
+ */
+int32_t
+rte_telemetry_selftest(void);
+
 #endif
lib/librte_telemetry/rte_telemetry_internal.h +3 -0
index 0082cb2..de7afda 100644
@@ -75,4 +75,7 @@ int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
 
+int32_t
+rte_telemetry_socket_messaging_testing(int index, int socket);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser_test.c new file +534 -0

534 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser_test.h new file +39 -0
new file mode 100644
index 0000000..6ada852
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_TELEMETRY_PARSER_TEST_H_
+#define _RTE_TELEMETRY_PARSER_TEST_H_
+
+int32_t
+rte_telemetry_parser_test(struct telemetry_impl *telemetry);
+
+int32_t
+rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, json_t **data);
+
+int32_t
+rte_telemetry_create_json_request(int action, char *command,
+	const char *client_path, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, char **request,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
+	int action_choice, char *command_choice, int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
+	int action_choice, int *port_ids, int num_port_ids, int inv_choice);
+
+int32_t
+rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
+	*telemetry, int action_choice, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_unreg_request(int action_choice, const char *client_path,
+	int inv_choice);
+
+#endif
lib/librte_telemetry/rte_telemetry_socket_tests.h new file +36 -0
new file mode 100644
index 0000000..db9167c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdbool.h>
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
+#define _RTE_TELEMETRY_SOCKET_TESTING_H_
+
+int32_t
+rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
+	int fd);
+
+int32_t
+rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
+	int send_fd, int recv_fd);
+
+int32_t
+rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
+	int *recv_fd);
+
+#endif
lib/librte_telemetry/rte_telemetry_version.map +1 -0
index 992d227..98459fc 100644
@@ -2,5 +2,6 @@ DPDK_18.11 {
 	global:
 
 	rte_telemetry_init;
+	rte_telemetry_selftest;
 	local: *;
 };
Signature · 1 line
2.9.5
#143 lore raw

PATCH v6 10/13 telemetry: add ability to disable selftest

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

---
 lib/librte_telemetry/rte_telemetry.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/librte_telemetry/rte_telemetry.c +13 -10
index 717416e..c43b657 100644
@@ -660,6 +660,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
 	uint16_t pid;
 	int ret;
+	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
@@ -672,18 +673,20 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 	}
 
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (selftest) {
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+				telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Parser Tests Failed");
-		return -1;
-	}
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Parser Tests Failed");
+			return -1;
+		}
 
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+	}
 
 	return 0;
 }
Signature · 1 line
2.9.5
#144 lore raw

PATCH v6 11/13 doc: add telemetry documentation

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry for telemetry.

---
 MAINTAINERS                    |  5 +++
 doc/guides/howto/index.rst     |  1 +
 doc/guides/howto/telemetry.rst | 85 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)
 create mode 100644 doc/guides/howto/telemetry.rst
MAINTAINERS +5 -0
index 84b9ff7..e695a68 100644
@@ -1168,6 +1168,11 @@ F: test/bpf/
 F: test/test/test_bpf.c
 F: doc/guides/prog_guide/bpf_lib.rst
 
+Telemetry
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst
 
 Test Applications
 -----------------
doc/guides/howto/index.rst +1 -0
index e13a090..a642a2b 100644
@@ -17,3 +17,4 @@ HowTo Guides
     virtio_user_for_container_networking
     virtio_user_as_exceptional_path
     packet_capture_framework
+    telemetry
doc/guides/howto/telemetry.rst new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.9.5
Acked-by on v6 11/13
#145 lore raw

Re: [PATCH v6 11/13] doc: add telemetry documentation

Quoted 27 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Kevin Laatz
Sent: Monday, October 22, 2018 12:00 PM
To: [email protected]
Cc: Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Richardson, Bruce <[email protected]>; Ciara Power <[email protected]>; Brian Archbold <[email protected]>; Laatz, Kevin <[email protected]>
Subject: [dpdk-dev] [PATCH v6 11/13] doc: add telemetry documentation

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry for telemetry.

Quoted 5 lines
---
 MAINTAINERS                    |  5 +++
 doc/guides/howto/index.rst     |  1 +
 doc/guides/howto/telemetry.rst | 85

++++++++++++++++++++++++++++++++++++++++++

#146 lore raw

PATCH v6 12/13 usertools: add client python script for telemetry

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds a python script which can be used as a demo client. The script is interactive and will allow the user to register, request statistics, and unregister.

To run the script, an argument for the client file path must be passed in: "python telemetry_client.py <file_path>".

This script is useful to see how the Telemetry API for DPDK is used, and how to make the initial connection.

---
 usertools/dpdk-telemetry-client.py | 116 +++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 usertools/dpdk-telemetry-client.py
usertools/dpdk-telemetry-client.py new file +116 -0
new file mode 100644
index 0000000..6dcf62b
@@ -0,0 +1,116 @@
+# SPDK-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+import socket
+import os
+import sys
+import time
+
+BUFFER_SIZE = 200000
+
+METRICS_REQ = "{\"action\":0,\"command\":\"ports_all_stat_values\",\"data\":null}"
+API_REG = "{\"action\":1,\"command\":\"clients\",\"data\":{\"client_path\":\""
+API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
+DEFAULT_FP = "/var/run/dpdk/default_client"
+
+class Socket:
+
+    def __init__(self):
+        self.send_fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+        self.recv_fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+        self.client_fd = None
+
+    def __del__(self):
+        try:
+            self.send_fd.close()
+            self.recv_fd.close()
+            self.client_fd.close()
+        except:
+            print("Error - Sockets could not be closed")
+
+class Client:
+
+    def __init__(self): # Creates a client instance
+        self.socket = Socket()
+        self.file_path = None
+        self.choice = None
+        self.unregistered = 0
+
+    def __del__(self):
+        try:
+            if self.unregistered == 0:
+                self.unregister();
+        except:
+            print("Error - Client could not be destroyed")
+
+    def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client
+        self.file_path = file_path
+
+    def register(self): # Connects a client to DPDK-instance
+        if os.path.exists(self.file_path):
+            os.unlink(self.file_path)
+        try:
+            self.socket.recv_fd.bind(self.file_path)
+        except socket.error as msg:
+            print ("Error - Socket binding error: " + str(msg) + "\n")
+        self.socket.recv_fd.settimeout(2)
+        self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry")
+        JSON = (API_REG + self.file_path + "\"}}")
+        self.socket.send_fd.sendall(JSON)
+        self.socket.recv_fd.listen(1)
+        self.socket.client_fd = self.socket.recv_fd.accept()[0]
+
+    def unregister(self): # Unregister a given client
+        self.socket.client_fd.send(API_UNREG + self.file_path + "\"}}")
+        self.socket.client_fd.close()
+
+    def requestMetrics(self): # Requests metrics for given client
+        self.socket.client_fd.send(METRICS_REQ)
+        data = self.socket.client_fd.recv(BUFFER_SIZE)
+        print "\nResponse: \n", str(data)
+
+    def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
+        print("\nPlease enter the number of times you'd like to continuously request Metrics:")
+        n_requests = int(input("\n:"))
+        print("\033[F") #Removes the user input from screen, cleans it up
+        print("\033[K")
+        for i in range(n_requests):
+            self.requestMetrics()
+            time.sleep(sleep_time)
+
+    def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script
+        while self.choice != 3:
+            print("\nOptions Menu")
+            print("[1] Send for Metrics for all ports")
+            print("[2] Send for Metrics for all ports recursively")
+            print("[3] Unregister client")
+
+            try:
+                self.choice = int(input("\n:"))
+                print("\033[F") #Removes the user input for screen, cleans it up
+                print("\033[K")
+                if self.choice == 1:
+                    self.requestMetrics()
+                elif self.choice == 2:
+                    self.repeatedlyRequestMetrics(sleep_time)
+                elif self.choice == 3:
+                    self.unregister()
+                    self.unregistered = 1
+                else:
+                    print("Error - Invalid request choice")
+            except:
+                pass
+
+if __name__ == "__main__":
+
+    sleep_time = 1
+    file_path = ""
+    if (len(sys.argv) == 2):
+	file_path = sys.argv[1]
+    else:
+        print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")
+	file_path = DEFAULT_FP
+    client = Client()
+    client.getFilepath(file_path)
+    client.register()
+    client.interactiveMenu(sleep_time)
Signature · 1 line
2.9.5
#147 lore raw

PATCH v6 13/13 build: add dependency on telemetry to apps in meson

In reply to Kevin Laatz

This patch adds telemetry as a dependecy to all applications. Without these changes, the --telemetry flag will not be recognised and applications will fail to run if they want to enable telemetry.

---
 app/meson.build                  | 4 ++--
 app/pdump/meson.build            | 2 +-
 app/proc-info/meson.build        | 2 +-
 app/test-bbdev/meson.build       | 2 +-
 app/test-crypto-perf/meson.build | 2 +-
 app/test-pmd/meson.build         | 2 +-
 config/meson.build               | 3 +++
 lib/meson.build                  | 1 +
 meson.build                      | 1 +
 9 files changed, 12 insertions(+), 7 deletions(-)
app/meson.build +2 -2
index 99e0b93..8e716bf 100644
@@ -24,7 +24,7 @@ foreach app:apps
 	# use "deps" for internal DPDK dependencies, and "ext_deps" for
 	# external package/library requirements
 	ext_deps = []
-	deps = []
+	deps = ['telemetry']
 
 	subdir(name)
 
@@ -38,7 +38,7 @@ foreach app:apps
 
 		link_libs = []
 		if get_option('default_library') == 'static'
-			link_libs = dpdk_drivers
+			link_libs = dpdk_static_libraries + dpdk_drivers
 		endif
 
 		if allow_experimental_apis
app/pdump/meson.build +1 -1
index 988cb4e..116c27f 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'kvargs', 'pdump']
+deps += ['ethdev', 'kvargs', 'pdump']
app/proc-info/meson.build +1 -1
index 9c148e3..a52b2ee 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'metrics']
+deps += ['ethdev', 'metrics']
app/test-bbdev/meson.build +1 -1
index 653907d..eb8cc04 100644
@@ -6,4 +6,4 @@ sources = files('main.c',
 		'test_bbdev_perf.c',
 		'test_bbdev_vector.c')
 allow_experimental_apis = true
-deps = ['bbdev', 'bus_vdev']
+deps += ['bbdev', 'bus_vdev']
app/test-crypto-perf/meson.build +1 -1
index eacd7a0..d735b18 100644
@@ -12,4 +12,4 @@ sources = files('cperf_ops.c',
 		'cperf_test_vectors.c',
 		'cperf_test_verify.c',
 		'main.c')
-deps = ['cryptodev']
+deps += ['cryptodev']
app/test-pmd/meson.build +1 -1
index a0b3be0..c24f75f 100644
@@ -22,7 +22,7 @@ sources = files('cmdline.c',
 	'testpmd.c',
 	'txonly.c')
 
-deps = ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
+deps += ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
 if dpdk_conf.has('RTE_LIBRTE_PDUMP')
 	deps += 'pdump'
 endif
config/meson.build +3 -0
index 6f9228c..275f00b 100644
@@ -21,6 +21,9 @@ toolchain = cc.get_id()
 dpdk_conf.set_quoted('RTE_TOOLCHAIN', toolchain)
 dpdk_conf.set('RTE_TOOLCHAIN_' + toolchain.to_upper(), 1)
 
+add_project_link_arguments('-Wl,--no-as-needed', language: 'c')
+dpdk_extra_ldflags += '-Wl,--no-as-needed'
+
 # use pthreads
 add_project_link_arguments('-pthread', language: 'c')
 dpdk_extra_ldflags += '-pthread'
lib/meson.build +1 -0
index b5612ad..ef3f3a6 100644
@@ -127,6 +127,7 @@ foreach l:libraries
 					dependencies: shared_deps)
 
 			dpdk_libraries = [shared_lib] + dpdk_libraries
+			dpdk_static_libraries = [static_lib] + dpdk_static_libraries
 		endif # sources.length() > 0
 
 		set_variable('shared_' + libname, shared_dep)
meson.build +1 -0
index c9af335..f3bddb2 100644
@@ -12,6 +12,7 @@ project('DPDK', 'C',
 cc = meson.get_compiler('c')
 dpdk_conf = configuration_data()
 dpdk_libraries = []
+dpdk_static_libraries = []
 dpdk_drivers = []
 dpdk_extra_ldflags = []
 
Signature · 1 line
2.9.5
#148 lore raw

v7 cover introduce telemetry library

In reply to Kevin Laatz

This patchset introduces a Telemetry library for DPDK Service Assurance. This library provides an easy way to query DPDK Ethdev metrics.

The telemetry library provides a method for a service assurance component to retrieve metrics from a DPDK packet forwarding application. Communicating from the service assurance component to DPDK is done using a UNIX domain socket, passing a JSON formatted string. A reply is sent (again a JSON formatted string) of the current DPDK metrics.

The telemetry component makes use of the existing rte_metrics library to query values. The values to be transmitted via the telemetry infrastructure must be present in the Metrics library. Currently the ethdev values are pushed to the metrics library, and the queried from there there is an open question on how applications would like this to occur. Currently only ethdev to metrics functionality is implemented, however other subsystems like crypto, eventdev, keepalive etc can use similar mechanisms.

Exposing DPDK Telemetry via a socket interface enables service assurance agents like collectd to consume data from DPDK. This is vital for monitoring, fault-detection, and error reporting. A collectd plugin has been created to interact with the DPDK Telemetry component, showing how it can be used in practice. The collectd plugin will be upstreamed to collectd at a later stage. A small python script is provided in ./usertools/telemetry_client.py to quick-start using DPDK Telemetry.

Note: Despite opterr being set to 0, --telemetry said to be 'unrecognized' as a startup print. This is a cosmetic issue and will be addressed in the future.

---
v2:
- Reworked telemetry as part of EAL instead of using vdev (Gaetan)
- Refactored rte_telemetry_command (Gaetan)
- Added MAINTAINERS file entry (Stephen)
- Updated docs to reflect vdev to eal rework
- Removed collectd patch from patchset (Thomas)
- General code clean up from v1 feedback

v3:
- Reworked registering with eal and moved to rte_param (Gaetan)
- Added BSD implementation for rte_param (Gaetan)
- Updated the paths to align with the new runtime file location (Mattias)
- Fixed pointer checks to align with the coding style 1.8.1 (Mattias)
- Added missing decref's and close's (Mattias)
- Fixed runtime issue in Meson (was not recognising flag due to linking)
- More general clean up

v4:
- Added Doxygen comments for rte_param.h (Thomas)
- Made eal_get_runtime_dir a public function to use outside of EAL (Thomas)
- Reworked telemetry to get path using rte_eal_get_runtime_dir (Thomas)
- Fixed checkpatch coding style error

v5:
- Moved the BUF_SIZE define to fix build (Harry)
- Set default config for telemetry to 'n' (Harry)
- Improved Doxygen comments (Thomas)
- Cleaned up rte_param struct (Thomas)

v6:
- Renamed rte_param to rte_option (Thomas)
- Moved internal functions to eal_private.h (Gaetan)
- Added fail check for pthread_attr_init() (Mattias)
- Changed socket implementation to SOCK_SEQPACKET (Mattias)
- Added check to avoid option duplicates (Gaetan)
- Removed telemetry example from Doxygen comment (Gaetan)
- General Doxygen clean-up (Thomas)
- General code clean-up (Mattias)

v7:
- Fix object leak (Mattias)
- General clean-up (Mattias)
- Fix rte_option header define
- Added release note update
- Rebased

Ciara Power, Brian Archbold and Kevin Laatz (10):
telemetry: initial telemetry infrastructure
telemetry: add initial connection socket
telemetry: add client feature and sockets
telemetry: add parser for client socket messages
telemetry: update metrics before sending stats
telemetry: format json response when sending stats
telemetry: add tests for telemetry api
telemetry: add ability to disable selftest
doc: add telemetry documentation
usertools: add client python script for telemetry

Kevin Laatz (3):
eal: add option register infrastructure
eal: make get runtime dir function public
build: add dependency on telemetry to apps in meson

 MAINTAINERS                                       |    5 +
 app/meson.build                                   |    4 +-
 app/pdump/meson.build                             |    2 +-
 app/proc-info/meson.build                         |    2 +-
 app/test-bbdev/meson.build                        |    2 +-
 app/test-crypto-perf/meson.build                  |    2 +-
 app/test-pmd/meson.build                          |    2 +-
 config/common_base                                |    5 +
 config/meson.build                                |    3 +
 doc/guides/howto/index.rst                        |    1 +
 doc/guides/howto/telemetry.rst                    |   85 +
 doc/guides/rel_notes/release_18_11.rst            |    6 +
 lib/Makefile                                      |    2 +
 lib/librte_eal/bsdapp/eal/Makefile                |    1 +
 lib/librte_eal/bsdapp/eal/eal.c                   |   16 +-
 lib/librte_eal/common/Makefile                    |    1 +
 lib/librte_eal/common/eal_filesystem.h            |   15 +-
 lib/librte_eal/common/eal_private.h               |   21 +
 lib/librte_eal/common/include/rte_eal.h           |    9 +
 lib/librte_eal/common/include/rte_option.h        |   63 +
 lib/librte_eal/common/meson.build                 |    2 +
 lib/librte_eal/common/rte_option.c                |   54 +
 lib/librte_eal/linuxapp/eal/Makefile              |    1 +
 lib/librte_eal/linuxapp/eal/eal.c                 |   16 +-
 lib/librte_eal/rte_eal_version.map                |    2 +
 lib/librte_telemetry/Makefile                     |   30 +
 lib/librte_telemetry/meson.build                  |    9 +
 lib/librte_telemetry/rte_telemetry.c              | 1815 +++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |   48 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   81 +
 lib/librte_telemetry/rte_telemetry_parser.c       |  586 +++++++
 lib/librte_telemetry/rte_telemetry_parser.h       |   13 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  |  534 ++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |   39 +
 lib/librte_telemetry/rte_telemetry_socket_tests.h |   36 +
 lib/librte_telemetry/rte_telemetry_version.map    |    7 +
 lib/meson.build                                   |    3 +-
 meson.build                                       |    1 +
 mk/rte.app.mk                                     |    1 +
 usertools/dpdk-telemetry-client.py                |  116 ++
 40 files changed, 3622 insertions(+), 19 deletions(-)
 create mode 100644 doc/guides/howto/telemetry.rst
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
 create mode 100644 usertools/dpdk-telemetry-client.py
Signature · 1 line
2.9.5
#149 lore raw

PATCH v7 1/13 eal: add option register infrastructure

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

---
 lib/librte_eal/bsdapp/eal/Makefile         |  1 +
 lib/librte_eal/bsdapp/eal/eal.c            | 14 ++++++-
 lib/librte_eal/common/Makefile             |  1 +
 lib/librte_eal/common/eal_private.h        | 21 ++++++++++
 lib/librte_eal/common/include/rte_option.h | 63 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/meson.build          |  2 +
 lib/librte_eal/common/rte_option.c         | 54 +++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile       |  1 +
 lib/librte_eal/linuxapp/eal/eal.c          | 14 ++++++-
 lib/librte_eal/rte_eal_version.map         |  1 +
 10 files changed, 170 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d19f53c..bfeddaa 100644
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
 
lib/librte_eal/bsdapp/eal/eal.c +13 -1
index 7735194..178cfd6 100644
@@ -42,6 +42,7 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 
@@ -414,12 +415,20 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -791,6 +800,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/common/Makefile +1 -0
index cca6882..87d8c45 100644
@@ -12,6 +12,7 @@ INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h
+INC += rte_option.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
lib/librte_eal/common/eal_private.h +21 -0
index b189d67..442c6dc 100644
@@ -349,4 +349,25 @@ dev_sigbus_handler_register(void);
 int
 dev_sigbus_handler_unregister(void);
 
+/**
+ * Check if the option is registered.
+ *
+ * @param option
+ *  The option to be parsed.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_option_parse(const char *opt);
+
+/**
+ * Iterate through the registered options and execute the associated
+ * callback if enabled.
+ */
+void
+rte_option_init(void);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_option.h new file +63 -0

63 lines not on this page · raw message

lib/librte_eal/common/meson.build +2 -0
index 04c4143..2a10d57 100644
@@ -34,6 +34,7 @@ common_sources = files(
 	'malloc_mp.c',
 	'rte_keepalive.c',
 	'rte_malloc.c',
+	'rte_option.c',
 	'rte_reciprocal.c',
 	'rte_service.c'
 )
@@ -71,6 +72,7 @@ common_headers = files(
 	'include/rte_malloc_heap.h',
 	'include/rte_memory.h',
 	'include/rte_memzone.h',
+	'include/rte_option.h',
 	'include/rte_pci_dev_feature_defs.h',
 	'include/rte_pci_dev_features.h',
 	'include/rte_per_lcore.h',
lib/librte_eal/common/rte_option.c new file +54 -0

54 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 7280885..51deb57 100644
@@ -75,6 +75,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
 
lib/librte_eal/linuxapp/eal/eal.c +13 -1
index a00cebf..70ab032 100644
@@ -48,6 +48,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
@@ -600,12 +601,20 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -1080,6 +1089,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/rte_eal_version.map +1 -0
index 08e3bc2..12ace18 100644
@@ -351,6 +351,7 @@ EXPERIMENTAL {
 	rte_mp_request_sync;
 	rte_mp_request_async;
 	rte_mp_sendmsg;
+	rte_option_register;
 	rte_service_lcore_attr_get;
 	rte_service_lcore_attr_reset_all;
 	rte_service_may_be_active;
Signature · 1 line
2.9.5
Acked-by on v7 1/13
#150 lore raw

Re: [PATCH v7 01/13] eal: add option register infrastructure

Hi Kevin,

Quoted 9 lines · Kevin Laatz

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

I think this is good enough,

The only remaining issue is rte_option_init().
Sorry I missed your previous message and did not respond in time, I would have opted for leaving a return value to at least be able to stop the init on error. It is possible to force the callback type to return an error value along with a string / hint describing the error. It should not be hard to add it later, so not blocking IMO.

Signature · 2 lines
Gaëtan Rivet
6WIND
#151 lore raw

Re: [PATCH v7 01/13] eal: add option register infrastructure

24/10/2018 16:01, Gaëtan Rivet:

Quoted 10 lines

Hi Kevin,

Quoted 7 lines · Kevin Laatz

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

Quoted 6 lines
Quoted 2 lines

I think this is good enough,

Yes it looks good enough.
And it compiles fine in my test.

Quoted 6 lines

The only remaining issue is rte_option_init().
Sorry I missed your previous message and did not respond in time, I would have opted for leaving a return value to at least be able to stop the init on error. It is possible to force the callback type to return an error value along with a string / hint describing the error. It should not be hard to add it later, so not blocking IMO.

I think you need to set this API as experimental.

#152 lore raw

Re: [PATCH v7 01/13] eal: add option register infrastructure

Quoted 11 lines · Thomas Monjalon

24/10/2018 16:01, Gaëtan Rivet:

Quoted 10 lines

Hi Kevin,

Quoted 7 lines · Kevin Laatz

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

Quoted 14 lines
Quoted 5 lines
Quoted 2 lines

I think this is good enough,

Yes it looks good enough.
And it compiles fine in my test.

Quoted 6 lines

The only remaining issue is rte_option_init().
Sorry I missed your previous message and did not respond in time, I would have opted for leaving a return value to at least be able to stop the init on error. It is possible to force the callback type to return an error value along with a string / hint describing the error. It should not be hard to add it later, so not blocking IMO.

Agree this can be added in the future.

Quoted 1 line

I think you need to set this API as experimental.

Will do, thanks.

#153 lore raw

Re: [PATCH v7 01/13] eal: add option register infrastructure

Quoted 26 lines · Kevin
Quoted 11 lines · Thomas Monjalon

24/10/2018 16:01, Gaëtan Rivet:

Quoted 10 lines

Hi Kevin,

Quoted 7 lines · Kevin Laatz

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

Quoted 14 lines
Quoted 5 lines
Quoted 2 lines

I think this is good enough,

Yes it looks good enough.
And it compiles fine in my test.

Quoted 6 lines

The only remaining issue is rte_option_init().
Sorry I missed your previous message and did not respond in time, I would have opted for leaving a return value to at least be able to stop the init on error. It is possible to force the callback type to return an error value along with a string / hint describing the error. It should not be hard to add it later, so not blocking IMO.

Quoted 3 lines

Agree this can be added in the future.

Quoted 1 line

I think you need to set this API as experimental.

Will do, thanks.

Correction: This is an internal function (eal_private.h), so no need to mark as experimental. rte_option_register() is marked as experimental.

#154 lore raw

PATCH v7 2/13 eal: make get runtime dir function public

In reply to Kevin Laatz

This patch makes the eal_get_runtime_dir() API public so it can be used from outside EAL.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  2 +-
 lib/librte_eal/common/eal_filesystem.h  | 15 ++++++++-------
 lib/librte_eal/common/include/rte_eal.h |  9 +++++++++
 lib/librte_eal/linuxapp/eal/eal.c       |  2 +-
 lib/librte_eal/rte_eal_version.map      |  1 +
 5 files changed, 20 insertions(+), 9 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +1 -1
index 178cfd6..52c1dea 100644
@@ -142,7 +142,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/common/eal_filesystem.h +8 -7
index de05feb..b3e8ae5 100644
@@ -27,7 +27,7 @@ eal_create_runtime_dir(void);
 
 /* returns runtime dir */
 const char *
-eal_get_runtime_dir(void);
+rte_eal_get_runtime_dir(void);
 
 #define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
@@ -35,7 +35,7 @@ eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
@@ -47,7 +47,7 @@ eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
 	return buffer;
 }
@@ -55,7 +55,8 @@ eal_mp_socket_path(void)
 #define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(),
+			name);
 	return buffer;
 }
 
@@ -66,7 +67,7 @@ eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
@@ -78,7 +79,7 @@ eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
@@ -99,7 +100,7 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, rte_eal_get_runtime_dir(),
 			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
lib/librte_eal/common/include/rte_eal.h +9 -0
index 3ee897c..150ced7 100644
@@ -507,6 +507,15 @@ enum rte_iova_mode rte_eal_iova_mode(void);
 const char *
 rte_eal_mbuf_user_pool_ops(void);
 
+/**
+ * Get the runtime directory of DPDK
+ *
+ * @return
+ *  The runtime directory path of DPDK
+ */
+const char *
+rte_eal_get_runtime_dir(void);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/linuxapp/eal/eal.c +1 -1
index 70ab032..b75dd01 100644
@@ -150,7 +150,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/rte_eal_version.map +1 -0
index 12ace18..42bd367 100644
@@ -261,6 +261,7 @@ DPDK_18.08 {
 DPDK_18.11 {
 	global:
 
+	rte_eal_get_runtime_dir;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 	rte_strscpy;
Signature · 1 line
2.9.5
#155 lore raw

PATCH v7 3/13 telemetry: initial telemetry infrastructure

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

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.

---
 config/common_base                             |   5 +
 lib/Makefile                                   |   2 +
 lib/librte_telemetry/Makefile                  |  28 ++++++
 lib/librte_telemetry/meson.build               |   7 ++
 lib/librte_telemetry/rte_telemetry.c           | 123 +++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h           |  36 ++++++++
 lib/librte_telemetry/rte_telemetry_internal.h  |  32 +++++++
 lib/librte_telemetry/rte_telemetry_version.map |   6 ++
 lib/meson.build                                |   2 +-
 mk/rte.app.mk                                  |   1 +
 10 files changed, 241 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
config/common_base +5 -0
index be7365e..d59141b 100644
@@ -753,6 +753,11 @@ CONFIG_RTE_LIBRTE_HASH=y
 CONFIG_RTE_LIBRTE_HASH_DEBUG=n
 
 #
+# Compile librte_telemetry
+#
+CONFIG_RTE_LIBRTE_TELEMETRY=n
+
+#
 # Compile librte_efd
 #
 CONFIG_RTE_LIBRTE_EFD=y
lib/Makefile +2 -0
index 8c83942..2b446c6 100644
@@ -105,6 +105,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
lib/librte_telemetry/Makefile new file +28 -0
new file mode 100644
index 0000000..0d61361
@@ -0,0 +1,28 @@
+# 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
+LDLIBS += -ljansson
+
+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
lib/librte_telemetry/meson.build new file +7 -0
new file mode 100644
index 0000000..7716076
@@ -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'
lib/librte_telemetry/rte_telemetry.c new file +123 -0

123 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h new file +36 -0
new file mode 100644
index 0000000..d3b0d8d
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdint.h>
+
+#ifndef _RTE_TELEMETRY_H_
+#define _RTE_TELEMETRY_H_
+
+/**
+ * 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_telemetry_init(void);
+
+/**
+ * Clean up and free memory.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -EPERM on failure
+ */
+int32_t
+rte_telemetry_cleanup(void);
+
+#endif
lib/librte_telemetry/rte_telemetry_internal.h new file +32 -0
new file mode 100644
index 0000000..4e810a8
@@ -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
lib/librte_telemetry/rte_telemetry_version.map new file +6 -0
new file mode 100644
index 0000000..992d227
@@ -0,0 +1,6 @@
+DPDK_18.11 {
+	global:
+
+	rte_telemetry_init;
+	local: *;
+};
lib/meson.build +1 -1
index 24351cc..90a4227 100644
@@ -24,7 +24,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')
mk/rte.app.mk +1 -0
index 3203cf0..a5ce715 100644
@@ -80,6 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#156 lore raw

PATCH v7 4/13 telemetry: add initial connection socket

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the telemetry UNIX socket. It is used to allow connections from external clients.

On the initial connection from a client, ethdev stats are registered in the metrics library, to allow for their retrieval at a later stage.

---
 lib/librte_telemetry/rte_telemetry.c          | 225 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 2 files changed, 229 insertions(+)
lib/librte_telemetry/rte_telemetry.c +225 -0
index ee9c90f..816296b 100644
@@ -3,23 +3,163 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include <pthread.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #include <rte_eal.h>
 #include <rte_ethdev.h>
 #include <rte_metrics.h>
 #include <rte_option.h>
+#include <rte_string_fns.h>
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
 
+#define BUF_SIZE 1024
 #define SLEEP_TIME 10
 
 static telemetry_impl *static_telemetry;
 
+static void
+rte_telemetry_get_runtime_dir(char *socket_path, size_t size)
+{
+	snprintf(socket_path, size, "%s/telemetry", rte_eal_get_runtime_dir());
+}
+
+int32_t
+rte_telemetry_is_port_active(int port_id)
+{
+	int ret;
+
+	ret = rte_eth_find_next(port_id);
+	if (ret == port_id)
+		return 1;
+
+	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
+		port_id);
+	return 0;
+}
+
+static int32_t
+rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
+{
+	int ret, num_xstats, ret_val, i;
+	struct rte_eth_xstat *eth_xstats = NULL;
+	struct rte_eth_xstat_name *eth_xstats_names = NULL;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		return -EINVAL;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d",
+				port_id, num_xstats);
+		return -EPERM;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		return -ENOMEM;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	const char *xstats_names[num_xstats];
+	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	if (eth_xstats_names == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats_names");
+		ret_val = -ENOMEM;
+		goto free_xstats;
+	}
+
+	ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	for (i = 0; i < num_xstats; i++)
+		xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name;
+
+	ret_val = rte_metrics_reg_names(xstats_names, num_xstats);
+	if (ret_val < 0) {
+		TELEMETRY_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
+		ret_val = -1;
+		goto free_xstats;
+	}
+
+	goto free_xstats;
+
+free_xstats:
+	free(eth_xstats);
+	free(eth_xstats_names);
+	return ret_val;
+}
+
+static int32_t
+rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
+{
+	uint16_t pid;
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		telemetry->reg_index =
+			rte_telemetry_reg_ethdev_to_metrics(pid);
+		break;
+	}
+
+	if (telemetry->reg_index < 0) {
+		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+		return -1;
+	}
+
+	telemetry->metrics_register_done = 1;
+
+	return 0;
+}
+
+static int32_t
+rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
+{
+	int ret;
+
+	if (telemetry->accept_fd <= 0) {
+		ret = listen(telemetry->server_fd, 1);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Listening error with server fd");
+			return -1;
+		}
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
+
+		if (telemetry->accept_fd >= 0 &&
+			telemetry->metrics_register_done == 0) {
+			ret = rte_telemetry_initial_accept(telemetry);
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Failed to run initial configurations/tests");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int32_t
 rte_telemetry_run(void *userdata)
 {
+	int ret;
 	struct telemetry_impl *telemetry = userdata;
 
 	if (telemetry == NULL) {
@@ -27,6 +167,12 @@ rte_telemetry_run(void *userdata)
 		return -1;
 	}
 
+	ret = rte_telemetry_accept_new_client(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Accept and read new client failed");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -50,6 +196,67 @@ static void
 	pthread_exit(0);
 }
 
+static int32_t
+rte_telemetry_set_socket_nonblock(int fd)
+{
+	int flags;
+
+	if (fd < 0) {
+		TELEMETRY_LOG_ERR("Invalid fd provided");
+		return -1;
+	}
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0)
+		flags = 0;
+
+	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+static int32_t
+rte_telemetry_create_socket(struct telemetry_impl *telemetry)
+{
+	int ret;
+	struct sockaddr_un addr;
+	char socket_path[BUF_SIZE];
+
+	if (telemetry == NULL)
+		return -1;
+
+	telemetry->server_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (telemetry->server_fd == -1) {
+		TELEMETRY_LOG_ERR("Failed to open socket");
+		return -1;
+	}
+
+	ret  = rte_telemetry_set_socket_nonblock(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		goto close_socket;
+	}
+
+	addr.sun_family = AF_UNIX;
+	rte_telemetry_get_runtime_dir(socket_path, sizeof(socket_path));
+	strlcpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
+	unlink(socket_path);
+
+	if (bind(telemetry->server_fd, (struct sockaddr *)&addr,
+		sizeof(addr)) < 0) {
+		TELEMETRY_LOG_ERR("Socket binding error");
+		goto close_socket;
+	}
+
+	return 0;
+
+close_socket:
+	if (close(telemetry->server_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		return -EPERM;
+	}
+
+	return -1;
+}
+
 int32_t
 rte_telemetry_init()
 {
@@ -77,6 +284,14 @@ rte_telemetry_init()
 		return -EPERM;
 	}
 
+	ret = rte_telemetry_create_socket(static_telemetry);
+	if (ret < 0) {
+		ret = rte_telemetry_cleanup();
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+		return -EPERM;
+	}
+
 	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
 		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
 		(void *)static_telemetry);
@@ -95,11 +310,21 @@ rte_telemetry_init()
 int32_t
 rte_telemetry_cleanup(void)
 {
+	int ret;
 	struct telemetry_impl *telemetry = static_telemetry;
+
+	ret = close(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
 	telemetry->thread_status = 0;
 	pthread_join(telemetry->thread_id, NULL);
 	free(telemetry);
 	static_telemetry = NULL;
+
 	return 0;
 }
 
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 4e810a8..569d56a 100644
@@ -24,9 +24,13 @@ extern int telemetry_log_level;
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
 typedef struct telemetry_impl {
+	int accept_fd;
+	int server_fd;
 	pthread_t thread_id;
 	int thread_status;
 	uint32_t socket_id;
+	int reg_index;
+	int metrics_register_done;
 } telemetry_impl;
 
 #endif
Signature · 1 line
2.9.5
#157 lore raw

PATCH v7 5/13 telemetry: add client feature and sockets

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch introduces clients to the telemetry API.

When a client makes a connection through the initial telemetry socket, they can send a message through the socket to be parsed. Register messages are expected through this socket, to enable clients to register and have a client socket setup for future communications.

A TAILQ is used to store all clients information. Using this, the client sockets are polled for messages, which will later be parsed and dealt with accordingly.

Functionality that make use of the client sockets were introduced in this patch also, such as writing to client sockets, and sending error responses.

---
 lib/librte_telemetry/meson.build              |   2 +
 lib/librte_telemetry/rte_telemetry.c          | 370 +++++++++++++++++++++++++-
 lib/librte_telemetry/rte_telemetry_internal.h |  25 ++
 mk/rte.app.mk                                 |   2 +-
 4 files changed, 395 insertions(+), 4 deletions(-)
lib/librte_telemetry/meson.build +2 -0
index 7716076..0ccfa36 100644
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson
lib/librte_telemetry/rte_telemetry.c +367 -3

442 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_internal.h +25 -0
index 569d56a..e3292cf 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_log.h>
+#include <rte_tailq.h>
 
 #ifndef _RTE_TELEMETRY_INTERNAL_H_
 #define _RTE_TELEMETRY_INTERNAL_H_
@@ -23,6 +24,12 @@ extern int telemetry_log_level;
 #define TELEMETRY_LOG_INFO(fmt, args...) \
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
+typedef struct telemetry_client {
+	char *file_path;
+	int fd;
+	TAILQ_ENTRY(telemetry_client) client_list;
+} telemetry_client;
+
 typedef struct telemetry_impl {
 	int accept_fd;
 	int server_fd;
@@ -31,6 +38,24 @@ typedef struct telemetry_impl {
 	uint32_t socket_id;
 	int reg_index;
 	int metrics_register_done;
+	TAILQ_HEAD(, telemetry_client) client_list_head;
+	struct telemetry_client *request_client;
+	int register_fail_count;
 } telemetry_impl;
 
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type);
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
 #endif
mk/rte.app.mk +1 -1
index a5ce715..620059c 100644
@@ -80,7 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
-_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry -ljansson
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#158 lore raw

PATCH v7 6/13 telemetry: add parser for client socket messages

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the parser file. This is used to parse any messages that are received on any of the client sockets.

Currently, the unregister functionality works using the parser. Functionality relating to getting statistic values for certain ports will be added in a subsequent patch, however the parsing involved for that command is added in this patch.

Some of the parser code included is in preparation for future functionality, that is not implemented yet in this patchset.

---
 lib/librte_telemetry/Makefile                 |   1 +
 lib/librte_telemetry/meson.build              |   4 +-
 lib/librte_telemetry/rte_telemetry.c          |   8 +
 lib/librte_telemetry/rte_telemetry_internal.h |  13 +
 lib/librte_telemetry/rte_telemetry_parser.c   | 569 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser.h   |  13 +
 6 files changed, 606 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
lib/librte_telemetry/Makefile +1 -0
index 0d61361..95c7296 100644
@@ -21,6 +21,7 @@ LIBABIVER := 1
 
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 0ccfa36..7450f96 100644
@@ -1,8 +1,8 @@
 # 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')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +8 -0
index 15292de..d9b67d4 100644
@@ -17,6 +17,7 @@
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
+#include "rte_telemetry_parser.h"
 
 #define BUF_SIZE 1024
 #define ACTION_POST 1
@@ -283,6 +284,7 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
 static int32_t
 rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 {
+	int ret;
 	telemetry_client *client;
 	char client_buf[BUF_SIZE];
 	int bytes;
@@ -293,6 +295,12 @@ rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 		if (bytes > 0) {
 			client_buf[bytes] = '\0';
 			telemetry->request_client = client;
+			ret = rte_telemetry_parse(telemetry, client_buf);
+			if (ret < 0) {
+				TELEMETRY_LOG_WARN("Parse socket input failed: %i",
+						ret);
+				return -1;
+			}
 		}
 	}
 
lib/librte_telemetry/rte_telemetry_internal.h +13 -0
index e3292cf..86a5ba1 100644
@@ -43,6 +43,11 @@ typedef struct telemetry_impl {
 	int register_fail_count;
 } telemetry_impl;
 
+enum rte_telemetry_parser_actions {
+	ACTION_GET = 0,
+	ACTION_DELETE = 2
+};
+
 int32_t
 rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
 
@@ -58,4 +63,12 @@ int32_t
 rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 	const char *client_path);
 
+/**
+ * This is a wrapper for the ethdev api rte_eth_find_next().
+ * If rte_eth_find_next() returns the same port id that we passed it,
+ * then we know that that port is active.
+ */
+int32_t
+rte_telemetry_is_port_active(int port_id);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c new file +569 -0

569 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser.h new file +13 -0
new file mode 100644
index 0000000..63e633d
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_PARSER_H_
+#define _RTE_TELEMETRY_PARSER_H_
+
+int32_t
+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);
+
+#endif
Signature · 1 line
2.9.5
#159 lore raw

PATCH v7 7/13 telemetry: update metrics before sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to update the statistics in the metrics library with values from the ethdev stats.

Values need to be updated before they are encoded into a JSON message and sent to the client that requested them. The JSON encoding will be added in a subsequent patch.

---
 lib/librte_telemetry/rte_telemetry.c          | 134 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 lib/librte_telemetry/rte_telemetry_parser.c   |  17 ++++
 3 files changed, 155 insertions(+)
lib/librte_telemetry/rte_telemetry.c +134 -0
index d9b67d4..556e53d 100644
@@ -46,6 +46,78 @@ rte_telemetry_is_port_active(int port_id)
 	return 0;
 }
 
+static int32_t
+rte_telemetry_update_metrics_ethdev(struct telemetry_impl *telemetry,
+	uint16_t port_id, int reg_start_index)
+{
+	int ret, num_xstats, i;
+	struct rte_eth_xstat *eth_xstats;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_telemetry_is_port_active(port_id);
+	if (ret < 1) {
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", port_id,
+				num_xstats);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		free(eth_xstats);
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	uint64_t xstats_values[num_xstats];
+	for (i = 0; i < num_xstats; i++)
+		xstats_values[i] = eth_xstats[i].value;
+
+	ret = rte_metrics_update_values(port_id, reg_start_index, xstats_values,
+			num_xstats);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not update metrics values");
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		free(eth_xstats);
+		return -1;
+	}
+
+	free(eth_xstats);
+	return 0;
+}
+
 int32_t
 rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,
 	const char *json_string)
@@ -130,6 +202,68 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
+{
+	int ret, i;
+	char *json_buffer = NULL;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Invalid telemetry argument");
+		return -1;
+	}
+
+	if (metric_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid metric_ids array");
+		goto einval_fail;
+	}
+
+	if (num_metric_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_metric_ids, must be positive");
+		goto einval_fail;
+	}
+
+	if (port_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid port_ids array");
+		goto einval_fail;
+	}
+
+	if (num_port_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_port_ids, must be positive");
+		goto einval_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+
+		ret = rte_telemetry_update_metrics_ethdev(telemetry,
+			port_ids[i], telemetry->reg_index);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
+			return -1;
+		}
+	}
+
+	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not write to socket");
+		return -1;
+	}
+
+	return 0;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+
 static int32_t
 rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
 {
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 86a5ba1..0082cb2 100644
@@ -71,4 +71,8 @@ rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 int32_t
 rte_telemetry_is_port_active(int port_id);
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c +17 -0
index 6bc4c6d..084c160 100644
@@ -258,6 +258,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	int ret, num_metrics, i, p;
 	struct rte_metric_name *names;
 	uint64_t num_port_ids = 0;
+	uint32_t port_ids[RTE_MAX_ETHPORTS];
 
 	if (telemetry == NULL) {
 		TELEMETRY_LOG_ERR("Invalid telemetry argument");
@@ -313,6 +314,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	uint32_t stat_ids[num_metrics];
 
 	RTE_ETH_FOREACH_DEV(p) {
+		port_ids[num_port_ids] = p;
 		num_port_ids++;
 	}
 
@@ -337,6 +339,13 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 		goto fail;
 	}
 
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_metrics,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		goto fail;
+	}
+
 	return 0;
 
 fail:
@@ -428,6 +437,14 @@ rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl
 		TELEMETRY_LOG_ERR("Could not convert stat names to IDs");
 		return -1;
 	}
+
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_stat_names,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		return -1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.9.5
#160 lore raw

PATCH v7 8/13 telemetry: format json response when sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to create a JSON message in order to send it to a client socket.

When stats are requested by a client, they are retrieved from the metrics library and encoded in JSON format.

---
 lib/librte_telemetry/rte_telemetry.c | 309 ++++++++++++++++++++++++++++++++++-
 1 file changed, 307 insertions(+), 2 deletions(-)
lib/librte_telemetry/rte_telemetry.c +307 -2
index 556e53d..3e76108 100644
@@ -190,7 +190,7 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 		return -EPERM;
 	}
 
-	json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_buffer = json_dumps(root, 0);
 	json_decref(root);
 
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
@@ -202,6 +202,304 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+static int
+rte_telemetry_get_metrics(struct telemetry_impl *telemetry, uint32_t port_id,
+	struct rte_metric_value *metrics, struct rte_metric_name *names,
+	int num_metrics)
+{
+	int ret, num_values;
+
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Invalid metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	if (metrics == NULL) {
+		TELEMETRY_LOG_ERR("Metrics must be initialised.");
+		goto einval_fail;
+	}
+
+	if (names == NULL) {
+		TELEMETRY_LOG_ERR("Names must be initialised.");
+		goto einval_fail;
+	}
+
+	ret = rte_metrics_get_names(names, num_metrics);
+	if (ret < 0 || ret > num_metrics) {
+		TELEMETRY_LOG_ERR("Cannot get metrics names");
+		goto eperm_fail;
+	}
+
+	num_values = rte_metrics_get_values(port_id, NULL, 0);
+	ret = rte_metrics_get_values(port_id, metrics, num_values);
+	if (ret < 0 || ret > num_values) {
+		TELEMETRY_LOG_ERR("Cannot get metrics values");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_stat(struct telemetry_impl *telemetry, json_t *stats,
+	const char *metric_name, uint64_t metric_value)
+{
+	int ret;
+	json_t *stat = json_object();
+
+	if (stat == NULL) {
+		TELEMETRY_LOG_ERR("Could not create stat JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "name", json_string(metric_name));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Name field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "value", json_integer(metric_value));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Value field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(stats, stat);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat cannot be added to stats json array");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_port(struct telemetry_impl *telemetry,
+	uint32_t port_id, json_t *ports, uint32_t *metric_ids,
+	uint32_t num_metric_ids)
+{
+	struct rte_metric_value *metrics = 0;
+	struct rte_metric_name *names = 0;
+	int num_metrics, ret, err_ret;
+	json_t *port, *stats;
+	uint32_t i;
+
+	num_metrics = rte_metrics_get_names(NULL, 0);
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Cannot get metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	metrics = malloc(sizeof(struct rte_metric_value) * num_metrics);
+	names = malloc(sizeof(struct rte_metric_name) * num_metrics);
+	if (metrics == NULL || names == NULL) {
+		TELEMETRY_LOG_ERR("Cannot allocate memory");
+		free(metrics);
+		free(names);
+
+		err_ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (err_ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret  = rte_telemetry_get_metrics(telemetry, port_id, metrics, names,
+		num_metrics);
+	if (ret < 0) {
+		free(metrics);
+		free(names);
+		TELEMETRY_LOG_ERR("rte_telemetry_get_metrics failed");
+		return -1;
+	}
+
+	port = json_object();
+	stats = json_array();
+	if (port == NULL || stats == NULL) {
+		TELEMETRY_LOG_ERR("Could not create port/stats JSON objects");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(port, "port", json_integer(port_id));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port field cannot be set");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_metric_ids; i++) {
+		int metric_id = metric_ids[i];
+		int metric_index = -1;
+		int metric_name_key = -1;
+		int32_t j;
+		uint64_t metric_value;
+
+		if (metric_id >= num_metrics) {
+			TELEMETRY_LOG_ERR("Metric_id: %d is not valid",
+					metric_id);
+			goto einval_fail;
+		}
+
+		for (j = 0; j < num_metrics; j++) {
+			if (metrics[j].key == metric_id) {
+				metric_name_key = metrics[j].key;
+				metric_index = j;
+				break;
+			}
+		}
+
+		const char *metric_name = names[metric_name_key].name;
+		metric_value = metrics[metric_index].value;
+
+		if (metric_name_key < 0 || metric_index < 0) {
+			TELEMETRY_LOG_ERR("Could not get metric name/index");
+			goto eperm_fail;
+		}
+
+		ret = rte_telemetry_json_format_stat(telemetry, stats,
+			metric_name, metric_value);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format stat with id: %u failed",
+					metric_id);
+			free(metrics);
+			free(names);
+			return -1;
+		}
+	}
+
+	if (json_array_size(stats) == 0)
+		ret = json_object_set_new(port, "stats", json_null());
+	else
+		ret = json_object_set_new(port, "stats", stats);
+
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stats object cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(ports, port);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port object cannot be added to ports array");
+		goto eperm_fail;
+	}
+
+	free(metrics);
+	free(names);
+	return 0;
+
+eperm_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+static int32_t
+rte_telemetry_encode_json_format(struct telemetry_impl *telemetry,
+	uint32_t *port_ids, uint32_t num_port_ids, uint32_t *metric_ids,
+	uint32_t num_metric_ids, char **json_buffer)
+{
+	int ret;
+	json_t *root, *ports;
+	uint32_t i;
+
+	if (num_port_ids <= 0 || num_metric_ids <= 0) {
+		TELEMETRY_LOG_ERR("Please provide port and metric ids to query");
+		goto einval_fail;
+	}
+
+	ports = json_array();
+	if (ports == NULL) {
+		TELEMETRY_LOG_ERR("Could not create ports JSON array");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		ret = rte_telemetry_json_format_port(telemetry, port_ids[i],
+			ports, metric_ids, num_metric_ids);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format port in JSON failed");
+			return -1;
+		}
+	}
+
+	root = json_object();
+	if (root == NULL) {
+		TELEMETRY_LOG_ERR("Could not create root JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "status_code",
+		json_string("Status OK: 200"));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Status code field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "data", ports);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Data field cannot be set");
+		goto eperm_fail;
+	}
+
+	*json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_decref(root);
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
 int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
@@ -241,13 +539,20 @@ rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 		}
 
 		ret = rte_telemetry_update_metrics_ethdev(telemetry,
-			port_ids[i], telemetry->reg_index);
+				port_ids[i], telemetry->reg_index);
 		if (ret < 0) {
 			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
 			return -1;
 		}
 	}
 
+	ret = rte_telemetry_encode_json_format(telemetry, port_ids,
+		num_port_ids, metric_ids, num_metric_ids, &json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("JSON encode function failed");
+		return -1;
+	}
+
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
 	if (ret < 0) {
 		TELEMETRY_LOG_ERR("Could not write to socket");
Signature · 1 line
2.9.5
#161 lore raw

PATCH v7 9/13 telemetry: add tests for telemetry api

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

---
 lib/librte_telemetry/Makefile                     |   1 +
 lib/librte_telemetry/meson.build                  |   4 +-
 lib/librte_telemetry/rte_telemetry.c              | 653 ++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |  12 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   3 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  | 534 ++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |  39 ++
 lib/librte_telemetry/rte_telemetry_socket_tests.h |  36 ++
 lib/librte_telemetry/rte_telemetry_version.map    |   1 +
 9 files changed, 1281 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
lib/librte_telemetry/Makefile +1 -0
index 95c7296..1a05069 100644
@@ -22,6 +22,7 @@ LIBABIVER := 1
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 7450f96..57dd83d 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
-sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h', 'rte_telemetry_parser_test.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +653 -0

684 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h +12 -0
index d3b0d8d..958723b 100644
@@ -33,4 +33,16 @@ rte_telemetry_init(void);
 int32_t
 rte_telemetry_cleanup(void);
 
+/**
+ * Runs various tests to ensure telemetry initialisation and register/unregister
+ * functions are working correctly.
+ *
+ * @return
+ *  0 on success when all tests have passed
+ * @return
+ *  -1 on failure when the test has failed
+ */
+int32_t
+rte_telemetry_selftest(void);
+
 #endif
lib/librte_telemetry/rte_telemetry_internal.h +3 -0
index 0082cb2..de7afda 100644
@@ -75,4 +75,7 @@ int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
 
+int32_t
+rte_telemetry_socket_messaging_testing(int index, int socket);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser_test.c new file +534 -0

534 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser_test.h new file +39 -0
new file mode 100644
index 0000000..6ada852
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_TELEMETRY_PARSER_TEST_H_
+#define _RTE_TELEMETRY_PARSER_TEST_H_
+
+int32_t
+rte_telemetry_parser_test(struct telemetry_impl *telemetry);
+
+int32_t
+rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, json_t **data);
+
+int32_t
+rte_telemetry_create_json_request(int action, char *command,
+	const char *client_path, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, char **request,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
+	int action_choice, char *command_choice, int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
+	int action_choice, int *port_ids, int num_port_ids, int inv_choice);
+
+int32_t
+rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
+	*telemetry, int action_choice, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_unreg_request(int action_choice, const char *client_path,
+	int inv_choice);
+
+#endif
lib/librte_telemetry/rte_telemetry_socket_tests.h new file +36 -0
new file mode 100644
index 0000000..db9167c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdbool.h>
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
+#define _RTE_TELEMETRY_SOCKET_TESTING_H_
+
+int32_t
+rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
+	int fd);
+
+int32_t
+rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
+	int send_fd, int recv_fd);
+
+int32_t
+rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
+	int *recv_fd);
+
+#endif
lib/librte_telemetry/rte_telemetry_version.map +1 -0
index 992d227..98459fc 100644
@@ -2,5 +2,6 @@ DPDK_18.11 {
 	global:
 
 	rte_telemetry_init;
+	rte_telemetry_selftest;
 	local: *;
 };
Signature · 1 line
2.9.5
#162 lore raw

PATCH v7 10/13 telemetry: add ability to disable selftest

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

---
 lib/librte_telemetry/rte_telemetry.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/librte_telemetry/rte_telemetry.c +13 -10
index 324185f..a169832 100644
@@ -660,6 +660,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
 	uint16_t pid;
 	int ret;
+	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
@@ -672,18 +673,20 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 	}
 
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (selftest) {
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+				telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Parser Tests Failed");
-		return -1;
-	}
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Parser Tests Failed");
+			return -1;
+		}
 
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+	}
 
 	return 0;
 }
Signature · 1 line
2.9.5
#163 lore raw

PATCH v7 11/13 doc: add telemetry documentation

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry and a release notes update for telemetry.

---
 MAINTAINERS                            |  5 ++
 doc/guides/howto/index.rst             |  1 +
 doc/guides/howto/telemetry.rst         | 85 ++++++++++++++++++++++++++++++++++
 doc/guides/rel_notes/release_18_11.rst |  6 +++
 4 files changed, 97 insertions(+)
 create mode 100644 doc/guides/howto/telemetry.rst
MAINTAINERS +5 -0
index b220479..7612a5b 100644
@@ -1208,6 +1208,11 @@ F: test/bpf/
 F: test/test/test_bpf.c
 F: doc/guides/prog_guide/bpf_lib.rst
 
+Telemetry
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst
 
 Test Applications
 -----------------
doc/guides/howto/index.rst +1 -0
index e13a090..a642a2b 100644
@@ -17,3 +17,4 @@ HowTo Guides
     virtio_user_for_container_networking
     virtio_user_as_exceptional_path
     packet_capture_framework
+    telemetry
doc/guides/howto/telemetry.rst new file +85 -0

85 lines not on this page · raw message

doc/guides/rel_notes/release_18_11.rst +6 -0
index 04f3745..e82c790 100644
@@ -189,6 +189,12 @@ New Features
   the specified port. The port must be stopped before the command call in order
   to reconfigure queues.
 
+* **Added Telemetry API.**
+
+  Added the telemetry API which allows applications to transparently expose
+  their telemetry via a UNIX socket in JSON. The JSON can be consumed by any
+  Service Assurance agent, such as CollectD.
+
 * **Add a new sample for vDPA**
 
   The vdpa sample application creates vhost-user sockets by using the
Signature · 1 line
2.9.5
#164 lore raw

PATCH v7 12/13 usertools: add client python script for telemetry

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds a python script which can be used as a demo client. The script is interactive and will allow the user to register, request statistics, and unregister.

To run the script, an argument for the client file path must be passed in: "python telemetry_client.py <file_path>".

This script is useful to see how the Telemetry API for DPDK is used, and how to make the initial connection.

---
 usertools/dpdk-telemetry-client.py | 116 +++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 usertools/dpdk-telemetry-client.py
usertools/dpdk-telemetry-client.py new file +116 -0
new file mode 100644
index 0000000..6dcf62b
@@ -0,0 +1,116 @@
+# SPDK-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Intel Corporation
+
+import socket
+import os
+import sys
+import time
+
+BUFFER_SIZE = 200000
+
+METRICS_REQ = "{\"action\":0,\"command\":\"ports_all_stat_values\",\"data\":null}"
+API_REG = "{\"action\":1,\"command\":\"clients\",\"data\":{\"client_path\":\""
+API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
+DEFAULT_FP = "/var/run/dpdk/default_client"
+
+class Socket:
+
+    def __init__(self):
+        self.send_fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+        self.recv_fd = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+        self.client_fd = None
+
+    def __del__(self):
+        try:
+            self.send_fd.close()
+            self.recv_fd.close()
+            self.client_fd.close()
+        except:
+            print("Error - Sockets could not be closed")
+
+class Client:
+
+    def __init__(self): # Creates a client instance
+        self.socket = Socket()
+        self.file_path = None
+        self.choice = None
+        self.unregistered = 0
+
+    def __del__(self):
+        try:
+            if self.unregistered == 0:
+                self.unregister();
+        except:
+            print("Error - Client could not be destroyed")
+
+    def getFilepath(self, file_path): # Gets arguments from Command-Line and assigns to instance of client
+        self.file_path = file_path
+
+    def register(self): # Connects a client to DPDK-instance
+        if os.path.exists(self.file_path):
+            os.unlink(self.file_path)
+        try:
+            self.socket.recv_fd.bind(self.file_path)
+        except socket.error as msg:
+            print ("Error - Socket binding error: " + str(msg) + "\n")
+        self.socket.recv_fd.settimeout(2)
+        self.socket.send_fd.connect("/var/run/dpdk/rte/telemetry")
+        JSON = (API_REG + self.file_path + "\"}}")
+        self.socket.send_fd.sendall(JSON)
+        self.socket.recv_fd.listen(1)
+        self.socket.client_fd = self.socket.recv_fd.accept()[0]
+
+    def unregister(self): # Unregister a given client
+        self.socket.client_fd.send(API_UNREG + self.file_path + "\"}}")
+        self.socket.client_fd.close()
+
+    def requestMetrics(self): # Requests metrics for given client
+        self.socket.client_fd.send(METRICS_REQ)
+        data = self.socket.client_fd.recv(BUFFER_SIZE)
+        print "\nResponse: \n", str(data)
+
+    def repeatedlyRequestMetrics(self, sleep_time): # Recursively requests metrics for given client
+        print("\nPlease enter the number of times you'd like to continuously request Metrics:")
+        n_requests = int(input("\n:"))
+        print("\033[F") #Removes the user input from screen, cleans it up
+        print("\033[K")
+        for i in range(n_requests):
+            self.requestMetrics()
+            time.sleep(sleep_time)
+
+    def interactiveMenu(self, sleep_time): # Creates Interactive menu within the script
+        while self.choice != 3:
+            print("\nOptions Menu")
+            print("[1] Send for Metrics for all ports")
+            print("[2] Send for Metrics for all ports recursively")
+            print("[3] Unregister client")
+
+            try:
+                self.choice = int(input("\n:"))
+                print("\033[F") #Removes the user input for screen, cleans it up
+                print("\033[K")
+                if self.choice == 1:
+                    self.requestMetrics()
+                elif self.choice == 2:
+                    self.repeatedlyRequestMetrics(sleep_time)
+                elif self.choice == 3:
+                    self.unregister()
+                    self.unregistered = 1
+                else:
+                    print("Error - Invalid request choice")
+            except:
+                pass
+
+if __name__ == "__main__":
+
+    sleep_time = 1
+    file_path = ""
+    if (len(sys.argv) == 2):
+	file_path = sys.argv[1]
+    else:
+        print("Warning - No filepath passed, using default (" + DEFAULT_FP + ").")
+	file_path = DEFAULT_FP
+    client = Client()
+    client.getFilepath(file_path)
+    client.register()
+    client.interactiveMenu(sleep_time)
Signature · 1 line
2.9.5
#165 lore raw

PATCH v7 13/13 build: add dependency on telemetry to apps in meson

In reply to Kevin Laatz

This patch adds telemetry as a dependecy to all applications. Without these changes, the --telemetry flag will not be recognised and applications will fail to run if they want to enable telemetry.

---
 app/meson.build                  | 4 ++--
 app/pdump/meson.build            | 2 +-
 app/proc-info/meson.build        | 2 +-
 app/test-bbdev/meson.build       | 2 +-
 app/test-crypto-perf/meson.build | 2 +-
 app/test-pmd/meson.build         | 2 +-
 config/meson.build               | 3 +++
 lib/meson.build                  | 1 +
 meson.build                      | 1 +
 9 files changed, 12 insertions(+), 7 deletions(-)
app/meson.build +2 -2
index e68d949..78bc3af 100644
@@ -29,7 +29,7 @@ foreach app:apps
 	# use "deps" for internal DPDK dependencies, and "ext_deps" for
 	# external package/library requirements
 	ext_deps = []
-	deps = []
+	deps = ['telemetry']
 
 	subdir(name)
 
@@ -43,7 +43,7 @@ foreach app:apps
 
 		link_libs = []
 		if get_option('default_library') == 'static'
-			link_libs = dpdk_drivers
+			link_libs = dpdk_static_libraries + dpdk_drivers
 		endif
 
 		if allow_experimental_apis
app/pdump/meson.build +1 -1
index 988cb4e..116c27f 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'kvargs', 'pdump']
+deps += ['ethdev', 'kvargs', 'pdump']
app/proc-info/meson.build +1 -1
index 9c148e3..a52b2ee 100644
@@ -3,4 +3,4 @@
 
 sources = files('main.c')
 allow_experimental_apis = true
-deps = ['ethdev', 'metrics']
+deps += ['ethdev', 'metrics']
app/test-bbdev/meson.build +1 -1
index 653907d..eb8cc04 100644
@@ -6,4 +6,4 @@ sources = files('main.c',
 		'test_bbdev_perf.c',
 		'test_bbdev_vector.c')
 allow_experimental_apis = true
-deps = ['bbdev', 'bus_vdev']
+deps += ['bbdev', 'bus_vdev']
app/test-crypto-perf/meson.build +1 -1
index eacd7a0..d735b18 100644
@@ -12,4 +12,4 @@ sources = files('cperf_ops.c',
 		'cperf_test_vectors.c',
 		'cperf_test_verify.c',
 		'main.c')
-deps = ['cryptodev']
+deps += ['cryptodev']
app/test-pmd/meson.build +1 -1
index cd66618..6006c60 100644
@@ -24,7 +24,7 @@ sources = files('cmdline.c',
 	'txonly.c',
 	'util.c')
 
-deps = ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
+deps += ['ethdev', 'gro', 'gso', 'cmdline', 'metrics', 'meter', 'bus_pci']
 if dpdk_conf.has('RTE_LIBRTE_PDUMP')
 	deps += 'pdump'
 endif
config/meson.build +3 -0
index 6f9228c..275f00b 100644
@@ -21,6 +21,9 @@ toolchain = cc.get_id()
 dpdk_conf.set_quoted('RTE_TOOLCHAIN', toolchain)
 dpdk_conf.set('RTE_TOOLCHAIN_' + toolchain.to_upper(), 1)
 
+add_project_link_arguments('-Wl,--no-as-needed', language: 'c')
+dpdk_extra_ldflags += '-Wl,--no-as-needed'
+
 # use pthreads
 add_project_link_arguments('-pthread', language: 'c')
 dpdk_extra_ldflags += '-pthread'
lib/meson.build +1 -0
index 90a4227..ae99ab0 100644
@@ -131,6 +131,7 @@ foreach l:libraries
 					dependencies: shared_deps)
 
 			dpdk_libraries = [shared_lib] + dpdk_libraries
+			dpdk_static_libraries = [static_lib] + dpdk_static_libraries
 		endif # sources.length() > 0
 
 		set_variable('shared_' + libname, shared_dep)
meson.build +1 -0
index c9af335..f3bddb2 100644
@@ -12,6 +12,7 @@ project('DPDK', 'C',
 cc = meson.get_compiler('c')
 dpdk_conf = configuration_data()
 dpdk_libraries = []
+dpdk_static_libraries = []
 dpdk_drivers = []
 dpdk_extra_ldflags = []
 
Signature · 1 line
2.9.5
#168 lore raw

v8 cover introduce telemetry library

In reply to Kevin Laatz

This patchset introduces a Telemetry library for DPDK Service Assurance. This library provides an easy way to query DPDK Ethdev metrics.

The telemetry library provides a method for a service assurance component to retrieve metrics from a DPDK packet forwarding application. Communicating from the service assurance component to DPDK is done using a UNIX domain socket, passing a JSON formatted string. A reply is sent (again a JSON formatted string) of the current DPDK metrics.

The telemetry component makes use of the existing rte_metrics library to query values. The values to be transmitted via the telemetry infrastructure must be present in the Metrics library. Currently the ethdev values are pushed to the metrics library, and the queried from there there is an open question on how applications would like this to occur. Currently only ethdev to metrics functionality is implemented, however other subsystems like crypto, eventdev, keepalive etc can use similar mechanisms.

Exposing DPDK Telemetry via a socket interface enables service assurance agents like collectd to consume data from DPDK. This is vital for monitoring, fault-detection, and error reporting. A collectd plugin has been created to interact with the DPDK Telemetry component, showing how it can be used in practice. The collectd plugin will be upstreamed to collectd at a later stage. A small python script is provided in ./usertools/telemetry_client.py to quick-start using DPDK Telemetry.

Note: Despite opterr being set to 0, --telemetry said to be 'unrecognized' as a startup print. This is a cosmetic issue and will be addressed in the future.

---
v2:
- Reworked telemetry as part of EAL instead of using vdev (Gaetan)
- Refactored rte_telemetry_command (Gaetan)
- Added MAINTAINERS file entry (Stephen)
- Updated docs to reflect vdev to eal rework
- Removed collectd patch from patchset (Thomas)
- General code clean up from v1 feedback

v3:
- Reworked registering with eal and moved to rte_param (Gaetan)
- Added BSD implementation for rte_param (Gaetan)
- Updated the paths to align with the new runtime file location (Mattias)
- Fixed pointer checks to align with the coding style 1.8.1 (Mattias)
- Added missing decref's and close's (Mattias)
- Fixed runtime issue in Meson (was not recognising flag due to linking)
- More general clean up

v4:
- Added Doxygen comments for rte_param.h (Thomas)
- Made eal_get_runtime_dir a public function to use outside of EAL (Thomas)
- Reworked telemetry to get path using rte_eal_get_runtime_dir (Thomas)
- Fixed checkpatch coding style error

v5:
- Moved the BUF_SIZE define to fix build (Harry)
- Set default config for telemetry to 'n' (Harry)
- Improved Doxygen comments (Thomas)
- Cleaned up rte_param struct (Thomas)

v6:
- Renamed rte_param to rte_option (Thomas)
- Moved internal functions to eal_private.h (Gaetan)
- Added fail check for pthread_attr_init() (Mattias)
- Changed socket implementation to SOCK_SEQPACKET (Mattias)
- Added check to avoid option duplicates (Gaetan)
- Removed telemetry example from Doxygen comment (Gaetan)
- General Doxygen clean-up (Thomas)
- General code clean-up (Mattias)

v7:
- Fix object leak (Mattias)
- General clean-up (Mattias)
- Fix rte_option header define
- Added release note update
- Rebased

v8:
- Added missing experimental tags
- Added Gaetan's Ack from ML

Ciara Power, Brian Archbold and Kevin Laatz (10):
telemetry: initial telemetry infrastructure
telemetry: add initial connection socket
telemetry: add client feature and sockets
telemetry: add parser for client socket messages
telemetry: update metrics before sending stats
telemetry: format json response when sending stats
telemetry: add tests for telemetry api
telemetry: add ability to disable selftest
doc: add telemetry documentation
usertools: add client python script for telemetry

Kevin Laatz (3):
eal: add option register infrastructure
eal: make get runtime dir function public
build: add dependency on telemetry to apps in meson

 MAINTAINERS                                       |    5 +
 app/meson.build                                   |    4 +-
 app/pdump/meson.build                             |    2 +-
 app/proc-info/meson.build                         |    2 +-
 app/test-bbdev/meson.build                        |    2 +-
 app/test-crypto-perf/meson.build                  |    2 +-
 app/test-pmd/meson.build                          |    2 +-
 config/common_base                                |    5 +
 config/meson.build                                |    3 +
 doc/guides/howto/index.rst                        |    1 +
 doc/guides/howto/telemetry.rst                    |   85 +
 doc/guides/rel_notes/release_18_11.rst            |    6 +
 lib/Makefile                                      |    2 +
 lib/librte_eal/bsdapp/eal/Makefile                |    1 +
 lib/librte_eal/bsdapp/eal/eal.c                   |   16 +-
 lib/librte_eal/common/Makefile                    |    1 +
 lib/librte_eal/common/eal_filesystem.h            |   15 +-
 lib/librte_eal/common/eal_private.h               |   21 +
 lib/librte_eal/common/include/rte_eal.h           |    9 +
 lib/librte_eal/common/include/rte_option.h        |   63 +
 lib/librte_eal/common/meson.build                 |    2 +
 lib/librte_eal/common/rte_option.c                |   54 +
 lib/librte_eal/linuxapp/eal/Makefile              |    1 +
 lib/librte_eal/linuxapp/eal/eal.c                 |   16 +-
 lib/librte_eal/rte_eal_version.map                |    2 +
 lib/librte_telemetry/Makefile                     |   30 +
 lib/librte_telemetry/meson.build                  |    9 +
 lib/librte_telemetry/rte_telemetry.c              | 1815 +++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |   57 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   81 +
 lib/librte_telemetry/rte_telemetry_parser.c       |  586 +++++++
 lib/librte_telemetry/rte_telemetry_parser.h       |   13 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  |  534 ++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |   39 +
 lib/librte_telemetry/rte_telemetry_socket_tests.h |   36 +
 lib/librte_telemetry/rte_telemetry_version.map    |    9 +
 lib/meson.build                                   |    3 +-
 meson.build                                       |    1 +
 mk/rte.app.mk                                     |    1 +
 usertools/dpdk-telemetry-client.py                |  116 ++
 40 files changed, 3633 insertions(+), 19 deletions(-)
 create mode 100644 doc/guides/howto/telemetry.rst
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
 create mode 100644 usertools/dpdk-telemetry-client.py
Signature · 1 line
2.9.5
#169 lore raw

PATCH v8 1/13 eal: add option register infrastructure

This commit adds infrastructure to EAL that allows an application to register it's init function with EAL. This allows libraries to be initialized at the end of EAL init.

This infrastructure allows libraries that depend on EAL to be initialized as part of EAL init, removing circular dependency issues.

---
 lib/librte_eal/bsdapp/eal/Makefile         |  1 +
 lib/librte_eal/bsdapp/eal/eal.c            | 14 ++++++-
 lib/librte_eal/common/Makefile             |  1 +
 lib/librte_eal/common/eal_private.h        | 21 ++++++++++
 lib/librte_eal/common/include/rte_option.h | 63 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/meson.build          |  2 +
 lib/librte_eal/common/rte_option.c         | 54 +++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile       |  1 +
 lib/librte_eal/linuxapp/eal/eal.c          | 14 ++++++-
 lib/librte_eal/rte_eal_version.map         |  1 +
 10 files changed, 170 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_option.h
 create mode 100644 lib/librte_eal/common/rte_option.c
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index d19f53c..bfeddaa 100644
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_reciprocal.c
 
lib/librte_eal/bsdapp/eal/eal.c +13 -1
index 7735194..178cfd6 100644
@@ -42,6 +42,7 @@
 #include <rte_devargs.h>
 #include <rte_version.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 
@@ -414,12 +415,20 @@ eal_parse_args(int argc, char **argv)
 	argvopt = argv;
 	optind = 1;
 	optreset = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -791,6 +800,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/common/Makefile +1 -0
index cca6882..87d8c45 100644
@@ -12,6 +12,7 @@ INC += rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h
+INC += rte_option.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_malloc.h rte_keepalive.h rte_time.h
 INC += rte_service.h rte_service_component.h
lib/librte_eal/common/eal_private.h +21 -0
index b189d67..442c6dc 100644
@@ -349,4 +349,25 @@ dev_sigbus_handler_register(void);
 int
 dev_sigbus_handler_unregister(void);
 
+/**
+ * Check if the option is registered.
+ *
+ * @param option
+ *  The option to be parsed.
+ *
+ * @return
+ *  0 on success
+ * @return
+ *  -1 on fail
+ */
+int
+rte_option_parse(const char *opt);
+
+/**
+ * Iterate through the registered options and execute the associated
+ * callback if enabled.
+ */
+void
+rte_option_init(void);
+
 #endif /* _EAL_PRIVATE_H_ */
lib/librte_eal/common/include/rte_option.h new file +63 -0

63 lines not on this page · raw message

lib/librte_eal/common/meson.build +2 -0
index 04c4143..2a10d57 100644
@@ -34,6 +34,7 @@ common_sources = files(
 	'malloc_mp.c',
 	'rte_keepalive.c',
 	'rte_malloc.c',
+	'rte_option.c',
 	'rte_reciprocal.c',
 	'rte_service.c'
 )
@@ -71,6 +72,7 @@ common_headers = files(
 	'include/rte_malloc_heap.h',
 	'include/rte_memory.h',
 	'include/rte_memzone.h',
+	'include/rte_option.h',
 	'include/rte_pci_dev_feature_defs.h',
 	'include/rte_pci_dev_features.h',
 	'include/rte_per_lcore.h',
lib/librte_eal/common/rte_option.c new file +54 -0

54 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 7280885..51deb57 100644
@@ -75,6 +75,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_keepalive.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_option.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_service.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_reciprocal.c
 
lib/librte_eal/linuxapp/eal/eal.c +13 -1
index a00cebf..70ab032 100644
@@ -48,6 +48,7 @@
 #include <rte_atomic.h>
 #include <malloc_heap.h>
 #include <rte_vfio.h>
+#include <rte_option.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
@@ -600,12 +601,20 @@ eal_parse_args(int argc, char **argv)
 
 	argvopt = argv;
 	optind = 1;
+	opterr = 0;
 
 	while ((opt = getopt_long(argc, argvopt, eal_short_options,
 				  eal_long_options, &option_index)) != EOF) {
 
-		/* getopt is not happy, stop right now */
+		/*
+		 * getopt didn't recognise the option, lets parse the
+		 * registered options to see if the flag is valid
+		 */
 		if (opt == '?') {
+			ret = rte_option_parse(argv[optind-1]);
+			if (ret == 0)
+				continue;
+
 			eal_usage(prgname);
 			ret = -1;
 			goto out;
@@ -1080,6 +1089,9 @@ rte_eal_init(int argc, char **argv)
 
 	rte_eal_mcfg_complete();
 
+	/* Call each registered callback, if enabled */
+	rte_option_init();
+
 	return fctret;
 }
 
lib/librte_eal/rte_eal_version.map +1 -0
index 08e3bc2..12ace18 100644
@@ -351,6 +351,7 @@ EXPERIMENTAL {
 	rte_mp_request_sync;
 	rte_mp_request_async;
 	rte_mp_sendmsg;
+	rte_option_register;
 	rte_service_lcore_attr_get;
 	rte_service_lcore_attr_reset_all;
 	rte_service_may_be_active;
Signature · 1 line
2.9.5
#170 lore raw

PATCH v8 2/13 eal: make get runtime dir function public

In reply to Kevin Laatz

This patch makes the eal_get_runtime_dir() API public so it can be used from outside EAL.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  2 +-
 lib/librte_eal/common/eal_filesystem.h  | 15 ++++++++-------
 lib/librte_eal/common/include/rte_eal.h |  9 +++++++++
 lib/librte_eal/linuxapp/eal/eal.c       |  2 +-
 lib/librte_eal/rte_eal_version.map      |  1 +
 5 files changed, 20 insertions(+), 9 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +1 -1
index 178cfd6..52c1dea 100644
@@ -142,7 +142,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/common/eal_filesystem.h +8 -7
index de05feb..b3e8ae5 100644
@@ -27,7 +27,7 @@ eal_create_runtime_dir(void);
 
 /* returns runtime dir */
 const char *
-eal_get_runtime_dir(void);
+rte_eal_get_runtime_dir(void);
 
 #define RUNTIME_CONFIG_FNAME "config"
 static inline const char *
@@ -35,7 +35,7 @@ eal_runtime_config_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			RUNTIME_CONFIG_FNAME);
 	return buffer;
 }
@@ -47,7 +47,7 @@ eal_mp_socket_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			MP_SOCKET_FNAME);
 	return buffer;
 }
@@ -55,7 +55,8 @@ eal_mp_socket_path(void)
 #define FBARRAY_NAME_FMT "%s/fbarray_%s"
 static inline const char *
 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
-	snprintf(buffer, buflen, FBARRAY_NAME_FMT, eal_get_runtime_dir(), name);
+	snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(),
+			name);
 	return buffer;
 }
 
@@ -66,7 +67,7 @@ eal_hugepage_info_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_INFO_FNAME);
 	return buffer;
 }
@@ -78,7 +79,7 @@ eal_hugepage_data_path(void)
 {
 	static char buffer[PATH_MAX]; /* static so auto-zeroed */
 
-	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", eal_get_runtime_dir(),
+	snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
 			HUGEPAGE_DATA_FNAME);
 	return buffer;
 }
@@ -99,7 +100,7 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id
 static inline const char *
 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
 {
-	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, eal_get_runtime_dir(),
+	snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, rte_eal_get_runtime_dir(),
 			f_id);
 	buffer[buflen - 1] = '\0';
 	return buffer;
lib/librte_eal/common/include/rte_eal.h +9 -0
index 3ee897c..150ced7 100644
@@ -507,6 +507,15 @@ enum rte_iova_mode rte_eal_iova_mode(void);
 const char *
 rte_eal_mbuf_user_pool_ops(void);
 
+/**
+ * Get the runtime directory of DPDK
+ *
+ * @return
+ *  The runtime directory path of DPDK
+ */
+const char *
+rte_eal_get_runtime_dir(void);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_eal/linuxapp/eal/eal.c +1 -1
index 70ab032..b75dd01 100644
@@ -150,7 +150,7 @@ eal_create_runtime_dir(void)
 }
 
 const char *
-eal_get_runtime_dir(void)
+rte_eal_get_runtime_dir(void)
 {
 	return runtime_dir;
 }
lib/librte_eal/rte_eal_version.map +1 -0
index 12ace18..42bd367 100644
@@ -261,6 +261,7 @@ DPDK_18.08 {
 DPDK_18.11 {
 	global:
 
+	rte_eal_get_runtime_dir;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 	rte_strscpy;
Signature · 1 line
2.9.5
#171 lore raw

PATCH v8 3/13 telemetry: initial telemetry infrastructure

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

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.

---
 config/common_base                             |   5 +
 lib/Makefile                                   |   2 +
 lib/librte_telemetry/Makefile                  |  28 ++++++
 lib/librte_telemetry/meson.build               |   7 ++
 lib/librte_telemetry/rte_telemetry.c           | 123 +++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h           |  42 +++++++++
 lib/librte_telemetry/rte_telemetry_internal.h  |  32 +++++++
 lib/librte_telemetry/rte_telemetry_version.map |   8 ++
 lib/meson.build                                |   2 +-
 mk/rte.app.mk                                  |   1 +
 10 files changed, 249 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_telemetry/Makefile
 create mode 100644 lib/librte_telemetry/meson.build
 create mode 100644 lib/librte_telemetry/rte_telemetry.c
 create mode 100644 lib/librte_telemetry/rte_telemetry.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_internal.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_version.map
config/common_base +5 -0
index be7365e..d59141b 100644
@@ -753,6 +753,11 @@ CONFIG_RTE_LIBRTE_HASH=y
 CONFIG_RTE_LIBRTE_HASH_DEBUG=n
 
 #
+# Compile librte_telemetry
+#
+CONFIG_RTE_LIBRTE_TELEMETRY=n
+
+#
 # Compile librte_efd
 #
 CONFIG_RTE_LIBRTE_EFD=y
lib/Makefile +2 -0
index 8c83942..2b446c6 100644
@@ -105,6 +105,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
lib/librte_telemetry/Makefile new file +28 -0
new file mode 100644
index 0000000..0d61361
@@ -0,0 +1,28 @@
+# 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
+LDLIBS += -ljansson
+
+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
lib/librte_telemetry/meson.build new file +7 -0
new file mode 100644
index 0000000..7716076
@@ -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'
lib/librte_telemetry/rte_telemetry.c new file +123 -0

123 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h new file +42 -0

42 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_internal.h new file +32 -0
new file mode 100644
index 0000000..4e810a8
@@ -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
lib/librte_telemetry/rte_telemetry_version.map new file +8 -0
new file mode 100644
index 0000000..bbcd9a7
@@ -0,0 +1,8 @@
+EXPERIMENTAL {
+	global:
+
+	rte_telemetry_cleanup;
+	rte_telemetry_init;
+
+	local: *;
+};
lib/meson.build +1 -1
index 24351cc..90a4227 100644
@@ -24,7 +24,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')
mk/rte.app.mk +1 -0
index 3203cf0..a5ce715 100644
@@ -80,6 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#172 lore raw

Re: [PATCH v8 03/13] telemetry: initial telemetry infrastructure

We forgot to add rte_telemetry.h in doxygen:
doc/api/doxy-api-index.md
doc/api/doxy-api.conf.in

We need a section @file at the top of the header file to make it appear in doxygen.

24/10/2018 18:03, Kevin Laatz:

Quoted 45 lines
lib/librte_telemetry/rte_telemetry.h new file +42 -0
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdint.h>
+
+#ifndef _RTE_TELEMETRY_H_
+#define _RTE_TELEMETRY_H_
+
+/**
+ * @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
#173 lore raw

PATCH v8 4/13 telemetry: add initial connection socket

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the telemetry UNIX socket. It is used to allow connections from external clients.

On the initial connection from a client, ethdev stats are registered in the metrics library, to allow for their retrieval at a later stage.

---
 lib/librte_telemetry/rte_telemetry.c          | 225 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 2 files changed, 229 insertions(+)
lib/librte_telemetry/rte_telemetry.c +225 -0
index 7f4ad03..e9b3330 100644
@@ -3,23 +3,163 @@
  */
 
 #include <unistd.h>
+#include <fcntl.h>
 #include <pthread.h>
+#include <sys/socket.h>
+#include <sys/un.h>
 
 #include <rte_eal.h>
 #include <rte_ethdev.h>
 #include <rte_metrics.h>
 #include <rte_option.h>
+#include <rte_string_fns.h>
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
 
+#define BUF_SIZE 1024
 #define SLEEP_TIME 10
 
 static telemetry_impl *static_telemetry;
 
+static void
+rte_telemetry_get_runtime_dir(char *socket_path, size_t size)
+{
+	snprintf(socket_path, size, "%s/telemetry", rte_eal_get_runtime_dir());
+}
+
+int32_t
+rte_telemetry_is_port_active(int port_id)
+{
+	int ret;
+
+	ret = rte_eth_find_next(port_id);
+	if (ret == port_id)
+		return 1;
+
+	TELEMETRY_LOG_ERR("port_id: %d is invalid, not active",
+		port_id);
+	return 0;
+}
+
+static int32_t
+rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
+{
+	int ret, num_xstats, ret_val, i;
+	struct rte_eth_xstat *eth_xstats = NULL;
+	struct rte_eth_xstat_name *eth_xstats_names = NULL;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		return -EINVAL;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d",
+				port_id, num_xstats);
+		return -EPERM;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		return -ENOMEM;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	const char *xstats_names[num_xstats];
+	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	if (eth_xstats_names == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats_names");
+		ret_val = -ENOMEM;
+		goto free_xstats;
+	}
+
+	ret = rte_eth_xstats_get_names(port_id, eth_xstats_names, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get_names(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret_val = -EPERM;
+		goto free_xstats;
+	}
+
+	for (i = 0; i < num_xstats; i++)
+		xstats_names[i] = eth_xstats_names[eth_xstats[i].id].name;
+
+	ret_val = rte_metrics_reg_names(xstats_names, num_xstats);
+	if (ret_val < 0) {
+		TELEMETRY_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
+		ret_val = -1;
+		goto free_xstats;
+	}
+
+	goto free_xstats;
+
+free_xstats:
+	free(eth_xstats);
+	free(eth_xstats_names);
+	return ret_val;
+}
+
+static int32_t
+rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
+{
+	uint16_t pid;
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		telemetry->reg_index =
+			rte_telemetry_reg_ethdev_to_metrics(pid);
+		break;
+	}
+
+	if (telemetry->reg_index < 0) {
+		TELEMETRY_LOG_ERR("Failed to register ethdev metrics");
+		return -1;
+	}
+
+	telemetry->metrics_register_done = 1;
+
+	return 0;
+}
+
+static int32_t
+rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
+{
+	int ret;
+
+	if (telemetry->accept_fd <= 0) {
+		ret = listen(telemetry->server_fd, 1);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Listening error with server fd");
+			return -1;
+		}
+		telemetry->accept_fd = accept(telemetry->server_fd, NULL, NULL);
+
+		if (telemetry->accept_fd >= 0 &&
+			telemetry->metrics_register_done == 0) {
+			ret = rte_telemetry_initial_accept(telemetry);
+			if (ret < 0) {
+				TELEMETRY_LOG_ERR("Failed to run initial configurations/tests");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int32_t
 rte_telemetry_run(void *userdata)
 {
+	int ret;
 	struct telemetry_impl *telemetry = userdata;
 
 	if (telemetry == NULL) {
@@ -27,6 +167,12 @@ rte_telemetry_run(void *userdata)
 		return -1;
 	}
 
+	ret = rte_telemetry_accept_new_client(telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Accept and read new client failed");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -50,6 +196,67 @@ static void
 	pthread_exit(0);
 }
 
+static int32_t
+rte_telemetry_set_socket_nonblock(int fd)
+{
+	int flags;
+
+	if (fd < 0) {
+		TELEMETRY_LOG_ERR("Invalid fd provided");
+		return -1;
+	}
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0)
+		flags = 0;
+
+	return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+}
+
+static int32_t
+rte_telemetry_create_socket(struct telemetry_impl *telemetry)
+{
+	int ret;
+	struct sockaddr_un addr;
+	char socket_path[BUF_SIZE];
+
+	if (telemetry == NULL)
+		return -1;
+
+	telemetry->server_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (telemetry->server_fd == -1) {
+		TELEMETRY_LOG_ERR("Failed to open socket");
+		return -1;
+	}
+
+	ret  = rte_telemetry_set_socket_nonblock(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not set socket to NONBLOCK");
+		goto close_socket;
+	}
+
+	addr.sun_family = AF_UNIX;
+	rte_telemetry_get_runtime_dir(socket_path, sizeof(socket_path));
+	strlcpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
+	unlink(socket_path);
+
+	if (bind(telemetry->server_fd, (struct sockaddr *)&addr,
+		sizeof(addr)) < 0) {
+		TELEMETRY_LOG_ERR("Socket binding error");
+		goto close_socket;
+	}
+
+	return 0;
+
+close_socket:
+	if (close(telemetry->server_fd) < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		return -EPERM;
+	}
+
+	return -1;
+}
+
 int32_t __rte_experimental
 rte_telemetry_init()
 {
@@ -77,6 +284,14 @@ rte_telemetry_init()
 		return -EPERM;
 	}
 
+	ret = rte_telemetry_create_socket(static_telemetry);
+	if (ret < 0) {
+		ret = rte_telemetry_cleanup();
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("TELEMETRY cleanup failed");
+		return -EPERM;
+	}
+
 	ret = rte_ctrl_thread_create(&static_telemetry->thread_id,
 		telemetry_ctrl_thread, &attr, rte_telemetry_run_thread_func,
 		(void *)static_telemetry);
@@ -95,11 +310,21 @@ rte_telemetry_init()
 int32_t __rte_experimental
 rte_telemetry_cleanup(void)
 {
+	int ret;
 	struct telemetry_impl *telemetry = static_telemetry;
+
+	ret = close(telemetry->server_fd);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Close TELEMETRY socket failed");
+		free(telemetry);
+		return -EPERM;
+	}
+
 	telemetry->thread_status = 0;
 	pthread_join(telemetry->thread_id, NULL);
 	free(telemetry);
 	static_telemetry = NULL;
+
 	return 0;
 }
 
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 4e810a8..569d56a 100644
@@ -24,9 +24,13 @@ extern int telemetry_log_level;
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
 typedef struct telemetry_impl {
+	int accept_fd;
+	int server_fd;
 	pthread_t thread_id;
 	int thread_status;
 	uint32_t socket_id;
+	int reg_index;
+	int metrics_register_done;
 } telemetry_impl;
 
 #endif
Signature · 1 line
2.9.5
#174 lore raw

PATCH v8 5/13 telemetry: add client feature and sockets

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch introduces clients to the telemetry API.

When a client makes a connection through the initial telemetry socket, they can send a message through the socket to be parsed. Register messages are expected through this socket, to enable clients to register and have a client socket setup for future communications.

A TAILQ is used to store all clients information. Using this, the client sockets are polled for messages, which will later be parsed and dealt with accordingly.

Functionality that make use of the client sockets were introduced in this patch also, such as writing to client sockets, and sending error responses.

---
 lib/librte_telemetry/meson.build              |   2 +
 lib/librte_telemetry/rte_telemetry.c          | 370 +++++++++++++++++++++++++-
 lib/librte_telemetry/rte_telemetry_internal.h |  25 ++
 mk/rte.app.mk                                 |   2 +-
 4 files changed, 395 insertions(+), 4 deletions(-)
lib/librte_telemetry/meson.build +2 -0
index 7716076..0ccfa36 100644
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson
lib/librte_telemetry/rte_telemetry.c +367 -3

442 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_internal.h +25 -0
index 569d56a..e3292cf 100644
@@ -3,6 +3,7 @@
  */
 
 #include <rte_log.h>
+#include <rte_tailq.h>
 
 #ifndef _RTE_TELEMETRY_INTERNAL_H_
 #define _RTE_TELEMETRY_INTERNAL_H_
@@ -23,6 +24,12 @@ extern int telemetry_log_level;
 #define TELEMETRY_LOG_INFO(fmt, args...) \
 	TELEMETRY_LOG(INFO, fmt, ## args)
 
+typedef struct telemetry_client {
+	char *file_path;
+	int fd;
+	TAILQ_ENTRY(telemetry_client) client_list;
+} telemetry_client;
+
 typedef struct telemetry_impl {
 	int accept_fd;
 	int server_fd;
@@ -31,6 +38,24 @@ typedef struct telemetry_impl {
 	uint32_t socket_id;
 	int reg_index;
 	int metrics_register_done;
+	TAILQ_HEAD(, telemetry_client) client_list_head;
+	struct telemetry_client *request_client;
+	int register_fail_count;
 } telemetry_impl;
 
+int32_t
+rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
+
+int32_t
+rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
+	int error_type);
+
+int32_t
+rte_telemetry_register_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
+int32_t
+rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
+	const char *client_path);
+
 #endif
mk/rte.app.mk +1 -1
index a5ce715..620059c 100644
@@ -80,7 +80,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_SECURITY)       += -lrte_security
 _LDLIBS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV)    += -lrte_compressdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RAWDEV)         += -lrte_rawdev
-_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry
+_LDLIBS-$(CONFIG_RTE_LIBRTE_TELEMETRY)      += -lrte_telemetry -ljansson
 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING)   += -lrte_mempool_ring
Signature · 1 line
2.9.5
#175 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

24/10/2018 18:03, Kevin Laatz:

lib/librte_telemetry/meson.build sources = files('rte_telemetry.c') · line 9

Quoted 8 lines
lib/librte_telemetry/meson.build +2 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
cannot find -ljansson

I am worried because it is a real blocker.

#176 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

25/10/2018 22:29, Thomas Monjalon:

Quoted 13 lines

24/10/2018 18:03, Kevin Laatz:

lib/librte_telemetry/meson.build sources = files('rte_telemetry.c') · line 9

Quoted 8 lines
lib/librte_telemetry/meson.build +2 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

Quoted 4 lines

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
cannot find -ljansson

I am worried because it is a real blocker.

The dependency must be optional.
Should we disable the library if jansson is not found?

#177 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

Quoted 14 lines · Thomas Monjalon

25/10/2018 22:29, Thomas Monjalon:

Quoted 13 lines

24/10/2018 18:03, Kevin Laatz:

lib/librte_telemetry/meson.build sources = files('rte_telemetry.c') · line 9

Quoted 8 lines
lib/librte_telemetry/meson.build +2 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

Quoted 8 lines
Quoted 4 lines

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
cannot find -ljansson

I am worried because it is a real blocker.

The dependency must be optional.
Should we disable the library if jansson is not found?

Yes, it should be.

Needs:

jansson = cc.find_library('jansson', required: false) build = jansson.found()

/Bruce

#178 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

25/10/2018 22:44, Bruce Richardson:

Quoted 23 lines · Thomas Monjalon
Quoted 14 lines

25/10/2018 22:29, Thomas Monjalon:

Quoted 13 lines

24/10/2018 18:03, Kevin Laatz:

lib/librte_telemetry/meson.build sources = files('rte_telemetry.c') · line 9

Quoted 8 lines
lib/librte_telemetry/meson.build +2 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')
 headers = files('rte_telemetry.h', 'rte_telemetry_internal.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
+jansson = cc.find_library('jansson', required: true)
+ext_deps += jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

Quoted 8 lines
Quoted 4 lines

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-gnu/bin/ld:
cannot find -ljansson

I am worried because it is a real blocker.

The dependency must be optional.
Should we disable the library if jansson is not found?

Quoted 6 lines

Yes, it should be.

Needs:

jansson = cc.find_library('jansson', required: false) build = jansson.found()

And for the makefile?

It has been introduced (too early) in patch 3:

	LDLIBS += -ljansson

I think we must use pkg-config to check if jansson is found.

#179 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

Quoted 42 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, October 25, 2018 9:50 PM
To: Richardson, Bruce <[email protected]>
Cc: Laatz, Kevin <[email protected]>; [email protected]; Van Haaren, Harry <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Ciara Power <[email protected]>; Brian Archbold <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 05/13] telemetry: add client feature and sockets

25/10/2018 22:44, Bruce Richardson:

Quoted 14 lines · Thomas Monjalon
Quoted 13 lines

25/10/2018 22:29, Thomas Monjalon:

Quoted 12 lines

24/10/2018 18:03, Kevin Laatz:

Quoted 7 lines
lib/librte_telemetry/meson.build +0 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')  headers =

files('rte_telemetry.h', 'rte_telemetry_internal.h') deps += ['metrics', 'ethdev'] cflags += '-DALLOW_EXPERIMENTAL_API' +jansson = cc.find_library('jansson', required: true) ext_deps ++= jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

Quoted 1 line
Quoted 1 line
Quoted 1 line

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-

gnu/bin/ld:

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

cannot find -ljansson

I am worried because it is a real blocker.

The dependency must be optional.
Should we disable the library if jansson is not found?

Yes, it should be.

Needs:

Quoted 9 lines
Quoted 2 lines

jansson = cc.find_library('jansson', required: false) build = jansson.found()

And for the makefile?

It has been introduced (too early) in patch 3:

	LDLIBS += -ljansson

I think we must use pkg-config to check if jansson is found.

I didn't look at the makefile, because you never asked! :-)

#180 lore raw

Re: [PATCH v8 05/13] telemetry: add client feature and sockets

25/10/2018 23:16, Richardson, Bruce:

Quoted 32 lines

From: Thomas Monjalon [mailto:[email protected]]

Quoted 31 lines

25/10/2018 22:44, Bruce Richardson:

Quoted 14 lines · Thomas Monjalon
Quoted 13 lines

25/10/2018 22:29, Thomas Monjalon:

Quoted 12 lines

24/10/2018 18:03, Kevin Laatz:

Quoted 7 lines
lib/librte_telemetry/meson.build +0 -0
@@ -5,3 +5,5 @@ sources = files('rte_telemetry.c')  headers =

files('rte_telemetry.h', 'rte_telemetry_internal.h') deps += ['metrics', 'ethdev'] cflags += '-DALLOW_EXPERIMENTAL_API' +jansson = cc.find_library('jansson', required: true) ext_deps ++= jansson

I just discovered an issue when trying to compile for arm64 (with devtools/test-meson-builds.sh):

Quoted 1 line
Quoted 1 line
Quoted 1 line

/usr/lib/gcc/aarch64-linux-gnu/8.2.0/../../../../aarch64-linux-

gnu/bin/ld:

Quoted 13 lines
Quoted 7 lines
Quoted 3 lines

cannot find -ljansson

I am worried because it is a real blocker.

The dependency must be optional.
Should we disable the library if jansson is not found?

Yes, it should be.

Needs:

jansson = cc.find_library('jansson', required: false) build = jansson.found()

Quoted 7 lines
Quoted 5 lines

And for the makefile?

It has been introduced (too early) in patch 3:

	LDLIBS += -ljansson

I think we must use pkg-config to check if jansson is found.

I didn't look at the makefile, because you never asked! :-)

The code is already written in examples/power:

	https://patches.dpdk.org/patch/46984/
#181 lore raw

PATCH v8 6/13 telemetry: add parser for client socket messages

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds the parser file. This is used to parse any messages that are received on any of the client sockets.

Currently, the unregister functionality works using the parser. Functionality relating to getting statistic values for certain ports will be added in a subsequent patch, however the parsing involved for that command is added in this patch.

Some of the parser code included is in preparation for future functionality, that is not implemented yet in this patchset.

---
 lib/librte_telemetry/Makefile                 |   1 +
 lib/librte_telemetry/meson.build              |   4 +-
 lib/librte_telemetry/rte_telemetry.c          |   8 +
 lib/librte_telemetry/rte_telemetry_internal.h |  13 +
 lib/librte_telemetry/rte_telemetry_parser.c   | 569 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser.h   |  13 +
 6 files changed, 606 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser.h
lib/librte_telemetry/Makefile +1 -0
index 0d61361..95c7296 100644
@@ -21,6 +21,7 @@ LIBABIVER := 1
 
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 0ccfa36..7450f96 100644
@@ -1,8 +1,8 @@
 # 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')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +8 -0
index 3c8b922..cac7884 100644
@@ -17,6 +17,7 @@
 
 #include "rte_telemetry.h"
 #include "rte_telemetry_internal.h"
+#include "rte_telemetry_parser.h"
 
 #define BUF_SIZE 1024
 #define ACTION_POST 1
@@ -283,6 +284,7 @@ rte_telemetry_accept_new_client(struct telemetry_impl *telemetry)
 static int32_t
 rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 {
+	int ret;
 	telemetry_client *client;
 	char client_buf[BUF_SIZE];
 	int bytes;
@@ -293,6 +295,12 @@ rte_telemetry_read_client_sockets(struct telemetry_impl *telemetry)
 		if (bytes > 0) {
 			client_buf[bytes] = '\0';
 			telemetry->request_client = client;
+			ret = rte_telemetry_parse(telemetry, client_buf);
+			if (ret < 0) {
+				TELEMETRY_LOG_WARN("Parse socket input failed: %i",
+						ret);
+				return -1;
+			}
 		}
 	}
 
lib/librte_telemetry/rte_telemetry_internal.h +13 -0
index e3292cf..86a5ba1 100644
@@ -43,6 +43,11 @@ typedef struct telemetry_impl {
 	int register_fail_count;
 } telemetry_impl;
 
+enum rte_telemetry_parser_actions {
+	ACTION_GET = 0,
+	ACTION_DELETE = 2
+};
+
 int32_t
 rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
 
@@ -58,4 +63,12 @@ int32_t
 rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 	const char *client_path);
 
+/**
+ * This is a wrapper for the ethdev api rte_eth_find_next().
+ * If rte_eth_find_next() returns the same port id that we passed it,
+ * then we know that that port is active.
+ */
+int32_t
+rte_telemetry_is_port_active(int port_id);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c new file +569 -0

569 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser.h new file +13 -0
new file mode 100644
index 0000000..63e633d
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_PARSER_H_
+#define _RTE_TELEMETRY_PARSER_H_
+
+int32_t
+rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);
+
+#endif
Signature · 1 line
2.9.5
#182 lore raw

PATCH v8 7/13 telemetry: update metrics before sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to update the statistics in the metrics library with values from the ethdev stats.

Values need to be updated before they are encoded into a JSON message and sent to the client that requested them. The JSON encoding will be added in a subsequent patch.

---
 lib/librte_telemetry/rte_telemetry.c          | 134 ++++++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_internal.h |   4 +
 lib/librte_telemetry/rte_telemetry_parser.c   |  17 ++++
 3 files changed, 155 insertions(+)
lib/librte_telemetry/rte_telemetry.c +134 -0
index cac7884..7616e7c 100644
@@ -46,6 +46,78 @@ rte_telemetry_is_port_active(int port_id)
 	return 0;
 }
 
+static int32_t
+rte_telemetry_update_metrics_ethdev(struct telemetry_impl *telemetry,
+	uint16_t port_id, int reg_start_index)
+{
+	int ret, num_xstats, i;
+	struct rte_eth_xstat *eth_xstats;
+
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		TELEMETRY_LOG_ERR("port_id: %d is invalid", port_id);
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_telemetry_is_port_active(port_id);
+	if (ret < 1) {
+		ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	num_xstats = rte_eth_xstats_get(port_id, NULL, 0);
+	if (num_xstats < 0) {
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) failed: %d", port_id,
+				num_xstats);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	eth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);
+	if (eth_xstats == NULL) {
+		TELEMETRY_LOG_ERR("Failed to malloc memory for xstats");
+		ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);
+	if (ret < 0 || ret > num_xstats) {
+		free(eth_xstats);
+		TELEMETRY_LOG_ERR("rte_eth_xstats_get(%u) len%i failed: %d",
+				port_id, num_xstats, ret);
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	uint64_t xstats_values[num_xstats];
+	for (i = 0; i < num_xstats; i++)
+		xstats_values[i] = eth_xstats[i].value;
+
+	ret = rte_metrics_update_values(port_id, reg_start_index, xstats_values,
+			num_xstats);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not update metrics values");
+		ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+		if (ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		free(eth_xstats);
+		return -1;
+	}
+
+	free(eth_xstats);
+	return 0;
+}
+
 int32_t
 rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,
 	const char *json_string)
@@ -130,6 +202,68 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
+{
+	int ret, i;
+	char *json_buffer = NULL;
+
+	if (telemetry == NULL) {
+		TELEMETRY_LOG_ERR("Invalid telemetry argument");
+		return -1;
+	}
+
+	if (metric_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid metric_ids array");
+		goto einval_fail;
+	}
+
+	if (num_metric_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_metric_ids, must be positive");
+		goto einval_fail;
+	}
+
+	if (port_ids == NULL) {
+		TELEMETRY_LOG_ERR("Invalid port_ids array");
+		goto einval_fail;
+	}
+
+	if (num_port_ids < 0) {
+		TELEMETRY_LOG_ERR("Invalid num_port_ids, must be positive");
+		goto einval_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+
+		ret = rte_telemetry_update_metrics_ethdev(telemetry,
+			port_ids[i], telemetry->reg_index);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
+			return -1;
+		}
+	}
+
+	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Could not write to socket");
+		return -1;
+	}
+
+	return 0;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+
 static int32_t
 rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)
 {
lib/librte_telemetry/rte_telemetry_internal.h +4 -0
index 86a5ba1..0082cb2 100644
@@ -71,4 +71,8 @@ rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
 int32_t
 rte_telemetry_is_port_active(int port_id);
 
+int32_t
+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
+	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser.c +17 -0
index 6bc4c6d..084c160 100644
@@ -258,6 +258,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	int ret, num_metrics, i, p;
 	struct rte_metric_name *names;
 	uint64_t num_port_ids = 0;
+	uint32_t port_ids[RTE_MAX_ETHPORTS];
 
 	if (telemetry == NULL) {
 		TELEMETRY_LOG_ERR("Invalid telemetry argument");
@@ -313,6 +314,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 	uint32_t stat_ids[num_metrics];
 
 	RTE_ETH_FOREACH_DEV(p) {
+		port_ids[num_port_ids] = p;
 		num_port_ids++;
 	}
 
@@ -337,6 +339,13 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
 		goto fail;
 	}
 
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_metrics,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		goto fail;
+	}
+
 	return 0;
 
 fail:
@@ -428,6 +437,14 @@ rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl
 		TELEMETRY_LOG_ERR("Could not convert stat names to IDs");
 		return -1;
 	}
+
+	ret = rte_telemetry_send_ports_stats_values(stat_ids, num_stat_names,
+		port_ids, num_port_ids, telemetry);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Sending ports stats values failed");
+		return -1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.9.5
#183 lore raw

PATCH v8 8/13 telemetry: format json response when sending stats

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to create a JSON message in order to send it to a client socket.

When stats are requested by a client, they are retrieved from the metrics library and encoded in JSON format.

---
 lib/librte_telemetry/rte_telemetry.c | 309 ++++++++++++++++++++++++++++++++++-
 1 file changed, 307 insertions(+), 2 deletions(-)
lib/librte_telemetry/rte_telemetry.c +307 -2
index 7616e7c..36cd748 100644
@@ -190,7 +190,7 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 		return -EPERM;
 	}
 
-	json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_buffer = json_dumps(root, 0);
 	json_decref(root);
 
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
@@ -202,6 +202,304 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
 	return 0;
 }
 
+static int
+rte_telemetry_get_metrics(struct telemetry_impl *telemetry, uint32_t port_id,
+	struct rte_metric_value *metrics, struct rte_metric_name *names,
+	int num_metrics)
+{
+	int ret, num_values;
+
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Invalid metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	if (metrics == NULL) {
+		TELEMETRY_LOG_ERR("Metrics must be initialised.");
+		goto einval_fail;
+	}
+
+	if (names == NULL) {
+		TELEMETRY_LOG_ERR("Names must be initialised.");
+		goto einval_fail;
+	}
+
+	ret = rte_metrics_get_names(names, num_metrics);
+	if (ret < 0 || ret > num_metrics) {
+		TELEMETRY_LOG_ERR("Cannot get metrics names");
+		goto eperm_fail;
+	}
+
+	num_values = rte_metrics_get_values(port_id, NULL, 0);
+	ret = rte_metrics_get_values(port_id, metrics, num_values);
+	if (ret < 0 || ret > num_values) {
+		TELEMETRY_LOG_ERR("Cannot get metrics values");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_stat(struct telemetry_impl *telemetry, json_t *stats,
+	const char *metric_name, uint64_t metric_value)
+{
+	int ret;
+	json_t *stat = json_object();
+
+	if (stat == NULL) {
+		TELEMETRY_LOG_ERR("Could not create stat JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "name", json_string(metric_name));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Name field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(stat, "value", json_integer(metric_value));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat Value field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(stats, stat);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stat cannot be added to stats json array");
+		goto eperm_fail;
+	}
+
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+}
+
+static int32_t
+rte_telemetry_json_format_port(struct telemetry_impl *telemetry,
+	uint32_t port_id, json_t *ports, uint32_t *metric_ids,
+	uint32_t num_metric_ids)
+{
+	struct rte_metric_value *metrics = 0;
+	struct rte_metric_name *names = 0;
+	int num_metrics, ret, err_ret;
+	json_t *port, *stats;
+	uint32_t i;
+
+	num_metrics = rte_metrics_get_names(NULL, 0);
+	if (num_metrics < 0) {
+		TELEMETRY_LOG_ERR("Cannot get metrics count");
+		goto einval_fail;
+	} else if (num_metrics == 0) {
+		TELEMETRY_LOG_ERR("No metrics to display (none have been registered)");
+		goto eperm_fail;
+	}
+
+	metrics = malloc(sizeof(struct rte_metric_value) * num_metrics);
+	names = malloc(sizeof(struct rte_metric_name) * num_metrics);
+	if (metrics == NULL || names == NULL) {
+		TELEMETRY_LOG_ERR("Cannot allocate memory");
+		free(metrics);
+		free(names);
+
+		err_ret = rte_telemetry_send_error_response(telemetry, -ENOMEM);
+		if (err_ret < 0)
+			TELEMETRY_LOG_ERR("Could not send error");
+		return -1;
+	}
+
+	ret  = rte_telemetry_get_metrics(telemetry, port_id, metrics, names,
+		num_metrics);
+	if (ret < 0) {
+		free(metrics);
+		free(names);
+		TELEMETRY_LOG_ERR("rte_telemetry_get_metrics failed");
+		return -1;
+	}
+
+	port = json_object();
+	stats = json_array();
+	if (port == NULL || stats == NULL) {
+		TELEMETRY_LOG_ERR("Could not create port/stats JSON objects");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(port, "port", json_integer(port_id));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port field cannot be set");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_metric_ids; i++) {
+		int metric_id = metric_ids[i];
+		int metric_index = -1;
+		int metric_name_key = -1;
+		int32_t j;
+		uint64_t metric_value;
+
+		if (metric_id >= num_metrics) {
+			TELEMETRY_LOG_ERR("Metric_id: %d is not valid",
+					metric_id);
+			goto einval_fail;
+		}
+
+		for (j = 0; j < num_metrics; j++) {
+			if (metrics[j].key == metric_id) {
+				metric_name_key = metrics[j].key;
+				metric_index = j;
+				break;
+			}
+		}
+
+		const char *metric_name = names[metric_name_key].name;
+		metric_value = metrics[metric_index].value;
+
+		if (metric_name_key < 0 || metric_index < 0) {
+			TELEMETRY_LOG_ERR("Could not get metric name/index");
+			goto eperm_fail;
+		}
+
+		ret = rte_telemetry_json_format_stat(telemetry, stats,
+			metric_name, metric_value);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format stat with id: %u failed",
+					metric_id);
+			free(metrics);
+			free(names);
+			return -1;
+		}
+	}
+
+	if (json_array_size(stats) == 0)
+		ret = json_object_set_new(port, "stats", json_null());
+	else
+		ret = json_object_set_new(port, "stats", stats);
+
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Stats object cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_array_append_new(ports, port);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Port object cannot be added to ports array");
+		goto eperm_fail;
+	}
+
+	free(metrics);
+	free(names);
+	return 0;
+
+eperm_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	free(metrics);
+	free(names);
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
+static int32_t
+rte_telemetry_encode_json_format(struct telemetry_impl *telemetry,
+	uint32_t *port_ids, uint32_t num_port_ids, uint32_t *metric_ids,
+	uint32_t num_metric_ids, char **json_buffer)
+{
+	int ret;
+	json_t *root, *ports;
+	uint32_t i;
+
+	if (num_port_ids <= 0 || num_metric_ids <= 0) {
+		TELEMETRY_LOG_ERR("Please provide port and metric ids to query");
+		goto einval_fail;
+	}
+
+	ports = json_array();
+	if (ports == NULL) {
+		TELEMETRY_LOG_ERR("Could not create ports JSON array");
+		goto eperm_fail;
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		if (!rte_eth_dev_is_valid_port(port_ids[i])) {
+			TELEMETRY_LOG_ERR("Port: %d invalid", port_ids[i]);
+			goto einval_fail;
+		}
+	}
+
+	for (i = 0; i < num_port_ids; i++) {
+		ret = rte_telemetry_json_format_port(telemetry, port_ids[i],
+			ports, metric_ids, num_metric_ids);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Format port in JSON failed");
+			return -1;
+		}
+	}
+
+	root = json_object();
+	if (root == NULL) {
+		TELEMETRY_LOG_ERR("Could not create root JSON object");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "status_code",
+		json_string("Status OK: 200"));
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Status code field cannot be set");
+		goto eperm_fail;
+	}
+
+	ret = json_object_set_new(root, "data", ports);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("Data field cannot be set");
+		goto eperm_fail;
+	}
+
+	*json_buffer = json_dumps(root, JSON_INDENT(2));
+	json_decref(root);
+	return 0;
+
+eperm_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EPERM);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+
+einval_fail:
+	ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
+	if (ret < 0)
+		TELEMETRY_LOG_ERR("Could not send error");
+	return -1;
+}
+
 int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)
@@ -241,13 +539,20 @@ rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 		}
 
 		ret = rte_telemetry_update_metrics_ethdev(telemetry,
-			port_ids[i], telemetry->reg_index);
+				port_ids[i], telemetry->reg_index);
 		if (ret < 0) {
 			TELEMETRY_LOG_ERR("Failed to update ethdev metrics");
 			return -1;
 		}
 	}
 
+	ret = rte_telemetry_encode_json_format(telemetry, port_ids,
+		num_port_ids, metric_ids, num_metric_ids, &json_buffer);
+	if (ret < 0) {
+		TELEMETRY_LOG_ERR("JSON encode function failed");
+		return -1;
+	}
+
 	ret = rte_telemetry_write_to_socket(telemetry, json_buffer);
 	if (ret < 0) {
 		TELEMETRY_LOG_ERR("Could not write to socket");
Signature · 1 line
2.9.5
#184 lore raw

PATCH v8 9/13 telemetry: add tests for telemetry api

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all tests for the Telemetry API. The tests added include a parser test, selftest, and socket messaging tests.

The parser tests pass valid and invalid messages to the parser to ensure the correct return values are received.
The selftest tests basic functions in the Telemetry API such as registering, unregistering, and initialisation.
The socket messaging tests pass messages through the socket and validates the return message, to ensure the Telemetry API is responding correctly.

---
 lib/librte_telemetry/Makefile                     |   1 +
 lib/librte_telemetry/meson.build                  |   4 +-
 lib/librte_telemetry/rte_telemetry.c              | 653 ++++++++++++++++++++++
 lib/librte_telemetry/rte_telemetry.h              |  15 +
 lib/librte_telemetry/rte_telemetry_internal.h     |   3 +
 lib/librte_telemetry/rte_telemetry_parser_test.c  | 534 ++++++++++++++++++
 lib/librte_telemetry/rte_telemetry_parser_test.h  |  39 ++
 lib/librte_telemetry/rte_telemetry_socket_tests.h |  36 ++
 lib/librte_telemetry/rte_telemetry_version.map    |   1 +
 9 files changed, 1284 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.c
 create mode 100644 lib/librte_telemetry/rte_telemetry_parser_test.h
 create mode 100644 lib/librte_telemetry/rte_telemetry_socket_tests.h
lib/librte_telemetry/Makefile +1 -0
index 95c7296..1a05069 100644
@@ -22,6 +22,7 @@ LIBABIVER := 1
 # library source files
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
 SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
 
 # export include files
 SYMLINK-$(CONFIG_RTE_LIBRTE_TELEMETRY)-include := rte_telemetry.h
lib/librte_telemetry/meson.build +2 -2
index 7450f96..57dd83d 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
-sources = files('rte_telemetry.c', 'rte_telemetry_parser.c')
-headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
+sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c')
+headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h', 'rte_telemetry_parser_test.h')
 deps += ['metrics', 'ethdev']
 cflags += '-DALLOW_EXPERIMENTAL_API'
 jansson = cc.find_library('jansson', required: true)
lib/librte_telemetry/rte_telemetry.c +653 -0

684 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry.h +15 -0
index 1e8dce6..807bd9f 100644
@@ -39,4 +39,19 @@ rte_telemetry_init(void);
 int32_t __rte_experimental
 rte_telemetry_cleanup(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Runs various tests to ensure telemetry initialisation and register/unregister
+ * functions are working correctly.
+ *
+ * @return
+ *  0 on success when all tests have passed
+ * @return
+ *  -1 on failure when the test has failed
+ */
+int32_t __rte_experimental
+rte_telemetry_selftest(void);
+
 #endif
lib/librte_telemetry/rte_telemetry_internal.h +3 -0
index 0082cb2..de7afda 100644
@@ -75,4 +75,7 @@ int32_t
 rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,
 	uint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);
 
+int32_t
+rte_telemetry_socket_messaging_testing(int index, int socket);
+
 #endif
lib/librte_telemetry/rte_telemetry_parser_test.c new file +534 -0

534 lines not on this page · raw message

lib/librte_telemetry/rte_telemetry_parser_test.h new file +39 -0
new file mode 100644
index 0000000..6ada852
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_TELEMETRY_PARSER_TEST_H_
+#define _RTE_TELEMETRY_PARSER_TEST_H_
+
+int32_t
+rte_telemetry_parser_test(struct telemetry_impl *telemetry);
+
+int32_t
+rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, json_t **data);
+
+int32_t
+rte_telemetry_create_json_request(int action, char *command,
+	const char *client_path, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names, char **request,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
+	int action_choice, char *command_choice, int inv_choice);
+
+int32_t
+rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
+	int action_choice, int *port_ids, int num_port_ids, int inv_choice);
+
+int32_t
+rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
+	*telemetry, int action_choice, int *port_ids, int num_port_ids,
+	const char * const stat_names, int num_stat_names,
+	int inv_choice);
+
+int32_t
+rte_telemetry_send_unreg_request(int action_choice, const char *client_path,
+	int inv_choice);
+
+#endif
lib/librte_telemetry/rte_telemetry_socket_tests.h new file +36 -0
new file mode 100644
index 0000000..db9167c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <stdbool.h>
+
+#include "rte_telemetry_internal.h"
+
+#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
+#define _RTE_TELEMETRY_SOCKET_TESTING_H_
+
+int32_t
+rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
+	int fd);
+
+int32_t
+rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
+
+int32_t
+rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
+	int send_fd, int recv_fd);
+
+int32_t
+rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
+	int *recv_fd);
+
+#endif
lib/librte_telemetry/rte_telemetry_version.map +1 -0
index bbcd9a7..b5a8265 100644
@@ -3,6 +3,7 @@ EXPERIMENTAL {
 
 	rte_telemetry_cleanup;
 	rte_telemetry_init;
+	rte_telemetry_selftest;
 
 	local: *;
 };
Signature · 1 line
2.9.5
#185 lore raw

PATCH v8 10/13 telemetry: add ability to disable selftest

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds functionality to enable/disable the selftest.

This functionality will be extended in future to make the enabling/disabling more dynamic and remove this 'hardcoded' approach. We are temporarily using this approach due to the design changes (vdev vs eal) made to the library.

---
 lib/librte_telemetry/rte_telemetry.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
lib/librte_telemetry/rte_telemetry.c +13 -10
index 5b66b71..2e27491 100644
@@ -660,6 +660,7 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 {
 	uint16_t pid;
 	int ret;
+	int selftest = 0;
 
 	RTE_ETH_FOREACH_DEV(pid) {
 		telemetry->reg_index = rte_telemetry_reg_ethdev_to_metrics(pid);
@@ -672,18 +673,20 @@ rte_telemetry_initial_accept(struct telemetry_impl *telemetry)
 	}
 
 	telemetry->metrics_register_done = 1;
-	ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
-		telemetry->server_fd);
-	if (ret < 0)
-		return -1;
+	if (selftest) {
+		ret = rte_telemetry_socket_messaging_testing(telemetry->reg_index,
+				telemetry->server_fd);
+		if (ret < 0)
+			return -1;
 
-	ret = rte_telemetry_parser_test(telemetry);
-	if (ret < 0) {
-		TELEMETRY_LOG_ERR("Parser Tests Failed");
-		return -1;
-	}
+		ret = rte_telemetry_parser_test(telemetry);
+		if (ret < 0) {
+			TELEMETRY_LOG_ERR("Parser Tests Failed");
+			return -1;
+		}
 
-	TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+		TELEMETRY_LOG_INFO("Success - All Parser Tests Passed");
+	}
 
 	return 0;
 }
Signature · 1 line
2.9.5
#186 lore raw

PATCH v8 11/13 doc: add telemetry documentation

In reply to Kevin Laatz

From: Ciara Power <[email protected]>

This patch adds all documentation for telemetry.

A description on how to use the Telemetry API with a DPDK application is given in this document.

It also adds the MAINTAINERS file entry and a release notes update for telemetry.

---
 MAINTAINERS                            |  5 ++
 doc/guides/howto/index.rst             |  1 +
 doc/guides/howto/telemetry.rst         | 85 ++++++++++++++++++++++++++++++++++
 doc/guides/rel_notes/release_18_11.rst |  6 +++
 4 files changed, 97 insertions(+)
 create mode 100644 doc/guides/howto/telemetry.rst
MAINTAINERS +5 -0
index b220479..6b64c15 100644
@@ -1208,6 +1208,11 @@ F: test/bpf/
 F: test/test/test_bpf.c
 F: doc/guides/prog_guide/bpf_lib.rst
 
+Telemetry - EXPERIMENTAL
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst
 
 Test Applications
 -----------------
doc/guides/howto/index.rst +1 -0
index e13a090..a642a2b 100644
@@ -17,3 +17,4 @@ HowTo Guides
     virtio_user_for_container_networking
     virtio_user_as_exceptional_path
     packet_capture_framework
+    telemetry
doc/guides/howto/telemetry.rst new file +85 -0

85 lines not on this page · raw message

doc/guides/rel_notes/release_18_11.rst +6 -0
index 04f3745..e82c790 100644
@@ -189,6 +189,12 @@ New Features
   the specified port. The port must be stopped before the command call in order
   to reconfigure queues.
 
+* **Added Telemetry API.**
+
+  Added the telemetry API which allows applications to transparently expose
+  their telemetry via a UNIX socket in JSON. The JSON can be consumed by any
+  Service Assurance agent, such as CollectD.
+
 * **Add a new sample for vDPA**
 
   The vdpa sample application creates vhost-user sockets by using the
Signature · 1 line
2.9.5
#187 lore raw

Re: [PATCH v8 11/13] doc: add telemetry documentation

24/10/2018 18:03, Kevin Laatz:

MAINTAINERS F: test/bpf/ · line 1215

Quoted 7 lines
MAINTAINERS +5 -0
+Telemetry - EXPERIMENTAL
+M: Kevin Laatz <[email protected]>
+F: lib/librte_telemetry/
+F: usertools/dpdk-telemetry-client.py
+F: doc/guides/howto/telemetry.rst

It would be a bit better to introduce it in previous patches when files are created. I wanted to spread it in other patches myself, but I stopped when encountering a build issue (patch 5).