From: Yasufumi Ogawa <yasufum.o@gmail.com>
In SPP worker processes, master lcore ID is managed as a member of
global variable, but no need to this because it can be retrieved with
rte_get_master_lcore(). This update is to change to use this function.
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/mirror/spp_mirror.c | 44 ++++++---------
.../secondary/spp_worker_th/cmd_utils.c | 13 ++---
.../secondary/spp_worker_th/cmd_utils.h | 4 +-
src/vf/spp_vf.c | 55 ++++++++-----------
4 files changed, 49 insertions(+), 67 deletions(-)
diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c
index f040010..898755d 100644
--- a/src/mirror/spp_mirror.c
+++ b/src/mirror/spp_mirror.c
@@ -56,9 +56,6 @@ struct mirror_info {
static uint16_t nb_rxd = MIR_RX_DESC_DEFAULT;
static uint16_t nb_txd = MIR_TX_DESC_DEFAULT;
-/* Logical core ID for main process */
-static unsigned int g_main_lcore_id = 0xffffffff;
-
/* Interface management information */
static struct iface_info g_iface_info;
@@ -421,7 +418,7 @@ slave_main(void *arg __attribute__ ((unused)))
struct core_mng_info *info = &g_core_info[lcore_id];
struct core_info *core = get_core_info(lcore_id);
- RTE_LOG(INFO, MIRROR, "Core[%d] Start.\n", lcore_id);
+ RTE_LOG(INFO, MIRROR, "Slave started on lcore %d.\n", lcore_id);
set_core_status(lcore_id, SPP_CORE_IDLE);
while ((status = spp_get_core_status(lcore_id)) !=
@@ -446,14 +443,14 @@ slave_main(void *arg __attribute__ ((unused)))
}
if (unlikely(ret != 0)) {
RTE_LOG(ERR, MIRROR,
- "Core[%d] Component Error. (id = %d)\n",
+ "Failed to forward on lcore %d (id = %d)\n",
lcore_id, core->id[cnt]);
break;
}
}
set_core_status(lcore_id, SPP_CORE_STOP);
- RTE_LOG(INFO, MIRROR, "Core[%d] End.\n", lcore_id);
+ RTE_LOG(INFO, MIRROR, "Terminated slave on lcore %d.\n", lcore_id);
return ret;
}
@@ -469,6 +466,7 @@ main(int argc, char *argv[])
char ctl_ip[IPADDR_LEN] = { 0 };
int ctl_port;
int ret_cmd_init;
+ unsigned int master_lcore;
unsigned int lcore_id;
#ifdef SPP_DEMONIZE
@@ -498,13 +496,12 @@ main(int argc, char *argv[])
if (unlikely(ret_parse != 0))
break;
- /* Get lcore id of main thread to set its status after */
- g_main_lcore_id = rte_lcore_id();
+ master_lcore = rte_get_master_lcore();
if (sppwk_set_mng_data(&g_iface_info, g_component_info,
g_core_info, g_change_core,
- g_change_component, &g_backup_info,
- g_main_lcore_id) < 0) {
+ g_change_component,
+ &g_backup_info) < 0) {
RTE_LOG(ERR, MIRROR,
"Failed to set management data.\n");
break;
@@ -514,7 +511,7 @@ main(int argc, char *argv[])
ret = mirror_pool_create(get_client_id());
if (ret == SPP_RET_NG) {
RTE_LOG(ERR, MIRROR,
- "mirror mnuf pool create failed.\n");
+ "Failed to create mbuf pool.\n");
return SPP_RET_NG;
}
@@ -547,7 +544,7 @@ main(int argc, char *argv[])
}
/* Set the status of main thread to idle */
- g_core_info[g_main_lcore_id].status = SPP_CORE_IDLE;
+ g_core_info[master_lcore].status = SPP_CORE_IDLE;
int ret_wait = check_core_status_wait(SPP_CORE_IDLE);
if (unlikely(ret_wait != 0))
break;
@@ -569,7 +566,7 @@ main(int argc, char *argv[])
/* Enter loop for accepting commands */
int ret_do = 0;
#ifndef USE_UT_SPP_VF
- while (likely(g_core_info[g_main_lcore_id].status !=
+ while (likely(g_core_info[master_lcore].status !=
SPP_CORE_STOP_REQUEST)) {
#else
{
@@ -599,24 +596,19 @@ main(int argc, char *argv[])
}
/* Finalize to exit */
- if (g_main_lcore_id == rte_lcore_id()) {
- g_core_info[g_main_lcore_id].status = SPP_CORE_STOP;
- int ret_core_end = check_core_status_wait(SPP_CORE_STOP);
- if (unlikely(ret_core_end != 0))
- RTE_LOG(ERR, MIRROR, "Core did not stop.\n");
-
- /*
- * Remove vhost sock file if it is not running
- * in vhost-client mode
- */
- del_vhost_sockfile(g_iface_info.vhost);
- }
+ g_core_info[master_lcore].status = SPP_CORE_STOP;
+ int ret_core_end = check_core_status_wait(SPP_CORE_STOP);
+ if (unlikely(ret_core_end != 0))
+ RTE_LOG(ERR, MIRROR, "Failed to terminate master thread.\n");
+
+ /* Remove vhost sock file if not running in vhost-client mode. */
+ del_vhost_sockfile(g_iface_info.vhost);
#ifdef SPP_RINGLATENCYSTATS_ENABLE
spp_ringlatencystats_uninit();
#endif /* SPP_RINGLATENCYSTATS_ENABLE */
- RTE_LOG(INFO, MIRROR, "spp_mirror exit.\n");
+ RTE_LOG(INFO, MIRROR, "Exit spp_mirror.\n");
return ret;
}
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.c b/src/shared/secondary/spp_worker_th/cmd_utils.c
index 4f84365..32929ec 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.c
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.c
@@ -40,7 +40,6 @@ struct mng_data_info {
int *p_change_core;
int *p_change_component; /* Set of flags for udpated components */
struct cancel_backup_info *p_backup_info;
- unsigned int main_lcore_id;
};
/* Logical core ID for main process */
@@ -137,13 +136,15 @@ set_all_core_status(enum sppwk_lcore_status status)
void
stop_process(int signal)
{
+ unsigned int master_lcore;
if (unlikely(signal != SIGTERM) &&
unlikely(signal != SIGINT)) {
return;
}
- (g_mng_data.p_core_info + g_mng_data.main_lcore_id)->status =
- SPP_CORE_STOP_REQUEST;
+ master_lcore = rte_get_master_lcore();
+ (g_mng_data.p_core_info + master_lcore)->status =
+ SPP_CORE_STOP_REQUEST;
set_all_core_status(SPP_CORE_STOP_REQUEST);
}
@@ -843,8 +844,7 @@ int sppwk_set_mng_data(
struct core_mng_info *core_mng_p,
int *change_core_p,
int *change_component_p,
- struct cancel_backup_info *backup_info_p,
- unsigned int main_lcore_id)
+ struct cancel_backup_info *backup_info_p)
{
/**
* TODO(yasufum) confirm why the last `0xffffffff` is same as NULL,
@@ -852,7 +852,7 @@ int sppwk_set_mng_data(
*/
if (iface_p == NULL || component_p == NULL || core_mng_p == NULL ||
change_core_p == NULL || change_component_p == NULL ||
- backup_info_p == NULL || main_lcore_id == 0xffffffff)
+ backup_info_p == NULL)
return SPP_RET_NG;
g_mng_data.p_iface_info = iface_p;
@@ -861,7 +861,6 @@ int sppwk_set_mng_data(
g_mng_data.p_change_core = change_core_p;
g_mng_data.p_change_component = change_component_p;
g_mng_data.p_backup_info = backup_info_p;
- g_mng_data.main_lcore_id = main_lcore_id;
return SPP_RET_OK;
}
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h
index e2b987f..f33bc62 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.h
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.h
@@ -532,7 +532,6 @@ int64_t sppwk_convert_mac_str_to_int64(const char *macaddr);
* @param change_core_p Pointer to g_change_core address.
* @param change_component_p Pointer to g_change_component address.
* @param backup_info_p Pointer to g_backup_info address.
- * @param main_lcore_id Lcore ID of main thread.
* @retval SPP_RET_OK If succeeded.
* @retval SPP_RET_NG If failed.
*/
@@ -541,8 +540,7 @@ int sppwk_set_mng_data(struct iface_info *iface_p,
struct core_mng_info *core_mng_p,
int *change_core_p,
int *change_component_p,
- struct cancel_backup_info *backup_info_p,
- unsigned int main_lcore_id);
+ struct cancel_backup_info *backup_info_p);
/**
* Get mange data address.
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 44e39fc..0068329 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -18,9 +18,6 @@
#include "shared/secondary/spp_worker_th/spp_port.h"
/* Declare global variables */
-/* Logical core ID for main process */
-static unsigned int g_main_lcore_id = 0xffffffff;
-
/* Interface management information */
static struct iface_info g_iface_info;
@@ -147,7 +144,7 @@ slave_main(void *arg __attribute__ ((unused)))
struct core_mng_info *info = &g_core_info[lcore_id];
struct core_info *core = get_core_info(lcore_id);
- RTE_LOG(INFO, APP, "Core[%d] Start.\n", lcore_id);
+ RTE_LOG(INFO, APP, "Slave started on lcore %d.\n", lcore_id);
set_core_status(lcore_id, SPP_CORE_IDLE);
while ((status = spp_get_core_status(lcore_id)) !=
@@ -178,15 +175,15 @@ slave_main(void *arg __attribute__ ((unused)))
}
}
if (unlikely(ret != 0)) {
- RTE_LOG(ERR, APP, "Core[%d] Component Error. "
- "(id = %d)\n",
+ RTE_LOG(ERR, APP, "Failed to forward on lcore %d. "
+ "(id = %d).\n",
lcore_id, core->id[cnt]);
break;
}
}
set_core_status(lcore_id, SPP_CORE_STOP);
- RTE_LOG(INFO, APP, "Core[%d] End.\n", lcore_id);
+ RTE_LOG(INFO, APP, "Terminated slave on lcore %d.\n", lcore_id);
return ret;
}
@@ -202,7 +199,8 @@ main(int argc, char *argv[])
char ctl_ip[IPADDR_LEN] = { 0 };
int ctl_port;
int ret_cmd_init;
- unsigned int lcore_id = 0;
+ unsigned int master_lcore;
+ unsigned int lcore_id;
#ifdef SPP_DEMONIZE
/* Daemonize process */
@@ -231,14 +229,10 @@ main(int argc, char *argv[])
if (unlikely(ret_parse != SPP_RET_OK))
break;
- /* Get lcore id of main thread to set its status after */
- g_main_lcore_id = rte_lcore_id();
-
- if (sppwk_set_mng_data(&g_iface_info,
- g_component_info, g_core_info,
- g_change_core, g_change_component,
- &g_backup_info,
- g_main_lcore_id) < SPP_RET_OK) {
+ if (sppwk_set_mng_data(&g_iface_info, g_component_info,
+ g_core_info, g_change_core,
+ g_change_component,
+ &g_backup_info) < SPP_RET_OK) {
RTE_LOG(ERR, APP,
"Failed to set management data.\n");
break;
@@ -276,7 +270,8 @@ main(int argc, char *argv[])
}
/* Set the status of main thread to idle */
- g_core_info[g_main_lcore_id].status = SPP_CORE_IDLE;
+ master_lcore = rte_get_master_lcore();
+ g_core_info[master_lcore].status = SPP_CORE_IDLE;
int ret_wait = check_core_status_wait(SPP_CORE_IDLE);
if (unlikely(ret_wait != SPP_RET_OK))
break;
@@ -292,7 +287,7 @@ main(int argc, char *argv[])
/* Enter loop for accepting commands */
int ret_do = SPP_RET_OK;
#ifndef USE_UT_SPP_VF
- while (likely(g_core_info[g_main_lcore_id].status !=
+ while (likely(g_core_info[master_lcore].status !=
SPP_CORE_STOP_REQUEST)) {
#else
{
@@ -322,23 +317,21 @@ main(int argc, char *argv[])
}
/* Finalize to exit */
- if (g_main_lcore_id == rte_lcore_id()) {
- g_core_info[g_main_lcore_id].status = SPP_CORE_STOP;
- int ret_core_end = check_core_status_wait(SPP_CORE_STOP);
- if (unlikely(ret_core_end != SPP_RET_OK))
- RTE_LOG(ERR, APP, "Core did not stop.\n");
-
- /*
- * Remove vhost sock file if it is not running
- * in vhost-client mode
- */
- del_vhost_sockfile(g_iface_info.vhost);
- }
+ g_core_info[master_lcore].status = SPP_CORE_STOP;
+ int ret_core_end = check_core_status_wait(SPP_CORE_STOP);
+ if (unlikely(ret_core_end != SPP_RET_OK))
+ RTE_LOG(ERR, APP, "Failed to terminate master thread.\n");
+
+ /*
+ * Remove vhost sock file if it is not running
+ * in vhost-client mode
+ */
+ del_vhost_sockfile(g_iface_info.vhost);
#ifdef SPP_RINGLATENCYSTATS_ENABLE
spp_ringlatencystats_uninit();
#endif /* SPP_RINGLATENCYSTATS_ENABLE */
- RTE_LOG(INFO, APP, "spp_vf exit.\n");
+ RTE_LOG(INFO, APP, "Exit spp_vf.\n");
return ret;
}
--
2.17.1