aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/adapt/nstack_dmm_adpt.c38
-rw-r--r--src/adapt/nstack_epoll_comm.c255
-rw-r--r--src/adapt/nstack_share_res.c88
-rw-r--r--src/adapt/nstack_share_res.h15
-rw-r--r--src/framework/CMakeLists.txt12
-rw-r--r--src/framework/common/base/include/common/common_func.h115
-rw-r--r--src/framework/common/base/include/common/common_mem_api.h143
-rw-r--r--src/framework/common/base/include/common/common_mem_base_type.h85
-rw-r--r--src/framework/common/base/include/common/common_mem_buf.h76
-rw-r--r--src/framework/common/base/include/common/common_mem_common.h25
-rw-r--r--src/framework/common/base/include/common/common_mem_malloc.h25
-rw-r--r--src/framework/common/base/include/common/common_mem_mbuf.h40
-rw-r--r--src/framework/common/base/include/common/common_mem_mempool.h25
-rw-r--r--src/framework/common/base/include/common/common_mem_memzone.h25
-rw-r--r--src/framework/common/base/include/common/common_mem_pal.h30
-rw-r--r--src/framework/common/base/include/common/common_mem_pal_memconfig.h26
-rw-r--r--src/framework/common/base/include/common/common_mem_spinlock.h40
-rw-r--r--src/framework/common/base/include/common/common_sys_config.h46
-rw-r--r--src/framework/common/base/include/common/generic/common_mem_rwlock.h25
-rw-r--r--src/framework/common/base/include/common_pal_bitwide_adjust.h202
-rw-r--r--src/framework/common/base/liblinuxapi/nsfw_lock_file.c2
-rw-r--r--src/framework/common/data_struct/eprb_tree.c185
-rw-r--r--src/framework/common/dmm_sys.c (renamed from src/framework/lib_common_mem/common_api.c)126
-rw-r--r--src/framework/common/include/dmm_sys.h44
-rw-r--r--src/framework/common/include/ephlist.h48
-rw-r--r--src/framework/common/include/eprb_tree.h9
-rw-r--r--src/framework/common/include/generic/dmm_atomic.h40
-rw-r--r--src/framework/common/include/generic/dmm_spinlock.h22
-rw-r--r--src/framework/common/mem_mgr/include/nsfw_mem_desc.h172
-rw-r--r--src/framework/common/mem_mgr/include/nsfw_ring_data.h95
-rw-r--r--src/framework/common/mem_mgr/include/nsfw_ring_fun.h110
-rw-r--r--src/framework/common/mem_mgr/nsfw_mem_api.c879
-rw-r--r--src/framework/common/mem_mgr/nsfw_mem_construct.c21
-rw-r--r--src/framework/common/mem_mgr/nsfw_mem_desc.c92
-rw-r--r--src/framework/common/mem_mgr/nsfw_mem_stat.c292
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.c47
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.h22
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.c544
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.h70
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.c437
-rw-r--r--src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.h37
-rw-r--r--src/framework/common/mem_mgr/nsfw_res_mgr.c429
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.c987
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.h51
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.c47
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.h22
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c821
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.h133
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.c839
-rw-r--r--src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.h60
-rw-r--r--src/framework/hal/hal.c5
-rw-r--r--src/framework/hal/hal.h1
-rw-r--r--src/framework/include/dmm_common.h76
-rw-r--r--src/framework/include/dmm_config.h16
-rw-r--r--src/framework/include/nsfw_fd_timer_api.h4
-rw-r--r--src/framework/include/nsfw_mem_api.h546
-rw-r--r--src/framework/include/nsfw_mgr_com_api.h2
-rw-r--r--src/framework/include/nsfw_ps_mem_api.h36
-rw-r--r--src/framework/include/nsfw_recycle_api.h2
-rw-r--r--src/framework/include/nstack_log.h1
-rw-r--r--src/framework/include/nstack_securec.h11
-rw-r--r--src/framework/init/CMakeLists.txt6
-rw-r--r--src/framework/init/fw_init.c39
-rw-r--r--src/framework/init/fw_module.c6
-rw-r--r--src/framework/ipc/mgr_com/mgr_com.c65
-rw-r--r--src/framework/ipc/mgr_com/mgr_com.h24
-rw-r--r--src/framework/ipc/ps/nsfw_fd_timer.c38
-rw-r--r--src/framework/ipc/ps/nsfw_ps_mem_module.c924
-rw-r--r--src/framework/ipc/ps/nsfw_ps_mem_module.h87
-rw-r--r--src/framework/ipc/ps/nsfw_ps_module.c50
-rw-r--r--src/framework/ipc/ps/nsfw_ps_module.h6
-rw-r--r--src/framework/ipc/ps/nsfw_recycle_module.c93
-rw-r--r--src/framework/ipc/ps/nsfw_recycle_module.h6
-rw-r--r--src/framework/ipc/ps/nsfw_soft_param.c4
-rw-r--r--src/framework/lib_common_mem/common_buf.c279
-rw-r--r--src/framework/lib_common_mem/common_func.c205
-rw-r--r--src/framework/log/nsfw_set_log.c3
-rw-r--r--src/framework/mem/dmm_fshm.c76
-rw-r--r--src/framework/mem/dmm_group.c46
-rw-r--r--src/framework/mem/dmm_huge.c144
-rw-r--r--src/framework/mem/dmm_memory.c145
-rw-r--r--src/framework/mem/dmm_memory.h55
-rw-r--r--src/framework/mem/dmm_segment.c145
-rw-r--r--src/framework/mem/dmm_segment.h8
-rw-r--r--src/framework/ring/dmm_ring.c94
-rw-r--r--src/framework/ring/dmm_ring.h205
-rw-r--r--src/framework/ring/dmm_ring_base.h189
-rw-r--r--src/nSocket/CMakeLists.txt12
-rw-r--r--src/nSocket/include/nstack_atomic.h57
-rw-r--r--src/nSocket/include/nstack_eventpoll.h26
-rw-r--r--src/nSocket/include/nstack_types.h1
-rw-r--r--src/nSocket/include/select_adapt.h11
-rw-r--r--src/nSocket/nstack/event/epoll/nstack_eventpoll.c174
-rw-r--r--src/nSocket/nstack/event/select/nstack_select.c2
-rw-r--r--src/nSocket/nstack/nstack.c68
-rw-r--r--src/nSocket/nstack/nstack.h20
-rw-r--r--src/nSocket/nstack/nstack_fd_mng.c3
-rw-r--r--src/nSocket/nstack/nstack_fd_mng.h9
-rw-r--r--src/nSocket/nstack/nstack_module.c1
-rw-r--r--src/nSocket/nstack/nstack_nsocket_construct.c5
-rw-r--r--src/nSocket/nstack/nstack_socket.c52
-rw-r--r--src/nSocket/nstack/nstack_socket.h30
-rw-r--r--src/nSocket/nstack_rd/nstack_rd_ip.c2
-rw-r--r--src/nSocket/nstack_rd/nstack_rd_proto.c3
105 files changed, 1747 insertions, 10398 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1069e7f..e7a469d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,20 +14,15 @@
# limitations under the License.
#########################################################################
-if(WITH_HAL_LIB)
-else()
- SET(COMM_CONFIG ${PROJECT_SOURCE_DIR}/src/framework/common/base/include/common/common_sys_config.h)
- #SET(PRI_DIRECTORIES "framework/common/base/include/common/")
-endif()
INCLUDE_DIRECTORIES(
framework/log/
framework/mem
+ framework/ring
framework/include/
framework/common/include/
framework/common/include/arch/${DMM_ARCH}
framework/common/base/include/
- framework/common/base/include/common/
${PRI_DIRECTORIES}
../platform/SecureC/include/
../thirdparty/glog/glog-0.3.4/src/
@@ -40,7 +35,6 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,relro,-z,now -Wl,--disable-new-dtags"
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack -mcmodel=medium")
SET(COMPLE_CONFIG ${PROJECT_SOURCE_DIR}/src/framework/common/include/compile_config.h)
-ADD_DEFINITIONS(-include ${COMM_CONFIG})
ADD_DEFINITIONS(-include ${COMPLE_CONFIG})
ADD_DEFINITIONS(-D_GNU_SOURCE -DNSTACK_GETVER_VERSION="18.07")
#LINK_DIRECTORIES(${LIB_PATH_SHARED} ${LIB_PATH_STATIC})
diff --git a/src/adapt/nstack_dmm_adpt.c b/src/adapt/nstack_dmm_adpt.c
index d497b80..d8138d8 100644
--- a/src/adapt/nstack_dmm_adpt.c
+++ b/src/adapt/nstack_dmm_adpt.c
@@ -21,10 +21,8 @@ extern "C" {
#endif /* __cplusplus */
#include "nsfw_init.h"
-#include "nsfw_mem_api.h"
#include "nsfw_recycle_api.h"
#include "nsfw_mgr_com_api.h"
-#include "nsfw_ps_mem_api.h"
#include "nsfw_ps_api.h"
#include "nsfw_recycle_api.h"
#include "nsfw_fd_timer_api.h"
@@ -34,6 +32,9 @@ extern "C" {
#include "nstack_dmm_adpt.h"
#include "mgr_com.h"
+#include "dmm_sys.h"
+#include "dmm_memory.h"
+
int g_same_process = 1;
extern int nsep_adpt_attach_memory ();
@@ -57,10 +58,9 @@ nstack_event_callback (void *pdata, int events)
NSSOC_LOGDBG ("Got one event]fd=%d,events=%u", epInfo->fd, events);
- sys_arch_lock_with_pid (&epInfo->epiLock);
- struct list_node *fdEpiHead =
- (struct list_node *) ADDR_SHTOL (epInfo->epiList.head);
- struct list_node *node = (struct list_node *) ADDR_SHTOL (fdEpiHead->next);
+ dmm_spin_lock_pid (&epInfo->epiLock);
+ struct list_node *fdEpiHead = epInfo->epiList.head;
+ struct list_node *node = fdEpiHead->next;
struct epitem *epi = NULL;
struct eventpoll *ep = NULL;
while (node)
@@ -68,8 +68,8 @@ nstack_event_callback (void *pdata, int events)
epi = (struct epitem *) ep_list_entry (node, struct epitem, fllink);
- node = (struct list_node *) ADDR_SHTOL (node->next);
- ep = (struct eventpoll *) ADDR_SHTOL (epi->ep);
+ node = node->next;
+ ep = epi->ep;
if (!(epi->event.events & events))
continue;
@@ -79,14 +79,14 @@ nstack_event_callback (void *pdata, int events)
continue;
}
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
if (unlikely (ep->ovflist != NSEP_EP_UNACTIVE_PTR))
{
if (epi->next == NSEP_EP_UNACTIVE_PTR)
{
epi->next = ep->ovflist;
- ep->ovflist = (struct epitem *) ADDR_LTOSH (epi);
+ ep->ovflist = epi;
}
epi->ovf_revents |= events;
NSSOC_LOGDBG ("Add to ovflist]protoFD=%d,event=%d", epInfo->fd,
@@ -100,9 +100,9 @@ nstack_event_callback (void *pdata, int events)
}
epi->revents |= (epi->event.events & events);
out_unlock:
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
}
- sys_sem_s_signal (&epInfo->epiLock);
+ dmm_spin_unlock (&epInfo->epiLock);
/* [Remove fdInf->event_sem post] */
return 0;
}
@@ -110,16 +110,12 @@ nstack_event_callback (void *pdata, int events)
int
nstack_adpt_init (nstack_dmm_para * para)
{
- nsfw_mem_para stinfo = { 0 };
i32 init_ret = 0;
if (!para)
{
return -1;
}
- stinfo.iargsnum = para->argc;
- stinfo.pargs = para->argv;
- stinfo.enflag = para->proc_type;
if (para->deploy_type != NSTACK_MODEL_TYPE1
&& para->deploy_type != NSTACK_MODEL_TYPE_SIMPLE_STACK)
{
@@ -128,15 +124,14 @@ nstack_adpt_init (nstack_dmm_para * para)
nsfw_com_attr_set (para->attr.policy, para->attr.pri);
- (void) nstack_framework_setModuleParam (NSFW_MEM_MGR_MODULE, &stinfo);
+ (void) nstack_framework_setModuleParam (DMM_MEMORY_MODULE,
+ (void *) ((u64) NSFW_PROC_MAIN));
(void) nstack_framework_setModuleParam (NSFW_MGR_COM_MODULE,
(void *) ((u64) para->proc_type));
(void) nstack_framework_setModuleParam (NSFW_TIMER_MODULE,
(void *) ((u64) para->proc_type));
(void) nstack_framework_setModuleParam (NSFW_PS_MODULE,
(void *) ((u64) para->proc_type));
- (void) nstack_framework_setModuleParam (NSFW_PS_MEM_MODULE,
- (void *) ((u64) para->proc_type));
(void) nstack_framework_setModuleParam (NSFW_RECYCLE_MODULE,
(void *) ((u64) para->proc_type));
(void) nstack_framework_setModuleParam (NSFW_RES_MGR_MODULE,
@@ -213,12 +208,11 @@ nstack_init_module (void *para)
}
NSFW_MODULE_NAME (NSTACK_DMM_MODULE)
-NSFW_MODULE_PRIORITY (10)
-NSFW_MODULE_DEPENDS (NSFW_MEM_MGR_MODULE)
+NSFW_MODULE_PRIORITY (70)
+NSFW_MODULE_DEPENDS (DMM_MEMORY_MODULE)
NSFW_MODULE_DEPENDS (NSFW_MGR_COM_MODULE)
NSFW_MODULE_DEPENDS (NSFW_TIMER_MODULE)
NSFW_MODULE_DEPENDS (NSFW_PS_MODULE)
-NSFW_MODULE_DEPENDS (NSFW_PS_MEM_MODULE)
NSFW_MODULE_DEPENDS (NSFW_RECYCLE_MODULE)
NSFW_MODULE_DEPENDS (NSFW_LOG_CFG_MODULE)
NSFW_MODULE_DEPENDS (NSFW_RES_MGR_MODULE)
diff --git a/src/adapt/nstack_epoll_comm.c b/src/adapt/nstack_epoll_comm.c
index 219803c..4ee2a89 100644
--- a/src/adapt/nstack_epoll_comm.c
+++ b/src/adapt/nstack_epoll_comm.c
@@ -15,13 +15,15 @@
*/
#include "nstack_eventpoll.h"
-#include "nsfw_mem_api.h"
#include "nstack_log.h"
#include "nstack_securec.h"
#include "nsfw_recycle_api.h"
#include "nsfw_maintain_api.h"
#include <stdio.h>
+#include <errno.h>
#include <stdlib.h>
+#include "dmm_memory.h"
+#include "dmm_sys.h"
nsep_epollManager_t g_epollMng = {
.infoSockMap = NULL,
@@ -37,7 +39,7 @@ nsep_find_ep (struct eventpoll *ep, int fd)
struct ep_rb_node *rbp;
struct epitem *epi, *epir = NULL;
u32_t loopCnt = 0;
- for (rbp = ADDR_SHTOL (ep->rbr.rb_node); rbp;)
+ for (rbp = (ep->rbr.rb_node); rbp;)
{
++loopCnt;
if (loopCnt > NSTACK_MAX_EPITEM_NUM)
@@ -46,11 +48,11 @@ nsep_find_ep (struct eventpoll *ep, int fd)
epi = (struct epitem *) ep_rb_entry (rbp, struct epitem, rbn);
if (fd > epi->fd)
{
- rbp = (struct ep_rb_node *) ADDR_SHTOL (rbp->rb_right);
+ rbp = (struct ep_rb_node *) (rbp->rb_right);
}
else if (fd < epi->fd)
{
- rbp = (struct ep_rb_node *) ADDR_SHTOL (rbp->rb_left);
+ rbp = (struct ep_rb_node *) (rbp->rb_left);
}
else
{
@@ -72,8 +74,7 @@ nstack_ep_unlink (struct eventpoll *ep, struct epitem *epi)
{
int error = ENOENT;
- if (ep_rb_parent (&epi->rbn) ==
- (struct ep_rb_node *) ADDR_LTOSH_EXT (&epi->rbn))
+ if (ep_rb_parent (&epi->rbn) == &epi->rbn)
{
NSSOC_LOGWAR ("ep_rb_parent == epi->rbn");
return error;
@@ -111,7 +112,7 @@ nsep_free_epitem (struct epitem *data)
return 0;
}
- if (nsfw_mem_ring_enqueue (pool->ring, (void *) epiEntry) != 1)
+ if (1 != dmm_enqueue (pool->ring, (void *) epiEntry))
{
NSSOC_LOGERR ("Error to free epitem");
}
@@ -123,15 +124,14 @@ nsep_initEpInfo (nsep_epollInfo_t * info)
{
int iindex = 0;
EP_LIST_INIT (&info->epiList);
- NSTACK_SEM_MALLOC (info->epiLock, 1);
- NSTACK_SEM_MALLOC (info->freeLock, 1);
+ dmm_spin_init (&info->epiLock);
+ dmm_spin_init (&info->freeLock);
info->rlfd = -1;
info->rmidx = -1;
info->fd = -1;
info->ep = NULL;
info->fdtype = 0;
- info->private_data = NULL;
info->epaddflag = 0;
for (iindex = 0; iindex < NSEP_SMOD_MAX; iindex++)
{
@@ -162,7 +162,7 @@ nsep_alloc_epinfo (nsep_epollInfo_t ** data)
NSSOC_LOGDBG ("epinfo alloc begin");
nsep_infoPool_t *pool = &nsep_getManager ()->infoPool;
- if (0 == nsfw_mem_ring_dequeue (pool->ring, (void *) &head_info)
+ if (1 != dmm_dequeue (pool->ring, (void **) &head_info)
|| NULL == head_info)
{
NSSOC_LOGERR ("epinfo ring alloc failed]pool->ring=%p", pool->ring);
@@ -206,7 +206,7 @@ nsep_free_epinfo (nsep_epollInfo_t * info)
return 0;
}
- if (nsfw_mem_ring_enqueue (pool->ring, (void *) info) != 1)
+ if (1 != dmm_enqueue (pool->ring, (void *) info))
{
NSSOC_LOGERR ("Error to free epinfo");
}
@@ -282,8 +282,8 @@ nsep_init_eventpoll (struct eventpoll *ep)
return -1;
}
- NSTACK_SEM_MALLOC (ep->lock, 1);
- NSTACK_SEM_MALLOC (ep->sem, 1);
+ dmm_spin_init (&ep->lock);
+ dmm_spin_init (&ep->sem);
EP_HLIST_INIT (&ep->rdlist);
ep->ovflist = NSEP_EP_UNACTIVE_PTR;
@@ -321,7 +321,7 @@ nsep_free_eventpoll (struct eventpoll *ep)
return 0;
}
- if (nsfw_mem_ring_enqueue (pool->ring, epEntry) != 1)
+ if (1 != dmm_enqueue (pool->ring, epEntry))
{
NSSOC_LOGERR ("Error to free eventpoll");
}
@@ -342,8 +342,7 @@ nsep_alloc_eventpoll (struct eventpoll **data)
struct eventpoll_pool *pool = &nsep_getManager ()->epollPool;
NSSOC_LOGDBG ("ring:%p alloc eventpool begin", pool->ring);
- if (0 == nsfw_mem_ring_dequeue (pool->ring, (void *) &p_head)
- || NULL == p_head)
+ if (1 != dmm_dequeue (pool->ring, (void **) &p_head) || NULL == p_head)
{
NSSOC_LOGERR ("ring alloc eventpool failed]ring=%p", pool->ring);
return -1;
@@ -371,7 +370,7 @@ NSTACK_STATIC int
nsep_init_epitem (struct epitem *epi)
{
int retVal;
- epi->rbn.rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (&epi->rbn);
+ epi->rbn.rb_parent = &epi->rbn;
EP_HLIST_INIT_NODE (&epi->rdllink);
EP_HLIST_INIT_NODE (&epi->lkFDllink);
epi->nwait = 0;
@@ -389,7 +388,7 @@ nsep_init_epitem (struct epitem *epi)
epi->revents = 0;
epi->ovf_revents = 0;
epi->fd = -1;
- epi->private_data = NULL;
+ epi->epInfo = NULL;
return 0;
}
@@ -408,8 +407,8 @@ nsep_alloc_epitem (struct epitem **data)
NSSOC_LOGDBG ("epitem alloc begin..");
- if (0 == nsfw_mem_ring_dequeue (pool->ring, (void *) &p_head_entry)
- || NULL == p_head_entry)
+ if (1 != dmm_dequeue (pool->ring, (void **) &p_head_entry) ||
+ NULL == p_head_entry)
{
NSSOC_LOGERR ("epitem ring alloc failed]ring=%p", pool->ring);
return -1;
@@ -418,7 +417,7 @@ nsep_alloc_epitem (struct epitem **data)
res_alloc (&p_head_entry->res_chk);
p_head_entry->pid = get_sys_pid ();
- if (nsep_init_epitem ((struct epitem *) p_head_entry))
+ if (nsep_init_epitem (p_head_entry))
{
(void) nsep_free_epitem ((struct epitem *) p_head_entry);
p_head_entry = NULL;
@@ -457,7 +456,7 @@ nsep_epPoolInit (void *addr, size_t length)
for (pos = 0; pos < NSTACK_MAX_EPOLL_INFO_NUM; pos++)
{
pool[pos].pid = 0;
- if (-1 == nsfw_mem_ring_enqueue (manager->epollPool.ring, &pool[pos]))
+ if (1 != dmm_enqueue (manager->epollPool.ring, &pool[pos]))
{
NSSOC_LOGERR ("init fail to enqueue epitem]pos=%u", pos);
return -1;
@@ -488,7 +487,7 @@ nsep_epitemPoolInit (void *addr, size_t length)
for (pos = 0; pos < NSTACK_MAX_EPITEM_NUM; pos++)
{
pool[pos].pid = 0;
- if (-1 == nsfw_mem_ring_enqueue (manager->epitemPool.ring, &pool[pos]))
+ if (1 != dmm_enqueue (manager->epitemPool.ring, &pool[pos]))
{
NSSOC_LOGERR ("init fail to enqueue epitem]pos=%u", pos);
return -1;
@@ -524,7 +523,7 @@ nsep_epInfoPoolInit (void *addr, size_t length)
return -1;
}
- if (-1 == nsfw_mem_ring_enqueue (manager->infoPool.ring, &pool[pos]))
+ if (1 != dmm_enqueue (manager->infoPool.ring, &pool[pos]))
{
NSSOC_LOGERR ("init fail to enqueue epInfo]pos=%u", pos);
return -1;
@@ -538,30 +537,15 @@ nsep_epInfoPoolInit (void *addr, size_t length)
NSTACK_STATIC int
nsep_create_shmem (size_t length, char *name, nsep_shem_initFn_t initFn)
{
- nsfw_mem_zone pmeminfo;
- mzone_handle phandle;
- int ret;
+ void *mem = dmm_locked_map (length, name);
- pmeminfo.ireserv = 0;
- pmeminfo.isocket_id = NSFW_SOCKET_ANY;
- pmeminfo.length = length;
- ret =
- STRCPY_S (pmeminfo.stname.aname, sizeof (pmeminfo.stname.aname), name);
- if (EOK != ret)
- {
- NSSOC_LOGERR ("STRCPY_S failed]name=%s,ret=%d", name, ret);
- return -1;
- }
- pmeminfo.stname.entype = NSFW_SHMEM;
-
- phandle = nsfw_mem_zone_create (&pmeminfo);
- if (NULL == phandle)
+ if (!mem)
{
NSSOC_LOGERR ("create nstack epoll memory failed]name=%s", name);
return -1;
}
- if (0 != initFn ((void *) phandle, length))
+ if (0 != initFn (mem, length))
{
NSSOC_LOGERR ("Fail to init memory]name=%s", name);
return -1;
@@ -573,25 +557,13 @@ nsep_create_shmem (size_t length, char *name, nsep_shem_initFn_t initFn)
NSTACK_STATIC int
nsep_create_epInfoMem ()
{
- nsfw_mem_mring pringinfo;
- pringinfo.enmptype = NSFW_MRING_MPMC;
- pringinfo.isocket_id = NSFW_SOCKET_ANY;
- pringinfo.stname.entype = NSFW_SHMEM;
- pringinfo.usnum = NSTACK_MAX_EPOLL_INFO_NUM;
-
- if (-1 ==
- SPRINTF_S (pringinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPINFO_RING_NAME))
- {
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
- return -1;
- }
-
- mring_handle ring_handle = nsfw_mem_ring_create (&pringinfo);
-
+ struct dmm_ring *ring_handle =
+ dmm_create_ring (NSTACK_MAX_EPOLL_INFO_NUM, DMM_RING_INIT_MPMC,
+ MP_NSTACK_EPINFO_RING_NAME);
if (NULL == ring_handle)
{
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
+ NSSOC_LOGERR ("Error to create ring]name=%s",
+ MP_NSTACK_EPINFO_RING_NAME);
return -1;
}
@@ -606,36 +578,18 @@ nsep_create_epInfoMem ()
NSTACK_STATIC int
nsep_adpt_attach_epInfoMem ()
{
- nsfw_mem_name name;
- name.entype = NSFW_SHMEM;
- name.enowner = NSFW_PROC_MAIN;
-
- if (-1 ==
- SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPINFO_RING_NAME))
- {
- NSSOC_LOGERR ("Error to attach ring]name=%s", name.aname);
- return -1;
- }
- mring_handle ring_handle = nsfw_mem_ring_lookup (&name);
-
+ struct dmm_ring *ring_handle = dmm_lookup (MP_NSTACK_EPINFO_RING_NAME);
if (NULL == ring_handle)
{
- NSSOC_LOGERR ("Error to attach ring]name=%s", name.aname);
+ NSSOC_LOGERR ("Error to attach ring]name=%s",
+ MP_NSTACK_EPINFO_RING_NAME);
return -1;
}
nsep_epollManager_t *manager = nsep_getManager ();
manager->infoPool.ring = ring_handle;
- if (-1 ==
- SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPOLL_INFO_NAME))
- {
- NSSOC_LOGERR ("SPRINTF_S failed]");
- return -1;
- }
- manager->infoPool.pool = nsfw_mem_zone_lookup (&name);
+ manager->infoPool.pool = dmm_lookup (MP_NSTACK_EPOLL_INFO_NAME);
if (NULL == manager->infoPool.pool)
{
NSSOC_LOGERR ("Error to attach memzone]name=%s",
@@ -648,25 +602,14 @@ nsep_adpt_attach_epInfoMem ()
NSTACK_STATIC int
nsep_create_epItemMem ()
{
- nsfw_mem_mring pringinfo;
- pringinfo.enmptype = NSFW_MRING_MPMC;
- pringinfo.isocket_id = NSFW_SOCKET_ANY;
- pringinfo.stname.entype = NSFW_SHMEM;
- pringinfo.usnum = NSTACK_MAX_EPITEM_NUM;
-
- if (-1 ==
- SPRINTF_S (pringinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPITEM_RING_NAME))
- {
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
- return -1;
- }
-
- mring_handle ring_handle = nsfw_mem_ring_create (&pringinfo);
+ struct dmm_ring *ring_handle =
+ dmm_create_ring (NSTACK_MAX_EPITEM_NUM, DMM_RING_INIT_MPMC,
+ MP_NSTACK_EPITEM_RING_NAME);
if (NULL == ring_handle)
{
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
+ NSSOC_LOGERR ("Error to create ring]name=%s",
+ MP_NSTACK_EPITEM_RING_NAME);
return -1;
}
@@ -680,37 +623,19 @@ nsep_create_epItemMem ()
NSTACK_STATIC int
nsep_adpt_attach_epItemMem ()
{
- nsfw_mem_name name;
- name.entype = NSFW_SHMEM;
- name.enowner = NSFW_PROC_MAIN;
-
- if (-1 ==
- SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPITEM_RING_NAME))
- {
- NSSOC_LOGERR ("Error to attach epItemMem]name=%s", name.aname);
- return -1;
- }
-
- mring_handle ring_handle = nsfw_mem_ring_lookup (&name);
+ struct dmm_ring *ring_handle = dmm_lookup (MP_NSTACK_EPITEM_RING_NAME);
if (NULL == ring_handle)
{
- NSSOC_LOGERR ("Error to attach ring]name=%s", name.aname);
+ NSSOC_LOGERR ("Error to attach ring]name=%s",
+ MP_NSTACK_EPITEM_RING_NAME);
return -1;
}
nsep_epollManager_t *manager = nsep_getManager ();
manager->epitemPool.ring = ring_handle;
- if (-1 ==
- SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EPITEM_POOL))
- {
- NSSOC_LOGERR ("SPRINTF_S failed]");
- return -1;
- }
- manager->epitemPool.pool = nsfw_mem_zone_lookup (&name);
+ manager->epitemPool.pool = dmm_lookup (MP_NSTACK_EPITEM_POOL);
if (NULL == manager->epitemPool.pool)
{
NSSOC_LOGERR ("Error to attach memzone]name=%s", MP_NSTACK_EPITEM_POOL);
@@ -722,25 +647,14 @@ nsep_adpt_attach_epItemMem ()
NSTACK_STATIC int
nsep_create_eventpollMem ()
{
- nsfw_mem_mring pringinfo;
- pringinfo.enmptype = NSFW_MRING_MPMC;
- pringinfo.isocket_id = NSFW_SOCKET_ANY;
- pringinfo.stname.entype = NSFW_SHMEM;
- pringinfo.usnum = NSTACK_MAX_EPOLL_NUM;
-
- if (-1 ==
- SPRINTF_S (pringinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EVENTPOOL_RING_NAME))
- {
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
- return -1;
- }
-
- mring_handle ring_handle = nsfw_mem_ring_create (&pringinfo);
+ struct dmm_ring *ring_handle =
+ dmm_create_ring (NSTACK_MAX_EPOLL_NUM, DMM_RING_INIT_MPMC,
+ MP_NSTACK_EVENTPOOL_RING_NAME);
if (NULL == ring_handle)
{
- NSSOC_LOGERR ("Error to create ring]name=%s", pringinfo.stname.aname);
+ NSSOC_LOGERR ("Error to create ring]name=%s",
+ MP_NSTACK_EVENTPOOL_RING_NAME);
return -1;
}
@@ -754,37 +668,17 @@ nsep_create_eventpollMem ()
NSTACK_STATIC int
nsep_adpt_attach_eventpollMem ()
{
- nsfw_mem_name name;
- name.entype = NSFW_SHMEM;
- name.enowner = NSFW_PROC_MAIN;
-
- if (-1 ==
- SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EVENTPOOL_RING_NAME))
- {
- NSSOC_LOGERR ("Error to attach ring]name=%s", name.aname);
- return -1;
- }
-
- mring_handle ring_handle = nsfw_mem_ring_lookup (&name);
-
- if (NULL == ring_handle)
- {
- NSSOC_LOGERR ("Error to create ring]name=%s", name.aname);
- return -1;
- }
-
nsep_epollManager_t *manager = nsep_getManager ();
- manager->epollPool.ring = ring_handle;
- int retVal = SPRINTF_S (name.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MP_NSTACK_EVENTPOLL_POOL);
- if (-1 == retVal)
+ manager->epollPool.ring = dmm_lookup (MP_NSTACK_EVENTPOOL_RING_NAME);
+ if (NULL == manager->epollPool.ring)
{
- NSSOC_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
+ NSSOC_LOGERR ("Error to create ring]name=%s",
+ MP_NSTACK_EVENTPOOL_RING_NAME);
return -1;
}
- manager->epollPool.pool = nsfw_mem_zone_lookup (&name);
+
+ manager->epollPool.pool = dmm_lookup (MP_NSTACK_EVENTPOLL_POOL);
if (NULL == manager->epollPool.pool)
{
NSSOC_LOGERR ("Error to attach memzone]name=%s",
@@ -841,6 +735,7 @@ nsep_adpt_attach_memory ()
int
nsep_adpt_reg_res_mgr ()
{
+/* disable these operation
nsep_epollManager_t *manager = nsep_getManager ();
@@ -874,6 +769,7 @@ nsep_adpt_reg_res_mgr ()
(void) nsfw_res_mgr_reg (&scn_cfg_info);
(void) nsfw_res_mgr_reg (&scn_cfg_item);
(void) nsfw_res_mgr_reg (&scn_cfg_event);
+*/
return 0;
}
@@ -885,10 +781,11 @@ nsep_epitem_remove (nsep_epollInfo_t * pinfo, u32 pid)
struct epitem *epi = NULL;
u32_t i = 0;
int icnt = 0;
- (void) sys_arch_lock_with_pid (&pinfo->epiLock);
+
+ dmm_spin_lock_pid (&pinfo->epiLock);
/*list head must be not null */
- prenode = (struct list_node *) ADDR_SHTOL (pinfo->epiList.head);
- nextnode = (struct list_node *) ADDR_SHTOL (prenode->next);
+ prenode = (struct list_node *) (pinfo->epiList.head);
+ nextnode = (struct list_node *) (prenode->next);
while ((nextnode) && (i++ <= NSTACK_MAX_EPOLL_INFO_NUM))
{
epi = ep_list_entry (nextnode, struct epitem, fllink);
@@ -898,14 +795,14 @@ nsep_epitem_remove (nsep_epollInfo_t * pinfo, u32 pid)
prenode->next = nextnode->next;
nextnode->next = NULL;
(void) nsep_free_epitem (epi);
- nextnode = ADDR_SHTOL (prenode->next);
+ nextnode = (prenode->next);
icnt++;
continue;
}
prenode = nextnode;
- nextnode = ADDR_SHTOL (nextnode->next);
+ nextnode = (nextnode->next);
}
- sys_sem_s_signal (&pinfo->epiLock);
+ dmm_spin_unlock (&pinfo->epiLock);
if (i >= NSTACK_MAX_EPOLL_INFO_NUM)
{
NSSOC_LOGERR ("free pinfo:%p pid:%u, error maybe happen", pinfo, pid);
@@ -925,9 +822,9 @@ nsep_recycle_epfd (void *epinfo, u32 pid)
NSSOC_LOGDBG ("input null, pid:%u", pid);
return;
}
- (void) sys_arch_lock_with_pid (&info->freeLock);
+ (void) dmm_spin_lock_pid (&info->freeLock);
ileftcnt = nsep_del_last_pid (&info->pidinfo, pid);
- sys_sem_s_signal (&info->freeLock);
+ dmm_spin_unlock (&info->freeLock);
/*no pid exist */
if (-1 == ileftcnt)
{
@@ -938,7 +835,7 @@ nsep_recycle_epfd (void *epinfo, u32 pid)
NSSOC_LOGDBG ("recycle epfd:%d epinfo pid:%u begin...", info->fd, pid);
if (0 == ileftcnt)
{
- ep = ADDR_SHTOL (info->ep);
+ ep = (info->ep);
info->ep = NULL;
(void) nsep_free_eventpoll (ep);
(void) nsep_free_epinfo (info);
@@ -1036,14 +933,14 @@ NSTACK_STATIC
{
for (pos = 0; pos < NSTACK_MAX_EPOLL_INFO_NUM; pos++)
{
- if (pid == pool[pos].epiLock.locked)
+ if (pid == pool[pos].epiLock.lock)
{
- pool[pos].epiLock.locked = 0;
+ pool[pos].epiLock.lock = 0;
NSFW_LOGWAR ("epiLock locked]pos=%u,pid=%u", pos, pid);
}
- if (pid == pool[pos].freeLock.locked)
+ if (pid == pool[pos].freeLock.lock)
{
- pool[pos].freeLock.locked = 0;
+ pool[pos].freeLock.lock = 0;
NSFW_LOGWAR ("freelock locked]pos=%u,pid=%u", pos, pid);
}
}
@@ -1054,15 +951,15 @@ NSTACK_STATIC
{
for (pos = 0; pos < NSTACK_MAX_EPOLL_NUM; pos++)
{
- if (pid == ev_pool[pos].lock.locked)
+ if (pid == ev_pool[pos].lock.lock)
{
- ev_pool[pos].lock.locked = 0;
+ ev_pool[pos].lock.lock = 0;
NSFW_LOGWAR ("event_pollLock locked]pos=%u,pid=%u", pos, pid);
}
- if (pid == ev_pool[pos].sem.locked)
+ if (pid == ev_pool[pos].sem.lock)
{
- ev_pool[pos].sem.locked = 0;
+ ev_pool[pos].sem.lock = 0;
NSFW_LOGWAR ("event_pollLock sem]pos=%u,pid=%u", pos, pid);
}
}
diff --git a/src/adapt/nstack_share_res.c b/src/adapt/nstack_share_res.c
index 9466145..a42a8a1 100644
--- a/src/adapt/nstack_share_res.c
+++ b/src/adapt/nstack_share_res.c
@@ -15,7 +15,6 @@
*/
#include "nstack_share_res.h"
-#include "nsfw_mem_api.h"
#include "types.h"
#include "nsfw_recycle_api.h"
#include "nstack_securec.h"
@@ -23,49 +22,30 @@
#include "nsfw_maintain_api.h"
#include "nstack_types.h"
+#include "dmm_memory.h"
+
#define NSTACK_SHARE_FORK_LOCK "share_fork_lock"
typedef struct
{
- common_mem_spinlock_t *fork_share_lock;
+ dmm_spinlock_t *fork_share_lock;
} nstack_share_res;
NSTACK_STATIC nstack_share_res g_nstack_share_res;
-/** global timer tick */
-nstack_tick_info_t g_nstack_timer_tick;
-
NSTACK_STATIC int
nstack_create_share_fork_lock ()
{
- mzone_handle zone;
- nsfw_mem_zone param;
- int ret;
-
- param.isocket_id = -1;
- param.length = sizeof (common_mem_spinlock_t);
- param.stname.entype = NSFW_SHMEM;
-
- ret =
- STRCPY_S (param.stname.aname, NSFW_MEM_NAME_LENGTH,
- NSTACK_SHARE_FORK_LOCK);
- if (EOK != ret)
- {
- NSSOC_LOGERR ("STRCPY_S failed]name=%s,ret=%d", NSTACK_SHARE_FORK_LOCK,
- ret);
- return -1;
- }
-
- zone = nsfw_mem_zone_create (&param);
- if (!zone)
+ g_nstack_share_res.fork_share_lock = (dmm_spinlock_t *)
+ dmm_locked_map (sizeof (dmm_spinlock_t), NSTACK_SHARE_FORK_LOCK);
+ if (!g_nstack_share_res.fork_share_lock)
{
NSSOC_LOGERR ("nsfw_mem_zone_create failed]name=%s",
NSTACK_SHARE_FORK_LOCK);
return -1;
}
- g_nstack_share_res.fork_share_lock = (common_mem_spinlock_t *) zone;
- common_mem_spinlock_init (g_nstack_share_res.fork_share_lock);
+ dmm_spin_init (g_nstack_share_res.fork_share_lock);
NSSOC_LOGDBG ("ok");
return 0;
@@ -74,58 +54,20 @@ nstack_create_share_fork_lock ()
NSTACK_STATIC int
nstack_lookup_share_fork_lock ()
{
- mzone_handle zone;
- nsfw_mem_name param;
-
- param.entype = NSFW_SHMEM;
- param.enowner = NSFW_PROC_MAIN;
- if (STRCPY_S (param.aname, NSFW_MEM_NAME_LENGTH, NSTACK_SHARE_FORK_LOCK) !=
- 0)
- {
- NSSOC_LOGERR ("STRCPY_S failed]name=%s", NSTACK_SHARE_FORK_LOCK);
- return -1;
- }
-
- zone = nsfw_mem_zone_lookup (&param);
- if (!zone)
+ g_nstack_share_res.fork_share_lock = (dmm_spinlock_t *)
+ dmm_lookup (NSTACK_SHARE_FORK_LOCK);
+ if (!g_nstack_share_res.fork_share_lock)
{
NSSOC_LOGERR ("nsfw_mem_zone_lookup failed]name=%s",
NSTACK_SHARE_FORK_LOCK);
return -1;
}
- g_nstack_share_res.fork_share_lock = (common_mem_spinlock_t *) zone;
-
NSSOC_LOGDBG ("ok");
return 0;
}
-NSTACK_STATIC int
-nstack_lookup_share_global_tick ()
-{
- int ret;
- nsfw_mem_name name = {.entype = NSFW_SHMEM,.enowner = NSFW_PROC_MAIN };
-
- ret = STRCPY_S (name.aname, NSFW_MEM_NAME_LENGTH, NSTACK_GLOBAL_TICK_SHM);
- if (EOK != ret)
- {
- NSSOC_LOGERR ("STRCPY_S failed]name=%s,ret=%d", NSTACK_GLOBAL_TICK_SHM,
- ret);
- return -1;
- }
-
- g_nstack_timer_tick.tick_ptr = (u64_t *) nsfw_mem_zone_lookup (&name);
- if (NULL == g_nstack_timer_tick.tick_ptr)
- {
- NSPOL_LOGERR ("Failed to lookup global timer tick memory");
- return -1;
- }
-
- NSSOC_LOGDBG ("ok");
- return 0;
-}
-
int
nstack_init_share_res ()
{
@@ -144,16 +86,16 @@ nstack_attach_share_res ()
{
return -1;
}
-
+#if 0
if (nstack_lookup_share_global_tick () != 0)
{
return -1;
}
-
+#endif
return 0;
}
-common_mem_spinlock_t *
+dmm_spinlock_t *
nstack_get_fork_share_lock ()
{
return g_nstack_share_res.fork_share_lock;
@@ -165,9 +107,9 @@ nstack_recycle_fork_share_lock (u32 exit_pid, void *pdata, u16 rec_type)
NSSOC_LOGDBG ("recycle]pid=%u", exit_pid);
if (g_nstack_share_res.fork_share_lock
- && (g_nstack_share_res.fork_share_lock->locked == exit_pid))
+ && (g_nstack_share_res.fork_share_lock->lock == exit_pid))
{
- common_mem_spinlock_unlock (g_nstack_share_res.fork_share_lock);
+ dmm_spin_unlock (g_nstack_share_res.fork_share_lock);
}
return NSFW_RCC_CONTINUE;
diff --git a/src/adapt/nstack_share_res.h b/src/adapt/nstack_share_res.h
index 2737730..1a6112a 100644
--- a/src/adapt/nstack_share_res.h
+++ b/src/adapt/nstack_share_res.h
@@ -18,9 +18,8 @@
#define NSTACK_SHARE_RES_H
#include <stdint.h>
-#include "common_mem_spinlock.h"
#include "nstack_log.h"
-#include "common_func.h"
+#include "dmm_spinlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -43,19 +42,9 @@ typedef struct unmatch_ver_info
char first_time_stamp[LOG_TIME_STAMP_LEN];
} unmatch_ver_info_t;
-#define DFX_TMR_INTERVAL 60000 /*60 seconds */
-typedef struct nstack_tick_info
-{
- uint64_t *tick_ptr; // tick from shared memory
- uint64_t interval; // tick interval, only used in stack process
- /* tick reference, updated periodically and read in tcpip_thread only */
- struct timeval ref_time; // ref tick time
- uint64_t ref_tick; // ref tick
-} nstack_tick_info_t;
-
int nstack_init_share_res ();
int nstack_attach_share_res ();
-common_mem_spinlock_t *nstack_get_fork_share_lock ();
+dmm_spinlock_t *nstack_get_fork_share_lock ();
#ifdef __cplusplus
/* *INDENT-OFF* */
diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt
index 6b22e51..4d49cdb 100644
--- a/src/framework/CMakeLists.txt
+++ b/src/framework/CMakeLists.txt
@@ -14,12 +14,6 @@
# limitations under the License.
#########################################################################
-if(WITH_HAL_LIB)
-else()
- SET(PAL_H_DIRECTORIES "/usr/include/dpdk/")
- FILE(GLOB_RECURSE LIBCOMM lib_common_mem/*.c)
-endif()
-
FILE(GLOB_RECURSE COMMON common/*.c)
FILE(GLOB INIT init/*.c)
FILE(GLOB_RECURSE IPC ipc/*.c)
@@ -30,11 +24,12 @@ FILE(GLOB MAINTAIN maintain/*.c)
FILE(GLOB HAL hal/*.c)
FILE(GLOB DMM_ADPT ../adapt/*.c)
FILE(GLOB MEM mem/*.c)
+FILE(GLOB RING ring/*.c)
ADD_LIBRARY(dmm_api SHARED
${COMMON} ${INIT} ${IPC} ${LOG} ${SNAPSHOT}
${STARTUP} ${MAINTAIN} ${TRACEING} ${HAL}
- ${DMM_ADPT} ${LIBCOMM} ${MEM})
+ ${DMM_ADPT} ${LIBCOMM} ${MEM} ${RING})
if(WITH_SECUREC_LIB)
ADD_DEPENDENCIES(dmm_api SECUREC JSON GLOG)
@@ -50,9 +45,8 @@ INCLUDE_DIRECTORIES(
ipc/mgr_com/
hal/
include/
- common/base/include/generic
+ ring
common/base/include/
- ${PAL_H_DIRECTORIES}
common/base/liblinuxapi/
common/mem_mgr/include
common/mem_mgr/nsfw_shmem/
diff --git a/src/framework/common/base/include/common/common_func.h b/src/framework/common/base/include/common/common_func.h
deleted file mode 100644
index 2b84b7a..0000000
--- a/src/framework/common/base/include/common/common_func.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _RTE_COMM_FUNC_H_
-#define _RTE_COMM_FUNC_H_
-
-#ifdef HAL_LIB
-
-#else
-
-#define common_mem_rwlock_t rte_rwlock_t
-#define common_mem_spinlock_t rte_spinlock_t
- //typedef rte_rwlock_t common_mem_rwlock_t;
-
-#define nsfw_write_lock(plock) rte_rwlock_write_lock(plock)
-#define nsfw_write_unlock(plock) rte_rwlock_write_unlock(plock)
-#define nsfw_read_lock(plock) rte_rwlock_read_lock(plock)
-#define nsfw_read_unlock(plock) rte_rwlock_read_unlock(plock)
-
-#define common_mem_align32pow2 rte_align32pow2
-
-#define common_mem_atomic32_cmpset rte_atomic32_cmpset
-#define common_mem_pause rte_pause
-
-#define COMMON_MEM_MAX_MEMZONE RTE_MAX_MEMZONE
-
-#define common_mem_atomic32_t rte_atomic32_t
-
-#define common_mem_memseg rte_memseg
-#define common_mem_mem_config rte_mem_config
-
-#define common_mem_pal_get_configuration rte_eal_get_configuration
-
- //#define commem_mem_pal_module_info rte_eal_module_info
- //
-#define common_mem_pal_init rte_eal_init
-
-#define COMMON_MEM_MEMPOOL_NAMESIZE RTE_MEMPOOL_NAMESIZE
-
-#define common_mem_memzone_lookup rte_memzone_lookup
-#define common_mem_memzone rte_memzone
-#define common_mem_atomic32_add_return rte_atomic32_add_return
-
-#define common_mem_spinlock_init rte_spinlock_init
-#define common_mem_spinlock_lock rte_spinlock_lock
-#define common_mem_spinlock_unlock rte_spinlock_unlock
-
-#define common_mem_memzone_free rte_memzone_free
-#define common_mem_pktmbuf_pool_create rte_pktmbuf_pool_create
-
-#define common_mem_pktmbuf_alloc rte_pktmbuf_alloc
-
-#define common_mem_mempool rte_mempool
-
-#define common_mem_pktmbuf_free rte_pktmbuf_free
-#define common_mem_mbuf rte_mbuf
-
-#define common_mem_mempool_lookup rte_mempool_lookup
-
-#define common_mem_ring_get_memsize rte_ring_get_memsize
-#define common_mem_ring rte_ring
-
-#define COMMON_MEM_MAX_MEMSEG RTE_MAX_MEMSEG
-
-#define common_mem_memzone_reserve rte_memzone_reserve
-#define common_mem_rwlock_read_lock rte_rwlock_read_lock
-#define common_mem_rwlock_read_unlock rte_rwlock_read_unlock
-
-#define common_mem_rwlock_write_lock rte_rwlock_write_lock
-#define common_mem_rwlock_write_unlock rte_rwlock_write_unlock
-#define common_mem_spinlock_trylock rte_spinlock_trylock
-
-#define common_mem_socket_id rte_socket_id
-#define common_mem_malloc_socket_stats rte_malloc_socket_stats
-
-#define COMMON_MEM_MIN RTE_MIN
-
-#define common_pal_module_init nscomm_pal_module_init
-#define common_memzone_data_reserve_name nscomm_memzone_data_reserve_name
-#define common_memzone_data_lookup_name nscomm_memzone_data_lookup_name
-
-#define common_dump_stack rte_dump_stack
-#define COMMON_PKTMBUF_HEADROOM RTE_PKTMBUF_HEADROOM
-
-#define common_pktmbuf_mtod rte_pktmbuf_mtod
-#define common_memcpy rte_memcpy
-#define common_spinlock_try_lock_with_pid dmm_spinlock_try_lock_with_pid
-#define common_spinlock_unlock rte_spinlock_unlock
-#define common_atomic64_t rte_atomic64_t
-#define common_atomic64_inc rte_atomic64_inc
-#define common_atomic64_read rte_atomic64_read
-#define common_atomic64_dec rte_atomic64_dec
-#define common_mbuf_refcnt_set rte_mbuf_refcnt_set
-#define common_mbuf_refcnt_read rte_mbuf_refcnt_read
-#define common_exit rte_exit
-#define COMMON_CACHE_LINE_SIZE RTE_CACHE_LINE_SIZE
-#define common_eal_process_type rte_eal_process_type
-#define COMMON_PROC_PRIMARY RTE_PROC_PRIMARY
-
-#endif
-
-#endif // _RTE_COMM_FUNC_H_
diff --git a/src/framework/common/base/include/common/common_mem_api.h b/src/framework/common/base/include/common/common_mem_api.h
deleted file mode 100644
index d143732..0000000
--- a/src/framework/common/base/include/common/common_mem_api.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef __COMMON_MEM_API_H__
-#define __COMMON_MEM_API_H__
-
-#ifdef HAL_LIB
-#else
-
-#include "rte_atomic.h"
-#include "common_mem_spinlock.h"
-#include <sys/types.h>
-#include <unistd.h>
-#include <semaphore.h>
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C" {
-/* *INDENT-ON* */
-#endif
-
-#ifndef NSTACK_LINT_CODE_DISABLE
-#define NSTACK_LINT_CODE_DISABLE(code) /*lint -e#code */
-#endif
-
-#ifndef NSTACK_LINT_CODE_ENABLE
-#define NSTACK_LINT_CODE_ENABLE(code) /*lint +e#code */
-#endif
-
-#define SYS_MBOX_NULL (sys_mbox_t)0
-
-typedef sem_t *sys_sem_t_v1;
-typedef sem_t sys_sem_st_v1;
-typedef struct queue *sys_mbox_t;
-
-typedef rte_spinlock_t *sys_sem_t_v2;
-typedef rte_spinlock_t sys_sem_st_v2;
-
-#ifndef u32_t
-typedef uint32_t u32_t;
-#endif
-
-#ifndef u8_t
-typedef uint8_t u8_t;
-#endif
-
-#ifndef s8_t
-typedef int8_t s8_t;
-#endif
-
-#ifndef err_t
-typedef s8_t err_t;
-#endif
-
-/** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */
-#define SYS_ARCH_TIMEOUT 0xffffffffUL
-
-/** sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate.
- * For now we use the same magic value, but we allow this to change in future.
- */
-#define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
-
-void sys_sem_signal_s_v2 (sys_sem_t_v2 sem);
-void sys_sem_init_v2 (sys_sem_t_v2 sem);
-u32_t sys_arch_sem_trywait_v2 (sys_sem_t_v2 * sem);
-
-u32_t sys_arch_sem_wait_s_v2 (sys_sem_t_v2 sem);
-
-#define SYS_HOST_INITIAL_PID 1
-extern volatile pid_t g_sys_host_pid;
-pid_t sys_get_hostpid_from_file (pid_t pid);
-static inline pid_t
-get_sys_pid ()
-{
- if (SYS_HOST_INITIAL_PID == g_sys_host_pid)
- (void) sys_get_hostpid_from_file (getpid ());
- return g_sys_host_pid;
-}
-
-pid_t updata_sys_pid ();
-u32_t sys_now (void);
-
-#define sys_sem_t sys_sem_t_v2
-#define sys_sem_st sys_sem_st_v2
-#define sys_sem_new(sem, count) sys_sem_new_v2(sem, count)
-#define sys_sem_free(sem) sys_sem_free_v2(sem)
-#define sys_sem_signal(sem) sys_sem_signal_v2(sem)
-#define sys_arch_sem_wait(sem, timeout) sys_arch_sem_wait_v2(sem)
-#define sys_arch_sem_trywait(sem) sys_arch_sem_trywait_v2(sem)
-
-#define sys_sem_init(sem) sys_sem_init_v2(sem)
-#define sys_sem_s_signal(sem) sys_sem_signal_s_v2(sem)
-#define sys_arch_sem_s_wait(sem, timeout) sys_arch_sem_wait_s_v2(sem)
-#define sys_arch_lock_with_pid(sem) (void)sys_arch_lock_with_pid_v2(sem)
-
-#define BUF_SIZE_FILEPATH 256
-#define STR_PID "pid:"
-#define READ_FILE_BUFLEN 512
-
-extern pid_t sys_get_hostpid_from_file (pid_t pid);
-extern pid_t get_hostpid_from_file (u32_t pid);
-extern void get_exec_name_by_pid (pid_t pid, char *task_name,
- int task_name_len);
-
-static inline u32_t
-sys_arch_lock_with_pid_v2 (sys_sem_t_v2 sem)
-{
- if (SYS_HOST_INITIAL_PID == g_sys_host_pid)
- (void) sys_get_hostpid_from_file (getpid ());
- dmm_spinlock_lock_with_pid (sem, g_sys_host_pid);
- return 0;
-}
-
-#define NSTACK_SEM_MALLOC(sys_sem,count) \
-{ \
- rte_spinlock_init(&(sys_sem)); \
- if (!(count)) \
- { \
- rte_spinlock_lock(&(sys_sem)); \
- } \
-}
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif
-#endif
-
-#endif /* __COMMON_MEM_API_H__ */
diff --git a/src/framework/common/base/include/common/common_mem_base_type.h b/src/framework/common/base/include/common/common_mem_base_type.h
deleted file mode 100644
index 01707d9..0000000
--- a/src/framework/common/base/include/common/common_mem_base_type.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_BASE_TYPE_H_
-#define _COMMON_MEM_BASE_TYPE_H_
-
-#ifdef HAL_LIB
-
-#else
-
-#define ALIGN_TYPE uint64_t
-#define PTR_ALIGN_TYPE uint64_t
-
-/*alignment define*/
-#define ALIGNMENT_DEF(name, type, aligntype) \
- union { \
- type name; \
- aligntype name##_align; \
- }
-
-#define PTR_ALIGNMENT_DEF(name, type) ALIGNMENT_DEF(name, type, PTR_ALIGN_TYPE)
-
-#define OTHER_ALIGNMENT_DEF(name, type) ALIGNMENT_DEF(name, type, ALIGN_TYPE)
-
-/*
- * * List definitions.
- * */
-#define DMM_LIST_HEAD(name, type) \
-struct name { \
- PTR_ALIGNMENT_DEF(lh_first, struct type *); /* first element */ \
-}
-
-#define DMM_LIST_ENTRY(type) \
-struct { \
- PTR_ALIGNMENT_DEF(le_next, struct type *); /* next element */\
- PTR_ALIGNMENT_DEF(le_prev, struct type **); /* address of previous next element */ \
-}
-
-/*
- * * Tail queue definitions.
- * */
-#define _DMM_TAILQ_HEAD(name, type, qual) \
-struct name { \
- PTR_ALIGNMENT_DEF(tqh_first, qual type *); /* first element */ \
- PTR_ALIGNMENT_DEF(tqh_last, qual type * qual *); /* addr of last next element */ \
-}
-
-#define DMM_TAILQ_HEAD(name, type) _DMM_TAILQ_HEAD(name, struct type,)
-
-#define _DMM_TAILQ_ENTRY(type, qual) \
-struct { \
- PTR_ALIGNMENT_DEF(tqe_next, qual type *); /* next element */\
- PTR_ALIGNMENT_DEF(tqe_prev, qual type * qual*); /* address of previous next element */\
-}
-#define DMM_TAILQ_ENTRY(type) _DMM_TAILQ_ENTRY(struct type,)
-
-/*
- * * Singly-linked Tail queue declarations.
- * */
-#define DMM_STAILQ_HEAD(name, type) \
- struct name { \
- PTR_ALIGNMENT_DEF(stqh_first, struct type *); /* first element */ \
- PTR_ALIGNMENT_DEF(stqh_last, struct type **); /* addr of last next element */ \
- }
-
-#define DMM_STAILQ_ENTRY(type) \
- struct { \
- PTR_ALIGNMENT_DEF(stqe_next, struct type *); /* next element */ \
- }
-#endif
-
-#endif
diff --git a/src/framework/common/base/include/common/common_mem_buf.h b/src/framework/common/base/include/common/common_mem_buf.h
deleted file mode 100644
index f9f1593..0000000
--- a/src/framework/common/base/include/common/common_mem_buf.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_BUF_H_
-#define _COMMON_MEM_BUF_H_
-
-#ifdef HAL_LIB
-#else
-
-#include "common_mem_base_type.h"
-#include "types.h"
-
-typedef enum __DMM_PROC_TYPE
-{
- DMM_PROC_T_AUTO = 0, /*auto detect */
- DMM_PROC_T_PRIMARY = 1, /* set to primary */
- DMM_PROC_T_SECONDARY = 2, /* set to secondary */
- DMM_PROC_T_INVALID
-} DMM_PROC_TYPE;
-
-#define DMM_MBUF_RET_OK 0
-#define DMM_MBUF_RET_ERR 1
-
-#define LCORE_MAX 128
-#define LCORE_MASK_PER (sizeof(int) * 8)
-#define LCORE_MASK_MAX (LCORE_MAX/LCORE_MASK_PER)
-
-#define LCORE_MASK_SET(ilcoremask, value) \
- if (value < LCORE_MAX) \
- { \
- ilcoremask[(value/LCORE_MASK_PER)] = (int) ( (ilcoremask[(value/LCORE_MASK_PER)]) | (1< (value%LCORE_MASK_PER))); \
- } \
-
-#define DMM_HUGTBL_ENABLE 0
-#define DMM_HUGTBL_DISABLE 1
-
-typedef struct __common_pal_module_info
-{
- int ishare_mem_size; /*shared memory size */
- int ilcoremask[LCORE_MASK_MAX];
- /**/ unsigned char uchugeflag;
- unsigned char ucproctype;
- unsigned char ucinstance;
- unsigned char ucresrv2;
-} common_mem_pal_module_info;
-
-/**
- * rte pal module init.
- *
- *
- * @param name
- * The name of the buf pool.
- */
-int nscomm_pal_module_init (common_mem_pal_module_info * pinfo, u8 app_mode);
-
-void *nscomm_memzone_data_reserve_name (const char *name, size_t len,
- int socket_id);
-
-void *nscomm_memzone_data_lookup_name (const char *name);
-
-#endif
-
-#endif /* _COMMON_MEM_BUF_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_common.h b/src/framework/common/base/include/common/common_mem_common.h
deleted file mode 100644
index 1e4cf56..0000000
--- a/src/framework/common/base/include/common/common_mem_common.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_COMMON_H_
-#define _COMMON_MEM_COMMON_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_common.h"
-#endif
-
-#endif
diff --git a/src/framework/common/base/include/common/common_mem_malloc.h b/src/framework/common/base/include/common/common_mem_malloc.h
deleted file mode 100644
index 68721cd..0000000
--- a/src/framework/common/base/include/common/common_mem_malloc.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_MALLOC_H_
-#define _COMMON_MEM_MALLOC_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_malloc.h"
-#endif
-
-#endif /* _COMMON_MEM_MALLOC_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_mbuf.h b/src/framework/common/base/include/common/common_mem_mbuf.h
deleted file mode 100644
index 0bb7696..0000000
--- a/src/framework/common/base/include/common/common_mem_mbuf.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-/*******************************************************************
- Copyright 2017 - 2047, Huawei Tech. Co., Ltd.
- ALL RIGHTS RESERVED
-
-Filename : common_mem_mbuf.h
-Description :
-Version : 1.1
-********************************************************************/
-
-#ifndef _COMMON_MEM_MBUF_H_
-#define _COMMON_MEM_MBUF_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_mbuf.h"
-#include "common_func.h"
-
-typedef uint32_t (*dmm_mbuf_item_fun) (void *data, void *argv);
-int32_t dmm_pktmbuf_pool_iterator (struct common_mem_mempool *mp,
- uint32_t start, uint32_t end,
- dmm_mbuf_item_fun fun, void *argv);
-#endif
-
-#endif /* _COMMON_MEM_MBUF_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_mempool.h b/src/framework/common/base/include/common/common_mem_mempool.h
deleted file mode 100644
index 58a8e82..0000000
--- a/src/framework/common/base/include/common/common_mem_mempool.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_MEMPOOL_H_
-#define _COMMON_MEM_MEMPOOL_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_mempool.h"
-#endif
-
-#endif /* _COMMON_MEM_MEMPOOL_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_memzone.h b/src/framework/common/base/include/common/common_mem_memzone.h
deleted file mode 100644
index 20e18c2..0000000
--- a/src/framework/common/base/include/common/common_mem_memzone.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_MEMZONE_H_
-#define _COMMON_MEM_MEMZONE_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_memzone.h"
-#endif
-
-#endif /* _COMMON_MEM_MEMZONE_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_pal.h b/src/framework/common/base/include/common/common_mem_pal.h
deleted file mode 100644
index 209b8bd..0000000
--- a/src/framework/common/base/include/common/common_mem_pal.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_PAL_H_
-#define _COMMON_MEM_PAL_H_
-
-#ifdef HAL_LIB
-#else
-
-#include "nsfw_base_linux_api.h"
-
-/*print the map address*/
-void dmm_addr_print (void);
-
-#endif
-
-#endif /* _COMMON_MEM_PAL_H_ */
diff --git a/src/framework/common/base/include/common/common_mem_pal_memconfig.h b/src/framework/common/base/include/common/common_mem_pal_memconfig.h
deleted file mode 100644
index 65b6e04..0000000
--- a/src/framework/common/base/include/common/common_mem_pal_memconfig.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_PAL_MEMCONFIG_H_
-#define _COMMON_MEM_PAL_MEMCONFIG_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_eal_memconfig.h"
-
-#endif
-
-#endif
diff --git a/src/framework/common/base/include/common/common_mem_spinlock.h b/src/framework/common/base/include/common/common_mem_spinlock.h
deleted file mode 100644
index 23f6b1e..0000000
--- a/src/framework/common/base/include/common/common_mem_spinlock.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_SPINLOCK_X86_64_H_
-#define _COMMON_MEM_SPINLOCK_X86_64_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_spinlock.h"
-
-static inline void
-dmm_spinlock_lock_with_pid (rte_spinlock_t * sl, int pid)
-{
- while (!__sync_bool_compare_and_swap (&sl->locked, 0, pid))
- while (sl->locked)
- rte_pause ();
-}
-
-static inline int
-dmm_spinlock_try_lock_with_pid (rte_spinlock_t * sl, int pid)
-{
- return __sync_bool_compare_and_swap (&sl->locked, 0, pid);
-}
-
-#endif
-
-#endif /* _COMMON_MEM_SPINLOCK_X86_64_H_ */
diff --git a/src/framework/common/base/include/common/common_sys_config.h b/src/framework/common/base/include/common/common_sys_config.h
deleted file mode 100644
index 736c47b..0000000
--- a/src/framework/common/base/include/common/common_sys_config.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef __COMMON_SYS_CONFIG_H_
-#define __COMMON_SYS_CONFIG_H_
-
-/* Below compile macro is used only in UT makefile */
-#if (HAL_LIB)
-#else
-#undef RTE_CACHE_LINE_SIZE
-#define RTE_CACHE_LINE_SIZE 64 /* RTE_CACHE_LINE_SIZE */
-#undef RTE_MAX_LCORE
-#define RTE_MAX_LCORE 128 /* RTE_MAX_LCORE */
-#undef RTE_MAX_NUMA_NODES
-#define RTE_MAX_NUMA_NODES 8 /* RTE_MAX_NUMA_NODES */
-#undef RTE_MAX_MEMSEG
-#define RTE_MAX_MEMSEG 256 /* RTE_MAX_MEMSEG */
-#undef RTE_MAX_MEMZONE
-#define RTE_MAX_MEMZONE 2560 /* RTE_MAX_MEMZONE */
-#undef RTE_MAX_TAILQ
-#define RTE_MAX_TAILQ 32 /* RTE_MAX_TAILQ */
-#undef RTE_ARCH_X86
-#define RTE_ARCH_X86 1 /* RTE_ARCH_64 */
-#undef RTE_ARCH_64
-#define RTE_ARCH_64 1 /* RTE_ARCH_64 */
-#undef RTE_PKTMBUF_HEADROOM
-#define RTE_PKTMBUF_HEADROOM 128 /* RTE_PKTMBUF_HEADROOM */
-#undef RTE_MEMPOOL_CACHE_MAX_SIZE
-#define RTE_MEMPOOL_CACHE_MAX_SIZE 512 /* RTE_MEMPOOL_CACHE_MAX_SIZE */
-
-#endif
-
-#endif // __COMMON_SYS_CONFIG_H_
diff --git a/src/framework/common/base/include/common/generic/common_mem_rwlock.h b/src/framework/common/base/include/common/generic/common_mem_rwlock.h
deleted file mode 100644
index 2eed259..0000000
--- a/src/framework/common/base/include/common/generic/common_mem_rwlock.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_MEM_RWLOCK_H_
-#define _COMMON_MEM_RWLOCK_H_
-
-#ifdef HAL_LIB
-#else
-#include "rte_rwlock.h"
-#endif
-
-#endif /* _COMMON_MEM_RWLOCK_H_ */
diff --git a/src/framework/common/base/include/common_pal_bitwide_adjust.h b/src/framework/common/base/include/common_pal_bitwide_adjust.h
deleted file mode 100644
index 0e68533..0000000
--- a/src/framework/common/base/include/common_pal_bitwide_adjust.h
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _COMMON_PAL_BITWIDE_ADJUST_H_
-#define _COMMON_PAL_BITWIDE_ADJUST_H_
-
-#ifdef HAL_LIB
-#include "pal_bitwide_adjust.h"
-#else
-#define MODULE(name) (1)
-
-#include "common_mem_common.h"
-
-#include "common_func.h"
-
-#define ALIGN_SIZET(size) ((uint64_t)(size))
-#define ALIGN_PTR(PTR) ((uint64_t)(PTR))
-
-extern struct common_mem_memseg *g_PMemSegArry;
-extern void **g_LMegAddrArry;
-
-/*get Local Seg addr by segIdx*/
-#define HMEM_SEG_LVADDR(segid) (g_LMegAddrArry[segid])
-/*get SegIDX by PrimSegAddr, just get the array Idx of g_PMemSegArry*/
-#define HMEM_SEGID(segaddr) ((struct common_mem_memseg*)segaddr - &(g_PMemSegArry[0]))
-
-/*****************************************************************
-Parameters : LMegAddrArry[] Local common_mem_memseg addr Array
- SegNum common_mem_memseg Num.
-Return :
-Description : init g_PrimAddr2LocalMap g_LocalAddr2PrimMap while the process start
-*****************************************************************/
-void *pal_shddr_to_laddr (uint64_t shaddr);
-uint64_t pal_laddr_to_shddr (void *laddr);
-int dmm_pal_addr_align ();
-
-extern int g_PrimSameFlg;
-
-/* if __NSTACK_MAIN__ is defined, no need do addr trans*/
-#ifndef __NSTACK_MAIN__
-/* g_PrimSameFlg check should be done before calling cast functions */
-
-/*share memory address to local virtual address*/
-#define ADDR_SHTOL(addr) (g_PrimSameFlg ? ((void*) (addr)) : pal_shddr_to_laddr((uint64_t)(addr)))
-
-/*local virtual address to share memory address according to memseg*/
-#define ADDR_LTOSH(addr) (g_PrimSameFlg ? ((uint64_t)(addr)) : pal_laddr_to_shddr((void*)(addr)))
-
-#define PTR_SHTOL(type, addr) ((type)ADDR_SHTOL(addr))
-
-/*local virtual address to share memory address; for compatible, not delete ADDR_LTOSH_EXT*/
-#define ADDR_LTOSH_EXT(addr) ADDR_LTOSH(addr)
-#else
-/*share memory address to local virtual address*/
-#define ADDR_SHTOL(addr) ((void*)(addr))
-
-/*local virtual address to share memory address according to memseg*/
-#define ADDR_LTOSH(addr) ((uint64_t)(addr))
-
-#define PTR_SHTOL(type, addr) ((type)(addr))
-
-/*local virtual address to share memory address; for compatible, not delete ADDR_LTOSH_EXT*/
-#define ADDR_LTOSH_EXT(addr) ADDR_LTOSH(addr)
-#endif
-
-#if MODULE("list")
-#define COMMON_LIST_INSERT_HEAD(lhead, lelm, field) do { \
- if (((lelm)->field.le_next_align = (lhead)->lh_first_align) != ((typeof((lhead)->lh_first_align))(long)NULL)) \
- ((typeof((lhead)->lh_first))ADDR_SHTOL((lhead)->lh_first_align))->field.le_prev_align = \
- ADDR_LTOSH(&(lelm)->field.le_next); \
- (lhead)->lh_first_align = ADDR_LTOSH(lelm); \
- (lelm)->field.le_prev_align = ADDR_LTOSH(&(lhead)->lh_first); \
-} while (/*CONSTCOND*/0)
-
-#define COMMON_LIST_REMOVE(lelm, field) do { \
- if ((lelm)->field.le_next_align != ((typeof((lelm)->field.le_next_align))ALIGN_PTR(NULL))) \
- ((typeof((lelm)->field.le_next))ADDR_SHTOL((lelm)->field.le_next_align))->field.le_prev_align = \
- (lelm)->field.le_prev_align; \
- if (EOK != (MEMCPY_S((typeof((lelm)->field.le_prev))ADDR_SHTOL((lelm)->field.le_prev_align), \
- sizeof((lelm)->field.le_next_align), \
- &((lelm)->field.le_next_align), \
- sizeof((lelm)->field.le_next_align)))) \
- {\
- NSCOMM_LOGERR("MEMCPY_S failed.");\
- return;\
- }\
-} while (/*CONSTCOND*/0)
-
-#define COMMON_LIST_EMPTY(lhead) ((typeof((lhead)->lh_first))ADDR_SHTOL((lhead)->lh_first_align) == NULL)
-#define COMMON_LIST_FIRST(lhead) ((typeof((lhead)->lh_first))ADDR_SHTOL((lhead)->lh_first_align))
-#define COMMON_LIST_NEXT(lelm, field) ((typeof((lelm)->field.le_next))ADDR_SHTOL((lelm)->field.le_next_align))
-
-#endif
-
-#if MODULE("tailq")
-
-#define COMMON_TAILQ_INSERT_TAIL(lhead, lelm, field) do { \
- (lelm)->field.tqe_next_align = (typeof((lelm)->field.tqe_next_align))NULL; \
- (lelm)->field.tqe_prev_align = (lhead)->tqh_last_align; \
- typeof((lhead)->tqh_last_align) tempelm = ADDR_LTOSH(lelm);\
- if (EOK != (MEMCPY_S(ADDR_SHTOL((lhead)->tqh_last_align), sizeof(tempelm), &tempelm, sizeof(tempelm)))) \
- {\
- NSCOMM_LOGERR("MEMCPY_S failed.");\
- }\
- (lhead)->tqh_last_align = ADDR_LTOSH(&(lelm)->field.tqe_next); \
-} while (/*CONSTCOND*/0)
-
-#define COMMON_TAILQ_FOREACH(lvar, lhead, field) \
- for ((lvar) = (typeof(lvar))ADDR_SHTOL((lhead)->tqh_first_align); \
- (lvar); \
- (lvar) = (typeof(lvar))ADDR_SHTOL((lvar)->field.tqe_next_align))
-
-#define COMMON_TAILQ_REMOVE(lhead, lelm, field) do { \
- if (((lelm)->field.tqe_next_align) != (typeof((lelm)->field.tqe_next_align))NULL) \
- ((typeof((lelm)->field.tqe_next))ADDR_SHTOL((lelm)->field.tqe_next_align))->field.tqe_prev_align = \
- (lelm)->field.tqe_prev_align; \
- else \
- (lhead)->tqh_last_align = (lelm)->field.tqe_prev_align; \
- if (EOK != (MEMCPY_S(ADDR_SHTOL((lelm)->field.tqe_prev_align), \
- sizeof((lelm)->field.tqe_next_align), \
- &((lelm)->field.tqe_next_align), \
- sizeof((lelm)->field.tqe_next_align)))) \
- {\
- NSCOMM_LOGERR("MEMCPY_S failed.");\
- }\
- } while (/*CONSTCOND*/0)
-
-/*
- * Tail queue functions.
- */
-#define COMMON_TAILQ_INIT(head) do { \
- (head)->tqh_first_align = (typeof((head)->tqh_first_align))NULL; \
- (head)->tqh_last_align = ADDR_LTOSH(&(head)->tqh_first); \
- } while (/*CONSTCOND*/0)
-
-/*
- * Tail queue access methods.
- */
-#define COMMON_TAILQ_EMPTY(head) ((head)->tqh_first_align == (typeof((head)->tqh_first_align))NULL)
-#define COMMON_TAILQ_FIRST(head) ((typeof((head)->tqh_first))ADDR_SHTOL((head)->tqh_first_align))
-#define COMMON_TAILQ_NEXT(elm, field) ((typeof((elm)->field.tqe_next))ADDR_SHTOL((elm)->field.tqe_next_align))
-
-#endif
-
-#if MODULE("stailq")
-/*
-* Singly-linked Tail queue functions.
-*/
-#define COMMON_STAILQ_INIT(head) do { \
- (head)->stqh_first_align = ALIGN_PTR(NULL); \
- (head)->stqh_last_align = ADDR_LTOSH(&(head)->stqh_first); \
-} while (/*CONSTCOND*/0)
-
-#define COMMON_STAILQ_INSERT_TAIL(head, elm, field) do { \
- (elm)->field.stqe_next_align = ALIGN_PTR(NULL); \
- typeof((head)->stqh_last_align) telm = ADDR_LTOSH(elm);\
- if (EOK != (MEMCPY_S(ADDR_SHTOL((head)->stqh_last_align), sizeof(telm), &telm, sizeof(telm))))\
- {\
- NSCOMM_LOGERR("MEMCPY_S failed.");\
- }\
- (head)->stqh_last_align = ADDR_LTOSH(&(elm)->field.stqe_next); \
-} while (/*CONSTCOND*/0)
-
-#define COMMON_STAILQ_REMOVE_HEAD(head, field) do { \
- if (((head)->stqh_first_align = \
- ((typeof((head)->stqh_first))ADDR_SHTOL((head)->stqh_first_align))->field.stqe_next_align) == \
- (PTR_ALIGN_TYPE)NULL) \
- (head)->stqh_last_align = ADDR_LTOSH(&(head)->stqh_first); \
-} while (/*CONSTCOND*/0)
-
-#define COMMON_STAILQ_FOREACH(var, head, field) \
- for ((var) = ADDR_SHTOL((head)->stqh_first_align); \
- (var); \
- (var) = ADDR_SHTOL((var)->field.stqe_next_align))
-
-/*
-* Singly-linked Tail queue access methods.
-*/
-
-#define COMMON_STAILQ_EMPTY(head) ((head)->stqh_first_align == (PTR_ALIGN_TYPE)NULL)
-
-#define COMMON_STAILQ_FIRST(head) (ADDR_SHTOL((head)->stqh_first_align))
-
-#define COMMON_STAILQ_NEXT(elm, field) (ADDR_SHTOL((elm)->field.stqe_next_align))
-#endif
-
-#endif
-
-#endif
diff --git a/src/framework/common/base/liblinuxapi/nsfw_lock_file.c b/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
index abfbfd1..cdfb0b7 100644
--- a/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
+++ b/src/framework/common/base/liblinuxapi/nsfw_lock_file.c
@@ -23,8 +23,6 @@
#include "types.h"
#include "nstack_securec.h"
#include "nsfw_init.h"
-#include "common_mem_api.h"
-
#include "nstack_log.h"
#include "nsfw_maintain_api.h"
#include "nsfw_mgr_com_api.h"
diff --git a/src/framework/common/data_struct/eprb_tree.c b/src/framework/common/data_struct/eprb_tree.c
index c8e616d..3697313 100644
--- a/src/framework/common/data_struct/eprb_tree.c
+++ b/src/framework/common/data_struct/eprb_tree.c
@@ -32,7 +32,7 @@ ep_rb_first (const struct ep_rb_root *root)
return NULL;
struct ep_rb_node *n;
- n = (struct ep_rb_node *) ADDR_SHTOL (root->rb_node);
+ n = root->rb_node;
if (!n)
{
@@ -41,7 +41,7 @@ ep_rb_first (const struct ep_rb_root *root)
while (n->rb_left)
{
- n = (struct ep_rb_node *) ADDR_SHTOL (n->rb_left);
+ n = n->rb_left;
}
return n;
@@ -53,15 +53,14 @@ __ep_rb_rotate_left (struct ep_rb_node *X, struct ep_rb_root *root)
/**************************
* rotate Node X to left *
**************************/
- struct ep_rb_node *Y = (struct ep_rb_node *) ADDR_SHTOL (X->rb_right);
+ struct ep_rb_node *Y = X->rb_right;
/* establish X->Right link */
X->rb_right = Y->rb_left;
if (Y->rb_left != NULL)
{
- ((struct ep_rb_node *) ADDR_SHTOL (Y->rb_left))->rb_parent =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (X);
+ Y->rb_left->rb_parent = X;
}
/* establish Y->Parent link */
@@ -69,26 +68,25 @@ __ep_rb_rotate_left (struct ep_rb_node *X, struct ep_rb_root *root)
if (X->rb_parent)
{
- struct ep_rb_node *xParent =
- (struct ep_rb_node *) ADDR_SHTOL (X->rb_parent);
+ struct ep_rb_node *xParent = X->rb_parent;
- if (X == ADDR_SHTOL (xParent->rb_left))
+ if (X == xParent->rb_left)
{
- xParent->rb_left = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ xParent->rb_left = Y;
}
else
{
- xParent->rb_right = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ xParent->rb_right = Y;
}
}
else
{
- root->rb_node = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ root->rb_node = Y;
}
/* link X and Y */
- Y->rb_left = (struct ep_rb_node *) ADDR_LTOSH_EXT (X);
- X->rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ Y->rb_left = X;
+ X->rb_parent = Y;
return;
}
@@ -99,15 +97,14 @@ __ep_rb_rotate_right (struct ep_rb_node *X, struct ep_rb_root *root)
/****************************
* rotate Node X to right *
****************************/
- struct ep_rb_node *Y = (struct ep_rb_node *) ADDR_SHTOL (X->rb_left);
+ struct ep_rb_node *Y = X->rb_left;
/* establish X->Left link */
X->rb_left = Y->rb_right;
if (Y->rb_right != NULL)
{
- ((struct ep_rb_node *) ADDR_SHTOL (Y->rb_right))->rb_parent =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (X);
+ Y->rb_right->rb_parent = X;
}
/* establish Y->Parent link */
@@ -115,31 +112,30 @@ __ep_rb_rotate_right (struct ep_rb_node *X, struct ep_rb_root *root)
if (X->rb_parent)
{
- struct ep_rb_node *xParent =
- (struct ep_rb_node *) ADDR_SHTOL (X->rb_parent);
+ struct ep_rb_node *xParent = X->rb_parent;
- if (X == (struct ep_rb_node *) ADDR_SHTOL (xParent->rb_right))
+ if (X == xParent->rb_right)
{
- xParent->rb_right = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ xParent->rb_right = Y;
}
else
{
- xParent->rb_left = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ xParent->rb_left = Y;
}
}
else
{
- root->rb_node = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ root->rb_node = Y;
}
/* link X and Y */
- Y->rb_right = (struct ep_rb_node *) ADDR_LTOSH_EXT (X);
- X->rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (Y);
+ Y->rb_right = X;
+ X->rb_parent = Y;
return;
}
-#define EP_RBTREE_PARENT(X) ((struct ep_rb_node*) ADDR_SHTOL((X)->rb_parent))
+#define EP_RBTREE_PARENT(X) ((X)->rb_parent)
#define EP_RBTREE_GRANDF(X) EP_RBTREE_PARENT(EP_RBTREE_PARENT(X))
/* X, Y are for application */
@@ -151,14 +147,12 @@ ep_rb_insert_color (struct ep_rb_node *X, struct ep_rb_root *root)
* after inserting node X *
*************************************/
/* check red-black properties */
- while (X != (struct ep_rb_node *) ADDR_SHTOL (root->rb_node)
- && EP_RBTREE_PARENT (X)->color == EP_RB_RED)
+ while (X != root->rb_node && EP_RBTREE_PARENT (X)->color == EP_RB_RED)
{
/* we have a violation */
if (X->rb_parent == EP_RBTREE_GRANDF (X)->rb_left)
{
- struct ep_rb_node *Y =
- (struct ep_rb_node *) ADDR_SHTOL (EP_RBTREE_GRANDF (X)->rb_right);
+ struct ep_rb_node *Y = EP_RBTREE_GRANDF (X)->rb_right;
if (Y && Y->color == EP_RB_RED)
{
@@ -173,9 +167,7 @@ ep_rb_insert_color (struct ep_rb_node *X, struct ep_rb_root *root)
{
/* uncle is black */
- if (X ==
- (struct ep_rb_node *)
- ADDR_SHTOL (EP_RBTREE_PARENT (X)->rb_right))
+ if (X == EP_RBTREE_PARENT (X)->rb_right)
{
/* make X a left child */
X = EP_RBTREE_PARENT (X);
@@ -191,8 +183,7 @@ ep_rb_insert_color (struct ep_rb_node *X, struct ep_rb_root *root)
else
{
/* mirror image of above code */
- struct ep_rb_node *Y =
- (struct ep_rb_node *) ADDR_SHTOL (EP_RBTREE_GRANDF (X)->rb_left);
+ struct ep_rb_node *Y = EP_RBTREE_GRANDF (X)->rb_left;
if (Y && (Y->color == EP_RB_RED))
{
@@ -207,9 +198,7 @@ ep_rb_insert_color (struct ep_rb_node *X, struct ep_rb_root *root)
{
/* uncle is black */
- if (X ==
- (struct ep_rb_node *)
- ADDR_SHTOL (EP_RBTREE_PARENT (X)->rb_left))
+ if (X == EP_RBTREE_PARENT (X)->rb_left)
{
X = EP_RBTREE_PARENT (X);
__ep_rb_rotate_right (X, root);
@@ -222,7 +211,7 @@ ep_rb_insert_color (struct ep_rb_node *X, struct ep_rb_root *root)
}
}
- ((struct ep_rb_node *) ADDR_SHTOL (root->rb_node))->color = EP_RB_BLACK;
+ root->rb_node->color = EP_RB_BLACK;
return;
}
@@ -235,8 +224,7 @@ __ep_rb_erase_color (struct ep_rb_node *X, struct ep_rb_node *Parent,
* maintain red-black tree balance *
* after deleting node X *
*************************************/
- while (X != (struct ep_rb_node *) ADDR_SHTOL (root->rb_node)
- && (!X || X->color == EP_RB_BLACK))
+ while (X != root->rb_node && (!X || X->color == EP_RB_BLACK))
{
if (Parent == NULL)
@@ -244,117 +232,96 @@ __ep_rb_erase_color (struct ep_rb_node *X, struct ep_rb_node *Parent,
break;
}
- if (X == (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_left))
+ if (X == Parent->rb_left)
{
- struct ep_rb_node *W =
- (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_right);
+ struct ep_rb_node *W = Parent->rb_right;
if (W->color == EP_RB_RED)
{
W->color = EP_RB_BLACK;
Parent->color = EP_RB_RED; /* Parent != NIL? */
__ep_rb_rotate_left (Parent, root);
- W = (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_right);
+ W = Parent->rb_right;
}
- if ((!W->rb_left
- || ((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color ==
- EP_RB_BLACK) && (!W->rb_right
- || ((struct ep_rb_node *)
- ADDR_SHTOL (W->rb_right))->color ==
- EP_RB_BLACK))
+ if ((!W->rb_left || W->rb_left->color == EP_RB_BLACK)
+ && (!W->rb_right || W->rb_right->color == EP_RB_BLACK))
{
W->color = EP_RB_RED;
X = Parent;
- Parent = (struct ep_rb_node *) ADDR_SHTOL (X->rb_parent);
+ Parent = X->rb_parent;
}
else
{
- if (!W->rb_right
- || ((struct ep_rb_node *) ADDR_SHTOL (W->rb_right))->color
- == EP_RB_BLACK)
+ if (!W->rb_right || W->rb_right->color == EP_RB_BLACK)
{
if (W->rb_left != NULL)
{
- ((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color
- = EP_RB_BLACK;
+ W->rb_left->color = EP_RB_BLACK;
}
W->color = EP_RB_RED;
__ep_rb_rotate_right (W, root);
- W = (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_right);
+ W = Parent->rb_right;
}
W->color = Parent->color;
Parent->color = EP_RB_BLACK;
- if (((struct ep_rb_node *) ADDR_SHTOL (W->rb_right))->color !=
- EP_RB_BLACK)
+ if (W->rb_right->color != EP_RB_BLACK)
{
- ((struct ep_rb_node *) ADDR_SHTOL (W->rb_right))->color =
- EP_RB_BLACK;
+ W->rb_right->color = EP_RB_BLACK;
}
__ep_rb_rotate_left (Parent, root);
- X = (struct ep_rb_node *) ADDR_SHTOL (root->rb_node);
+ X = root->rb_node;
break;
}
}
else
{
- struct ep_rb_node *W =
- (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_left);
+ struct ep_rb_node *W = Parent->rb_left;
if (W->color == EP_RB_RED)
{
W->color = EP_RB_BLACK;
Parent->color = EP_RB_RED; /* Parent != NIL? */
__ep_rb_rotate_right (Parent, root);
- W = (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_left);
+ W = Parent->rb_left;
}
- if ((!W->rb_left
- || (((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color ==
- EP_RB_BLACK)) && (!W->rb_right
- ||
- (((struct ep_rb_node *)
- ADDR_SHTOL (W->rb_right))->color ==
- EP_RB_BLACK)))
+ if ((!W->rb_left || (W->rb_left->color == EP_RB_BLACK))
+ && (!W->rb_right || (W->rb_right->color == EP_RB_BLACK)))
{
W->color = EP_RB_RED;
X = Parent;
- Parent = (struct ep_rb_node *) ADDR_SHTOL (X->rb_parent);
+ Parent = X->rb_parent;
}
else
{
- if (!W->rb_left
- || ((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color
- == EP_RB_BLACK)
+ if (!W->rb_left || W->rb_left->color == EP_RB_BLACK)
{
if (W->rb_right != NULL)
{
- ((struct ep_rb_node *)
- ADDR_SHTOL (W->rb_right))->color = EP_RB_BLACK;
+ W->rb_right->color = EP_RB_BLACK;
}
W->color = EP_RB_RED;
__ep_rb_rotate_left (W, root);
- W = (struct ep_rb_node *) ADDR_SHTOL (Parent->rb_left);
+ W = Parent->rb_left;
}
W->color = Parent->color;
Parent->color = EP_RB_BLACK;
- if (((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color !=
- EP_RB_BLACK)
+ if (W->rb_left->color != EP_RB_BLACK)
{
- ((struct ep_rb_node *) ADDR_SHTOL (W->rb_left))->color =
- EP_RB_BLACK;
+ W->rb_left->color = EP_RB_BLACK;
}
__ep_rb_rotate_right (Parent, root);
- X = (struct ep_rb_node *) ADDR_SHTOL (root->rb_node);
+ X = root->rb_node;
break;
}
}
@@ -376,48 +343,43 @@ ep_rb_erase (struct ep_rb_node *node, struct ep_rb_root *root)
if (!node->rb_left)
{
- child = (struct ep_rb_node *) ADDR_SHTOL (node->rb_right);
+ child = node->rb_right;
}
else if (!node->rb_right)
{
- child = (struct ep_rb_node *) ADDR_SHTOL (node->rb_left);
+ child = node->rb_left;
}
else
{
struct ep_rb_node *old = node, *left;
- node = (struct ep_rb_node *) ADDR_SHTOL (node->rb_right);
+ node = node->rb_right;
- while ((left =
- (struct ep_rb_node *) ADDR_SHTOL (node->rb_left)) != NULL)
+ while ((left = node->rb_left) != NULL)
{
node = left;
}
if (old->rb_parent)
{
- struct ep_rb_node *oldParent =
- (struct ep_rb_node *) ADDR_SHTOL (old->rb_parent);
+ struct ep_rb_node *oldParent = old->rb_parent;
- if (oldParent->rb_left ==
- (struct ep_rb_node *) ADDR_LTOSH_EXT (old))
+ if (oldParent->rb_left == old)
{
- oldParent->rb_left =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ oldParent->rb_left = node;
}
else
{
- oldParent->rb_right =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ oldParent->rb_right = node;
}
}
else
{
- root->rb_node = (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ root->rb_node = node;
}
- child = (struct ep_rb_node *) ADDR_SHTOL (node->rb_right);
- parent = (struct ep_rb_node *) ADDR_SHTOL (node->rb_parent);
+ child = node->rb_right;
+ parent = node->rb_parent;
color = node->color;
if (parent == old)
@@ -428,22 +390,19 @@ ep_rb_erase (struct ep_rb_node *node, struct ep_rb_root *root)
{
if (child)
{
- child->rb_parent =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (parent);
+ child->rb_parent = parent;
}
- parent->rb_left = (struct ep_rb_node *) ADDR_LTOSH_EXT (child);
+ parent->rb_left = child;
node->rb_right = old->rb_right;
- ((struct ep_rb_node *) ADDR_SHTOL (old->rb_right))->rb_parent =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ old->rb_right->rb_parent = node;
}
node->color = old->color;
node->rb_parent = old->rb_parent;
node->rb_left = old->rb_left;
- ((struct ep_rb_node *) ADDR_SHTOL (old->rb_left))->rb_parent =
- (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ old->rb_left->rb_parent = node;
if (color == EP_RB_BLACK)
{
@@ -454,28 +413,28 @@ ep_rb_erase (struct ep_rb_node *node, struct ep_rb_root *root)
}
- parent = (struct ep_rb_node *) ADDR_SHTOL (node->rb_parent);
+ parent = node->rb_parent;
color = node->color;
if (child)
{
- child->rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (parent);
+ child->rb_parent = parent;
}
if (parent)
{
- if (parent->rb_left == (struct ep_rb_node *) ADDR_LTOSH_EXT (node))
+ if (parent->rb_left == node)
{
- parent->rb_left = (struct ep_rb_node *) ADDR_LTOSH_EXT (child);
+ parent->rb_left = child;
}
else
{
- parent->rb_right = (struct ep_rb_node *) ADDR_LTOSH_EXT (child);
+ parent->rb_right = child;
}
}
else
{
- root->rb_node = (struct ep_rb_node *) ADDR_LTOSH_EXT (child);
+ root->rb_node = child;
}
if (color == EP_RB_BLACK)
diff --git a/src/framework/lib_common_mem/common_api.c b/src/framework/common/dmm_sys.c
index 566b8be..6239395 100644
--- a/src/framework/lib_common_mem/common_api.c
+++ b/src/framework/common/dmm_sys.c
@@ -13,124 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include <string.h>
-#include "common_mem_api.h"
-#include "common_mem_pal.h"
-#include "nstack_log.h"
+#include <stdint.h>
#include "nstack_securec.h"
-#include "common_func.h"
-
-void
-sys_sem_init_v2 (sys_sem_t_v2 sem)
-{
- sem->locked = 1;
-}
-
-/** Returns the current time in milliseconds,
- * may be the same as sys_jiffies or at least based on it. */
-u32_t
-sys_now (void)
-{
- struct timespec now;
-
- if (unlikely (0 != clock_gettime (CLOCK_MONOTONIC, &now)))
- {
- NSCOMM_LOGERR ("Failed to get time, errno = %d", errno);
- }
-
- return 1000 * now.tv_sec + now.tv_nsec / 1000000;
-}
-
-long
-sys_jiffies (void)
-{
- return sys_now ();
-}
-
-err_t
-sys_sem_new_v2 (sys_sem_t_v2 * sem, u8_t isUnLockd)
-{
- int retVal;
- if (!sem)
- {
- return -1;
- }
- *sem = malloc (sizeof (common_mem_spinlock_t));
-
- if (NULL == *sem)
- {
- return -1;
- }
- else
- {
- retVal =
- MEMSET_S (*sem, sizeof (common_mem_spinlock_t), 0,
- sizeof (common_mem_spinlock_t));
- if (EOK != retVal)
- {
- NSCOMM_LOGERR ("MEMSET_S failed]ret=%d", retVal);
- free (*sem);
- *sem = NULL;
- return -1;
- }
- common_mem_spinlock_init (*sem);
- }
-
- if (!isUnLockd)
- {
- common_mem_spinlock_lock (*sem);
- }
-
- return 0;
-}
-
-void
-sys_sem_free_v2 (sys_sem_t_v2 * sem)
-{
- if ((sem != NULL) && (*sem != NULL))
- {
- free (*sem);
- *sem = NULL;
- }
- else
- {
- }
-}
-
-void
-sys_sem_signal_v2 (sys_sem_t_v2 * sem)
-{
- common_mem_spinlock_unlock (*sem);
-}
-
-void
-sys_sem_signal_s_v2 (sys_sem_t_v2 sem)
-{
- common_mem_spinlock_unlock (sem);
-}
-
-u32_t
-sys_arch_sem_trywait_v2 (sys_sem_t_v2 * sem)
-{
- return (u32_t) common_mem_spinlock_trylock (*sem);
-}
-
-u32_t
-sys_arch_sem_wait_v2 (sys_sem_t_v2 * pstsem)
-{
- common_mem_spinlock_lock (*pstsem);
- return 0;
-}
+#include "nstack_log.h"
+#include "dmm_sys.h"
-u32_t
-sys_arch_sem_wait_s_v2 (sys_sem_t_v2 sem)
-{
- common_mem_spinlock_lock (sem);
- return 0;
-}
+#define BUF_SIZE_FILEPATH 256
+#define STR_PID "pid:"
+#define READ_FILE_BUFLEN 512
-volatile pid_t g_sys_host_pid = SYS_HOST_INITIAL_PID;
+pid_t g_sys_host_pid = SYS_HOST_INITIAL_PID;
/*****************************************************************************
* Prototype : get_exec_name_by_pid
@@ -181,7 +73,7 @@ get_exec_name_by_pid (pid_t pid, char *task_name, int task_name_len)
}
pid_t
-get_hostpid_from_file_one_time (u32_t pid)
+get_hostpid_from_file_one_time (pid_t pid)
{
int retVal;
char path[READ_FILE_BUFLEN] = { 0 };
@@ -237,7 +129,7 @@ get_hostpid_from_file_one_time (u32_t pid)
#define MAX_GET_PID_TIME 10
pid_t
-get_hostpid_from_file (u32_t pid)
+get_hostpid_from_file (pid_t pid)
{
pid_t ret_pid = SYS_HOST_INITIAL_PID;
int i = 0;
diff --git a/src/framework/common/include/dmm_sys.h b/src/framework/common/include/dmm_sys.h
new file mode 100644
index 0000000..dae0d97
--- /dev/null
+++ b/src/framework/common/include/dmm_sys.h
@@ -0,0 +1,44 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef _DMM_SYS_H_
+#define _DMM_SYS_H_
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#define SYS_HOST_INITIAL_PID 1
+
+pid_t sys_get_hostpid_from_file (pid_t pid);
+pid_t get_hostpid_from_file (pid_t pid);
+void get_exec_name_by_pid (pid_t pid, char *task_name, int task_name_len);
+
+pid_t sys_get_hostpid_from_file (pid_t pid);
+
+static inline pid_t
+get_sys_pid ()
+{
+ extern pid_t g_sys_host_pid;
+ if (SYS_HOST_INITIAL_PID == g_sys_host_pid)
+ (void) sys_get_hostpid_from_file (getpid ());
+ return g_sys_host_pid;
+}
+
+pid_t updata_sys_pid ();
+
+#define dmm_spin_lock_pid(spinlock) dmm_spin_lock_with((spinlock), get_sys_pid())
+#define dmm_spin_trylock_pid(spinlock) dmm_spin_trylock_with((spinlock), get_sys_pid())
+
+#endif
diff --git a/src/framework/common/include/ephlist.h b/src/framework/common/include/ephlist.h
index 90491b0..9e54489 100644
--- a/src/framework/common/include/ephlist.h
+++ b/src/framework/common/include/ephlist.h
@@ -19,9 +19,7 @@
#include <stdio.h>
#include "types.h"
-#include "common_mem_pal.h"
-#include "common_mem_buf.h"
-#include "common_pal_bitwide_adjust.h"
+
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
@@ -48,21 +46,22 @@ struct ep_hlist
#define ep_hlist_entry(ptr, type, member) container_of(ptr, type, member)
-#define EP_HLIST_INIT_NODE(node) {\
+#define EP_HLIST_INIT_NODE(node) do {\
(node)->next = NULL;\
(node)->pprev = NULL; \
- }
+ } while (0)
-#define EP_HLIST_INIT(ptr) {\
- EP_HLIST_INIT_NODE(&((ptr)->node)); \
- (ptr)->head = (struct ep_hlist_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \
- (ptr)->tail = (struct ep_hlist_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \
- }
+#define EP_HLIST_INIT(ptr) do {\
+ struct ep_hlist *_ptr = (ptr); \
+ EP_HLIST_INIT_NODE(&_ptr->node); \
+ _ptr->head = &_ptr->node; \
+ _ptr->tail = &_ptr->node; \
+ } while (0)
-#define EP_HLIST_PREV(ptr) ((struct ep_hlist_node*)(ADDR_SHTOL((ptr)->pprev)))
+#define EP_HLIST_PREV(ptr) ((struct ep_hlist_node*)((ptr)->pprev))
/* list check may below zero check header, because if app crash before
do list->size++, it will lead problem */
-#define EP_HLIST_EMPTY(list) (NULL == ((struct ep_hlist_node*)ADDR_SHTOL((list)->head))->next)
+#define EP_HLIST_EMPTY(list) (NULL == ((struct ep_hlist_node*)((list)->head))->next)
#define EP_HLIST_NODE_LINKED(node) (!(!(node)->pprev))
static __inline void ep_hlist_del (struct ep_hlist *list,
@@ -81,7 +80,7 @@ ep_hlist_del (struct ep_hlist *list, struct ep_hlist_node *n)
EP_HLIST_PREV (n)->next = n->next;
if (n->next)
{
- ((struct ep_hlist_node *) ADDR_SHTOL (n->next))->pprev = n->pprev;
+ ((struct ep_hlist_node *) (n->next))->pprev = n->pprev;
}
else
{
@@ -96,12 +95,11 @@ ep_hlist_del (struct ep_hlist *list, struct ep_hlist_node *n)
static __inline void
ep_hlist_add_tail (struct ep_hlist *list, struct ep_hlist_node *node)
{
- struct ep_hlist_node *tail =
- (struct ep_hlist_node *) ADDR_SHTOL (list->tail);
+ struct ep_hlist_node *tail = (struct ep_hlist_node *) (list->tail);
EP_HLIST_INIT_NODE (node);
- node->pprev = (struct ep_hlist_node **) ADDR_LTOSH_EXT (&tail->next);
- tail->next = (struct ep_hlist_node *) ADDR_LTOSH_EXT (node);
- list->tail = (struct ep_hlist_node *) ADDR_LTOSH_EXT (node);
+ node->pprev = (struct ep_hlist_node **) (&tail->next);
+ tail->next = (struct ep_hlist_node *) (node);
+ list->tail = (struct ep_hlist_node *) (node);
}
/*#########################################################*/
@@ -124,10 +122,10 @@ struct ep_list
#define EP_LIST_INIT(ptr) {\
EP_LIST_INIT_NODE(&((ptr)->node)); \
- (ptr)->head = (struct list_node*)ADDR_LTOSH_EXT(&((ptr)->node)); \
+ (ptr)->head = (struct list_node*)(&((ptr)->node)); \
}
-#define EP_LIST_EMPTY(list) (NULL == ((struct list_node*)ADDR_SHTOL((list)->head))->next)
+#define EP_LIST_EMPTY(list) (NULL == ((struct list_node*)((list)->head))->next)
static __inline void ep_list_del (struct ep_list *list, struct list_node *n);
static __inline void ep_list_add_tail (struct ep_list *list,
@@ -146,11 +144,11 @@ ep_list_del (struct ep_list *list, struct list_node *n)
struct list_node *p_node;
struct list_node *p_prev = NULL;
- p_node = ((struct list_node *) ADDR_SHTOL (list->head));
+ p_node = ((struct list_node *) (list->head));
while (NULL != p_node && p_node != n)
{
p_prev = p_node;
- p_node = ((struct list_node *) ADDR_SHTOL (p_node->next));
+ p_node = ((struct list_node *) (p_node->next));
}
if (p_node != n || p_prev == NULL)
@@ -173,11 +171,11 @@ ep_list_add_tail (struct ep_list *list, struct list_node *node)
struct list_node *p_node;
struct list_node *p_prev = NULL;
- p_node = ((struct list_node *) ADDR_SHTOL (list->head));
+ p_node = ((struct list_node *) (list->head));
while (NULL != p_node)
{
p_prev = p_node;
- p_node = ((struct list_node *) ADDR_SHTOL (p_node->next));
+ p_node = ((struct list_node *) (p_node->next));
}
if (NULL == p_prev)
@@ -186,7 +184,7 @@ ep_list_add_tail (struct ep_list *list, struct list_node *node)
}
EP_LIST_INIT_NODE (node);
- p_prev->next = (struct list_node *) ADDR_LTOSH_EXT (node);
+ p_prev->next = (struct list_node *) (node);
return;
}
diff --git a/src/framework/common/include/eprb_tree.h b/src/framework/common/include/eprb_tree.h
index 558ab2d..eac18f7 100644
--- a/src/framework/common/include/eprb_tree.h
+++ b/src/framework/common/include/eprb_tree.h
@@ -20,9 +20,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
-#include "common_mem_pal.h"
-#include "common_mem_buf.h"
-#include "common_pal_bitwide_adjust.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
@@ -53,7 +50,7 @@ struct ep_rb_root
static inline void
ep_rb_set_parent (struct ep_rb_node *rb, struct ep_rb_node *p)
{
- rb->rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (p);
+ rb->rb_parent = p;
}
#define ep_rb_entry(ptr, type, member) container_of(ptr, type, member)
@@ -67,10 +64,10 @@ ep_rb_link_node (struct ep_rb_node *node,
struct ep_rb_node *parent, struct ep_rb_node **rb_link)
{
- node->rb_parent = (struct ep_rb_node *) ADDR_LTOSH_EXT (parent);
+ node->rb_parent = parent;
node->rb_left = node->rb_right = NULL;
- *rb_link = (struct ep_rb_node *) ADDR_LTOSH_EXT (node);
+ *rb_link = node;
node->color = EP_RB_RED;
}
diff --git a/src/framework/common/include/generic/dmm_atomic.h b/src/framework/common/include/generic/dmm_atomic.h
index 637306b..ceb1042 100644
--- a/src/framework/common/include/generic/dmm_atomic.h
+++ b/src/framework/common/include/generic/dmm_atomic.h
@@ -23,6 +23,12 @@ typedef struct
volatile int cnt;
} dmm_atomic_t;
+inline static void
+dmm_atomic_set (dmm_atomic_t * a, int n)
+{
+ a->cnt = n;
+}
+
inline static int
dmm_atomic_get (dmm_atomic_t * a)
{
@@ -36,12 +42,24 @@ dmm_atomic_add (dmm_atomic_t * a, int n)
}
inline static int
+dmm_atomic_inc (dmm_atomic_t * a)
+{
+ return dmm_atomic_add (a, 1);
+}
+
+inline static int
dmm_atomic_sub (dmm_atomic_t * a, int n)
{
return __sync_fetch_and_sub (&a->cnt, n);
}
inline static int
+dmm_atomic_dec (dmm_atomic_t * a)
+{
+ return dmm_atomic_sub (a, 1);
+}
+
+inline static int
dmm_atomic_and (dmm_atomic_t * a, int n)
{
return __sync_fetch_and_and (&a->cnt, n);
@@ -62,7 +80,7 @@ dmm_atomic_xor (dmm_atomic_t * a, int n)
inline static int
dmm_atomic_swap (dmm_atomic_t * a, int o, int n)
{
- return __sync_val_compare_and_swap (&a->cnt, o, n);
+ return __sync_bool_compare_and_swap (&a->cnt, o, n);
}
inline static int
@@ -108,18 +126,36 @@ dmm_atomic64_get (dmm_atomic64_t * a)
return a->cnt;
}
+inline static void
+dmm_atomic64_set (dmm_atomic64_t * a, int n)
+{
+ a->cnt = n;
+}
+
inline static long long int
dmm_atomic64_add (dmm_atomic64_t * a, int n)
{
return __sync_fetch_and_add (&a->cnt, n);
}
+inline static int
+dmm_atomic64_inc (dmm_atomic64_t * a)
+{
+ return dmm_atomic64_add (a, 1);
+}
+
inline static long long int
dmm_atomic64_sub (dmm_atomic64_t * a, int n)
{
return __sync_fetch_and_sub (&a->cnt, n);
}
+inline static int
+dmm_atomic64_dec (dmm_atomic64_t * a)
+{
+ return dmm_atomic64_sub (a, 1);
+}
+
inline static long long int
dmm_atomic64_and (dmm_atomic64_t * a, int n)
{
@@ -141,7 +177,7 @@ dmm_atomic64_xor (dmm_atomic64_t * a, int n)
inline static long long int
dmm_atomic64_swap (dmm_atomic_t * a, int o, int n)
{
- return __sync_val_compare_and_swap (&a->cnt, o, n);
+ return __sync_bool_compare_and_swap (&a->cnt, o, n);
}
inline static long long int
diff --git a/src/framework/common/include/generic/dmm_spinlock.h b/src/framework/common/include/generic/dmm_spinlock.h
index be183a6..90d2f3f 100644
--- a/src/framework/common/include/generic/dmm_spinlock.h
+++ b/src/framework/common/include/generic/dmm_spinlock.h
@@ -29,25 +29,37 @@ dmm_spin_init (dmm_spinlock_t * spinlock)
spinlock->lock = 0;
}
-inline static void
-dmm_spin_lock (dmm_spinlock_t * spinlock)
+static inline int
+dmm_spin_trylock_with (dmm_spinlock_t * spinlock, int value)
+{
+ return __sync_bool_compare_and_swap (&spinlock->lock, 0, value);
+}
+
+static inline void
+dmm_spin_lock_with (dmm_spinlock_t * spinlock, int value)
{
- while (0 != __sync_lock_test_and_set (&spinlock->lock, 1))
+ while (!dmm_spin_trylock_with (spinlock, value))
{
DMM_PAUSE_WHILE (spinlock->lock);
}
}
+inline static void
+dmm_spin_lock (dmm_spinlock_t * spinlock)
+{
+ dmm_spin_lock_with (spinlock, 1);
+}
+
inline static int
dmm_spin_trylock (dmm_spinlock_t * spinlock)
{
- return 0 == __sync_lock_test_and_set (&spinlock->lock, 1);
+ return dmm_spin_trylock_with (spinlock, 1);
}
inline static void
dmm_spin_unlock (dmm_spinlock_t * spinlock)
{
- spinlock->lock = 0;
+ __sync_lock_release (&spinlock->lock);
}
#endif /* #ifndef _DMM_SPINLOCK_H_ */
diff --git a/src/framework/common/mem_mgr/include/nsfw_mem_desc.h b/src/framework/common/mem_mgr/include/nsfw_mem_desc.h
deleted file mode 100644
index 9a14c8d..0000000
--- a/src/framework/common/mem_mgr/include/nsfw_mem_desc.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_MEM_DESC_H
-#define _NSFW_MEM_DESC_H
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include "nsfw_mem_api.h"
-#include "nsfw_mgr_com_api.h"
-#include "nsfw_ring_data.h"
-
-#define NSFW_MEM_NOT_INIT (0)
-#define NSFW_MEM_INIT_ERR (1)
-#define NSFW_MEM_INIT_OK (2)
-
-#define NSFW_NAME_LENCHECK_RET(name, desc) \
- { \
- i32 inamelen = strlen(name); \
- if (inamelen >= NSFW_MEM_APPNAME_LENGTH) \
- { \
- NSCOMM_LOGERR("name length check fail] desc=%s, name len=%d, expected max=%d", \
- #desc, inamelen, NSFW_MEM_APPNAME_LENGTH); \
- return NSFW_MEM_ERR; \
- } \
- }
-
-#define NSFW_NAME_LENCHECK_RET_NULL(name, desc) \
- { \
- i32 inamelen = strlen(name); \
- if (inamelen >= NSFW_MEM_APPNAME_LENGTH) \
- { \
- NSCOMM_LOGERR("name length check fail] desc=%s, name len=%d, expected max=%d", \
- #desc, inamelen, NSFW_MEM_APPNAME_LENGTH); \
- return NULL; \
- } \
- }
-
-#define NSFW_MEM_PARA_CHECK_RET(handle, pdata, desc, num) {\
- if ((NULL == (handle)) || (NULL == (pdata)) || (num <= 0)\
- || (((struct nsfw_mem_ring*)(handle))->memtype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s,mhandle=%p, pdata=%p, inum=%d", desc, (handle), (pdata), num); \
- return 0; \
- } \
- }
-
-#define NSFW_MEM_ENQ_PARA_CHECK_RET(handle, desc) {\
- if ((NULL == (handle)) \
- || (((struct nsfw_mem_ring*)(handle))->memtype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s,mhandle=%p", desc, (handle)); \
- return 0; \
- } \
- }
-
-#define NSFW_MEM_NAME_CHECK_RET_ERR(pname, desc) {\
- if ((NULL == (pname)) || ((pname)->entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s, pname=%p, mtype=%d", desc, pname, (pname) ? (pname)->entype:-1); \
- return NSFW_MEM_ERR; \
- } \
- }
-
-#define NSFW_MEM_NAME_CHECK_RET_NULL(pname, desc) {\
- if ((NULL == (pname)) || ((pname)->entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s, pname=%p, mtype=%d", desc, pname, (pname) ? (pname)->entype:-1); \
- return NULL; \
- } \
- }
-
-#define NSFW_MEM_RING_CHECK_RET(pringinfo, pringhandle_array, iringnum) {\
- if ((NULL == pringinfo) || (NULL == pringhandle_array) || (pringinfo[0].stname.entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] pringinfo=%p, iringnum=%d, pringhandle_array=%p, mtype=%d", \
- pringinfo, iringnum, pringhandle_array, pringinfo ? pringinfo[0].stname.entype : (-1)); \
- return NSFW_MEM_ERR; \
- } \
- }
-
-#define NSFW_MEM_RINGV_CHECK_RET(pmpinfo, inum, pringhandle_array, iarray_num) { \
- if ((NULL == pmpinfo) || (NULL == pringhandle_array) \
- || (inum != iarray_num) || (inum <= 0) || (pmpinfo[0].stname.entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] pmpinfo=%p, inum=%d, pringhandle_array=%p, iarray_num=%d", \
- pmpinfo, inum, pringhandle_array, iarray_num, pmpinfo ? pmpinfo[0].stname.entype : (-1)); \
- return NSFW_MEM_ERR; \
- } \
- }
-
-#define NSFW_MEM_MBUF_CHECK_RET_ERR(mhandle, entype, desc) {\
- if ((NULL == mhandle) || (entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s, mhandle=%p, mtype=%d", desc, mhandle, entype); \
- return NSFW_MEM_ERR; \
- } \
- }
-
-#define NSFW_MEM_MBUF_CHECK_RET_NULL(mhandle, entype, desc) {\
- if ((NULL == mhandle) || (entype >= NSFW_MEM_TYPEMAX)) \
- { \
- NSCOMM_LOGERR("input para error] desc=%s, mhandle=%p, mtype=%d", desc, mhandle, entype); \
- return NULL; \
- } \
- }
-
-/*memory access inferface define*/
-typedef struct
-{
- i32 (*mem_ops_init) (nsfw_mem_para * para);
- void (*mem_ops_destroy) (void);
- mzone_handle (*mem_ops_zone_create) (nsfw_mem_zone * pinfo);
- i32 (*mem_ops_zone_createv) (nsfw_mem_zone * pmeminfo, i32 inum,
- mzone_handle * paddr_array, i32 iarray_num);
- mzone_handle (*mem_ops_zone_lookup) (nsfw_mem_name * pname);
- i32 (*mem_ops_mzone_release) (nsfw_mem_name * pname);
- mpool_handle (*mem_ops_mbfmp_create) (nsfw_mem_mbfpool * pbufinfo);
- i32 (*mem_ops_mbfmp_createv) (nsfw_mem_mbfpool * pmbfname, i32 inum,
- mpool_handle * phandle_array,
- i32 iarray_num);
- mbuf_handle (*mem_ops_mbf_alloc) (mpool_handle mhandle);
- i32 (*mem_ops_mbf_free) (mbuf_handle mhandle);
- mpool_handle (*mem_ops_mbfmp_lookup) (nsfw_mem_name * pmbfname);
- i32 (*mem_ops_mbfmp_release) (nsfw_mem_name * pname);
- mring_handle (*mem_ops_sp_create) (nsfw_mem_sppool * pmpinfo);
- i32 (*mem_ops_sp_createv) (nsfw_mem_sppool * pmpinfo, i32 inum,
- mring_handle * pringhandle_array,
- i32 iarray_num);
- i32 (*mem_ops_spring_create) (nsfw_mem_mring * prpoolinfo,
- mring_handle * pringhandle_array,
- i32 iringnum);
- i32 (*mem_ops_sp_release) (nsfw_mem_name * pname);
- mring_handle (*mem_ops_sp_lookup) (nsfw_mem_name * pname);
- mring_handle (*mem_ops_ring_create) (nsfw_mem_mring * pringinfo);
- mring_handle (*mem_ops_ring_lookup) (nsfw_mem_name * pname);
- i32 (*mem_ops_ring_release) (nsfw_mem_name * pname);
- ssize_t (*mem_ops_mem_statics) (void *handle, nsfw_mem_struct_type type);
- i32 (*mem_ops_mbuf_recycle) (mpool_handle handle);
- i32 (*mem_ops_sp_iterator) (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
- i32 (*mem_ops_mbuf_iterator) (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
-} nsfw_mem_ops;
-
-typedef struct
-{
- nsfw_mem_type entype;
- nsfw_mem_ops *stmemop;
-} nsfw_mem_attr;
-
-typedef struct
-{
- fw_poc_type enflag; /*app, nStackMain, Master */
-} nsfw_mem_localdata;
-
-extern nsfw_mem_attr g_nsfw_mem_ops[];
-extern i32 g_mem_type_num;
-#endif
diff --git a/src/framework/common/mem_mgr/include/nsfw_ring_data.h b/src/framework/common/mem_mgr/include/nsfw_ring_data.h
deleted file mode 100644
index e6007ab..0000000
--- a/src/framework/common/mem_mgr/include/nsfw_ring_data.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_RING_DATA_H_
-#define _NSFW_RING_DATA_H_
-
-#include <stdint.h>
-#include "types.h"
-#include "common_mem_api.h"
-
-#define VALUE_LEN 40
-
-/*
-Ring Data has two part; Ver&Data
-val is a pointer offset base on rte_perf_ring::Addrbase, this struct support 1TB, it's enough now;
-future __int128 maybe used, this type can perfectly solve the version & address rang problem.
-*/
-union RingData_U
-{
- struct RingData_S
- {
- /*
- value of data, indeed it's a pointer offset base on rte_perf_ring::Addrbase;40bit is enough for user space addr
- ver must using 24bit, so val using 40bit; a CAS now just support 64bit; in future, we may using __int128,now __int128 not support well.
- */
- volatile unsigned long long val:VALUE_LEN;
- /*
- version of data, using 16b store version flg is more suitable for Address save, but using 16b version is too short, it's value range is [0-65535];
- between two cpu schedule time (TM-SPACE) of one process/thread, other processes/threads do N times queue oper. if N > 65535, still have a chance of ABA.
- if using a 24bit save version flg, if ABA happened, 16777216 times queue oper need done in one TM-SPACE, it's impossible for today cpu.
- */
- volatile unsigned long long ver:(64 - VALUE_LEN);
- } data_s;
- u64 data_l;
-};
-
-/*
- this high perf Ring rely on the init value of Ring Slot;
- Ring Must init using PerfRingInit, Pool Must init using PerfPoolInit
-
- the addrbase is base addr for all element; now we support 1024G offset;
- for nstack the Ring element is from hugepage, and the addr is in stack space.
-
- 1. not support a ring who's element space range bigger than 1024GB
- [if one element from heep, one from stack, range will bigger than 1024GB, we not support]
- 2. one more thing addr from mmap is in stack
- 3. rte_perf_ring must create by rte_perf_ring_create/rte_perf_pool_create
-*/
-struct nsfw_mem_ring
-{
- u8 memtype; //shared, no shared
- u8 ringflag; //scmp, scsp, mcsp,mcmp
- u16 reserv; //reserv data
- u32 size; //size of the Ring, must 2^n
- u32 eltsize; //for s-pool, it is the size of per buf, if is ring, eltsize is zero.
- u32 mask; //mask of the Ring, used mask mod Head/Tail to get real pos, must 2^n-1
- void *Addrbase; /*Cause the Addr we support just 40b(1024G), we using a basAddr+offset to get the real addr; ring[x].data_s.val just store offset;
- * not used when no shared mode
- */
- volatile u32_t prodhflag; //for nshmem fork recover
- volatile u32_t prodtflag; //for nshmem fork recover
- volatile u32_t conshflag; //for nshmem fork recover
- volatile u32_t constflag; //for nshmem fork recover
- nsfw_res res_chk;
-
- struct
- {
- volatile u32 head; //Head of the Ring, used to indicate pos where to pull a val
- volatile u32 tail; //for nshmem, shmem not used.
- } prod;
- struct
- {
- volatile u32 head; //for nshmem, shmem not used.
- volatile u32 tail; //Tail of the Ring, used to indicate pos where to push a val
- } cons;
- u32 uireserv[4]; //reserved for update
- union RingData_U ring[0]; //Value of Ring
-};
-
-#define PERFRING_ADDR_RANGE (0xFFFFFFFFFFL)
-
-#endif /*_NSFW_RING_DATA_H_*/
diff --git a/src/framework/common/mem_mgr/include/nsfw_ring_fun.h b/src/framework/common/mem_mgr/include/nsfw_ring_fun.h
deleted file mode 100644
index d74cc4b..0000000
--- a/src/framework/common/mem_mgr/include/nsfw_ring_fun.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_RING_FUN_H_
-#define _NSFW_RING_FUN_H_
-
-#include <stdint.h>
-#include "common_pal_bitwide_adjust.h"
-#include "nsfw_mem_api.h"
-#include "nsfw_ring_data.h"
-
-/*
- for nstack I advise addrbase set to lowest of mmaped hugepage Addr.
- to simple:
- 1. ring element is from mmaped mem, set Addrbase to 0x7fffffffffff - 0xffffffffff is OK;
- 1. ring element is from heap, set Addrbase to NULL is ok;
-*/
-static inline void
-nsfw_mem_ring_init (struct nsfw_mem_ring *ring, unsigned int size,
- void *addrbase, unsigned char memtype, unsigned char flag)
-{
- unsigned int loop = 0;
-
- if (!ring)
- {
- return;
- }
-
- ring->prod.head = 0;
- ring->prod.tail = 0;
- ring->cons.head = 0;
- ring->cons.tail = 0;
- ring->size = size;
- ring->eltsize = 0;
- ring->mask = size - 1;
- ring->memtype = memtype;
- ring->ringflag = flag;
- ring->prodtflag = ring->prodhflag = get_sys_pid ();
- ring->conshflag = ring->constflag = get_sys_pid ();
- /*if shmem, addrbase already changed to primary memory address */
- ring->Addrbase = addrbase;
- ring->uireserv[0] = 0;
- ring->uireserv[1] = 0;
- ring->uireserv[2] = 0;
- ring->uireserv[3] = 0;
-
- /*init Ring */
- for (loop = 0; loop < size; loop++)
- {
- /*
- for a empty ring, version is the mapping head val - size
- so the empty ring's ver is loop-size;
- */
- ring->ring[loop].data_s.ver = (loop - size);
- ring->ring[loop].data_s.val = 0;
- }
-}
-
-/*
-another way to init Pool while no continuous space
-1. init a empty rte_perf_ring
-2. add element to PerRing.
-*/
-static inline void
-nsfw_mem_pool_head_init (struct nsfw_mem_ring *ring, unsigned int size,
- unsigned int eltsize, void *addrbase,
- nsfw_mem_type memtype, nsfw_mpool_type flag)
-{
- ring->prod.head = size;
- ring->prod.tail = size;
- ring->cons.head = 0;
- ring->cons.tail = 0;
- ring->size = size;
- ring->eltsize = eltsize;
- ring->mask = size - 1;
- ring->memtype = memtype;
- ring->ringflag = flag;
- ring->prodtflag = ring->prodhflag = get_sys_pid ();
- ring->conshflag = ring->constflag = get_sys_pid ();
- /*if shmem, addrbase already changed to primary memory address */
- ring->Addrbase = addrbase;
- ring->uireserv[0] = 0;
- ring->uireserv[1] = 0;
- ring->uireserv[2] = 0;
- ring->uireserv[3] = 0;
- return;
-}
-
-#define NSFW_RING_FLAG_CHECK_RET(handle, desc) {\
- if (((struct nsfw_mem_ring*)mhandle)->ringflag >= NSFW_MPOOL_TYPEMAX) \
- { \
- NSCOMM_LOGERR("invalid ring] desc=%s, ringflag=%d", desc, ((struct nsfw_mem_ring*)mhandle)->ringflag); \
- return 0; \
- } \
- }
-
-#endif /*_NSFW_RING_FUN_H_*/
diff --git a/src/framework/common/mem_mgr/nsfw_mem_api.c b/src/framework/common/mem_mgr/nsfw_mem_api.c
deleted file mode 100644
index c89ada1..0000000
--- a/src/framework/common/mem_mgr/nsfw_mem_api.c
+++ /dev/null
@@ -1,879 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <sys/types.h>
-#include <unistd.h>
-#include "nsfw_mem_desc.h"
-#include "nstack_securec.h"
-
-#ifdef SYS_MEM_RES_STAT
-#include "common_mem_ring.h"
-#include "common_mem_mempool.h"
-#endif
-
-#define MEM_OP_CALL_OK_RET(mtype, fun, para) { \
- if (g_nsfw_mem_ops[mtype].stmemop->fun) \
- { \
- return g_nsfw_mem_ops[mtype].stmemop->fun para; \
- } \
- }
-
-/*****************************************************************************
-* Prototype : nsfw_mem_init
-* Description : memory mgr module init
-* Input : point to nstack_fwmem_para
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_init (void *para)
-{
- nsfw_mem_para *ptempara = NULL;
- i32 iret = NSFW_MEM_OK;
- i32 icount = 0;
- i32 iindex = 0;
-
- if (NULL == para)
- {
- NSCOMM_LOGERR ("ns mem init input error");
- return NSFW_MEM_ERR;
- }
-
- ptempara = (nsfw_mem_para *) para;
-
- if (ptempara->enflag >= NSFW_PROC_MAX)
- {
- NSCOMM_LOGERR ("ns mem init input enflag invalid] enflag=%d",
- ptempara->enflag);
- return NSFW_MEM_ERR;
- }
-
- NSCOMM_LOGINF ("ns mem init begin] enflag=%d, iargsnum=%d",
- ptempara->enflag, ptempara->iargsnum);
-
- for (iindex = 0; iindex < ptempara->iargsnum; iindex++)
- {
- NSCOMM_LOGINF ("%s", ptempara->pargs[iindex]);
- }
-
- for (icount = 0; icount < g_mem_type_num; icount++)
- {
- if ((NULL != g_nsfw_mem_ops[icount].stmemop)
- && (NULL != g_nsfw_mem_ops[icount].stmemop->mem_ops_init))
- {
- iret = g_nsfw_mem_ops[icount].stmemop->mem_ops_init (ptempara);
-
- if (NSFW_MEM_OK != iret)
- {
- NSCOMM_LOGERR ("mem init failed]index=%d, memtype=%d", icount,
- g_nsfw_mem_ops[icount].entype);
- break;
- }
- }
- }
-
- /*if some module init fail, destory the modules that success */
- if (icount < g_mem_type_num)
- {
- for (iindex = 0; iindex < icount; iindex++)
- {
- if (g_nsfw_mem_ops[icount].stmemop->mem_ops_destroy)
- {
- g_nsfw_mem_ops[icount].stmemop->mem_ops_destroy ();
- }
- }
-
- return NSFW_MEM_ERR;
- }
-
- NSCOMM_LOGINF ("ns mem init end");
- return NSFW_MEM_OK;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_zone_create
-* Description : create a block memory with name
-* nsfw_mem_zone::stname
-* nsfw_mem_zone::isize
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_zone* pinfo
-* Output : None
-* Return Value : mzone_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mzone_handle
-nsfw_mem_zone_create (nsfw_mem_zone * pinfo)
-{
-
- if ((NULL == pinfo) || (pinfo->stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR ("zone create input para error] pinfo=%p, mtype=%d",
- pinfo, pinfo ? pinfo->stname.entype : (-1));
- return NULL;
- }
-
- MEM_OP_CALL_OK_RET (pinfo->stname.entype, mem_ops_zone_create, (pinfo));
- NSCOMM_LOGINF ("mem create fail] memtype=%d, name=%s, size=%zu",
- pinfo->stname.entype, pinfo->stname.aname, pinfo->length);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_zone_createv
-* Description : create some memory blocks
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_zone* pmeminfo
-* i32 inum
-* mzone_handle* paddr_array
-* i32 iarray_num
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_zone_createv (nsfw_mem_zone * pmeminfo, i32 inum,
- mzone_handle * paddr_array, i32 iarray_num)
-{
- if ((NULL == pmeminfo) || (NULL == paddr_array)
- || (inum != iarray_num) || (inum <= 0)
- || (pmeminfo[0].stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR
- ("input para error] pmeminfo=%p, inum=%d, paddr_array=%p, iarray_num=%d, mtype=%d",
- pmeminfo, inum, paddr_array, iarray_num,
- pmeminfo ? pmeminfo[0].stname.entype : (-1));
- return NSFW_MEM_ERR;
- }
-
- MEM_OP_CALL_OK_RET (pmeminfo[0].stname.entype, mem_ops_zone_createv,
- (pmeminfo, inum, paddr_array, iarray_num));
- NSCOMM_LOGINF ("mem create fail] memtype=%d", pmeminfo[0].stname.entype);
- return NSFW_MEM_ERR;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_zone_lookup
-* Description : look up a memory
-* 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* 2. if the memory is shared, pname->enowner indicate that who create this memory.
-* note : 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
-* end with none created by nStackMaster, and end with _<pid> created by other.
-* 2. pname->enowner is available only when call look up shared memory.
-* 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
-* the name must be full name.
-* for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
-* must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
-* _(pid) at the end of name, nstack_123.
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : mzone_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mzone_handle
-nsfw_mem_zone_lookup (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_NULL (pname, "mem zone look up");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_zone_lookup, (pname));
- NSCOMM_LOGERR ("mem lookup fail] memtype=%d, name=%s ", pname->entype,
- pname->aname);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_zone_release
-* Description : release a memory
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_zone_release (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_ERR (pname, "mem zone release");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_mzone_release, (pname));
- NSCOMM_LOGERR ("mem release fail] memtype=%d, name=%s", pname->entype,
- pname->aname);
- return NSFW_MEM_ERR;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbfmp_create
-* Description : create a mbuf pool
-* Input : nsfw_mem_mbfpool* pbufinfo
-* Output : None
-* Return Value : mpool_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mpool_handle
-nsfw_mem_mbfmp_create (nsfw_mem_mbfpool * pbufinfo)
-{
- if ((NULL == pbufinfo) || (pbufinfo->stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR ("input para error] pbufinfo=%p, mtype=%d", pbufinfo,
- pbufinfo ? pbufinfo->stname.entype : (-1));
- return NULL;
- }
-
- MEM_OP_CALL_OK_RET (pbufinfo->stname.entype, mem_ops_mbfmp_create,
- (pbufinfo));
- NSCOMM_LOGERR ("mbufmp create fail] memtype=%d, name=%s ",
- pbufinfo->stname.entype, pbufinfo->stname.aname);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbfmp_createv
-* Description : create some mbuf pools
-* 1. the name of length must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_mbfpool* pmbfname
-* i32 inum
-* mpool_handle* phandle_array
-* i32 iarray_num
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_mbfmp_createv (nsfw_mem_mbfpool * pmbfname, i32 inum,
- mpool_handle * phandle_array, i32 iarray_num)
-{
- if ((NULL == pmbfname) || (NULL == phandle_array)
- || (inum != iarray_num) || (inum <= 0)
- || (pmbfname[0].stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR
- ("input para error] pmbfname=%p, inum=%d, phandle_array=%p, iarray_num=%d",
- pmbfname, inum, phandle_array, iarray_num,
- pmbfname ? pmbfname[0].stname.entype : (-1));
- return NSFW_MEM_ERR;
- }
-
- MEM_OP_CALL_OK_RET (pmbfname[0].stname.entype, mem_ops_mbfmp_createv,
- (pmbfname, inum, phandle_array, iarray_num));
- NSCOMM_LOGERR ("mbufmp createv fail] memtype=%d",
- pmbfname[0].stname.entype);
- return NSFW_MEM_ERR;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbf_alloc
-* Description : alloc a mbuf from mbuf pool
-* Input : mpool_handle mhandle
-* nsfw_mem_type entype
-* Output : None
-* Return Value : mbuf_handle
-* Calls :
-* Called By :
-*****************************************************************************/
-mbuf_handle
-nsfw_mem_mbf_alloc (mpool_handle mhandle, nsfw_mem_type entype)
-{
- NSFW_MEM_MBUF_CHECK_RET_NULL (mhandle, entype, "mbf alloc");
- MEM_OP_CALL_OK_RET (entype, mem_ops_mbf_alloc, (mhandle));
- NSCOMM_LOGERR ("mbf alloc fail] handle=%p, type=%d", mhandle, entype);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbf_free
-* Description : put a mbuf backintp mbuf pool
-* Input : mbuf_handle mhandle
-* nsfw_mem_type entype
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_mbf_free (mbuf_handle mhandle, nsfw_mem_type entype)
-{
- NSFW_MEM_MBUF_CHECK_RET_ERR (mhandle, entype, "mbuf free");
- MEM_OP_CALL_OK_RET (entype, mem_ops_mbf_free, (mhandle));
- NSCOMM_LOGERR ("mbf free fail] handle=%p, type=%d", mhandle, entype);
- return NSFW_MEM_ERR;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbfmp_lookup
-* Description : look up mbuf mpool
-* 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* 2. if the memory is shared, pname->enowner indicate that who create this memory.
-* note : 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
-* end with none created by nStackMaster, and end with _<pid> created by other.
-* 2. pname->enowner is available only when call look up shared memory.
-* 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
-* the name must be full name.
-* for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
-* must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
-* _(pid) at the end of name, nstack_123.
-* Input : nsfw_mem_name* pmbfname
-* Output : None
-* Return Value : mpool_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mpool_handle
-nsfw_mem_mbfmp_lookup (nsfw_mem_name * pmbfname)
-{
- NSFW_MEM_NAME_CHECK_RET_NULL (pmbfname, "mbuf pool look up");
- MEM_OP_CALL_OK_RET (pmbfname->entype, mem_ops_mbfmp_lookup, (pmbfname));
- NSCOMM_LOGERR ("mbufmp lookup fail] memtype=%d, name=%s ", pmbfname->entype,
- pmbfname->aname);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbfmp_release
-* Description : release mbuf pool
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_mbfmp_release (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_ERR (pname, "mbuf mp release");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_mbfmp_release, (pname));
- NSCOMM_LOGERR ("mbfmp release fail] memtype=%d, name=%s", pname->entype,
- pname->aname);
- return NSFW_MEM_ERR;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_create
-* Description : create a simple pool
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_sppool* pmpinfo
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mring_handle
-nsfw_mem_sp_create (nsfw_mem_sppool * pmpinfo)
-{
- if ((NULL == pmpinfo) || (pmpinfo->stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR ("input para error] pmpinfo=%p, mtype=%d", pmpinfo,
- pmpinfo ? pmpinfo->stname.entype : (-1));
- return NULL;
- }
-
- MEM_OP_CALL_OK_RET (pmpinfo->stname.entype, mem_ops_sp_create, (pmpinfo));
- NSCOMM_LOGERR ("sp create fail] memtype=%d, name=%s ",
- pmpinfo->stname.entype, pmpinfo->stname.aname);
- return NULL;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_createv
-* Description : create some simple pools one time
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_sppool* pmpinfo
-* i32 inum
-* mring_handle* pringhandle_array
-* i32 iarray_num
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_sp_createv (nsfw_mem_sppool * pmpinfo, i32 inum,
- mring_handle * pringhandle_array, i32 iarray_num)
-{
- NSFW_MEM_RINGV_CHECK_RET (pmpinfo, inum, pringhandle_array, iarray_num);
- MEM_OP_CALL_OK_RET (pmpinfo[0].stname.entype, mem_ops_sp_createv,
- (pmpinfo, inum, pringhandle_array, iarray_num));
- NSCOMM_LOGERR ("sp createv fail] memtype=%d", pmpinfo[0].stname.entype);
- return NSFW_MEM_ERR;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_ring_create
-* Description : create a simple pool with many rings
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_mring* pringinfo
-* mring_handle* pringhandle_array
-* i32 iringnum
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_sp_ring_create (nsfw_mem_mring * pringinfo,
- mring_handle * pringhandle_array, i32 iringnum)
-{
- NSFW_MEM_RING_CHECK_RET (pringinfo, pringhandle_array, iringnum);
- MEM_OP_CALL_OK_RET (pringinfo[0].stname.entype, mem_ops_spring_create,
- (pringinfo, pringhandle_array, iringnum));
- NSCOMM_LOGERR ("mppool spring creat fail] memtype=%d",
- pringinfo[0].stname.entype);
- return NSFW_MEM_ERR;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_release
-* Description : release a simple mempool
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_mem_sp_release (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_ERR (pname, "sp release");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_sp_release, (pname));
- NSCOMM_LOGERR ("sp release fail] memtype=%d, name=%s ", pname->entype,
- pname->aname);
- return NSFW_MEM_ERR;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_lookup
-* Description : look up a simpile ring
-* 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* 2. if the memory is shared, pname->enowner indicate that who create this memory.
-* note : 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
-* end with none created by nStackMaster, and end with _<pid> created by other.
-* 2. pname->enowner is available only when call look up shared memory.
-* 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
-* the name must be full name.
-* for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
-* must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
-* _(pid) at the end of name, nstack_123.
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mring_handle
-nsfw_mem_sp_lookup (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_NULL (pname, "sp look up");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_sp_lookup, (pname));
- NSCOMM_LOGERR ("sp lookup fail] memtype=%d, name=%s", pname->entype,
- pname->aname);
- return NULL;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_create
-* Description : create a ring
-* note : 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* 2. shared memory ring (NSFW_SHMEM) just can put a pointer into the queue, the queue also point to a shared block memory.
-* no shared memory ring(NSFW_NSHMEM) is other wise.
-* Input : nsfw_mem_mring* pringinfo
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mring_handle
-nsfw_mem_ring_create (nsfw_mem_mring * pringinfo)
-{
- if ((NULL == pringinfo) || (pringinfo->stname.entype >= NSFW_MEM_TYPEMAX))
- {
- NSCOMM_LOGERR ("input para error] pmpinfo=%p, mtype=%d", pringinfo,
- pringinfo ? pringinfo->stname.entype : (-1));
- return NULL;
- }
-
- MEM_OP_CALL_OK_RET (pringinfo->stname.entype, mem_ops_ring_create,
- (pringinfo));
- NSCOMM_LOGERR ("ring create fail] memtype=%d, name=%s ",
- pringinfo->stname.entype, pringinfo->stname.aname);
- return NULL;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_lookup
-* Description : look up a ring by name
-* 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
-* 2. if the memory is shared, pname->enowner indicate that who create this memory.
-* note:
-* 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
-* end with none created by nStackMaster, and end with _<pid> created by other.
-* 2. pname->enowner is available only when call look up shared memory.
-* 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
-* the name must be full name.
-* for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
-* must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
-* _(pid) at the end of name, nstack_123.
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*
-*
-*****************************************************************************/
-mring_handle
-nsfw_mem_ring_lookup (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_NULL (pname, "ring lookup");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_ring_lookup, (pname));
- NSCOMM_LOGERR ("ring lookup fail] memtype=%d, name=%s", pname->entype,
- pname->aname);
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_reset
-* Description : reset the number of producer and consumer, also, the
-* state of ring reset to empty
-* notes : must be called before doing any operations base on the ring
-* Input : mring_handle mhandle
-* nsfw_mpool_type entype
-* Output : None
-* Return Value : void
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-void
-nsfw_mem_ring_reset (mring_handle mhandle, nsfw_mpool_type entype)
-{
- u32 loop = 0;
- struct nsfw_mem_ring *ring = (struct nsfw_mem_ring *) mhandle;
-
- if (!ring)
- {
- return;
- }
-
- ring->prod.head = 0;
- ring->cons.tail = 0;
- ring->ringflag = (u8) entype;
-
- /*init Ring */
- for (loop = 0; loop < ring->size; loop++)
- {
- /*
- for a empty ring, version is the mapping head val - size
- so the empty ring's ver is loop-size;
- */
- ring->ring[loop].data_s.ver = (loop - ring->size);
- ring->ring[loop].data_s.val = 0;
- }
-
- return;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_free_count
-* Description : get the free number of ring
-* Input : mring_handle mhandle
-* Output : None
-* Return Value : u32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-u32
-nsfw_mem_ring_free_count (mring_handle mhandle)
-{
- struct nsfw_mem_ring *temp = NULL;
- u32 thead = 0;
- u32 ttail = 0;
- if (NULL == mhandle)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return 0;
- }
-
- temp = (struct nsfw_mem_ring *) mhandle;
- thead = temp->prod.head;
- ttail = temp->cons.tail;
- return ttail + temp->size - thead;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_using_count
-* Description : get the in using number of ring
-* Input : mring_handle mhandle
-* Output : None
-* Return Value : u32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-u32
-nsfw_mem_ring_using_count (mring_handle mhandle)
-{
- struct nsfw_mem_ring *temp = NULL;
- u32 thead = 0;
- u32 ttail = 0;
- if (NULL == mhandle)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return 0;
- }
-
- temp = (struct nsfw_mem_ring *) mhandle;
- thead = temp->prod.head;
- ttail = temp->cons.tail;
- return thead - ttail;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_size
-* Description : get size of ring
-* Input : mring_handle mhandle
-* Output : None
-* Return Value : u32
-* Calls :
-* Called By :
-*****************************************************************************/
-u32
-nsfw_mem_ring_size (mring_handle mhandle)
-{
- struct nsfw_mem_ring *temp = NULL;
-
- if (NULL == mhandle)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return 0;
- }
-
- temp = (struct nsfw_mem_ring *) mhandle;
-
- return temp->size;
-}
-
-#ifdef SYS_MEM_RES_STAT
-/*****************************************************************************
-* Prototype : nsfw_mem_mbfpool_free_count
-* Description : get the free mbuf count of a mbuf pool
-* Input : mpool_handle mhandle
-* Output : None
-* Return Value : u32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-u32
-nsfw_mem_mbfpool_free_count (mpool_handle mhandle)
-{
- if (!mhandle)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return 0;
- }
- struct common_mem_mempool *mp = (struct common_mem_mempool *) mhandle;
- struct common_mem_ring *mp_ring =
- (struct common_mem_ring *) (mp->ring_align);
- if (!mp_ring)
- {
- NSCOMM_LOGERR ("ring is null");
- return 0;
- }
- u32 p_head = mp_ring->prod.head;
- u32 c_tail = mp_ring->cons.tail;
-
- return p_head - c_tail;
-}
-#endif /* SYS_MEM_RES_STAT */
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_release
-* Description : release a ring memory
-* notes : the length of name must be less than NSFW_MEM_APPNAME_LENGTH
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_mem_ring_release (nsfw_mem_name * pname)
-{
- NSFW_MEM_NAME_CHECK_RET_ERR (pname, "ring release");
- MEM_OP_CALL_OK_RET (pname->entype, mem_ops_ring_release, (pname));
- NSCOMM_LOGERR ("ring release fail] name=%s, type=%d", pname->aname,
- pname->entype);
- return NSFW_MEM_ERR;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_get_len
-* Description : statics mbufpool, sppool, ring mem size.
-* return: <=0, err happen, >0 mem size
-* NSFW_MEM_MZONE: not surport because you already know the length when create
-* Input : void * handle
-* nsfw_mem_struct_type type
-* Output : None
-* Return Value : ssize_t
-* Calls :
-* Called By :
-*****************************************************************************/
-ssize_t
-nsfw_mem_get_len (void *handle, nsfw_mem_struct_type type)
-{
- if (NULL == handle)
- {
- NSCOMM_LOGERR ("input para error] handle=%p", handle);
- return -1;
- }
- if ((NSFW_MEM_SPOOL == type) || (NSFW_MEM_RING == type))
- {
- struct nsfw_mem_ring *ring = (struct nsfw_mem_ring *) handle;
- if (ring->memtype >= NSFW_MEM_TYPEMAX)
- {
- NSCOMM_LOGERR ("invalid ring] ring type=%u ,handle=%p",
- ring->memtype, handle);
- return -1;
- }
- MEM_OP_CALL_OK_RET (ring->memtype, mem_ops_mem_statics, (handle, type));
- }
- else
- {
- MEM_OP_CALL_OK_RET (NSFW_SHMEM, mem_ops_mem_statics, (handle, type));
- }
- return -1;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbuf_pool_recycle
-* Description : recycle mbuf
-* Input : mpool_handle handle
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_mem_mbuf_pool_recycle (mpool_handle handle)
-{
- MEM_OP_CALL_OK_RET (NSFW_SHMEM, mem_ops_mbuf_recycle, (handle));
- return -1;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_sp_iterator
-* Description : spool iterator
-* Input : mpool_handle handle
-* u32 start
-* u32 end
-* nsfw_mem_item_fun fun
-* void *argv
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_sp_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv)
-{
- MEM_OP_CALL_OK_RET (NSFW_SHMEM, mem_ops_sp_iterator,
- (handle, start, end, fun, argv));
- return -1;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_mbuf_iterator
-* Description : mbuf iterator
-* Input : mpool_handle handle
-* u32 start
-* u32 end
-* nsfw_mem_item_fun fun
-* void *argv
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_mem_mbuf_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv)
-{
- MEM_OP_CALL_OK_RET (NSFW_SHMEM, mem_ops_mbuf_iterator,
- (handle, start, end, fun, argv));
- return -1;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_dfx_ring_print
-* Description : print ring info
-* Input : mring_handle mhandle
-* Output : None
-* Return Value : if no err happen, return the length of string print, 0 or -1 maybe err happen
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_mem_dfx_ring_print (mring_handle mhandle, char *pbuf, int length)
-{
- struct nsfw_mem_ring *temp = (struct nsfw_mem_ring *) mhandle;
- u32 head = 0;
- u32 tail = 0;
- int ret = 0;
- if ((!temp) || (!pbuf) || (length <= 0))
- {
- return 0;
- }
- head = temp->prod.head;
- tail = temp->cons.tail;
- ret =
- SPRINTF_S (pbuf, length,
- "[.Head=%u,\n .Tail=%u,\n .(|Tail-Head|)=%u,\n .size=%u,\n .mask=%u]\n",
- head, tail, (tail >= head) ? (tail - head) : (head - tail),
- temp->size, temp->mask);
- return ret;
-}
diff --git a/src/framework/common/mem_mgr/nsfw_mem_construct.c b/src/framework/common/mem_mgr/nsfw_mem_construct.c
deleted file mode 100644
index ed6fe27..0000000
--- a/src/framework/common/mem_mgr/nsfw_mem_construct.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "nsfw_init.h"
-#include "nsfw_mem_api.h"
-
-NSFW_MODULE_NAME (NSFW_MEM_MGR_MODULE)
-NSFW_MODULE_PRIORITY (10) NSFW_MODULE_INIT (nsfw_mem_init)
diff --git a/src/framework/common/mem_mgr/nsfw_mem_desc.c b/src/framework/common/mem_mgr/nsfw_mem_desc.c
deleted file mode 100644
index d0fbfd3..0000000
--- a/src/framework/common/mem_mgr/nsfw_mem_desc.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <sys/types.h>
-#include <unistd.h>
-#include "nsfw_mem_desc.h"
-#include "nsfw_shmem_mdesc.h"
-#include "nsfw_nshmem_mdesc.h"
-#include "nsfw_shmem_ring.h"
-#include "nsfw_nshmem_ring.h"
-
-/* *INDENT-OFF* */
-/*the order you add must be NSFW_SHMEM, NSFW_NSHMEM*/
-nsfw_mem_attr g_nsfw_mem_ops[] =
-{
- {NSFW_SHMEM, &g_shmem_ops},
- {NSFW_NSHMEM, &g_nshmem_ops},
-};
-
-i32 g_mem_type_num = sizeof(g_nsfw_mem_ops) / sizeof(nsfw_mem_attr);
-
-
-nsfw_ring_ops g_ring_ops_arry[NSFW_MEM_TYPEMAX][NSFW_MPOOL_TYPEMAX] = {
- {
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_shmem_ring_sp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_shmem_ring_sc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_shmem_ring_sc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_shmem_ring_mp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_shmem_ring_sc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_shmem_ring_sc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_shmem_ring_sp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_shmem_ring_mc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_shmem_ring_mc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_shmem_ring_mp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_shmem_ring_mc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_shmem_ring_mc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_shmem_ring_singlethread_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_shmem_ring_singlethread_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_shmem_ring_singlethread_dequeuev
- }
- },
- {
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_nshmem_ring_sp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_nshmem_ring_sc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_nshmem_ring_sc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_nshmem_ring_mp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_nshmem_ring_sc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_nshmem_ring_sc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_nshmem_ring_sp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_nshmem_ring_mc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_nshmem_ring_mc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_nshmem_ring_mp_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_nshmem_ring_mc_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_nshmem_ring_mc_dequeuev
- },
- {
- (nsfw_mem_ring_enqueue_fun)nsfw_nshmem_ring_singlethread_enqueue, \
- (nsfw_mem_ring_dequeue_fun)nsfw_nshmem_ring_singlethread_dequeue, \
- (nsfw_mem_ring_dequeuev_fun)nsfw_nshmem_ring_singlethread_dequeuev
- }
- }
-};
-/* *INDENT-ON* */
diff --git a/src/framework/common/mem_mgr/nsfw_mem_stat.c b/src/framework/common/mem_mgr/nsfw_mem_stat.c
deleted file mode 100644
index f7a1f41..0000000
--- a/src/framework/common/mem_mgr/nsfw_mem_stat.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdlib.h>
-#include "types.h"
-#include "nstack_securec.h"
-#include "nsfw_init.h"
-
-#include "nstack_log.h"
-#include "nsfw_maintain_api.h"
-#include "nsfw_mem_api.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-#define NSFW_MEM_STAT_NUM 512
-
-#define NSFW_MEM_STAT_MODULE "nsfw_mem_stat_module"
-
-typedef struct _nsfw_mem_stat
-{
- u8 mem_type;
- u8 alloc_flag;
- char module[NSFW_MEM_MODULE_LEN];
- char mem_name[NSFW_MEM_NAME_LEN];
- u32 mem_size;
-} nsfw_mem_stat_t;
-
-nsfw_mem_stat_t g_mem_stat[NSFW_MEM_STAT_NUM];
-
-#ifdef SYS_MEM_RES_STAT
-#define MAX_STAT_ITEM_NUM 20
-typedef struct _mem_stat_item_t
-{
- char name[32];
- u64 size;
-} mem_stat_item_t;
-
-typedef struct _mem_stat_mgr_t
-{
- u32 item_num;
- mem_stat_item_t item[MAX_STAT_ITEM_NUM];
-} mem_stat_mgr;
-
-mem_stat_mgr g_max_mem_list;
-#endif
-
-/*****************************************************************************
-* Prototype : nsfw_mem_stat
-* Description : add memory stat
-* Input : char *module
-* char *mem_name
-* u8 mem_type
-* u32 mem_size
-* Output : None
-* Return Value : void
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-void
-nsfw_mem_stat (char *module, char *mem_name, u8 mem_type, u32 mem_size)
-{
- if (NULL == module || NULL == mem_name)
- {
- NSFW_LOGERR ("argv err]module=%p,mem_name=%p", module, mem_name);
- return;
- }
-
- int i;
- nsfw_mem_stat_t *mem_stat_item = NULL;
- for (i = 0; i < NSFW_MEM_STAT_NUM; i++)
- {
- if (FALSE == g_mem_stat[i].alloc_flag)
- {
- g_mem_stat[i].alloc_flag = TRUE;
- mem_stat_item = &g_mem_stat[i];
- break;
- }
- }
-
- if (NULL == mem_stat_item)
- {
- NSFW_LOGERR ("mem stat full]module=%s,type=%u,name=%s,size=%u",
- module, mem_type, mem_name, mem_size);
- return;
- }
-
- mem_stat_item->mem_type = mem_type;
- mem_stat_item->mem_size = mem_size;
-
- if (EOK != STRCPY_S (mem_stat_item->module, NSFW_MEM_MODULE_LEN, module))
- {
- NSFW_LOGERR ("STRNCPY_S failed");
- return;
- }
- if (EOK != STRCPY_S (mem_stat_item->mem_name, NSFW_MEM_NAME_LEN, mem_name))
- {
- NSFW_LOGERR ("STRNCPY_S failed");
- return;
- }
-
- return;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_stat_print
-* Description : print all memory info
-* Input : None
-* Output : None
-* Return Value : void
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-void
-nsfw_mem_stat_print ()
-{
- int i;
- for (i = 0; i < NSFW_MEM_STAT_NUM; i++)
- {
- if (TRUE == g_mem_stat[i].alloc_flag)
- {
- NSFW_LOGINF ("mem_module=%s,name=%s,type=%u,size=%u",
- g_mem_stat[i].module, g_mem_stat[i].mem_name,
- g_mem_stat[i].mem_type, g_mem_stat[i].mem_size);
- }
- }
-
-}
-
-#ifdef SYS_MEM_RES_STAT
-void
-clear_mem_stat_item ()
-{
- if (EOK != MEMSET_S ((char *) &g_max_mem_list, sizeof (mem_stat_mgr),
- 0, sizeof (mem_stat_mgr)))
- {
- NSFW_LOGERR ("MEMSET_S failed");
- }
-}
-
-void
-insert_mem_stat_item (char *name, u64 len)
-{
- int j, temp;
-
- if (g_max_mem_list.item_num == 0)
- {
- if (EOK !=
- STRCPY_S (g_max_mem_list.item[0].name,
- sizeof (g_max_mem_list.item[0].name), name))
- {
- NSFW_LOGERR ("STRCPY_S failed");
- }
- g_max_mem_list.item[0].size = len;
- g_max_mem_list.item_num++;
- return;
- }
- else if (g_max_mem_list.item_num < MAX_STAT_ITEM_NUM)
- {
- if (len <= g_max_mem_list.item[g_max_mem_list.item_num - 1].size)
- {
- if (EOK !=
- STRCPY_S (g_max_mem_list.item[g_max_mem_list.item_num].name,
- sizeof (g_max_mem_list.item
- [g_max_mem_list.item_num].name), name))
- {
- NSFW_LOGERR ("STRCPY_S failed");
- }
- g_max_mem_list.item[g_max_mem_list.item_num].size = len;
- g_max_mem_list.item_num++;
- return;
- }
- j = 0;
- temp = g_max_mem_list.item_num;
- while (j < temp)
- {
- if (len >= g_max_mem_list.item[j].size)
- {
- goto insert_it;
- }
- j++;
- }
- if (j == temp)
- {
- if (EOK !=
- STRCPY_S (g_max_mem_list.item[j].name,
- sizeof (g_max_mem_list.item[j].name), name))
- {
- NSFW_LOGERR ("STRCPY_S failed");
- }
- g_max_mem_list.item[j].size = len;
- g_max_mem_list.item_num++;
- return;
- }
- }
- else
- {
- j = 0;
- temp = MAX_STAT_ITEM_NUM - 1;
- while (j < MAX_STAT_ITEM_NUM)
- {
- if (len >= g_max_mem_list.item[j].size)
- {
- goto insert_it;
- }
- j++;
- }
- }
-
- return;
-
-insert_it:
- while (temp - 1 >= j)
- {
- if (EOK !=
- STRCPY_S (g_max_mem_list.item[temp].name,
- sizeof (g_max_mem_list.item[temp].name),
- g_max_mem_list.item[temp - 1].name))
- {
- NSFW_LOGERR ("STRCPY_S failed");
- }
- g_max_mem_list.item[temp].size = g_max_mem_list.item[temp - 1].size;
- temp--;
- }
- if (EOK !=
- STRCPY_S (g_max_mem_list.item[j].name,
- sizeof (g_max_mem_list.item[j].name), name))
- {
- NSFW_LOGERR ("STRCPY_S failed");
- }
- g_max_mem_list.item[j].size = len;
- g_max_mem_list.item_num++;
- return;
-}
-
-int
-get_mem_stat_item (int idx, char **name, u64 * len)
-{
- if (idx < 0 || idx >= MAX_STAT_ITEM_NUM)
- {
- return -1;
- }
-
- *name = g_max_mem_list.item[idx].name;
- *len = g_max_mem_list.item[idx].size;
-
- return 0;
-}
-#endif
-
-static int nsfw_mem_stat_init (void *param);
-static int
-nsfw_mem_stat_init (void *param)
-{
- MEM_STAT (NSFW_MEM_STAT_MODULE, "g_mem_stat", NSFW_NSHMEM,
- sizeof (g_mem_stat));
- nsfw_mem_stat_print ();
-#ifdef SYS_MEM_RES_STAT
- clear_mem_stat_item ();
-#endif
- return 0;
-}
-
-/* *INDENT-OFF* */
-NSFW_MODULE_NAME (NSFW_MEM_STAT_MODULE)
-NSFW_MODULE_PRIORITY (99)
-NSFW_MODULE_INIT (nsfw_mem_stat_init)
-/* *INDENT-ON* */
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif /* __cplusplus */
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.c b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.c
deleted file mode 100644
index fdb2079..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "nsfw_mem_desc.h"
-#include "nsfw_nshmem_mng.h"
-#include "nsfw_nshmem_mdesc.h"
-
-/*no share memory access inferface*/
-nsfw_mem_ops g_nshmem_ops = {
- nsfw_nshmem_init,
- nsfw_nshmem_destory,
- nsfw_nshmem_create,
- NULL,
- nsfw_nshmem_lookup,
- nsfw_nshmem_release,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- nsfw_nshmem_spcreate,
- NULL,
- NULL,
- nsfw_nshmem_sprelease,
- nsfw_nshmem_sp_lookup,
- nsfw_nshmem_ringcreate,
- NULL,
- nsfw_nshmem_ringrelease,
- nsfw_nshmem_static,
- NULL,
- NULL, /*mem_ops_sp_iterator */
- NULL, /*mem_ops_mbuf_iterator */
-};
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.h b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.h
deleted file mode 100644
index 1b63520..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mdesc.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_NSHMEM_MDESC_H
-#define _NSFW_NSHMEM_MDESC_H
-
-extern nsfw_mem_ops g_nshmem_ops;
-
-#endif
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.c b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.c
deleted file mode 100644
index 49e3769..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.c
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdlib.h>
-#include "nstack_log.h"
-#include "nstack_securec.h"
-#include "nsfw_mem_desc.h"
-#include "nsfw_ring_fun.h"
-#include "nsfw_nshmem_ring.h"
-#include "nsfw_nshmem_mng.h"
-
-#include "common_func.h"
-
-#define nsfw_get_glb_lock() (&g_nshmem_internal_cfg->mlock)
-
-#define NSFW_NSHMEM_INIT_CHK_RET_NULL() \
- if ((!g_nshmem_internal_cfg) || (!g_nshmem_localdata)) \
- { \
- NSCOMM_LOGDBG("Error] g_nshmem_internal_cfg=%p, g_nshmem_localdata=%p", g_nshmem_internal_cfg, g_nshmem_localdata); \
- return NULL; \
- }
-
-#define NSFW_NSHMEM_INIT_CHK_RET() \
- if ((!g_nshmem_internal_cfg) || (!g_nshmem_localdata)) \
- { \
- NSCOMM_LOGDBG("Error] g_nshmem_internal_cfg=%p, g_nshmem_localdata=%p", g_nshmem_internal_cfg, g_nshmem_localdata); \
- return NSFW_MEM_ERR; \
- }
-
-nsfw_mem_localdata *g_nshmem_localdata = NULL;
-nsfw_nshmem_cfg *g_nshmem_internal_cfg = NULL;
-
-/*look up a mem zone*/
-NSTACK_STATIC inline nsfw_nshmem_mzone *
-nsfw_nshmem_get_free_zone (void)
-{
- int icnt = 0;
-
- /*g_nshmem_internal_cfg must not be null if come here */
- for (icnt = 0; icnt < COMMON_MEM_MAX_MEMZONE; icnt++)
- {
- if (g_nshmem_internal_cfg->amemzone[icnt].addr == NULL)
- {
- return &g_nshmem_internal_cfg->amemzone[icnt];
- }
- }
-
- return NULL;
-}
-
-NSTACK_STATIC inline void
-nsfw_nshmem_free_zone (nsfw_nshmem_mzone * pzone)
-{
- nsfw_nshmem_mzone *pzonebase = &g_nshmem_internal_cfg->amemzone[0];
- nsfw_nshmem_mzone *pzoneend =
- &g_nshmem_internal_cfg->amemzone[NSFW_NSHMEM_ZONE_MAX - 1];
-
- if ((((int) ((char *) pzone - (char *) pzonebase) < 0)
- || ((int) ((char *) pzone - (char *) pzoneend) > 0))
- && ((unsigned int) ((char *) pzone - (char *) pzonebase) %
- sizeof (nsfw_nshmem_mzone) != 0))
- {
- NSCOMM_LOGERR ("nshmem free fail] mem=%p", pzone);
- return;
- }
- if (pzone->addr)
- {
- free (pzone->addr);
- }
- pzone->addr = NULL;
-
- int ret = MEMSET_S ((void *) pzone, sizeof (nsfw_nshmem_mzone), 0,
- sizeof (nsfw_nshmem_mzone));
- if (EOK != ret)
- {
- NSCOMM_LOGERR ("MEMSET_S failed] mem=%p, ret=%d", pzone, ret);
- }
- return;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_init
-* Description : nsh module init
-* Input : nsfw_mem_para* para
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_nshmem_init (nsfw_mem_para * para)
-{
- i32 iret = NSFW_MEM_OK;
- NSCOMM_LOGINF ("nsfw nshmem init begin");
- g_nshmem_localdata =
- (nsfw_mem_localdata *) malloc (sizeof (nsfw_mem_localdata));
-
- if (NULL == g_nshmem_localdata)
- {
- NSCOMM_LOGERR ("nshmem init g_nshmem_localdata malloc fail");
- return NSFW_MEM_ERR;
- }
-
- iret =
- MEMSET_S (g_nshmem_localdata, sizeof (nsfw_mem_localdata), 0,
- sizeof (nsfw_mem_localdata));
-
- if (EOK != iret)
- {
- NSCOMM_LOGERR ("nshmem init g_nshmem_localdata MEMSET_S fail");
- goto ERROR;
- }
-
- g_nshmem_internal_cfg =
- (nsfw_nshmem_cfg *) malloc (sizeof (nsfw_nshmem_cfg));
-
- if (NULL == g_nshmem_internal_cfg)
- {
- NSCOMM_LOGERR ("nshmem init g_nshmem_internal_cfg malloc fail");
- goto ERROR;
- }
-
- iret =
- MEMSET_S (g_nshmem_internal_cfg, sizeof (nsfw_nshmem_cfg), 0,
- sizeof (nsfw_nshmem_cfg));
-
- if (EOK != iret)
- {
- NSCOMM_LOGERR ("nshmem init g_nshmem_internal_cfg MEMSET_S fail");
- goto ERROR;
- }
-
- g_nshmem_localdata->enflag = para->enflag;
- NSCOMM_LOGINF ("nsfw nshmem init end");
- goto OK;
-
-ERROR:
- iret = NSFW_MEM_ERR;
- nsfw_nshmem_destory ();
- return iret;
-OK:
- iret = NSFW_MEM_OK;
- return iret;
-}
-
-/*
- * memory destory
- */
-void
-nsfw_nshmem_destory (void)
-{
- if (g_nshmem_localdata)
- {
- free (g_nshmem_localdata);
- g_nshmem_localdata = NULL;
- }
-
- if (g_nshmem_internal_cfg)
- {
- free (g_nshmem_internal_cfg);
- g_nshmem_internal_cfg = NULL;
- }
-
- return;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_reserv_safe
-* Description : malloc a memory and save to memzone
-* Input : const char* name
-* size_t length
-* Output : None
-* Return Value : mzone_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mzone_handle
-nsfw_nshmem_reserv_safe (const char *name, size_t length)
-{
- void *addr = NULL;
- i32 iret = NSFW_MEM_OK;
- nsfw_nshmem_mzone *pmemzone = NULL;
-
- if (length <= 0)
- {
- return NULL;
- }
-
- nsfw_write_lock (nsfw_get_glb_lock ());
-
- addr = malloc (length);
- if (!addr)
- {
- NSCOMM_LOGERR ("nshmem malloc addr fail] addr=%p", addr);
- nsfw_write_unlock (nsfw_get_glb_lock ());
- return NULL;
- }
-
- iret = MEMSET_S (addr, length, 0, length);
- if (EOK != iret)
- {
- NSCOMM_LOGERR ("nshmem malloc addr MEMSET_S fail] addr=%p", addr);
- free (addr);
- nsfw_write_unlock (nsfw_get_glb_lock ());
- return NULL;
- }
-
- pmemzone = nsfw_nshmem_get_free_zone ();
-
- if (!pmemzone)
- {
- NSCOMM_LOGERR ("nshmem get free zone fail");
- free (addr);
- nsfw_write_unlock (nsfw_get_glb_lock ());
- return NULL;
- }
-
- pmemzone->addr = addr;
- pmemzone->length = length;
- /*name must be less than NSFW_MEM_APPNAME_LENGTH */
- if (EOK !=
- STRCPY_S ((char *) pmemzone->aname, sizeof (pmemzone->aname), name))
- {
- NSCOMM_LOGERR ("STRCPY_S failed]name=%s", name);
- free (addr);
- nsfw_write_unlock (nsfw_get_glb_lock ());
- return NULL;
- }
-
- nsfw_write_unlock (nsfw_get_glb_lock ());
- return addr;
-}
-
-/*
- * create no shared memory
- * nsfw_mem_zone::stname no shared memory name
- * nsfw_mem_zone::isize memory size
- */
-mzone_handle
-nsfw_nshmem_create (nsfw_mem_zone * pinfo)
-{
-
- NSFW_NAME_LENCHECK_RET_NULL (pinfo->stname.aname, "nshmem create");
- NSFW_NSHMEM_INIT_CHK_RET_NULL ();
- return nsfw_nshmem_reserv_safe (pinfo->stname.aname, pinfo->length);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_lookup
-* Description : find a block memory by name
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : mzone_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mzone_handle
-nsfw_nshmem_lookup (nsfw_mem_name * pname)
-{
- int icnt = 0;
- nsfw_nshmem_mzone *mz = NULL;
-
- NSFW_NAME_LENCHECK_RET_NULL (pname->aname, "nshmem lookup");
- NSFW_NSHMEM_INIT_CHK_RET_NULL ();
- nsfw_read_lock (nsfw_get_glb_lock ());
-
- for (icnt = 0; icnt < NSFW_NSHMEM_ZONE_MAX; icnt++)
- {
- mz = &g_nshmem_internal_cfg->amemzone[icnt];
-
- if (mz->addr != NULL
- && !strncmp (pname->aname, mz->aname, NSFW_MEM_NAME_LENGTH))
- {
- nsfw_read_unlock (nsfw_get_glb_lock ());
- return mz->addr;
- }
- }
-
- nsfw_read_unlock (nsfw_get_glb_lock ());
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_release
-* Description : free a block memory
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_nshmem_release (nsfw_mem_name * pname)
-{
- int icnt = 0;
- nsfw_nshmem_mzone *mz = NULL;
-
- NSFW_NAME_LENCHECK_RET (pname->aname, "nshmem release");
- NSFW_NSHMEM_INIT_CHK_RET ();
- nsfw_read_lock (nsfw_get_glb_lock ());
-
- for (icnt = 0; icnt < NSFW_NSHMEM_ZONE_MAX; icnt++)
- {
- mz = &g_nshmem_internal_cfg->amemzone[icnt];
-
- if (mz->addr != NULL
- && !strncmp (pname->aname, mz->aname, NSFW_MEM_NAME_LENGTH))
- {
- nsfw_nshmem_free_zone (mz);
- nsfw_read_unlock (nsfw_get_glb_lock ());
- return NSFW_MEM_OK;
- }
- }
-
- nsfw_read_unlock (nsfw_get_glb_lock ());
- return NSFW_MEM_OK;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_spcreate
-* Description : create a memory pool by ring
-* Input : nsfw_mem_sppool* pmpinfo
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*****************************************************************************/
-mring_handle
-nsfw_nshmem_spcreate (nsfw_mem_sppool * pmpinfo)
-{
- size_t len = 0;
- unsigned int usnum = common_mem_align32pow2 (pmpinfo->usnum + 1);
- unsigned int uselt_size = pmpinfo->useltsize;
- struct nsfw_mem_ring *pringhead = NULL;
- unsigned int uscnt = 0;
- char *pmz = NULL;
- NSFW_NAME_LENCHECK_RET_NULL (pmpinfo->stname.aname, "nshmem sp create");
- NSFW_NSHMEM_INIT_CHK_RET_NULL ();
-
- len =
- sizeof (struct nsfw_mem_ring) +
- (size_t) usnum *sizeof (union RingData_U) + (size_t) usnum *uselt_size;
- pringhead =
- (struct nsfw_mem_ring *) nsfw_nshmem_reserv_safe (pmpinfo->stname.aname,
- len);
-
- if (!pringhead)
- {
- NSCOMM_LOGERR ("nshmem sp create mzone reserv fail");
- return NULL;
- }
-
- nsfw_mem_ring_init (pringhead, usnum, pringhead, NSFW_NSHMEM,
- pmpinfo->enmptype);
- pmz =
- ((char *) pringhead + sizeof (struct nsfw_mem_ring) +
- usnum * sizeof (union RingData_U));
-
- for (uscnt = 0; uscnt < usnum; uscnt++)
- {
- if (0 ==
- g_ring_ops_arry[pringhead->memtype][pringhead->
- ringflag].ring_ops_enqueue
- (pringhead, (void *) pmz))
- {
- NSCOMM_LOGERR ("nsfw_nshmem_ringenqueue enqueue fail] uscnt=%u",
- uscnt);
- }
-
- pmz = pmz + uselt_size;
- }
-
- return pringhead;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_sp_lookup
-* Description : look up a sppool memory
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*****************************************************************************/
-mring_handle
-nsfw_nshmem_sp_lookup (nsfw_mem_name * pname)
-{
- return nsfw_nshmem_lookup (pname);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_sprelease
-* Description : release a sp pool
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_nshmem_sprelease (nsfw_mem_name * pname)
-{
- NSFW_NAME_LENCHECK_RET (pname->aname, "nshmem sp mempool release");
- NSFW_NSHMEM_INIT_CHK_RET ();
- return nsfw_nshmem_release (pname);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_ringcreate
-* Description : create a ring
-* Input : nsfw_mem_mring* pringinfo
-* Output : None
-* Return Value : mring_handle
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-mring_handle
-nsfw_nshmem_ringcreate (nsfw_mem_mring * pringinfo)
-{
- size_t len = 0;
- unsigned int usnum = common_mem_align32pow2 (pringinfo->usnum + 1);
- struct nsfw_mem_ring *pringhead = NULL;
- NSFW_NAME_LENCHECK_RET_NULL (pringinfo->stname.aname, "nshmem ring create");
- NSFW_NSHMEM_INIT_CHK_RET_NULL ();
-
- len = sizeof (struct nsfw_mem_ring) + usnum * sizeof (union RingData_U);
- pringhead =
- (struct nsfw_mem_ring *) nsfw_nshmem_reserv_safe (pringinfo->stname.aname,
- len);
-
- if (!pringhead)
- {
- NSCOMM_LOGERR ("nshmem ring create mzone reserv fail");
- return NULL;
- }
-
- nsfw_mem_ring_init (pringhead, usnum, (void *) pringhead, NSFW_NSHMEM,
- pringinfo->enmptype);
- return pringhead;
-
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_ringrelease
-* Description : release a nsh ring memory
-* Input : nsfw_mem_name* pname
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32
-nsfw_nshmem_ringrelease (nsfw_mem_name * pname)
-{
- NSFW_NAME_LENCHECK_RET (pname->aname, "nshmem ring mempool release");
- NSFW_NSHMEM_INIT_CHK_RET ();
- return nsfw_nshmem_release (pname);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_sppool_statics
-* Description : static the memory size of sppool
-* Input : mring_handle sppool
-* Output : None
-* Return Value : ssize_t
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-ssize_t
-nsfw_nshmem_sppool_statics (mring_handle sppool)
-{
- struct nsfw_mem_ring *phead = (struct nsfw_mem_ring *) sppool;
-
- return sizeof (struct nsfw_mem_ring) +
- (ssize_t) phead->size * sizeof (union RingData_U) +
- (ssize_t) phead->size * phead->eltsize;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_ring_statics
-* Description : static the memory size of ring
-* Input : mring_handle handle
-* Output : None
-* Return Value : ssize_t
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-ssize_t
-nsfw_nshmem_ring_statics (mring_handle handle)
-{
- struct nsfw_mem_ring *ring = (struct nsfw_mem_ring *) handle;
- return ring->size * sizeof (union RingData_U) +
- sizeof (struct nsfw_mem_ring);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_nshmem_static
-* Description : static the memory size according to mem type
-* Input : void* handle
-* nsfw_mem_struct_type type
-* Output : None
-* Return Value : ssize_t
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-ssize_t
-nsfw_nshmem_static (void *handle, nsfw_mem_struct_type type)
-{
- switch (type)
- {
- case NSFW_MEM_MBUF:
- return -1;
- case NSFW_MEM_SPOOL:
- return nsfw_nshmem_sppool_statics (handle);
- case NSFW_MEM_RING:
- return nsfw_nshmem_ring_statics (handle);
- default:
- break;
- }
- return -1;
-}
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.h b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.h
deleted file mode 100644
index 06ab562..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_mng.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_NSHMEM_MNG_H_
-#define _NSFW_NSHMEM_MNG_H_
-
-#include "generic/common_mem_rwlock.h"
-
-#include "common_func.h"
-
-#define NSFW_NSHMEM_ZONE_MAX 2560
-
-typedef struct
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- void *addr;
- int length;
-} nsfw_nshmem_mzone;
-
-typedef struct
-{
- nsfw_nshmem_mzone amemzone[NSFW_NSHMEM_ZONE_MAX];
- common_mem_rwlock_t mlock;
-} nsfw_nshmem_cfg;
-
-/*
- * no share memory module init
- */
-i32 nsfw_nshmem_init (nsfw_mem_para * para);
-
-/*
- * no share memory module destory
- */
-void nsfw_nshmem_destory (void);
-
-/*
- * create a no shared memory
- */
-mzone_handle nsfw_nshmem_create (nsfw_mem_zone * pinfo);
-
-mzone_handle nsfw_nshmem_lookup (nsfw_mem_name * pname);
-
-i32 nsfw_nshmem_release (nsfw_mem_name * pname);
-
-mring_handle nsfw_nshmem_spcreate (nsfw_mem_sppool * pmpinfo);
-
-i32 nsfw_nshmem_sprelease (nsfw_mem_name * pname);
-
-mring_handle nsfw_nshmem_sp_lookup (nsfw_mem_name * pname);
-
-mring_handle nsfw_nshmem_ringcreate (nsfw_mem_mring * pringinfo);
-
-i32 nsfw_nshmem_ringrelease (nsfw_mem_name * pname);
-
-ssize_t nsfw_nshmem_static (void *handle, nsfw_mem_struct_type type);
-
-#endif
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.c b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.c
deleted file mode 100644
index 7e56f3c..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <string.h>
-#include <sched.h>
-#include "nstack_securec.h"
-
-#include "nsfw_mem_desc.h"
-#include "nsfw_nshmem_ring.h"
-#include "nsfw_ring_fun.h"
-#include "common_func.h"
-
-/*copy the data to obj*/
-NSTACK_STATIC inline void
-nsfw_nshmem_ring_obj_copy (struct nsfw_mem_ring *r, uint32_t cons_head,
- void **obj_table, unsigned n)
-{
- uint32_t idx = cons_head & r->mask;
- unsigned i = 0;
- const uint32_t size = r->size;
-
- if (likely (idx + n < size))
- {
- for (i = 0; i < (n & (~(unsigned) 0x3)); i += 4, idx += 4)
- {
- obj_table[i] = (void *) r->ring[idx].data_l;
- obj_table[i + 1] = (void *) r->ring[idx + 1].data_l;
- obj_table[i + 2] = (void *) r->ring[idx + 2].data_l;
- obj_table[i + 3] = (void *) r->ring[idx + 3].data_l;
- }
- switch (n & 0x3)
- {
- case 3:
- obj_table[i++] = (void *) r->ring[idx++].data_l;
-
- case 2:
- obj_table[i++] = (void *) r->ring[idx++].data_l;
-
- case 1:
- obj_table[i++] = (void *) r->ring[idx++].data_l;
- }
- }
- else
- {
- for (i = 0; idx < size; i++, idx++)
- {
- obj_table[i] = (void *) r->ring[idx].data_l;
- }
-
- for (idx = 0; i < n; i++, idx++)
- {
- obj_table[i] = (void *) r->ring[idx].data_l;
- }
- }
-}
-
-/*fork recover*/
-NSTACK_STATIC inline void
-nsfw_nshmem_enqueue_fork_recov (struct nsfw_mem_ring *r)
-{
- u32_t pidflag = 0;
- u32_t curpid = get_sys_pid ();
- int success = 0;
- /*if pid is not the same, maybe mult thread fork happen */
- pidflag = r->prodhflag;
-
- if (unlikely (pidflag != curpid))
- {
- success = common_mem_atomic32_cmpset (&r->prodhflag, pidflag, curpid);
-
- if (unlikely (success != 0))
- {
- /*recover it */
- if (r->prod.tail != r->prod.head)
- {
- r->prod.head = r->prod.tail;
- }
-
- r->prodtflag = curpid;
- }
- }
-
- return;
-}
-
-NSTACK_STATIC inline void
-nsfw_nshmem_dequeue_fork_recov (struct nsfw_mem_ring *r)
-{
- u32_t pidflag = 0;
- u32_t curpid = get_sys_pid ();
- int success = 0;
- /*if pid is not the same, maybe mult thread fork happen */
- pidflag = r->conshflag;
-
- if (unlikely (pidflag != curpid))
- {
- success = common_mem_atomic32_cmpset (&r->conshflag, pidflag, curpid);
-
- if (unlikely (success != 0))
- {
- /*recover it */
- if (r->cons.tail != r->cons.head)
- {
- r->cons.head = r->cons.tail;
- }
-
- r->constflag = curpid;
- }
- }
-
- return;
-}
-
-/*
-this is a multi thread/process enqueue function, please pay attention to the bellow point
-1. while Enqueue corrupt, we may lose one element; because no one to add the Head
-*/
-int
-nsfw_nshmem_ring_mp_enqueue (struct nsfw_mem_ring *mem_ring, void *obj_table)
-{
- uint32_t producer_head, producer_next;
- uint32_t consumer_tail, free_entries;
- int success;
- unsigned rep = 0;
- uint32_t mask = mem_ring->mask;
- uint32_t size = mem_ring->size;
- uint32_t n = 1;
-
- /* move prod.head atomically */
- do
- {
-
- producer_head = mem_ring->prod.head;
- consumer_tail = mem_ring->cons.tail;
- /* The subtraction is done between two unsigned 32bits value
- * (the result is always modulo 32 bits even if we have
- * producer_head > consumer_tail). So 'free_entries' is always between 0
- * and size(ring)-1. */
- free_entries = (size + consumer_tail - producer_head);
-
- /* check that we have enough room in ring */
- if (unlikely (n > free_entries))
- {
- return 0;
- /* Below code is commented currenlty as its a dead code. */
- }
-
- /*if pid is not the same, maybe mult thread fork happen */
- nsfw_nshmem_enqueue_fork_recov (mem_ring);
-
- while (unlikely
- ((mem_ring->prod.tail != mem_ring->prod.head)
- || (mem_ring->prodtflag != mem_ring->prodhflag)))
- {
- common_mem_pause ();
- }
-
- producer_next = producer_head + n;
- success =
- common_mem_atomic32_cmpset (&mem_ring->prod.head, producer_head,
- producer_next);
- }
- while (unlikely (success == 0));
-
- mem_ring->ring[producer_head & mask].data_l = (u64) obj_table;
-
- /*
- * If there are other enqueues in progress that preceded us,
- * we need to wait for them to complete
- */
- while (unlikely (mem_ring->prod.tail != producer_head))
- {
- common_mem_pause ();
-
- /* Set COMMON_RING_PAUSE_REP_COUNT to avoid spin too long waiting
- * for other thread finish. It gives pre-emptied thread a chance
- * to proceed and finish with ring dequeue operation. */
- /* check the queue can be operate */
- if (++rep == 5)
- {
- rep = 0;
- (void) sched_yield ();
- }
- }
-
- mem_ring->prod.tail = producer_next;
- return (int) n;
-}
-
-/*
- this is a single thread/process enqueue function
- */
-int
-nsfw_nshmem_ring_sp_enqueue (struct nsfw_mem_ring *r, void *obj_table)
-{
- uint32_t producer_head, consumer_tail;
- uint32_t producer_next, free_entries;
- uint32_t mask = r->mask;
- uint32_t n = 1;
- uint32_t size = r->size;
-
- producer_head = r->prod.head;
- consumer_tail = r->cons.tail;
- /* The subtraction is done between two unsigned 32bits value
- * (the result is always modulo 32 bits even if we have
- * producer_head > consumer_tail). So 'free_entries' is always between 0
- * and size(ring)-1. */
- free_entries = size + consumer_tail - producer_head;
-
- /* check that we have enough room in ring */
- if (unlikely (n > free_entries))
- {
- return 0;
- }
-
- nsfw_nshmem_enqueue_fork_recov (r);
-
- producer_next = producer_head + n;
- r->prod.head = producer_next;
-
- r->ring[producer_head & mask].data_l = (u64) obj_table;
-
- r->prod.tail = producer_next;
- return (int) n;
-}
-
-/*
- this is enhanced mc_ring_dequeue, support dequeue multi element one time.
-*/
-int
-nsfw_nshmem_ring_mc_dequeuev (struct nsfw_mem_ring *r, void **obj_table,
- unsigned int n)
-{
- uint32_t consumer_head, producer_tail;
- uint32_t consumer_next, entries;
- int success;
- unsigned rep = 0;
- uint32_t num = n;
-
- /* Avoid the unnecessary cmpset operation below, which is also
- * potentially harmful when n equals 0. */
- if (unlikely (num == 0))
- {
- return 0;
- }
-
- nsfw_nshmem_dequeue_fork_recov (r);
-
- /* move cons.head atomically */
- do
- {
- num = n;
- consumer_head = r->cons.head;
- producer_tail = r->prod.tail;
- /* The subtraction is done between two unsigned 32bits value
- * (the result is always modulo 32 bits even if we have
- * cons_head > prod_tail). So 'entries' is always between 0
- * and size(ring)-1. */
- entries = (producer_tail - consumer_head);
-
- /* Set the actual entries for dequeue */
- if (unlikely (num > entries))
- {
- if (likely (entries > 0))
- {
- num = entries;
- }
- else
- {
- return 0;
- }
- }
-
- /* check the queue can be operate */
- while (unlikely
- ((r->cons.tail != r->cons.head)
- || (r->conshflag != r->constflag)))
- {
- common_mem_pause ();
- }
-
- consumer_next = consumer_head + num;
-
- success =
- common_mem_atomic32_cmpset (&r->cons.head, consumer_head,
- consumer_next);
- }
- while (unlikely (success == 0));
-
- nsfw_nshmem_ring_obj_copy (r, consumer_head, obj_table, num);
-
- /*
- * If there are other dequeues in progress that preceded us,
- * we need to wait for them to complete
- */
- while (unlikely (r->cons.tail != consumer_head))
- {
- common_mem_pause ();
-
- /* Set COMMON_RING_PAUSE_REP_COUNT to avoid spin too long waiting
- * for other thread finish. It gives pre-emptied thread a chance
- * to proceed and finish with ring dequeue operation. */
- /* check the queue can be operate */
- if (++rep == 5)
- {
- rep = 0;
- (void) sched_yield ();
- }
- }
-
- r->cons.tail = consumer_next;
-
- return (int) num;
-}
-
-/*this is a multi thread/process dequeue function, please pay attention to the bellow point
-1. while dequeue corrupt, the tail no one added, may multi the try times.
-*/
-int
-nsfw_nshmem_ring_mc_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- return nsfw_nshmem_ring_mc_dequeuev (ring, box, 1);
-}
-
-/*
- this is a single thread/process dequeue function
-*/
-int
-nsfw_nshmem_ring_sc_dequeuev (struct nsfw_mem_ring *r, void **obj_table,
- unsigned int n)
-{
- uint32_t consumer_head, producer_tail;
- uint32_t consumer_next, entries;
- uint32_t inum = n;
- consumer_head = r->cons.head;
- producer_tail = r->prod.tail;
- /* The subtraction is done between two unsigned 32bits value
- * (the result is always modulo 32 bits even if we have
- * cons_head > prod_tail). So 'entries' is always between 0
- * and size(ring)-1. */
- entries = producer_tail - consumer_head;
-
- if (unlikely (inum > entries))
- {
- if (likely (entries > 0))
- {
- inum = entries;
- }
- else
- {
- return 0;
- }
- }
-
- nsfw_nshmem_dequeue_fork_recov (r);
-
- consumer_next = consumer_head + inum;
- r->cons.head = consumer_next;
-
- nsfw_nshmem_ring_obj_copy (r, consumer_head, obj_table, inum);
-
- r->cons.tail = consumer_next;
- return (int) inum;
-}
-
-/*
- this is enhanced mc_ring_dequeue, support dequeue multi element one time.
-*/
-int
-nsfw_nshmem_ring_sc_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- return nsfw_nshmem_ring_sc_dequeuev (ring, box, 1);
-}
-
-/*stack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_nshmem_ring_singlethread_enqueue (struct nsfw_mem_ring *ring, void *box)
-{
- u32 head = 0;
-
- /*if queue is full, just return 0 */
- if (unlikely (ring->prod.head >= (ring->size + ring->cons.tail)))
- {
- return 0;
- }
-
- head = ring->prod.head;
- ring->ring[head & ring->mask].data_l = (u64) box;
- ring->prod.head++;
- return 1;
-}
-
-/*stack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_nshmem_ring_singlethread_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- return nsfw_nshmem_ring_singlethread_dequeuev (ring, box, 1);
-}
-
-/*stack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_nshmem_ring_singlethread_dequeuev (struct nsfw_mem_ring *ring,
- void **box, unsigned int n)
-{
- u32 tail = 0;
- u32 num = 0;
-
- while (num < n)
- {
- tail = ring->cons.tail;
-
- /* if all entries are dequeued return 0 */
- if (unlikely (ring->prod.head == ring->cons.tail))
- {
- return num;
- }
-
- box[num] = (void *) ring->ring[tail & ring->mask].data_l;
- ring->cons.tail++;
- num++;
- }
-
- return num;
-}
diff --git a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.h b/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.h
deleted file mode 100644
index 93a4d4a..0000000
--- a/src/framework/common/mem_mgr/nsfw_nshmem/nsfw_nshmem_ring.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_NSHMEM_RING_H_
-#define _NSFW_NSHMEM_RING_H_
-
-#include <stdint.h>
-
-int nsfw_nshmem_ring_mp_enqueue (struct nsfw_mem_ring *ring, void *box);
-int nsfw_nshmem_ring_sp_enqueue (struct nsfw_mem_ring *ring, void *box);
-int nsfw_nshmem_ring_mc_dequeue (struct nsfw_mem_ring *ring, void **box);
-int nsfw_nshmem_ring_mc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n);
-int nsfw_nshmem_ring_sc_dequeue (struct nsfw_mem_ring *ring, void **box);
-int nsfw_nshmem_ring_sc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n);
-int nsfw_nshmem_ring_singlethread_enqueue (struct nsfw_mem_ring *ring,
- void *box);
-int nsfw_nshmem_ring_singlethread_dequeue (struct nsfw_mem_ring *ring,
- void **box);
-int nsfw_nshmem_ring_singlethread_dequeuev (struct nsfw_mem_ring *ring,
- void **box, unsigned int n);
-
-#endif /*_NSFW_NSHMEM_RING_H_*/
diff --git a/src/framework/common/mem_mgr/nsfw_res_mgr.c b/src/framework/common/mem_mgr/nsfw_res_mgr.c
deleted file mode 100644
index c4d8010..0000000
--- a/src/framework/common/mem_mgr/nsfw_res_mgr.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-/*==============================================*
- * include header files *
- *----------------------------------------------*/
-
-/*==============================================*
- * constants or macros define *
- *----------------------------------------------*/
-
-/*==============================================*
- * project-wide global variables *
- *----------------------------------------------*/
-
-/*==============================================*
- * routines' or functions' implementations *
- *----------------------------------------------*/
-
-#include <stdlib.h>
-#include "types.h"
-#include "nstack_securec.h"
-#include "nsfw_init.h"
-#include "common_mem_mbuf.h"
-
-#include "nstack_log.h"
-#include "nsfw_maintain_api.h"
-
-#include "nsfw_mem_api.h"
-#include "nsfw_fd_timer_api.h"
-#include "nsfw_ring_data.h"
-
-#include "common_func.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-nsfw_res_mgr_item_cfg g_all_res_can[NSFW_MAX_RES_SCAN_COUNT];
-
-#define NSFW_RES_SCAN_TVLAUE_DEF 60
-#define NSFW_RES_SCAN_TVLAUE (g_scan_cfg.scan_tvalue)
-
-typedef struct _nsfw_res_scan_init_cfg
-{
- nsfw_timer_info *scan_timer;
- u16 scan_tvalue;
-} nsfw_res_scan_init_cfg;
-nsfw_res_scan_init_cfg g_scan_cfg;
-
-u8
-nsfw_res_mgr_reg (nsfw_res_scn_cfg * cfg)
-{
- if (NULL == cfg)
- {
- NSFW_LOGERR ("argv err!");
- return FALSE;
- }
-
- u32 i;
- for (i = 0; i < NSFW_MAX_RES_SCAN_COUNT; i++)
- {
- if ((NULL == g_all_res_can[i].scn_cfg.free_fun)
- &&
- (__sync_bool_compare_and_swap
- (&g_all_res_can[i].scn_cfg.free_fun, 0, cfg->free_fun)))
- {
- g_all_res_can[i].scn_cfg = *cfg;
- NSFW_LOGINF ("reg res_mgr fun suc]fun=%p,data=%p", cfg->free_fun,
- cfg->data);
- return TRUE;
- }
- }
-
- NSFW_LOGERR
- ("reg]type=%u,per=%u,chk=%u,cyc=%u,total=%u,size=%u,offset=%u,fun=%p,data=%p",
- cfg->type, cfg->force_free_percent, cfg->force_free_chk_num,
- cfg->num_per_cyc, cfg->total_num, cfg->elm_size, cfg->res_mem_offset,
- cfg->res_mem_offset, cfg->free_fun, cfg->data);
- return FALSE;
-}
-
-static inline u32
-nsfw_get_alloc_count (u32 head, u32 tail)
-{
- if (head >= tail)
- {
- return head - tail;
- }
-
- return head + (0xFFFFFFFF - tail);
-}
-
-int
-nsfw_res_sp_item_chk (void *data, void *argv)
-{
- nsfw_res_mgr_item_cfg *res_scn_item = (nsfw_res_mgr_item_cfg *) argv;
- nsfw_res_scn_cfg *scn_cfg = &res_scn_item->scn_cfg;
- char *elm = (char *) data;
-
- if (NULL == scn_cfg || NULL == elm)
- {
- return FALSE;
- }
-
- nsfw_res *res_item = NULL;
- res_item = (nsfw_res *) (elm + scn_cfg->res_mem_offset);
- if (0 == res_item->chk_count)
- {
- res_item->data = res_scn_item->cons_head;
- }
- res_item->chk_count++;
-
- if (res_item->chk_count < scn_cfg->force_free_chk_num)
- {
- return FALSE;
- }
-
- if (res_scn_item->free_percent > scn_cfg->force_free_percent)
- {
- return FALSE;
- }
-
- if (scn_cfg->total_num * scn_cfg->alloc_speed_factor >
- nsfw_get_alloc_count (res_scn_item->cons_head, res_item->data))
- {
- return FALSE;
- }
-
- if (NULL == scn_cfg->free_fun)
- {
- return FALSE;
- }
-
- if (TRUE == scn_cfg->free_fun ((void *) elm))
- {
- res_scn_item->force_count++;
- }
-
- res_item->chk_count = 0;
- return TRUE;
-}
-
-int
-nsfw_res_flash_data (nsfw_res_mgr_item_cfg * res_scn_item)
-{
- nsfw_res_scn_cfg *scn_cfg = &res_scn_item->scn_cfg;
-
- u32 cur_head = 0;
- u32 cur_tail = 0;
- u32 elm_num = 0;
- u32 free_count = 0;
-
- switch (scn_cfg->type)
- {
- case NSFW_RES_SCAN_MBUF:
- {
- struct common_mem_ring *ring =
- (struct common_mem_ring *) scn_cfg->mgr_ring;
- struct common_mem_mempool *mp =
- (struct common_mem_mempool *) scn_cfg->data;
- if (NULL == ring)
- {
- ring = mp->pool_data;
- if (NULL == ring)
- return FALSE;
- }
- cur_head = ring->prod.head;
- cur_tail = ring->cons.head;
- elm_num = mp->size;
- }
- break;
- case NSFW_RES_SCAN_SPOOL:
- {
- struct nsfw_mem_ring *mem_ring =
- (struct nsfw_mem_ring *) scn_cfg->mgr_ring;
- if (NULL == mem_ring)
- {
- mem_ring = (struct nsfw_mem_ring *) scn_cfg->data;
- if (NULL == mem_ring)
- return FALSE;
- }
-
- cur_head = mem_ring->prod.head;
- cur_tail = mem_ring->cons.tail;
- elm_num = mem_ring->size;
- }
- break;
- case NSFW_RES_SCAN_ARRAY:
- {
- struct nsfw_mem_ring *mem_ring =
- (struct nsfw_mem_ring *) scn_cfg->mgr_ring;
- if (NULL == mem_ring)
- {
- return FALSE;
- }
-
- cur_head = mem_ring->prod.head;
- cur_tail = mem_ring->cons.tail;
- elm_num = scn_cfg->total_num;
- }
- break;
- default:
- return FALSE;
- }
-
- free_count = nsfw_get_alloc_count (cur_head, cur_tail);
-
- res_scn_item->cons_head = cur_head;
- res_scn_item->prod_head = cur_tail;
- if (0 != elm_num)
- {
- res_scn_item->free_percent = free_count * 100 / elm_num;
- }
- else
- {
- res_scn_item->free_percent = 100;
- }
-
- scn_cfg->total_num = elm_num;
- return TRUE;
-}
-
-void
-nsfw_res_scan_mem (nsfw_res_mgr_item_cfg * res_scn_item)
-{
- if (NULL == res_scn_item)
- {
- return;
- }
-
- nsfw_res_scn_cfg *scn_cfg = &res_scn_item->scn_cfg;
- if (NULL == scn_cfg->data)
- {
- return;
- }
-
- u32 start = res_scn_item->last_scn_idx;
- u32 end = start + scn_cfg->num_per_cyc;
- int res_chk_number = 0;
- if (NSFW_RES_SCAN_SPOOL == scn_cfg->type)
- {
- res_chk_number =
- nsfw_mem_sp_iterator (scn_cfg->data, start, end,
- nsfw_res_sp_item_chk, (void *) res_scn_item);
- }
- else
- {
- res_chk_number =
- nsfw_mem_mbuf_iterator (scn_cfg->data, start, end,
- nsfw_res_sp_item_chk, (void *) res_scn_item);
- }
-
- if (0 == res_chk_number)
- {
- res_scn_item->last_scn_idx = 0;
- start = res_scn_item->last_scn_idx;
- end = start + scn_cfg->num_per_cyc;
- if (NSFW_RES_SCAN_SPOOL == scn_cfg->type)
- {
- res_chk_number =
- nsfw_mem_sp_iterator (scn_cfg->data, start, end,
- nsfw_res_sp_item_chk,
- (void *) res_scn_item);
- }
- else
- {
- res_chk_number =
- nsfw_mem_mbuf_iterator (scn_cfg->data, start, end,
- nsfw_res_sp_item_chk,
- (void *) res_scn_item);
- }
- }
-
- if (res_chk_number + start < end)
- {
- res_scn_item->last_scn_idx = 0;
- }
- else
- {
- res_scn_item->last_scn_idx += res_chk_number;
- }
-
- return;
-}
-
-void
-nsfw_res_scan_array (nsfw_res_mgr_item_cfg * res_scn_item)
-{
- if (NULL == res_scn_item)
- {
- return;
- }
-
- nsfw_res_scn_cfg *scn_cfg = &res_scn_item->scn_cfg;
- if (NULL == scn_cfg->data)
- {
- return;
- }
-
- u32 i;
- char *elm =
- (char *) scn_cfg->data + (res_scn_item->last_scn_idx * scn_cfg->elm_size);
- for (i = res_scn_item->last_scn_idx; i < scn_cfg->total_num; i++)
- {
- if (i >= res_scn_item->last_scn_idx + scn_cfg->num_per_cyc)
- {
- break;
- }
-
- if (TRUE == nsfw_res_sp_item_chk (elm, (void *) res_scn_item))
- {
- NSFW_LOGINF ("force free item]data=%p,cfg=%p", elm, res_scn_item);
- }
-
- elm += scn_cfg->elm_size;
- }
-
- if (i >= scn_cfg->total_num)
- {
- res_scn_item->last_scn_idx = 0;
- }
- else
- {
- res_scn_item->last_scn_idx = i;
- }
-
- return;
-}
-
-void
-nsfw_res_scan_proc (nsfw_res_mgr_item_cfg * res_scn_item)
-{
- (void) nsfw_res_flash_data (res_scn_item);
- switch (res_scn_item->scn_cfg.type)
- {
- case NSFW_RES_SCAN_ARRAY:
- nsfw_res_scan_array (res_scn_item);
- break;
- case NSFW_RES_SCAN_SPOOL:
- case NSFW_RES_SCAN_MBUF:
- nsfw_res_scan_mem (res_scn_item);
- break;
- default:
- break;
- }
-}
-
-int
-nsfw_res_scan_all (u32 timer_type, void *data)
-{
- NSFW_LOGDBG ("scan start!");
- struct timespec time_left = { NSFW_RES_SCAN_TVLAUE, 0 };
- g_scan_cfg.scan_timer =
- nsfw_timer_reg_timer (0, NULL, nsfw_res_scan_all, time_left);
-
- if (g_hbt_switch)
- {
- return TRUE;
- }
-
- int i;
- for (i = 0; i < NSFW_MAX_RES_SCAN_COUNT; i++)
- {
- /*last fun */
- if (NULL == g_all_res_can[i].scn_cfg.data)
- {
- break;
- }
-
- nsfw_res_scan_proc (&g_all_res_can[i]);
- }
-
- return TRUE;
-}
-
-static int nsfw_resmgr_module_init (void *param);
-static int
-nsfw_resmgr_module_init (void *param)
-{
- u8 proc_type = (u8) ((long long) param);
- NSFW_LOGINF ("res mgr module init]type=%u", proc_type);
- g_scan_cfg.scan_tvalue = NSFW_RES_SCAN_TVLAUE_DEF;
- switch (proc_type)
- {
- case NSFW_PROC_MAIN:
- {
- struct timespec time_left = { NSFW_RES_SCAN_TVLAUE, 0 };
- g_scan_cfg.scan_timer =
- nsfw_timer_reg_timer (0, NULL, nsfw_res_scan_all, time_left);
- return 0;
- }
- default:
- if (proc_type < NSFW_PROC_MAX)
- {
- break;
- }
- return -1;
- }
-
- return 0;
-}
-
-/* *INDENT-OFF* */
-NSFW_MODULE_NAME(NSFW_RES_MGR_MODULE)
-NSFW_MODULE_PRIORITY(99)
-NSFW_MODULE_INIT(nsfw_resmgr_module_init)
-/* *INDENT-ON* */
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif /* __cplusplus */
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.c
deleted file mode 100644
index c29b108..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.c
+++ /dev/null
@@ -1,987 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdint.h>
-#include "nstack_securec.h"
-#include "nstack_log.h"
-#include "nsfw_ring_fun.h"
-#include "nsfw_shmem_ring.h"
-#include "nsfw_shmem_mng.h"
-#include "common_mem_buf.h"
-#include "common_mem_common.h"
-
-#include "common_func.h"
-
-/*get the base address of msg data */
-#define NSFW_SHMEM_GET_DATA(pmsg, type) (type *)&((pmsg)->aidata[0])
-
-/*if input point is nun, just return null*/
-#define NSFW_POINT_CHK_RET_NULL(p, desc) \
- if (NULL == (p)) \
- { \
- NSCOMM_LOGERR("point check fail] desc_para=%s", desc); \
- return NULL; \
- }
-
-/*if input point is nun, just return err num*/
-#define NSFW_POINT_CHK_RET_ERR(p, desc) \
- if (NULL == (p)) \
- { \
- NSCOMM_LOGDBG("point check fail] desc_para=%s", desc); \
- return NSFW_MEM_ERR; \
- }
-
-/*if input point is nun, goto flag*/
-#define NSFW_POINT_CHK_RET_GOTO(p, gotoflag, desc) \
- if (NULL == (p)) \
- { \
- NSCOMM_LOGERR("point check fail] desc_para=%s", desc); \
- goto gotoflag; \
- }
-
-/*init the msg head*/
-#define NSFW_SHMEM_MSG_HEAD_INIT(pmsg, type, length) { \
- (pmsg)->usmsg_type = (type); \
- (pmsg)->uslength = (length); \
- }
-
-/*rsp msg head check, and if err goto*/
-#define NSFW_SHMEM_MSGHEAD_CHK_GOTO(pmsg, type, length, gotoflag) { \
- if (((type) != pmsg->usmsg_type) && ((length) != pmsg->uslength)) \
- { \
- NSCOMM_LOGERR("check fail] msgtype=%d, type_para=%d, len=%d", (pmsg->usmsg_type), (type), (length)); \
- goto gotoflag; \
- } \
- }
-
-/*rsp check the state*/
-#define NSFW_SHMEM_ACKSTATE_CHK_GOTO(expret, ret, expseg, seg, gotoflag) { \
- if (((ret) != (expret)) || ((expseg) != (seg))) \
- { \
- NSCOMM_LOGERR("ackstate check fail]msgack exp=%d, real=%d,eseg=%d, rseg=%d", (expret), (ret), (expseg), (seg)); \
- goto gotoflag; \
- } \
- }
-
-/*mzone msg init*/
-#define NSFW_SHMEM_MZONE_DATA_INIT(pdata, slength, seg, socketid) { \
- (pdata)->isocket_id = (socketid); \
- (pdata)->length = (slength); \
- (pdata)->usseq = (seg); \
- (pdata)->ireserv = 0; \
- }
-
-/*mbuf msg init*/
-#define NSFW_SHMEM_MBUF_DATA_INIT(pdata, seg, num, cashsize, priv_size, data_room, flag, socketid) { \
- (pdata)->usseq = (seg); \
- (pdata)->usnum = (num); \
- (pdata)->uscash_size = (cashsize); \
- (pdata)->uspriv_size = (priv_size); \
- (pdata)->usdata_room = (data_room); \
- (pdata)->enmptype = (flag); \
- (pdata)->isocket_id = (socketid); \
- (pdata)->ireserv = 0; \
- }
-
-/*mpool msg init*/
-#define NSFW_SHMEM_MPOOL_DATA_INIT(pdata, seg, num, eltsize, flag, socketid) { \
- (pdata)->usseq = (seg); \
- (pdata)->usnum = (num); \
- (pdata)->useltsize = (eltsize); \
- (pdata)->enmptype = (flag); \
- (pdata)->isocket_id = (socketid); \
- (pdata)->ireserv = 0; \
- }
-
-/*mring msg init*/
-#define NSFW_SHMEM_MRING_DATA_INIT(pdata, seg, num, flag, socketid) { \
- (pdata)->usseq = (seg); \
- (pdata)->usnum = (num); \
- (pdata)->enmptype = (flag); \
- (pdata)->isocket_id = (socketid); \
- (pdata)->ireserv = 0; \
- }
-
-#define NSFW_SHMEM_MSG_FREE(pmsg, prsp_msg) {\
- if (pmsg) \
- { \
- nsfw_mgr_msg_free(pmsg); \
- } \
- if (prsp_msg) \
- { \
- nsfw_mgr_msg_free(prsp_msg); \
- } \
-}
-
-/*
- * create a block memory by send a msg
- *
- */
-mzone_handle
-nsfw_memzone_remote_reserv (const i8 * name, size_t mlen, i32 socket_id)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
-
- /*msg head point define */
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- /*msg data point define */
- nsfw_shmem_reserv_req *pdata = NULL;
- nsfw_shmem_msg_head *pack_head = NULL;
-
- /*ack msg define */
- nsfw_shmem_ack *pack_data = NULL;
-
- mzone_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
-
- //pmsg = nsfw_mgr_msg_alloc(MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MASTER);
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_NULL (pmsg, "remote reserv pmsg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, release, "remote reserv rspmsg alloc");
-
- /*msg head init */
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_RESERV_REQ_MSG,
- sizeof (nsfw_shmem_reserv_req));
-
- /*msg data init */
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_reserv_req);
- iretval = STRCPY_S (pdata->aname, sizeof (pdata->aname), name);
- if (EOK != iretval)
- {
- NSCOMM_LOGERR ("reserv mem copy name fail] ret=%d", iretval);
- goto release;
- }
-
- /*fill msg data */
- NSFW_SHMEM_MZONE_DATA_INIT (pdata, mlen, (u16) 0, socket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("reserv mem req rsp fail] ret=%u", ucret);
- goto release;
- }
-
- /*interrupt msg head */
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_RESERV_ACK_MSG,
- sizeof (nsfw_shmem_ack), release);
-
- pack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, pack_data->cstate, 0,
- pack_data->usseq, release);
-
- hhandle = (mzone_handle) ADDR_SHTOL (pack_data->pbase_addr);
- NSCOMM_LOGDBG ("mem reserve] name=%s, handle=%p, seg=%u", name, hhandle,
- pack_data->usseq);
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return hhandle;
-}
-
-/*
- *create some memories by send a msg
- */
-i32
-nsfw_memzone_remote_reserv_v (nsfw_mem_zone * pmeminfo,
- mzone_handle * paddr_array, i32 inum, pid_t pid)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
- nsfw_shmem_msg_head *pdata_head = NULL;
- nsfw_shmem_reserv_req *pdata = NULL;
- nsfw_shmem_reserv_req *ptempdata = NULL;
- nsfw_shmem_msg_head *pack_head = NULL;
-
- nsfw_shmem_ack *pack_data = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
- i32 icount = 0;
- i32 itindex = 0;
- i32 iindex = 0;
- u16 ussegbase = 0;
- u16 ustempv = 0;
- i32 ieltnum = 0;
- i32 ieltnum_max =
- (NSFW_MGR_MSG_BODY_LEN -
- sizeof (nsfw_shmem_msg_head)) / sizeof (nsfw_shmem_reserv_req);
-
- //pmsg = nsfw_mgr_msg_alloc(MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MASTER);
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_GOTO (pmsg, err, "remote reserv_v msg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, err, "remote reserv_v rspmsg alloc");
-
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
-
- ptempdata = pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_reserv_req);
-
- do
- {
- icount++;
- ieltnum++;
-
- if (((icount % ieltnum_max) == 0) || (icount >= inum))
- {
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_RESERV_REQ_MSG,
- ieltnum * sizeof (nsfw_shmem_reserv_req));
-
- itindex = icount - 1;
- int retVal =
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmeminfo[itindex].stname.aname, pid);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- }
- NSFW_SHMEM_MZONE_DATA_INIT (ptempdata, pmeminfo[itindex].length,
- (u16) itindex,
- pmeminfo[itindex].isocket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("reserv v mem req rsp fail] ret=%u", ucret);
- goto err;
- }
-
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_RESERV_ACK_MSG,
- ieltnum * sizeof (nsfw_shmem_ack),
- err);
-
- pack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
-
- for (iindex = 0; iindex < ieltnum; iindex++)
- {
- ustempv = ussegbase + iindex;
-
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC,
- pack_data->cstate, ustempv,
- (u16) pack_data->usseq, err);
-
- paddr_array[ustempv] = ADDR_SHTOL (pack_data->pbase_addr);
- NSCOMM_LOGDBG ("remote reserve]index=%u, seg=%u, handle=%p",
- ustempv, pack_data->usseq, paddr_array[ustempv]);
- pack_data++;
- }
-
- ussegbase = icount;
- ieltnum = 0;
- ptempdata = pdata;
- }
- else
- {
- itindex = icount - 1;
- int retVal =
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmeminfo[itindex].stname.aname, pid);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- }
- NSFW_SHMEM_MZONE_DATA_INIT (ptempdata, pmeminfo[itindex].length,
- (u16) itindex,
- pmeminfo[itindex].isocket_id);
- ptempdata++;
- }
- }
- while (icount < inum);
-
- iretval = NSFW_MEM_OK;
- goto free;
-
-err:
- iretval = NSFW_MEM_ERR;
-free:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return iretval;
-}
-
-/*
- *release a block memory with name by send msg
- */
-i32
-nsfw_remote_free (const i8 * name, nsfw_mem_struct_type entype)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
-
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- nsfw_shmem_free_req *pdata = NULL;
-
- nsfw_shmem_msg_head *pack_head = NULL;
- nsfw_shmem_ack *pack_data = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
-
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_ERR (pmsg, "remote free msg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, terr, "remote free rspmsg alloc");
-
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_RELEASE_REQ_MSG,
- sizeof (nsfw_shmem_free_req));
-
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_free_req);
- if (EOK != STRCPY_S (pdata->aname, sizeof (pdata->aname), name))
- {
- NSCOMM_LOGERR ("STRCPY_S failed]name=%s", name);
- }
- pdata->usseq = 0;
- pdata->ustype = entype;
- pdata->ireserv = 0;
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("free mem req rsp fail] ret=%u", ucret);
- goto release;
- }
-
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_RELEASE_ACK_MSG,
- sizeof (nsfw_shmem_ack), terr);
-
- pack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, pack_data->cstate, 0,
- pack_data->usseq, terr);
-
- iretval = NSFW_MEM_OK;
- goto release;
-terr:
- iretval = NSFW_MEM_ERR;
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return iretval;
-}
-
-/*
- *create a mbuf pool by send a msg
- */
-mpool_handle
-nsfw_remote_shmem_mbf_create (const i8 * name, unsigned n,
- unsigned cache_size, unsigned priv_size,
- unsigned data_room_size, i32 socket_id,
- nsfw_mpool_type entype)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
- nsfw_shmem_msg_head *pdata_head = NULL;
- nsfw_shmem_mbuf_req *pdata = NULL;
- nsfw_shmem_msg_head *tpack_head = NULL;
- nsfw_shmem_ack *tpack_data = NULL;
- mpool_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
-
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_NULL (pmsg, "remote mbf create pmsg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, release, "remote mbf create msg alloc");
-
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_MBUF_REQ_MSG,
- sizeof (nsfw_shmem_mbuf_req));
-
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_mbuf_req);
- iretval = STRCPY_S (pdata->aname, sizeof (pdata->aname), name);
- if (EOK != iretval)
- {
- NSCOMM_LOGERR ("mbf create name cpy fail] ret=%d", iretval);
- goto release;
- }
-
- NSFW_SHMEM_MBUF_DATA_INIT (pdata, 0, n, cache_size, priv_size,
- data_room_size, (u16) entype, socket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("mbf create mem req rsp fail] ret=%u", ucret);
- goto release;
- }
-
- tpack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (tpack_head, NSFW_MBUF_ACK_MSG,
- sizeof (nsfw_shmem_ack), release);
-
- tpack_data = NSFW_SHMEM_GET_DATA (tpack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, tpack_data->cstate, 0,
- tpack_data->usseq, release);
-
- hhandle = ADDR_SHTOL (tpack_data->pbase_addr);
- NSCOMM_LOGDBG ("mbf create] name=%s, handle=%p, seg=%u", name, hhandle,
- tpack_data->usseq);
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return hhandle;
-}
-
-/*
- *create some mbuf pools
- */
-i32
-nsfw_remote_shmem_mbf_createv (nsfw_mem_mbfpool * pmbfname,
- mpool_handle * phandle_array, i32 inum,
- pid_t pid)
-{
- /*msg point define */
- nsfw_mgr_msg *mbpmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- nsfw_shmem_mbuf_req *pdata = NULL;
- nsfw_shmem_mbuf_req *ptempdata = NULL;
-
- nsfw_shmem_msg_head *pack_head = NULL;
-
- nsfw_shmem_ack *pack_data = NULL;
- mpool_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
- i32 icount = 0;
- i32 itindex = 0;
- i32 iindex = 0;
- i32 isegbase = 0;
- i32 ieltnum = 0;
- i32 ieltnum_max =
- (NSFW_MGR_MSG_BODY_LEN -
- sizeof (nsfw_shmem_msg_head)) / sizeof (nsfw_shmem_mbuf_req);
-
- mbpmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_GOTO (mbpmsg, lerr, "remote mbf createv msg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, lerr, "remote mbf createv rspmsg alloc");
-
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, mbpmsg);
-
- ptempdata = pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_mbuf_req);
-
- do
- {
- icount++;
- ieltnum++;
-
- if (((icount % ieltnum_max) == 0) || (icount >= inum))
- {
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_MBUF_REQ_MSG,
- ieltnum * sizeof (nsfw_shmem_mbuf_req));
-
- /*fill msg data */
- itindex = icount - 1;
- if (-1 ==
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmbfname[itindex].stname.aname, pid))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- goto lerr;
- }
- NSFW_SHMEM_MBUF_DATA_INIT (ptempdata, (u16) itindex,
- pmbfname[itindex].usnum,
- pmbfname[itindex].uscash_size,
- pmbfname[itindex].uspriv_size,
- pmbfname[itindex].usdata_room,
- pmbfname[itindex].enmptype,
- pmbfname[itindex].isocket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (mbpmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("mbf createv mem req rsp fail] ret=%d", ucret);
- goto lerr;
- }
-
- /*interrupt msg head */
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_MBUF_ACK_MSG,
- ieltnum * sizeof (nsfw_shmem_ack),
- lerr);
-
- pack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
-
- for (iindex = 0; iindex < ieltnum; iindex++)
- {
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC,
- pack_data->cstate,
- (isegbase + iindex),
- (u16) pack_data->usseq, lerr);
- phandle_array[isegbase + iindex] =
- ADDR_SHTOL (pack_data->pbase_addr);
- NSCOMM_LOGDBG ("mbf createv] seg=%d, handle=%p",
- pack_data->usseq, hhandle);
- pack_data++;
- }
-
- isegbase = icount;
- ieltnum = 0;
- ptempdata = pdata;
- }
- else
- {
- itindex = icount - 1;
- if (-1 ==
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmbfname[itindex].stname.aname, pid))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- goto lerr;
- }
- NSFW_SHMEM_MBUF_DATA_INIT (ptempdata, (u16) itindex,
- pmbfname[itindex].usnum,
- pmbfname[itindex].uscash_size,
- pmbfname[itindex].uspriv_size,
- pmbfname[itindex].usdata_room,
- pmbfname[itindex].enmptype,
- pmbfname[itindex].isocket_id);
- ptempdata++;
- }
- }
- while (icount < inum);
-
- /*release memory */
- iretval = NSFW_MEM_OK;
- goto release;
-
-lerr:
- iretval = NSFW_MEM_ERR;
-release:
- NSFW_SHMEM_MSG_FREE (mbpmsg, prsp_msg);
- return iretval;
-}
-
-/*
- *create a simpile pool
- */
-mring_handle
-nsfw_remote_shmem_mpcreate (const char *name, unsigned int n,
- unsigned int elt_size, i32 socket_id,
- nsfw_mpool_type entype)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
- nsfw_shmem_msg_head *pdata_head = NULL;
- nsfw_shmem_sppool_req *pdata = NULL;
- nsfw_shmem_msg_head *mppack_head = NULL;
- nsfw_shmem_ack *mppack_data = NULL;
- mring_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
-
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_NULL (pmsg, "remote mbf mpcreate pmsg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, release, "remote mpcreate rspmsg alloc");
-
- /*init msg head */
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_SPPOOL_REQ_MSG,
- sizeof (nsfw_shmem_sppool_req));
-
- /*fill msg data */
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_sppool_req);
- iretval = STRCPY_S (pdata->aname, sizeof (pdata->aname), name);
- if (EOK != iretval)
- {
- NSCOMM_LOGERR ("mp create copy name fail] ret=%d", iretval);
- goto release;
- }
-
- /*fill msg data */
- NSFW_SHMEM_MPOOL_DATA_INIT (pdata, 0, n, elt_size, entype, socket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("mp create rsp fail] ret=%d", ucret);
- goto release;
- }
-
- /*get msg head */
- mppack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (mppack_head, NSFW_SPPOOL_ACK_MSG,
- sizeof (nsfw_shmem_ack), release);
-
- mppack_data = NSFW_SHMEM_GET_DATA (mppack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, mppack_data->cstate, 0,
- mppack_data->usseq, release);
-
- hhandle = ADDR_SHTOL (mppack_data->pbase_addr);
- NSCOMM_LOGDBG ("mpcreate] name=%s, handle=%p, seg=%d", name, hhandle,
- mppack_data->usseq);
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return hhandle;
-}
-
-/*
- *create some simpile pools by send a msg
- */
-i32
-nsfw_remote_shmem_mpcreatev (nsfw_mem_sppool * pmpinfo,
- mring_handle * pringhandle_array, i32 inum,
- pid_t pid)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
-
- /*msg head define */
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- /*msg data define */
- nsfw_shmem_sppool_req *pdata = NULL;
- nsfw_shmem_sppool_req *ptempdata = NULL;
-
- /*ack msg define */
- nsfw_shmem_msg_head *pack_head = NULL;
-
- nsfw_shmem_ack *pack_data = NULL;
- mring_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
- i32 icount = 0;
- i32 itindex = 0;
- i32 iindex = 0;
- i32 isegbase = 0;
- i32 ieltnum = 0;
- /*the max members that a msg can take */
- i32 ieltnum_max =
- (NSFW_MGR_MSG_BODY_LEN -
- sizeof (nsfw_shmem_msg_head)) / sizeof (nsfw_shmem_sppool_req);
-
- /*alloc a msg */
- //pmsg = nsfw_mgr_msg_alloc(MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MASTER);
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_GOTO (pmsg, mperr, "remote mpcreatev pmsg alloc");
-
- /*alloc rsp msg */
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, mperr, "remote mpcreatev rspmsg alloc");
-
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
-
- ptempdata = pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_sppool_req);
-
- do
- {
- icount++;
- ieltnum++;
-
- /*if the element num reach the bigest, or already send all, just deal */
- if (((icount % ieltnum_max) == 0) || (icount >= inum))
- {
- /*init msg header */
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_SPPOOL_REQ_MSG,
- ieltnum * sizeof (nsfw_shmem_sppool_req));
-
- /*fill the msg data */
- itindex = icount - 1;
-
- int retVal =
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmpinfo[itindex].stname.aname, pid);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S fail]ret=%d", retVal);
- goto mperr;
- }
- NSFW_SHMEM_MPOOL_DATA_INIT (ptempdata, itindex,
- pmpinfo[itindex].usnum,
- pmpinfo[itindex].useltsize,
- pmpinfo[itindex].enmptype,
- pmpinfo[itindex].isocket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("mpcreatev create fail] ret=%u", ucret);
- goto mperr;
- }
-
- /*interrupt mgs head */
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_SPPOOL_ACK_MSG,
- ieltnum * sizeof (nsfw_shmem_ack),
- mperr);
-
- pack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
-
- for (iindex = 0; iindex < ieltnum; iindex++)
- {
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC,
- pack_data->cstate,
- (isegbase + iindex),
- (u16) pack_data->usseq, mperr);
- pringhandle_array[isegbase + iindex] =
- ADDR_SHTOL (pack_data->pbase_addr);
- NSCOMM_LOGDBG ("mpcreatev] seg=%u, handle=%p", pack_data->usseq,
- hhandle);
- pack_data++;
- }
-
- isegbase = icount;
- ieltnum = 0;
- ptempdata = pdata;
- }
- else
- {
- itindex = icount - 1;
- int retVal =
- SPRINTF_S (ptempdata->aname, sizeof (ptempdata->aname), "%s_%x",
- pmpinfo[itindex].stname.aname, pid);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S fail]ret=%d", retVal);
- goto mperr;
- }
- NSFW_SHMEM_MPOOL_DATA_INIT (ptempdata, itindex,
- pmpinfo[itindex].usnum,
- pmpinfo[itindex].useltsize,
- pmpinfo[itindex].enmptype,
- pmpinfo[itindex].isocket_id);
-
- ptempdata++;
- }
- }
- while (icount < inum);
-
- /*release the memory */
- iretval = NSFW_MEM_OK;
- goto release;
-
-mperr:
- iretval = NSFW_MEM_ERR;
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return iretval;
-}
-
-/*
- *create a ring
- */
-mring_handle
-nsfw_remote_shmem_ringcreate (const char *name, unsigned int n, i32 socket_id,
- nsfw_mpool_type entype)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
-
- /*msg head define */
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- /*msg data define */
- nsfw_shmem_ring_req *pdata = NULL;
- /*ack msg define */
- nsfw_shmem_msg_head *pack_head = NULL;
- nsfw_shmem_ack *ppack_data = NULL;
- mring_handle hhandle = NULL;
- u8 ucret = TRUE;
- i32 iretval = NSFW_MEM_OK;
-
- //pmsg = nsfw_mgr_msg_alloc(MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MASTER);
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_NULL (pmsg, "remote ringcreate pmsg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, release,
- "remote ringcreate rspmsg alloc");
-
- /*fill msg head */
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_RING_REQ_MSG,
- sizeof (nsfw_shmem_ring_req));
-
- /*fill msg data */
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_ring_req);
- iretval = STRCPY_S (pdata->aname, sizeof (pdata->aname), name);
- if (EOK != iretval)
- {
- NSCOMM_LOGERR ("ring create cpy name fail] ret=%d", iretval);
- goto release;
- }
-
- /*fill msg data */
- NSFW_SHMEM_MRING_DATA_INIT (pdata, 0, n, entype, socket_id);
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("ring create rsp fail] ret=%d", ucret);
- goto release;
- }
-
- /*interrupt mgs head */
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_RING_ACK_MSG,
- sizeof (nsfw_shmem_ack), release);
-
- ppack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, ppack_data->cstate, 0,
- ppack_data->usseq, release);
-
- hhandle = ADDR_SHTOL (ppack_data->pbase_addr);
- NSCOMM_LOGDBG ("ring create] name=%s, handle=%p, seg=%u", name, hhandle,
- ppack_data->usseq);
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return hhandle;
-}
-
-/*
- *create a mem pool that the members are rings by send a msg
- *ieltnum:the num of ring member
- *iringnum:the num of ring in simple mem pool
- *entype:the default the of ring
- */
-i32
-nsfw_remote_shmem_ringcreatev (const char *name, i32 ieltnum,
- mring_handle * pringhandle_array, i32 iringnum,
- i32 socket_id, nsfw_mpool_type entype)
-{
- unsigned int useltsize = 0;
- mring_handle nhandle = NULL;
- i32 icount = 0;
- i32 n = 0;
- uint64_t baseaddr = 0;
- uint64_t endaddr = 0;
- /*the num of ring member must be power of 2 */
- unsigned int usnum = common_mem_align32pow2 (ieltnum + 1);
-
- useltsize =
- sizeof (struct nsfw_mem_ring) + usnum * sizeof (union RingData_U);
- nhandle =
- nsfw_remote_shmem_mpcreate (name, iringnum, useltsize, socket_id,
- NSFW_MRING_SPSC);
- NSFW_POINT_CHK_RET_ERR (nhandle, "remote ringcreatev msg alloc");
-
- n =
- nsfw_shmem_ring_sc_dequeuev (nhandle, (void **) pringhandle_array,
- iringnum);
-
- if (n != iringnum)
- {
- NSCOMM_LOGERR ("ring dequeue fail] ringnum=%d, retnum=%d", iringnum, n);
- return NSFW_MEM_ERR;
- }
-
- nsfw_shmem_ring_baseaddr_query (&baseaddr, &endaddr);
-
- for (icount = 0; icount < iringnum; icount++)
- {
- nsfw_mem_ring_init (pringhandle_array[icount], usnum, (void *) baseaddr,
- NSFW_SHMEM, entype);
- }
-
- return NSFW_MEM_OK;
-}
-
-/*
- *look up a msg by send a msg
- */
-void *
-nsfw_remote_shmem_lookup (const i8 * name, nsfw_mem_struct_type entype)
-{
- /*msg point define */
- nsfw_mgr_msg *pmsg = NULL;
- nsfw_mgr_msg *prsp_msg = NULL;
- void *addr = NULL;
- /*msg head data define */
- nsfw_shmem_msg_head *pdata_head = NULL;
-
- /*msg data define */
- nsfw_shmem_lookup_req *pdata = NULL;
-
- /*ack msg define */
- nsfw_shmem_msg_head *pack_head = NULL;
- nsfw_shmem_ack *lpack_data = NULL;
- u8 ucret = TRUE;
-
- pmsg = nsfw_mgr_msg_alloc (MGR_MSG_MEM_ALLOC_REQ, NSFW_PROC_MAIN);
- NSFW_POINT_CHK_RET_NULL (pmsg, "remote lookup pmsg alloc");
-
- prsp_msg = nsfw_mgr_null_rspmsg_alloc ();
- NSFW_POINT_CHK_RET_GOTO (prsp_msg, perr, "remote lookup rspmsg alloc");
-
- /*msg head init */
- pdata_head = GET_USER_MSG (nsfw_shmem_msg_head, pmsg);
- NSFW_SHMEM_MSG_HEAD_INIT (pdata_head, NSFW_MEM_LOOKUP_REQ_MSG,
- sizeof (nsfw_shmem_lookup_req));
-
- pdata = NSFW_SHMEM_GET_DATA (pdata_head, nsfw_shmem_lookup_req);
- if (EOK != STRCPY_S (pdata->aname, sizeof (pdata->aname), name))
- {
- NSCOMM_LOGERR ("STRCPY_S failed]name=%s", name);
- }
- pdata->usseq = 0;
- pdata->ustype = entype;
- pdata->ireserv = 0;
-
- ucret = nsfw_mgr_send_req_wait_rsp (pmsg, prsp_msg);
-
- if (FALSE == ucret)
- {
- NSCOMM_LOGERR ("mem lookup fail] ret=%u", ucret);
- goto release;
- }
-
- /*interrupt mgs head */
- pack_head = GET_USER_MSG (nsfw_shmem_msg_head, prsp_msg);
- NSFW_SHMEM_MSGHEAD_CHK_GOTO (pack_head, NSFW_MEM_LOOKUP_ACK_MSG,
- sizeof (nsfw_shmem_ack), perr);
-
- lpack_data = NSFW_SHMEM_GET_DATA (pack_head, nsfw_shmem_ack);
- NSFW_SHMEM_ACKSTATE_CHK_GOTO (NSFW_MEM_ALLOC_SUCC, lpack_data->cstate, 0,
- lpack_data->usseq, perr);
-
- addr = ADDR_SHTOL (lpack_data->pbase_addr);
- NSCOMM_LOGDBG ("shmem lookup] name=%s, handle=%p, seg=%u", name, addr,
- lpack_data->usseq);
- goto release;
-perr:
- addr = NULL;
-
-release:
- NSFW_SHMEM_MSG_FREE (pmsg, prsp_msg);
- return addr;
-}
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.h b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.h
deleted file mode 100644
index 60c4115..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_rshmem_mng.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_RSHMEM_MNG_H
-#define _NSFW_RSHMEM_MNG_H
-
-mzone_handle nsfw_memzone_remote_reserv (const i8 * name, size_t mlen,
- i32 socket_id);
-i32 nsfw_memzone_remote_reserv_v (nsfw_mem_zone * pmeminfo,
- mzone_handle * paddr_array, i32 inum,
- pid_t pid);
-i32 nsfw_remote_free (const i8 * name, nsfw_mem_struct_type entype);
-mpool_handle nsfw_remote_shmem_mbf_create (const i8 * name, unsigned int n,
- unsigned cache_size,
- unsigned priv_size,
- unsigned data_room_size,
- i32 socket_id,
- nsfw_mpool_type entype);
-i32 nsfw_remote_shmem_mbf_createv (nsfw_mem_mbfpool * pmbfname,
- mpool_handle * phandle_array, i32 inum,
- pid_t pid);
-mring_handle nsfw_remote_shmem_mpcreate (const char *name, unsigned int n,
- unsigned int elt_size, i32 socket_id,
- nsfw_mpool_type entype);
-i32 nsfw_remote_shmem_mpcreatev (nsfw_mem_sppool * pmpinfo,
- mring_handle * pringhandle_array, i32 inum,
- pid_t pid);
-mring_handle nsfw_remote_shmem_ringcreate (const char *name, unsigned int n,
- i32 socket_id,
- nsfw_mpool_type entype);
-i32 nsfw_remote_shmem_ringcreatev (const char *name, i32 ieltnum,
- mring_handle * pringhandle_array,
- i32 iringnum, i32 socket_id,
- nsfw_mpool_type entype);
-
-void *nsfw_remote_shmem_lookup (const i8 * name, nsfw_mem_struct_type entype);
-
-#endif
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.c
deleted file mode 100644
index 2e9c969..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "nsfw_mem_desc.h"
-#include "nsfw_shmem_mng.h"
-#include "nsfw_shmem_mdesc.h"
-
-/*the inferaces accessing memory*/
-nsfw_mem_ops g_shmem_ops = {
- nsfw_shmem_init,
- nsfw_shmem_destroy,
- nsfw_shmem_create,
- nsfw_shmem_createv,
- nsfw_shmem_lookup,
- nsfw_shmem_release,
- nsfw_shmem_mbfmpcreate,
- nsfw_shmem_mbfmpcreatev,
- nsfw_shmem_mbfalloc,
- nsfw_shmem_mbffree,
- nsfw_shmem_mbfmplookup,
- nsfw_shmem_mbfmprelease,
- nsfw_shmem_spcreate,
- nsfw_shmem_spcreatev,
- nswf_shmem_sp_ringcreate,
- nsfw_shmem_sprelease,
- nsfw_shmem_sp_lookup,
- nsfw_shmem_ringcreate,
- nsfw_shmem_ring_lookup,
- nsfw_shmem_ringrelease,
- nsfw_shmem_static,
- nsfw_shmem_mbuf_recycle,
- nsfw_shmem_sp_iterator,
- nsfw_shmem_mbuf_iterator
-};
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.h b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.h
deleted file mode 100644
index afd9e29..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mdesc.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_SHMEM_MDESC_H_
-#define _NSFW_SHMEM_MDESC_H_
-
-extern nsfw_mem_ops g_shmem_ops;
-
-#endif
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c
deleted file mode 100644
index ba38c32..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.c
+++ /dev/null
@@ -1,821 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "nstack_securec.h"
-#include "nstack_log.h"
-#include "nsfw_mem_desc.h"
-#include "nsfw_ring_fun.h"
-#include "nsfw_shmem_ring.h"
-#include "nsfw_shmem_mng.h"
-#include "common_mem_mempool.h"
-#include "common_mem_memzone.h"
-#include "common_mem_buf.h"
-#include "common_mem_mbuf.h"
-#include "nsfw_rshmem_mng.h"
-#include "common_mem_api.h"
-#include "common_sys_config.h"
-#include "nsfw_maintain_api.h"
-#include "common_pal_bitwide_adjust.h"
-
-#include "common_mem_pal.h"
-
-#include "common_func.h"
-
-#define NSFW_SHMEM_PID (get_sys_pid())
-#define NSFW_SHMEM_FLAG (g_shmem_localdata->enflag)
-
-/* app_mode 1: simple stack with APP*/
-extern u8 app_mode;
-u8 app_mode = 0;
-
-nsfw_mem_localdata *g_shmem_localdata = NULL;
-
-/*check g_mem_localdata*/
-#define NSFW_INIT_CHK_RET() \
- if (!g_shmem_localdata) \
- { \
- return NSFW_MEM_ERR; \
- }
-
-#define NSFW_INIT_CHK_RET_NULL() \
- if (!g_shmem_localdata) \
- { \
- return NULL; \
- }
-
-/*
- *share memory mng module init
- *
- */
-i32
-nsfw_shmem_init (nsfw_mem_para * para)
-{
- common_mem_pal_module_info rteinfo = { 0 };
- i32 iret = NSFW_MEM_ERR;
- int flag = 0;
- if (!para)
- {
- return NSFW_MEM_ERR;
- }
-
- NSCOMM_LOGINF ("nsfw shmem init begin");
-
- if (NSFW_PROC_MAIN == para->enflag)
- {
- iret = common_pal_module_init (NULL, app_mode);
- }
- else
- {
- LCORE_MASK_SET (rteinfo.ilcoremask, 1);
- rteinfo.ucproctype = DMM_PROC_T_SECONDARY;
- iret = common_pal_module_init (&rteinfo, app_mode);
- }
-
- if (NSFW_MEM_OK != iret)
- {
- NSCOMM_LOGERR ("rte init fail] ret=0x%x", iret);
- return NSFW_MEM_ERR;
- }
-
- flag = dmm_pal_addr_align ();
- if ((0 == flag) && (NSFW_PROC_MAIN == para->enflag))
- {
- dmm_addr_print ();
- NSCOMM_LOGERR
- ("rte init addr is not the same with primary] nstackmain flag=%d",
- flag);
- return NSFW_MEM_ERR;
- }
-
- g_shmem_localdata =
- (nsfw_mem_localdata *) malloc (sizeof (nsfw_mem_localdata));
-
- if (NULL == g_shmem_localdata)
- {
- NSCOMM_LOGERR ("g_shmem_localdata malloc fail");
- return NSFW_MEM_ERR;
- }
-
- iret =
- MEMSET_S (g_shmem_localdata, sizeof (nsfw_mem_localdata), 0,
- sizeof (nsfw_mem_localdata));
- if (EOK != iret)
- {
- NSCOMM_LOGERR ("memset fail] g_shmem_localdata=%p ", g_shmem_localdata);
- free (g_shmem_localdata);
- g_shmem_localdata = NULL;
- return NSFW_MEM_ERR;
- }
-
- g_shmem_localdata->enflag = para->enflag;
-
- NSCOMM_LOGINF ("nsfw shmem init end] enflag=%d", para->enflag);
- return NSFW_MEM_OK;
-
-}
-
-/*
- *module destroy
- */
-void
-nsfw_shmem_destroy (void)
-{
- if (g_shmem_localdata)
- {
- free (g_shmem_localdata);
- g_shmem_localdata = NULL;
- }
-
- return;
-}
-
-/*
- * create a shared memory
- * nsfw_mem_zone::stname memory name
- * nsfw_mem_zone::isize
- */
-mzone_handle
-nsfw_shmem_create (nsfw_mem_zone * pinfo)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET_NULL ()if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return common_memzone_data_reserve_name (pinfo->stname.aname,
- pinfo->length,
- pinfo->isocket_id);
- }
- else
- {
- /*app must less than NSFW_MEM_APPNAME_LENGTH */
- NSFW_NAME_LENCHECK_RET_NULL (pinfo->stname.aname, "shmem create")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pinfo->stname.aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- return NULL;
- }
- }
-
- return nsfw_memzone_remote_reserv ((char *) &aname[0], pinfo->length,
- SOCKET_ID_ANY);
-}
-
-/*
- *create some memory
- *inum must be equal iarray_num
- */
-i32
-nsfw_shmem_createv (nsfw_mem_zone * pmeminfo, i32 inum,
- mzone_handle * paddr_array, i32 iarray_num)
-{
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_memzone_remote_reserv_v (pmeminfo, paddr_array, iarray_num,
- 0);
- }
- else
- {
- return nsfw_memzone_remote_reserv_v (pmeminfo, paddr_array, iarray_num,
- NSFW_SHMEM_PID);
- }
- return NSFW_MEM_ERR;
-}
-
-mzone_handle
-nsfw_shmem_lookup (nsfw_mem_name * pname)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return common_memzone_data_lookup_name (pname->aname);
- }
-
- if ((NSFW_PROC_NULL == pname->enowner)
- || (NSFW_PROC_MAIN == pname->enowner))
- {
- int retVal =
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s", pname->aname);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed");
- return NULL;
- }
- }
- else
- {
- /*app must less than NSFW_MEM_APPNAME_LENGTH */
- NSFW_NAME_LENCHECK_RET_NULL (pname->aname, "shmem lookup")
- int retVal =
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x", pname->aname,
- NSFW_SHMEM_PID);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed");
- return NULL;
- }
- }
-
- return nsfw_remote_shmem_lookup (aname, NSFW_MEM_MZONE);
-}
-
-i32
-nsfw_shmem_release (nsfw_mem_name * pname)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
- const struct common_mem_memzone *pmzone = NULL;
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- pmzone = common_mem_memzone_lookup (pname->aname);
-
- if (pmzone)
- {
- common_mem_memzone_free (pmzone);
- }
- return NSFW_MEM_OK;
- }
- else
- {
- NSFW_NAME_LENCHECK_RET (pname->aname, "shmem free")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pname->aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed");
- return NSFW_MEM_ERR;
- }
- }
-
- return nsfw_remote_free (aname, NSFW_MEM_MZONE);
-}
-
-mpool_handle
-nsfw_shmem_mbfmpcreate (nsfw_mem_mbfpool * pbufinfo)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return common_mem_pktmbuf_pool_create (pbufinfo->stname.aname,
- pbufinfo->usnum,
- pbufinfo->uscash_size,
- pbufinfo->uspriv_size,
- pbufinfo->usdata_room,
- pbufinfo->isocket_id);
- }
- else
- {
- /*app must less than NSFW_MEM_APPNAME_LENGTH */
- NSFW_NAME_LENCHECK_RET_NULL (pbufinfo->stname.aname, "mbufpool create")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pbufinfo->stname.aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_mbf_create (aname, pbufinfo->usnum,
- pbufinfo->uscash_size,
- pbufinfo->uspriv_size,
- pbufinfo->usdata_room, SOCKET_ID_ANY,
- pbufinfo->enmptype);
-}
-
-/*
- *create some mbuf pools
- */
-i32
-nsfw_shmem_mbfmpcreatev (nsfw_mem_mbfpool * pmbfname, i32 inum,
- mpool_handle * phandle_array, i32 iarray_num)
-{
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_remote_shmem_mbf_createv (pmbfname, phandle_array,
- iarray_num, 0);
- }
- else
- {
- return nsfw_remote_shmem_mbf_createv (pmbfname, phandle_array,
- iarray_num, NSFW_SHMEM_PID);
- }
-
- return NSFW_MEM_ERR;
-}
-
-mbuf_handle
-nsfw_shmem_mbfalloc (mpool_handle mhandle)
-{
- return (mbuf_handle) common_mem_pktmbuf_alloc ((struct common_mem_mempool *)
- mhandle);
-}
-
-i32
-nsfw_shmem_mbffree (mbuf_handle mhandle)
-{
- common_mem_pktmbuf_free ((struct common_mem_mbuf *) mhandle);
- return NSFW_MEM_OK;
-}
-
-i32
-nsfw_shmem_mbfmprelease (nsfw_mem_name * pname)
-{
- return NSFW_MEM_OK;
-}
-
-mpool_handle
-nsfw_shmem_mbfmplookup (nsfw_mem_name * pmbfname)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return common_mem_mempool_lookup (pmbfname->aname);
- }
-
- if ((NSFW_PROC_NULL == pmbfname->enowner)
- || (NSFW_PROC_MAIN == pmbfname->enowner))
- {
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s",
- pmbfname->aname))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
- else
- {
- /*app must less than NSFW_MEM_APPNAME_LENGTH */
- NSFW_NAME_LENCHECK_RET_NULL (pmbfname->aname, "shmem lookup")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pmbfname->aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_lookup (aname, NSFW_MEM_MBUF);
-}
-
-mring_handle
-nsfw_shmem_spcreate (nsfw_mem_sppool * pmpinfo)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_shmem_pool_create (pmpinfo->stname.aname, pmpinfo->usnum,
- pmpinfo->useltsize, pmpinfo->isocket_id,
- pmpinfo->enmptype);
- }
- else
- {
- NSFW_NAME_LENCHECK_RET_NULL (pmpinfo->stname.aname, "mpool create")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pmpinfo->stname.aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_mpcreate (aname, pmpinfo->usnum,
- pmpinfo->useltsize, SOCKET_ID_ANY,
- pmpinfo->enmptype);
-}
-
-i32
-nsfw_shmem_spcreatev (nsfw_mem_sppool * pmpinfo, i32 inum,
- mring_handle * pringhandle_array, i32 iarray_num)
-{
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_remote_shmem_mpcreatev (pmpinfo, pringhandle_array, inum,
- 0);
- }
- else
- {
- return nsfw_remote_shmem_mpcreatev (pmpinfo, pringhandle_array, inum,
- NSFW_SHMEM_PID);
- }
- return NSFW_MEM_ERR;
-}
-
-i32
-nsfw_lshmem_ringcreatev (const char *name, i32 ieltnum,
- mring_handle * pringhandle_array, i32 iringnum,
- i32 socket_id, nsfw_mpool_type entype)
-{
- i32 useltsize = 0;
- mring_handle nhandle = NULL;
- i32 icount = 0;
- i32 n = 0;
- uint64_t baseaddr = 0;
- uint64_t endaddr = 0;
- i32 usnum = common_mem_align32pow2 (ieltnum + 1);
-
- useltsize =
- sizeof (struct nsfw_mem_ring) + usnum * sizeof (union RingData_U);
- nhandle =
- nsfw_shmem_pool_create (name, iringnum, useltsize, socket_id,
- NSFW_MRING_SPSC);
- if (NULL == (nhandle))
- {
- return NSFW_MEM_ERR;
- }
-
- n =
- nsfw_shmem_ring_sc_dequeuev (nhandle, (void **) pringhandle_array,
- iringnum);
-
- if (n != iringnum)
- {
- NSCOMM_LOGERR
- ("ring dequeuev failed] ring=%p, dequeue num=%d, expect num=%d",
- nhandle, n, iringnum);
- return NSFW_MEM_ERR;
- }
-
- nsfw_shmem_ring_baseaddr_query (&baseaddr, &endaddr);
-
- for (icount = 0; icount < iringnum; icount++)
- {
- nsfw_mem_ring_init (pringhandle_array[icount], usnum, (void *) baseaddr,
- NSFW_SHMEM, entype);
- }
-
- return NSFW_MEM_OK;
-}
-
-i32
-nswf_shmem_sp_ringcreate (nsfw_mem_mring * prpoolinfo,
- mring_handle * pringhandle_array, i32 iringnum)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_lshmem_ringcreatev (prpoolinfo->stname.aname,
- prpoolinfo->usnum, pringhandle_array,
- iringnum, SOCKET_ID_ANY,
- prpoolinfo->enmptype);
- }
- else
- {
- NSFW_NAME_LENCHECK_RET (prpoolinfo->stname.aname, "ring pool")
- int retVal = SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- prpoolinfo->stname.aname, NSFW_SHMEM_PID);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_ringcreatev (aname, prpoolinfo->usnum,
- pringhandle_array, iringnum,
- SOCKET_ID_ANY, prpoolinfo->enmptype);
-}
-
-i32
-nsfw_shmem_sprelease (nsfw_mem_name * pname)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
- void *mz_mem = NULL;
- struct nsfw_mem_ring *ring_ptr = NULL;
- NSFW_INIT_CHK_RET ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- mz_mem = common_memzone_data_lookup_name (pname->aname);
-
- if (mz_mem)
- {
- ring_ptr =
- (struct nsfw_mem_ring *) ((char *) mz_mem +
- sizeof (struct nsfw_shmem_ring_head));
- nsfw_shmem_pool_free (ring_ptr);
- }
- return NSFW_MEM_OK;
- }
- else
- {
- NSFW_NAME_LENCHECK_RET (pname->aname, "shmem free")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pname->aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_free (aname, NSFW_MEM_SPOOL);
-}
-
-mring_handle
-nsfw_shmem_sp_lookup (nsfw_mem_name * pname)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
- void *mz_mem = NULL;
- struct nsfw_mem_ring *ring_ptr = NULL;
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- mz_mem = common_memzone_data_lookup_name (pname->aname);
-
- if (mz_mem)
- {
- ring_ptr =
- (struct nsfw_mem_ring *) ((char *) mz_mem +
- sizeof (struct nsfw_shmem_ring_head));
- return ring_ptr;
- }
- return mz_mem;
- }
-
- if ((NSFW_PROC_NULL == pname->enowner)
- || (NSFW_PROC_MAIN == pname->enowner))
- {
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s", pname->aname))
- {
- NSCOMM_LOGERR ("SPRINTF_S fails]");
- }
- }
- else
- {
- /*app's name can not over NSFW_MEM_APPNAME_LENGTH */
- NSFW_NAME_LENCHECK_RET_NULL (pname->aname, "shmem lookup")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pname->aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_lookup (aname, NSFW_MEM_SPOOL);
-}
-
-mring_handle
-nsfw_shmem_ringcreate (nsfw_mem_mring * pringinfo)
-{
- i8 aname[COMMON_MEM_MEMPOOL_NAMESIZE] = { 0 };
-
- NSFW_INIT_CHK_RET_NULL ();
-
- if (NSFW_PROC_MAIN == NSFW_SHMEM_FLAG)
- {
- return nsfw_shmem_ring_create (pringinfo->stname.aname,
- pringinfo->usnum, pringinfo->isocket_id,
- pringinfo->enmptype);
- }
- else
- {
- NSFW_NAME_LENCHECK_RET_NULL (pringinfo->stname.aname, "ring create")
- if (-1 ==
- SPRINTF_S (aname, COMMON_MEM_MEMPOOL_NAMESIZE, "%s_%x",
- pringinfo->stname.aname, NSFW_SHMEM_PID))
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]");
- }
- }
-
- return nsfw_remote_shmem_ringcreate (aname, pringinfo->usnum, SOCKET_ID_ANY,
- pringinfo->enmptype);
-}
-
-mring_handle
-nsfw_shmem_ring_lookup (nsfw_mem_name * pname)
-{
- return nsfw_shmem_lookup (pname);
-}
-
-i32
-nsfw_shmem_ringrelease (nsfw_mem_name * pname)
-{
- return nsfw_shmem_release (pname);
-}
-
-size_t
-nsfw_shmem_mbufpool_statics (mpool_handle mbufpool)
-{
- struct common_mem_mempool *mp = (struct common_mem_mempool *) mbufpool;
- return (size_t) mp->size * (mp->header_size + mp->elt_size +
- mp->trailer_size) +
- (size_t) mp->private_data_size +
- (size_t)
- common_mem_ring_get_memsize (common_mem_align32pow2 (mp->size + 1));
-}
-
-size_t
-nsfw_shmem_sppool_statics (mring_handle sppool)
-{
- struct nsfw_shmem_ring_head *temp = NULL;
- size_t lent = 0;
- temp =
- (struct nsfw_shmem_ring_head *) ((char *) sppool -
- sizeof (struct nsfw_shmem_ring_head));
-
- while (temp)
- {
- lent += temp->mem_zone->len;
- temp = temp->next;
- }
-
- return lent;
-}
-
-size_t
-nsfw_shmem_ring_statics (mring_handle handle)
-{
- struct nsfw_mem_ring *ring = (struct nsfw_mem_ring *) handle;
- return ring->size * sizeof (union RingData_U) +
- sizeof (struct nsfw_mem_ring);
-}
-
-ssize_t
-nsfw_shmem_static (void *handle, nsfw_mem_struct_type type)
-{
- switch (type)
- {
- case NSFW_MEM_MBUF:
- return nsfw_shmem_mbufpool_statics (handle);
- case NSFW_MEM_SPOOL:
- return nsfw_shmem_sppool_statics (handle);
- case NSFW_MEM_RING:
- return nsfw_shmem_ring_statics (handle);
- default:
- break;
- }
- return -1;
-}
-
-i32
-nsfw_shmem_mbuf_recycle (mpool_handle handle)
-{
- return NSFW_MEM_OK;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_shmem_sp_iterator
-* Description : sp pool iterator
-* Input : mpool_handle handle
-* u32 start
-* u32 end
-* nsfw_mem_item_fun fun
-* void *argv
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*****************************************************************************/
-i32
-nsfw_shmem_sp_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv)
-{
- struct nsfw_mem_ring *perfring_ptr = (struct nsfw_mem_ring *) handle;
- if (NULL == perfring_ptr || NULL == fun)
- {
- return 0;
- }
-
- if (0 == perfring_ptr->eltsize)
- {
- return 0;
- }
-
- int num = perfring_ptr->size;
- if (start >= (u32) num || end <= start)
- {
- return 0;
- }
-
- struct nsfw_shmem_ring_head *ring_head =
- (struct nsfw_shmem_ring_head *) ((char *) handle -
- sizeof (struct nsfw_shmem_ring_head));
- void *mz =
- (void *) ((char *) perfring_ptr + sizeof (struct nsfw_mem_ring) +
- num * sizeof (union RingData_U));
-
- if (ring_head->mem_zone->len <
- sizeof (struct nsfw_shmem_ring_head) + sizeof (struct nsfw_mem_ring) +
- num * sizeof (union RingData_U))
- {
- return 0;
- }
-
- u32 mz_len =
- ring_head->mem_zone->len - sizeof (struct nsfw_shmem_ring_head) -
- sizeof (struct nsfw_mem_ring) - num * sizeof (union RingData_U);
-
- u32 start_idx = 0;
- u32 elm_num = 0;
- elm_num = mz_len / perfring_ptr->eltsize;
- while (start > start_idx + elm_num)
- {
- if (NULL == ring_head->next || NULL == ring_head->next->mem_zone
- || 0 == elm_num)
- {
- return 0;
- }
-
- ring_head =
- (struct nsfw_shmem_ring_head *) ring_head->next->mem_zone->addr_64;
- mz_len =
- ring_head->mem_zone->len - sizeof (struct nsfw_shmem_ring_head);
-
- elm_num = mz_len / perfring_ptr->eltsize;
- mz =
- (void *) ((char *) ring_head + sizeof (struct nsfw_shmem_ring_head));
- start_idx += elm_num;
- }
-
- u32 cur_idx = start - start_idx;
- char *cur_elm = NULL;
- int proc_count = 0;
- while (cur_idx + start_idx < end && cur_idx + start_idx < (u32) num)
- {
- if (cur_idx >= elm_num)
- {
- if (NULL == ring_head->next || NULL == ring_head->next->mem_zone
- || 0 == elm_num)
- {
- break;
- }
-
- ring_head =
- (struct nsfw_shmem_ring_head *) ring_head->next->
- mem_zone->addr_64;
- mz_len =
- ring_head->mem_zone->len - sizeof (struct nsfw_shmem_ring_head);
-
- elm_num = mz_len / perfring_ptr->eltsize;
- mz =
- (void *) ((char *) ring_head +
- sizeof (struct nsfw_shmem_ring_head));
- start_idx += elm_num;
-
- cur_idx = 0;
- cur_elm = NULL;
- continue;
- }
-
- if (NULL == cur_elm)
- {
- cur_elm = ((char *) mz + cur_idx * perfring_ptr->eltsize);
- }
- else
- {
- cur_elm += perfring_ptr->eltsize;
- }
-
- cur_idx++;
- proc_count++;
- (void) fun (cur_elm, argv);
- }
-
- return proc_count;
-}
-
-i32
-nsfw_shmem_mbuf_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv)
-{
- return dmm_pktmbuf_pool_iterator ((struct common_mem_mempool *) handle,
- start, end, (dmm_mbuf_item_fun) fun,
- argv);
-}
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.h b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.h
deleted file mode 100644
index d489525..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_mng.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_SHMEM_MNG_H
-#define _NSFW_SHMEM_MNG_H
-
-/*
- * mem mgr module init
- * para:point to nstack_fwmem_para
- */
-i32 nsfw_shmem_init (nsfw_mem_para * para);
-
-/*
- * mem mgr module destory
- *
- */
-void nsfw_shmem_destroy (void);
-
-/*
- * create a block memory with name
- * fw_mem_zone::stname name of memory
- * fw_mem_zone::isize memory size
- */
-mzone_handle nsfw_shmem_create (nsfw_mem_zone * pinfo);
-
-/*
- *create some blocks memory
- */
-i32 nsfw_shmem_createv (nsfw_mem_zone * pmeminfo, i32 inum,
- mzone_handle * paddr_array, i32 iarray_num);
-
-/*
- *lookup a memory
- */
-mzone_handle nsfw_shmem_lookup (nsfw_mem_name * pname);
-
-/*release the memory*/
-i32 nsfw_shmem_release (nsfw_mem_name * pname);
-
-/*
- *create mbuf pool
- */
-mpool_handle nsfw_shmem_mbfmpcreate (nsfw_mem_mbfpool * pbufinfo);
-
-/*
- *create some mbuf pool
- */
-i32 nsfw_shmem_mbfmpcreatev (nsfw_mem_mbfpool * pmbfname, i32 inum,
- mpool_handle * phandle_array, i32 iarray_num);
-
-/*
- *alloc a mbuf from mbuf pool
- */
-mbuf_handle nsfw_shmem_mbfalloc (mpool_handle mhandle);
-
-/*
- *release a mbuf pool
- */
-i32 nsfw_shmem_mbffree (mbuf_handle mhandle);
-
-/*
- *put mbuf back to mbuf pool
- */
-i32 nsfw_shmem_mbfmprelease (nsfw_mem_name * pname);
-
-/*look up mbuf mpool*/
-mpool_handle nsfw_shmem_mbfmplookup (nsfw_mem_name * pmbfname);
-
-/*
- *create simple pool
- */
-mring_handle nsfw_shmem_spcreate (nsfw_mem_sppool * pmpinfo);
-
-/*
- *create some simple pools
- */
-i32 nsfw_shmem_spcreatev (nsfw_mem_sppool * pmpinfo, i32 inum,
- mring_handle * pringhandle_array, i32 iarray_num);
-
-/*
- *create a simple pool that members are rings
- */
-i32 nswf_shmem_sp_ringcreate (nsfw_mem_mring * prpoolinfo,
- mring_handle * pringhandle_array, i32 iringnum);
-
-/*
- *release a simple pool
- */
-i32 nsfw_shmem_sprelease (nsfw_mem_name * pname);
-
-/*
- *look up a simple pool
- */
-mring_handle nsfw_shmem_sp_lookup (nsfw_mem_name * pname);
-
-/*
- *create a ring with name
- */
-mring_handle nsfw_shmem_ringcreate (nsfw_mem_mring * pringinfo);
-
-/*
- *look up a ring with name
- */
-mring_handle nsfw_shmem_ring_lookup (nsfw_mem_name * pname);
-
-/*
- *release ring
- */
-i32 nsfw_shmem_ringrelease (nsfw_mem_name * pname);
-
-ssize_t nsfw_shmem_static (void *handle, nsfw_mem_struct_type type);
-
-i32 nsfw_shmem_mbuf_recycle (mpool_handle handle);
-
-i32 nsfw_shmem_sp_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
-i32 nsfw_shmem_mbuf_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
-
-#endif
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.c b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.c
deleted file mode 100644
index c42c840..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.c
+++ /dev/null
@@ -1,839 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <string.h>
-#include <common_sys_config.h>
-
-#include "common_mem_pal.h"
-#include "common_mem_pal_memconfig.h"
-#include "nstack_securec.h"
-#include "nsfw_shmem_ring.h"
-#include "nsfw_ring_fun.h"
-#include "common_mem_buf.h"
-#include "common_func.h"
-
-void
-nsfw_shmem_ring_baseaddr_query (uint64_t * rte_lowest_addr,
- uint64_t * rte_highest_addr)
-{
- struct common_mem_mem_config *pMemCfg =
- common_mem_pal_get_configuration ()->mem_config;
- struct common_mem_memseg *PMemSegArry = pMemCfg->memseg;
-
- *rte_lowest_addr = PMemSegArry[0].addr_64;
- *rte_highest_addr = PMemSegArry[0].addr_64 + PMemSegArry[0].len;
-
- int s = 1;
-
- while (s < COMMON_MEM_MAX_MEMSEG && PMemSegArry[s].len > 0)
- {
- if (*rte_lowest_addr > PMemSegArry[s].addr_64)
- {
- *rte_lowest_addr = PMemSegArry[s].addr_64;
- }
-
- if (*rte_highest_addr < PMemSegArry[s].addr_64 + PMemSegArry[s].len)
- {
- *rte_highest_addr = PMemSegArry[s].addr_64 + PMemSegArry[s].len;
- }
-
- s++;
- }
-
-}
-
-static unsigned
-nsfw_shmem_pool_node_alloc (struct nsfw_mem_ring *perfring_ptr,
- unsigned alloc_index, unsigned max_index,
- void *mz, size_t mz_len, unsigned elt_size)
-{
- size_t alloc_size = 0;
- unsigned offset_idx = 0;
- NSTCP_LOGINF ("mz(%p), mz_len = 0x%x", mz, mz_len);
-
- while (alloc_size + elt_size <= mz_len)
- {
- perfring_ptr->ring[alloc_index + offset_idx].data_s.ver =
- alloc_index + offset_idx;
- perfring_ptr->ring[alloc_index + offset_idx].data_s.val =
- ADDR_LTOSH_EXT (mz) - ((uint64_t) perfring_ptr->Addrbase);
- mz = (char *) mz + elt_size;
- alloc_size += elt_size;
- offset_idx++;
-
- if (alloc_index + offset_idx == max_index)
- {
- break;
- }
- }
-
- return offset_idx;
-}
-
-void
-nsfw_shmem_pool_free (struct nsfw_mem_ring *perfring_ptr)
-{
- struct nsfw_shmem_ring_head *ptemp;
-
- if (NULL == perfring_ptr)
- {
- return;
- }
-
- struct nsfw_shmem_ring_head *pnode =
- (struct nsfw_shmem_ring_head *) ((char *) perfring_ptr -
- sizeof (struct nsfw_shmem_ring_head));
-
- while (pnode)
- {
- // phead is involved in phead->mem_zone
- ptemp = pnode->next;
- common_mem_memzone_free (pnode->mem_zone);
- pnode = ptemp;
- }
-}
-
-struct nsfw_mem_ring *
-nsfw_shmem_pool_create (const char *name, unsigned int n,
- unsigned int elt_size, int socket_id,
- unsigned char flag)
-{
- struct nsfw_mem_ring *perfring_ptr = NULL;
- struct common_mem_memzone *mz_mem;
- void *mz = NULL;
-
- /*get pool size, pool size must pow of 2 */
- unsigned int num = common_mem_align32pow2 (n + 1);
-
- struct nsfw_shmem_ring_head *pcur = NULL;
- /*calculate the empty rte_perf_ring Size */
- size_t len =
- sizeof (struct nsfw_shmem_ring_head) + sizeof (struct nsfw_mem_ring) +
- (size_t) num * sizeof (union RingData_U) + (size_t) num * elt_size;
- size_t alloc_len = len;
- unsigned int alloc_num = 0;
- unsigned int alloc_index = 0;
-
- size_t mz_len = 0;
-
- unsigned int mz_index = 1;
- char mz_name[128] = { 0 };
- int retVal;
- /*we'd better use `strlen(src)` or `sizeof(dst)` to explain copying length of src string.
- it's meaningless using `sizeof(dst) - 1` to reserve 1 byte for '\0'.
- if copying length equals to or bigger than dst length, just let STRNCPY_S() returns failure. */
- retVal = STRNCPY_S (mz_name, sizeof (mz_name), name, sizeof (mz_name));
-
- if (EOK != retVal)
- {
- NSTCP_LOGERR ("STRNCPY_S failed]ret=%d", retVal);
- return NULL;
- }
-
- mz_mem = common_memzone_data_lookup_name (name);
- NSTCP_LOGINF ("memzone data look up] n=%u,num=%u,len=%zu", n, num, len);
-
- if (mz_mem)
- {
- perfring_ptr =
- (struct nsfw_mem_ring *) ((char *) mz_mem +
- sizeof (struct nsfw_shmem_ring_head));
- return perfring_ptr;
- }
-
- while (alloc_len > 0)
- {
- if (NULL != perfring_ptr)
- {
- retVal =
- SPRINTF_S (mz_name, sizeof (mz_name), "%s_%03d", name, mz_index);
-
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- nsfw_shmem_pool_free (perfring_ptr);
- return NULL;
- }
- }
-
- mz_mem =
- (struct common_mem_memzone *) common_mem_memzone_reserve (mz_name,
- alloc_len,
- socket_id,
- 0);
-
- if (mz_mem == NULL)
- {
- mz_mem =
- (struct common_mem_memzone *) common_mem_memzone_reserve (mz_name,
- 0,
- socket_id,
- 0);
- }
-
- if (mz_mem == NULL)
- {
- nsfw_shmem_pool_free (perfring_ptr);
- return NULL;
- }
-
- if (NULL == perfring_ptr
- && (mz_mem->len <
- sizeof (struct nsfw_shmem_ring_head) +
- sizeof (struct nsfw_mem_ring) +
- num * sizeof (union RingData_U)))
- {
- common_mem_memzone_free (mz_mem);
- return NULL;
- }
-
- if (NULL == perfring_ptr)
- {
- pcur = (struct nsfw_shmem_ring_head *) ADDR_SHTOL (mz_mem->addr_64);
- pcur->mem_zone = mz_mem;
- pcur->next = NULL;
-
- perfring_ptr =
- (struct nsfw_mem_ring *) ((char *) pcur +
- sizeof (struct nsfw_shmem_ring_head));
-
- mz =
- (void *) ((char *) perfring_ptr + sizeof (struct nsfw_mem_ring) +
- num * sizeof (union RingData_U));
- mz_len =
- mz_mem->len - sizeof (struct nsfw_shmem_ring_head) -
- sizeof (struct nsfw_mem_ring) - num * sizeof (union RingData_U);
-
- uint64_t rte_base_addr;
- uint64_t rte_highest_addr;
- nsfw_shmem_ring_baseaddr_query (&rte_base_addr, &rte_highest_addr);
- nsfw_mem_pool_head_init (perfring_ptr, num, elt_size,
- (void *) rte_base_addr, NSFW_SHMEM,
- (nsfw_mpool_type) flag);
- }
- else
- {
- if (pcur)
- {
- pcur->next =
- (struct nsfw_shmem_ring_head *) ADDR_SHTOL (mz_mem->addr_64);
- pcur = pcur->next;
- pcur->mem_zone = mz_mem;
- pcur->next = NULL;
-
- if (mz_mem->len < sizeof (struct nsfw_shmem_ring_head))
- {
- NSCOMM_LOGERR ("mz_len error %d", mz_mem->len);
- nsfw_shmem_pool_free (perfring_ptr);
- return NULL;
- }
-
- mz =
- (void *) ((char *) pcur +
- sizeof (struct nsfw_shmem_ring_head));
- mz_len = mz_mem->len - sizeof (struct nsfw_shmem_ring_head);
- }
- }
-
- alloc_num =
- nsfw_shmem_pool_node_alloc (perfring_ptr, alloc_index, num, mz,
- mz_len, elt_size);
- alloc_index += alloc_num;
-
- if (alloc_index >= num)
- {
- break;
- }
-
- // second time allocate should not contained all ring head
- alloc_len =
- (size_t) (num - alloc_index) * elt_size +
- sizeof (struct nsfw_shmem_ring_head);
- mz_index++;
- }
-
- return perfring_ptr;
-}
-
-/*ring create*/
-struct nsfw_mem_ring *
-nsfw_shmem_ring_create (const char *name, unsigned int n, int socket_id,
- unsigned char flag)
-{
- struct nsfw_mem_ring *perfring_ptr;
- struct common_mem_memzone *mz;
- uint64_t rte_base_addr;
- uint64_t rte_highest_addr;
-
- unsigned int num = common_mem_align32pow2 (n);
-
- mz =
- (struct common_mem_memzone *) common_mem_memzone_reserve (name,
- sizeof (struct
- nsfw_mem_ring)
- +
- num *
- sizeof (union
- RingData_U),
- socket_id, 0);
-
- if (mz == NULL)
- {
- return NULL;
- }
-
- perfring_ptr = mz->addr;
-
- nsfw_shmem_ring_baseaddr_query (&rte_base_addr, &rte_highest_addr);
- nsfw_mem_ring_init (perfring_ptr, num, (void *) rte_base_addr, NSFW_SHMEM,
- flag);
-
- return perfring_ptr;
-}
-
-/*
-this is a multi thread/process enqueue function, please pay attention to the bellow point
-1. while Enqueue corrupt, we may lose one element; because no one to add the Head
-*/
-int
-nsfw_shmem_ring_mp_enqueue (struct nsfw_mem_ring *ring, void *box)
-{
- union RingData_U expectPostVal;
- union RingData_U curVal;
- unsigned int tmpHead;
- unsigned int tmpTail;
- unsigned int CurHead = ring->prod.head;
- unsigned int mask = ring->mask;
- unsigned int size = ring->size;
- void *prmBox = NULL;
-
- prmBox = (void *) ADDR_LTOSH_EXT (box);
-
- /*do box range check */
- if ((char *) prmBox <= (char *) ring->Addrbase
- || (char *) prmBox > (char *) ring->Addrbase + PERFRING_ADDR_RANGE)
- {
- /*invalid addr of box, can't put in rte_perf_ring, maybe should set a errno here */
- return -1;
- }
-
- do
- {
- /*
- if the ring is Full return directly; this not a exact check, cause we made tail++ after dequeue success.
- the thing we could make sure is ring[ring->Tail&mask] already dequeue
- */
- tmpTail = ring->cons.tail;
-
- if (tmpTail + size - CurHead == 0)
- {
- /*
- here we give enqueue a chance to recorrect the Tail, if tail not has Data let tail++
- */
- if (ring->ring[tmpTail & mask].data_s.val == 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->cons.tail, tmpTail,
- tmpTail + 1);
- }
- else
- {
- return 0;
- }
- }
-
- /*
- the old version of ring->ring[CurHead&mask] must CurHead - size, which enqueue set to this pos lasttime
- & the val must already dequeue. otherwise this pos can't enqueue;
- */
- expectPostVal.data_l =
- (((unsigned long long) (CurHead - size)) << VALUE_LEN);
-
- /*
- the new version of ring->ring[CurHead&mask] must CurHead, which enqueue set to this pos this time.
- */
- curVal.data_l =
- ((((unsigned long long) CurHead) << VALUE_LEN) |
- ((char *) prmBox - (char *) ring->Addrbase));
- if (ring->ring[CurHead & mask].data_s.ver == expectPostVal.data_s.ver
- && __sync_bool_compare_and_swap (&ring->ring[CurHead & mask].data_l,
- expectPostVal.data_l,
- curVal.data_l))
- {
- /*
- enqueue success, add Head Value now
- here we using CAS set instead __sync_fetch_and_add(&ring->Head, 1) to assume that, if one process enqueue success && been killed before
- add Head, other process can recorrect the Head Value;
- one more thing the direction of Tail must been add-direction, so we using the condition (ring->Head - CurHead >0x80000000);
- while many thread do enqueue at same time, Head may not correct,exp:
- thread A get old head 10, thread A want set head to 11
- thread B get old head 10, thread B want set head to 12
- thread A do CAS && thread B do CAS at same time, thread A do CAS success;
- the result of head is 11, but the correct Value should be 12;
-
- then thread C get old head 11, thread C will set head to 13[cause pos 12 already has value, thread C will skill 12],
- the head will be recorrect by thread C.
- if no thread C, thread A& B are the last enqueue thread; the head must recorrect by the deque function.
- */
- tmpHead = ring->prod.head;
-
- if (0 == (CurHead & 0x03) && tmpHead - CurHead > 0x80000000)
- {
- (void) __sync_bool_compare_and_swap (&ring->prod.head, tmpHead,
- CurHead + 1);
- }
-
- break;
- }
-
- /*
- CurHead++ here;
- may be cpu slice is end here; while re-sched CurHead < ring->Tail < ring->Head; to avoid multi try
- we using a cmp & CurHead++ instead CurHead++ directly.
- if using CurHead++ will amplify the probability of ABA problem
- */
- /*CurHead++; */
- tmpHead = ring->prod.head;
- CurHead = CurHead - tmpHead < mask - 1 ? CurHead + 1 : tmpHead;
- }
- while (1);
-
- return 1;
-}
-
-/*
- this is a single thread/process enqueue function
- */
-int
-nsfw_shmem_ring_sp_enqueue (struct nsfw_mem_ring *ring, void *box)
-{
- union RingData_U texpectPostVal;
- union RingData_U curVal;
- unsigned int tmpTail;
- unsigned int CurHead = ring->prod.head;
- unsigned int mask = ring->mask;
- unsigned int uisize = ring->size;
- void *prmBox = NULL;
-
- prmBox = (void *) ADDR_LTOSH_EXT (box);
-
- if ((char *) prmBox <= (char *) ring->Addrbase
- || (char *) prmBox > (char *) ring->Addrbase + PERFRING_ADDR_RANGE)
- {
- return -1;
- }
-
- do
- {
- tmpTail = ring->cons.tail;
- if (tmpTail + uisize - CurHead == 0)
- {
- /*
- *here we give enqueue a chance to recorrect the Tail, if tail not has Data let tail++
- */
- if (ring->ring[tmpTail & mask].data_s.val == 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->cons.tail, tmpTail,
- tmpTail + 1);
- }
- else
- {
- return 0;
- }
- }
- texpectPostVal.data_l =
- (((unsigned long long) (CurHead - uisize)) << VALUE_LEN);
-
- curVal.data_l =
- ((((unsigned long long) CurHead) << VALUE_LEN) |
- ((char *) prmBox - (char *) ring->Addrbase));
-
- if (ring->ring[CurHead & mask].data_l == texpectPostVal.data_l)
- {
- ring->ring[CurHead & mask].data_l = curVal.data_l;
- ring->prod.head = CurHead + 1;
- break;
- }
-
- CurHead++;
- }
- while (1);
- return 1;
-}
-
-/*this is a multi thread/process dequeue function, please pay attention to the bellow point
-*/
-int
-nsfw_shmem_ring_mc_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- unsigned int CurTail;
- unsigned int tmpTail;
- unsigned int tmpHead;
- unsigned int mask = ring->mask;
- union RingData_U curNullVal;
- union RingData_U ExcpRingVal;
-
- CurTail = ring->cons.tail;
- do
- {
- /*if ring is empty return directly */
- tmpHead = ring->prod.head;
-
- if (CurTail == tmpHead)
- {
- /*
- here we give deque a chance to recorrect the Head, if head has Data let Head++
- */
- if (ring->ring[tmpHead & mask].data_s.val != 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->prod.head, tmpHead,
- tmpHead + 1);
- }
- else
- {
- return 0;
- }
- }
- curNullVal.data_l = (((unsigned long long) CurTail) << VALUE_LEN);
- ExcpRingVal = ring->ring[CurTail & mask];
- /*
- *the version of ring->ring[CurTail&mask] must CurTail&0xFFFFFF
- */
- if ((curNullVal.data_s.ver == ExcpRingVal.data_s.ver)
- && (ExcpRingVal.data_s.val)
- && __sync_bool_compare_and_swap (&ring->ring[CurTail & mask].data_l,
- ExcpRingVal.data_l,
- curNullVal.data_l))
- {
-
- *box =
- ADDR_SHTOL (((char *) ring->Addrbase + ExcpRingVal.data_s.val));
-
- /*
- enqueue success, add Tail Value now
- here we using CAS set instead __sync_fetch_and_add(&ring->Tail, 1) to assume that, if one process dequeue success && been killed before
- add Tail, other process can recorrect the Tail Value;
- one more thing the direction of Tail must been add-direction, so we using the condition (rlTail - CurTail >0x80000000);
- while multi CAS done the result value of CurTail may not correct, but we don't care, it will be recorrect while next deque done.
-
- avg CAS cost 200-300 Cycles, so we using cache loop to instead some CAS;[head&tail not exact guide, so no need Do CAS evertime]
- here we using 0 == (CurTail&0x11) means we only do CAS while head/tail low bit is 0x11; four times do one CAS.
- */
- tmpTail = ring->cons.tail;
-
- if (0 == (CurTail & 0x03) && tmpTail - CurTail > 0x80000000)
- {
- (void) __sync_bool_compare_and_swap (&ring->cons.tail, tmpTail,
- CurTail + 1);
- }
- break;
- }
-
- /*
- CurTail++ here;
- may be cpu slice is end here; while re-sched CurTail < ring->Tail < ring->Head; to avoid multi try
- we using a cmp & CurTail++ instead CurTail++ directly.
- if using CurTail++ will amplify the probability of ABA problem
- */
- /*CurTail++; */
- tmpTail = ring->cons.tail;
- CurTail = CurTail - tmpTail < mask - 1 ? CurTail + 1 : tmpTail;
- }
- while (1);
-
- return 1;
-}
-
-/*
- this is enhanced mc_ring_dequeue, support dequeue multi element one time.
-*/
-int
-nsfw_shmem_ring_mc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n)
-{
- unsigned int uiCurTail;
- unsigned int tmpTail;
- unsigned int tmpHead;
- unsigned int uimask = ring->mask;
- union RingData_U curNullVal;
- union RingData_U ExcpRingVal;
- unsigned int deqNum = 0;
- uiCurTail = ring->cons.tail;
- do
- {
- /*if ring is empty return directly */
- tmpHead = ring->prod.head;
- if (uiCurTail == tmpHead)
- {
- /*
- here we give deque a chance to recorrect the Head, if head has Data let Head++;
- here must done to avoid some msg can't deque.
- */
- if (deqNum == 0 && ring->ring[tmpHead & uimask].data_s.val != 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->prod.head, tmpHead,
- tmpHead + 1);
- }
- else
- {
- return deqNum;
- }
- }
-
- curNullVal.data_l = (((unsigned long long) uiCurTail) << VALUE_LEN);
- ExcpRingVal = ring->ring[uiCurTail & uimask];
-
- /*
- *the version of ring->ring[CurTail&mask] must CurTail&0xFFFFFF
- */
- if ((curNullVal.data_s.ver == ExcpRingVal.data_s.ver)
- && (ExcpRingVal.data_s.val)
- && __sync_bool_compare_and_swap (&ring->
- ring[uiCurTail & uimask].data_l,
- ExcpRingVal.data_l,
- curNullVal.data_l))
- {
-
- box[deqNum] =
- ADDR_SHTOL (((char *) ring->Addrbase + ExcpRingVal.data_s.val));
-
- /*
- enqueue success, add Tail Value now
- here we using CAS set instead __sync_fetch_and_add(&ring->Tail, 1) to assume that, if one process dequeue success && been killed before
- add Tail, other process can recorrect the Tail Value;
- one more thing the direction of Tail must been add-direction, so we using the condition (rlTail - CurTail >0x80000000);
-
- avg CAS cost 200-300 Cycles, so we using cache loop to instead some CAS;[head&tail not exact guide, so no need Do CAS evertime]
- here we using 0 == (CurTail&0x11) means we only do CAS while head/tail low bit is 0x11; four times do one CAS.
- */
- tmpTail = ring->cons.tail;
-
- if (0 == (uiCurTail & 0x03) && tmpTail - uiCurTail > 0x80000000)
- {
- (void) __sync_bool_compare_and_swap (&ring->cons.tail, tmpTail,
- uiCurTail + 1);
- }
-
- deqNum++;
- }
-
- /*
- CurTail++ here;
- may be cpu slice is end here; while re-sched CurTail < ring->Tail < ring->Head; to avoid multi try
- we using a cmp & CurTail++ instead CurTail++ directly.
- if using CurTail++ will amplify the probability of ABA problem
- */
- /*CurTail++; */
- tmpTail = ring->cons.tail;
- uiCurTail = uiCurTail - tmpTail < uimask - 1 ? uiCurTail + 1 : tmpTail;
-
- }
- while (n > deqNum);
-
- return deqNum;
-}
-
-/*
- this is enhanced mc_ring_dequeue, support dequeue multi element one time.
-*/
-int
-nsfw_shmem_ring_sc_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- unsigned int CurTail;
- unsigned int mask = ring->mask;
- union RingData_U curNullVal;
- union RingData_U ExcpRingVal;
- unsigned int uitmpHead;
-
- CurTail = ring->cons.tail;
-
- do
- {
- /*if ring is empty return directly */
- uitmpHead = ring->prod.head;
- if (CurTail == uitmpHead)
- {
- /*
- here we give deque a chance to recorrect the Head, if head has Data let Head++
- */
- if (ring->ring[uitmpHead & mask].data_s.val != 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->prod.head,
- uitmpHead, uitmpHead + 1);
- }
- else
- {
- return 0;
- }
- }
- curNullVal.data_l = (((unsigned long long) CurTail) << VALUE_LEN);
- ExcpRingVal = ring->ring[CurTail & mask];
-
- if ((curNullVal.data_s.ver == ExcpRingVal.data_s.ver)
- && (ExcpRingVal.data_s.val))
- {
- ring->ring[CurTail & mask].data_l = curNullVal.data_l;
-
- *box =
- ADDR_SHTOL (((char *) ring->Addrbase + ExcpRingVal.data_s.val));
-
- ring->cons.tail = CurTail + 1;
- break;
- }
-
- CurTail++;
- }
- while (1);
-
- return 1;
-}
-
-/*
- this is a single thread/process dequeue function
-*/
-int
-nsfw_shmem_ring_sc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n)
-{
- unsigned int CurTail;
- unsigned int tmpHead;
- unsigned int mask = ring->mask;
- union RingData_U curNullVal;
- union RingData_U ExcpRingVal;
- unsigned int usdeqNum = 0;
-
- CurTail = ring->cons.tail;
-
- do
- {
- /*if ring is empty return directly */
- tmpHead = ring->prod.head;
- if (CurTail == tmpHead)
- {
- /*
- here we give deque a chance to recorrect the Head, if head has Data let Head++;
- here must done to avoid some msg can't deque.
- */
- if (usdeqNum == 0 && ring->ring[tmpHead & mask].data_s.val != 0)
- {
- (void) __sync_bool_compare_and_swap (&ring->prod.head, tmpHead,
- tmpHead + 1);
- }
- else
- {
- return usdeqNum;
- }
- }
- curNullVal.data_l = (((unsigned long long) CurTail) << VALUE_LEN);
- ExcpRingVal = ring->ring[CurTail & mask];
-
- /*
- the version of ring->ring[CurTail&mask] must CurTail&0xFFFFFF
- */
- if ((curNullVal.data_s.ver == ExcpRingVal.data_s.ver)
- && (ExcpRingVal.data_s.val))
- {
- ring->ring[CurTail & mask].data_l = curNullVal.data_l;
-
- box[usdeqNum] =
- ADDR_SHTOL (((char *) ring->Addrbase + ExcpRingVal.data_s.val));
-
- ring->cons.tail = CurTail + 1;
- usdeqNum++;
- }
-
- CurTail++;
- }
- while (n > usdeqNum);
-
- return usdeqNum;
-}
-
-/* nstack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_shmem_ring_singlethread_enqueue (struct nsfw_mem_ring *ring, void *box)
-{
- u32 head = 0;
- void *prmBox = NULL;
-
- /*if queue is full, just return 0 */
- if (ring->prod.head >= (ring->size + ring->cons.tail))
- {
- return 0;
- }
-
- prmBox = (void *) ADDR_LTOSH_EXT (box);
-
- head = ring->prod.head;
- ring->prod.head = head + 1;
- ring->ring[head & ring->mask].data_s.ver = head;
- ring->ring[head & ring->mask].data_s.val =
- (char *) prmBox - (char *) ring->Addrbase;
- return 1;
-}
-
-/* nstack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_shmem_ring_singlethread_dequeue (struct nsfw_mem_ring *ring, void **box)
-{
- u32 tail = 0;
-
- /* if all entries are dequeued return 0 */
- if (unlikely (ring->prod.head == ring->cons.tail))
- {
- return 0;
- }
-
- tail = ring->cons.tail;
- *box =
- ADDR_SHTOL ((char *) ring->Addrbase +
- ring->ring[tail & ring->mask].data_s.val);
- ring->ring[tail & ring->mask].data_s.val = 0;
- ring->ring[tail & ring->mask].data_s.ver = tail;
- ring->cons.tail++;
- return 1;
-}
-
-/* nstack just using one thread, for performance using que not support multi thread*/
-int
-nsfw_shmem_ring_singlethread_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n)
-{
- u32 tail = 0;
- u32 num = 0;
-
- while (num < n)
- {
- tail = ring->cons.tail;
-
- /* if all entries are dequeued return 0 */
- if (unlikely (ring->prod.head == ring->cons.tail))
- {
- return num;
- }
-
- ring->cons.tail = tail + 1;
-
- box[num] =
- ADDR_SHTOL ((char *) ring->Addrbase +
- ring->ring[tail & ring->mask].data_s.val);
-
- ring->ring[tail & ring->mask].data_s.val = 0;
- ring->ring[tail & ring->mask].data_s.ver = tail;
- num++;
- }
-
- return num;
-}
diff --git a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.h b/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.h
deleted file mode 100644
index 15cd1dd..0000000
--- a/src/framework/common/mem_mgr/nsfw_shmem/nsfw_shmem_ring.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_SHMEM_RING_H_
-#define _NSFW_SHMEM_RING_H_
-
-#include <stdint.h>
-
-#include "common_func.h"
-
-struct nsfw_shmem_ring_head
-{
- struct common_mem_memzone *mem_zone;
- struct nsfw_shmem_ring_head *next;
- unsigned int uireserv[4];
-};
-
-void nsfw_shmem_ring_baseaddr_query (uint64_t * rte_lowest_addr,
- uint64_t * rte_highest_addr);
-struct nsfw_mem_ring *nsfw_shmem_pool_create (const char *name,
- unsigned int n,
- unsigned int elt_size,
- int socket_id,
- unsigned char flag);
-struct nsfw_mem_ring *nsfw_shmem_ring_create (const char *name,
- unsigned int n, int socket_id,
- unsigned char flag);
-
-void nsfw_shmem_pool_free (struct nsfw_mem_ring *perfring_ptr);
-
-void nsfw_shmem_ring_reset (struct nsfw_mem_ring *ring, unsigned char flag);
-int nsfw_shmem_ring_mp_enqueue (struct nsfw_mem_ring *ring, void *box);
-int nsfw_shmem_ring_sp_enqueue (struct nsfw_mem_ring *ring, void *box);
-int nsfw_shmem_ring_mc_dequeue (struct nsfw_mem_ring *ring, void **box);
-int nsfw_shmem_ring_mc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n);
-int nsfw_shmem_ring_sc_dequeue (struct nsfw_mem_ring *ring, void **box);
-int nsfw_shmem_ring_sc_dequeuev (struct nsfw_mem_ring *ring, void **box,
- unsigned int n);
-int nsfw_shmem_ring_singlethread_enqueue (struct nsfw_mem_ring *ring,
- void *box);
-int nsfw_shmem_ring_singlethread_dequeue (struct nsfw_mem_ring *ring,
- void **box);
-int nsfw_shmem_ring_singlethread_dequeuev (struct nsfw_mem_ring *ring,
- void **box, unsigned int n);
-
-#endif /*_NSFW_SHMEM_RING_H_*/
diff --git a/src/framework/hal/hal.c b/src/framework/hal/hal.c
index 545c759..97e4608 100644
--- a/src/framework/hal/hal.c
+++ b/src/framework/hal/hal.c
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <errno.h>
-#include "common_sys_config.h"
-#include "common_mem_mbuf.h"
#include "nstack_log.h"
#include "nstack_securec.h"
#include "hal.h"
@@ -848,7 +847,7 @@ hal_is_nic_exist (const char *name)
"sudo ifconfig -a | grep -w \"%s[ :]\"", name);
if (-1 == retval)
{
- NSHAL_LOGERR ("rte_snprintf failed]retval=%d", retval);
+ NSHAL_LOGERR ("hal_snprintf failed]retval=%d", retval);
return 0;
}
diff --git a/src/framework/hal/hal.h b/src/framework/hal/hal.h
index 36ad79d..3ccbd4b 100644
--- a/src/framework/hal/hal.h
+++ b/src/framework/hal/hal.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include "hal_api.h"
#include "nstack_log.h"
+#include "dmm_common.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
diff --git a/src/framework/include/dmm_common.h b/src/framework/include/dmm_common.h
new file mode 100644
index 0000000..a696e48
--- /dev/null
+++ b/src/framework/include/dmm_common.h
@@ -0,0 +1,76 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef _DMM_COMMON_H_
+#define _DMM_COMMON_H_
+
+#include "dmm_config.h"
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#define _dmm_packed __attribute__((__packed__))
+#define _dmm_aliened(a) __attribute__((__aligned__(a)))
+#define _dmm_cache_aligned _dmm_aliened(DMM_CACHE_LINE_SIZE)
+
+#define DMM_ALIGN(x, a) (((x) + ((a) - 1)) / (a) * (a))
+#define dmm_align(x, a) ({ \
+ typeof(x) _a = (a); \
+ ((x) + (_a - 1)) / _a * _a; \
+})
+
+#ifndef offsetof
+#define offsetof(type, member) ((size_t)((type *)0)->member)
+#endif
+
+#ifndef container_of
+#define container_of(ptr, type, member) ({ \
+ typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) ); \
+})
+#endif
+
+inline static unsigned int
+dmm_align32pow2 (unsigned int v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+
+ return v + 1;
+}
+
+inline static unsigned long long
+dmm_align64pow2 (unsigned long long v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ v |= v >> 32;
+
+ return v + 1;
+}
+
+#endif
diff --git a/src/framework/include/dmm_config.h b/src/framework/include/dmm_config.h
index 43a06ab..4939842 100644
--- a/src/framework/include/dmm_config.h
+++ b/src/framework/include/dmm_config.h
@@ -21,23 +21,31 @@
#endif
#ifndef DMM_MAIN_SHARE_TYPE
-#define DMM_MAIN_SHARE_TYPE DMM_SHARE_FSHM /* 1 */
+#define DMM_MAIN_SHARE_TYPE DMM_SHARE_FSHM
#endif
#ifndef DMM_MAIN_SHARE_SIZE
#define DMM_MAIN_SHARE_SIZE 1024 /* Megabyte */
#endif
+#ifndef DMM_MAIN_SHARE_BASE
+#define DMM_MAIN_SHARE_BASE 0x700080000000 /* fixed base address */
+#endif
+
#ifndef DMM_SHARE_TYPE
-#define DMM_SHARE_TYPE DMM_SHARE_FSHM /* 1 */
+#define DMM_SHARE_TYPE DMM_SHARE_FSHM
#endif
#ifndef DMM_SHARE_SIZE
-#define DMM_SHARE_SIZE 16 /* Megabyte */
+#define DMM_SHARE_SIZE 8 /* Megabyte */
#endif
#ifndef DMM_HUGE_DIR
-#define DMM_HUGE_DIR "/mnt/dmm-huge"
+#define DMM_HUGE_DIR "/mnt/nstackhuge"
+#endif
+
+#ifndef DMM_CACHE_LINE_SIZE
+#define DMM_CACHE_LINE_SIZE 64
#endif
#endif /* _DMM_CONFIG_H_ */
diff --git a/src/framework/include/nsfw_fd_timer_api.h b/src/framework/include/nsfw_fd_timer_api.h
index 0b42fe0..7aa8bb7 100644
--- a/src/framework/include/nsfw_fd_timer_api.h
+++ b/src/framework/include/nsfw_fd_timer_api.h
@@ -26,12 +26,14 @@ extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */
+#include "dmm_ring.h"
+
#define NSFW_TIMER_MODULE "nsfw_timer"
typedef struct _nsfw_timer_init_cfg
{
u32 timer_info_size;
- void *timer_info_pool;
+ struct dmm_ring *timer_info_pool;
struct list_head timer_head;
struct list_head exp_timer_head;
} nsfw_timer_init_cfg;
diff --git a/src/framework/include/nsfw_mem_api.h b/src/framework/include/nsfw_mem_api.h
deleted file mode 100644
index db7f5e7..0000000
--- a/src/framework/include/nsfw_mem_api.h
+++ /dev/null
@@ -1,546 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_MEM_API_H
-#define _NSFW_MEM_API_H
-#include <stdint.h>
-#include <sys/types.h>
-
-#include "types.h"
-#include "nsfw_mgr_com_api.h"
-#include "nstack_log.h"
-
-#define NSFW_MEM_MGR_MODULE "nsfw_mem_mgr"
-
-/*
- *the max len of memory name is 32bytes, but app just can use max 22bytes, left 10bytes to memory manager module
- */
-#define NSFW_MEM_NAME_LENGTH (32)
-#define NSFW_MEM_APPNAME_LENGTH (22)
-
-#define NSFW_SOCKET_ANY (-1)
-#define NSFW_MEM_OK (0)
-#define NSFW_MEM_ERR (-1)
-
-/*
- *type of memory:
- *NSFW_SHMEM:shared memory
- *NSFW_NSHMEM:allocated by calling malloc
- */
-typedef enum
-{
- NSFW_SHMEM,
- NSFW_NSHMEM,
- NSFW_MEM_TYPEMAX,
-} nsfw_mem_type;
-
-/*type of ring operation*/
-typedef enum
-{
- NSFW_MRING_SPSC, /*single producer single consumer ring */
- NSFW_MRING_MPSC, /*multi producer single consumer ring */
- NSFW_MRING_SPMC, /*single producer multi consumer ring */
- NSFW_MRING_MPMC, /*multi producer multi consumer ring */
- NSFW_MRING_SPSC_ST, /*single producer single consumer and belong to one thread ring */
- NSFW_MPOOL_TYPEMAX,
-} nsfw_mpool_type;
-
-typedef void *mpool_handle;
-typedef void *mzone_handle;
-typedef void *mbuf_handle;
-typedef void *mring_handle;
-
-/*initial of param*/
-typedef struct
-{
- i32 iargsnum;
- i8 **pargs;
- fw_poc_type enflag; /*app, nStackMain, Master */
-} nsfw_mem_para;
-
-typedef struct
-{
- nsfw_mem_type entype;
- fw_poc_type enowner; /*notes: 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
- * end with null created by nStackMaster, and end with _<pid> created by other.
- * 2. pname->enowner is available only when call look up shared memory.
- * 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
- * the name must be full name.
- * for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
- * must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
- * _(pid) at the end of name, nstack_123.
- */
- i8 aname[NSFW_MEM_NAME_LENGTH]; /*the length of name must be less than NSFW_MEM_APPNAME_LENGTH. */
-} nsfw_mem_name;
-
-typedef struct
-{
- nsfw_mem_name stname;
- size_t length;
- i32 isocket_id;
- i32 ireserv;
-} nsfw_mem_zone;
-
-typedef struct
-{
- nsfw_mem_name stname;
- unsigned usnum; /*the really created mbfpool num is (num+1) power of 2 */
- unsigned uscash_size;
- unsigned uspriv_size;
- unsigned usdata_room;
- i32 isocket_id;
- nsfw_mpool_type enmptype;
-} nsfw_mem_mbfpool;
-
-typedef struct
-{
- nsfw_mem_name stname;
- u32 usnum; /*the really created sppool num is (num+1) power of 2 */
- u32 useltsize;
- i32 isocket_id;
- nsfw_mpool_type enmptype;
-} nsfw_mem_sppool;
-
-typedef struct
-{
- nsfw_mem_name stname;
- u32 usnum; /*the really created ring num is (num+1) power of 2 */
- i32 isocket_id;
- nsfw_mpool_type enmptype;
-} nsfw_mem_mring;
-
-typedef enum
-{
- NSFW_MEM_ALLOC_SUCC = 1,
- NSFW_MEM_ALLOC_FAIL = 2,
-} nsfw_mem_alloc_state;
-
-typedef enum
-{
- NSFW_MEM_MZONE,
- NSFW_MEM_MBUF,
- NSFW_MEM_SPOOL,
- NSFW_MEM_RING
-} nsfw_mem_struct_type;
-
-typedef enum
-{
- NSFW_RESERV_REQ_MSG,
- NSFW_RESERV_ACK_MSG,
- NSFW_MBUF_REQ_MSG,
- NSFW_MBUF_ACK_MSG,
- NSFW_SPPOOL_REQ_MSG,
- NSFW_SPPOOL_ACK_MSG,
- NSFW_RING_REQ_MSG,
- NSFW_RING_ACK_MSG,
- NSFW_RELEASE_REQ_MSG,
- NSFW_RELEASE_ACK_MSG,
- NSFW_MEM_LOOKUP_REQ_MSG,
- NSFW_MEM_LOOKUP_ACK_MSG,
- NSFW_MEM_MAX_MSG
-} nsfw_remote_msg;
-
-typedef struct __nsfw_shmem_msg_head
-{
- unsigned usmsg_type;
- unsigned uslength;
- i32 aidata[0];
-} nsfw_shmem_msg_head;
-
-typedef struct __nsfw_shmem_ack
-{
- void *pbase_addr;
- u16 usseq;
- i8 cstate;
- i8 creserv;
- i32 ireserv;
-} nsfw_shmem_ack;
-
-typedef struct __nsfw_shmem_reserv_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 usreserv;
- i32 isocket_id;
- size_t length;
- i32 ireserv;
-} nsfw_shmem_reserv_req;
-
-typedef struct __nsfw_shmem_mbuf_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 enmptype;
- unsigned usnum;
- unsigned uscash_size;
- unsigned uspriv_size;
- unsigned usdata_room;
- i32 isocket_id;
- i32 ireserv;
-} nsfw_shmem_mbuf_req;
-
-typedef struct __nsfw_shmem_sppool_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 enmptype;
- u32 usnum;
- u32 useltsize;
- i32 isocket_id;
- i32 ireserv;
-} nsfw_shmem_sppool_req;
-
-typedef struct __nsfw_shmem_ring_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 enmptype;
- u32 usnum;
- i32 isocket_id;
- i32 ireserv;
-} nsfw_shmem_ring_req;
-
-typedef struct __nsfw_shmem_free_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 ustype; /*structure of memory(memzone,mbuf,mpool,ring) */
- i32 ireserv;
-} nsfw_shmem_free_req;
-
-typedef struct __nsfw_shmem_lookup_req
-{
- i8 aname[NSFW_MEM_NAME_LENGTH];
- u16 usseq;
- u16 ustype; /*structure of memory(memzone,mbuf,mpool,ring) */
- i32 ireserv;
-} nsfw_shmem_lookup_req;
-
-typedef int (*nsfw_mem_ring_enqueue_fun) (mring_handle ring, void *box);
-typedef int (*nsfw_mem_ring_dequeue_fun) (mring_handle ring, void **box);
-typedef int (*nsfw_mem_ring_dequeuev_fun) (mring_handle ring, void **box,
- unsigned int n);
-
-typedef struct
-{
- nsfw_mem_ring_enqueue_fun ring_ops_enqueue;
- nsfw_mem_ring_dequeue_fun ring_ops_dequeue;
- nsfw_mem_ring_dequeuev_fun ring_ops_dequeuev;
-} nsfw_ring_ops;
-
-/*
- * memory module init
- * para:point to nstack_fwmem_para
- */
-i32 nsfw_mem_init (void *para);
-
-/*
- * create a block memory with name
- * nsfw_mem_zone::stname
- * nsfw_mem_zone::isize
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-mzone_handle nsfw_mem_zone_create (nsfw_mem_zone * pinfo);
-
-/*
- *create some memory blocks
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_zone_createv (nsfw_mem_zone * pmeminfo, i32 inum,
- mzone_handle * paddr_array, i32 iarray_num);
-
-/*
- *look up a memory
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- * 2. if the memory is shared, pname->enowner indicate that who create this memory,
- * note:
- * 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
- * end with none created by nStackMaster, and end with _<pid> created by other.
- * 2. pname->enowner is available only when call look up shared memory.
- * 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
- * the name must be full name.
- * for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
- * must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
- * _(pid) at the end of name, nstack_123.
- */
-mzone_handle nsfw_mem_zone_lookup (nsfw_mem_name * pname);
-
-/*release a memory*/
-i32 nsfw_mem_zone_release (nsfw_mem_name * pname);
-
-/*
- *create a mbuf pool
- */
-mpool_handle nsfw_mem_mbfmp_create (nsfw_mem_mbfpool * pbufinfo);
-
-/*
- *create some mbuf pools
- * note: 1. the name of length must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_mbfmp_createv (nsfw_mem_mbfpool * pmbfname, i32 inum,
- mpool_handle * phandle_array, i32 iarray_num);
-
-/*
- *alloc a mbuf from mbuf pool
- */
-mbuf_handle nsfw_mem_mbf_alloc (mpool_handle mhandle, nsfw_mem_type entype);
-
-/*
- *put a mbuf backintp mbuf pool
- */
-i32 nsfw_mem_mbf_free (mbuf_handle mhandle, nsfw_mem_type entype);
-
-/*
- *look up mbuf mpool
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- * 2. if the memory is shared, pname->enowner indicate that who create this memory.
- * note:
- * 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
- * end with none created by nStackMaster, and end with _<pid> created by other.
- * 2. pname->enowner is available only when call look up shared memory.
- * 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
- * the name must be full name.
- * for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
- * must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
- * _(pid) at the end of name, nstack_123.
- */
-mpool_handle nsfw_mem_mbfmp_lookup (nsfw_mem_name * pmbfname);
-
-/*
- *release mbuf pool
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_mbfmp_release (nsfw_mem_name * pname);
-
-/*
- *create a simple pool
- *note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-mring_handle nsfw_mem_sp_create (nsfw_mem_sppool * pmpinfo);
-
-/*
- *create some simple pools one time
- *note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_sp_createv (nsfw_mem_sppool * pmpinfo, i32 inum,
- mring_handle * pringhandle_array, i32 iarray_num);
-
-/*
- *create a simple pool with many rings
- *note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_sp_ring_create (nsfw_mem_mring * prpoolinfo,
- mring_handle * pringhandle_array, i32 iringnum);
-
-/*
- *release a simple mempool
- *note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_sp_release (nsfw_mem_name * pname);
-
-/*
- *look up a simpile ring
- * note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- * 2. if the memory is shared, pname->enowner indicate that who create this memory,
- * note:
- * 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
- * end with none created by nStackMaster, and end with _<pid> created by other.
- * 2. pname->enowner is available only when call look up shared memory.
- * 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
- * the name must be full name.
- * for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
- * must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
- * _(pid) at the end of name, nstack_123.
- */
-mring_handle nsfw_mem_sp_lookup (nsfw_mem_name * pname);
-
-/*
- *create a ring
- *note: 1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- * 2. shared memory ring (NSFW_SHMEM) just can put a pointer into the queue, the queue also point to a shared block memory.
- * no shared memory ring(NSFW_NSHMEM) is other wise.
- */
-mring_handle nsfw_mem_ring_create (nsfw_mem_mring * pringinfo);
-
-/*
- *look up a ring by name
- * note:1. the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- * 2. if the memory is shared, pname->enowner indicate that who create this memory,
- * note:
- * 1. when calling any shared memory create inferface, the name of memory end with _0 created by nStackMain,
- * end with none created by nStackMaster, and end with _<pid> created by other.
- * 2. pname->enowner is available only when call look up shared memory.
- * 3. if the roles of process is NSFW_PROC_MASTER but the memory was created by others, or pname->enowner is NSFW_PROC_NULL,
- * the name must be full name.
- * for examles if the memory was created by nStackMain and pname->enowner is NSFW_PROC_NULL,
- * must add '_0' at the end of name, if the memory was created by app and the role of process is NSFW_PROC_MASTER, must add
- * _(pid) at the end of name, nstack_123.
- */
-mring_handle nsfw_mem_ring_lookup (nsfw_mem_name * pname);
-
-/*
- * reset the number of producer and consumer, also, the state of ring reset to empty
- * notes: must be called before doing any operations base on the ring
- */
-void nsfw_mem_ring_reset (mring_handle mhandle, nsfw_mpool_type entype);
-
-extern nsfw_ring_ops g_ring_ops_arry[NSFW_MEM_TYPEMAX][NSFW_MPOOL_TYPEMAX];
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_dequeue
-* Description : get a member from a ring
-* note : if NSFW_SHMEM ring, pdata returned already a local address
-* Input : mring_handle mhandle
-* void** pdata
-* Output : None
-* Return Value : the num of elment get from the queue, =0: get null, <0: err happen, >0: return num.
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-static inline i32
-nsfw_mem_ring_dequeue (mring_handle mhandle, void **pdata)
-{
- if (NULL == mhandle || *((u8 *) mhandle) >= NSFW_MEM_TYPEMAX
- || *((u8 *) mhandle + 1) >= NSFW_MPOOL_TYPEMAX)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return -1;
- }
-
- return
- g_ring_ops_arry[*((u8 *) mhandle)][*((u8 *) mhandle + 1)].ring_ops_dequeue
- (mhandle, pdata);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_dequeuev
-* Description : get some members from a ring
-* note : if NSFW_SHMEM ring, pdata returned already a local address
-* Input : mring_handle mhandle
-* void** pdata
-* unsigned inum
-* Output : None
-* Return Value : the num of elment get from the queue, =0: get null, <0: err happen, >0: return num.
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-static inline i32
-nsfw_mem_ring_dequeuev (mring_handle mhandle, void **pdata, unsigned int inum)
-{
- if (NULL == mhandle || *((u8 *) mhandle) >= NSFW_MEM_TYPEMAX
- || *((u8 *) mhandle + 1) >= NSFW_MPOOL_TYPEMAX)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return -1;
- }
-
- return
- g_ring_ops_arry[*((u8 *) mhandle)][*
- ((u8 *) mhandle +
- 1)].ring_ops_dequeuev (mhandle, pdata,
- inum);
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_ring_enqueue
-* Description : put a member back into a ring
-* note : pdata must point to a shared block memory when put into the NSFW_SHMEM type memory ring, and the
-* value of pdata must be local address
-* Input : mring_handle mhandle
-* void* pdata
-* Output : None
-* Return Value : the num of elment put into the queue, =0: put null, <0: err happen, >0: return num.
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-static inline i32
-nsfw_mem_ring_enqueue (mring_handle mhandle, void *pdata)
-{
- if (NULL == mhandle || *((u8 *) mhandle) >= NSFW_MEM_TYPEMAX
- || *((u8 *) mhandle + 1) >= NSFW_MPOOL_TYPEMAX)
- {
- NSCOMM_LOGERR ("input para error] mhandle=%p", mhandle);
- return -1;
- }
-
- return
- g_ring_ops_arry[*((u8 *) mhandle)][*((u8 *) mhandle + 1)].ring_ops_enqueue
- (mhandle, pdata);
-}
-
-/*
- *get the free number of ring
- */
-u32 nsfw_mem_ring_free_count (mring_handle mhandle);
-
-/*
- *get the in using number of ring
- */
-u32 nsfw_mem_ring_using_count (mring_handle mhandle);
-
-/*
- *get size of ring
- */
-u32 nsfw_mem_ring_size (mring_handle mhandle);
-
-/*
- *release a ring memory
- *note: the length of name must be less than NSFW_MEM_APPNAME_LENGTH.
- */
-i32 nsfw_mem_ring_release (nsfw_mem_name * pname);
-
-/*
- *statics mbufpool, sppool, ring mem size
- *return: <=0, err happen, >0 mem size
- * NSFW_MEM_MZONE: not surport because you already know the length when create
- */
-ssize_t nsfw_mem_get_len (void *handle, nsfw_mem_struct_type type);
-
-/*
- *recycle mbuf
- *
- */
-i32 nsfw_mem_mbuf_pool_recycle (mpool_handle handle);
-
-typedef int (*nsfw_mem_item_fun) (void *data, void *argv);
-
-i32 nsfw_mem_sp_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
-i32 nsfw_mem_mbuf_iterator (mpool_handle handle, u32 start, u32 end,
- nsfw_mem_item_fun fun, void *argv);
-
-/*****************************************************************************
-* Prototype : nsfw_mem_dfx_ring_print
-* Description : print ring info
-* Input : mring_handle mhandle
-* char *pbuf
-* int length
-* Output : None
-* Return Value : i32
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-i32 nsfw_mem_dfx_ring_print (mring_handle mhandle, char *pbuf, int length);
-
-#ifdef SYS_MEM_RES_STAT
-u32 nsfw_mem_mbfpool_free_count (mpool_handle mhandle);
-#endif
-
-#endif
diff --git a/src/framework/include/nsfw_mgr_com_api.h b/src/framework/include/nsfw_mgr_com_api.h
index 56ec08f..a7da957 100644
--- a/src/framework/include/nsfw_mgr_com_api.h
+++ b/src/framework/include/nsfw_mgr_com_api.h
@@ -26,6 +26,8 @@ extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */
+#include "types.h"
+
#define NSFW_MGR_COM_MODULE "nsfw_mgr_com"
#define MRG_RSP(_req_msg) (_req_msg + MGR_MSG_RSP_BASE)
diff --git a/src/framework/include/nsfw_ps_mem_api.h b/src/framework/include/nsfw_ps_mem_api.h
deleted file mode 100644
index 01f9cd3..0000000
--- a/src/framework/include/nsfw_ps_mem_api.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_PS_MEM_API_H
-#define _NSFW_PS_MEM_API_H
-
-#include "nsfw_mem_api.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-#define NSFW_PS_MEM_MODULE "nsfw_ps_mem"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-#endif /* _NSFW_PS_MEM_API_H */
diff --git a/src/framework/include/nsfw_recycle_api.h b/src/framework/include/nsfw_recycle_api.h
index 9d7f3bb..e103812 100644
--- a/src/framework/include/nsfw_recycle_api.h
+++ b/src/framework/include/nsfw_recycle_api.h
@@ -23,6 +23,8 @@ extern "C"{
/* *INDENT-ON* */
#endif /* __cplusplus */
+#include "types.h"
+
#define NSFW_RECYCLE_MODULE "nsfw_recycle"
typedef enum _nsfw_recycle_item_type
diff --git a/src/framework/include/nstack_log.h b/src/framework/include/nstack_log.h
index 4e1ba81..f7cbdfe 100644
--- a/src/framework/include/nstack_log.h
+++ b/src/framework/include/nstack_log.h
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
diff --git a/src/framework/include/nstack_securec.h b/src/framework/include/nstack_securec.h
index c9efb4f..15f88b6 100644
--- a/src/framework/include/nstack_securec.h
+++ b/src/framework/include/nstack_securec.h
@@ -33,15 +33,12 @@ extern "C" {
#ifndef NULL
#define NULL ((void *)0)
-#endif /*
- */
+#endif
/*define error code*/
#ifndef errno_t
typedef int errno_t;
-
-#endif /*
- */
+#endif
/* success */
#define EOK (0)
@@ -49,8 +46,7 @@ typedef int errno_t;
/* invalid parameter */
#ifndef EINVAL
#define EINVAL (22)
-#endif /*
- */
+#endif
#define EINVAL_AND_RESET (22 | 0X80)
#define ERANGE_AND_RESET (34 | 0X80)
@@ -136,6 +132,7 @@ typedef int errno_t;
#define WCSTOK_S(a, b, c) wcstok_s(a, b, c)
#define GETS_S(a, b) gets_s(a, b)
#endif /* */
+
#ifdef __cplusplus
/* *INDENT-OFF* */
}
diff --git a/src/framework/init/CMakeLists.txt b/src/framework/init/CMakeLists.txt
index ff8d4d2..134610c 100644
--- a/src/framework/init/CMakeLists.txt
+++ b/src/framework/init/CMakeLists.txt
@@ -14,11 +14,9 @@
# limitations under the License.
#########################################################################
-SET(LIBSBR_SRC fw_init.c fw_module.c)
+SET(LIBINIT_SRC fw_init.c fw_module.c)
-SET(COMM_CONFIG ${PROJECT_SOURCE_DIR}/src/framework/common/base/include/common_sys_config.h)
ADD_DEFINITIONS(-fPIC -mssse3)
-ADD_DEFINITIONS(-include ${COMM_CONFIG})
-ADD_LIBRARY(nStackfwinit static ${LIBSBR_SRC})
+ADD_LIBRARY(nStackfwinit static ${LIBINIT_SRC})
diff --git a/src/framework/init/fw_init.c b/src/framework/init/fw_init.c
index 2764479..c7f38a0 100644
--- a/src/framework/init/fw_init.c
+++ b/src/framework/init/fw_init.c
@@ -245,6 +245,43 @@ nstack_framework_printInitialResult ()
NSFW_LOGINF ("All modules are inited");
}
+static void
+nstack_framework_print_list ()
+{
+ nsfw_module_manager_t *manager = nsfw_module_getManager ();
+ nsfw_module_instance_t *inst;
+
+ for (inst = manager->inst; inst; inst = inst->next)
+ {
+ char deps[512];
+ nsfw_module_depends_t *depends;
+
+ if (inst->depends)
+ {
+ int depn = 0;
+
+ for (depends = inst->depends; depends; depends = depends->next)
+ {
+ int len = snprintf (&deps[depn], sizeof (deps) - depn,
+ "%s", depends->name);
+ if (len < 0)
+ {
+ break;
+ }
+ depn += len;
+ }
+ deps[sizeof (deps) - 1] = 0;
+ }
+ else
+ {
+ (void) snprintf (deps, sizeof (deps), "{null}");
+ }
+
+ NSFW_LOGDBG ("module: %s father: %s priority: %d depends: %s",
+ inst->name, inst->fatherName, inst->priority, deps);
+ }
+}
+
/**
* @Function nstack_framework_init
* @Description This function will do framework initial work, it will invoke all initial functions
@@ -271,6 +308,8 @@ nstack_framework_init (void)
goto done;
}
+ nstack_framework_print_list ();
+
ret = nstack_framework_initChild_unsafe (NULL);
if (0 == ret)
diff --git a/src/framework/init/fw_module.c b/src/framework/init/fw_module.c
index 1f22ecb..acf4fdb 100644
--- a/src/framework/init/fw_module.c
+++ b/src/framework/init/fw_module.c
@@ -225,10 +225,8 @@ nsfw_module_set_instance_depends (nsfw_module_instance_t * inst, char *name)
if (NULL == dep)
return;
- if (NULL == inst->depends)
- inst->depends = dep;
- else
- inst->depends->next = dep;
+ dep->next = inst->depends;
+ inst->depends = dep;
}
/* *INDENT-OFF* */
diff --git a/src/framework/ipc/mgr_com/mgr_com.c b/src/framework/ipc/mgr_com/mgr_com.c
index 2fb9789..0541ba8 100644
--- a/src/framework/ipc/mgr_com/mgr_com.c
+++ b/src/framework/ipc/mgr_com/mgr_com.c
@@ -17,28 +17,27 @@
/*==============================================*
* include header files *
*----------------------------------------------*/
+#include <errno.h>
+#include <sys/un.h>
+#include <stddef.h>
+#include <sys/epoll.h>
+#include <fcntl.h>
+#include <sys/stat.h>
#include "types.h"
#include "nstack_securec.h"
#include "nsfw_init.h"
-#include "common_mem_api.h"
-
#include "nsfw_mgr_com_api.h"
#include "mgr_com.h"
#include "nstack_log.h"
#include "nsfw_base_linux_api.h"
-
-#include <sys/un.h>
-#include <stddef.h>
-#include <sys/epoll.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
#include "nsfw_maintain_api.h"
#include "nsfw_ps_api.h"
#include "nsfw_fd_timer_api.h"
-#include "common_func.h"
+#include "dmm_atomic.h"
+#include "dmm_sys.h"
+#include "dmm_memory.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -168,8 +167,7 @@ nsfw_mgr_msg_alloc (u16 msg_type, u8 dst_proc_type)
if (FALSE == from_mem_flag)
{
- if (0 ==
- nsfw_mem_ring_dequeue (g_mgr_com_cfg.msg_pool, (void *) &p_msg))
+ if (1 != dmm_dequeue (g_mgr_com_cfg.msg_pool, (void **) &p_msg))
{
NSFW_LOGERR ("alloc msg full]type=%u,dst=%u", msg_type,
dst_proc_type);
@@ -200,7 +198,8 @@ nsfw_mgr_msg_alloc (u16 msg_type, u8 dst_proc_type)
if (msg_type < MGR_MSG_RSP_BASE && msg_type > 0)
{
- p_msg->seq = common_mem_atomic32_add_return (&g_mgr_com_cfg.cur_idx, 1);
+ p_msg->seq =
+ dmm_atomic_add_return ((dmm_atomic_t *) & g_mgr_com_cfg.cur_idx, 1);
}
p_msg->from_mem = from_mem_flag;
@@ -298,7 +297,7 @@ nsfw_mgr_msg_free (nsfw_mgr_msg * msg)
NSFW_LOGERR ("msg err free]type=%u", msg->msg_type);
}
- if (0 == nsfw_mem_ring_enqueue (g_mgr_com_cfg.msg_pool, msg))
+ if (1 != dmm_enqueue (g_mgr_com_cfg.msg_pool, msg))
{
NSFW_LOGERR ("msg free failed pool full]msg=%p, type=%u", msg,
msg->msg_type);
@@ -693,7 +692,7 @@ nsfw_mgr_clr_fd_lock ()
}
for (i = 0; i < (i32) NSFW_MGR_FD_MAX; i++)
{
- common_mem_spinlock_init (&(g_mgr_socket_map.sock[i].opr_lock));
+ dmm_spin_init (&(g_mgr_socket_map.sock[i].opr_lock));
}
return TRUE;
}
@@ -1953,32 +1952,8 @@ nsfw_mgr_com_module_init (void *param)
mgr_cfg->proc_type = proc_type;
- nsfw_mem_sppool pmpinfo;
- if (EOK != MEMSET_S (&pmpinfo, sizeof (pmpinfo), 0, sizeof (pmpinfo)))
- {
- NSFW_LOGERR ("Error to memset!!!");
- nsfw_mgr_comm_fd_destroy ();
- lint_unlock_1 ();
- return -1;
- }
-
- pmpinfo.enmptype = NSFW_MRING_MPMC;
- pmpinfo.usnum = mgr_cfg->msg_size;
- pmpinfo.useltsize = sizeof (nsfw_mgr_msg);
- pmpinfo.isocket_id = NSFW_SOCKET_ANY;
- pmpinfo.stname.entype = NSFW_NSHMEM;
- if (-1 ==
- SPRINTF_S (pmpinfo.stname.aname, sizeof (pmpinfo.stname.aname), "%s",
- "MS_MGR_MSGPOOL"))
- {
- NSFW_LOGERR ("Error to SPRINTF_S!!!");
- nsfw_mgr_comm_fd_destroy ();
- lint_unlock_1 ();
- return -1;
- }
-
- mgr_cfg->msg_pool = nsfw_mem_sp_create (&pmpinfo);
-
+ mgr_cfg->msg_pool = dmm_malloc_pool (sizeof (nsfw_mgr_msg),
+ mgr_cfg->msg_size, DMM_RING_INIT_MPMC);
if (!mgr_cfg->msg_pool)
{
NSFW_LOGERR ("module mgr init msg_pool alloc failed!");
@@ -1987,8 +1962,8 @@ nsfw_mgr_com_module_init (void *param)
return -1;
}
- (void) MEM_STAT (NSFW_MGR_COM_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
- nsfw_mem_get_len (mgr_cfg->msg_pool, NSFW_MEM_SPOOL));
+// (void) MEM_STAT (NSFW_MGR_COM_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
+// nsfw_mem_get_len (mgr_cfg->msg_pool, NSFW_MEM_SPOOL));
if ((NSFW_PROC_TOOLS == proc_type)
|| (NSFW_PROC_CTRL == proc_type) || (NSFW_PROC_MAIN == proc_type))
@@ -2048,8 +2023,8 @@ nsfw_mgr_run_script (const char *cmd, char *result, int result_buf_len)
/* *INDENT-OFF* */
NSFW_MODULE_NAME(NSFW_MGR_COM_MODULE)
-NSFW_MODULE_PRIORITY(10)
-NSFW_MODULE_DEPENDS(NSFW_MEM_MGR_MODULE)
+NSFW_MODULE_PRIORITY(20)
+NSFW_MODULE_DEPENDS(DMM_MEMORY_MODULE)
NSFW_MODULE_INIT(nsfw_mgr_com_module_init)
/* *INDENT-ON* */
diff --git a/src/framework/ipc/mgr_com/mgr_com.h b/src/framework/ipc/mgr_com/mgr_com.h
index 03f58c8..dbcce63 100644
--- a/src/framework/ipc/mgr_com/mgr_com.h
+++ b/src/framework/ipc/mgr_com/mgr_com.h
@@ -26,11 +26,13 @@
#ifndef _NSFW_MGRCOM_MODULE_H
#define _NSFW_MGRCOM_MODULE_H
-#include "pthread.h"
-#include "nsfw_mem_api.h"
-#include "common_mem_api.h"
-#include "common_mem_memzone.h"
-#include "common_func.h"
+#include <pthread.h>
+
+#include "types.h"
+#include "nsfw_mgr_com_api.h"
+
+#include "dmm_ring.h"
+#include "dmm_spinlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -44,7 +46,7 @@ extern "C"{
#define MAX_RECV_BUF_DEF 0x34000*2
-#define MGR_COM_MSG_COUNT_DEF 1023 /*g_mgr_com_cfg */
+#define MGR_COM_MSG_COUNT_DEF 1024 /*g_mgr_com_cfg */
#define MGR_COM_RECV_TIMEOUT_DEF 5
#define MGR_COM_MAX_DROP_MSG_DEF 1024
@@ -64,9 +66,9 @@ typedef struct _nsfw_mgr_init_cfg
u8 max_recv_timeout;
u16 max_recv_drop_msg;
u32 msg_size;
- common_mem_atomic32_t cur_idx;
+ int cur_idx;
u64 u64reserve;
- mring_handle msg_pool;
+ struct dmm_ring *msg_pool;
char domain_path[NSFW_MGRCOM_PATH_LEN];
} nsfw_mgr_init_cfg;
@@ -85,7 +87,7 @@ typedef struct _nsfw_mgr_sock_info
{
u8 proc_type; /*_ns_poc_type*/
u32 host_pid;
- common_mem_spinlock_t opr_lock;
+ dmm_spinlock_t opr_lock;
} nsfw_mgr_sock_info;
typedef struct _nsfw_mgr_sock_map
@@ -123,14 +125,14 @@ u8 nsfw_mgr_stop ();
#define LOCK_MGR_FD(_fd){\
if ((i32)NSFW_MGR_FD_MAX > _fd)\
{\
- common_mem_spinlock_lock(&g_mgr_socket_map.sock[_fd].opr_lock);\
+ dmm_spin_lock(&g_mgr_socket_map.sock[_fd].opr_lock);\
}\
}
#define UNLOCK_MGR_FD(_fd){\
if ((i32)NSFW_MGR_FD_MAX > _fd)\
{\
- common_mem_spinlock_unlock(&g_mgr_socket_map.sock[_fd].opr_lock);\
+ dmm_spin_unlock(&g_mgr_socket_map.sock[_fd].opr_lock);\
}\
}
diff --git a/src/framework/ipc/ps/nsfw_fd_timer.c b/src/framework/ipc/ps/nsfw_fd_timer.c
index cea2486..643348a 100644
--- a/src/framework/ipc/ps/nsfw_fd_timer.c
+++ b/src/framework/ipc/ps/nsfw_fd_timer.c
@@ -22,17 +22,16 @@
#include "types.h"
#include "list.h"
-#include "common_mem_common.h"
-
#include "nstack_securec.h"
#include "nsfw_init.h"
#include "nsfw_mgr_com_api.h"
-#include "nsfw_mem_api.h"
#include "nstack_log.h"
#include "nsfw_base_linux_api.h"
#include "nsfw_fd_timer_api.h"
#include "nsfw_maintain_api.h"
+#include "dmm_memory.h"
+
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
@@ -40,7 +39,7 @@ extern "C"{
#endif /* __cplusplus */
#define NSFW_TIMER_CYCLE 1
-#define NSFW_TIMER_INFO_MAX_COUNT_DEF 8191
+#define NSFW_TIMER_INFO_MAX_COUNT_DEF 8192
#define NSFW_TIMER_INFO_MAX_COUNT (g_timer_cfg.timer_info_size)
/* *INDENT-OFF* */
nsfw_timer_init_cfg g_timer_cfg;
@@ -66,8 +65,7 @@ nsfw_timer_reg_timer (u32 timer_type, void *data,
nsfw_timer_proc_fun fun, struct timespec time_left)
{
nsfw_timer_info *tm_info = NULL;
- if (0 ==
- nsfw_mem_ring_dequeue (g_timer_cfg.timer_info_pool, (void *) &tm_info))
+ if (1 != dmm_dequeue (g_timer_cfg.timer_info_pool, (void **) &tm_info))
{
NSFW_LOGERR ("dequeue error]data=%p,fun=%p", data, fun);
return NULL;
@@ -75,7 +73,7 @@ nsfw_timer_reg_timer (u32 timer_type, void *data,
if (EOK != MEMSET_S (tm_info, sizeof (*tm_info), 0, sizeof (*tm_info)))
{
- if (0 == nsfw_mem_ring_enqueue (g_timer_cfg.timer_info_pool, tm_info))
+ if (1 != dmm_enqueue (g_timer_cfg.timer_info_pool, tm_info))
{
NSFW_LOGERR ("enqueue error]data=%p,fun=%p", data, fun);
}
@@ -121,7 +119,7 @@ nsfw_timer_rmv_timer (nsfw_timer_info * tm_info)
tm_info->alloc_flag = FALSE;
list_del (&tm_info->node);
- if (0 == nsfw_mem_ring_enqueue (g_timer_cfg.timer_info_pool, tm_info))
+ if (1 != dmm_enqueue (g_timer_cfg.timer_info_pool, tm_info))
{
NSFW_LOGERR ("tm_info free failed]tm_info=%p,argv=%p,fun=%p", tm_info,
tm_info->argv, tm_info->fun);
@@ -334,29 +332,17 @@ nsfw_timer_module_init (void *param)
timer_cfg->timer_info_size = NSFW_TIMER_INFO_MAX_COUNT_DEF;
- nsfw_mem_sppool pmpinfo;
- pmpinfo.enmptype = NSFW_MRING_MPMC;
- pmpinfo.usnum = timer_cfg->timer_info_size;
- pmpinfo.useltsize = sizeof (nsfw_timer_info);
- pmpinfo.isocket_id = NSFW_SOCKET_ANY;
- pmpinfo.stname.entype = NSFW_NSHMEM;
- if (-1 ==
- SPRINTF_S (pmpinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- "MS_TM_INFOPOOL"))
- {
- NSFW_LOGERR ("SPRINTF_S failed");
- return -1;
- }
- timer_cfg->timer_info_pool = nsfw_mem_sp_create (&pmpinfo);
-
+ timer_cfg->timer_info_pool = dmm_malloc_pool (sizeof (nsfw_timer_info),
+ timer_cfg->timer_info_size,
+ DMM_RING_INIT_MPMC);
if (!timer_cfg->timer_info_pool)
{
NSFW_LOGERR ("alloc timer info pool_err");
return -1;
}
- MEM_STAT (NSFW_TIMER_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
- nsfw_mem_get_len (timer_cfg->timer_info_pool, NSFW_MEM_SPOOL));
+// MEM_STAT (NSFW_TIMER_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
+// nsfw_mem_get_len (timer_cfg->timer_info_pool, NSFW_MEM_SPOOL));
INIT_LIST_HEAD (&(timer_cfg->timer_head));
INIT_LIST_HEAD (&(timer_cfg->exp_timer_head));
@@ -367,7 +353,7 @@ nsfw_timer_module_init (void *param)
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSFW_TIMER_MODULE)
-NSFW_MODULE_PRIORITY (10)
+NSFW_MODULE_PRIORITY (30)
NSFW_MODULE_DEPENDS (NSFW_MGR_COM_MODULE)
NSFW_MODULE_INIT (nsfw_timer_module_init)
/* *INDENT-ON* */
diff --git a/src/framework/ipc/ps/nsfw_ps_mem_module.c b/src/framework/ipc/ps/nsfw_ps_mem_module.c
deleted file mode 100644
index 55af158..0000000
--- a/src/framework/ipc/ps/nsfw_ps_mem_module.c
+++ /dev/null
@@ -1,924 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <stdlib.h>
-#include "types.h"
-#include "nstack_securec.h"
-#include "nsfw_init.h"
-
-#include "nsfw_ps_module.h"
-#include "nsfw_mgr_com_api.h"
-#include "nsfw_ps_mem_api.h"
-#include "nsfw_ps_mem_module.h"
-#include "nsfw_ps_api.h"
-#include "nsfw_maintain_api.h"
-#include "nsfw_fd_timer_api.h"
-
-#include "nstack_log.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-ns_mem_mng_init_cfg g_mem_cfg;
-
-int mem_ps_exiting (void *pps_info, void *argv);
-
-int
-nsfw_mem_ps_exit_resend_timeout (u32 timer_type, void *data)
-{
- nsfw_ps_info *ps_info = data;
- if (NULL == ps_info)
- {
- NSFW_LOGERR ("ps_info nul!");
- return FALSE;
- }
-
- if (NSFW_PROC_APP != ps_info->proc_type)
- {
- return FALSE;
- }
-
- if (NSFW_PS_EXITING != ps_info->state)
- {
- return FALSE;
- }
-
- ps_info->resend_timer_ptr = NULL;
- (void) mem_ps_exiting (ps_info, NULL);
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_ps_exiting
-* Description : send exiting message when ps_info exiting
-* Input : void *pps_info
-* void* argv
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-mem_ps_exiting (void *pps_info, void *argv)
-{
- if (NULL == pps_info)
- {
- NSFW_LOGERR ("ps_info nul!");
- return FALSE;
- }
-
- if (TRUE == NSFW_SRV_STATE_SUSPEND)
- {
- NSFW_LOGERR ("main suspend]ps_info=%d,pid=%u", pps_info,
- ((nsfw_ps_info *) pps_info)->host_pid);
- return FALSE;
- }
-
- nsfw_mgr_msg *msg =
- nsfw_mgr_msg_alloc (MGR_MSG_APP_EXIT_REQ, NSFW_PROC_MAIN);
- if (NULL == msg)
- {
- NSFW_LOGERR ("ps_exit alloc msg failed]ps_info=%p,pid=%u", pps_info,
- ((nsfw_ps_info *) pps_info)->host_pid);
- return FALSE;
- }
-
- nsfw_ps_info_msg *ps_msg = GET_USER_MSG (nsfw_ps_info_msg, msg);
- ps_msg->host_pid = ((nsfw_ps_info *) pps_info)->host_pid;
-
- (void) nsfw_mgr_send_msg (msg);
- NSFW_LOGINF ("ps_exiting send msg]ps_info=%p,pid=%u", pps_info,
- ps_msg->host_pid);
- nsfw_mgr_msg_free (msg);
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_alloc_ps_info
-* Description : alloc ps_info
-* Input : u32 pid
-* u8 proc_type
-* Output : None
-* Return Value : u8
-* Calls :
-* Called By :
-*****************************************************************************/
-u8
-mem_alloc_ps_info (u32 pid, u8 proc_type)
-{
- nsfw_ps_info *pps_info = NULL;
- pps_info = nsfw_ps_info_get (pid);
- if (NULL != pps_info)
- {
- return TRUE;
- }
-
- pps_info = nsfw_ps_info_alloc (pid, proc_type);
- if (NULL == pps_info)
- {
- NSFW_LOGERR ("alloc ps_info failed!]pid=%u,proc_type=%u", pid,
- proc_type);
- return FALSE;
- }
-
- NSFW_LOGINF ("alloc new ps_info]pps_info=%p,pid=%u", pps_info, pid);
- return TRUE;
-}
-
-/*mem alloc by msg begin*/
-void *
-mem_item_zone_create (void *mem_info)
-{
- return (void *) nsfw_mem_zone_create ((nsfw_mem_zone *) mem_info);
-}
-
-void *
-mem_item_mbfmp_create (void *mem_info)
-{
- return (void *) nsfw_mem_mbfmp_create ((nsfw_mem_mbfpool *) mem_info);
-}
-
-void *
-mem_item_sp_create (void *mem_info)
-{
- return (void *) nsfw_mem_sp_create ((nsfw_mem_sppool *) mem_info);
-}
-
-void *
-mem_item_ring_create (void *mem_info)
-{
- return (void *) nsfw_mem_ring_create ((nsfw_mem_mring *) mem_info);
-}
-
-nsfw_ps_mem_item_cfg g_ps_mem_map[] = {
- {
- NSFW_RESERV_REQ_MSG,
- sizeof (nsfw_shmem_reserv_req),
- NSFW_MEM_MZONE,
- mem_item_zone_create,
- mem_item_get_callargv}
- ,
-
- {
- NSFW_MBUF_REQ_MSG,
- sizeof (nsfw_shmem_mbuf_req),
- NSFW_MEM_MBUF,
- mem_item_mbfmp_create,
- mem_item_get_callargv}
- ,
- {
- NSFW_SPPOOL_REQ_MSG,
- sizeof (nsfw_shmem_sppool_req),
- NSFW_MEM_SPOOL,
- mem_item_sp_create,
- mem_item_get_callargv}
- ,
- {
- NSFW_RING_REQ_MSG,
- sizeof (nsfw_shmem_ring_req),
- NSFW_MEM_RING,
- mem_item_ring_create,
- mem_item_get_callargv}
- ,
- {
- NSFW_RELEASE_REQ_MSG,
- sizeof (nsfw_shmem_free_req),
- 0xFFFF,
- mem_item_free,
- mem_item_get_callargv,
- }
- ,
- {
- NSFW_MEM_LOOKUP_REQ_MSG,
- sizeof (nsfw_shmem_lookup_req),
- 0xFFFF,
- mem_item_lookup,
- mem_item_get_callargv,
- }
-};
-
-/*****************************************************************************
-* Prototype : mem_item_get_cfg_from_msg
-* Description : get memory config
-* Input : u16 msg_type
-* Output : None
-* Return Value : nsfw_ps_mem_item_cfg *
-* Calls :
-* Called By :
-*****************************************************************************/
-nsfw_ps_mem_item_cfg *
-mem_item_get_cfg_from_msg (u16 msg_type)
-{
- int idx;
- int map_count = sizeof (g_ps_mem_map) / sizeof (nsfw_ps_mem_item_cfg);
- for (idx = 0; idx < map_count; idx++)
- {
- if (g_ps_mem_map[idx].usmsg_type == msg_type)
- {
- return &g_ps_mem_map[idx];
- }
- }
-
- return NULL;
-}
-
-/*****************************************************************************
-* Prototype : mem_item_get_callargv
-* Description : change the message value to structure value
-* Input : u16 msg_type
-* char* msg_body
-* char *memstr_buf
-* i32 buf_len
-* Output : None
-* Return Value : u8
-* Calls :
-* Called By :
-*****************************************************************************/
-u8
-mem_item_get_callargv (u16 msg_type, char *msg_body, char *memstr_buf,
- i32 buf_len)
-{
- switch (msg_type)
- {
- case NSFW_RESERV_REQ_MSG:
- MEM_GET_CALLARGV (length, length, nsfw_mem_zone, nsfw_shmem_reserv_req,
- memstr_buf, msg_body);
- MEM_GET_CALLARGV (isocket_id, isocket_id, nsfw_mem_zone,
- nsfw_shmem_reserv_req, memstr_buf, msg_body);
- break;
- case NSFW_MBUF_REQ_MSG:
- MEM_GET_CALLARGV (usnum, usnum, nsfw_mem_mbfpool, nsfw_shmem_mbuf_req,
- memstr_buf, msg_body);
- MEM_GET_CALLARGV (uscash_size, uscash_size, nsfw_mem_mbfpool,
- nsfw_shmem_mbuf_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (uspriv_size, uspriv_size, nsfw_mem_mbfpool,
- nsfw_shmem_mbuf_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (usdata_room, usdata_room, nsfw_mem_mbfpool,
- nsfw_shmem_mbuf_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (enmptype, enmptype, nsfw_mem_mbfpool,
- nsfw_shmem_mbuf_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (isocket_id, isocket_id, nsfw_mem_mbfpool,
- nsfw_shmem_mbuf_req, memstr_buf, msg_body);
- break;
- case NSFW_SPPOOL_REQ_MSG:
- MEM_GET_CALLARGV (usnum, usnum, nsfw_mem_sppool,
- nsfw_shmem_sppool_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (useltsize, useltsize, nsfw_mem_sppool,
- nsfw_shmem_sppool_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (enmptype, enmptype, nsfw_mem_sppool,
- nsfw_shmem_sppool_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (isocket_id, isocket_id, nsfw_mem_sppool,
- nsfw_shmem_sppool_req, memstr_buf, msg_body);
- break;
- case NSFW_RING_REQ_MSG:
- MEM_GET_CALLARGV (usnum, usnum, nsfw_mem_mring, nsfw_shmem_ring_req,
- memstr_buf, msg_body);
- MEM_GET_CALLARGV (enmptype, enmptype, nsfw_mem_mring,
- nsfw_shmem_ring_req, memstr_buf, msg_body);
- MEM_GET_CALLARGV (isocket_id, isocket_id, nsfw_mem_mring,
- nsfw_shmem_ring_req, memstr_buf, msg_body);
- break;
- case NSFW_RELEASE_REQ_MSG:
- MEM_GET_CALLARGV (ustype, ustype, nsfw_mem_type_info,
- nsfw_shmem_free_req, memstr_buf, msg_body);
- break;
- case NSFW_MEM_LOOKUP_REQ_MSG:
- MEM_GET_CALLARGV (ustype, ustype, nsfw_mem_type_info,
- nsfw_shmem_lookup_req, memstr_buf, msg_body);
- break;
- default:
- NSFW_LOGERR ("error msg]type=%u", msg_type);
- return FALSE;
- }
- if (EOK !=
- STRCPY_S (((nsfw_mem_zone *) memstr_buf)->stname.aname,
- NSFW_MEM_NAME_LENGTH,
- ((nsfw_shmem_reserv_req *) msg_body)->aname))
- {
- NSFW_LOGERR ("STRCPY_S failed]msg_type=%u", msg_type);
- return FALSE;
- }
-
- ((nsfw_mem_zone *) memstr_buf)->stname.entype = NSFW_SHMEM;
-
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_item_free
-* Description : free memory item
-* Input : void *pdata
-* Output : None
-* Return Value : void*
-* Calls :
-* Called By :
-*****************************************************************************/
-void *
-mem_item_free (void *pdata)
-{
- nsfw_mem_type_info *mem_free = (nsfw_mem_type_info *) pdata;
- i32 ret;
- NSFW_LOGINF ("free mem]type=%u,name=%s", mem_free->ustype,
- mem_free->stname.aname);
- switch (mem_free->ustype)
- {
- case NSFW_MEM_MZONE:
- ret = nsfw_mem_zone_release (&mem_free->stname);
- break;
- case NSFW_MEM_MBUF:
- ret = nsfw_mem_mbfmp_release (&mem_free->stname);
- break;
- case NSFW_MEM_SPOOL:
- ret = nsfw_mem_sp_release (&mem_free->stname);
- break;
- case NSFW_MEM_RING:
- ret = nsfw_mem_ring_release (&mem_free->stname);
- break;
- default:
- NSFW_LOGERR ("free mem err type]type=%u", mem_free->ustype);
- return NULL;
- }
-
- if (NSFW_MEM_OK != ret)
- {
- NSFW_LOGERR ("mem free failed!]ret=%d", ret);
- return NULL;
- }
-
- return pdata;
-}
-
-/*****************************************************************************
-* Prototype : mem_item_lookup
-* Description : lookup memory item
-* Input : void *pdata
-* Output : None
-* Return Value : void*
-* Calls :
-* Called By :
-*****************************************************************************/
-void *
-mem_item_lookup (void *pdata)
-{
- nsfw_mem_type_info *mem_lookup = (nsfw_mem_type_info *) pdata;
- void *ret;
- NSFW_LOGDBG ("lookup mem]type=%u,name=%s", mem_lookup->ustype,
- mem_lookup->stname.aname);
- switch (mem_lookup->ustype)
- {
- case NSFW_MEM_MZONE:
- ret = nsfw_mem_zone_lookup (&mem_lookup->stname);
- break;
- case NSFW_MEM_MBUF:
- ret = nsfw_mem_mbfmp_lookup (&mem_lookup->stname);
- break;
- case NSFW_MEM_SPOOL:
- ret = nsfw_mem_sp_lookup (&mem_lookup->stname);
- break;
- case NSFW_MEM_RING:
- ret = nsfw_mem_ring_lookup (&mem_lookup->stname);
- break;
- default:
- NSFW_LOGERR ("lookup mem err type]type=%d", mem_lookup->ustype);
- return NULL;
- }
-
- if (NULL == ret)
- {
- NSFW_LOGERR ("mem lookup failed!]ret=%p,name=%s", ret,
- mem_lookup->stname.aname);
- return NULL;
- }
-
- return ret;
-}
-
-/*****************************************************************************
-* Prototype : mem_item_proc_by_msg
-* Description : call memory item process function
-* Input : void *pdata
-* nsfw_ps_mem_item_cfg* item_cfg
-* Output : None
-* Return Value : void*
-* Calls :
-* Called By :
-*****************************************************************************/
-void *
-mem_item_proc_by_msg (void *pdata, nsfw_ps_mem_item_cfg * item_cfg)
-{
- char argv_buf[NSFW_MEM_CALL_ARG_BUF] = { 0 };
-
- if ((NULL == item_cfg->change_fun) || (NULL == item_cfg->create_fun))
- {
- NSFW_LOGERR ("item error]change_fun=%p,create_fun=%p",
- item_cfg->change_fun, item_cfg->create_fun);
- return NULL;
- }
-
- if (FALSE ==
- item_cfg->change_fun (item_cfg->usmsg_type, pdata, argv_buf,
- NSFW_MEM_CALL_ARG_BUF))
- {
- NSFW_LOGERR ("call change_fun failed!]type=%u", item_cfg->usmsg_type);
- return NULL;
- }
-
- void *pdataret = NULL;
- pdataret = (item_cfg->create_fun) ((void *) argv_buf);
- return pdataret;
-}
-
-/*****************************************************************************
-* Prototype : mem_init_rsp_msg
-* Description : init the rsp message
-* Input : nsfw_shmem_msg_head* msg
-* nsfw_shmem_msg_head *rsp
-* Output : None
-* Return Value : u8
-* Calls :
-* Called By :
-*
-*****************************************************************************/
-u8
-mem_init_rsp_msg (nsfw_shmem_msg_head * msg, nsfw_shmem_msg_head * rsp)
-{
- nsfw_ps_mem_item_cfg *item_cfg =
- mem_item_get_cfg_from_msg (msg->usmsg_type);
- if (NULL == item_cfg)
- {
- NSFW_LOGERR ("get item cfg failed!]msg_type=%u", msg->usmsg_type);
- return FALSE;
- }
-
- int idx;
- int mem_count = msg->uslength / item_cfg->item_size;
-
- rsp->usmsg_type = msg->usmsg_type + 1;
- rsp->uslength = mem_count * sizeof (nsfw_shmem_ack);
- nsfw_shmem_ack *pack = (nsfw_shmem_ack *) & (rsp->aidata[0]);
- char *pdata = NULL;
- for (idx = 0; idx < mem_count; idx++)
- {
- pdata = (char *) msg->aidata + idx * item_cfg->item_size;
- pack->pbase_addr = NULL;
- pack->usseq = ((nsfw_shmem_reserv_req *) pdata)->usseq;
- pack->cstate = NSFW_MEM_ALLOC_FAIL;
- pack++;
- }
-
- NSFW_LOGDBG ("init all rsp ack]mem_count=%d,msg_type=%u", mem_count,
- msg->usmsg_type);
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_rel_mem_by_msg
-* Description : release memory by message
-* Input : nsfw_shmem_msg_head* req_msg
-* nsfw_shmem_msg_head *rsp
-* u32 pid
-* Output : None
-* Return Value : u8
-* Calls :
-* Called By :
-*****************************************************************************/
-u8
-mem_rel_mem_by_msg (nsfw_shmem_msg_head * req_msg,
- nsfw_shmem_msg_head * rsp, u32 pid)
-{
- u32 i;
- nsfw_ps_mem_item_cfg *item_cfg =
- mem_item_get_cfg_from_msg (req_msg->usmsg_type);
- if (NULL == item_cfg)
- {
- NSFW_LOGERR ("get item cfg failed!]msg_type=%u", req_msg->usmsg_type);
- return FALSE;
- }
-
- unsigned int mem_count = req_msg->uslength / item_cfg->item_size;
- char *pdata = NULL;
- nsfw_shmem_ack *pack = (nsfw_shmem_ack *) & (rsp->aidata[0]);
- for (i = 0; i < mem_count; i++)
- {
- pdata = (char *) req_msg->aidata + i * item_cfg->item_size;
- if (NULL != mem_item_proc_by_msg ((void *) pdata, item_cfg))
- {
- pack->cstate = NSFW_MEM_ALLOC_SUCC;
- pack->pbase_addr = NULL;
- }
- pack++;
- }
-
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_lookup_mem_by_msg
-* Description : lookup memory by message
-* Input : nsfw_shmem_msg_head* mgr_msg
-* nsfw_shmem_msg_head *rsp
-* u32 pid
-* Output : None
-* Return Value : u8
-* Calls :
-* Called By :
-*****************************************************************************/
-u8
-mem_lookup_mem_by_msg (nsfw_shmem_msg_head * mgr_msg,
- nsfw_shmem_msg_head * rsp, u32 pid)
-{
- i32 idx;
- nsfw_ps_mem_item_cfg *item_cfg =
- mem_item_get_cfg_from_msg (mgr_msg->usmsg_type);
- if (NULL == item_cfg)
- {
- NSFW_LOGERR ("get item cfg failed!]msg_type=%u", mgr_msg->usmsg_type);
- return FALSE;
- }
-
- int mem_count = mgr_msg->uslength / item_cfg->item_size;
- char *pdata = NULL;
- void *paddr = NULL;
- nsfw_shmem_ack *pack = (nsfw_shmem_ack *) & (rsp->aidata[0]);
-
- for (idx = 0; idx < mem_count; idx++)
- {
- pdata = (char *) mgr_msg->aidata + idx * item_cfg->item_size;
- paddr = mem_item_proc_by_msg ((void *) pdata, item_cfg);
- if (NULL != paddr)
- {
- pack->cstate = NSFW_MEM_ALLOC_SUCC;
- pack->pbase_addr = paddr;
- }
- pack++;
- }
-
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_alloc_mem_by_msg
-* Description : alloc memory by message
-* Input : nsfw_shmem_msg_head* mem_msg
-* nsfw_shmem_msg_head *rsp
-* Output : None
-* Return Value : ns_mem_info*
-* Calls :
-* Called By :
-*****************************************************************************/
-void *
-mem_alloc_mem_by_msg (nsfw_shmem_msg_head * mem_msg,
- nsfw_shmem_msg_head * rsp)
-{
- nsfw_ps_mem_item_cfg *item_cfg =
- mem_item_get_cfg_from_msg (mem_msg->usmsg_type);
- if (NULL == item_cfg)
- {
- NSFW_LOGERR ("get item cfg failed!]msg_type=%u", mem_msg->usmsg_type);
- return NULL;
- }
-
- int i;
- int j;
- nsfw_mem_type_info mem_free;
- char *pdata = NULL;
- void *p_addr = NULL;
-
- int mem_count = mem_msg->uslength / item_cfg->item_size;
- nsfw_shmem_ack *pack = (nsfw_shmem_ack *) & (rsp->aidata[0]);
- for (i = 0; i < mem_count; i++)
- {
- pdata = (char *) mem_msg->aidata + i * item_cfg->item_size;
- p_addr = mem_item_proc_by_msg ((void *) pdata, item_cfg);
- if (NULL == p_addr)
- {
- NSFW_LOGERR
- ("alloc mem failed!]type=%u,mem_count=%d,item=%d,name=%s",
- mem_msg->usmsg_type, mem_count, i,
- ((nsfw_shmem_reserv_req *) pdata)->aname);
- goto fail_free_mem;
- }
-
- pack->cstate = NSFW_MEM_ALLOC_SUCC;
- pack->pbase_addr = p_addr;
- NSFW_LOGINF
- ("alloc mem suc!]addr=%p,type=%u,mem_count=%d,item=%d,name=%s",
- p_addr, mem_msg->usmsg_type, mem_count, i,
- ((nsfw_shmem_reserv_req *) pdata)->aname);
- pack++;
- }
- return p_addr;
-
-fail_free_mem:
- for (j = 0; j < i; j++)
- {
- pdata = (char *) mem_msg->aidata + j * item_cfg->item_size;
- if (EOK !=
- STRCPY_S (mem_free.stname.aname, NSFW_MEM_NAME_LENGTH,
- ((nsfw_shmem_reserv_req *) pdata)->aname))
- {
- NSFW_LOGERR ("STRCPY_S failed]j=%d", j);
- continue;
- }
-
- mem_free.ustype = item_cfg->mem_type;
- mem_free.stname.entype = NSFW_SHMEM;
- (void) mem_item_free (&mem_free);
- NSFW_LOGINF ("free mem]addr=%p,type=%u,mem_count=%d,item=%d,name=%s",
- p_addr, mem_msg->usmsg_type, mem_count, j,
- ((nsfw_shmem_reserv_req *) pdata)->aname);
- pack++;
- }
-
- return NULL;
-
-}
-
-/*****************************************************************************
-* Prototype : mem_alloc_req_proc
-* Description : memory message
-* Input : nsfw_mgr_msg* msg
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-mem_alloc_req_proc (nsfw_mgr_msg * msg)
-{
- void *mem_addr = NULL;
-
- if (NULL == msg)
- {
- NSFW_LOGERR ("msg nul");
- return FALSE;
- }
-
- nsfw_shmem_msg_head *mem_msg = GET_USER_MSG (nsfw_shmem_msg_head, msg);
- nsfw_mgr_msg *rsp_msg = nsfw_mgr_rsp_msg_alloc (msg);
- if (NULL == rsp_msg)
- {
- NSFW_LOGERR ("alloc rsp msg failed]msg_type=%u", mem_msg->usmsg_type);
- return FALSE;
- }
-
- nsfw_shmem_msg_head *mem_rsp_msg =
- GET_USER_MSG (nsfw_shmem_msg_head, rsp_msg);
-
- if (!mem_init_rsp_msg (mem_msg, mem_rsp_msg))
- {
- NSFW_LOGERR ("init rsp msg failed]msg_type=%u", mem_msg->usmsg_type);
- nsfw_mgr_msg_free (rsp_msg);
- return FALSE;
- }
-
- switch (mem_msg->usmsg_type)
- {
- case NSFW_MEM_LOOKUP_REQ_MSG:
- if (!mem_lookup_mem_by_msg (mem_msg, mem_rsp_msg, msg->src_pid))
- {
- NSFW_LOGERR ("lookup mem msg failed]msg_type=%u",
- mem_msg->usmsg_type);
- goto sendrspmsg;
- }
- (void) mem_alloc_ps_info (msg->src_pid, msg->src_proc_type);
- break;
- case NSFW_RESERV_REQ_MSG:
- case NSFW_MBUF_REQ_MSG:
- case NSFW_SPPOOL_REQ_MSG:
- case NSFW_RING_REQ_MSG:
- mem_addr = mem_alloc_mem_by_msg (mem_msg, mem_rsp_msg);
- if (NULL == mem_addr)
- {
- NSFW_LOGERR ("alloc mem msg failed]msg_type=%u",
- mem_msg->usmsg_type);
- (void) mem_init_rsp_msg (mem_msg, mem_rsp_msg);
- goto sendrspmsg;
- }
- (void) mem_alloc_ps_info (msg->src_pid, msg->src_proc_type);
- break;
- case NSFW_RELEASE_REQ_MSG:
- if (!mem_rel_mem_by_msg (mem_msg, mem_rsp_msg, msg->src_pid))
- {
- NSFW_LOGERR ("rel mem msg failed]msg_type=%u", mem_msg->usmsg_type);
- goto sendrspmsg;
- }
- break;
- default:
- break;
- }
-
-sendrspmsg:
- (void) nsfw_mgr_send_msg (rsp_msg);
- nsfw_mgr_msg_free (rsp_msg);
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_ps_exiting_resend
-* Description : send the exiting message again
-* Input : void *pps_info
-* void* argv
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-mem_ps_exiting_resend (void *pps_info, void *argv)
-{
- u32 *count = argv;
- nsfw_ps_info *ps_info = pps_info;
- if (NULL == ps_info)
- {
- NSFW_LOGERR ("ps_info nul!");
- return FALSE;
- }
-
- if (NSFW_PROC_APP != ps_info->proc_type)
- {
- return FALSE;
- }
-
- if (NSFW_PS_EXITING != ps_info->state)
- {
- return FALSE;
- }
-
- if (NULL != count)
- {
- NSFW_LOGINF ("send count]count=%u,pid=%u", *count, ps_info->host_pid);
- if (NSFW_PS_SEND_PER_TIME < (*count)++)
- {
- struct timespec time_left =
- { NSFW_PS_MEM_RESEND_TVLAUE +
-((*count) / NSFW_PS_SEND_PER_TIME), 0
- };
- ps_info->resend_timer_ptr =
- (void *) nsfw_timer_reg_timer (NSFW_PS_MEM_RESEND_TIMER,
- pps_info,
- nsfw_mem_ps_exit_resend_timeout,
- time_left);
- return TRUE;
- }
- }
-
- (void) mem_ps_exiting (ps_info, NULL);
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_mem_srv_restore_timeout
-* Description : service waiting resume timeout
-* Input : u32 timer_type
-* void* data
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-nsfw_mem_srv_restore_timeout (u32 timer_type, void *data)
-{
- u32 max_count = 0;
-
- g_mem_cfg.p_restore_timer = NULL;
- if (TRUE == NSFW_SRV_STATE_SUSPEND)
- {
- NSFW_SRV_STATE_SUSPEND = FALSE;
- (void) nsfw_ps_iterator (mem_ps_exiting_resend, &max_count);
- }
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : mem_srv_ctrl_proc
-* Description : service control message process
-* Input : nsfw_mgr_msg* msg
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-mem_srv_ctrl_proc (nsfw_mgr_msg * msg)
-{
- if (NULL == msg)
- {
- NSFW_LOGERR ("msg nul");
- return FALSE;
- }
-
- nsfw_srv_ctrl_msg *ctrl_msg = GET_USER_MSG (nsfw_srv_ctrl_msg, msg);
- nsfw_mgr_msg *rsp_msg = nsfw_mgr_rsp_msg_alloc (msg);
- if (NULL == rsp_msg)
- {
- NSFW_LOGERR ("alloc rsp msg failed]msg=%p", msg);
- return FALSE;
- }
- nsfw_srv_ctrl_msg *ctrl_rsp_msg = GET_USER_MSG (nsfw_srv_ctrl_msg, rsp_msg);
- NSFW_LOGINF ("get srv ctrl state] state=%d", ctrl_msg->srv_state);
-
- ctrl_rsp_msg->rsp_code = NSFW_MGR_SUCCESS;
-
- (void) nsfw_mgr_send_msg (rsp_msg);
- nsfw_mgr_msg_free (rsp_msg);
-
- if (NSFW_SRV_CTRL_RESUME == ctrl_msg->srv_state)
- {
- if (TRUE == NSFW_SRV_STATE_SUSPEND)
- {
- NSFW_SRV_STATE_SUSPEND = FALSE;
- }
- u32 max_count = 0;
- (void) nsfw_ps_iterator (mem_ps_exiting_resend, &max_count);
- if (NULL != g_mem_cfg.p_restore_timer)
- {
- nsfw_timer_rmv_timer ((nsfw_timer_info *)
- g_mem_cfg.p_restore_timer);
- g_mem_cfg.p_restore_timer = NULL;
- }
- }
- else
- {
- NSFW_SRV_STATE_SUSPEND = TRUE;
- struct timespec time_left = { NSFW_SRV_RESTORE_TVALUE, 0 };
- g_mem_cfg.p_restore_timer =
- (void *) nsfw_timer_reg_timer (0, NULL,
- nsfw_mem_srv_restore_timeout,
- time_left);
- }
-
- return TRUE;
-}
-
-/*****************************************************************************
-* Prototype : nsfw_ps_mem_module_init
-* Description : module init
-* Input : void* param
-* Output : None
-* Return Value : int
-* Calls :
-* Called By :
-*****************************************************************************/
-int
-nsfw_ps_mem_module_init (void *param)
-{
- u32 proc_type = (u32) ((long long) param);
- NSFW_LOGINF ("ps_mem module init]type=%u", proc_type);
- switch (proc_type)
- {
- case NSFW_PROC_MAIN:
- (void) nsfw_ps_reg_global_fun (NSFW_PROC_APP, NSFW_PS_EXITING,
- mem_ps_exiting, NULL);
- (void) nsfw_mgr_reg_msg_fun (MGR_MSG_MEM_ALLOC_REQ, mem_alloc_req_proc);
- (void) NSFW_REG_SOFT_INT (NSFW_SRV_RESTORE_TIMER,
- NSFW_SRV_RESTORE_TVALUE, 1, 0xFFFF);
- (void) NSFW_REG_SOFT_INT (NSFW_APP_RESEND_TIMER,
- NSFW_PS_MEM_RESEND_TVLAUE, 1, 0xFFFF);
- (void) NSFW_REG_SOFT_INT (NSFW_APP_SEND_PER_TIME,
- NSFW_PS_SEND_PER_TIME, 1, 0xFFFF);
- break;
- default:
- if (proc_type < NSFW_PROC_MAX)
- {
- return 0;
- }
- return -1;
- }
-
- g_mem_cfg.srv_restore_tvalue = NSFW_SRV_RESTORE_TVALUE_DEF;
- g_mem_cfg.ps_exit_resend_tvalue = NSFW_PS_MEM_RESEND_TVLAUE_DEF;
- g_mem_cfg.ps_send_per_time = NSFW_PS_SEND_PER_TIME_DEF;
-
- return 0;
-}
-
-/* *INDENT-OFF* */
-NSFW_MODULE_NAME (NSFW_PS_MEM_MODULE)
-NSFW_MODULE_PRIORITY (10)
-NSFW_MODULE_DEPENDS (NSFW_PS_MODULE)
-NSFW_MODULE_INIT (nsfw_ps_mem_module_init)
-/* *INDENT-ON* */
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif /* __cplusplus */
diff --git a/src/framework/ipc/ps/nsfw_ps_mem_module.h b/src/framework/ipc/ps/nsfw_ps_mem_module.h
deleted file mode 100644
index 6b2b3c9..0000000
--- a/src/framework/ipc/ps/nsfw_ps_mem_module.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSFW_PS_MEM_MODULE_H
-#define _NSFW_PS_MEM_MODULE_H
-
-#include "list.h"
-#include "pidinfo.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-#define MEMZONE_MAX_NAME 32
-#define NS_MAX_FORK_NUM 32
-#define NSFW_PS_MEM_MAX_FILTER 4
-
-#define NSFW_SRV_RESTORE_TVALUE_DEF 120
-#define NSFW_SRV_RESTORE_TVALUE g_mem_cfg.srv_restore_tvalue
-#define NSFW_SRV_STATE_SUSPEND g_mem_cfg.srv_suspend
-
-#define NSFW_PS_MEM_RESEND_TIMER 1
-#define NSFW_PS_MEM_RESEND_TVLAUE_DEF 2
-#define NSFW_PS_SEND_PER_TIME_DEF 150
-#define NSFW_PS_SEND_PER_TIME (g_mem_cfg.ps_send_per_time)
-#define NSFW_PS_MEM_RESEND_TVLAUE (g_mem_cfg.ps_exit_resend_tvalue)
-
-typedef struct _ns_mem_mng_init_cfg
-{
- u16 srv_restore_tvalue;
- u16 ps_exit_resend_tvalue;
- u16 ps_send_per_time;
- u16 srv_suspend;
- void *p_restore_timer;
-} ns_mem_mng_init_cfg;
-
-/*mem alloc by msg begin*/
-typedef struct
-{
- nsfw_mem_name stname;
- u16 ustype;
-} nsfw_mem_type_info;
-
-#define NSFW_MEM_CALL_ARG_BUF 256
-#define MEM_GET_CALLARGV(_dst_member,_src_member, _dst_type,_srctype,_dst_buf, _src_buf) \
- ((_dst_type*)(void*)_dst_buf)->_dst_member = ((_srctype*)(void*)_src_buf)->_src_member
-
-typedef void *(*nsfw_ps_mem_create_fun) (void *memstr);
-typedef u8 (*nsfw_ps_mem_msg_to_memstr) (u16 msg_type, char *msg_body,
- char *memstr_buf, i32 buf_len);
-
-typedef struct __nsfw_ps_mem_item_cfg
-{
- u16 usmsg_type;
- u16 item_size;
- u16 mem_type;
- nsfw_ps_mem_create_fun create_fun;
- nsfw_ps_mem_msg_to_memstr change_fun;
-} nsfw_ps_mem_item_cfg;
-
-void *mem_item_free (void *pdata);
-void *mem_item_lookup (void *pdata);
-u8 mem_item_get_callargv (u16 msg_type, char *msg_body, char *memstr_buf,
- i32 buf_len);
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif /* __cplusplus */
-
-#endif /* _NSFW_PS_MEM_MODULE_H */
diff --git a/src/framework/ipc/ps/nsfw_ps_module.c b/src/framework/ipc/ps/nsfw_ps_module.c
index 6e03e11..3f7cae0 100644
--- a/src/framework/ipc/ps/nsfw_ps_module.c
+++ b/src/framework/ipc/ps/nsfw_ps_module.c
@@ -22,7 +22,6 @@
#include "nsfw_mgr_com_api.h"
#include "nsfw_ps_api.h"
#include "nsfw_ps_module.h"
-#include "nsfw_mem_api.h"
#include "nstack_log.h"
#include "nsfw_base_linux_api.h"
#include "nsfw_fd_timer_api.h"
@@ -39,7 +38,7 @@
#include <linux/netlink.h>
#include <dirent.h>
#include <fnmatch.h>
-#include "common_mem_common.h"
+#include "dmm_memory.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -259,7 +258,7 @@ nsfw_ps_info *
nsfw_ps_info_alloc (u32 pid, u8 proc_type)
{
nsfw_ps_info *pps_info = NULL;
- if (0 == nsfw_mem_ring_dequeue (g_ps_cfg.ps_info_pool, (void *) &pps_info))
+ if (1 != dmm_dequeue (g_ps_cfg.ps_info_pool, (void **) &pps_info))
{
NSFW_LOGERR ("alloc ps_info failed]pid=%u,type=%u", pid, proc_type);
return NULL;
@@ -397,7 +396,7 @@ nsfw_ps_info_free (nsfw_ps_info * ps_info)
ps_info->host_pid, ps_info->state);
if (ps_info != &g_main_ps_info)
{
- if (0 == nsfw_mem_ring_enqueue (g_ps_cfg.ps_info_pool, ps_info))
+ if (1 != dmm_enqueue (g_ps_cfg.ps_info_pool, ps_info))
{
NSFW_LOGERR ("ps_info free failed]ps_info=%p,pid=%u,state=%u",
ps_info, ps_info->host_pid, ps_info->state);
@@ -1554,6 +1553,8 @@ nsfw_ps_cfg_set_chk_count (u16 count)
g_ps_cfg.ps_chk_hbt_count = count;
}
+#define MAS_PS_INFO_NAME "MAS_PS_INFO"
+
/*****************************************************************************
* Prototype : nsfw_ps_module_init
* Description : ps_module init
@@ -1566,6 +1567,7 @@ nsfw_ps_cfg_set_chk_count (u16 count)
int
nsfw_ps_module_init (void *param)
{
+ size_t length;
u32 proc_type = (u32) ((long long) param);
nsfw_ps_init_cfg *ps_cfg = &g_ps_cfg;
int retval;
@@ -1576,17 +1578,7 @@ nsfw_ps_module_init (void *param)
ps_cfg->ps_chk_hbt_tvalue = NSFW_CHK_HBT_TVLAUE_DEF;
ps_cfg->ps_chk_hbt_soft_count = ps_cfg->ps_chk_hbt_count;
- nsfw_mem_zone pzoneinfo;
- pzoneinfo.isocket_id = NSFW_SOCKET_ANY;
- pzoneinfo.stname.entype = NSFW_SHMEM;
- pzoneinfo.length = sizeof (nsfw_pid_item) * NSFW_MAX_PID;
- if (-1 ==
- SPRINTF_S (pzoneinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- "MAS_PS_INFO"))
- {
- NSFW_LOGERR ("SPRINTF_S failed]");
- return -1;
- }
+ length = sizeof (nsfw_pid_item) * NSFW_MAX_PID;
switch (proc_type)
{
@@ -1611,8 +1603,7 @@ nsfw_ps_module_init (void *param)
g_ps_info = pid_info;
- pzoneinfo.stname.enowner = NSFW_PROC_MAIN;
- pid_info = nsfw_mem_zone_create (&pzoneinfo);
+ pid_info = dmm_locked_map (length, MAS_PS_INFO_NAME);
if (NULL == pid_info)
{
NSFW_LOGERR ("create pid_info failed!");
@@ -1632,30 +1623,17 @@ nsfw_ps_module_init (void *param)
INIT_LIST_HEAD (&(g_ps_runing_list));
- nsfw_mem_sppool pmpinfo;
- pmpinfo.enmptype = NSFW_MRING_MPMC;
- pmpinfo.usnum = ps_cfg->ps_info_size;
- pmpinfo.useltsize = sizeof (nsfw_ps_info);
- pmpinfo.isocket_id = NSFW_SOCKET_ANY;
- pmpinfo.stname.entype = NSFW_NSHMEM;
- if (-1 ==
- SPRINTF_S (pmpinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- "MAS_PS_INFOPOOL"))
- {
- NSFW_LOGERR ("SPRINTF_S failed]");
- return -1;
- }
-
- ps_cfg->ps_info_pool = nsfw_mem_sp_create (&pmpinfo);
-
+ ps_cfg->ps_info_pool = dmm_malloc_pool (sizeof (nsfw_ps_info),
+ ps_cfg->ps_info_size,
+ DMM_RING_INIT_MPMC);
if (!ps_cfg->ps_info_pool)
{
NSFW_LOGERR ("alloc ps info pool_err");
return -1;
}
- MEM_STAT (NSFW_PS_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
- nsfw_mem_get_len (ps_cfg->ps_info_pool, NSFW_MEM_SPOOL));
+// MEM_STAT (NSFW_PS_MODULE, pmpinfo.stname.aname, NSFW_NSHMEM,
+// nsfw_mem_get_len (ps_cfg->ps_info_pool, NSFW_MEM_SPOOL));
if (NSFW_PROC_MAIN != proc_type)
{
@@ -1677,7 +1655,7 @@ nsfw_ps_module_init (void *param)
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSFW_PS_MODULE)
-NSFW_MODULE_PRIORITY (10)
+NSFW_MODULE_PRIORITY (40)
NSFW_MODULE_DEPENDS (NSFW_MGR_COM_MODULE)
NSFW_MODULE_DEPENDS (NSFW_TIMER_MODULE)
NSFW_MODULE_INIT (nsfw_ps_module_init)
diff --git a/src/framework/ipc/ps/nsfw_ps_module.h b/src/framework/ipc/ps/nsfw_ps_module.h
index b754cea..c09644d 100644
--- a/src/framework/ipc/ps/nsfw_ps_module.h
+++ b/src/framework/ipc/ps/nsfw_ps_module.h
@@ -18,7 +18,7 @@
#define _NSFW_PS_MODULE_H
#include "nsfw_ps_api.h"
-#include "nsfw_mem_api.h"
+#include "dmm_ring.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -33,7 +33,7 @@ extern "C"{
#define NSFW_MAX_PID 65535
COMPAT_PROTECT (NSFW_MAX_PID, 65535);
-#define NSFW_PS_INFO_MAX_COUNT 4095
+#define NSFW_PS_INFO_MAX_COUNT 4096
#define MAX_NET_LINK_BUF_DEF 0x34000*32
#define NSFW_PS_WEXIT_TIMER 1
@@ -52,7 +52,7 @@ typedef struct _nsfw_ps_init_cfg
u16 ps_chk_hbt_soft_count;
u16 ps_chk_hbt_tvalue;
- mring_handle ps_info_pool;
+ struct dmm_ring *ps_info_pool;
} nsfw_ps_init_cfg;
#define NSFW_PS_CHK_TIMER 1
diff --git a/src/framework/ipc/ps/nsfw_recycle_module.c b/src/framework/ipc/ps/nsfw_recycle_module.c
index 01e16fb..c561b7c 100644
--- a/src/framework/ipc/ps/nsfw_recycle_module.c
+++ b/src/framework/ipc/ps/nsfw_recycle_module.c
@@ -20,14 +20,14 @@
#include "nsfw_init.h"
#include "nsfw_mgr_com_api.h"
-#include "nsfw_mem_api.h"
#include "nsfw_ps_api.h"
-#include "nsfw_ps_mem_api.h"
#include "nsfw_fd_timer_api.h"
#include "nsfw_recycle_module.h"
#include "nsfw_maintain_api.h"
#include "nstack_log.h"
-#include "common_mem_api.h"
+
+#include "dmm_memory.h"
+#include "dmm_sys.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -432,22 +432,13 @@ nsfw_recycle_obj_timeout (u32 timer_type, void *data)
u8
mem_rec_zone_init ()
{
- nsfw_mem_mring pringinfo;
- pringinfo.enmptype = NSFW_MRING_MPMC;
- pringinfo.isocket_id = NSFW_SOCKET_ANY;
- pringinfo.stname.entype = NSFW_NSHMEM;
- pringinfo.usnum = MEM_RECYCLE_PER_PRO_QUE;
+ size_t length;
u32 i;
+
for (i = 0; i < NSFW_REC_PRO_MAX; i++)
{
- if (-1 ==
- SPRINTF_S (pringinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s%d",
- MEM_REC_QUEUE_NAME, i))
- {
- NSFW_LOGERR ("SPRINTF_S failed]");
- return FALSE;
- }
- g_rec_cfg.mem_rec_pro[i] = nsfw_mem_ring_create (&pringinfo);
+ g_rec_cfg.mem_rec_pro[i] = dmm_malloc_ring (MEM_RECYCLE_PER_PRO_QUE,
+ DMM_RING_INIT_MPMC);
if (NULL == g_rec_cfg.mem_rec_pro[i])
{
NSFW_LOGERR ("alloc rec ring nul!");
@@ -455,66 +446,36 @@ mem_rec_zone_init ()
}
}
- MEM_STAT (NSFW_RECYCLE_MODULE, MEM_REC_QUEUE_NAME, NSFW_NSHMEM,
- NSFW_REC_PRO_MAX * nsfw_mem_get_len (g_rec_cfg.mem_rec_pro[0],
- NSFW_MEM_RING));
-
- nsfw_mem_zone pzoneinfo;
- pzoneinfo.isocket_id = NSFW_SOCKET_ANY;
- pzoneinfo.stname.entype = NSFW_NSHMEM;
- pzoneinfo.length =
- MEM_RECYCLE_OBJ_MAX_NUM * sizeof (nsfw_recycle_obj) +
- sizeof (nsfw_recycle_pool);
- if (-1 ==
- SPRINTF_S (pzoneinfo.stname.aname, NSFW_MEM_NAME_LENGTH, "%s",
- MEM_REC_POOL_NAME))
- {
- NSFW_LOGERR ("SPRINTF_S failed]");
- return FALSE;
- }
+// MEM_STAT (NSFW_RECYCLE_MODULE, MEM_REC_QUEUE_NAME, NSFW_NSHMEM,
+// NSFW_REC_PRO_MAX * nsfw_mem_get_len (g_rec_cfg.mem_rec_pro[0],
+// NSFW_MEM_RING));
- g_rec_cfg.mem_rec_obj_pool = nsfw_mem_zone_create (&pzoneinfo);
+ length = sizeof (nsfw_recycle_pool)
+ + MEM_RECYCLE_OBJ_MAX_NUM * sizeof (nsfw_recycle_obj);
+ g_rec_cfg.mem_rec_obj_pool = calloc (1, length);
if (NULL == g_rec_cfg.mem_rec_obj_pool)
{
NSFW_LOGERR ("alloc rec pool nul!");
return FALSE;
}
- MEM_STAT (NSFW_RECYCLE_MODULE, MEM_REC_POOL_NAME, NSFW_NSHMEM,
- pzoneinfo.length);
+// MEM_STAT (NSFW_RECYCLE_MODULE, MEM_REC_POOL_NAME, NSFW_NSHMEM,
+// pzoneinfo.length);
- int retval;
- retval =
- MEMSET_S (g_rec_cfg.mem_rec_obj_pool, pzoneinfo.length, 0,
- pzoneinfo.length);
- if (EOK != retval)
- {
- NSFW_LOGERR ("mem set init failed!");
- return FALSE;
- }
-
- i32 j;
- nsfw_recycle_pool *rec_pool =
- (nsfw_recycle_pool *) g_rec_cfg.mem_rec_obj_pool;
+ nsfw_recycle_pool *rec_pool = g_rec_cfg.mem_rec_obj_pool;
rec_pool->pool_size = MEM_RECYCLE_OBJ_MAX_NUM;
nsfw_recycle_obj *p_start = rec_pool->obj;
for (i = 0; i < NSFW_REC_PRO_MAX; i++)
{
- for (j = 0; j < MEM_RECYCLE_PER_PRO_QUE; j++)
+ int ret = dmm_array_enqueue (g_rec_cfg.mem_rec_pro[i], p_start,
+ MEM_RECYCLE_PER_PRO_QUE,
+ sizeof (nsfw_recycle_obj));
+ if (ret != MEM_RECYCLE_PER_PRO_QUE)
{
- if (FALSE == p_start[j].alloc_flag)
- {
- if (0 ==
- nsfw_mem_ring_enqueue (g_rec_cfg.mem_rec_pro[i],
- &p_start[j]))
- {
- NSFW_LOGERR ("enqueue failed");
- break;
- }
- }
+ NSFW_LOGERR ("enqueue failed");
}
- p_start = p_start + MEM_RECYCLE_PER_PRO_QUE;
+ p_start += MEM_RECYCLE_PER_PRO_QUE;
}
NSFW_LOGINF ("init rec pool and ring suc!");
@@ -543,8 +504,7 @@ nsfw_recycle_reg_obj (u8 priority, u16 rec_type, void *data)
}
nsfw_recycle_obj *obj = NULL;
- if (0 ==
- nsfw_mem_ring_dequeue (g_rec_cfg.mem_rec_pro[priority], (void *) &obj))
+ if (1 != dmm_dequeue (g_rec_cfg.mem_rec_pro[priority], (void **) &obj))
{
NSFW_LOGERR ("dequeue error]priority=%d,rec_type=%d,data=%p",
priority, rec_type, data);
@@ -553,7 +513,7 @@ nsfw_recycle_reg_obj (u8 priority, u16 rec_type, void *data)
if (EOK != MEMSET_S (obj, sizeof (*obj), 0, sizeof (*obj)))
{
- if (0 == nsfw_mem_ring_enqueue (g_rec_cfg.mem_rec_pro[priority], obj))
+ if (1 != dmm_enqueue (g_rec_cfg.mem_rec_pro[priority], obj))
{
NSFW_LOGERR ("enqueue error]priority=%d,rec_type=%d,data=%p",
priority, rec_type, data);
@@ -651,8 +611,9 @@ nsfw_recycle_fork_init ()
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSFW_RECYCLE_MODULE)
-NSFW_MODULE_PRIORITY (10)
-NSFW_MODULE_DEPENDS (NSFW_PS_MEM_MODULE)
+NSFW_MODULE_PRIORITY (60)
+NSFW_MODULE_DEPENDS (DMM_MEMORY_MODULE)
+NSFW_MODULE_DEPENDS (NSFW_PS_MODULE)
NSFW_MODULE_INIT (nsfw_recycle_module_init)
/* *INDENT-ON* */
diff --git a/src/framework/ipc/ps/nsfw_recycle_module.h b/src/framework/ipc/ps/nsfw_recycle_module.h
index 694c1d2..73f9317 100644
--- a/src/framework/ipc/ps/nsfw_recycle_module.h
+++ b/src/framework/ipc/ps/nsfw_recycle_module.h
@@ -18,6 +18,7 @@
#define _NSFW_RECYCLE_MODULE_H
#include "nsfw_recycle_api.h"
+#include "dmm_ring.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -45,7 +46,6 @@ typedef struct _nsfw_recycle_obj
u16 rec_type;
u32 host_pid;
void *data;
- u64 u64reserve;
} nsfw_recycle_obj;
#define NSFW_REC_LOCK_REL_MAX_FUN 32
@@ -66,8 +66,8 @@ typedef struct _nsfw_recycle_pool
typedef struct _nsfw_recycle_cfg
{
u16 rec_waite_end_tvalue;
- mring_handle mem_rec_obj_pool;
- mzone_handle mem_rec_pro[NSFW_REC_PRO_MAX];
+ nsfw_recycle_pool *mem_rec_obj_pool;
+ struct dmm_ring *mem_rec_pro[NSFW_REC_PRO_MAX];
} nsfw_recycle_cfg;
extern nsfw_rcc_stat nsfw_recycle_callback_all_obj (u32 pid,
diff --git a/src/framework/ipc/ps/nsfw_soft_param.c b/src/framework/ipc/ps/nsfw_soft_param.c
index 743276f..6294acc 100644
--- a/src/framework/ipc/ps/nsfw_soft_param.c
+++ b/src/framework/ipc/ps/nsfw_soft_param.c
@@ -26,8 +26,6 @@
#include "nstack_log.h"
#include "nsfw_maintain_api.h"
-#include "nsfw_mem_api.h"
-
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
@@ -286,7 +284,7 @@ nsfw_softparam_module_init (void *param)
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSFW_SOFT_PARAM_MODULE)
-NSFW_MODULE_PRIORITY (99)
+NSFW_MODULE_PRIORITY (50)
NSFW_MODULE_INIT (nsfw_softparam_module_init)
/* *INDENT-ON* */
diff --git a/src/framework/lib_common_mem/common_buf.c b/src/framework/lib_common_mem/common_buf.c
deleted file mode 100644
index 9d9a127..0000000
--- a/src/framework/lib_common_mem/common_buf.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/queue.h>
-
-#include "common_mem_base_type.h"
-
-#include "common_mem_common.h"
-
-#include "common_mem_memzone.h"
-
-#include "common_mem_pal.h"
-
-#include "common_mem_mempool.h"
-#include "common_mem_buf.h"
-
-#include "nstack_log.h"
-#include "nstack_securec.h"
-
-#include "common_func.h"
-#include "common_pal_bitwide_adjust.h"
-
-#define LOG_ERR 0
-#define LOG_WARN 1
-#define LOG_INFO 2
-#define LOG_DEBUG 3
-#define LOG_MAX 4
-
-#define COMMON_LOG_PRINT(level, fmt, args...) \
- if (level <= log_level) NSCOMM_LOGERR("===>[COMMON]"fmt, ##args); \
-
-#define COMMON_PANIC(fmt) \
- NSCOMM_LOGERR("==>[COMMON_PANIC]"fmt); \
- common_dump_stack(); \
-
-#define PARA1_SET(argv, tempargv, Index, para1) do {\
- retVal = STRCPY_S(tempargv[Index], PATA_STRLENT, para1);\
- if (retVal != EOK)\
- {\
- NSCOMM_LOGERR("STRCPY_S failed]ret=%d", retVal);\
- return DMM_MBUF_RET_ERR;\
- }\
- argv[Index] = tempargv[Index]; \
- Index ++; } while (0)
-
-#define PARA2_SET(argv, tempargv, Index, para1, para2) do {\
- retVal = STRCPY_S(tempargv[Index], PATA_STRLENT, para1); \
- if (retVal != EOK)\
- {\
- NSCOMM_LOGERR("STRCPY_S failed]ret=%d", retVal);\
- return DMM_MBUF_RET_ERR;\
- }\
- argv[Index] = tempargv[Index]; \
- Index++; \
- retVal = STRCPY_S(tempargv[Index], PATA_STRLENT, para2); \
- if (retVal != EOK)\
- {\
- NSCOMM_LOGERR("STRCPY_S failed]ret=%d", retVal);\
- return DMM_MBUF_RET_ERR;\
- }\
- argv[Index] = tempargv[Index]; \
- Index ++; } while (0)
-
-#define PATA_STRLENT 64
-#define PATA_NUM_MAX 12
-
-int log_level = LOG_INFO;
-
-int
-nscomm_pal_module_init (common_mem_pal_module_info * pinfo, u8 app_mode)
-{
- char tempargv[PATA_NUM_MAX][PATA_STRLENT];
- char *argv[PATA_NUM_MAX];
- char tempbuf[PATA_STRLENT];
- unsigned int Index = 0;
- int ioffset = 0;
- int agindex = 0;
- int intmask = 0;
- int retVal;
- char name[10] = { '\0' };
-
- retVal = MEMSET_S (tempargv, sizeof (tempargv), '\0', sizeof (tempargv));
- if (EOK != retVal)
- {
- NSCOMM_LOGERR ("MEMSET_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- retVal = MEMSET_S (argv, sizeof (argv), 0, sizeof (argv));
- if (EOK != retVal)
- {
- NSCOMM_LOGERR ("MEMSET_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- if (NULL == pinfo)
- {
- PARA1_SET (argv, tempargv, agindex, "nStackMain");
- PARA2_SET (argv, tempargv, agindex, "-c", "0x1");
- PARA2_SET (argv, tempargv, agindex, "-n", "4");
- PARA1_SET (argv, tempargv, agindex, "--huge-dir=/mnt/nstackhuge");
- PARA1_SET (argv, tempargv, agindex, "--proc-type=primary");
-
- if (app_mode == 1)
- {
- sprintf (name, "dmm_app_%ld", (long) getpid ());
- PARA2_SET (argv, tempargv, agindex, "--file-prefix", name);
- PARA1_SET (argv, tempargv, agindex, "--no-pci");
-
- // TODO: the size of the memory should not be fixed
- PARA2_SET (argv, tempargv, agindex, "-m", "32");
- }
- else
- {
- // TODO: replay the name 'nStackMain'
- /* snprintf(name, 10, "dmm_main_%ld", (long) getpid()); */
- PARA2_SET (argv, tempargv, agindex, "--file-prefix", "nStackMain");
- PARA2_SET (argv, tempargv, agindex, "-m", "2048");
- }
-
- }
- else
- {
- PARA1_SET (argv, tempargv, agindex, "nStackMain");
- PARA2_SET (argv, tempargv, agindex, "--file-prefix", "nStackMain");
-
- retVal = SPRINTF_S (tempbuf, PATA_STRLENT, "0x");
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", ioffset);
- return DMM_MBUF_RET_ERR;
- }
- ioffset = retVal;
- for (Index = 0; Index < LCORE_MASK_MAX; Index++)
- {
- if (ioffset >= PATA_STRLENT)
- {
- NSCOMM_LOGERR ("SPRINTF_S tempbuf overflow]ioffset=%d",
- ioffset);
- return DMM_MBUF_RET_ERR;
- }
- retVal =
- SPRINTF_S (&(tempbuf[ioffset]), PATA_STRLENT - ioffset, "%8u",
- pinfo->ilcoremask[Index]);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", ioffset);
- return DMM_MBUF_RET_ERR;
- }
- ioffset = ioffset + retVal;
- intmask |= pinfo->ilcoremask[Index];
- }
- if (0 == intmask)
- {
- PARA2_SET (argv, tempargv, agindex, "-c", "0x1");
- }
- else
- {
- PARA2_SET (argv, tempargv, agindex, "-c", tempbuf);
- }
- if (pinfo->ishare_mem_size > 0)
- {
- retVal = MEMSET_S (tempbuf, PATA_STRLENT, 0, PATA_NUM_MAX);
- if (EOK != retVal)
- {
- NSCOMM_LOGERR ("MEMSET_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- retVal =
- SPRINTF_S (tempbuf, PATA_STRLENT, "%d", pinfo->ishare_mem_size);
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- PARA2_SET (argv, tempargv, agindex, "-m", tempbuf);
- }
-
- retVal = MEMSET_S (tempbuf, PATA_STRLENT, 0, PATA_NUM_MAX);
- if (EOK != retVal)
- {
- NSCOMM_LOGERR ("MEMSET_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
-
- switch (pinfo->ucproctype)
- {
- case DMM_PROC_T_PRIMARY:
- retVal = SPRINTF_S (tempbuf, PATA_STRLENT, "--proc-type=primary");
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- break;
- case DMM_PROC_T_SECONDARY:
- retVal = SPRINTF_S (tempbuf, PATA_STRLENT, "--proc-type=secondary");
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- break;
- case DMM_PROC_T_AUTO:
- default:
- retVal = SPRINTF_S (tempbuf, PATA_STRLENT, "--proc-type=auto");
- if (-1 == retVal)
- {
- NSCOMM_LOGERR ("SPRINTF_S failed]ret=%d", retVal);
- return DMM_MBUF_RET_ERR;
- }
- break;
- }
- PARA1_SET (argv, tempargv, agindex, tempbuf);
-
- if (DMM_HUGTBL_DISABLE == pinfo->uchugeflag)
- {
- PARA1_SET (argv, tempargv, agindex, "--no-huge");
- }
- }
- if (common_mem_pal_init (agindex, argv) < 0)
- {
- COMMON_LOG_PRINT (LOG_ERR, "Cannot init pal\r\n");
- return DMM_MBUF_RET_ERR;
- }
- return DMM_MBUF_RET_OK;
-}
-
-void *
-nscomm_memzone_data_reserve_name (const char *name, size_t len, int socket_id)
-{
- const struct common_mem_memzone *mz = NULL;
- /*
- rte_memzone_reserve must Call first, cause rte_memzone_reserve has a globe lock.
- while proc race happen, who(calls A) got lock first will create memzone success.
- others create same memzone proc will got lock after A, and rte_memzone_reserve return NULL;
- so while rte_memzone_reserve return NULL we need do rte_memzone_lookup;
- */
- mz = common_mem_memzone_reserve (name, len, socket_id, 0);
- if (mz == NULL)
- {
- mz = common_mem_memzone_lookup (name);
- }
-
- return mz ? (void *) ADDR_SHTOL (mz->addr_64) : NULL;
-}
-
-void *
-nscomm_memzone_data_lookup_name (const char *name)
-{
- void *addr = NULL;
- const struct common_mem_memzone *mz = NULL;
- mz = common_mem_memzone_lookup (name);
- if (mz == NULL)
- {
- return NULL;
- }
- addr = (void *) ADDR_SHTOL (mz->addr_64);
- return addr;
-}
diff --git a/src/framework/lib_common_mem/common_func.c b/src/framework/lib_common_mem/common_func.c
deleted file mode 100644
index 5220374..0000000
--- a/src/framework/lib_common_mem/common_func.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include "common_mem_pal_memconfig.h"
-#include "common_mem_mbuf.h"
-#include "common_mem_common.h"
-#include "nstack_log.h"
-#include "common_pal_bitwide_adjust.h"
-
-#include "common_func.h"
-
-#include "nstack_securec.h"
-
-#define COMMON_PROCESS_MAPS "/proc/self/maps"
-
-int g_PrimSameFlg = 1;
-
-NSTACK_STATIC void **g_PrimAddr2LocalMap = NULL;
-NSTACK_STATIC void *g_LocalBaseAddr = NULL;
-NSTACK_STATIC void *g_LocalMaxAddr = NULL;
-NSTACK_STATIC void *g_LocalCfgAddrBase = NULL;
-
-NSTACK_STATIC uint64_t *g_LocalAddr2PrimMap = NULL;
-NSTACK_STATIC uint64_t g_PrimBaseAddr = 0;
-NSTACK_STATIC uint64_t g_PrimMaxAddr = 0;
-NSTACK_STATIC uint64_t g_PrimCfgAddrBase = 0;
-
-NSTACK_STATIC uint64_t g_LBitMask = 0;
-NSTACK_STATIC int g_LBitMaskLen = 0;
-
-uint64_t
-pal_laddr_to_shddr (void *LAddr)
-{
- size_t l2pIdx;
-
- if (g_PrimSameFlg || LAddr == NULL)
- {
- return (uint64_t) LAddr;
- }
-
- /*calculate the IDX */
- l2pIdx = (ALIGN_PTR (LAddr) - ALIGN_PTR (g_LocalBaseAddr)) >> g_LBitMaskLen;
-
- /*check the Hugepage Addr Rang */
- if (LAddr <= g_LocalMaxAddr && LAddr >= g_LocalBaseAddr
- && g_LocalAddr2PrimMap[l2pIdx])
- {
- return g_LocalAddr2PrimMap[l2pIdx] + (ALIGN_PTR (LAddr) & g_LBitMask);
- }
-
- /*check the Cfg Mapping Addr Rang */
- if (LAddr >= g_LocalCfgAddrBase
- && LAddr <=
- (void *) ((char *) g_LocalCfgAddrBase +
- sizeof (struct common_mem_mem_config)))
- {
- return g_PrimCfgAddrBase + ((char *) LAddr -
- (char *) g_LocalCfgAddrBase);
- }
-
- NSCOMM_LOGWAR
- ("WARNING!!! Input invalid LAddr]LAddr=%p, g_LocalBaseAddr=%p, g_LocalMaxAddr=%p, g_LocalCfgAddrBase=%p, g_LocalCfgAddrMax=%p.",
- LAddr, g_LocalBaseAddr, g_LocalMaxAddr, g_LocalCfgAddrBase,
- (char *) g_LocalCfgAddrBase + sizeof (struct common_mem_mem_config));
-
- return (uint64_t) LAddr;
-}
-
-void *
-pal_shddr_to_laddr (uint64_t PAddr)
-{
- size_t p2lIdx;
-
- if (g_PrimSameFlg || PAddr == ALIGN_PTR (NULL))
- {
- return (void *) PAddr;
- }
-
- p2lIdx = (PAddr - g_PrimBaseAddr) >> g_LBitMaskLen;
- /*check the Hugepage Addr Rang */
- if (PAddr <= g_PrimMaxAddr && PAddr >= g_PrimBaseAddr
- && g_PrimAddr2LocalMap[p2lIdx])
- {
- return (void *) ((uint64_t) g_PrimAddr2LocalMap[p2lIdx] +
- (PAddr & g_LBitMask));
- }
-
- /*check the Cfg Mapping Addr Rang */
- if (PAddr >= g_PrimCfgAddrBase
- && PAddr <= g_PrimCfgAddrBase + sizeof (struct common_mem_mem_config))
- {
- return (void *) ((uint64_t) g_LocalCfgAddrBase + PAddr -
- g_PrimCfgAddrBase);
- }
-
- NSCOMM_LOGWAR
- ("WARNING!!! Input invalid PAddr]PAddr=%lx, g_PrimBaseAddr=%lx, g_PrimMaxAddr=%lx, g_PrimCfgAddrBase=%lx, g_PrimCfgAddrMax=%lx.",
- PAddr, g_PrimBaseAddr, g_PrimMaxAddr, g_PrimCfgAddrBase,
- g_PrimCfgAddrBase + sizeof (struct common_mem_mem_config));
-
- return (void *) PAddr;
-}
-
-/*lint +e539 */
-
-int
-dmm_pal_addr_align ()
-{
- return g_PrimSameFlg;
-}
-
-int32_t
-dmm_pktmbuf_pool_iterator (struct common_mem_mempool * mp, uint32_t start,
- uint32_t end, dmm_mbuf_item_fun fun, void *argv)
-{
- if (NULL == mp || fun == NULL)
- {
- return 0;
- }
-
- if (start >= mp->size || end <= start)
- {
- return 0;
- }
-
- int32_t elm_size = mp->elt_size + mp->header_size + mp->trailer_size;
- struct common_mem_mbuf *elm_mbuf = (struct common_mem_mbuf *) (STAILQ_FIRST (&mp->mem_list)->addr + start * elm_size + mp->header_size); /*lint !e647 */
-
- uint32_t i;
- uint32_t mbuf_end = COMMON_MEM_MIN (end, mp->size) - start;
- for (i = 0; i < mbuf_end; i++)
- {
- (void) fun (elm_mbuf, argv);
- elm_mbuf = (struct common_mem_mbuf *) ((char *) elm_mbuf + elm_size);
- }
-
- return mbuf_end;
-}
-
-void
-dmm_addr_print (void)
-{
- const struct common_mem_mem_config *mcfg =
- common_mem_pal_get_configuration ()->mem_config;
- int s;
- FILE *fd;
- char *ptembuf = NULL;
- if (!mcfg)
- {
- NSCOMM_LOGERR ("mcfg is null");
- return;
- }
- /*printf base address */
- NSCOMM_LOGINF ("********master baseaddr begin***************");
- for (s = 0; s < COMMON_MEM_MAX_MEMSEG; ++s)
- {
- if ((mcfg->memseg[s].len > 0) && (mcfg->memseg[s].addr != 0))
- {
- NSCOMM_LOGINF ("addr:%p, len:%u", mcfg->memseg[s].addr,
- mcfg->memseg[s].len);
- }
- }
- NSCOMM_LOGINF ("********master baseaddr end***************");
-
- fd = fopen (COMMON_PROCESS_MAPS, "r");
- if (!fd)
- {
- NSCOMM_LOGERR ("/proc/self/maps open fail, erro:%d", errno);
- return;
- }
-
- ptembuf = (char *) malloc (BUFSIZ);
- if (!ptembuf)
- {
- NSCOMM_LOGERR ("malloc buff failed]buff_len=%d", BUFSIZ);
- fclose (fd);
- return;
- }
- if (EOK != MEMSET_S (ptembuf, BUFSIZ, 0, BUFSIZ))
- {
- NSCOMM_LOGERR ("MEMSET_S failed] buff=%p", ptembuf);
- }
- NSCOMM_LOGINF ("********self process addr space begin***************");
- while (fgets (ptembuf, BUFSIZ, fd) != NULL)
- {
- NSCOMM_LOGERR ("%s", ptembuf);
- }
- NSCOMM_LOGINF ("********self process addr space end*****************");
- fclose (fd);
- free (ptembuf);
- return;
-}
diff --git a/src/framework/log/nsfw_set_log.c b/src/framework/log/nsfw_set_log.c
index 31241b5..04501a9 100644
--- a/src/framework/log/nsfw_set_log.c
+++ b/src/framework/log/nsfw_set_log.c
@@ -21,7 +21,6 @@
#include "nstack_log.h"
#include "nsfw_maintain_api.h"
-#include "nsfw_mem_api.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -216,7 +215,7 @@ nsfw_cfg_module_init (void *param)
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSFW_LOG_CFG_MODULE)
-NSFW_MODULE_PRIORITY (99)
+NSFW_MODULE_PRIORITY (50)
NSFW_MODULE_INIT (nsfw_cfg_module_init)
/* *INDENT-ON* */
diff --git a/src/framework/mem/dmm_fshm.c b/src/framework/mem/dmm_fshm.c
index 605c728..a037318 100644
--- a/src/framework/mem/dmm_fshm.c
+++ b/src/framework/mem/dmm_fshm.c
@@ -19,6 +19,10 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
+#include <errno.h>
+
+#include "nstack_log.h"
+#include "nsfw_base_linux_api.h"
#include "dmm_config.h"
#include "dmm_share.h"
@@ -27,10 +31,11 @@
#define DMM_FSHM_FMT "%s/dmm-fshm-%d" /* VAR_DIR pid */
inline static void
-set_fshm_path (struct dmm_share *share)
+set_fshm_path (char path[DMM_SHARE_PATH_MAX], pid_t pid)
{
- (void) snprintf (share->path, sizeof (share->path), DMM_FSHM_FMT,
- DMM_VAR_DIR, share->pid);
+ (void) snprintf (path, DMM_SHARE_PATH_MAX, DMM_FSHM_FMT, DMM_VAR_DIR, pid);
+
+ path[DMM_SHARE_PATH_MAX - 1] = 0;
}
/*
@@ -41,34 +46,58 @@ int
dmm_fshm_create (struct dmm_share *share)
{
int fd, ret;
- void *base;
+ void *base, *hint = (void *) DMM_MAIN_SHARE_BASE;
+
+ if (share->type != DMM_SHARE_FSHM)
+ {
+ NSFW_LOGERR ("type error, type:%d", share->type);
+ return -1;
+ }
- set_fshm_path (share);
+ set_fshm_path (share->path, share->pid);
+
+ NSFW_LOGINF ("Start create share memory, path:'%s' size:%lu",
+ share->path, share->size);
fd = open (share->path, O_RDWR | O_CREAT, 0666);
if (fd < 0)
{
+ NSFW_LOGERR ("Open file failed, path:'%s', errno=%d",
+ share->path, errno);
return -1;
}
ret = ftruncate (fd, share->size);
if (ret < 0)
{
- (void) close (fd);
+ NSFW_LOGERR ("Set file size failed, path:'%s', errno=%d",
+ share->path, errno);
+ (void) nsfw_base_close (fd);
return -1;
}
- base = mmap (NULL, share->size,
- PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0);
+ base = mmap (hint, share->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (base == MAP_FAILED)
{
- (void) close (fd);
+ NSFW_LOGERR ("Map failed, path:'%s' size:%lu, errno=%d",
+ share->path, share->size, errno);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+ else if (hint && hint != MAP_FAILED && base != hint)
+ {
+ NSFW_LOGERR ("Map address failed, path:'%s' hint:%p size:%lu, base:%p",
+ share->path, hint, share->size, base);
+ (void) munmap (base, share->size);
+ (void) nsfw_base_close (fd);
return -1;
}
share->base = base;
- (void) close (fd);
+ NSFW_LOGINF ("Share memory created, size:%lu, base=%p", share->size, base);
+
+ (void) nsfw_base_close (fd);
return 0;
}
@@ -91,14 +120,22 @@ dmm_fshm_attach (struct dmm_share *share)
int fd;
void *base;
+ NSFW_LOGINF ("Start attach, share:%p"
+ " {type:%d pid:%d base:%p size:%lu path:'%s'}",
+ share, share->type, share->pid,
+ share->base, share->size, share->path);
+
if (share->type != DMM_SHARE_FSHM)
{
+ NSFW_LOGERR ("type error, type:%d", share->type);
return -1;
}
fd = open (share->path, O_RDWR);
if (fd < 0)
{
+ NSFW_LOGERR ("Open file failed, path:'%s', errno=%d",
+ share->path, errno);
return -1;
}
@@ -107,16 +144,19 @@ dmm_fshm_attach (struct dmm_share *share)
share->size = dmm_file_size (fd);
if (share->size == 0)
{
- (void) close (fd);
+ NSFW_LOGERR ("No file size '%s'", share->path);
+ (void) nsfw_base_close (fd);
return -1;
}
}
- base = mmap (share->base, share->size,
- PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0);
+ base = mmap (share->base, share->size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
if (base == MAP_FAILED)
{
- (void) close (fd);
+ NSFW_LOGERR ("Map failed, path:'%s' base:%p size:%lu, errno=%d",
+ share->path, share->base, share->size, errno);
+ (void) nsfw_base_close (fd);
return -1;
}
@@ -126,12 +166,16 @@ dmm_fshm_attach (struct dmm_share *share)
}
else if (base != share->base)
{
+ NSFW_LOGERR ("Map address error, path:'%s' share->base:%p, base:%p",
+ share->path, share->base, base);
(void) munmap (base, share->size);
- (void) close (fd);
+ (void) nsfw_base_close (fd);
return -1;
}
- (void) close (fd);
+ NSFW_LOGINF ("Memory attached, base=%p", base);
+
+ (void) nsfw_base_close (fd);
return 0;
}
diff --git a/src/framework/mem/dmm_group.c b/src/framework/mem/dmm_group.c
index 35e6100..1eedd4d 100644
--- a/src/framework/mem/dmm_group.c
+++ b/src/framework/mem/dmm_group.c
@@ -15,6 +15,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
@@ -22,7 +23,8 @@
#include <fcntl.h>
#include <sys/mman.h>
-//#include "dmm_memory.h"
+#include "nsfw_base_linux_api.h"
+#include "nstack_log.h"
#include "dmm_config.h"
#include "dmm_group.h"
#include "dmm_pause.h"
@@ -66,6 +68,7 @@ void
dmm_group_active ()
{
main_group->group_init = DMM_GROUP_ACTIVE;
+ NSFW_LOGINF ("main group actived");
}
int
@@ -74,16 +77,21 @@ dmm_group_create_main ()
int ret;
const char *path = get_group_path ();
+ NSFW_LOGINF ("start create main group '%s'", path);
+
group_fd = open (path, O_RDWR | O_CREAT, 0664);
if (group_fd < 0)
{
+ NSFW_LOGERR ("open file failed, path:'%s', errno=%d", path, errno);
return -1;
}
ret = ftruncate (group_fd, sizeof (struct dmm_group));
if (ret < 0)
{
- (void) close (group_fd);
+ NSFW_LOGERR ("set size failed, path:'%s' size:%lu, errno=%d",
+ path, sizeof (struct dmm_group), errno);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
return -1;
}
@@ -91,7 +99,8 @@ dmm_group_create_main ()
ret = fcntl (group_fd, F_SETLK, &group_lock);
if (ret < 0)
{
- (void) close (group_fd);
+ NSFW_LOGERR ("lock file failed, path:'%s', errno=%d", path, errno);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
return -1;
}
@@ -102,11 +111,16 @@ dmm_group_create_main ()
if (main_group == MAP_FAILED)
{
- (void) close (group_fd);
+ NSFW_LOGERR ("mmap failed, path:'%s' size:%lu, errno:%d",
+ path, sizeof (struct dmm_group), errno);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
return -1;
}
+ NSFW_LOGINF ("main group created, main_group:%p size:%lu",
+ main_group, sizeof (struct dmm_group));
+
return 0;
}
@@ -121,7 +135,7 @@ dmm_group_delete_main ()
if (group_fd >= 0)
{
- (void) close (group_fd);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
}
@@ -135,17 +149,22 @@ dmm_group_attach_main ()
{
const char *path = get_group_path ();
+ NSFW_LOGINF ("Start attach main group '%s'", path);
+
group_fd = open (path, O_RDONLY);
if (group_fd < 0)
{
+ NSFW_LOGERR ("open group file failed, path:'%s', errno=%d",
+ path, errno);
return -1;
}
- main_group = (struct dmm_group *) mmap (NULL, sizeof (struct dmm_group *),
+ main_group = (struct dmm_group *) mmap (NULL, sizeof (struct dmm_group),
PROT_READ, MAP_SHARED, group_fd, 0);
if (main_group == MAP_FAILED)
{
- (void) close (group_fd);
+ NSFW_LOGERR ("mmap failed, path:'%s', errno=%d", path, errno);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
return -1;
}
@@ -157,12 +176,21 @@ dmm_group_attach_main ()
if (kill (main_group->share.pid, 0))
{
+ NSFW_LOGERR ("main group process not exist, path:'%s' pid:%d errno=%d",
+ path, main_group->share.pid, errno);
(void) munmap (main_group->share.base, main_group->share.size);
- (void) close (group_fd);
+ (void) nsfw_base_close (group_fd);
+ (void) unlink (path);
group_fd = -1;
return -1;
}
+ NSFW_LOGINF ("main group attached, main_group=%p"
+ " {type=%d pid=%d base=%p size=%ld path='%s'}",
+ main_group, main_group->share.type, main_group->share.pid,
+ main_group->share.base, main_group->share.size,
+ main_group->share.path);
+
return 0;
}
@@ -177,7 +205,7 @@ dmm_group_detach_main ()
if (group_fd >= 0)
{
- (void) close (group_fd);
+ (void) nsfw_base_close (group_fd);
group_fd = -1;
}
diff --git a/src/framework/mem/dmm_huge.c b/src/framework/mem/dmm_huge.c
index 735c507..6e3fc42 100644
--- a/src/framework/mem/dmm_huge.c
+++ b/src/framework/mem/dmm_huge.c
@@ -15,39 +15,167 @@
*/
#include <stdio.h>
#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+#include "nstack_log.h"
+#include "nsfw_base_linux_api.h"
#include "dmm_config.h"
#include "dmm_share.h"
+#include "dmm_fs.h"
-#define DMM_HUGE_FMT "%s/dmm-%d-%d" /* HUGE_DIR pid index */
+#define DMM_HUGE_FMT "%s/dmm-%d-%d" /* HUGE_DIR/dmm-pid-index */
inline static void
-huge_set_path (struct dmm_share *share, int index)
+huge_set_path (char path[DMM_SHARE_PATH_MAX], pid_t pid, int index)
{
- (void) snprintf (share->path, sizeof (share->path), DMM_HUGE_FMT,
- DMM_HUGE_DIR, share->pid, index);
+ (void) snprintf (path, DMM_SHARE_PATH_MAX, DMM_HUGE_FMT,
+ DMM_HUGE_DIR, pid, index);
+ path[DMM_SHARE_PATH_MAX - 1] = 0;
}
int
dmm_huge_create (struct dmm_share *share)
{
- return -1;
+ int fd, ret;
+ void *base, *hint = (void *) DMM_MAIN_SHARE_BASE;
+
+ if (share->type != DMM_SHARE_HUGE)
+ {
+ NSFW_LOGERR ("Type error, type:%d", share->type);
+ return -1;
+ }
+
+ huge_set_path (share->path, share->pid, 0);
+
+ NSFW_LOGINF ("Start create share memory, path:'%s' size:%lu",
+ share->path, share->size);
+
+ fd = open (share->path, O_RDWR | O_CREAT, 0666);
+ if (fd < 0)
+ {
+ NSFW_LOGERR ("Open file failed, path:'%s', errno=%d",
+ share->path, errno);
+ return -1;
+ }
+
+ ret = ftruncate (fd, share->size);
+ if (ret < 0)
+ {
+ NSFW_LOGERR ("Set file size failed, path:'%s', errno=%d",
+ share->path, errno);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+
+ base = mmap (hint, share->size, PROT_READ | PROT_WRITE,
+ MAP_HUGETLB | MAP_SHARED | MAP_POPULATE, fd, 0);
+ if (base == MAP_FAILED)
+ {
+ NSFW_LOGERR ("Map failed, path:'%s' size:%lu, errno=%d",
+ share->path, share->size, errno);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+ else if (hint && hint != MAP_FAILED && hint != base)
+ {
+ NSFW_LOGERR ("Map address failed, path:'%s' hint:%p size:%lu, base:%p",
+ share->path, hint, share->size, base);
+ (void) munmap (base, share->size);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+
+ share->base = base;
+
+ NSFW_LOGINF ("Share memory created, size:%lu, base=%p", share->size, base);
+
+ (void) nsfw_base_close (fd);
+ return 0;
}
int
dmm_huge_delete (struct dmm_share *share)
{
- return -1;
+ (void) munmap (share->base, share->size);
+ (void) unlink (share->path);
+
+ return 0;
}
int
dmm_huge_attach (struct dmm_share *share)
{
- return -1;
+ int fd;
+ void *base;
+
+ NSFW_LOGINF ("Start attach, share:%p"
+ " {type:%d pid:%d base:%p size:%lu path:'%s'}",
+ share, share->type, share->pid,
+ share->base, share->size, share->path);
+
+ if (share->type != DMM_SHARE_HUGE)
+ {
+ NSFW_LOGERR ("Type error, type:%d", share->type);
+ return -1;
+ }
+
+ fd = open (share->path, O_RDWR);
+ if (fd < 0)
+ {
+ NSFW_LOGERR ("Open file failed, path:'%s', errno=%d",
+ share->path, errno);
+ return -1;
+ }
+
+ if (share->size <= 0)
+ {
+ share->size = dmm_file_size (fd);
+ if (share->size == 0)
+ {
+ NSFW_LOGERR ("No file size '%s'", share->path);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+ }
+
+ base = mmap (share->base, share->size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
+ if (base == MAP_FAILED)
+ {
+ NSFW_LOGERR ("mmap failed, path:'%s' base:%p size:%lu, errno=%d",
+ share->path, share->base, share->size, errno);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+
+ if (NULL == share->base)
+ {
+ share->base = base;
+ }
+ else if (base != share->base)
+ {
+ NSFW_LOGERR ("mmap address error, path:'%s' share->base:%p, base:%p",
+ share->path, share->base, base);
+ (void) munmap (base, share->size);
+ (void) nsfw_base_close (fd);
+ return -1;
+ }
+
+ NSFW_LOGINF ("Memory attached, base=%p", base);
+
+ (void) nsfw_base_close (fd);
+ return 0;
}
int
dmm_huge_detach (struct dmm_share *share)
{
- return -1;
+ (void) munmap (share->base, share->size);
+
+ return 0;
}
diff --git a/src/framework/mem/dmm_memory.c b/src/framework/mem/dmm_memory.c
index 0352432..b768eef 100644
--- a/src/framework/mem/dmm_memory.c
+++ b/src/framework/mem/dmm_memory.c
@@ -15,11 +15,16 @@
*/
#include <sys/types.h>
#include <unistd.h>
+#include <stdlib.h>
#include "dmm_config.h"
#include "dmm_memory.h"
#include "dmm_group.h"
+#include "nsfw_init.h"
+#include "nsfw_mgr_com_api.h"
+#include "nstack_log.h"
+
#define DMM_MEGABYTE (1024 * 1024)
/* shared from main process */
@@ -44,7 +49,8 @@ dmm_mem_main_init ()
main_share = &main_group->share;
main_share->type = DMM_MAIN_SHARE_TYPE;
- main_share->size = DMM_MAIN_SHARE_SIZE * DMM_MEGABYTE;
+ main_share->size = DMM_MAIN_SHARE_SIZE;
+ main_share->size *= DMM_MEGABYTE;
main_share->base = NULL;
main_share->pid = getpid ();
ret = dmm_share_create (main_share);
@@ -59,6 +65,8 @@ dmm_mem_main_init ()
return -1;
}
+ base_seg = main_seg;
+
dmm_group_active ();
return 0;
@@ -83,12 +91,18 @@ dmm_mem_app_init ()
ret = dmm_share_attach (main_share);
if (ret)
{
+ NSFW_LOGERR
+ ("share attach failed, type:%d pid:%d base:%p size:%lu path:%s",
+ main_share->type, main_share->pid, main_share->base,
+ main_share->size, main_share->path);
return -1;
}
main_seg = dmm_seg_attach (main_share->base, main_share->size);
if (!main_seg)
{
+ NSFW_LOGERR ("segment attach failed, base:%p size:%lu",
+ main_share->base, main_share->size);
return -1;
}
@@ -131,3 +145,132 @@ dmm_mem_app_exit ()
return 0;
}
+
+struct dmm_ring *
+dmm_create_ring (int num, int flag, const char name[DMM_MEM_NAME_SIZE])
+{
+ struct dmm_ring *ring;
+ const size_t bufsize = dmm_ring_bufsize (num);
+
+ dmm_lock_map ();
+
+ ring = dmm_map (bufsize, name);
+
+ if (ring)
+ {
+ if (0 != dmm_ring_init (ring, num, flag))
+ {
+ (void) dmm_unmap (ring);
+ ring = NULL;
+ }
+ }
+
+ dmm_unlock_map ();
+
+ return ring;
+}
+
+struct dmm_ring *
+dmm_attach_ring (const char name[DMM_MEM_NAME_SIZE])
+{
+ return (struct dmm_ring *) dmm_lookup (name);
+}
+
+struct dmm_ring *
+dmm_malloc_ring (int num, int flag)
+{
+ const size_t size = dmm_ring_bufsize (num);
+ struct dmm_ring *ring = malloc (size);
+
+ if (!ring)
+ return NULL;
+
+ if (0 != dmm_ring_init (ring, num, flag))
+ {
+ free (ring);
+ return NULL;
+ }
+
+ return ring;
+}
+
+struct dmm_ring *
+dmm_create_pool (size_t elt_size, int num, int flag,
+ const char name[DMM_MEM_NAME_SIZE])
+{
+ struct dmm_ring *pool;
+ const size_t pool_size = dmm_pool_bufsize (num, elt_size);
+
+ dmm_lock_map ();
+
+ pool = dmm_map (pool_size, name);
+
+ if (pool)
+ {
+ if (0 != dmm_pool_init (pool, elt_size, num, flag))
+ {
+ (void) dmm_unmap (pool);
+ pool = NULL;
+ }
+ }
+
+ dmm_unlock_map ();
+
+ return pool;
+}
+
+struct dmm_ring *
+dmm_attach_pool (const char name[DMM_MEM_NAME_SIZE])
+{
+ return (struct dmm_ring *) dmm_lookup (name);
+}
+
+struct dmm_ring *
+dmm_malloc_pool (size_t elt_size, int num, int flag)
+{
+ const size_t size = dmm_pool_bufsize (num, elt_size);
+ struct dmm_ring *pool = malloc (size);
+
+ if (!pool)
+ {
+ return NULL;
+ }
+
+ if (0 != dmm_pool_init (pool, elt_size, num, flag))
+ {
+ free (pool);
+ return NULL;
+ }
+
+ return pool;
+}
+
+int
+dmm_mem_module_init (void *param)
+{
+ int ret;
+ const u32 proc_type = (u32) ((long) param);
+
+ NSFW_LOGINF ("dmm mem module init]type=%u", proc_type);
+
+ switch (proc_type)
+ {
+ case NSFW_PROC_MAIN:
+ ret = dmm_mem_main_init ();
+ break;
+ case NSFW_PROC_NULL:
+ ret = 0;
+ break;
+ default:
+ ret = dmm_mem_app_init ();
+ break;
+ }
+
+ return ret;
+}
+
+/* *INDENT-OFF* */
+NSFW_MODULE_NAME (DMM_MEMORY_MODULE)
+NSFW_MODULE_PRIORITY (10)
+NSFW_MODULE_INIT (dmm_mem_module_init)
+/* *INDENT-ON* */
diff --git a/src/framework/mem/dmm_memory.h b/src/framework/mem/dmm_memory.h
index 2fac118..b304fb8 100644
--- a/src/framework/mem/dmm_memory.h
+++ b/src/framework/mem/dmm_memory.h
@@ -19,16 +19,41 @@
#include <stdarg.h>
#include "dmm_share.h"
#include "dmm_segment.h"
+#include "dmm_ring.h"
-int dmm_mem_main_init ();
-int dmm_mem_main_exit ();
-
-int dmm_mem_app_init ();
-int dmm_mem_app_exit ();
+#define DMM_MEMORY_MODULE "DMM_MEMORY_MODULE"
extern struct dmm_segment *main_seg;
extern struct dmm_segment *base_seg;
+inline static void
+dmm_lock_map ()
+{
+ dmm_seg_lock (base_seg);
+}
+
+inline static void
+dmm_unlock_map ()
+{
+ dmm_seg_unlock (base_seg);
+}
+
+inline static int
+dmm_unmap (void *mem)
+{
+ return dmm_mem_unmap (base_seg, mem);
+}
+
+inline static void *
+dmm_locked_map (size_t size, const char name[DMM_MEM_NAME_SIZE])
+{
+ void *mem;
+ dmm_lock_map ();
+ mem = dmm_mem_map (base_seg, size, name);
+ dmm_unlock_map ();
+ return mem;
+}
+
inline static void *
dmm_map (size_t size, const char name[DMM_MEM_NAME_SIZE])
{
@@ -75,4 +100,24 @@ dmm_lookupv (const char *name_fmt, ...)
return dmm_mem_lookup (base_seg, name);
}
+int dmm_mem_main_init ();
+int dmm_mem_main_exit ();
+int dmm_mem_app_init ();
+int dmm_mem_app_exit ();
+
+struct dmm_ring *dmm_create_ring (int num, int flag,
+ const char name[DMM_MEM_NAME_SIZE]);
+
+struct dmm_ring *dmm_attach_ring (const char name[DMM_MEM_NAME_SIZE]);
+
+struct dmm_ring *dmm_malloc_ring (int num, int flag);
+
+struct dmm_ring *dmm_create_pool (size_t elt_size, int num, int flag,
+ const char name[DMM_MEM_NAME_SIZE]);
+
+struct dmm_ring *dmm_attach_pool (const char name[DMM_MEM_NAME_SIZE]);
+
+/* allocate pool from heap */
+struct dmm_ring *dmm_malloc_pool (size_t elt_size, int num, int flag);
+
#endif /* _DMM_MEMORY_H_ */
diff --git a/src/framework/mem/dmm_segment.c b/src/framework/mem/dmm_segment.c
index 6358506..7600d3e 100644
--- a/src/framework/mem/dmm_segment.c
+++ b/src/framework/mem/dmm_segment.c
@@ -16,11 +16,14 @@
#include <stdio.h>
#include <string.h>
+#include <limits.h>
+#include "dmm_common.h"
#include "dmm_rwlock.h"
#include "dmm_segment.h"
#include "nstack_log.h"
-#define SECTION_SIZE 64 /* cache line size */
+#define BLOCK_SIZE 64 /* cache line size */
+#define BLOCK_MASK (BLOCK_SIZE - 1)
#define FIRST_NAME "FIRST SECTION FOR SEGMENT"
#define LAST_NAME "LAST SECTION FOR FREE HEAD"
@@ -28,6 +31,11 @@
#define MEM_ERR(fmt, ...) \
NS_LOGPID(LOGFW, "DMM-MEM", NSLOG_ERR, fmt, ##__VA_ARGS__)
+typedef struct
+{
+ char _dummy_block_size[BLOCK_SIZE];
+} _dmm_packed __BLOCK;
+
/*
init create:
\--total number
@@ -53,13 +61,15 @@ typedef struct dmm_section
int prev_rel;
int used_num;
int free_num;
- int __flags; /* reserved */
+ int flags; /* reserved */
size_t req_size; /* in bytes */
int less_rel; /* for free list */
int more_rel; /* for free list */
char name[DMM_MEM_NAME_SIZE];
-} __attribute__ ((__aligned__ (SECTION_SIZE))) section_t;
-SIZE_OF_TYPE_EQUAL_TO (section_t, SECTION_SIZE);
+} _dmm_cache_aligned section_t;
+
+/* dmm_section struct hold blocks number */
+#define SECTION_HOLD ((sizeof(struct dmm_section) + (BLOCK_SIZE - 1)) / BLOCK_SIZE)
struct dmm_segment
{
@@ -80,23 +90,22 @@ CALC_NUM (size_t size)
{
if (size)
{
- const size_t MASK = SECTION_SIZE - 1;
- return (size + MASK) / SECTION_SIZE + 1;
+ return SECTION_HOLD + (size + BLOCK_MASK) / BLOCK_SIZE;
}
- return 2; /* if size is 0, then alloc 1 block */
+ return SECTION_HOLD + 1; /* if size is 0, then alloc 1 block */
}
inline static int
SEC_REL (const section_t * base, const section_t * sec)
{
- return sec - base;
+ return (__BLOCK *) sec - (__BLOCK *) base;
}
section_t *
REL_SEC (section_t * base, int rel)
{
- return base + rel;
+ return (section_t *) ((__BLOCK *) base + rel);
}
inline static int
@@ -108,25 +117,25 @@ SEC_INDEX (struct dmm_segment *seg, section_t * sec)
inline static section_t *
LESS_SEC (section_t * sec)
{
- return sec + sec->less_rel;
+ return REL_SEC (sec, sec->less_rel);
}
inline static section_t *
MORE_SEC (section_t * sec)
{
- return sec + sec->more_rel;
+ return REL_SEC (sec, sec->more_rel);
}
inline static section_t *
PREV_SEC (section_t * sec)
{
- return sec + sec->prev_rel;
+ return REL_SEC (sec, sec->prev_rel);
}
inline static section_t *
NEXT_SEC (section_t * sec)
{
- return sec + (sec->free_num + sec->used_num);
+ return REL_SEC (sec, sec->free_num + sec->used_num);
}
inline static int
@@ -136,7 +145,7 @@ CHECK_ADDR (struct dmm_segment *seg, void *mem)
return -1;
if (mem > (void *) seg->last)
return -1;
- if ((long) mem & (SECTION_SIZE - 1))
+ if ((long) mem & BLOCK_MASK)
return -1;
return 0;
@@ -185,7 +194,7 @@ mem_alloc (struct dmm_segment *seg, size_t size)
}
while (num > pos->free_num);
- /* allocate pos pos section tail */
+ /* allocate from pos section's tail */
/* change next section's prev possion */
next = NEXT_SEC (pos);
@@ -201,13 +210,13 @@ mem_alloc (struct dmm_segment *seg, size_t size)
sec->more_rel = 0;
sec->name[0] = 0;
- /* adjust pos */
+ /* adjust pos section */
pos->free_num -= num;
less = LESS_SEC (pos);
more = MORE_SEC (pos);
- /* remove pos free list */
+ /* remove from free list */
less->more_rel = SEC_REL (less, more);
more->less_rel = SEC_REL (more, less);
pos->more_rel = 0;
@@ -294,23 +303,35 @@ mem_free (struct dmm_segment *seg, section_t * sec)
}
void
+dmm_seg_lock (struct dmm_segment *seg)
+{
+ dmm_write_lock (&seg->lock);
+}
+
+void
+dmm_seg_unlock (struct dmm_segment *seg)
+{
+ dmm_write_unlock (&seg->lock);
+}
+
+void
dmm_seg_dump (struct dmm_segment *seg)
{
section_t *sec;
dmm_read_lock (&seg->lock);
- (void) printf ("---- segment:%p base:%p size:%lu --------------\n"
- " first[%d]:%p last[%d]:%p total_num:%d used_num:%d\n"
- " sec_num:%d used_size:%lu use%%:%lu%% free%%:%lu%%\n",
- seg, seg->base, seg->size,
- SEC_INDEX (seg, seg->first), seg->first,
- SEC_INDEX (seg, seg->last), seg->last,
- seg->total_num, seg->used_num,
- seg->sec_num, seg->used_size,
- seg->used_size * 100 / seg->size,
- (seg->total_num -
- seg->used_num) * SECTION_SIZE * 100 / seg->size);
+ (void)
+ printf
+ ("---- segment:%p base:%p size:%lu ---- BS:%u SS:%lu SH:%lu ----\n"
+ " first[%d]:%p last[%d]:%p total_num:%d used_num:%d\n"
+ " sec_num:%d used_size:%lu use%%:%lu%% free%%:%ld%%\n", seg,
+ seg->base, seg->size, BLOCK_SIZE, sizeof (struct dmm_section),
+ SECTION_HOLD, SEC_INDEX (seg, seg->first), seg->first, SEC_INDEX (seg,
+ seg->last),
+ seg->last, seg->total_num, seg->used_num, seg->sec_num, seg->used_size,
+ seg->used_size * 100 / seg->size,
+ (seg->total_num - seg->used_num) * (BLOCK_SIZE * 100) / seg->size);
(void) printf ("----------------------------------------\n"
"%18s %9s %9s %9s %9s %10s %9s %9s %s\n",
@@ -345,16 +366,15 @@ dmm_seg_dump (struct dmm_segment *seg)
inline static int
align_section (void *base, size_t size, section_t ** first)
{
- const long MASK = ((long) SECTION_SIZE - 1);
const int SEG_NUM = CALC_NUM (sizeof (struct dmm_segment));
const long align = (long) base;
- const long addr = (align + MASK) & (~MASK);
- const size_t total = (size - (addr - align)) / SECTION_SIZE;
+ const long addr = (align + BLOCK_MASK) & (~BLOCK_MASK);
+ const size_t total = (size - (addr - align)) / BLOCK_SIZE;
- if (total > 0x7fffFFFF)
+ if (total > INT_MAX)
return -1;
- if (total < SEG_NUM + 1) /* first+segment + last */
+ if (total < SEG_NUM + SECTION_HOLD) /* first+segment + last */
return -1;
*first = (section_t *) addr;
@@ -364,21 +384,21 @@ align_section (void *base, size_t size, section_t ** first)
struct dmm_segment *
dmm_seg_create (void *base, size_t size)
{
- const int SEG_NUM = CALC_NUM (sizeof (struct dmm_segment));
section_t *first, *last;
struct dmm_segment *seg;
- int total = align_section (base, size, &first);
+ const int total = align_section (base, size, &first);
+ const int SEG_NUM = CALC_NUM (sizeof (struct dmm_segment));
if (total <= 0)
return NULL;
- last = first + (total - 1);
+ last = first + (total - SECTION_HOLD);
/* first section */
first->prev_rel = 0;
first->used_num = SEG_NUM;
first->req_size = sizeof (struct dmm_segment);
- first->free_num = total - (SEG_NUM + 1);
+ first->free_num = total - (SEG_NUM + SECTION_HOLD);
first->less_rel = SEC_REL (first, last);
first->more_rel = SEC_REL (first, last);
first->name[0] = 0;
@@ -402,9 +422,9 @@ dmm_seg_create (void *base, size_t size)
seg->first = first;
seg->last = last;
seg->total_num = total;
- seg->sec_num = 2;
+ seg->sec_num = 2; /* first and tail */
seg->used_size = sizeof (struct dmm_segment);
- seg->used_num = first->used_num;
+ seg->used_num = first->used_num + SECTION_HOLD;
return seg;
}
@@ -414,12 +434,12 @@ dmm_seg_attach (void *base, size_t size)
{
section_t *first, *last;
struct dmm_segment *seg;
- int total = align_section (base, size, &first);
+ const int total = align_section (base, size, &first);
if (total <= 0)
return NULL;
- last = first + (total - 1);
+ last = first + (total - SECTION_HOLD);
seg = (struct dmm_segment *) (first + 1);
if (seg->base != base)
@@ -451,9 +471,9 @@ dmm_mem_alloc (struct dmm_segment *seg, size_t size)
{
section_t *sec;
- dmm_write_lock (&seg->lock);
+ dmm_seg_lock (seg);
sec = mem_alloc (seg, size);
- dmm_write_unlock (&seg->lock);
+ dmm_seg_unlock (seg);
return sec ? sec + 1 : NULL;
}
@@ -467,9 +487,9 @@ dmm_mem_free (struct dmm_segment *seg, void *mem)
return -1;
}
- dmm_write_lock (&seg->lock);
+ dmm_seg_lock (seg);
mem_free (seg, ((section_t *) mem) - 1);
- dmm_write_unlock (&seg->lock);
+ dmm_seg_unlock (seg);
return 0;
}
@@ -499,45 +519,36 @@ dmm_mem_map (struct dmm_segment *seg, size_t size,
if (!name || !name[0] || strlen (name) >= DMM_MEM_NAME_SIZE)
return NULL;
- dmm_write_lock (&seg->lock);
-
sec = mem_lookup (seg, name);
if (sec)
{
MEM_ERR ("Map '%s' exist", name);
mem = NULL;
}
- else if (!(sec = mem_alloc (seg, size)))
+ else if (NULL != (sec = mem_alloc (seg, size)))
{
- MEM_ERR ("alloc '%s' failed for size %lu", name, size);
- mem = NULL;
+ (void) strncpy (sec->name, name, sizeof (sec->name));
+ mem = sec + 1;
}
else
{
- (void) strncpy (sec->name, name, sizeof (sec->name));
- mem = sec + 1;
+ MEM_ERR ("alloc '%s' failed for size %lu", name, size);
+ mem = NULL;
}
- dmm_write_unlock (&seg->lock);
-
return mem;
}
int
-dmm_mem_unmap (struct dmm_segment *seg, const char name[DMM_MEM_NAME_SIZE])
+dmm_mem_unmap (struct dmm_segment *seg, void *mem)
{
- section_t *sec;
-
- if (!name || !name[0])
- return -1;
-
- dmm_write_lock (&seg->lock);
-
- sec = mem_lookup (seg, name);
- if (sec)
- mem_free (seg, sec);
+ if (CHECK_ADDR (seg, mem))
+ {
+ MEM_ERR ("Invalid address:%p", mem);
+ return -1;
+ }
- dmm_write_unlock (&seg->lock);
+ mem_free (seg, ((section_t *) mem) - 1);
- return sec != NULL ? 0 : -1;
+ return 0;
}
diff --git a/src/framework/mem/dmm_segment.h b/src/framework/mem/dmm_segment.h
index 135f347..500e4e8 100644
--- a/src/framework/mem/dmm_segment.h
+++ b/src/framework/mem/dmm_segment.h
@@ -18,6 +18,11 @@
#define DMM_MEM_NAME_SIZE 32
+struct dmm_segment;
+
+void dmm_seg_lock (struct dmm_segment *seg);
+void dmm_seg_unlock (struct dmm_segment *seg);
+
struct dmm_segment *dmm_seg_create (void *base, size_t size);
struct dmm_segment *dmm_seg_attach (void *base, size_t size);
void dmm_seg_dump (struct dmm_segment *seg);
@@ -29,7 +34,6 @@ void *dmm_mem_lookup (struct dmm_segment *seg,
const char name[DMM_MEM_NAME_SIZE]);
void *dmm_mem_map (struct dmm_segment *seg, size_t size,
const char name[DMM_MEM_NAME_SIZE]);
-int dmm_mem_unmap (struct dmm_segment *seg,
- const char name[DMM_MEM_NAME_SIZE]);
+int dmm_mem_unmap (struct dmm_segment *seg, void *mem);
#endif /* #ifndef _DMM_SEGMENT_H_ */
diff --git a/src/framework/ring/dmm_ring.c b/src/framework/ring/dmm_ring.c
new file mode 100644
index 0000000..2b1b1ee
--- /dev/null
+++ b/src/framework/ring/dmm_ring.c
@@ -0,0 +1,94 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#include <stdio.h>
+#include <string.h>
+
+#include "nstack_log.h"
+
+#include "dmm_ring.h"
+
+void
+dmm_ring_dump (struct dmm_ring *ring, int list)
+{
+ if (!ring)
+ return;
+
+ (void) printf ("ring:%p size:%d flag:0x%x prod:%d-%d/%d cons:%d-%d/%d",
+ ring, ring->size, ring->flag,
+ ring->prod_head, ring->prod_tail, ring->is_sp,
+ ring->cons_head, ring->cons_tail, ring->is_sc);
+ if (list && dmm_ring_count (ring))
+ {
+ int count = 0;
+ void **p = (void **) (ring + 1);
+ int i = ring->cons_head;
+ while (i != ring->prod_tail)
+ {
+ if ((count++ & 3) == 0)
+ (void) printf ("\n");
+ (void) printf (" %d:%p", i, p[i]);
+ if (++i >= ring->size)
+ i = 0;
+ }
+ }
+ (void) printf ("\n----------------\n");
+}
+
+int
+dmm_ring_init (struct dmm_ring *ring, int num, int flag)
+{
+ if (num > DMM_RING_MAX_NUM)
+ return -1;
+
+ (void) memset (ring, 0, sizeof (struct dmm_ring));
+
+ ring->size = num + 1;
+
+ ring->prod_head = 0;
+ ring->prod_tail = 0;
+ ring->is_sp = flag & DMM_RING_INIT_SP;
+
+ ring->cons_head = 0;
+ ring->cons_tail = 0;
+ ring->is_sc = flag & DMM_RING_INIT_SC;
+
+ return 0;
+}
+
+int
+dmm_pool_init (struct dmm_ring *pool, size_t elt_size, int num, uint32_t flag)
+{
+ int ret;
+ void *array;
+ const size_t ring_size = dmm_ring_bufsize (num);
+
+ if (0 != dmm_ring_init (pool, num, flag))
+ {
+ NSFW_LOGERR ("init pool's ring failed, num:%d flag:0x%x ring_size:%lu",
+ num, flag, ring_size);
+ return -1;
+ }
+
+ array = (char *) pool + ring_size;
+ ret = dmm_array_enqueue (pool, array, num, elt_size);
+ if (ret != num)
+ {
+ NSFW_LOGERR ("enqueue failed, num:%d elt_size:%lu", num, elt_size);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/framework/ring/dmm_ring.h b/src/framework/ring/dmm_ring.h
new file mode 100644
index 0000000..914eff2
--- /dev/null
+++ b/src/framework/ring/dmm_ring.h
@@ -0,0 +1,205 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef _DMM_RING_H_
+#define _DMM_RING_H_
+
+#include <stdint.h>
+
+#include "dmm_atomic.h"
+#include "dmm_pause.h"
+#include "dmm_barrier.h"
+#include "dmm_common.h"
+
+#define DMM_RING_MAX_NUM 0x7FFFFFFE /* 2,147,483,646 */
+
+#define DMM_RING_INIT_SP 0x0001
+#define DMM_RING_INIT_SC 0x0002
+#define DMM_RING_INIT_MPMC 0
+#define DMM_RING_INIT_SPSC (DMM_RING_INIT_SP | DMM_RING_INIT_SC)
+
+struct dmm_ring
+{
+ int size;
+ uint32_t flag;
+
+ volatile int prod_head;
+ volatile int prod_tail;
+ int is_sp;
+ int _prod_pad;
+
+ volatile int cons_head;
+ volatile int cons_tail;
+ int is_sc;
+ int _cons_pad;
+} _dmm_cache_aligned;
+
+#include "dmm_ring_base.h"
+
+void dmm_ring_dump (struct dmm_ring *ring, int list);
+int dmm_ring_init (struct dmm_ring *ring, int num, int flag);
+int dmm_pool_init (struct dmm_ring *pool, size_t elt_size,
+ int num, uint32_t flag);
+
+inline static size_t
+dmm_ring_bufsize (int num)
+{
+ size_t size = sizeof (struct dmm_ring);
+
+ size += (sizeof (void *) * (num + 1));
+
+ return dmm_align (size, DMM_CACHE_LINE_SIZE);
+}
+
+inline static size_t
+dmm_pool_arraysize (int num, int elt_size)
+{
+ const size_t size = elt_size * num;
+ return dmm_align (size, DMM_CACHE_LINE_SIZE);
+}
+
+inline static size_t
+dmm_pool_bufsize (int num, int elt_size)
+{
+ return dmm_ring_bufsize (num) + dmm_pool_arraysize (num, elt_size);
+}
+
+inline static int
+dmm_ring_count (struct dmm_ring *ring)
+{
+ const int count = ring->prod_tail - ring->cons_head;
+
+ if (count >= 0)
+ return count;
+ return count + ring->size;
+}
+
+inline static int
+dmm_ring_free_count (struct dmm_ring *ring)
+{
+ const int count = ring->cons_tail - ring->prod_head;
+
+ if (count >= 0)
+ return count;
+ return count + ring->size;
+}
+
+/* enqueue several objects in a ring.
+ ring: point to the ring
+ p: object pointer list array
+ num: number of object
+ fixed: enqueue fixed number
+single_cons: is single producer
+ <return>: number of enqueued object, 0: queue is full
+*/
+inline static int
+dmm_ring_enqueue (struct dmm_ring *ring, void **p, int num,
+ int fixed, int is_sp)
+{
+ int n, pos, new_pos;
+
+ n = dmm_enqueue_prep (ring, num, &pos, fixed, is_sp);
+
+ if (n == 0)
+ return 0;
+
+ new_pos = dmm_enqueue_copy (ring, pos, p, n);
+
+ dmm_enqueue_done (ring, pos, new_pos, is_sp);
+
+ return n;
+}
+
+inline static int
+dmm_fix_enqueue (struct dmm_ring *ring, void **p, int num)
+{
+ return dmm_ring_enqueue (ring, p, num, 1, ring->is_sp);
+}
+
+inline static int
+dmm_var_enqueue (struct dmm_ring *ring, void **p, int num)
+{
+ return dmm_ring_enqueue (ring, p, num, 0, ring->is_sp);
+}
+
+inline static int
+dmm_enqueue (struct dmm_ring *ring, void *p)
+{
+ return dmm_var_enqueue (ring, &p, 1);
+}
+
+inline static int
+dmm_array_enqueue (struct dmm_ring *ring, void *array,
+ int num, size_t elt_size)
+{
+ int n, pos, new_pos;
+
+ n = dmm_enqueue_prep (ring, num, &pos, 0, ring->is_sp);
+
+ if (n == 0)
+ return 0;
+
+ new_pos = dmm_enqueue_copy_array (ring, pos, array, n, elt_size);
+
+ dmm_enqueue_done (ring, pos, new_pos, ring->is_sp);
+
+ return n;
+}
+
+/* dequeue several objects from a ring.
+ ring: point to the ring
+ p: save object array
+ num: number of p
+ fixed: dequeue fixed number
+single_cons: is single consumer
+ <return>: number of dequeued object, 0: queue is empty
+*/
+inline static int
+dmm_ring_dequeue (struct dmm_ring *ring, void **p, int num,
+ int fixed, int single_cons)
+{
+ int n, pos, new_pos;
+
+ n = dmm_dequeue_prep (ring, num, &pos, fixed, single_cons);
+
+ if (n == 0)
+ return 0;
+
+ new_pos = dmm_dequeue_copy (ring, pos, p, n);
+
+ dmm_dequeue_done (ring, pos, new_pos, single_cons);
+
+ return n;
+}
+
+inline static int
+dmm_fix_dequeue (struct dmm_ring *ring, void **p, int num)
+{
+ return dmm_ring_dequeue (ring, p, num, 1, ring->is_sc);
+}
+
+inline static int
+dmm_var_dequeue (struct dmm_ring *ring, void **p, int num)
+{
+ return dmm_ring_dequeue (ring, p, num, 0, ring->is_sc);
+}
+
+inline static int
+dmm_dequeue (struct dmm_ring *ring, void **p)
+{
+ return dmm_var_dequeue (ring, p, 1);
+}
+
+#endif
diff --git a/src/framework/ring/dmm_ring_base.h b/src/framework/ring/dmm_ring_base.h
new file mode 100644
index 0000000..9a48eea
--- /dev/null
+++ b/src/framework/ring/dmm_ring_base.h
@@ -0,0 +1,189 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at:
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#ifndef _DMM_RING_BASE_H_
+#define _DMM_RING_BASE_H_
+
+#ifndef _DMM_RING_H_
+#error include dmm_ring.h please
+#endif
+
+inline static int
+__move_head (volatile int *head, int ring_size,
+ int old_head, int real_num, int is_single)
+{
+ int new_head = old_head + real_num;
+
+ if (new_head >= ring_size)
+ {
+ new_head -= ring_size;
+ }
+
+ if (is_single)
+ {
+ *head = new_head;
+ return 1;
+ }
+
+ return dmm_atomic_swap ((dmm_atomic_t *) head, old_head, new_head);
+}
+
+inline static int
+dmm_enqueue_prep (struct dmm_ring *ring, const int num,
+ int *pos, const int fixed, int is_sp)
+{
+ int succ, real, head;
+ const int ring_size = ring->size;
+
+ do
+ {
+ head = ring->prod_head;
+
+ dmm_barrier ();
+
+ if ((real = ring->cons_tail - head - 1) < 0)
+ real += ring_size;
+
+ if (real >= num)
+ real = num;
+ else if (fixed)
+ return 0;
+
+ if (real <= 0)
+ return 0;
+
+ succ = __move_head (&ring->prod_head, ring_size, head, real, is_sp);
+ }
+ while (!succ);
+
+ *pos = head;
+ return real;
+}
+
+inline static int
+dmm_enqueue_copy (struct dmm_ring *ring, int pos, void **from, int num)
+{
+ const int ring_size = ring->size;
+ void **box = (void **) (ring + 1);
+
+ while (num > 0)
+ {
+ box[pos++] = *from++;
+ if (pos >= ring_size)
+ pos = 0;
+ --num;
+ }
+
+ return pos;
+}
+
+inline static void
+dmm_enqueue_done (struct dmm_ring *ring, int pos, int new_pos, int is_sp)
+{
+ dmm_barrier ();
+
+ if (!is_sp)
+ {
+ while (ring->prod_tail != pos)
+ dmm_pause ();
+ }
+
+ ring->prod_tail = new_pos;
+}
+
+inline static int
+dmm_enqueue_copy_array (struct dmm_ring *ring, int pos,
+ void *array, int num, size_t elt_size)
+{
+ const int ring_size = ring->size;
+ void **box = (void **) (ring + 1);
+ char *from = (char *) array;
+
+ while (num > 0)
+ {
+ box[pos++] = from;
+ if (pos >= ring_size)
+ pos = 0;
+ from += elt_size;
+ --num;
+ }
+
+ return pos;
+}
+
+inline static int
+dmm_dequeue_prep (struct dmm_ring *ring, const int num, int *pos,
+ const int fixed, int is_sc)
+{
+ int succ, real, head;
+ const int ring_size = ring->size;
+
+ do
+ {
+ head = ring->cons_head;
+
+ dmm_barrier ();
+
+ if ((real = ring->prod_tail - head) < 0)
+ real += ring_size;
+
+ if (real >= num)
+ real = num;
+ else if (fixed)
+ return 0;
+
+ if (real <= 0)
+ return 0;
+
+ succ = __move_head (&ring->cons_head, ring_size, head, real, is_sc);
+ }
+ while (!succ);
+
+ *pos = head;
+ return real;
+}
+
+inline static int
+dmm_dequeue_copy (struct dmm_ring *ring, int pos, void **to, int num)
+{
+ const int ring_size = ring->size;
+ void **box = (void **) (ring + 1);
+
+ while (num > 0)
+ {
+ *to++ = box[pos++];
+ if (pos >= ring_size)
+ pos = 0;
+ --num;
+ }
+
+ return pos;
+}
+
+inline static void
+dmm_dequeue_done (struct dmm_ring *ring, int pos, int new_pos, int is_sc)
+{
+ dmm_barrier ();
+
+ if (!is_sc)
+ {
+ while (ring->cons_tail != pos)
+ dmm_pause ();
+ }
+
+ ring->cons_tail = new_pos;
+}
+
+#endif
diff --git a/src/nSocket/CMakeLists.txt b/src/nSocket/CMakeLists.txt
index 5701e8e..f428e7b 100644
--- a/src/nSocket/CMakeLists.txt
+++ b/src/nSocket/CMakeLists.txt
@@ -14,12 +14,6 @@
# limitations under the License.
#########################################################################
-
-if(WITH_HAL_LIB)
-else()
- SET(PAL_H_DIRECTORIES "/usr/include/dpdk/")
-endif()
-
INCLUDE_DIRECTORIES(
include/
kernel/
@@ -28,7 +22,6 @@ INCLUDE_DIRECTORIES(
nstack/event/epoll
nstack/event/select
${SECUREC_SRC_H}
- ${PAL_H_DIRECTORIES}
${CMAKE_CURRENT_LIST_DIR}/../adapt
${CMAKE_CURRENT_LIST_DIR}/../../thirdparty/json/json-c-0.12.1
)
@@ -42,8 +35,5 @@ TARGET_LINK_LIBRARIES(
${LIB_PATH_STATIC}/libglog.a
dmm_api
-Wl,--no-whole-archive,-lstdc++
- rte_eal
- rte_mempool
- rte_mbuf
- rte_ring)
+)
ADD_DEPENDENCIES(nStackAPI dmm_api)
diff --git a/src/nSocket/include/nstack_atomic.h b/src/nSocket/include/nstack_atomic.h
deleted file mode 100644
index bb5ec13..0000000
--- a/src/nSocket/include/nstack_atomic.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-*
-* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at:
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#ifndef _NSTACK_ATOMIC_H_
-#define _NSTACK_ATOMIC_H_
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "nstack_types.h"
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-extern "C"{
-/* *INDENT-ON* */
-#endif
-
-typedef struct
-{
- volatile ns_int32 counter;
-} atomic_t;
-
-#define atomic_set(v, i) ((v)->counter = (i))
-
-#define atomic_fetch_and_add(v, i) __sync_fetch_and_add(&(v)->counter, i)
-#define atomic_add_and_fetch(v, i) __sync_add_and_fetch(&(v)->counter, i)
-
-#define atomic_fetch_and_sub(v, i) __sync_fetch_and_sub(&(v)->counter, i)
-#define atomic_sub_and_fetch(v, i) __sync_sub_and_fetch(&(v)->counter, i)
-
-#define atomic_read(v) atomic_fetch_and_add(v, 0)
-#define atomic_inc(v) atomic_add_and_fetch(v, 1)
-#define atomic_dec(v)atomic_sub_and_fetch(v, 1)
-#define atomic_add(v, i) atomic_add_and_fetch(v, i)
-#define atomic_sub(v, i) atomic_sub_and_fetch(v,i)
-
-#define cas(ptr, oldValue, exchange) __sync_bool_compare_and_swap(ptr, oldValue, exchange)
-
-#ifdef __cplusplus
-/* *INDENT-OFF* */
-}
-/* *INDENT-ON* */
-#endif
-
-#endif
diff --git a/src/nSocket/include/nstack_eventpoll.h b/src/nSocket/include/nstack_eventpoll.h
index afb0b05..ac9622d 100644
--- a/src/nSocket/include/nstack_eventpoll.h
+++ b/src/nSocket/include/nstack_eventpoll.h
@@ -19,14 +19,17 @@
#include "ephlist.h"
#include "eprb_tree.h"
-#include "common_mem_api.h"
#include "types.h"
#include <semaphore.h>
#include <sys/epoll.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include "nstack_types.h"
#include "nstack_securec.h"
#include "nstack_log.h"
+#include "dmm_ring.h"
+#include "dmm_spinlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -68,8 +71,7 @@ struct eventpoll
* Protect the this structure access
* This is for event add to ready list and poll out
*/
- sys_sem_st lock;
-
+ dmm_spinlock_t lock;
/*
* This semaphore is used to ensure that files are not removed
* while epoll is using them. This is read-held during the event
@@ -78,7 +80,7 @@ struct eventpoll
* When we do epoll_ctl, we write lock
* When we collecting data , we read lock
*/
- sys_sem_st sem;
+ dmm_spinlock_t sem;
/*
* This semaphore is used to block epoll_wait function
@@ -102,14 +104,12 @@ struct eventpoll
struct eventpoll_pool
{
- void *ring;
+ struct dmm_ring *ring;
struct eventpoll *pool;
};
typedef struct
{
- int iindex;
- int iNext;
int fd;
i32 epaddflag;
i32 fdtype; /*0: socket fd, 1: epoll fd */
@@ -117,21 +117,18 @@ typedef struct
i32 rmidx; /* copy of fdInf->rmidx */
i32 protoFD[NSEP_SMOD_MAX]; /* copy of fdInf->protoFD */// Here we need to set router infomations dependency
struct eventpoll *ep;
- sys_sem_st epiLock;
- sys_sem_st freeLock;
+ dmm_spinlock_t epiLock;
+ dmm_spinlock_t freeLock;
struct ep_list epiList; /* This restore the epitem of this file descriptor */
u32 sleepTime; //add for NSTACK_SEM_SLEEP
nsep_pidinfo pidinfo;
nsfw_res res_chk;
- void *private_data; /*add for debug, just used to record extern infomation, for example sbr conn */
- i32 reserv[4];
} nsep_epollInfo_t;
typedef struct
{
- void *ring;
+ struct dmm_ring *ring;
nsep_epollInfo_t *pool;
- char last_reserve[8]; //reserve for update
} nsep_infoPool_t;
struct epitem
@@ -149,13 +146,12 @@ struct epitem
unsigned int ovf_revents;
int fd;
u32 pid;
- void *private_data;
nsfw_res res_chk;
};
struct epitem_pool
{
- void *ring;
+ struct dmm_ring *ring;
struct epitem *pool;
};
diff --git a/src/nSocket/include/nstack_types.h b/src/nSocket/include/nstack_types.h
index 90b538e..556dc7e 100644
--- a/src/nSocket/include/nstack_types.h
+++ b/src/nSocket/include/nstack_types.h
@@ -20,7 +20,6 @@
#include <time.h>
#include <stdint.h>
#include <stdlib.h>
-#include <common_pal_bitwide_adjust.h>
#ifdef __cplusplus
/* *INDENT-OFF* */
diff --git a/src/nSocket/include/select_adapt.h b/src/nSocket/include/select_adapt.h
index 2898c76..072f53b 100644
--- a/src/nSocket/include/select_adapt.h
+++ b/src/nSocket/include/select_adapt.h
@@ -35,9 +35,8 @@
#include "types.h"
#include "nstack_module.h"
-#include "common_mem_spinlock.h"
#include "nstack_securec.h"
-#include "common_func.h"
+#include "dmm_spinlock.h"
#define SBR_MAX_FD_NUM MAX_SOCKET_NUM
@@ -54,11 +53,11 @@
}
typedef sem_t select_sem_t;
-typedef common_mem_spinlock_t select_spinlock_t;
+typedef dmm_spinlock_t select_spinlock_t;
-#define select_spin_lock(lock) (common_mem_spinlock_lock((lock)))
-#define select_spin_unlock(lock) (common_mem_spinlock_unlock((lock)))
-#define select_spin_lock_init(lock) (common_mem_spinlock_init((lock)))
+#define select_spin_lock(lock) (dmm_spin_lock((lock)))
+#define select_spin_unlock(lock) (dmm_spin_unlock((lock)))
+#define select_spin_lock_init(lock) (dmm_spin_init((lock)))
#define select_sem_wait(sem) (sem_wait((sem)))
#define select_sem_init(sem, share, val) (sem_init((sem), (share), (val)))
diff --git a/src/nSocket/nstack/event/epoll/nstack_eventpoll.c b/src/nSocket/nstack/event/epoll/nstack_eventpoll.c
index a8b3757..1777aee 100644
--- a/src/nSocket/nstack/event/epoll/nstack_eventpoll.c
+++ b/src/nSocket/nstack/event/epoll/nstack_eventpoll.c
@@ -14,17 +14,21 @@
* limitations under the License.
*/
+#include <errno.h>
+
#include "nstack_eventpoll.h"
#include "nstack_log.h"
#include "nsfw_recycle_api.h"
#include "nstack_securec.h"
#include "nstack_module.h"
#include "nstack_sockops.h"
-#include "nsfw_mem_api.h"
#include "nstack_fd_mng.h"
#include "nstack.h"
#include "nstack_dmm_adpt.h"
+#include "dmm_sys.h"
+#include "dmm_memory.h"
+
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
@@ -55,21 +59,21 @@ nsep_ctl_event_add (struct epitem *epi, struct eventpoll *ep,
case nstack_ep_triggle_add:
if (events & epi->event.events)
{
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
if (!EP_HLIST_NODE_LINKED (&epi->rdllink))
{
ep_hlist_add_tail (&ep->rdlist, &epi->rdllink);
}
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
sem_post (&ep->waitSem);
}
break;
case nstack_ep_triggle_mod:
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
if (events & epi->event.events)
{
@@ -88,7 +92,7 @@ nsep_ctl_event_add (struct epitem *epi, struct eventpoll *ep,
}
}
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
break;
default:
break;
@@ -114,7 +118,7 @@ nsep_epctl_triggle (struct epitem *epi, nsep_epollInfo_t * info,
struct eventpoll *ep = NULL;
nsep_epollInfo_t *epInfo = NULL;
- ep = ADDR_SHTOL (epi->ep);
+ ep = epi->ep;
epfd = ep->epfd;
epInfo = nsep_get_infoBySock (epfd);
@@ -190,7 +194,7 @@ nsep_rbtree_insert (struct eventpoll *ep, struct epitem *epi)
break;
}
- parent = (struct ep_rb_node *) ADDR_SHTOL (*p);
+ parent = *p;
epic = ep_rb_entry (parent, struct epitem, rbn);
if (epi->fd > epic->fd)
{
@@ -226,8 +230,7 @@ nsep_insert_node (struct eventpoll *ep, struct epoll_event *event,
EP_HLIST_INIT_NODE (&epi->lkFDllink);
epi->nwait = 0;
- epi->ep = (struct eventpoll *) ADDR_LTOSH_EXT (ep);
- epi->epInfo = (nsep_epollInfo_t *) ADDR_LTOSH_EXT (fdInfo);
+ epi->ep = ep;
epi->revents = 0;
epi->ovf_revents = 0;
epi->event = *event;
@@ -238,10 +241,10 @@ nsep_insert_node (struct eventpoll *ep, struct epoll_event *event,
/* Add the current item to the list of active epoll hook for this file
This should lock because file descriptor may be called by other eventpoll */
- sys_arch_lock_with_pid (&fdInfo->epiLock);
+ dmm_spin_lock_pid (&fdInfo->epiLock);
ep_list_add_tail (&fdInfo->epiList, &epi->fllink);
- epi->private_data = (void *) ADDR_LTOSH_EXT (fdInfo);
- sys_sem_s_signal (&fdInfo->epiLock);
+ epi->epInfo = fdInfo;
+ dmm_spin_unlock (&fdInfo->epiLock);
/* Add epitem to eventpoll fd list, don't need lock here because epoll_ctl will lock before calling this function */
nsep_rbtree_insert (ep, epi);
@@ -306,20 +309,18 @@ nsep_epctl_del (struct eventpoll *ep, struct epitem *epi)
{
int ret = 0;
- nsep_epollInfo_t *epInfo =
- (nsep_epollInfo_t *) ADDR_SHTOL (epi->private_data);
+ nsep_epollInfo_t *epInfo = epi->epInfo;
NSSOC_LOGINF ("epfd=%d,fd=%d,epi=%p", ep->epfd, epi->fd, epi); // modify log format error
nsep_epctl_triggle (epi, epInfo, nstack_ep_triggle_del);
- sys_arch_lock_with_pid (&epInfo->epiLock);
+ dmm_spin_lock_pid (&epInfo->epiLock);
ep_list_del (&epInfo->epiList, &epi->fllink);
+ dmm_spin_unlock (&epInfo->epiLock);
- sys_sem_s_signal (&epInfo->epiLock);
-
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
ret = nstack_ep_unlink (ep, epi);
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
nsep_free_epitem (epi);
return ret;
@@ -340,9 +341,9 @@ nsep_epctl_mod (struct eventpoll *ep,
NSSOC_LOGINF ("epfd=%d,fd=%d,events=%u", ep->epfd, epInfo->fd,
events->events);
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
epi->event = *events; /* kernel tells me that I need to modify epi->event in lock context */
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
nsep_epctl_triggle (epi, epInfo, nstack_ep_triggle_mod);
return 0;
@@ -367,11 +368,10 @@ nsep_events_proc (struct eventpoll *ep,
{
node = head;
epi = ep_hlist_entry (node, struct epitem, rdllink);
- head = (struct ep_hlist_node *) ADDR_SHTOL (node->next);
+ head = (struct ep_hlist_node *) (node->next);
EP_HLIST_INIT_NODE (node);
- nsep_epollInfo_t *fdInfo =
- (nsep_epollInfo_t *) ADDR_SHTOL (epi->private_data);
+ nsep_epollInfo_t *fdInfo = epi->epInfo;
if (fdInfo->rmidx != -1)
{
@@ -434,48 +434,47 @@ nsep_ep_poll (struct eventpoll *ep, struct epoll_event *events, int maxevents,
return 0;
}
- sys_arch_lock_with_pid (&ep->sem);
+ dmm_spin_lock_pid (&ep->sem);
if (EP_HLIST_EMPTY (&ep->rdlist))
{
goto out;
}
- sys_arch_lock_with_pid (&ep->lock);
- head = (struct ep_hlist_node *) ADDR_SHTOL (ep->rdlist.head);
+ dmm_spin_lock_pid (&ep->lock);
+ head = (struct ep_hlist_node *) (ep->rdlist.head);
if (!head)
{
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
goto out;
}
- nhead.head = (struct ep_hlist_node *) ADDR_SHTOL (head->next);
- nhead.tail = (struct ep_hlist_node *) ADDR_SHTOL (ep->rdlist.tail);
+ nhead.head = (struct ep_hlist_node *) (head->next);
+ nhead.tail = (struct ep_hlist_node *) (ep->rdlist.tail);
/*unlink from ep->rdlist */
EP_HLIST_INIT (&(ep->rdlist));
ep->ovflist = NULL;
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
/*get event list */
evt = nsep_events_proc (ep, &nhead, events, maxevents, eventflag, num);
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
/*put rest epitem back to the rdlist */
if (nhead.head)
{
- tail = (struct ep_hlist_node *) ADDR_SHTOL (ep->rdlist.tail);
- tail->next = (struct ep_hlist_node *) ADDR_LTOSH (nhead.head);
- nhead.head->pprev = (struct ep_hlist_node **) ADDR_LTOSH (&tail->next);
- ep->rdlist.tail = (struct ep_hlist_node *) ADDR_LTOSH (nhead.tail);
+ tail = (struct ep_hlist_node *) (ep->rdlist.tail);
+ tail->next = (struct ep_hlist_node *) (nhead.head);
+ nhead.head->pprev = (struct ep_hlist_node **) (&tail->next);
+ ep->rdlist.tail = (struct ep_hlist_node *) (nhead.tail);
}
/*put the epitem in ep->ovflist to rdlist */
- for (nepi = (struct epitem *) ADDR_SHTOL (ep->ovflist);
+ for (nepi = (struct epitem *) (ep->ovflist);
(epi = nepi) != NULL;
- nepi = (struct epitem *) ADDR_SHTOL (epi->next), epi->next =
- NSEP_EP_UNACTIVE_PTR)
+ nepi = (struct epitem *) (epi->next), epi->next = NSEP_EP_UNACTIVE_PTR)
{
epi->revents |= epi->ovf_revents;
/*set the flag that already have event int the rdlist */
- fdInfo = (nsep_epollInfo_t *) ADDR_SHTOL (epi->private_data);
+ fdInfo = epi->epInfo;
if (eventflag && fdInfo && (fdInfo->rmidx >= 0)
&& (fdInfo->rmidx < num))
{
@@ -488,9 +487,9 @@ nsep_ep_poll (struct eventpoll *ep, struct epoll_event *events, int maxevents,
}
}
ep->ovflist = NSEP_EP_UNACTIVE_PTR;
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
out:
- sys_sem_s_signal (&ep->sem);
+ dmm_spin_unlock (&ep->sem);
NSSOC_LOGDBG ("Return epfd=%d,evt=%d,EP_HLIST_EMPTY(&ep->rdlist)=%d",
ep->epfd, evt, EP_HLIST_EMPTY (&ep->rdlist));
return evt;
@@ -548,10 +547,10 @@ nsep_remove_epfd (nsep_epollInfo_t * pinfo)
return;
}
#endif
- sys_arch_lock_with_pid (&pinfo->epiLock);
+ dmm_spin_lock_pid (&pinfo->epiLock);
/*list head must be not null */
- prenode = (struct list_node *) ADDR_SHTOL (pinfo->epiList.head);
- nextnode = (struct list_node *) ADDR_SHTOL (prenode->next);
+ prenode = pinfo->epiList.head;
+ nextnode = prenode->next;
icnt = 0;
/*find all node that pid is belong to itself */
@@ -594,10 +593,10 @@ nsep_remove_epfd (nsep_epollInfo_t * pinfo)
{
prenode = nextnode;
}
- nextnode = (struct list_node *) ADDR_SHTOL (prenode->next);
+ nextnode = prenode->next;
}
- sys_sem_s_signal (&pinfo->epiLock);
+ dmm_spin_unlock (&pinfo->epiLock);
/*free all epitem */
#ifdef FREE_LIST_SIZE
@@ -622,10 +621,10 @@ nsep_remove_epfd (nsep_epollInfo_t * pinfo)
#else
epi = ep_list_entry (node_arry[i], struct epitem, fllink);
#endif
- ep = (struct eventpoll *) ADDR_SHTOL (epi->ep);
+ ep = epi->ep;
if (ep)
{
- sys_arch_lock_with_pid (&ep->sem);
+ dmm_spin_lock_pid (&ep->sem);
/* Here don't use epi you find before, use fd and ep to find the epi again.that is multithread safe */
tepi = nsep_find_ep (ep, pinfo->fd);
/*record the exception log */
@@ -638,13 +637,13 @@ nsep_remove_epfd (nsep_epollInfo_t * pinfo)
if (tepi)
{
nsep_epctl_triggle (tepi, pinfo, nstack_ep_triggle_del);
- sys_arch_lock_with_pid (&ep->lock);
+ dmm_spin_lock_pid (&ep->lock);
(void) nstack_ep_unlink (ep, tepi);
- sys_sem_s_signal (&ep->lock);
+ dmm_spin_unlock (&ep->lock);
nsep_free_epitem (epi);
}
- sys_sem_s_signal (&ep->sem);
+ dmm_spin_unlock (&ep->sem);
}
}
#ifdef FREE_LIST_SIZE
@@ -669,7 +668,7 @@ nsep_close_epfd (struct eventpoll *ep)
struct epitem *epi = NULL;
struct ep_rb_node *node = NULL;
- sys_arch_lock_with_pid (&ep->sem);
+ dmm_spin_lock_pid (&ep->sem);
while ((node = ep_rb_first (&ep->rbr)))
{
@@ -684,7 +683,7 @@ nsep_close_epfd (struct eventpoll *ep)
break;
}
}
- sys_sem_s_signal (&ep->sem);
+ dmm_spin_unlock (&ep->sem);
nsep_free_eventpoll (ep);
}
@@ -696,9 +695,9 @@ nsp_epoll_close_kernel_fd (int sock, nsep_epollInfo_t * epInfo)
nsep_remove_epfd (epInfo);
u32_t pid = get_sys_pid ();
- sys_arch_lock_with_pid (&epInfo->freeLock);
+ dmm_spin_lock_pid (&epInfo->freeLock);
int left_count = nsep_del_last_pid (&epInfo->pidinfo, pid);
- sys_sem_s_signal (&epInfo->freeLock);
+ dmm_spin_unlock (&epInfo->freeLock);
if (-1 == left_count)
{
NSSOC_LOGERR ("pid not exist]fd=%d,type=%d,pid=%d", sock,
@@ -725,12 +724,12 @@ nsp_epoll_close_spl_fd (int sock, nsep_epollInfo_t * epInfo)
static inline int
nsp_epoll_close_ep_fd (int sock, nsep_epollInfo_t * epInfo)
{
- struct eventpoll *ep = ADDR_SHTOL (epInfo->ep);
+ struct eventpoll *ep = epInfo->ep;
u32_t pid = get_sys_pid ();
NSSOC_LOGINF ("fd:%d is epoll fd ep:%p]", sock, ep);
- sys_arch_lock_with_pid (&epInfo->freeLock);
+ dmm_spin_lock_pid (&epInfo->freeLock);
int left_count = nsep_del_last_pid (&epInfo->pidinfo, pid);
- sys_sem_s_signal (&epInfo->freeLock);
+ dmm_spin_unlock (&epInfo->freeLock);
if (0 == left_count)
{
epInfo->ep = NULL;
@@ -932,7 +931,7 @@ nsep_set_infoEp (int fd, struct eventpoll *ep)
if (NULL == epInfo)
return;
- epInfo->ep = (struct eventpoll *) ADDR_LTOSH (ep);
+ epInfo->ep = ep;
epInfo->fdtype = NSTACK_EPOL_FD;
}
@@ -944,7 +943,7 @@ nsep_get_infoEp (int fd)
if (NULL == epInfo)
return NULL;
- return (struct eventpoll *) ADDR_SHTOL (epInfo->ep);
+ return epInfo->ep;
}
int
@@ -1001,7 +1000,7 @@ nsep_init_infoSockMap ()
return 0;
}
-NSTACK_STATIC mzone_handle
+NSTACK_STATIC struct dmm_ring *
nsep_ring_lookup (char *name)
{
if (NULL == name)
@@ -1010,20 +1009,10 @@ nsep_ring_lookup (char *name)
return NULL;
}
- nsfw_mem_name mem_name;
- if (EOK != STRCPY_S (mem_name.aname, sizeof (mem_name.aname), name))
- {
- NSSOC_LOGERR ("Error to lookup ring by name, strcpy fail]name=%s",
- name);
- return NULL;
- }
- mem_name.enowner = NSFW_PROC_MAIN;
- mem_name.entype = NSFW_SHMEM;
-
- return nsfw_mem_ring_lookup (&mem_name);
+ return (struct dmm_ring *) dmm_lookup (name);
}
-NSTACK_STATIC mzone_handle
+NSTACK_STATIC void *
nsep_attach_shmem (char *name)
{
if (NULL == name)
@@ -1031,86 +1020,69 @@ nsep_attach_shmem (char *name)
NSSOC_LOGERR ("param error]name=%p", name);
return NULL;
}
-
- nsfw_mem_name mem_name;
- int retVal = STRCPY_S (mem_name.aname, sizeof (mem_name.aname), name);
- if (EOK != retVal)
- {
- NSSOC_LOGERR ("STRCPY_S failed]");
- return NULL;
- }
- mem_name.enowner = NSFW_PROC_MAIN;
- mem_name.entype = NSFW_SHMEM;
-
- return nsfw_mem_zone_lookup (&mem_name);
+ return dmm_lookup (name);
}
NSTACK_STATIC int
nsep_attach_infoMem ()
{
- mzone_handle hdl = nsep_attach_shmem (MP_NSTACK_EPOLL_INFO_NAME);
+ void *hdl = nsep_attach_shmem (MP_NSTACK_EPOLL_INFO_NAME);
if (NULL == hdl)
return -1;
nsep_epollManager_t *manager = nsep_getManager ();
manager->infoPool.pool = (nsep_epollInfo_t *) hdl;
- hdl = nsep_ring_lookup (MP_NSTACK_EPINFO_RING_NAME);
- if (NULL == hdl)
+ manager->infoPool.ring = nsep_ring_lookup (MP_NSTACK_EPINFO_RING_NAME);
+ if (NULL == manager->infoPool.ring)
{
NSSOC_LOGERR ("Fail to lock up epoll info ring]name=%s",
MP_NSTACK_EPINFO_RING_NAME);
return -1;
}
- manager->infoPool.ring = hdl;
-
return 0;
}
NSTACK_STATIC int
nsep_attach_epItemMem ()
{
- mzone_handle hdl = nsep_attach_shmem (MP_NSTACK_EPITEM_POOL);
+ void *hdl = nsep_attach_shmem (MP_NSTACK_EPITEM_POOL);
if (NULL == hdl)
return -1;
nsep_epollManager_t *manager = nsep_getManager ();
manager->epitemPool.pool = (struct epitem *) hdl;
- hdl = nsep_ring_lookup (MP_NSTACK_EPITEM_RING_NAME);
- if (NULL == hdl)
+ manager->epitemPool.ring = dmm_lookup (MP_NSTACK_EPITEM_RING_NAME);
+ if (NULL == manager->epitemPool.ring)
{
NSSOC_LOGERR ("Fail to lock up epoll info ring]name=%s",
MP_NSTACK_EPITEM_RING_NAME);
return -1;
}
- manager->epitemPool.ring = hdl;
-
return 0;
}
NSTACK_STATIC int
nsep_attach_eventpollMem ()
{
- mzone_handle hdl = nsep_attach_shmem (MP_NSTACK_EVENTPOLL_POOL);
+ void *hdl = nsep_attach_shmem (MP_NSTACK_EVENTPOLL_POOL);
if (NULL == hdl)
return -1;
nsep_epollManager_t *manager = nsep_getManager ();
manager->epollPool.pool = (struct eventpoll *) hdl;
- hdl = nsep_ring_lookup (MP_NSTACK_EVENTPOOL_RING_NAME);
- if (NULL == hdl)
+ manager->epollPool.ring = nsep_ring_lookup (MP_NSTACK_EVENTPOOL_RING_NAME);
+ if (NULL == manager->epollPool.ring)
{
NSSOC_LOGERR ("Fail to lock up epoll info ring]name=%s",
MP_NSTACK_EVENTPOOL_RING_NAME);
return -1;
}
- manager->epollPool.ring = hdl;
-
return 0;
}
diff --git a/src/nSocket/nstack/event/select/nstack_select.c b/src/nSocket/nstack/event/select/nstack_select.c
index 930f1db..6901274 100644
--- a/src/nSocket/nstack/event/select/nstack_select.c
+++ b/src/nSocket/nstack/event/select/nstack_select.c
@@ -17,6 +17,8 @@
/*==============================================*
* include header files *
*----------------------------------------------*/
+#include "pthread.h"
+#include "errno.h"
#include "nstack_select.h"
#include "nstack_log.h"
#include "nsfw_base_linux_api.h"
diff --git a/src/nSocket/nstack/nstack.c b/src/nSocket/nstack/nstack.c
index 4198266..67746f4 100644
--- a/src/nSocket/nstack/nstack.c
+++ b/src/nSocket/nstack/nstack.c
@@ -20,15 +20,12 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include "common_mem_buf.h"
-#include "common_mem_api.h"
#include "nstack_eventpoll.h"
#include "nstack_socket.h"
#include "nstack_securec.h"
#include "nsfw_init.h"
#include "nstack_share_res.h"
#include "nsfw_mgr_com_api.h"
-#include "nsfw_ps_mem_api.h"
#include "nsfw_fd_timer_api.h"
#include "nsfw_ps_api.h"
#include "nsfw_recycle_api.h"
@@ -38,7 +35,9 @@
#include "nstack_rd.h"
#include "nstack_module.h"
#include "nstack_select.h"
-#include "common_func.h"
+
+#include "dmm_memory.h"
+#include "dmm_sys.h"
#define NSTACK_EVENT_MEN_MAXLEN (sizeof(struct eventpoll_pool) + NSTACK_MAX_EPOLL_NUM * sizeof(struct eventpoll_entry))
#define NSTACK_EPITEM_MEN_MAXLEN (sizeof(struct epitem_pool) + NSTACK_MAX_EPITEM_NUM *sizeof(struct epitem_entry))
@@ -50,15 +49,13 @@ nStack_info_t g_nStackInfo = {
.load_mutex = PTHREAD_MUTEX_INITIALIZER,
.lk_sockPoll = NULL,
.pid = 0,
- .fork_lock = {0},
+ .fork_lock = DMM_RWLOCK_INIT,
.ikernelfdmax = NSTACK_MAX_SOCK_NUM,
};
/*if this flag was set, maybe all socket interface called during initializing*/
__thread int g_tloadflag = 0;
-extern u8 app_mode;
-
/*check init stack*/
#define NSTACK_INIT_STATE_CHECK_RET(state) do {\
if ((state) == NSTACK_MODULE_SUCCESS) \
@@ -376,8 +373,7 @@ NSTACK_STATIC inline void
check_main_version ()
{
char my_version[NSTACK_VERSION_LEN] = { 0 };
- nsfw_mem_name stname = { NSFW_SHMEM, NSFW_PROC_MAIN, {NSTACK_VERSION_SHM} };
- g_nStackInfo.nstack_version = nsfw_mem_zone_lookup (&stname);
+ g_nStackInfo.nstack_version = dmm_lookup(NSTACK_VERSION_SHM);
if (NULL == g_nStackInfo.nstack_version)
{
@@ -482,22 +478,22 @@ nstack_init_mem (void)
void
nstack_fork_fd_local_lock_info (nstack_fd_local_lock_info_t * local_lock)
{
- if (local_lock->fd_ref.counter > 1) /* after fork, if fd ref > 1, need set it to 1 */
+ if (local_lock->fd_ref.cnt > 1) /* after fork, if fd ref > 1, need set it to 1 */
{
- local_lock->fd_ref.counter = 1;
+ local_lock->fd_ref.cnt = 1;
}
- common_mem_spinlock_init (&local_lock->close_lock);
+ dmm_spin_init (&local_lock->close_lock);
}
void
nstack_reset_fd_local_lock_info (nstack_fd_local_lock_info_t * local_lock)
{
- atomic_set (&local_lock->fd_ref, 0);
- common_mem_spinlock_init (&local_lock->close_lock);
+ dmm_atomic_set (&local_lock->fd_ref, 0);
+ dmm_spin_init (&local_lock->close_lock);
local_lock->fd_status = FD_CLOSE;
}
-common_mem_rwlock_t *
+dmm_rwlock_t *
get_fork_lock ()
{
return &g_nStackInfo.fork_lock;
@@ -674,11 +670,11 @@ int nstack_stack_module_load()
NSTACK_INIT_STATE_CHECK_RET(g_nStackInfo.moduleload);
/*lock for fork*/
- common_mem_rwlock_read_lock(get_fork_lock());
+ dmm_read_lock(get_fork_lock());
if (pthread_mutex_lock(&g_nStackInfo.load_mutex)){
NSSOC_LOGERR("nstack mutex lock fail");
- common_mem_rwlock_read_unlock(get_fork_lock());
+ dmm_read_unlock(get_fork_lock());
return -1;
}
@@ -700,14 +696,14 @@ int nstack_stack_module_load()
NSTACK_THREAD_LOAD_UNSET();
g_nStackInfo.moduleload = NSTACK_MODULE_SUCCESS;
- common_mem_rwlock_read_unlock(get_fork_lock());
+ dmm_read_unlock(get_fork_lock());
pthread_mutex_unlock(&g_nStackInfo.load_mutex);
return 0;
LOAD_FAIL:
g_nStackInfo.moduleload = NSTACK_MODULE_FAIL;
NSTACK_THREAD_LOAD_UNSET();
- common_mem_rwlock_read_unlock(get_fork_lock());
+ dmm_read_unlock(get_fork_lock());
pthread_mutex_unlock(&g_nStackInfo.load_mutex);
return -1;
}
@@ -748,7 +744,6 @@ nstack_app_init (void *ppara)
int
nstack_fw_init ()
{
-
int ret = ns_fail;
if (NSTACK_MODULE_SUCCESS == g_nStackInfo.fwInited)
@@ -768,44 +763,45 @@ nstack_fw_init ()
return -1;
}
- common_mem_rwlock_read_lock (get_fork_lock ());
+ dmm_read_lock (get_fork_lock ());
updata_sys_pid ();
u8 proc_type = NSFW_PROC_APP;
- nsfw_mem_para stinfo = { 0 };
int deploytype = nstack_get_deploy_type();
if (deploytype == NSTACK_MODEL_TYPE1)
{
proc_type = NSFW_PROC_MAIN;
- }else if (deploytype == NSTACK_MODEL_TYPE_SIMPLE_STACK)
+ }
+ else if (deploytype == NSTACK_MODEL_TYPE_SIMPLE_STACK)
{
proc_type = NSFW_PROC_MAIN;
- app_mode=1;
}
- stinfo.iargsnum = 0;
- stinfo.pargs = NULL;
- stinfo.enflag = (fw_poc_type)proc_type;
- nstack_framework_setModuleParam(NSFW_MEM_MGR_MODULE, (void*)&stinfo);
- nstack_framework_setModuleParam(NSFW_MGR_COM_MODULE, (void*) ((long long)proc_type));
- nstack_framework_setModuleParam(NSFW_TIMER_MODULE, (void*) ((long long)proc_type));
- nstack_framework_setModuleParam(NSFW_PS_MODULE, (void*) ((long long)proc_type));
- nstack_framework_setModuleParam(NSFW_PS_MEM_MODULE, (void*) ((long long)proc_type));
- nstack_framework_setModuleParam(NSFW_RECYCLE_MODULE, (void*) ((long long)proc_type));
+ (void) nstack_framework_setModuleParam (DMM_MEMORY_MODULE,
+ (void *) ((u64) NSFW_PROC_APP));
+
+ nstack_framework_setModuleParam(NSFW_MGR_COM_MODULE,
+ (void*) ((long long)proc_type));
+ nstack_framework_setModuleParam(NSFW_TIMER_MODULE,
+ (void*) ((long long)proc_type));
+ nstack_framework_setModuleParam(NSFW_PS_MODULE,
+ (void*) ((long long)proc_type));
+ nstack_framework_setModuleParam(NSFW_RECYCLE_MODULE,
+ (void*) ((long long)proc_type));
NSTACK_THREAD_LOAD_SET();
ret = nstack_framework_init();
if (ns_success == ret)
{
- g_nStackInfo.fwInited = NSTACK_MODULE_SUCCESS;
+ g_nStackInfo.fwInited = NSTACK_MODULE_SUCCESS;
}
else
{
- g_nStackInfo.fwInited = NSTACK_MODULE_FAIL;
+ g_nStackInfo.fwInited = NSTACK_MODULE_FAIL;
}
NSTACK_THREAD_LOAD_UNSET();
- common_mem_rwlock_read_unlock(get_fork_lock());
+ dmm_read_unlock(get_fork_lock());
}
return ret;
diff --git a/src/nSocket/nstack/nstack.h b/src/nSocket/nstack/nstack.h
index 1ec88f0..1fbd37e 100644
--- a/src/nSocket/nstack/nstack.h
+++ b/src/nSocket/nstack/nstack.h
@@ -17,6 +17,10 @@
#ifndef _NSTACK_H_
#define _NSTACK_H_
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/socket.h>
#include <pthread.h>
#include <time.h>
@@ -27,22 +31,12 @@
#include "nstack_log.h"
#include "nstack_module.h"
#include "nstack_fd_mng.h"
-
#include "nstack_types.h"
#include "nstack_eventpoll.h"
-#include "common_mem_api.h"
#include "nstack_select.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "nstack_atomic.h"
-#include "common_mem_spinlock.h"
-#include "generic/common_mem_rwlock.h"
-
-#include "nsfw_mem_api.h"
#include "nsfw_recycle_api.h"
+#include "dmm_rwlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -73,7 +67,7 @@ typedef struct
*/
nstack_fd_Inf *lk_sockPoll;
- common_mem_rwlock_t fork_lock; /* to ensure that there is no fd to create and close when fork */
+ dmm_rwlock_t fork_lock; /* to ensure that there is no fd to create and close when fork */
uint32_t pid;
char *nstack_version;
int checkEpollFD;
@@ -109,7 +103,7 @@ void nstack_fork_fd_local_lock_info (nstack_fd_local_lock_info_t *
local_lock);
void nstack_reset_fd_local_lock_info (nstack_fd_local_lock_info_t *
local_lock);
-common_mem_rwlock_t *get_fork_lock ();
+dmm_rwlock_t *get_fork_lock ();
int nstack_for_epoll_init ();
int nstack_stack_module_load ();
diff --git a/src/nSocket/nstack/nstack_fd_mng.c b/src/nSocket/nstack/nstack_fd_mng.c
index ba9b8f1..fe643ee 100644
--- a/src/nSocket/nstack/nstack_fd_mng.c
+++ b/src/nSocket/nstack/nstack_fd_mng.c
@@ -26,6 +26,9 @@
#include "nstack_socket.h"
#include "nstack_securec.h"
#include "nstack_sockops.h"
+#include "nsfw_mgr_com_api.h"
+
+#include "dmm_sys.h"
/* test_epollCtl_004_001_trial : both 32bit and 64bit members of 'ops' and 'conn'
need to reset, otherwise it will be invalid address in 32bit APP case */
diff --git a/src/nSocket/nstack/nstack_fd_mng.h b/src/nSocket/nstack/nstack_fd_mng.h
index cb25e8e..d05dc8d 100644
--- a/src/nSocket/nstack/nstack_fd_mng.h
+++ b/src/nSocket/nstack/nstack_fd_mng.h
@@ -18,15 +18,12 @@
#define __NSTACK_FD_MNG_H__
#include <semaphore.h>
-#include "nstack_atomic.h"
#include "types.h"
#include "nstack_module.h"
#include "nstack_types.h"
#include "nstack_eventpoll.h"
-#include "common_mem_spinlock.h"
-#include "common_mem_api.h"
-#include "common_func.h"
+#include "dmm_spinlock.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -114,8 +111,8 @@ typedef struct
typedef struct
{
- atomic_t fd_ref;
- common_mem_spinlock_t close_lock;
+ dmm_atomic_t fd_ref;
+ dmm_spinlock_t close_lock;
volatile int fd_status;
} nstack_fd_local_lock_info_t;
/*
diff --git a/src/nSocket/nstack/nstack_module.c b/src/nSocket/nstack/nstack_module.c
index 9566ab8..c167232 100644
--- a/src/nSocket/nstack/nstack_module.c
+++ b/src/nSocket/nstack/nstack_module.c
@@ -29,7 +29,6 @@
#include <arpa/inet.h>
#include <errno.h>
#include "nstack_module.h"
-#include "common_mem_buf.h"
#include "nstack_log.h"
#include "nstack_securec.h"
#include "nstack_dmm_api.h"
diff --git a/src/nSocket/nstack/nstack_nsocket_construct.c b/src/nSocket/nstack/nstack_nsocket_construct.c
index 0b447b7..1bf518c 100644
--- a/src/nSocket/nstack/nstack_nsocket_construct.c
+++ b/src/nSocket/nstack/nstack_nsocket_construct.c
@@ -15,7 +15,6 @@
*/
#include "nsfw_init.h"
-#include "nsfw_mem_api.h"
#include "nsfw_mgr_com_api.h"
#include "nsfw_recycle_api.h"
@@ -30,9 +29,9 @@ extern "C"{
extern int nstack_app_init (void *ppara);
/* *INDENT-OFF* */
NSFW_MODULE_NAME (NSACK_NSOCKET_MODULE)
-NSFW_MODULE_PRIORITY (7)
+NSFW_MODULE_PRIORITY (90)
NSFW_MODULE_DEPENDS (NSFW_MGR_COM_MODULE)
-NSFW_MODULE_DEPENDS (NSFW_MEM_MGR_MODULE)
+//NSFW_MODULE_DEPENDS (NSFW_MEM_MGR_MODULE)
NSFW_MODULE_DEPENDS (NSFW_RECYCLE_MODULE)
NSFW_MODULE_INIT (nstack_app_init)
/* *INDENT-ON* */
diff --git a/src/nSocket/nstack/nstack_socket.c b/src/nSocket/nstack/nstack_socket.c
index cd1557b..1b7a416 100644
--- a/src/nSocket/nstack/nstack_socket.c
+++ b/src/nSocket/nstack/nstack_socket.c
@@ -25,6 +25,7 @@
#define _GNU_SOURCE /* define RTLD_NEXT */
#endif
+#include <errno.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
@@ -34,7 +35,6 @@
#include "nstack_dmm_api.h"
#include "nstack_sockops.h"
#include "nstack_module.h"
-#include "common_mem_spinlock.h"
#include "nstack_securec.h"
#include "nsfw_init.h"
#include "nsfw_recycle_api.h"
@@ -44,6 +44,9 @@
#include "select_adapt.h"
#include "nstack_select.h"
#include "nstack_share_res.h"
+
+#include "dmm_sys.h"
+
#ifndef F_SETFL
#define F_SETFL 4
#endif
@@ -116,7 +119,7 @@ set_fd_status (int fd, FD_STATUS status)
{
if (FD_OPEN == status)
{
- atomic_inc (&local_lock->fd_ref);
+ dmm_atomic_inc (&local_lock->fd_ref);
}
local_lock->fd_status = status;
}
@@ -125,9 +128,9 @@ set_fd_status (int fd, FD_STATUS status)
void
set_fd_status_lock_fork (int fd, FD_STATUS status)
{
- common_mem_rwlock_read_lock (get_fork_lock ());
+ dmm_read_lock (get_fork_lock ());
set_fd_status (fd, status);
- common_mem_rwlock_read_unlock (get_fork_lock ());
+ dmm_read_unlock (get_fork_lock ());
}
/*****************************************************************
@@ -999,7 +1002,7 @@ release_fd (int fd, nstack_fd_local_lock_info_t * local_lock)
LOCK_CLOSE (local_lock);
/* if fd is used by others, just pass, delay close it */
- if (local_lock->fd_status != FD_CLOSING || local_lock->fd_ref.counter > 0)
+ if (local_lock->fd_status != FD_CLOSING || local_lock->fd_ref.cnt > 0)
{
UNLOCK_CLOSE (local_lock);
return 0;
@@ -1112,8 +1115,10 @@ nstack_close (int fd)
set_fd_status_lock_fork (fd, FD_CLOSING);
UNLOCK_CLOSE (local_lock);
- ret =
- (atomic_dec (&local_lock->fd_ref) > 0 ? 0 : release_fd (fd, local_lock));
+ if (dmm_atomic_sub_return (&local_lock->fd_ref, 1) > 0)
+ ret = 0;
+ else
+ ret = release_fd (fd, local_lock);
if (-1 == ret)
{
@@ -2404,7 +2409,7 @@ nstack_epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
goto err_return;
}
- ep = ADDR_SHTOL (epInfo->ep);
+ ep = epInfo->ep;
if (NULL == ep)
{
NSSOC_LOGWAR ("ep of epfd=%d is NULL [return]", epfd);
@@ -2427,7 +2432,7 @@ nstack_epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
}
}
- sys_arch_lock_with_pid (&ep->sem);
+ dmm_spin_lock_pid (&ep->sem);
epi = nsep_find_ep (ep, fd);
switch (op)
@@ -2436,9 +2441,9 @@ nstack_epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
if (!epi)
{
ep_event.events |= (EPOLLERR | EPOLLHUP); // Check `man epoll_ctl` if you don't understand , smile :)
- common_mem_rwlock_read_lock (get_fork_lock ()); /* to ensure that there is no fd to create and close when fork. added by tongshaojun t00391048 */
+ dmm_read_lock (get_fork_lock ()); /* to ensure that there is no fd to create and close when fork. added by tongshaojun t00391048 */
ret = nsep_epctl_add (ep, fd, &ep_event);
- common_mem_rwlock_read_unlock (get_fork_lock ());
+ dmm_read_unlock (get_fork_lock ());
}
else
{
@@ -2450,9 +2455,9 @@ nstack_epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
case EPOLL_CTL_DEL:
if (epi)
{
- common_mem_rwlock_read_lock (get_fork_lock ());
+ dmm_read_lock (get_fork_lock ());
ret = nsep_epctl_del (ep, epi);
- common_mem_rwlock_read_unlock (get_fork_lock ());
+ dmm_read_unlock (get_fork_lock ());
}
else
{
@@ -2480,7 +2485,7 @@ nstack_epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
ret = -1;
}
- sys_sem_s_signal (&ep->sem);
+ dmm_spin_unlock (&ep->sem);
NSSOC_LOGINF ("epfd=%d,op=%d,fd=%d,ret=%d [return]", epfd, op, fd, ret);
err_return:
@@ -2664,7 +2669,7 @@ nstack_epoll_wait (int epfd, struct epoll_event *events, int maxevents,
return -1;
}
- ep = ADDR_SHTOL (epInfo->ep);
+ ep = epInfo->ep;
if (NULL == ep)
{
NSSOC_LOGWAR ("fdInf->ep is NULL, return -1,epinfo=%p,epfd=%d", epInfo,
@@ -2760,11 +2765,13 @@ nstack_fork (void)
NSTACK_INIT_CHECK_RET (fork);
- common_mem_rwlock_write_lock (get_fork_lock ());
+ dmm_write_lock (get_fork_lock ());
if (NSTACK_MODULE_SUCCESS == g_nStackInfo.fwInited)
{
+ dmm_spinlock_t *fork_lock = nstack_get_fork_share_lock ();
+
nstack_fork_init_parent (parent_pid);
- dmm_spinlock_lock_with_pid (nstack_get_fork_share_lock (), parent_pid);
+ dmm_spin_lock_with (fork_lock, parent_pid);
pid = nsfw_base_fork ();
if (pid == 0)
{
@@ -2772,24 +2779,23 @@ nstack_fork (void)
nstack_log_lock_release ();
nstack_fork_init_child (parent_pid);
(void) nstack_for_epoll_init ();
- dmm_spinlock_lock_with_pid (nstack_get_fork_share_lock (),
- get_sys_pid ());
+ dmm_spin_lock_with (fork_lock, get_sys_pid ());
nsep_fork_child_proc (parent_pid);
(void) select_module_init_child ();
- common_mem_spinlock_unlock (nstack_get_fork_share_lock ());
+ dmm_spin_unlock (fork_lock);
}
else if (pid > 0)
{
pid_t child_pid = get_hostpid_from_file (pid);
nsep_fork_parent_proc (parent_pid, child_pid);
- common_mem_spinlock_unlock (nstack_get_fork_share_lock ());
+ dmm_spin_unlock (fork_lock);
sys_sleep_ns (0, 10000000); /* wait child add pid for netconn */
}
else
{
NSSOC_LOGERR ("fork failed]parent_pid=%d", parent_pid);
- common_mem_spinlock_unlock (nstack_get_fork_share_lock ());
+ dmm_spin_unlock (fork_lock);
}
}
else
@@ -2803,6 +2809,6 @@ nstack_fork (void)
parent_pid, pid);
}
- common_mem_rwlock_write_unlock (get_fork_lock ());
+ dmm_write_unlock (get_fork_lock ());
return pid;
}
diff --git a/src/nSocket/nstack/nstack_socket.h b/src/nSocket/nstack/nstack_socket.h
index 3bb7843..3c47f79 100644
--- a/src/nSocket/nstack/nstack_socket.h
+++ b/src/nSocket/nstack/nstack_socket.h
@@ -19,6 +19,7 @@
#include <sys/socket.h>
#include <poll.h>
#include <sys/epoll.h>
+#include "dmm_atomic.h"
#undef NSTACK_MK_DECL
#define NSTACK_MK_DECL(ret, fn, args) extern ret nstack_##fn args
@@ -56,7 +57,8 @@ int nstack_socket (int domain, int itype, int protocol);
static inline void
UNLOCK_SEND (int fd, nstack_fd_local_lock_info_t * local_lock)
{
- if ((NULL != local_lock) && atomic_dec (&local_lock->fd_ref) == 0)
+ if ((NULL != local_lock) &&
+ dmm_atomic_sub_return (&local_lock->fd_ref, 1) == 0)
{
release_fd (fd, local_lock);
}
@@ -88,7 +90,8 @@ UNLOCK_SEND (int fd, nstack_fd_local_lock_info_t * local_lock)
static inline void
UNLOCK_EPOLL (int fd, nstack_fd_local_lock_info_t * local_lock)
{
- if ((NULL != local_lock) && atomic_dec (&local_lock->fd_ref) == 0)
+ if ((NULL != local_lock)
+ && dmm_atomic_sub_return (&local_lock->fd_ref, 1) == 0)
{
release_fd (fd, local_lock);
}
@@ -97,8 +100,8 @@ UNLOCK_EPOLL (int fd, nstack_fd_local_lock_info_t * local_lock)
#define LOCK_EPOLL_CTRL(fd_val, local_lock, epoll_fd, epoll_local_lock){\
if (local_lock)\
{\
- atomic_inc(&local_lock->fd_ref);\
- common_mem_spinlock_lock(&local_lock->close_lock);\
+ dmm_atomic_inc(&local_lock->fd_ref);\
+ dmm_spin_lock(&local_lock->close_lock);\
nstack_fd_Inf* fd_inf = nstack_getValidInf(fd_val);\
if (fd_inf)\
{\
@@ -106,8 +109,8 @@ UNLOCK_EPOLL (int fd, nstack_fd_local_lock_info_t * local_lock)
{\
NSSOC_LOGWAR("fd %d is not open [return]", fd_val);\
nstack_set_errno(EBADF);\
- common_mem_spinlock_unlock(&local_lock->close_lock);\
- if(atomic_dec(&local_lock->fd_ref)==0){ \
+ dmm_spin_unlock(&local_lock->close_lock);\
+ if(dmm_atomic_sub_return(&local_lock->fd_ref, 1)==0){ \
release_fd(fd_val, local_lock);\
}\
UNLOCK_EPOLL(epoll_fd, epoll_local_lock);\
@@ -122,8 +125,8 @@ UNLOCK_EPOLL_CTRL (int fd, nstack_fd_local_lock_info_t * local_lock)
{
if (local_lock)
{
- common_mem_spinlock_unlock (&local_lock->close_lock);
- if (atomic_dec (&local_lock->fd_ref) == 0)
+ dmm_spin_unlock (&local_lock->close_lock);
+ if (dmm_atomic_sub_return (&local_lock->fd_ref, 1) == 0)
{
release_fd (fd, local_lock);
}
@@ -133,12 +136,12 @@ UNLOCK_EPOLL_CTRL (int fd, nstack_fd_local_lock_info_t * local_lock)
#define INC_FD_REF(fd, fd_inf, local_lock){ \
if (local_lock)\
{\
- atomic_inc(&local_lock->fd_ref);\
+ dmm_atomic_inc(&local_lock->fd_ref);\
if (local_lock->fd_status != FD_OPEN)\
{\
nstack_set_errno(EBADF);\
NSSOC_LOGERR("nstack call, fd_status=%d [return]", local_lock->fd_status); \
- if(atomic_dec(&local_lock->fd_ref) == 0){ \
+ if(dmm_atomic_sub_return(&local_lock->fd_ref, 1) == 0){ \
release_fd(fd, local_lock);\
}\
return -1;\
@@ -158,7 +161,8 @@ UNLOCK_EPOLL_CTRL (int fd, nstack_fd_local_lock_info_t * local_lock)
static inline void
UNLOCK_BASE (int fd, nstack_fd_local_lock_info_t * local_lock)
{
- if ((NULL != local_lock) && (atomic_dec (&local_lock->fd_ref) == 0))
+ if ((NULL != local_lock)
+ && (dmm_atomic_sub_return (&local_lock->fd_ref, 1) == 0))
{
release_fd (fd, local_lock);
}
@@ -173,7 +177,7 @@ UNLOCK_BASE (int fd, nstack_fd_local_lock_info_t * local_lock)
#define LOCK_CLOSE(local_lock){\
if (local_lock)\
{\
- common_mem_spinlock_lock(&local_lock->close_lock);\
+ dmm_spin_lock(&local_lock->close_lock);\
}\
}
@@ -182,7 +186,7 @@ UNLOCK_CLOSE (nstack_fd_local_lock_info_t * local_lock)
{
if (local_lock)
{
- common_mem_spinlock_unlock (&local_lock->close_lock);
+ dmm_spin_unlock (&local_lock->close_lock);
}
}
diff --git a/src/nSocket/nstack_rd/nstack_rd_ip.c b/src/nSocket/nstack_rd/nstack_rd_ip.c
index bcbe731..5297d4a 100644
--- a/src/nSocket/nstack_rd/nstack_rd_ip.c
+++ b/src/nSocket/nstack_rd/nstack_rd_ip.c
@@ -26,6 +26,8 @@
#include "nstack_ip_addr.h"
+#include "dmm_common.h"
+
#define NSTACK_IP_MLSTACKID RD_STACKX_NAME
#define PP_HTONL(x) ((((x) & 0xff) << 24) | \
diff --git a/src/nSocket/nstack_rd/nstack_rd_proto.c b/src/nSocket/nstack_rd/nstack_rd_proto.c
index 81246c0..a227391 100644
--- a/src/nSocket/nstack_rd/nstack_rd_proto.c
+++ b/src/nSocket/nstack_rd/nstack_rd_proto.c
@@ -23,7 +23,8 @@
#include "nstack_rd_proto.h"
#include "nstack_log.h"
#include "nstack_securec.h"
-#include "common_mem_common.h"
+
+#include "dmm_common.h"
/*copy rd data*/
int