summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-07-15 05:58:06 (GMT)
committer Hanhui <sylixos@gmail.com>2019-06-19 09:04:05 (GMT)
commit504ba40e3b00d12d871367f9514a93c7b8adde1c (patch)
treedaead23fb7f9c333bea81694010ea9c7c52ae5b9
parent3d1e2cf4710336a779b274582f6f38642ac2acf0 (diff)
downloadAIC-OS-504ba40e3b00d12d871367f9514a93c7b8adde1c.zip
Add memory pre-allocation mechanism for anonymous mapping to improve AI operation efficiency.
-rw-r--r--SylixOS/CHANGELOG3
-rw-r--r--SylixOS/kernel/include/k_kernel.h2
-rw-r--r--SylixOS/kernel/vmm/vmmMmap.c49
-rw-r--r--SylixOS/kernel/vmm/vmmSwap.h5
-rw-r--r--SylixOS/posix/include/px_mman.h8
-rw-r--r--SylixOS/posix/mman/mman.c4
-rw-r--r--SylixOS/vpmpdm/dlmalloc/dlmalloc.c3
-rw-r--r--SylixOS/vpmpdm/dlmalloc/dlmalloc.h2
-rw-r--r--SylixOS/vpmpdm/vpmpdm.c2
9 files changed, 59 insertions, 19 deletions
diff --git a/SylixOS/CHANGELOG b/SylixOS/CHANGELOG
index 6673e22..a29e14e 100644
--- a/SylixOS/CHANGELOG
+++ b/SylixOS/CHANGELOG
@@ -4,6 +4,9 @@ HISTORY
++ New features:
+ 2019-07-15: han.hui
+ 加入 mmap 匿名映射的内存预分配机制, 提高 AI 运算效率.
+
2019-03-07: han.hui
加入 ISO9660 光盘文件系统支持.
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index b08c77e..ed44732 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -51,7 +51,7 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 10
-#define __SYLIXOS_PATCH_VER 1
+#define __SYLIXOS_PATCH_VER 2
#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
diff --git a/SylixOS/kernel/vmm/vmmMmap.c b/SylixOS/kernel/vmm/vmmMmap.c
index 57f4755..45572be 100644
--- a/SylixOS/kernel/vmm/vmmMmap.c
+++ b/SylixOS/kernel/vmm/vmmMmap.c
@@ -245,7 +245,7 @@ __full_with_zero:
** 功能描述: 分配虚拟空间
** 输 入 : pmapn mmap node
** stLen 内存大小
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag 虚拟空间内存属性
** 输 出 : 内存地址
** 全局变量:
@@ -255,9 +255,14 @@ static PVOID __vmmMapnMalloc (PLW_VMM_MAP_NODE pmapn, size_t stLen, INT iFla
{
REGISTER PVOID pvMem;
- pvMem = API_VmmMallocAreaEx(stLen, __vmmMapnFill, pmapn, iFlags, ulFlag);
- if (pvMem) {
- API_VmmSetFindShare(pvMem, __vmmMapnFindShare, pmapn);
+ if (iFlags & LW_VMM_PHY_PREALLOC) {
+ pvMem = API_VmmMallocEx(stLen, ulFlag);
+
+ } else {
+ pvMem = API_VmmMallocAreaEx(stLen, __vmmMapnFill, pmapn, iFlags, ulFlag);
+ if (pvMem) {
+ API_VmmSetFindShare(pvMem, __vmmMapnFindShare, pmapn);
+ }
}
return (pvMem);
@@ -353,7 +358,7 @@ static VOID __vmmMapnReclaim (PLW_VMM_MAP_NODE pmapn, LW_LD_VPROC *pvproc)
** 函数名称: __vmmMmapNew
** 功能描述: 分配一段新的虚拟内存
** 输 入 : stLen 映射长度
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag LW_VMM_FLAG_READ | LW_VMM_FLAG_RDWR | LW_VMM_FLAG_EXEC
** iFd 文件描述符
** off 文件偏移量
@@ -379,10 +384,10 @@ static PVOID __vmmMmapNew (size_t stLen, INT iFlags, ULONG ulFlag, int iFd,
if (iosFdGetFlag(iFd, &iFileFlag) < 0) { /* 获得文件权限 */
_ErrorHandle(EBADF);
return (LW_VMM_MAP_FAILED);
- }
+ }
iFileFlag &= O_ACCMODE;
- if (iFlags == LW_VMM_SHARED_CHANGE) {
+ if (iFlags & LW_VMM_SHARED_CHANGE) {
if ((ulFlag & LW_VMM_FLAG_WRITABLE) &&
(iFileFlag == O_RDONLY)) { /* 带有写权限映射只读文件 */
_ErrorHandle(EACCES);
@@ -532,6 +537,12 @@ static PVOID __vmmMmapChange (PVOID pvAddr, size_t stLen, INT iFlags,
return (LW_VMM_MAP_FAILED);
}
+ if ((iFlags & LW_VMM_PHY_PREALLOC) ||
+ (pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC)) { /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (LW_VMM_MAP_FAILED);
+ }
+
if ((pmapn->MAPN_iFd != iFd) ||
(pmapn->MAPN_off != off) ||
(pmapn->MAPN_iFlags != iFlags) ||
@@ -719,7 +730,7 @@ static VOID __vmmMmapMerge (PLW_VMM_MAP_NODE pmapnL, PLW_VMM_MAP_NODE pmapnR)
** 功能描述: 内存文件映射.
** 输 入 : pvAddr 虚拟地址
** stLen 映射长度
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag LW_VMM_FLAG_READ | LW_VMM_FLAG_RDWR | LW_VMM_FLAG_EXEC
** iFd 文件描述符
** off 文件偏移量
@@ -733,8 +744,8 @@ PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, IN
{
PVOID pvRet;
- if ((iFlags != LW_VMM_SHARED_CHANGE) &&
- (iFlags != LW_VMM_PRIVATE_CHANGE)) {
+ if ((iFlags & LW_VMM_SHARED_CHANGE) &&
+ (iFlags & LW_VMM_PRIVATE_CHANGE)) { /* 不允许同时出现两个 */
_ErrorHandle(EINVAL);
return (LW_VMM_MAP_FAILED);
}
@@ -747,7 +758,7 @@ PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, IN
stLen = ROUND_UP(stLen, LW_CFG_VMM_PAGE_SIZE); /* 变成页面对齐大小 */
#if LW_CFG_CACHE_EN > 0
- if (iFlags == LW_VMM_SHARED_CHANGE) {
+ if (iFlags & LW_VMM_SHARED_CHANGE) {
if (API_CacheAliasProb()) { /* 如果有 CACHE 别名可能 */
ulFlag &= ~(LW_VMM_FLAG_CACHEABLE | LW_VMM_FLAG_WRITETHROUGH);
} /* 共享内存不允许任何形式 CACHE*/
@@ -799,6 +810,11 @@ PVOID API_VmmMremap (PVOID pvAddr, size_t stOldSize, size_t stNewSize, INT iM
return (LW_VMM_MAP_FAILED);
}
+ if (pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC) { /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (LW_VMM_MAP_FAILED);
+ }
+
if ((pmapn->MAPN_pvAddr != pvAddr) ||
(pmapn->MAPN_stLen != stOldSize)) { /* 只支持完整空间操作 */
__VMM_MMAP_UNLOCK();
@@ -860,6 +876,13 @@ __goon:
return (PX_ERROR);
}
+ if ((pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC) &&
+ ((pmapn->MAPN_pvAddr != pvAddr) || (pmapn->MAPN_stLen != stLen))) {
+ __VMM_MMAP_UNLOCK(); /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (PX_ERROR);
+ }
+
pmapnL = LW_NULL;
if (pmapn->MAPN_pvAddr != pvAddr) { /* 将左侧分段隔开 */
@@ -1027,7 +1050,7 @@ INT API_VmmMsync (PVOID pvAddr, size_t stLen, INT iInval)
if (iInval) {
API_VmmInvalidateArea(pmapn->MAPN_pvAddr, pvAddr, stLen); /* 释放对应的物理内存 */
- } else if (pmapn->MAPN_iFlags == LW_VMM_SHARED_CHANGE) { /* SHARED 类型可以回写文件 */
+ } else if (pmapn->MAPN_iFlags & LW_VMM_SHARED_CHANGE) { /* SHARED 类型可以回写文件 */
INT i;
ULONG ulPageNum;
size_t stExcess;
@@ -1116,7 +1139,7 @@ VOID API_VmmMmapShow (VOID)
pcWrite = "false";
}
- if (pmapn->MAPN_iFlags == LW_VMM_SHARED_CHANGE) {
+ if (pmapn->MAPN_iFlags & LW_VMM_SHARED_CHANGE) {
pcShare = "true ";
} else {
pcShare = "false";
diff --git a/SylixOS/kernel/vmm/vmmSwap.h b/SylixOS/kernel/vmm/vmmSwap.h
index e3887b6..ddf5e85 100644
--- a/SylixOS/kernel/vmm/vmmSwap.h
+++ b/SylixOS/kernel/vmm/vmmSwap.h
@@ -56,8 +56,9 @@ typedef struct {
LW_LIST_LINE PAGEP_lineManage; /* area 链表 */
PLW_VMM_PAGE PAGEP_pvmpageVirtual; /* 回指虚拟页面控制块 */
-#define LW_VMM_SHARED_CHANGE 1
-#define LW_VMM_PRIVATE_CHANGE 2
+#define LW_VMM_SHARED_CHANGE 0x1 /* 共享更改 */
+#define LW_VMM_PRIVATE_CHANGE 0x2 /* 写时拷贝 */
+#define LW_VMM_PHY_PREALLOC 0x4 /* 物理内存预分配 */
INT PAGEP_iFlags; /* like mmap flags */
FUNCPTR PAGEP_pfuncFiller; /* 页面填充器 */
diff --git a/SylixOS/posix/include/px_mman.h b/SylixOS/posix/include/px_mman.h
index 993210f..c01dba5 100644
--- a/SylixOS/posix/include/px_mman.h
+++ b/SylixOS/posix/include/px_mman.h
@@ -60,6 +60,14 @@ extern "C" {
#endif
/*********************************************************************************************************
+ extends flag
+*********************************************************************************************************/
+
+#if defined(__SYLIXOS_EXTEND) || defined(__SYLIXOS_KERNEL)
+#define MAP_PREALLOC 0x8000 /* MAP_ANON pre alloc memory */
+#endif
+
+/*********************************************************************************************************
msync() flag
*********************************************************************************************************/
diff --git a/SylixOS/posix/mman/mman.c b/SylixOS/posix/mman/mman.c
index 55c374e..ce46df8 100644
--- a/SylixOS/posix/mman/mman.c
+++ b/SylixOS/posix/mman/mman.c
@@ -231,6 +231,10 @@ void *mmap (void *pvAddr, size_t stLen, int iProt, int iFlag, int iFd, off
return (MAP_FAILED);
}
+ if ((iFlag & MAP_ANONYMOUS) && (iFlag & MAP_PREALLOC) && (pvAddr == LW_NULL)) {
+ iFlags |= LW_VMM_PHY_PREALLOC; /* 内存管理预分配 */
+ }
+
pvRet = API_VmmMmap(pvAddr, stLen, iFlags, ulFlag, iFd, off);
return ((pvRet != LW_VMM_MAP_FAILED) ? pvRet : MAP_FAILED);
diff --git a/SylixOS/vpmpdm/dlmalloc/dlmalloc.c b/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
index 38084c0..9fcba24 100644
--- a/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
+++ b/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
@@ -521,6 +521,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
improvement at the expense of carrying around more memory.
*/
+#define __SYLIXOS_EXTEND
#include "dlmalloc.h"
/* Version identifier to allow people to support multiple versions */
@@ -1644,7 +1645,7 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
#define MAP_ANONYMOUS MAP_ANON
#endif /* MAP_ANON */
#ifdef MAP_ANONYMOUS
-#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
+#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS|MAP_PREALLOC) /* SylixOS Add 'MAP_PREALLOC' */
#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
#else /* MAP_ANONYMOUS */
/*
diff --git a/SylixOS/vpmpdm/dlmalloc/dlmalloc.h b/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
index cdf29d4..012f880 100644
--- a/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
+++ b/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
@@ -59,7 +59,7 @@ void dlmalloc_abort(void);
#define DIRECT_MMAP dlmalloc_mmap
#define MREMAP dlmalloc_mremap
-#define DEFAULT_MMAP_THRESHOLD (256 * 1024) /* 256K */
+#define DEFAULT_MMAP_THRESHOLD (128 * 1024) /* 128K */
#endif /* LW_CFG_VMM_EN > 0 */
/* Abort */
diff --git a/SylixOS/vpmpdm/vpmpdm.c b/SylixOS/vpmpdm/vpmpdm.c
index 17fb530..82fd5c9 100644
--- a/SylixOS/vpmpdm/vpmpdm.c
+++ b/SylixOS/vpmpdm/vpmpdm.c
@@ -58,7 +58,7 @@
#include "./loader/include/loader_lib.h" /* need __eabi */
#endif /* LW_CFG_CPU_ARCH_PPC */
-#define __VP_PATCH_VERSION "2.1.4" /* vp patch version */
+#define __VP_PATCH_VERSION "2.1.5" /* vp patch version */
/*
* fixed gcc old version.