1 Star 0 Fork 48

hantwofish/lwip

forked from src-openEuler/lwip 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0156-cleancode-refactor-memp.patch 20.92 KB
一键复制 编辑 原始数据 按行查看 历史
LemmyHuang 提交于 2024-07-19 17:18 . cleancode: refactor memp
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
From a7fe9f4e87e1ec6333ac374875fc97e6d9c86868 Mon Sep 17 00:00:00 2001
From: Lemmy Huang <huangliming5@huawei.com>
Date: Fri, 12 Jul 2024 14:36:46 +0800
Subject: [PATCH] cleancode: refactor memp
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
---
src/api/sys_arch.c | 158 +++++++++++++++++++++---------------
src/core/init.c | 22 ++---
src/core/mem.c | 7 ++
src/core/memp.c | 10 ++-
src/include/arch/cc.h | 61 ++++++--------
src/include/arch/sys_arch.h | 72 ++++++++++------
src/include/lwip/memp.h | 19 +----
src/include/lwipgz_log.h | 8 +-
src/include/lwipgz_memp.h | 77 ------------------
src/include/lwipgz_sock.h | 2 -
10 files changed, 196 insertions(+), 240 deletions(-)
delete mode 100644 src/include/lwipgz_memp.h
diff --git a/src/api/sys_arch.c b/src/api/sys_arch.c
index dfcdc2f..cb4716f 100644
--- a/src/api/sys_arch.c
+++ b/src/api/sys_arch.c
@@ -40,11 +40,14 @@
#include <rte_cycles.h>
#include "lwip/err.h"
-#include "lwip/memp.h"
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "arch/sys_arch.h"
+#include "lwipgz_sock.h"
+
+#define MBOX_NAME_PREFIX "_mbox_0x"
+#define MAX_MBOX_NAME_LEN (sizeof(MBOX_NAME_PREFIX) + 32) // log(UINT64_MAX) < 32
static u64_t g_sys_cycles_per_ms = 0;
static u64_t g_sys_cycles_per_us = 0;
@@ -52,7 +55,7 @@ static u64_t g_sys_cycles_per_us = 0;
/*
* Timer
* */
-void sys_timer_init(void)
+static void sys_timer_init(void)
{
u64_t freq = rte_get_tsc_hz();
if (g_sys_cycles_per_ms == 0) {
@@ -75,43 +78,63 @@ u64_t sys_now_us(void)
void sys_timer_run(void)
{
- u32_t sleeptime;
+ u32_t sleeptime;
- sleeptime = sys_timeouts_sleeptime();
- if (sleeptime == 0) {
- sys_check_timeouts();
- }
+ sleeptime = sys_timeouts_sleeptime();
+ if (sleeptime == 0) {
+ sys_check_timeouts();
+ }
}
-struct sys_mutex {
- volatile unsigned int m;
-};
+/*
+ * Threads
+ * */
+int thread_create(const char *name, unsigned id, thread_fn func, void *arg)
+{
+ int ret;
+ pthread_t tid;
+ char thread_name[SYS_NAME_LEN];
-struct sys_mutex lstack_mutex;
+ ret = pthread_create(&tid, NULL, func, arg);
+ if (ret != 0) {
+ LWIP_DEBUGF(SYS_DEBUG, ("thread_create: pthread_create failed\n"));
+ return ret;
+ }
-struct sys_sem lstack_sem;
+ SYS_FORMAT_NAME(thread_name, sizeof(thread_name), "%s_%02u", name, id);
+ ret = pthread_setname_np(tid, thread_name);
+ if (ret != 0) {
+ LWIP_DEBUGF(SYS_DEBUG, ("thread_create: pthread_setname_np %s failed\n", thread_name));
+ }
+ return 0;
+}
-#define MAX_THREAD_NAME 64
-#define MBOX_NAME_PREFIX "_mbox_0x"
-#define MAX_MBOX_NAME_LEN (sizeof(MBOX_NAME_PREFIX) + 32) // log(UINT64_MAX) < 32
+sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio)
+{
+ int ret;
+ sys_thread_t thread;
-struct sys_thread {
- struct sys_thread *next;
- char name[MAX_THREAD_NAME];
- lwip_thread_fn fn;
- void *arg;
- int stacksize;
- int prio;
- pthread_t tid;
-};
+ thread = (sys_thread_t)malloc(sizeof(*thread));
+ if (thread == NULL) {
+ LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: malloc sys_thread failed\n"));
+ return NULL;
+ }
+ ret = thread_create(name, 0, (thread_fn)function, arg);
+ if (ret != 0) {
+ free(thread);
+ return NULL;
+ }
-struct sys_mem_stats {
- uint32_t tot_len;
-};
+ SYS_FORMAT_NAME(thread->name, sizeof(thread->name), "%s", name);
+ thread->stacksize = stacksize;
+ thread->prio = prio;
+
+ return thread;
+}
-static PER_THREAD struct sys_mem_stats hugepage_stats;
+extern int eth_dev_poll(void);
/*
* Mailbox
* */
@@ -277,38 +300,6 @@ int sys_mbox_empty(struct sys_mbox *mb)
return rte_ring_count(mb->ring) == 0;
}
-/*
- * Threads
- * */
-sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio)
-{
- int err;
- pthread_t tid;
- struct sys_thread *thread;
-
- thread = (struct sys_thread *)malloc(sizeof(struct sys_thread));
- if (thread == NULL) {
- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: malloc sys_thread failed\n"));
- rte_exit(EXIT_FAILURE, "malloc sys_thread failed\n");
- }
-
- err = pthread_create(&tid, NULL, (void*(*)(void *))function, arg);
- if (err > 0) {
- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_create failed\n"));
- rte_exit(EXIT_FAILURE, "pthread_create failed\n");
- }
-
- err = pthread_setname_np(tid, name);
- if (err > 0) {
- LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: pthread_setname_np failed\n"));
- }
- thread->tid = tid;
- thread->stacksize = stacksize;
- thread->prio = prio;
-
- return thread;
-}
-
/*
* Semaphore
* */
@@ -379,7 +370,7 @@ uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout)
void sys_sem_free(struct sys_sem **s)
{
- if ((s != NULL) && (*s != SYS_SEM_NULL))
+ if ((s != NULL) && (*s != NULL))
memp_free(MEMP_SYS_SEM, *s);
}
@@ -416,20 +407,55 @@ void sys_arch_unprotect(sys_prot_t pval)
}
/*
- * Hugepage memory manager
+ * Memory
* */
-uint8_t *sys_hugepage_malloc(const char *name, uint32_t size)
+u8_t *sys_hugepage_malloc(const char *name, unsigned size)
{
const struct rte_memzone *mz;
+ char memname[PATH_MAX];
- mz = rte_memzone_reserve(name, size, rte_socket_id(), 0);
+ SYS_FORMAT_NAME(memname, sizeof(memname), "%s_%d", name, rte_gettid());
+ mz = rte_memzone_reserve(memname, size, rte_socket_id(), 0);
if (mz == NULL) {
- LWIP_DEBUGF(SYS_DEBUG, ("sys_hugepage_malloc: failed to reserve memory for mempool\n"));
+ LWIP_DEBUGF(SYS_DEBUG, ("sys_hugepage_malloc: failed to reserver memory for mempool[%s]\n", name));
+ set_errno(ENOMEM);
return NULL;
}
memset(mz->addr, 0, mz->len);
- hugepage_stats.tot_len += mz->len;
return (uint8_t*)mz->addr;
}
+
+void sys_mempool_var_init(struct memp_desc *memp, char *desc, u16_t size, u16_t num,
+ u8_t *base, struct memp **tab, struct stats_mem *stats)
+{
+ LWIP_DEBUGF(SYS_DEBUG, ("[tid %u] %s: memp %p desc %s size %u num %u base %p\n",
+ rte_gettid(), __FUNCTION__, memp, desc, size, num, base));
+
+#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY
+ memp->desc = desc;
+#endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */
+#if MEMP_STATS
+ LWIP_ASSERT("stats != NULL", stats != NULL);
+ memp->stats = stats;
+#endif
+
+ memp->size = size;
+
+#if !MEMP_MEM_MALLOC
+ LWIP_ASSERT("base != NULL", base != NULL);
+ memp->num = num;
+ memp->base = base;
+ memp->tab = tab;
+#endif /* MEMP_MEM_MALLOC */
+}
+
+/* Using errno to return lwip_init() result,
+ * mem_init() and memp_init() will set failed errno.
+ */
+void sys_init(void)
+{
+ set_errno(0);
+ sys_timer_init();
+}
diff --git a/src/core/init.c b/src/core/init.c
index bb24092..dbe89d7 100644
--- a/src/core/init.c
+++ b/src/core/init.c
@@ -61,10 +61,6 @@
#include "netif/ppp/ppp_opts.h"
#include "netif/ppp/ppp_impl.h"
-#if GAZELLE_ENABLE
-#include "lwipgz_memp.h"
-#endif /* GAZELLE_ENABLE */
-
#ifndef LWIP_SKIP_PACKING_CHECK
#ifdef PACK_STRUCT_USE_INCLUDES
@@ -355,22 +351,22 @@ lwip_init(void)
LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);
#endif
-#if GAZELLE_ENABLE
- sys_timer_init();
- if (hugepage_init() != 0) {
- rte_exit(EXIT_FAILURE, "hugepage init failed\n");
- }
-#endif /* GAZELLE_ENABLE */
-
/* Modules initialization */
stats_init();
-
+#if !NO_SYS
+ sys_init();
+#endif /* !NO_SYS */
mem_init();
memp_init();
+#if GAZELLE_ENABLE
+ /* mem_init() and memp_init() will set failed errno. */
+ if (errno != 0)
+ return;
+#endif /* GAZELLE_ENABLE */
pbuf_init();
#if !GAZELLE_ENABLE
netif_init();
-#endif /* GAZELLE_ENABLE */
+#endif /* GAZELLE_ENABLE */
#if LWIP_IPV4
ip_init();
#if LWIP_ARP
diff --git a/src/core/mem.c b/src/core/mem.c
index 3522825..b5e50c0 100644
--- a/src/core/mem.c
+++ b/src/core/mem.c
@@ -515,6 +515,13 @@ plug_holes(struct mem *mem)
void
mem_init(void)
{
+#if GAZELLE_ENABLE
+ /* see LWIP_RAM_HEAP_POINTER */
+ LWIP_MEMORY_INIT_VAR(LWIP_RAM_HEAP_POINTER, MEM_SIZE_ALIGNED + (2U * SIZEOF_STRUCT_MEM));
+ if (errno != 0)
+ return;
+#endif /* GAZELLE_ENABLE */
+
struct mem *mem;
LWIP_ASSERT("Sanity check alignment",
diff --git a/src/core/memp.c b/src/core/memp.c
index fca1b0c..6c858be 100644
--- a/src/core/memp.c
+++ b/src/core/memp.c
@@ -80,7 +80,7 @@
#if GAZELLE_ENABLE
PER_THREAD struct memp_desc* memp_pools[MEMP_MAX] = {NULL};
-#else
+#else /* GAZELLE_ENABLE */
const struct memp_desc *const memp_pools[MEMP_MAX] = {
#define LWIP_MEMPOOL(name,num,size,desc) &memp_ ## name,
#include "lwip/priv/memp_std.h"
@@ -227,6 +227,14 @@ memp_init_pool(const struct memp_desc *desc)
void
memp_init(void)
{
+#if GAZELLE_ENABLE
+#define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_INIT_VAR(name,num,size,desc)
+#include "lwip/priv/memp_std.h"
+
+ if (errno != 0)
+ return;
+#endif /* GAZELLE_ENABLE */
+
u16_t i;
/* for every pool: */
diff --git a/src/include/arch/cc.h b/src/include/arch/cc.h
index 9fc6089..8527b44 100644
--- a/src/include/arch/cc.h
+++ b/src/include/arch/cc.h
@@ -30,52 +30,39 @@
*
*/
-#ifndef _LWIP_ARCH_CC_H_
-#define _LWIP_ARCH_CC_H_
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <sys/types.h>
+#ifndef __LWIP_ARCH_CC_H__
+#define __LWIP_ARCH_CC_H__
#include "lwipgz_log.h"
+#ifndef LWIP_RAND
+#define LWIP_RAND() ((uint32_t)rand())
+#endif
+
#define LWIP_NOASSERT
#define LWIP_ERRNO_STDINCLUDE 1
-#define MEMP_MEMORY_BASE_PLACEHOLDER 0
-#define MEMZONE_NAMESIZE 32
-#define LWIP_RAND() ((uint32_t)rand())
+#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \
+ static PER_THREAD u8_t *variable_name;
-extern uint8_t *sys_hugepage_malloc(const char *name, uint32_t size);
+#define LWIP_MEMORY_INIT_VAR(name, size) \
+ name = sys_hugepage_malloc(#name, size);
-#define LWIP_DECLARE_MEMP_BASE_ALIGNED(name, __size)\
-PER_THREAD uint8_t *memp_memory_##name##_base; \
-void alloc_memp_##name##_base(void) \
-{ \
- memp_ ## name.desc = memp_desc_ ## name; \
- memp_ ## name.stats = &memp_stat ## name; \
- memp_ ## name.size = memp_size ## name; \
- memp_ ## name.num = memp_num ## name; \
- memp_ ## name.tab = &memp_tab_ ## name; \
- memp_pools[MEMP_##name] = &memp_ ## name; \
- \
- char mpname[MEMZONE_NAMESIZE] = {0}; \
- snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", (int)syscall(SYS_gettid), #name); \
- memp_memory_##name##_base = \
- sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(__size)); \
- memp_pools[MEMP_##name]->base = memp_memory_##name##_base; \
-}
+#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
+ LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, 0); \
+ static PER_THREAD struct stats_mem memp_stat_ ## name; \
+ static PER_THREAD struct memp *memp_tab_ ## name; \
+ \
+ PER_THREAD struct memp_desc memp_ ## name;
-#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) \
-PER_THREAD uint8_t *variable_name; \
-void alloc_memory_##variable_name(void) \
-{ \
- char mpname[MEMZONE_NAMESIZE] = {0}; \
- snprintf(mpname, MEMZONE_NAMESIZE, "%d_%s", (int)syscall(SYS_gettid), #variable_name); \
- (variable_name) = \
- sys_hugepage_malloc(mpname, LWIP_MEM_ALIGN_BUFFER(size)); \
-}
+#define LWIP_MEMPOOL_INIT_VAR(name,num,size,desc) \
+ memp_memory_ ## name ## _base = sys_hugepage_malloc(#name, LWIP_MEM_ALIGN_BUFFER((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \
+ sys_mempool_var_init(&memp_ ## name, \
+ desc, size, num, \
+ memp_memory_ ## name ## _base, \
+ &memp_tab_ ## name, \
+ &memp_stat_ ## name); \
+ memp_pools[MEMP_ ## name] = &memp_ ## name;
#endif /* _LWIP_ARCH_CC_H_ */
diff --git a/src/include/arch/sys_arch.h b/src/include/arch/sys_arch.h
index 04ef282..55c204f 100644
--- a/src/include/arch/sys_arch.h
+++ b/src/include/arch/sys_arch.h
@@ -33,56 +33,76 @@
#ifndef _LWIP_ARCH_SYS_ARCH_H_
#define _LWIP_ARCH_SYS_ARCH_H_
-#include <rte_cycles.h>
-#include <rte_debug.h>
+#include <stdio.h>
+#include <string.h>
-#define SYS_MBOX_NULL NULL
-#define SYS_SEM_NULL NULL
-typedef uint32_t sys_prot_t;
+#include "lwip/debug.h"
+#include "lwip/memp.h"
-struct sys_sem {
- volatile unsigned int c;
- int (*wait_fn)(void);
+#define SYS_NAME_LEN 64
+
+struct sys_thread {
+ struct sys_thread *next;
+ char name[SYS_NAME_LEN];
+ void *arg;
+ int stacksize;
+ int prio;
};
+typedef struct sys_thread *sys_thread_t;
+typedef void *(*thread_fn)(void *arg);
+int thread_create(const char *name, unsigned id, thread_fn func, void *arg);
-#define MBOX_NAME_LEN 64
-struct sys_mbox {
- struct rte_ring *ring;
- char name[MBOX_NAME_LEN];
- int size;
- int socket_id;
- unsigned flags;
+
+struct sys_sem {
+ volatile unsigned int c;
int (*wait_fn)(void);
};
-
typedef struct sys_sem *sys_sem_t;
#define sys_sem_valid(sem) (((sem) != NULL) && (*(sem) != NULL))
-#define sys_sem_valid_val(sem) ((sem) != NULL)
#define sys_sem_set_invalid(sem) do { if ((sem) != NULL) { *(sem) = NULL; }} while(0)
-#define sys_sem_set_invalid_val(sem) do { (sem) = NULL; } while(0)
-struct sys_mutex;
+
+struct sys_mutex {
+ volatile unsigned int m;
+};
typedef struct sys_mutex *sys_mutex_t;
#define sys_mutex_valid(mutex) sys_sem_valid(mutex)
#define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex)
+
+struct sys_mbox {
+ char name[SYS_NAME_LEN];
+ int size;
+ int socket_id;
+ unsigned flags;
+ struct rte_ring *ring;
+ int (*wait_fn)(void);
+};
typedef struct sys_mbox *sys_mbox_t;
#define sys_mbox_valid(mbox) sys_sem_valid(mbox)
-#define sys_mbox_valid_val(mbox) sys_sem_valid_val(mbox)
#define sys_mbox_set_invalid(mbox) sys_sem_set_invalid(mbox)
-#define sys_mbox_set_invalid_val(mbox) sys_sem_set_invalid_val(mbox)
int sys_mbox_empty(struct sys_mbox *);
-struct sys_thread;
-typedef struct sys_thread *sys_thread_t;
+typedef uint32_t sys_prot_t;
+
+u8_t *sys_hugepage_malloc(const char *name, unsigned size);
+void sys_mempool_var_init(struct memp_desc *memp, char *desc, u16_t size, u16_t num,
+ u8_t *base, struct memp **tab, struct stats_mem *stats);
-void sys_timer_init(void);
void sys_timer_run(void);
u32_t sys_now(void);
u64_t sys_now_us(void);
+#define SYS_FORMAT_NAME(buf, size, fmt, ...) \
+ do { \
+ int ret = snprintf(buf, size, ""fmt"", ##__VA_ARGS__); \
+ if (ret < 0) { \
+ LWIP_DEBUGF(SYS_DEBUG, ("%s:%d: sprintf failed\n", __FUNCTION__, __LINE__)); \
+ (void)memset((void *)buf, 0, size); \
+ } \
+ } while(0)
+
#if GAZELLE_ENABLE
-extern int eth_dev_poll(void);
#include <rte_ring.h>
#include "dpdk_version.h"
@@ -132,6 +152,6 @@ static __rte_always_inline uint32_t gazelle_st_ring_dequeue_burst(struct rte_rin
void gazelle_ring_free_fast(struct rte_ring *ring);
struct rte_ring *gazelle_ring_create_fast(const char *name, uint32_t size, uint32_t flags);
-#endif
+#endif /* GAZELLE_ENABLE */
#endif /* _LWIP_ARCH_SYS_ARCH_H_ */
diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h
index 1763836..d660e9f 100644
--- a/src/include/lwip/memp.h
+++ b/src/include/lwip/memp.h
@@ -60,9 +60,10 @@ typedef enum {
#if GAZELLE_ENABLE
extern PER_THREAD struct memp_desc* memp_pools[MEMP_MAX];
-#else
+#include "arch/cc.h"
+#else /* GAZELLE_ENABLE */
+
extern const struct memp_desc* const memp_pools[MEMP_MAX];
-#endif /* GAZELLE_ENABLE */
/**
* @ingroup mempool
@@ -96,18 +97,6 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
* To relocate a pool, declare it as extern in cc.h. Example for GCC:
* extern u8_t \_\_attribute\_\_((section(".onchip_mem"))) memp_memory_my_private_pool_base[];
*/
-#if GAZELLE_ENABLE
-#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
- PER_THREAD struct memp_desc memp_ ## name = {0}; \
- PER_THREAD char memp_desc_ ## name[] = desc; \
- PER_THREAD struct stats_mem memp_stat ## name = {0}; \
- PER_THREAD u16_t memp_size ## name = size; \
- PER_THREAD u16_t memp_num ## name = num; \
- PER_THREAD struct memp *memp_tab_ ## name = NULL; \
- LWIP_DECLARE_MEMP_BASE_ALIGNED(name, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size))));
-
-#else /* GAZELLE_ENABLE */
-
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \
\
@@ -124,8 +113,8 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
&memp_tab_ ## name \
};
-#endif /* GAZELLE_ENABLE */
#endif /* MEMP_MEM_MALLOC */
+#endif /* GAZELLE_ENABLE */
/**
* @ingroup mempool
diff --git a/src/include/lwipgz_log.h b/src/include/lwipgz_log.h
index 9e01a5f..db844af 100644
--- a/src/include/lwipgz_log.h
+++ b/src/include/lwipgz_log.h
@@ -33,14 +33,16 @@
#ifndef __LWIPGZ_LOG__
#define __LWIPGZ_LOG__
+#include <errno.h>
#include <stdio.h>
-#include <sys/syscall.h>
-#include <unistd.h>
+#include <stdlib.h>
#include <rte_log.h>
#include "lwipopts.h"
+#define set_errno(err) do { errno = (err); } while(0)
+
#if GAZELLE_USE_DPDK_LOG
#define LWIP_LOG_WARN LWIP_DBG_LEVEL_WARNING
@@ -72,7 +74,7 @@ do { \
do { LWIP_PLATFORM_LOG(LWIP_LOG_FATAL, "Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); abort();} while(0)
-#else
+#else /* GAZELLE_USE_DPDK_LOG */
#define LWIP_PLATFORM_LOG(debug, message)
diff --git a/src/include/lwipgz_memp.h b/src/include/lwipgz_memp.h
deleted file mode 100644
index e1a2873..0000000
--- a/src/include/lwipgz_memp.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Huawei Technologies
- *
- */
-
-#ifndef __LWIPGZ_MEMP_H__
-#define __LWIPGZ_MEMP_H__
-
-#include "lwip/opt.h"
-#include "arch/cc.h"
-
-#define LWIP_MEMPOOL_BASE_DECLARE(name) \
- extern void alloc_memp_##name##_base(void);
-
-#define LWIP_MEM_MEMORY_DECLARE(name) \
- extern void alloc_memory_##name(void);
-
-#define LWIP_MEMPOOL_BASE_INIT(name) \
- alloc_memp_##name##_base();
-
-#define LWIP_MEM_MEMORY_INIT(name) \
- alloc_memory_##name();
-
-#define LWIP_MEMPOOL(name, num, size, desc) LWIP_MEMPOOL_BASE_DECLARE(name)
-#include <lwip/priv/memp_std.h>
-#undef LWIP_MEMPOOL
-
-extern PER_THREAD uint8_t *ram_heap;
-static inline int hugepage_init(void)
-{
-#define LWIP_MEMPOOL(name,num,size,desc) LWIP_MEMPOOL_BASE_INIT(name)
-#include "lwip/priv/memp_std.h"
- u16_t i;
- for (i = 0; i < LWIP_ARRAYSIZE(memp_pools); i++) {
- if (memp_pools[i]->base == NULL) {
- return -1;
- }
- }
-
-#if !MEM_LIBC_MALLOC
- LWIP_MEM_MEMORY_DECLARE(ram_heap)
- LWIP_MEM_MEMORY_INIT(ram_heap)
- if (ram_heap == NULL) {
- return -1;
- }
-#endif /* MEM_LIBC_MALLOC */
- return 0;
-}
-
-#endif /* __LWIPGZ_MEMP_H__ */
diff --git a/src/include/lwipgz_sock.h b/src/include/lwipgz_sock.h
index 16b5e85..e0fe7c8 100644
--- a/src/include/lwipgz_sock.h
+++ b/src/include/lwipgz_sock.h
@@ -42,8 +42,6 @@
#include <rte_memzone.h>
#include "lwipgz_event.h"
-#define set_errno(err) do { errno = (err); } while(0)
-
enum posix_type {
POSIX_KERNEL = 0x100,
POSIX_LWIP = 0x200,
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hantwofish/lwip.git
git@gitee.com:hantwofish/lwip.git
hantwofish
lwip
lwip
master

搜索帮助