Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] shared/sec: move getter funcs for worker status
Date: Mon, 24 Jun 2019 15:21:49 +0900	[thread overview]
Message-ID: <20190624062149.22505-1-yasufum.o@gmail.com> (raw)

From: Yasufumi Ogawa <yasufum.o@gmail.com>

Following getter functinos for spp_vf and spp_mirror are defined in
shared directory and worker specific tasks are compiled by using
`#ifdef SPP_VF_MODULE` and `#ifdef SPP_MIRROR_MODULE` selectively.
  * get_forwarder_status()
  * get_classifier_status()
  * get_mirror_status()

However, it tends to be messed up because common and specific functions
are mixed up. It should be separated cleanly. This update is to fix the
issue by reorganizing them and remove ifdef switches.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/mirror/mir_cmd_runner.c                   | 86 ++++++++++++++++
 src/mirror/spp_mirror.c                       | 89 ++++++++---------
 src/mirror/spp_mirror.h                       | 28 ++++++
 .../spp_worker_th/cmd_res_formatter.c         | 94 ------------------
 .../secondary/spp_worker_th/mirror_deps.h     | 15 +--
 src/shared/secondary/spp_worker_th/vf_deps.h  | 27 +----
 src/vf/classifier_mac.h                       | 20 ++++
 src/vf/spp_forward.c                          | 98 +++++++++----------
 src/vf/spp_forward.h                          | 21 ++++
 src/vf/vf_cmd_runner.c                        | 92 +++++++++++++++++
 10 files changed, 347 insertions(+), 223 deletions(-)
 create mode 100644 src/mirror/spp_mirror.h

diff --git a/src/mirror/mir_cmd_runner.c b/src/mirror/mir_cmd_runner.c
index 5731628..461e85c 100644
--- a/src/mirror/mir_cmd_runner.c
+++ b/src/mirror/mir_cmd_runner.c
@@ -2,9 +2,13 @@
  * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
  */
 
+#include "spp_mirror.h"
 #include "shared/secondary/return_codes.h"
+#include "shared/secondary/string_buffer.h"
+#include "shared/secondary/json_helper.h"
 #include "shared/secondary/spp_worker_th/cmd_parser.h"
 #include "shared/secondary/spp_worker_th/cmd_runner.h"
+#include "shared/secondary/spp_worker_th/cmd_res_formatter.h"
 #include "shared/secondary/spp_worker_th/mirror_deps.h"
 
 #define RTE_LOGTYPE_MIR_CMD_RUNNER RTE_LOGTYPE_USER1
@@ -286,3 +290,85 @@ exec_one_cmd(const struct sppwk_cmd_attrs *cmd)
 
 	return ret;
 }
+
+/* Iterate core information to create response to status command */
+static int
+spp_iterate_core_info(struct spp_iterate_core_params *params)
+{
+	int ret;
+	int lcore_id, cnt;
+	struct core_info *core = NULL;
+	struct sppwk_comp_info *comp_info_base = NULL;
+	struct sppwk_comp_info *comp_info = NULL;
+
+	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+		if (spp_get_core_status(lcore_id) == SPP_CORE_UNUSE)
+			continue;
+
+		core = get_core_info(lcore_id);
+		if (core->num == 0) {
+			ret = (*params->element_proc)(
+				params, lcore_id,
+				"", SPPWK_TYPE_NONE_STR,
+				0, NULL, 0, NULL);
+			if (unlikely(ret != 0)) {
+				RTE_LOG(ERR, MIR_CMD_RUNNER,
+						"Cannot iterate core "
+						"information. "
+						"(core = %d, type = %d)\n",
+						lcore_id, SPPWK_TYPE_NONE);
+				return SPP_RET_NG;
+			}
+			continue;
+		}
+
+		for (cnt = 0; cnt < core->num; cnt++) {
+			sppwk_get_mng_data(NULL, NULL, &comp_info_base,
+							NULL, NULL, NULL, NULL);
+			comp_info = (comp_info_base + core->id[cnt]);
+			ret = get_mirror_status(lcore_id, core->id[cnt],
+					params);
+
+			if (unlikely(ret != 0)) {
+				RTE_LOG(ERR, MIR_CMD_RUNNER,
+						"Cannot iterate core "
+						"information. "
+						"(core = %d, type = %d)\n",
+						lcore_id, comp_info->wk_type);
+				return SPP_RET_NG;
+			}
+		}
+	}
+
+	return SPP_RET_OK;
+}
+
+/* Add entry of core info of worker to a response in JSON such as "core:0". */
+int
+add_core(const char *name, char **output,
+		void *tmp __attribute__ ((unused)))
+{
+	int ret = SPP_RET_NG;
+	struct spp_iterate_core_params itr_params;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, MIR_CMD_RUNNER,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	itr_params.output = tmp_buff;
+	itr_params.element_proc = append_core_element_value;
+
+	ret = spp_iterate_core_info(&itr_params);
+	if (unlikely(ret != SPP_RET_OK)) {
+		spp_strbuf_free(itr_params.output);
+		return SPP_RET_NG;
+	}
+
+	ret = append_json_array_brackets(output, name, itr_params.output);
+	spp_strbuf_free(itr_params.output);
+	return ret;
+}
diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c
index c00cad6..2cae48a 100644
--- a/src/mirror/spp_mirror.c
+++ b/src/mirror/spp_mirror.c
@@ -9,6 +9,7 @@
 #include <rte_common.h>
 #include <rte_cycles.h>
 
+#include "spp_mirror.h"
 #include "shared/common.h"
 #include "shared/secondary/return_codes.h"
 #include "shared/secondary/utils.h"
@@ -457,50 +458,6 @@ mirror_proc(int id)
 	return SPP_RET_OK;
 }
 
-/* Mirror get component status */
-int
-get_mirror_status(unsigned int lcore_id, int id,
-		struct spp_iterate_core_params *params)
-{
-	int ret = SPP_RET_NG;
-	int cnt;
-	const char *component_type = NULL;
-	struct mirror_info *info = &g_mirror_info[id];
-	struct mirror_path *path = &info->path[info->ref_index];
-	struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS];
-	struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS];
-
-	if (unlikely(path->wk_type == SPPWK_TYPE_NONE)) {
-		RTE_LOG(ERR, MIRROR,
-			"Mirror is not used. (id=%d, lcore=%d, type=%d)\n",
-			id, lcore_id, path->wk_type);
-		return SPP_RET_NG;
-	}
-
-	component_type = SPPWK_TYPE_MIR_STR;
-
-	memset(rx_ports, 0x00, sizeof(rx_ports));
-	for (cnt = 0; cnt < path->nof_rx; cnt++) {
-		rx_ports[cnt].iface_type = path->ports[cnt].rx.iface_type;
-		rx_ports[cnt].iface_no   = path->ports[cnt].rx.iface_no;
-	}
-
-	memset(tx_ports, 0x00, sizeof(tx_ports));
-	for (cnt = 0; cnt < path->nof_tx; cnt++) {
-		tx_ports[cnt].iface_type = path->ports[cnt].tx.iface_type;
-		tx_ports[cnt].iface_no   = path->ports[cnt].tx.iface_no;
-	}
-
-	/* Set the information with the function specified by the command. */
-	ret = (*params->element_proc)(params, lcore_id, path->name,
-			component_type, path->nof_rx, rx_ports, path->nof_tx,
-			tx_ports);
-	if (unlikely(ret != 0))
-		return SPP_RET_NG;
-
-	return SPP_RET_OK;
-}
-
 /* Main process of slave core */
 static int
 slave_main(void *arg __attribute__ ((unused)))
@@ -706,3 +663,47 @@ main(int argc, char *argv[])
 	RTE_LOG(INFO, MIRROR, "spp_mirror exit.\n");
 	return ret;
 }
+
+/* Mirror get component status */
+int
+get_mirror_status(unsigned int lcore_id, int id,
+		struct spp_iterate_core_params *params)
+{
+	int ret = SPP_RET_NG;
+	int cnt;
+	const char *component_type = NULL;
+	struct mirror_info *info = &g_mirror_info[id];
+	struct mirror_path *path = &info->path[info->ref_index];
+	struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS];
+	struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS];
+
+	if (unlikely(path->wk_type == SPPWK_TYPE_NONE)) {
+		RTE_LOG(ERR, MIRROR,
+			"Mirror is not used. (id=%d, lcore=%d, type=%d)\n",
+			id, lcore_id, path->wk_type);
+		return SPP_RET_NG;
+	}
+
+	component_type = SPPWK_TYPE_MIR_STR;
+
+	memset(rx_ports, 0x00, sizeof(rx_ports));
+	for (cnt = 0; cnt < path->nof_rx; cnt++) {
+		rx_ports[cnt].iface_type = path->ports[cnt].rx.iface_type;
+		rx_ports[cnt].iface_no   = path->ports[cnt].rx.iface_no;
+	}
+
+	memset(tx_ports, 0x00, sizeof(tx_ports));
+	for (cnt = 0; cnt < path->nof_tx; cnt++) {
+		tx_ports[cnt].iface_type = path->ports[cnt].tx.iface_type;
+		tx_ports[cnt].iface_no   = path->ports[cnt].tx.iface_no;
+	}
+
+	/* Set the information with the function specified by the command. */
+	ret = (*params->element_proc)(params, lcore_id, path->name,
+			component_type, path->nof_rx, rx_ports, path->nof_tx,
+			tx_ports);
+	if (unlikely(ret != 0))
+		return SPP_RET_NG;
+
+	return SPP_RET_OK;
+}
diff --git a/src/mirror/spp_mirror.h b/src/mirror/spp_mirror.h
new file mode 100644
index 0000000..c742541
--- /dev/null
+++ b/src/mirror/spp_mirror.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef __SPP_MIRROR_H__
+#define __SPP_MIRROR_H__
+
+#include "shared/secondary/spp_worker_th/cmd_utils.h"
+
+/**
+ * Get mirror status.
+ *
+ * @param lcore_id Lcore ID for forwarder and merger.
+ * @param id Unique component ID.
+ * @param params Pointer to detailed data of mirror status.
+ * @retval SPP_RET_OK If succeeded.
+ * @retval SPP_RET_NG If failed.
+ */
+/**
+ * TODO(yasufum) Consider to move this function to `mir_cmd_runner.c`.
+ * This function is called only from `mir_cmd_runner.c`, but
+ * must be defined in `spp_mirror.c` because it refers g_mirror_info defined
+ * in this file. It is bad dependency for the global variable.
+ */
+int get_mirror_status(unsigned int lcore_id, int id,
+		struct spp_iterate_core_params *params);
+
+#endif /* __SPP_MIRROR_H__ */
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index 9c0c873..bfe13e5 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -18,8 +18,6 @@ static int add_interface(const char *name, char **output,
 		void *tmp __attribute__ ((unused)));
 static int add_master_lcore(const char *name, char **output,
 		void *tmp __attribute__ ((unused)));
-static int add_core(const char *name, char **output,
-		void *tmp __attribute__ ((unused)));
 
 /**
  * List of worker process type. The order of items should be same as the order
@@ -614,68 +612,6 @@ append_info_value(const char *name, char **output)
 	return ret;
 }
 
-/* Iterate core information to create response to status command */
-static int
-spp_iterate_core_info(struct spp_iterate_core_params *params)
-{
-	int ret;
-	int lcore_id, cnt;
-	struct core_info *core = NULL;
-	struct sppwk_comp_info *comp_info_base = NULL;
-	struct sppwk_comp_info *comp_info = NULL;
-
-	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-		if (spp_get_core_status(lcore_id) == SPP_CORE_UNUSE)
-			continue;
-
-		core = get_core_info(lcore_id);
-		if (core->num == 0) {
-			ret = (*params->element_proc)(
-				params, lcore_id,
-				"", SPPWK_TYPE_NONE_STR,
-				0, NULL, 0, NULL);
-			if (unlikely(ret != 0)) {
-				RTE_LOG(ERR, WK_CMD_RES_FMT,
-						"Cannot iterate core "
-						"information. "
-						"(core = %d, type = %d)\n",
-						lcore_id, SPPWK_TYPE_NONE);
-				return SPP_RET_NG;
-			}
-			continue;
-		}
-
-		for (cnt = 0; cnt < core->num; cnt++) {
-			sppwk_get_mng_data(NULL, NULL, &comp_info_base,
-							NULL, NULL, NULL, NULL);
-			comp_info = (comp_info_base + core->id[cnt]);
-#ifdef SPP_VF_MODULE
-			if (comp_info->wk_type == SPPWK_TYPE_CLS) {
-				ret = get_classifier_status(lcore_id,
-						core->id[cnt], params);
-			} else {
-				ret = get_forwarder_status(lcore_id,
-						core->id[cnt], params);
-			}
-#endif /* SPP_VF_MODULE */
-#ifdef SPP_MIRROR_MODULE
-			ret = get_mirror_status(lcore_id, core->id[cnt],
-					params);
-#endif /* SPP_MIRROR_MODULE */
-			if (unlikely(ret != 0)) {
-				RTE_LOG(ERR, WK_CMD_RES_FMT,
-						"Cannot iterate core "
-						"information. "
-						"(core = %d, type = %d)\n",
-						lcore_id, comp_info->wk_type);
-				return SPP_RET_NG;
-			}
-		}
-	}
-
-	return SPP_RET_OK;
-}
-
 /* TODO(yasufum) move to another file for util funcs. */
 /* Get client ID from global command params. */
 static int
@@ -744,36 +680,6 @@ add_master_lcore(const char *name, char **output,
 	return ret;
 }
 
-/* Add entry of core info of worker to a response in JSON such as "core:0". */
-static int
-add_core(const char *name, char **output,
-		void *tmp __attribute__ ((unused)))
-{
-	int ret = SPP_RET_NG;
-	struct spp_iterate_core_params itr_params;
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RES_FMT,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	itr_params.output = tmp_buff;
-	itr_params.element_proc = append_core_element_value;
-
-	ret = spp_iterate_core_info(&itr_params);
-	if (unlikely(ret != SPP_RET_OK)) {
-		spp_strbuf_free(itr_params.output);
-		return SPP_RET_NG;
-	}
-
-	ret = append_json_array_brackets(output, name, itr_params.output);
-	spp_strbuf_free(itr_params.output);
-	return ret;
-}
-
 #ifdef SPP_VF_MODULE
 /* Iterate classifier_table to create response to status command */
 static int
diff --git a/src/shared/secondary/spp_worker_th/mirror_deps.h b/src/shared/secondary/spp_worker_th/mirror_deps.h
index 55ba913..2cf0fd9 100644
--- a/src/shared/secondary/spp_worker_th/mirror_deps.h
+++ b/src/shared/secondary/spp_worker_th/mirror_deps.h
@@ -10,6 +10,9 @@
 
 int exec_one_cmd(const struct sppwk_cmd_attrs *cmd);
 
+int add_core(const char *name, char **output,
+		void *tmp __attribute__ ((unused)));
+
 /**
  * Update mirror info.
  *
@@ -19,16 +22,4 @@ int exec_one_cmd(const struct sppwk_cmd_attrs *cmd);
  */
 int update_mirror(struct sppwk_comp_info *wk_comp_info);
 
-/**
- * Get mirror status.
- *
- * @param lcore_id Lcore ID for forwarder and merger.
- * @param id Unique component ID.
- * @param params Pointer to detailed data of mirror status.
- * @retval SPP_RET_OK If succeeded.
- * @retval SPP_RET_NG If failed.
- */
-int get_mirror_status(unsigned int lcore_id, int id,
-		struct spp_iterate_core_params *params);
-
 #endif  /* __SPP_WORKER_TH_MIRROR_DEPS_H__ */
diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h
index 6a78ef5..2ec700e 100644
--- a/src/shared/secondary/spp_worker_th/vf_deps.h
+++ b/src/shared/secondary/spp_worker_th/vf_deps.h
@@ -43,6 +43,9 @@ struct cls_comp_info {
 	struct cls_port_info tx_ports_i[RTE_MAX_ETHPORTS];  /* TX info. */
 };
 
+int add_core(const char *name, char **output,
+		void *tmp __attribute__ ((unused)));
+
 /* Release instance of mac classifier. */
 static inline void
 free_mac_classifier(struct mac_classifier *mac_clf)
@@ -87,28 +90,4 @@ void uninit_component_info(struct cls_comp_info *cmp_info);
 int add_classifier_table_val(
 		struct spp_iterate_classifier_table_params *params);
 
-/**
- * Get classifier status.
- *
- * @param[in] lcore_id Lcore ID for classifier.
- * @param[in] id Unique component ID.
- * @param[in,out] params Pointer to detailed data of classifier status.
- * @retval SPP_RET_OK If succeeded.
- * @retval SPP_RET_NG If failed.
- */
-int get_classifier_status(unsigned int lcore_id, int id,
-		struct spp_iterate_core_params *params);
-
-/**
- * Get forwarder status.
- *
- * @param lcore_id Lcore ID for forwarder and merger.
- * @param id Unique component ID.
- * @param params Pointer detailed data of forwarder and merger status.
- * @retval SPP_RET_OK If succeeded.
- * @retval SPP_RET_NG If failed.
- */
-int get_forwarder_status(unsigned int lcore_id, int id,
-		struct spp_iterate_core_params *params);
-
 #endif  /* _SPPWK_TH_VF_DEPS_H_ */
diff --git a/src/vf/classifier_mac.h b/src/vf/classifier_mac.h
index 21433e6..521e1d6 100644
--- a/src/vf/classifier_mac.h
+++ b/src/vf/classifier_mac.h
@@ -5,6 +5,8 @@
 #ifndef _CLASSIFIER_MAC_H_
 #define _CLASSIFIER_MAC_H_
 
+#include "shared/secondary/spp_worker_th/cmd_utils.h"
+
 /**
  * @file
  * SPP Classifier
@@ -59,4 +61,22 @@ int spp_classifier_mac_do(int id);
 int add_classifier_table_val(
 		struct spp_iterate_classifier_table_params *params);
 
+/**
+ * Get classifier status.
+ *
+ * @param[in] lcore_id Lcore ID for classifier.
+ * @param[in] id Unique component ID.
+ * @param[in,out] params Pointer to detailed data of classifier status.
+ * @retval SPP_RET_OK If succeeded.
+ * @retval SPP_RET_NG If failed.
+ */
+/**
+ * TODO(yasufum) Consider to move this function to `vf_cmd_runner.c`.
+ * This function is called only from `vf_cmd_runner.c`, but
+ * must be defined in `classifier_mac.c` because it refers g_mng_info defined
+ * in this file. It is bad dependency for the global variable.
+ */
+int get_classifier_status(unsigned int lcore_id, int id,
+		struct spp_iterate_core_params *params);
+
 #endif /* _CLASSIFIER_MAC_H_ */
diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c
index d381c92..07031f7 100644
--- a/src/vf/spp_forward.c
+++ b/src/vf/spp_forward.c
@@ -50,6 +50,55 @@ spp_forward_init(void)
 	}
 }
 
+/* Get forwarder status. */
+int
+get_forwarder_status(unsigned int lcore_id, int id,
+		struct spp_iterate_core_params *params)
+{
+	int ret = SPP_RET_NG;
+	int cnt;
+	const char *component_type = NULL;
+	struct forward_info *fwd_info = &g_forward_info[id];
+	struct forward_path *fwd_path = &fwd_info->path[fwd_info->ref_index];
+	struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS];
+	struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS];
+
+	if (unlikely(fwd_path->wk_type == SPPWK_TYPE_NONE)) {
+		RTE_LOG(ERR, FORWARD,
+				"Forwarder is not used. "
+				"(id=%d, lcore=%d, type=%d).\n",
+				id, lcore_id, fwd_path->wk_type);
+		return SPP_RET_NG;
+	}
+
+	if (fwd_path->wk_type == SPPWK_TYPE_MRG)
+		component_type = SPPWK_TYPE_MRG_STR;
+	else
+		component_type = SPPWK_TYPE_FWD_STR;
+
+	memset(rx_ports, 0x00, sizeof(rx_ports));
+	for (cnt = 0; cnt < fwd_path->num_rx; cnt++) {
+		rx_ports[cnt].iface_type = fwd_path->ports[cnt].rx.iface_type;
+		rx_ports[cnt].iface_no = fwd_path->ports[cnt].rx.iface_no;
+	}
+
+	memset(tx_ports, 0x00, sizeof(tx_ports));
+	for (cnt = 0; cnt < fwd_path->num_tx; cnt++) {
+		tx_ports[cnt].iface_type = fwd_path->ports[cnt].tx.iface_type;
+		tx_ports[cnt].iface_no = fwd_path->ports[cnt].tx.iface_no;
+	}
+
+	/* Set the information with the function specified by the command. */
+	ret = (*params->element_proc)(
+		params, lcore_id,
+		fwd_path->name, component_type,
+		fwd_path->num_rx, rx_ports, fwd_path->num_tx, tx_ports);
+	if (unlikely(ret != SPP_RET_OK))
+		return SPP_RET_NG;
+
+	return SPP_RET_OK;
+}
+
 /* Update forward info */
 int
 update_forwarder(struct sppwk_comp_info *comp_info)
@@ -182,52 +231,3 @@ spp_forward(int id)
 	}
 	return SPP_RET_OK;
 }
-
-/* Get forwarder status */
-int
-get_forwarder_status(unsigned int lcore_id, int id,
-		struct spp_iterate_core_params *params)
-{
-	int ret = SPP_RET_NG;
-	int cnt;
-	const char *component_type = NULL;
-	struct forward_info *fwd_info = &g_forward_info[id];
-	struct forward_path *fwd_path = &fwd_info->path[fwd_info->ref_index];
-	struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS];
-	struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS];
-
-	if (unlikely(fwd_path->wk_type == SPPWK_TYPE_NONE)) {
-		RTE_LOG(ERR, FORWARD,
-				"Forwarder is not used. "
-				"(id=%d, lcore=%d, type=%d).\n",
-				id, lcore_id, fwd_path->wk_type);
-		return SPP_RET_NG;
-	}
-
-	if (fwd_path->wk_type == SPPWK_TYPE_MRG)
-		component_type = SPPWK_TYPE_MRG_STR;
-	else
-		component_type = SPPWK_TYPE_FWD_STR;
-
-	memset(rx_ports, 0x00, sizeof(rx_ports));
-	for (cnt = 0; cnt < fwd_path->num_rx; cnt++) {
-		rx_ports[cnt].iface_type = fwd_path->ports[cnt].rx.iface_type;
-		rx_ports[cnt].iface_no = fwd_path->ports[cnt].rx.iface_no;
-	}
-
-	memset(tx_ports, 0x00, sizeof(tx_ports));
-	for (cnt = 0; cnt < fwd_path->num_tx; cnt++) {
-		tx_ports[cnt].iface_type = fwd_path->ports[cnt].tx.iface_type;
-		tx_ports[cnt].iface_no = fwd_path->ports[cnt].tx.iface_no;
-	}
-
-	/* Set the information with the function specified by the command. */
-	ret = (*params->element_proc)(
-		params, lcore_id,
-		fwd_path->name, component_type,
-		fwd_path->num_rx, rx_ports, fwd_path->num_tx, tx_ports);
-	if (unlikely(ret != SPP_RET_OK))
-		return SPP_RET_NG;
-
-	return SPP_RET_OK;
-}
diff --git a/src/vf/spp_forward.h b/src/vf/spp_forward.h
index 4da083c..37b1e3c 100644
--- a/src/vf/spp_forward.h
+++ b/src/vf/spp_forward.h
@@ -5,6 +5,8 @@
 #ifndef __SPP_FORWARD_H__
 #define __SPP_FORWARD_H__
 
+#include "shared/secondary/spp_worker_th/cmd_utils.h"
+
 /**
  * @file
  * SPP Forwarder and Merger
@@ -35,4 +37,23 @@ void spp_forward_init(void);
  */
 int spp_forward(int id);
 
+/**
+ * Get forwarder status.
+ *
+ * @param lcore_id Lcore ID for forwarder and merger.
+ * @param id Unique component ID.
+ * @param params Pointer detailed data of forwarder and merger status.
+ * @retval SPP_RET_OK If succeeded.
+ * @retval SPP_RET_NG If failed.
+ */
+/**
+ * TODO(yasufum) Consider to move this function to `vf_cmd_runner.c`.
+ * This function is called only from `vf_cmd_runner.c`, but
+ * must be defined in `spp_forward.c` because it refers g_forward_info defined
+ * in this file. It is bad dependency for the global variable.
+ */
+int
+get_forwarder_status(unsigned int lcore_id, int id,
+		struct spp_iterate_core_params *params);
+
 #endif /* __SPP_FORWARD_H__ */
diff --git a/src/vf/vf_cmd_runner.c b/src/vf/vf_cmd_runner.c
index 2fb071e..182a917 100644
--- a/src/vf/vf_cmd_runner.c
+++ b/src/vf/vf_cmd_runner.c
@@ -3,9 +3,13 @@
  */
 
 #include "classifier_mac.h"
+#include "spp_forward.h"
 #include "shared/secondary/return_codes.h"
+#include "shared/secondary/string_buffer.h"
+#include "shared/secondary/json_helper.h"
 #include "shared/secondary/spp_worker_th/cmd_parser.h"
 #include "shared/secondary/spp_worker_th/cmd_runner.h"
+#include "shared/secondary/spp_worker_th/cmd_res_formatter.h"
 #include "shared/secondary/spp_worker_th/vf_deps.h"
 
 #define RTE_LOGTYPE_VF_CMD_RUNNER RTE_LOGTYPE_USER1
@@ -409,3 +413,91 @@ exec_one_cmd(const struct sppwk_cmd_attrs *cmd)
 
 	return ret;
 }
+
+/* Iterate core information to create response to status command */
+static int
+spp_iterate_core_info(struct spp_iterate_core_params *params)
+{
+	int ret;
+	int lcore_id, cnt;
+	struct core_info *core = NULL;
+	struct sppwk_comp_info *comp_info_base = NULL;
+	struct sppwk_comp_info *comp_info = NULL;
+
+	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+		if (spp_get_core_status(lcore_id) == SPP_CORE_UNUSE)
+			continue;
+
+		core = get_core_info(lcore_id);
+		if (core->num == 0) {
+			ret = (*params->element_proc)(
+				params, lcore_id,
+				"", SPPWK_TYPE_NONE_STR,
+				0, NULL, 0, NULL);
+			if (unlikely(ret != 0)) {
+				RTE_LOG(ERR, VF_CMD_RUNNER,
+						"Cannot iterate core "
+						"information. "
+						"(core = %d, type = %d)\n",
+						lcore_id, SPPWK_TYPE_NONE);
+				return SPP_RET_NG;
+			}
+			continue;
+		}
+
+		for (cnt = 0; cnt < core->num; cnt++) {
+			sppwk_get_mng_data(NULL, NULL, &comp_info_base,
+							NULL, NULL, NULL, NULL);
+			comp_info = (comp_info_base + core->id[cnt]);
+
+			if (comp_info->wk_type == SPPWK_TYPE_CLS) {
+				ret = get_classifier_status(lcore_id,
+						core->id[cnt], params);
+			} else {
+				ret = get_forwarder_status(lcore_id,
+						core->id[cnt], params);
+			}
+
+			if (unlikely(ret != 0)) {
+				RTE_LOG(ERR, VF_CMD_RUNNER,
+						"Cannot iterate core "
+						"information. "
+						"(core = %d, type = %d)\n",
+						lcore_id, comp_info->wk_type);
+				return SPP_RET_NG;
+			}
+		}
+	}
+
+	return SPP_RET_OK;
+}
+
+/* Add entry of core info of worker to a response in JSON such as "core:0". */
+int
+add_core(const char *name, char **output,
+		void *tmp __attribute__ ((unused)))
+{
+	int ret = SPP_RET_NG;
+	struct spp_iterate_core_params itr_params;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, VF_CMD_RUNNER,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	itr_params.output = tmp_buff;
+	itr_params.element_proc = append_core_element_value;
+
+	ret = spp_iterate_core_info(&itr_params);
+	if (unlikely(ret != SPP_RET_OK)) {
+		spp_strbuf_free(itr_params.output);
+		return SPP_RET_NG;
+	}
+
+	ret = append_json_array_brackets(output, name, itr_params.output);
+	spp_strbuf_free(itr_params.output);
+	return ret;
+}
-- 
2.17.1


                 reply	other threads:[~2019-06-24  6:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190624062149.22505-1-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).