From 9980175dfd8e33ed17bbe928c5adaeee10907e4b Mon Sep 17 00:00:00 2001
From: hantwofish <hankangkang5@huawei.com>
Date: Sat, 18 Nov 2023 10:28:59 +0800
Subject: [PATCH] add gazelle log

---
 src/common/gazelle_dfx_msg.c           |  6 ++---
 src/lstack/core/lstack_control_plane.c |  9 ++++++++
 src/lstack/core/lstack_dpdk.c          | 31 ++++++++++++++++++++------
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/common/gazelle_dfx_msg.c b/src/common/gazelle_dfx_msg.c
index b8472be..5fe4e06 100644
--- a/src/common/gazelle_dfx_msg.c
+++ b/src/common/gazelle_dfx_msg.c
@@ -32,16 +32,16 @@ int read_specied_len(int fd, char *buf, size_t target_size)
             printf("read_specied_len:: poll ret=%d \n", ret);
             return -1;
         } else if (ret == 0) {
-            printf("read_specied_len:: time out");
+            printf("read_specied_len:: time out \n");
             return -1;
         }
         if (fds[0].revents & POLLIN) {
             int n = read(fd, buf + total_read, target_size - total_read);
             if (n < 0) {
-                printf("read_specied_len:: read ret=%d", ret);
+                printf("read_specied_len:: read ret=%d \n", ret);
                 return -1;
             } else if (n == 0) {
-                printf("read_specied_len:: Connection closed");
+                printf("read_specied_len:: Connection closed \n");
                 return -1;
             }
             total_read += n;
diff --git a/src/lstack/core/lstack_control_plane.c b/src/lstack/core/lstack_control_plane.c
index be156dc..746c209 100644
--- a/src/lstack/core/lstack_control_plane.c
+++ b/src/lstack/core/lstack_control_plane.c
@@ -134,11 +134,13 @@ static int32_t msg_proc_init(enum request_type rqt_type, struct reg_request_msg
 
     ret = strncpy_s(conf->file_prefix, PATH_MAX, global_params->sec_attach_arg.file_prefix, PATH_MAX - 1);
     if (ret != EOK) {
+        LSTACK_LOG(ERR, LSTACK, "strncpy_s fail ret=%d \n", ret);
         return ret;
     }
 
     ret = memcpy_s(conf->mac_addr, ETHER_ADDR_LEN, global_params->mac_addr, ETHER_ADDR_LEN);
     if (ret != EOK) {
+        LSTACK_LOG(ERR, LSTACK, "memcpy_s fail ret=%d \n", ret);
         return ret;
     }
     switch (rqt_type) {
@@ -153,14 +155,17 @@ static int32_t msg_proc_init(enum request_type rqt_type, struct reg_request_msg
             conf->argc = 0;
             ret = gazelle_copy_param(OPT_SOCKET_MEM, true, (int32_t *)&conf->argc, conf->argv);
             if (ret != EOK) {
+                LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_SOCKET_MEM fail ret=%d \n", ret);
                 return ret;
             }
             ret = gazelle_copy_param(OPT_FILE_PREFIX, true, (int32_t *)&conf->argc, conf->argv);
             if (ret != EOK) {
+                LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_FILE_PREFIX fail ret=%d \n", ret);
                 return ret;
             }
             ret = gazelle_copy_param(OPT_LEGACY_MEM, false, (int32_t *)&conf->argc, conf->argv);
             if (ret != EOK) {
+                LSTACK_LOG(ERR, LSTACK, "gazelle_copy_param OPT_LEGACY_MEM fail ret=%d \n", ret);
                 return ret;
             }
 
@@ -494,6 +499,7 @@ int32_t control_init_client(bool is_reconnect)
 
     ret = client_reg_proc_memory(is_reconnect);
     if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "client_reg_proc_memory ret=%d \n", ret);
         posix_api->close_fn(g_data_fd);
         g_data_fd = -1;
         return -1;
@@ -501,6 +507,7 @@ int32_t control_init_client(bool is_reconnect)
 
     ret = client_reg_proc_attach(is_reconnect);
     if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "client_reg_proc_memory ret=%d \n", ret);
         posix_api->close_fn(g_data_fd);
         g_data_fd = -1;
         return -1;
@@ -636,12 +643,14 @@ static int32_t client_reg_proc_reconnect(int32_t epfd)
     /* longterm connect g_data_fd; init process info */
     ret = control_init_client(true);
     if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "control_init_client fail ret=%d\n", ret);
         return -1;
     }
     sockfd = g_data_fd;
 
     ret = thread_register();
     if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "thread_register fail ret=%d\n", ret);
         posix_api->close_fn(sockfd);
         g_data_fd = -1;
         return -1;
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index da6eda0..966507f 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -75,15 +75,20 @@ int32_t thread_affinity_default(void)
 {
     static cpu_set_t cpuset;
     static bool first_flags = true;
+    int ret = 0;
     if (first_flags) {
         CPU_ZERO(&cpuset);
-        if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) != 0) {
+        ret = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
+        if (ret != 0) {
+            LSTACK_LOG(ERR, LSTACK, "pthread_getaffinity_np fail ret=%d\n", ret);
             return -1;
         }
         first_flags = false;
     } else {
         /* cancel the core binding from DPDK initialization */
-        if (pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) != 0) {
+        ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
+        if (ret != 0) {
+            LSTACK_LOG(ERR, LSTACK, "pthread_setaffinity_np fail ret=%d\n", ret);
             return -1;
         }
     }
@@ -167,6 +172,7 @@ static struct rte_mempool* get_pktmbuf_mempool(const char *name, uint16_t queue_
 
     ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id);
     if (ret < 0) {
+        LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret);
         return NULL;
     }
     pool = rte_mempool_lookup(pool_name);
@@ -185,6 +191,7 @@ static struct reg_ring_msg *create_reg_mempool(const char *name, uint16_t queue_
 
     ret = snprintf_s(pool_name, sizeof(pool_name), PATH_MAX - 1, "%s_%hu", name, queue_id);
     if (ret < 0) {
+        LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret);
         return NULL;
     }
 
@@ -205,12 +212,14 @@ int32_t pktmbuf_pool_init(struct protocol_stack *stack, uint16_t stack_num)
 
     stack->rxtx_pktmbuf_pool = get_pktmbuf_mempool("rxtx_mbuf", stack->queue_id);
     if (stack->rxtx_pktmbuf_pool == NULL) {
+        LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n");
         return -1;
     }
 
     if (use_ltran()) {
         stack->reg_buf = create_reg_mempool("reg_ring_msg", stack->queue_id);
         if (stack->reg_buf == NULL) {
+            LSTACK_LOG(ERR, LSTACK, "rxtx_pktmbuf_pool is NULL\n");
             return -1;
         }
     }
@@ -226,6 +235,7 @@ struct rte_mempool *create_mempool(const char *name, uint32_t count, uint32_t si
     int32_t ret = snprintf_s(pool_name, sizeof(pool_name), RTE_MEMPOOL_NAMESIZE - 1,
         "%s_%d", name, idx);
     if (ret < 0) {
+        LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret);
         return NULL;
     }
 
@@ -246,6 +256,7 @@ struct rte_ring *create_ring(const char *name, uint32_t count, uint32_t flags, i
     int32_t ret = snprintf_s(ring_name, sizeof(ring_name), RTE_RING_NAMESIZE - 1,
         "%s_%d_%d", name, get_global_cfg_params()->process_idx,  queue_id);
     if (ret < 0) {
+        LSTACK_LOG(ERR, LSTACK, "snprintf_s fail ret=%d\n", ret);
         return NULL;
     }
 
@@ -286,6 +297,8 @@ int32_t dpdk_alloc_pktmbuf(struct rte_mempool *pool, struct rte_mbuf **mbufs, ui
 {
     int32_t ret = rte_pktmbuf_alloc_bulk(pool, mbufs, num);
     if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "rte_pktmbuf_alloc_bulk fail allocNum=%d, ret=%d, info:=%s \n",
+                   num, ret, rte_strerror(-ret));
         return ret;
     }
 
@@ -477,6 +490,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port)
     if (get_global_cfg_params()->bond_mode < 0) {
         port_id = ethdev_port_id(get_global_cfg_params()->mac_addr);
         if (port_id < 0) {
+            LSTACK_LOG(ERR, LSTACK, "ethdev_port_id FAIL port_id=%d\n", port_id);
             return port_id;
         }
     }
@@ -589,7 +603,7 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port)
 
         ret = dpdk_ethdev_start();
         if (ret < 0) {
-            LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_start failed\n");
+            LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_start failed ret=%d\n", ret);
             stack_group->eth_params = NULL;
             free(eth_params);
             return ret;
@@ -644,6 +658,7 @@ int32_t dpdk_ethdev_start(void)
     for (int32_t i = 0; i < get_global_cfg_params()->tot_queue_num; i++) {
         ret = dpdk_ethdev_setup(stack_group->eth_params, i);
         if (ret < 0) {
+            LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_setup fail queueid=%d, ret=%d\n", i, ret);
             return ret;
         }
     }
@@ -666,11 +681,13 @@ int32_t dpdk_init_lstack_kni(void)
     struct protocol_stack_group *stack_group = get_protocol_stack_group();
     stack_group->kni_pktmbuf_pool = create_pktmbuf_mempool("kni_mbuf", KNI_NB_MBUF, 0, 0, rte_socket_id());
     if (stack_group->kni_pktmbuf_pool == NULL) {
+        LSTACK_LOG(ERR, LSTACK, "kni_mbuf is NULL\n");
         return -1;
     }
 
     int32_t ret = dpdk_kni_init(stack_group->port_id, stack_group->kni_pktmbuf_pool);
     if (ret < 0) {
+        LSTACK_LOG(ERR, LSTACK, "dpdk_kni_init fail ret=%d\n", ret);
         return -1;
     }
 
@@ -706,18 +723,18 @@ int32_t init_dpdk_ethdev(void)
         }
 
         ret = dpdk_ethdev_init(bond_port_id, 1);
-        if (ret != 0) {
+	if (ret != 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret);
             return -1;
         }
 
         ret = rte_eth_bond_xmit_policy_set(bond_port_id, BALANCE_XMIT_POLICY_LAYER34);
         if (ret < 0) {
-	    LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret);
+            LSTACK_LOG(ERR, LSTACK, "dpdk set bond xmit policy failed ret = %d\n", ret);
             return -1;
         }
 
-	if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) {
+        if (get_global_cfg_params()->bond_mode == BONDING_MODE_8023AD) {
             ret = rte_eth_bond_8023ad_dedicated_queues_enable(bond_port_id);
             if (ret < 0) {
                 LSTACK_LOG(ERR, LSTACK, "dpdk enable 8023 dedicated queues failed ret = %d\n", ret);
@@ -743,7 +760,7 @@ int32_t init_dpdk_ethdev(void)
         }
 
         ret = rte_eth_dev_start(bond_port_id);
-        if (ret < 0) {
+	if (ret < 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret);
             return -1;
         }
-- 
2.27.0

