[RFC,6/6] examples/l3fwd-power: enable use of process-info
diff mbox series

Message ID 20191205173128.64543-7-ciara.power@intel.com
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • replace telemetry with process_info
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Power, Ciara Dec. 5, 2019, 5:31 p.m. UTC
The l3fwd-power example app now registers a stats command with
process_info, and provides a callback function to handle formatting the
power stats.

Using the process-info library in this app replaces the previous method
of making l3fwd-power stats available in the metrics library, for use
with telemetry.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 examples/l3fwd-power/main.c | 83 +++++++++++--------------------------
 1 file changed, 25 insertions(+), 58 deletions(-)

Patch
diff mbox series

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index d049d8a5d..939b3dd88 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -45,7 +45,7 @@ 
 #include <rte_power.h>
 #include <rte_spinlock.h>
 #include <rte_power_empty_poll.h>
-#include <rte_metrics.h>
+#include <rte_process_info.h>
 
 #include "perf_core.h"
 #include "main.h"
@@ -131,7 +131,7 @@ 
 #define EMPTY_POLL_MED_THRESHOLD 350000UL
 #define EMPTY_POLL_HGH_THRESHOLD 580000UL
 
-
+#define NUM_TELSTATS RTE_DIM(telstats_strings)
 
 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
@@ -154,11 +154,6 @@  volatile bool quit_signal;
 static struct  ep_params *ep_params;
 static struct  ep_policy policy;
 static long  ep_med_edpi, ep_hgh_edpi;
-/* timer to update telemetry every 500ms */
-static struct rte_timer telemetry_timer;
-
-/* stats index returned by metrics lib */
-int telstats_index;
 
 struct telstats_name {
 	char name[RTE_ETH_XSTATS_NAME_SIZE];
@@ -187,9 +182,6 @@  enum busy_rate {
 #define MIN_CYCLES  1500000ULL
 #define MAX_CYCLES 22000000ULL
 
-/* (500ms) */
-#define TELEMETRY_INTERVALS_PER_SEC 2
-
 static int parse_ptype; /**< Parse packet type using rx callback, and */
 			/**< disabled by default */
 
@@ -2087,17 +2079,21 @@  init_power_library(void)
 	}
 	return ret;
 }
-static void
-update_telemetry(__attribute__((unused)) struct rte_timer *tim,
-		__attribute__((unused)) void *arg)
+
+static int
+handle_app_stats(const char *cmd __rte_unused,
+		const char *params __rte_unused,
+		char *buffer, int buf_len)
 {
 	unsigned int lcore_id = rte_lcore_id();
 	struct lcore_conf *qconf;
 	uint64_t app_eps = 0, app_fps = 0, app_br = 0;
-	uint64_t values[3] = {0};
-	int ret;
+	uint64_t values[NUM_TELSTATS];
+	int ret, used = 0;
+	uint32_t i;
 	uint64_t count = 0;
 
+	used = strlcpy(buffer, "{", buf_len);
 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 		qconf = &lcore_conf[lcore_id];
 		if (qconf->n_rx_queue == 0)
@@ -2114,32 +2110,21 @@  update_telemetry(__attribute__((unused)) struct rte_timer *tim,
 		values[0] = app_eps/count;
 		values[1] = app_fps/count;
 		values[2] = app_br/count;
-	} else {
-		values[0] = 0;
-		values[1] = 0;
-		values[2] = 0;
+	} else
+		memset(values, 0, sizeof(uint64_t) * NUM_TELSTATS);
+
+	for (i = 0; i < NUM_TELSTATS; i++) {
+		ret = snprintf(buffer + used, buf_len - used, "\"%s\":%"PRIu64",",
+				telstats_strings[i].name, values[i]);
+		if (ret + used >= buf_len)
+			break;
+		used += ret;
 	}
 
-	ret = rte_metrics_update_values(RTE_METRICS_GLOBAL, telstats_index,
-					values, RTE_DIM(values));
-	if (ret < 0)
-		RTE_LOG(WARNING, POWER, "failed to update metrcis\n");
+	buffer[used - 1] = '}';
+	return used;
 }
-static void
-telemetry_setup_timer(void)
-{
-	int lcore_id = rte_lcore_id();
-	uint64_t hz = rte_get_timer_hz();
-	uint64_t ticks;
 
-	ticks = hz / TELEMETRY_INTERVALS_PER_SEC;
-	rte_timer_reset_sync(&telemetry_timer,
-			ticks,
-			PERIODICAL,
-			lcore_id,
-			update_telemetry,
-			NULL);
-}
 static void
 empty_poll_setup_timer(void)
 {
@@ -2176,8 +2161,6 @@  launch_timer(unsigned int lcore_id)
 
 	if (app_mode == APP_MODE_EMPTY_POLL)
 		empty_poll_setup_timer();
-	else
-		telemetry_setup_timer();
 
 	cycles_10ms = rte_get_timer_hz() / 100;
 
@@ -2196,7 +2179,6 @@  launch_timer(unsigned int lcore_id)
 	return 0;
 }
 
-
 int
 main(int argc, char **argv)
 {
@@ -2212,8 +2194,6 @@  main(int argc, char **argv)
 	uint32_t dev_rxq_num, dev_txq_num;
 	uint8_t nb_rx_queue, queue, socketid;
 	uint16_t portid;
-	uint8_t num_telstats = RTE_DIM(telstats_strings);
-	const char *ptr_strings[num_telstats];
 
 	/* catch SIGINT and restore cpufreq governor to ondemand */
 	signal(SIGINT, signal_exit_now);
@@ -2507,29 +2487,16 @@  main(int argc, char **argv)
 		rte_eal_mp_remote_launch(main_empty_poll_loop, NULL,
 				SKIP_MASTER);
 	} else {
-		unsigned int i;
-
-		/* Init metrics library */
-		rte_metrics_init(rte_socket_id());
-		/** Register stats with metrics library */
-		for (i = 0; i < num_telstats; i++)
-			ptr_strings[i] = telstats_strings[i].name;
-
-		ret = rte_metrics_reg_names(ptr_strings, num_telstats);
-		if (ret >= 0)
-			telstats_index = ret;
-		else
-			rte_exit(EXIT_FAILURE, "failed to register metrics names");
-
 		RTE_LCORE_FOREACH_SLAVE(lcore_id) {
 			rte_spinlock_init(&stats[lcore_id].telemetry_lock);
 		}
-		rte_timer_init(&telemetry_timer);
+		rte_process_info_register("/l3fwd-power:stats",
+				handle_app_stats);
 		rte_eal_mp_remote_launch(main_telemetry_loop, NULL,
 						SKIP_MASTER);
 	}
 
-	if (app_mode == APP_MODE_EMPTY_POLL || app_mode == APP_MODE_TELEMETRY)
+	if (app_mode == APP_MODE_EMPTY_POLL)
 		launch_timer(rte_lcore_id());
 
 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {