summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2020-10-12 11:59:42 (GMT)
committer Hanhui <hanhui@acoinfo.com>2020-10-12 11:59:42 (GMT)
commit9cb7c36f1be725eb2f0e4e8633c31376e834631b (patch)
tree472778cfdf8e6ee6c7afcef42e8a6b23924ec985 /SylixOS
parent671bf5466dc97c1e2c06ffb879ef6d3d408420db (diff)
downloadlibsylixos-9cb7c36f1be725eb2f0e4e8633c31376e834631b.zip
libsylixos-9cb7c36f1be725eb2f0e4e8633c31376e834631b.tar.gz
libsylixos-9cb7c36f1be725eb2f0e4e8633c31376e834631b.tar.bz2
Fixed task activation sequence of broadcast events.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/CHANGELOG4
-rw-r--r--SylixOS/driver/sio/16c550.c49
-rw-r--r--SylixOS/driver/sio/16c550.h6
-rw-r--r--SylixOS/kernel/core/_EventHighLevel.c10
-rw-r--r--SylixOS/kernel/core/_Sched.c6
-rw-r--r--SylixOS/kernel/core/_SmpSpinlock.c18
-rw-r--r--SylixOS/kernel/core/_UpSpinlock.c10
-rw-r--r--SylixOS/kernel/include/k_cpu.h11
-rw-r--r--SylixOS/kernel/include/k_internal.h2
-rw-r--r--SylixOS/kernel/include/k_kernel.h4
-rw-r--r--SylixOS/kernel/interface/MsgQueueClear.c4
-rw-r--r--SylixOS/kernel/interface/MsgQueueDelete.c8
-rw-r--r--SylixOS/kernel/interface/MsgQueueFlush.c8
-rw-r--r--SylixOS/kernel/interface/MsgQueueReceive.c8
-rw-r--r--SylixOS/kernel/interface/MsgQueueSend.c4
-rw-r--r--SylixOS/kernel/interface/MsgQueueSendEx.c8
-rw-r--r--SylixOS/kernel/interface/MsgQueueTryReceive.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreBDelete.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreBFlush.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreBPost.c8
-rw-r--r--SylixOS/kernel/interface/SemaphoreBPostEx.c8
-rw-r--r--SylixOS/kernel/interface/SemaphoreBRelease.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreCDelete.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreCFlush.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreCPost.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreCRelease.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreMDelete.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreMPost.c4
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWDelete.c8
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWPost.c8
-rw-r--r--SylixOS/kernel/vmm/phyPage.c21
-rw-r--r--SylixOS/kernel/vmm/phyPage.h2
-rw-r--r--SylixOS/kernel/vmm/vmmAbort.c27
-rw-r--r--SylixOS/kernel/vmm/vmmMmap.c45
-rw-r--r--SylixOS/kmodule/xtimer/xtimer.c63
-rw-r--r--SylixOS/kmodule/xtimer/xtimer.h9
-rw-r--r--SylixOS/posix/aio/aio.c6
-rw-r--r--SylixOS/posix/aio/aio_lib.c7
-rw-r--r--SylixOS/system/logLib/logLib.c4
-rw-r--r--SylixOS/system/select/selectLib.c6
-rw-r--r--SylixOS/system/signal/signalEvent.c16
41 files changed, 288 insertions, 150 deletions
diff --git a/SylixOS/CHANGELOG b/SylixOS/CHANGELOG
index 126d83d..e568248 100644
--- a/SylixOS/CHANGELOG
+++ b/SylixOS/CHANGELOG
@@ -24,6 +24,10 @@ HISTORY
++ Bugfixes:
+ 2020-10-12: han.hui
+ 修正内核事件广播激活顺序.
+ xtimer 可配置多种锁类型.
+
2020-09-24: han.hui
修正桥接网卡与 bound 网卡防火墙 hook 错误.
修正 loader init/fini call 死锁错误.
diff --git a/SylixOS/driver/sio/16c550.c b/SylixOS/driver/sio/16c550.c
index a8284d0..72564cb 100644
--- a/SylixOS/driver/sio/16c550.c
+++ b/SylixOS/driver/sio/16c550.c
@@ -154,7 +154,7 @@ INT sio16c550Init (SIO16C550_CHAN *psiochan)
psiochan->err_framing = 0;
psiochan->err_break = 0;
- psiochan->rx_trigger_level &= 0x3;
+ psiochan->rx_trigger_level &= (0x3 | SIO16C550_FIFO_MERGE_INIT);
/*
* reset the chip
@@ -403,6 +403,31 @@ static INT sio16c550SetHighBaud (SIO16C550_CHAN *psiochan, ULONG baud)
#endif /* __GNUC__ */
/*********************************************************************************************************
+** 函数名称: sio16c550ClearFifo
+** 功能描述: 清除 FIFO
+** 输 入 : psiochan SIO CHAN
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID sio16c550ClearFifo (SIO16C550_CHAN *psiochan)
+{
+ REGISTER INT rx_trigger_level = psiochan->rx_trigger_level & ~SIO16C550_FIFO_MERGE_INIT;
+
+ if (psiochan->rx_trigger_level & SIO16C550_FIFO_MERGE_INIT) {
+ SET_REG(psiochan, FCR,
+ ((rx_trigger_level << 6) |
+ RxCLEAR | TxCLEAR | FIFO_ENABLE));
+
+ } else {
+ SET_REG(psiochan, FCR,
+ ((rx_trigger_level << 6) |
+ RxCLEAR | TxCLEAR));
+
+ SET_REG(psiochan, FCR, FIFO_ENABLE);
+ }
+}
+/*********************************************************************************************************
** 函数名称: sio16c550SetBaud
** 功能描述: 设置波特率
** 输 入 : psiochan SIO CHAN
@@ -463,12 +488,8 @@ static INT sio16c550SetBaud (SIO16C550_CHAN *psiochan, ULONG baud)
*/
SET_REG(psiochan, IER, 0); /* disable interrupt */
- SET_REG(psiochan, FCR,
- ((psiochan->rx_trigger_level << 6) |
- RxCLEAR | TxCLEAR));
-
- SET_REG(psiochan, FCR, FIFO_ENABLE);
-
+ sio16c550ClearFifo(psiochan); /* clear FIFO */
+
if (psiochan->channel_mode == SIO_MODE_INT) {
SET_REG(psiochan, IER, psiochan->ier); /* enable interrupt */
}
@@ -567,15 +588,11 @@ static INT sio16c550SetHwOption (SIO16C550_CHAN *psiochan, INT hw_option)
SET_REG(psiochan, LCR, psiochan->lcr);
SET_REG(psiochan, MCR, psiochan->mcr);
+ sio16c550ClearFifo(psiochan); /* clear FIFO */
+
/*
* now reset the channel mode registers
*/
- SET_REG(psiochan, FCR,
- ((psiochan->rx_trigger_level << 6) |
- RxCLEAR | TxCLEAR));
-
- SET_REG(psiochan, FCR, FIFO_ENABLE);
-
if (hw_option & CREAD) {
psiochan->ier |= RxFIFO_BIT;
}
@@ -643,11 +660,7 @@ static INT sio16c550Open (SIO16C550_CHAN *psiochan)
/*
* clear Tx and receive and enable FIFO
*/
- SET_REG(psiochan, FCR,
- ((psiochan->rx_trigger_level << 6) |
- RxCLEAR | TxCLEAR));
-
- SET_REG(psiochan, FCR, FIFO_ENABLE);
+ sio16c550ClearFifo(psiochan);
LW_SPIN_UNLOCK_QUICK(&psiochan->slock, intreg);
}
diff --git a/SylixOS/driver/sio/16c550.h b/SylixOS/driver/sio/16c550.h
index a59a28d..9962bde 100644
--- a/SylixOS/driver/sio/16c550.h
+++ b/SylixOS/driver/sio/16c550.h
@@ -214,6 +214,12 @@ struct sio16c550_chan {
};
/*********************************************************************************************************
+ rx_trigger_level
+*********************************************************************************************************/
+
+#define SIO16C550_FIFO_MERGE_INIT 0x40000000 /* FIFO register set clear enable merge */
+
+/*********************************************************************************************************
additional ioctl commands
ioctl(fd, SIO_SWITCH_PIN_EN_SET, 1); RS-485 mode
ioctl(fd, SIO_SWITCH_PIN_EN_SET, 0); RS-232/422 mode
diff --git a/SylixOS/kernel/core/_EventHighLevel.c b/SylixOS/kernel/core/_EventHighLevel.c
index a818831..eac4637 100644
--- a/SylixOS/kernel/core/_EventHighLevel.c
+++ b/SylixOS/kernel/core/_EventHighLevel.c
@@ -33,6 +33,7 @@
2013.07.18 使用新的获取 TCB 的方法, 确保 SMP 系统安全.
2013.09.02 等待类型改为 16 位.
2014.01.14 修改长函数名.
+2020.10.12 _EventReadyHighLevel() 加入可选调度激活方式.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -154,14 +155,15 @@ PLW_CLASS_TCB _EventReadyPriorityLowLevel (PLW_CLASS_EVENT pevent,
** 函数名称: _EventReadyHighLevel
** 功能描述: 将一个线程从 FIFO 事件等待队列中解锁并就绪, 同时设置相关标志位, 需要时进入就绪表.
** 此函数在内核锁定状态被调用.
-** 输 入 : ptcb 任务控制块
-** usWaitType 等待类型
+** 输 入 : ptcb 任务控制块
+** usWaitType 等待类型
+** ucSchedActivate 激活调度方式
** 输 出 : NONE
** 全局变量:
** 调用模块:
此函数在开中断时被调用.
*********************************************************************************************************/
-VOID _EventReadyHighLevel (PLW_CLASS_TCB ptcb, UINT16 usWaitType)
+VOID _EventReadyHighLevel (PLW_CLASS_TCB ptcb, UINT16 usWaitType, UINT8 ucSchedActivate)
{
INTREG iregInterLevel;
REGISTER PLW_CLASS_PCB ppcb;
@@ -176,7 +178,7 @@ VOID _EventReadyHighLevel (PLW_CLASS_TCB ptcb, UINT16 usWaitType)
} else { /* 清除相应等待位 */
ptcb->TCB_usStatus = (UINT16)(ptcb->TCB_usStatus & (~usWaitType));
if (__LW_THREAD_IS_READY(ptcb)) { /* 是否就绪 */
- ptcb->TCB_ucSchedActivate = LW_SCHED_ACT_INTERRUPT; /* 中断激活方式 */
+ ptcb->TCB_ucSchedActivate = ucSchedActivate; /* 调度激活方式 */
ppcb = _GetPcb(ptcb);
__ADD_TO_READY_RING(ptcb, ppcb); /* 加入到相对优先级就绪环 */
}
diff --git a/SylixOS/kernel/core/_Sched.c b/SylixOS/kernel/core/_Sched.c
index ff96a58..1c3f03a 100644
--- a/SylixOS/kernel/core/_Sched.c
+++ b/SylixOS/kernel/core/_Sched.c
@@ -133,17 +133,13 @@ static VOID _SchedSmpNotify (ULONG ulCPUIdCur)
{
INT i;
PLW_CLASS_CPU pcpu;
- PLW_CLASS_TCB ptcb;
LW_CPU_FOREACH_ACTIVE_EXCEPT (i, ulCPUIdCur) { /* 遍历 CPU 检查是否需要调度 */
pcpu = LW_CPU_GET(i);
if (LW_CAND_ROT(pcpu) && /* 需要检查调度 */
((LW_CPU_GET_IPI_PEND(i) & LW_IPI_SCHED_MSK) == 0) && /* 没有核间中断标志 */
!LW_ACCESS_ONCE(ULONG, pcpu->CPU_ulInterNesting)) { /* 不在中断中 */
- ptcb = LW_CAND_TCB(pcpu);
- if (LW_CPU_LOCK_QUICK_GET(pcpu) || !__THREAD_LOCK_GET(ptcb)) {
- _SmpSendIpi(i, LW_IPI_SCHED, 0, LW_TRUE); /* 产生核间中断 */
- }
+ _SmpSendIpi(i, LW_IPI_SCHED, 0, LW_TRUE); /* 产生核间中断 */
}
}
}
diff --git a/SylixOS/kernel/core/_SmpSpinlock.c b/SylixOS/kernel/core/_SmpSpinlock.c
index 009f70b..9c4d333 100644
--- a/SylixOS/kernel/core/_SmpSpinlock.c
+++ b/SylixOS/kernel/core/_SmpSpinlock.c
@@ -340,28 +340,26 @@ INT _SmpSpinUnlockIrq (spinlock_t *psl, INTREG iregInterLevel)
}
/*********************************************************************************************************
** 函数名称: _SmpSpinLockIrqQuick
-** 功能描述: 自旋锁加锁操作, 连同锁定中断
+** 功能描述: 自旋锁加锁操作, 连同锁定中断 (目前与 _SmpSpinLockIrq 相同)
** 输 入 : psl 自旋锁
** piregInterLevel 中断锁定信息
** 输 出 : NONE
-** 全局变量:
-** 调用模块:
+** 全局变量:
+** 调用模块:
*********************************************************************************************************/
VOID _SmpSpinLockIrqQuick (spinlock_t *psl, INTREG *piregInterLevel)
{
PLW_CLASS_CPU pcpuCur;
-
+
*piregInterLevel = KN_INT_DISABLE();
-
+
pcpuCur = LW_CPU_GET_CUR();
if (!pcpuCur->CPU_ulInterNesting) {
- LW_CPU_LOCK_QUICK_INC(pcpuCur); /* 先于锁定任务之前 */
- KN_SMP_WMB();
__THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */
}
-
+
LW_CPU_SPIN_NESTING_INC(pcpuCur);
-
+
__ARCH_SPIN_LOCK(psl, pcpuCur, LW_NULL, LW_NULL); /* 驱动保证锁定必须成功 */
KN_SMP_MB();
}
@@ -386,8 +384,6 @@ VOID _SmpSpinUnlockIrqQuick (spinlock_t *psl, INTREG iregInterLevel)
if (!pcpuCur->CPU_ulInterNesting) {
__THREAD_LOCK_DEC(pcpuCur->CPU_ptcbTCBCur); /* 解除任务锁定 */
- KN_SMP_WMB();
- LW_CPU_LOCK_QUICK_DEC(pcpuCur); /* 后于锁定任务之后 */
}
LW_CPU_SPIN_NESTING_DEC(pcpuCur);
diff --git a/SylixOS/kernel/core/_UpSpinlock.c b/SylixOS/kernel/core/_UpSpinlock.c
index 8ca56b7..ad42ca6 100644
--- a/SylixOS/kernel/core/_UpSpinlock.c
+++ b/SylixOS/kernel/core/_UpSpinlock.c
@@ -226,21 +226,21 @@ INT _UpSpinUnlockIrq (spinlock_t *psl, INTREG iregInterLevel)
}
/*********************************************************************************************************
** 函数名称: _UpSpinLockIrqQuick
-** 功能描述: 自旋锁加锁操作, 连同锁定中断
+** 功能描述: 自旋锁加锁操作, 连同锁定中断 (目前与 _UpSpinLockIrq 相同)
** 输 入 : psl 自旋锁
** piregInterLevel 中断锁定信息
** 输 出 : NONE
-** 全局变量:
-** 调用模块:
+** 全局变量:
+** 调用模块:
*********************************************************************************************************/
VOID _UpSpinLockIrqQuick (spinlock_t *psl, INTREG *piregInterLevel)
{
PLW_CLASS_CPU pcpuCur = LW_CPU_GET_CUR();
-
+
if (!pcpuCur->CPU_ulInterNesting) {
__THREAD_LOCK_INC(pcpuCur->CPU_ptcbTCBCur); /* 锁定任务在当前 CPU */
}
-
+
*piregInterLevel = KN_INT_DISABLE();
}
/*********************************************************************************************************
diff --git a/SylixOS/kernel/include/k_cpu.h b/SylixOS/kernel/include/k_cpu.h
index 22002eb..d52567f 100644
--- a/SylixOS/kernel/include/k_cpu.h
+++ b/SylixOS/kernel/include/k_cpu.h
@@ -112,7 +112,6 @@ typedef struct __lw_cpu {
#ifdef __LW_SPINLOCK_BUG_TRACE_EN
ULONG CPU_ulSpinNesting; /* spinlock 加锁数量 */
#endif /* __LW_SPINLOCK_BUG_TRACE_EN */
- volatile UINT CPU_uiLockQuick; /* 是否在 Lock Quick 中 */
/*
* CPU 基本信息
@@ -250,16 +249,6 @@ extern LW_CLASS_PHYCPU _K_phycpuTable[]; /* 物理
#endif /* LW_CFG_CPU_ARCH_SMT > 0 */
/*********************************************************************************************************
- CPU LOCK QUICK 记录
-*********************************************************************************************************/
-
-#if LW_CFG_SMP_EN > 0
-#define LW_CPU_LOCK_QUICK_INC(pcpu) ((pcpu)->CPU_uiLockQuick++)
-#define LW_CPU_LOCK_QUICK_DEC(pcpu) ((pcpu)->CPU_uiLockQuick--)
-#define LW_CPU_LOCK_QUICK_GET(pcpu) ((pcpu)->CPU_uiLockQuick)
-#endif /* LW_CFG_SMP_EN > 0 */
-
-/*********************************************************************************************************
CPU 强制运行亲和度线程
*********************************************************************************************************/
diff --git a/SylixOS/kernel/include/k_internal.h b/SylixOS/kernel/include/k_internal.h
index b0d3371..1bfdbed 100644
--- a/SylixOS/kernel/include/k_internal.h
+++ b/SylixOS/kernel/include/k_internal.h
@@ -369,7 +369,7 @@ PLW_CLASS_TCB _EventReadyPriorityLowLevel(PLW_CLASS_EVENT pevent,
PVOID pvMsgBoxMessage,
PLW_LIST_RING *ppringList);
-VOID _EventReadyHighLevel(PLW_CLASS_TCB ptcb, UINT16 usWaitType);
+VOID _EventReadyHighLevel(PLW_CLASS_TCB ptcb, UINT16 usWaitType, UINT8 ucSchedActivate);
PLW_CLASS_EVENT _EventUnQueue(PLW_CLASS_TCB ptcb);
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index 976bdfe..009b377 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -53,8 +53,8 @@
#define __SYLIXOS_MAJOR_VER 2
#define __SYLIXOS_MINOR_VER 0
-#define __SYLIXOS_PATCH_VER 1
-#define __SYLIXOS_PATCH_PAD 0
+#define __SYLIXOS_PATCH_VER 2
+#define __SYLIXOS_PATCH_PAD 1
/*********************************************************************************************************
版本格式
diff --git a/SylixOS/kernel/interface/MsgQueueClear.c b/SylixOS/kernel/interface/MsgQueueClear.c
index 431480e..c66bf9c 100644
--- a/SylixOS/kernel/interface/MsgQueueClear.c
+++ b/SylixOS/kernel/interface/MsgQueueClear.c
@@ -88,7 +88,9 @@ ULONG API_MsgQueueClear (LW_OBJECT_HANDLE ulId)
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/MsgQueueDelete.c b/SylixOS/kernel/interface/MsgQueueDelete.c
index 48be38e..3be57aa 100644
--- a/SylixOS/kernel/interface/MsgQueueDelete.c
+++ b/SylixOS/kernel/interface/MsgQueueDelete.c
@@ -103,7 +103,9 @@ ULONG API_MsgQueueDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
@@ -119,7 +121,9 @@ ULONG API_MsgQueueDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/MsgQueueFlush.c b/SylixOS/kernel/interface/MsgQueueFlush.c
index 6866adc..e4171f5 100644
--- a/SylixOS/kernel/interface/MsgQueueFlush.c
+++ b/SylixOS/kernel/interface/MsgQueueFlush.c
@@ -87,7 +87,9 @@ ULONG API_MsgQueueFlushSend (LW_OBJECT_HANDLE ulId, ULONG *pulThreadUnblockNu
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
@@ -157,7 +159,9 @@ ULONG API_MsgQueueFlushReceive (LW_OBJECT_HANDLE ulId, ULONG *pulThreadUnbloc
*ptcb->TCB_pstMsgByteSize = 0; /* 消息长度为 0 */
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/MsgQueueReceive.c b/SylixOS/kernel/interface/MsgQueueReceive.c
index 950b390..e129610 100644
--- a/SylixOS/kernel/interface/MsgQueueReceive.c
+++ b/SylixOS/kernel/interface/MsgQueueReceive.c
@@ -151,7 +151,9 @@ __wait_again:
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
__KERNEL_EXIT(); /* 退出内核 */
} else {
@@ -341,7 +343,9 @@ __wait_again:
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
__KERNEL_EXIT(); /* 退出内核 */
} else {
diff --git a/SylixOS/kernel/interface/MsgQueueSend.c b/SylixOS/kernel/interface/MsgQueueSend.c
index bbb55d9..bf01b10 100644
--- a/SylixOS/kernel/interface/MsgQueueSend.c
+++ b/SylixOS/kernel/interface/MsgQueueSend.c
@@ -144,7 +144,9 @@ __re_send:
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_MSGQ, MONITOR_EVENT_MSGQ_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/MsgQueueSendEx.c b/SylixOS/kernel/interface/MsgQueueSendEx.c
index e56821e..a6a5c0e 100644
--- a/SylixOS/kernel/interface/MsgQueueSendEx.c
+++ b/SylixOS/kernel/interface/MsgQueueSendEx.c
@@ -143,7 +143,9 @@ __re_send:
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_MSGQ, MONITOR_EVENT_MSGQ_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
@@ -266,7 +268,9 @@ __re_send:
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_MSGQ, MONITOR_EVENT_MSGQ_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/MsgQueueTryReceive.c b/SylixOS/kernel/interface/MsgQueueTryReceive.c
index 12d5be1..76a2262 100644
--- a/SylixOS/kernel/interface/MsgQueueTryReceive.c
+++ b/SylixOS/kernel/interface/MsgQueueTryReceive.c
@@ -107,7 +107,9 @@ ULONG API_MsgQueueTryReceive (LW_OBJECT_HANDLE ulId,
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_MSGQUEUE); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_MSGQUEUE,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
__KERNEL_EXIT(); /* 退出内核 */
} else {
diff --git a/SylixOS/kernel/interface/SemaphoreBDelete.c b/SylixOS/kernel/interface/SemaphoreBDelete.c
index 41c63bf..1286e74 100644
--- a/SylixOS/kernel/interface/SemaphoreBDelete.c
+++ b/SylixOS/kernel/interface/SemaphoreBDelete.c
@@ -100,7 +100,9 @@ ULONG API_SemaphoreBDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/SemaphoreBFlush.c b/SylixOS/kernel/interface/SemaphoreBFlush.c
index 52eda7a..9d3f4a4 100644
--- a/SylixOS/kernel/interface/SemaphoreBFlush.c
+++ b/SylixOS/kernel/interface/SemaphoreBFlush.c
@@ -87,7 +87,9 @@ ULONG API_SemaphoreBFlush (LW_OBJECT_HANDLE ulId, ULONG *pulThreadUnblockNum)
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/SemaphoreBPost.c b/SylixOS/kernel/interface/SemaphoreBPost.c
index bc5f95d..fe506f4 100644
--- a/SylixOS/kernel/interface/SemaphoreBPost.c
+++ b/SylixOS/kernel/interface/SemaphoreBPost.c
@@ -82,7 +82,9 @@ ULONG API_SemaphoreBPost (LW_OBJECT_HANDLE ulId)
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMB, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
@@ -162,7 +164,9 @@ ULONG API_SemaphoreBPost2 (LW_OBJECT_HANDLE ulId, LW_OBJECT_HANDLE *pulId)
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
if (pulId) {
*pulId = ptcb->TCB_ulId; /* 记录激活的任务 */
diff --git a/SylixOS/kernel/interface/SemaphoreBPostEx.c b/SylixOS/kernel/interface/SemaphoreBPostEx.c
index af0cfbf..21b5a93 100644
--- a/SylixOS/kernel/interface/SemaphoreBPostEx.c
+++ b/SylixOS/kernel/interface/SemaphoreBPostEx.c
@@ -83,7 +83,9 @@ ULONG API_SemaphoreBPostEx (LW_OBJECT_HANDLE ulId, PVOID pvMsgPtr)
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMB, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
@@ -165,7 +167,9 @@ ULONG API_SemaphoreBPostEx2 (LW_OBJECT_HANDLE ulId, PVOID pvMsgPtr, LW_OBJECT
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
if (pulId) {
*pulId = ptcb->TCB_ulId; /* 记录激活的任务 */
diff --git a/SylixOS/kernel/interface/SemaphoreBRelease.c b/SylixOS/kernel/interface/SemaphoreBRelease.c
index 00f8211..b8dc556 100644
--- a/SylixOS/kernel/interface/SemaphoreBRelease.c
+++ b/SylixOS/kernel/interface/SemaphoreBRelease.c
@@ -93,7 +93,9 @@ ULONG API_SemaphoreBRelease (LW_OBJECT_HANDLE ulId, ULONG ulReleaseCounter, B
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMB, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/SemaphoreCDelete.c b/SylixOS/kernel/interface/SemaphoreCDelete.c
index 59d109b..dfa0e9c 100644
--- a/SylixOS/kernel/interface/SemaphoreCDelete.c
+++ b/SylixOS/kernel/interface/SemaphoreCDelete.c
@@ -99,7 +99,9 @@ ULONG API_SemaphoreCDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/SemaphoreCFlush.c b/SylixOS/kernel/interface/SemaphoreCFlush.c
index abe400c..bec98a9 100644
--- a/SylixOS/kernel/interface/SemaphoreCFlush.c
+++ b/SylixOS/kernel/interface/SemaphoreCFlush.c
@@ -86,7 +86,9 @@ ULONG API_SemaphoreCFlush (LW_OBJECT_HANDLE ulId, ULONG *pulThreadUnblockNum)
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
}
diff --git a/SylixOS/kernel/interface/SemaphoreCPost.c b/SylixOS/kernel/interface/SemaphoreCPost.c
index e4eef56..3804d1b 100644
--- a/SylixOS/kernel/interface/SemaphoreCPost.c
+++ b/SylixOS/kernel/interface/SemaphoreCPost.c
@@ -82,7 +82,9 @@ ULONG API_SemaphoreCPost (LW_OBJECT_HANDLE ulId)
}
KN_INT_ENABLE(iregInterLevel); /* 使能中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMC, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/SemaphoreCRelease.c b/SylixOS/kernel/interface/SemaphoreCRelease.c
index fdb5803..9831b22 100644
--- a/SylixOS/kernel/interface/SemaphoreCRelease.c
+++ b/SylixOS/kernel/interface/SemaphoreCRelease.c
@@ -93,7 +93,9 @@ ULONG API_SemaphoreCRelease (LW_OBJECT_HANDLE ulId, ULONG ulReleaseCounter, U
}
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMC, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/SemaphoreMDelete.c b/SylixOS/kernel/interface/SemaphoreMDelete.c
index e4b3768..4695fc0 100644
--- a/SylixOS/kernel/interface/SemaphoreMDelete.c
+++ b/SylixOS/kernel/interface/SemaphoreMDelete.c
@@ -109,7 +109,9 @@ ULONG API_SemaphoreMDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel);
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE();
}
diff --git a/SylixOS/kernel/interface/SemaphoreMPost.c b/SylixOS/kernel/interface/SemaphoreMPost.c
index 4f7ba41..eadf588 100644
--- a/SylixOS/kernel/interface/SemaphoreMPost.c
+++ b/SylixOS/kernel/interface/SemaphoreMPost.c
@@ -128,7 +128,9 @@ ULONG API_SemaphoreMPost (LW_OBJECT_HANDLE ulId)
pevent->EVENT_ulMaxCounter = (ULONG)ptcb->TCB_ucPriority;
pevent->EVENT_pvTcbOwn = (PVOID)ptcb; /* 保存线程信息 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) {
LW_THREAD_SAFE_INKERN(ptcb); /* 将激活任务设置为安全 */
diff --git a/SylixOS/kernel/interface/SemaphoreRWDelete.c b/SylixOS/kernel/interface/SemaphoreRWDelete.c
index 9b0a846..9ffb370 100644
--- a/SylixOS/kernel/interface/SemaphoreRWDelete.c
+++ b/SylixOS/kernel/interface/SemaphoreRWDelete.c
@@ -94,7 +94,9 @@ ULONG API_SemaphoreRWDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel);
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE();
}
@@ -110,7 +112,9 @@ ULONG API_SemaphoreRWDelete (LW_OBJECT_HANDLE *pulId)
KN_INT_ENABLE(iregInterLevel);
ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
iregInterLevel = KN_INT_DISABLE();
}
diff --git a/SylixOS/kernel/interface/SemaphoreRWPost.c b/SylixOS/kernel/interface/SemaphoreRWPost.c
index c1ef8bd..cdd107c 100644
--- a/SylixOS/kernel/interface/SemaphoreRWPost.c
+++ b/SylixOS/kernel/interface/SemaphoreRWPost.c
@@ -131,7 +131,9 @@ __release_pend:
}
KN_INT_ENABLE(iregInterLevel);
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_INTERRUPT); /* 处理 TCB */
pevent->EVENT_pvTcbOwn = (PVOID)ptcb;
pevent->EVENT_iStatus = EVENT_RW_STATUS_W;
@@ -166,7 +168,9 @@ __release_pend:
pevent->EVENT_ulCounter++; /* 增加使用者计数 */
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
- _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ _EventReadyHighLevel(ptcb,
+ LW_THREAD_STATUS_SEM,
+ LW_SCHED_ACT_OTHER); /* 处理 TCB */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 将激活任务设置为安全 */
LW_THREAD_SAFE_INKERN(ptcb);
diff --git a/SylixOS/kernel/vmm/phyPage.c b/SylixOS/kernel/vmm/phyPage.c
index b63ca1b..a61e64d 100644
--- a/SylixOS/kernel/vmm/phyPage.c
+++ b/SylixOS/kernel/vmm/phyPage.c
@@ -33,6 +33,7 @@
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
+#include "../SylixOS/system/include/s_system.h"
/*********************************************************************************************************
加入裁剪支持
*********************************************************************************************************/
@@ -736,6 +737,26 @@ VOID __vmmPhysicalPageFaultClear (LW_OBJECT_HANDLE ulId)
#endif /* LW_CFG_THREAD_DEL_EN > 0 */
/*********************************************************************************************************
+** 函数名称: __vmmPhysicalPageFaultWarn
+** 功能描述: 物理内存缺少告警
+** 输 入 : ulGuarder 警卫线程 ID
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID __vmmPhysicalPageFaultWarn (LW_OBJECT_HANDLE ulGuarder)
+{
+#if LW_CFG_SIGNAL_EN > 0
+ struct sigevent sigeventWarn;
+
+ sigeventWarn.sigev_signo = SIGLOWMEM;
+ sigeventWarn.sigev_notify = SIGEV_SIGNAL;
+ sigeventWarn.sigev_value.sival_ptr = LW_NULL;
+
+ _doSigEvent(ulGuarder, &sigeventWarn, SI_KILL);
+#endif /* LW_CFG_SIGNAL_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: __vmmPhysicalPageFaultGuarder
** 功能描述: 设置缺页中断警卫线程
** 输 入 : ulGuarder 新的警卫线程 ID (单次生效)
diff --git a/SylixOS/kernel/vmm/phyPage.h b/SylixOS/kernel/vmm/phyPage.h
index 39c4c71..a63bb33 100644
--- a/SylixOS/kernel/vmm/phyPage.h
+++ b/SylixOS/kernel/vmm/phyPage.h
@@ -74,6 +74,8 @@ VOID __vmmPhysicalGetKernelDesc(PLW_MMU_PHYSICAL_DESC pphydescText,
VOID __vmmPhysicalPageFaultClear(LW_OBJECT_HANDLE ulId);
#endif /* LW_CFG_THREAD_DEL_EN > 0 */
+VOID __vmmPhysicalPageFaultWarn(LW_OBJECT_HANDLE ulGuarder);
+
INT __vmmPhysicalPageFaultLimit(PLW_VMM_PAGE_FAULT_LIMIT pvpflNew,
PLW_VMM_PAGE_FAULT_LIMIT pvpflOld);
BOOL __vmmPhysicalPageFaultCheck(ULONG ulPageNum,
diff --git a/SylixOS/kernel/vmm/vmmAbort.c b/SylixOS/kernel/vmm/vmmAbort.c
index 26b413d..9e6949b 100644
--- a/SylixOS/kernel/vmm/vmmAbort.c
+++ b/SylixOS/kernel/vmm/vmmAbort.c
@@ -84,7 +84,6 @@ static LW_VMM_STATUS _K_vmmStatus;
/*********************************************************************************************************
内部函数声明
*********************************************************************************************************/
-static VOID __vmmWarnGuarder(LW_OBJECT_HANDLE ulGuarder);
static VOID __vmmAbortKill(PLW_VMM_ABORT_CTX pabtctx);
static VOID __vmmAbortAccess(PLW_VMM_ABORT_CTX pabtctx);
static PCHAR __vmmAbortTypeStr(PLW_VMM_ABORT pabtInfo);
@@ -753,7 +752,7 @@ static VOID __vmmAbortShell (PLW_VMM_ABORT_CTX pabtctx)
__abort_return:
if (ulGuarder) {
- __vmmWarnGuarder(ulGuarder); /* 发送警告通知 */
+ __vmmPhysicalPageFaultWarn(ulGuarder); /* 发送警告通知 */
}
__KERNEL_SPACE_SET(pabtctx->ABTCTX_iKernelSpace); /* 恢复成进入之前的状态 */
errno = pabtctx->ABTCTX_iLastErrno; /* 恢复之前的 errno */
@@ -828,30 +827,6 @@ static PCHAR __vmmAbortTypeStr (PLW_VMM_ABORT pabtInfo)
}
}
/*********************************************************************************************************
-** 函数名称: __vmmWarnGuarder
-** 功能描述: 向内存守护线程发送一个警告信息
-** 输 入 : pabtctx page fail 上下文
-** 输 出 : NONE
-** 全局变量:
-** 调用模块:
-*********************************************************************************************************/
-#if LW_CFG_VMM_EN > 0
-
-static VOID __vmmWarnGuarder (LW_OBJECT_HANDLE ulGuarder)
-{
-#if LW_CFG_SIGNAL_EN > 0
- struct sigevent sigeventWarn;
-
- sigeventWarn.sigev_signo = SIGLOWMEM;
- sigeventWarn.sigev_notify = SIGEV_SIGNAL;
- sigeventWarn.sigev_value.sival_ptr = LW_NULL;
-
- _doSigEvent(ulGuarder, &sigeventWarn, SI_KILL);
-#endif /* LW_CFG_SIGNAL_EN > 0 */
-}
-
-#endif /* LW_CFG_VMM_EN > 0 */
-/*********************************************************************************************************
** 函数名称: __vmmAbortKill
** 功能描述: 向当前线程产生一个信号
** 输 入 : pabtctx page fail 上下文
diff --git a/SylixOS/kernel/vmm/vmmMmap.c b/SylixOS/kernel/vmm/vmmMmap.c
index f860d79..43407eb 100644
--- a/SylixOS/kernel/vmm/vmmMmap.c
+++ b/SylixOS/kernel/vmm/vmmMmap.c
@@ -22,6 +22,7 @@
2015.07.20 msync() 仅针对 SHARED 类型映射才回写文件.
2017.06.08 修正 mmap() 针对 AF_PACKET 映射错误问题.
2018.08.06 加入 API_VmmMProtect().
+2020.10.10 mmap 预分配内存时需要进行内存配合限制.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -31,6 +32,7 @@
加入裁剪支持
*********************************************************************************************************/
#if LW_CFG_VMM_EN > 0 && LW_CFG_DEVICE_EN > 0
+#include "phyPage.h"
#include "vmmMmap.h"
/*********************************************************************************************************
全局变量声明
@@ -247,16 +249,26 @@ __full_with_zero:
** stLen 内存大小
** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag 虚拟空间内存属性
+** pulGuarder 警戒线程
** 输 出 : 内存地址
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static PVOID __vmmMapnMalloc (PLW_VMM_MAP_NODE pmapn, size_t stLen, INT iFlags, ULONG ulFlag)
+static PVOID __vmmMapnMalloc (PLW_VMM_MAP_NODE pmapn, size_t stLen,
+ INT iFlags, ULONG ulFlag, LW_OBJECT_HANDLE *pulGuarder)
{
REGISTER PVOID pvMem;
+ REGISTER BOOL bNoLimit;
+ PLW_CLASS_TCB ptcbCur;
if (iFlags & LW_VMM_PHY_PREALLOC) {
- pvMem = API_VmmMallocEx(stLen, ulFlag);
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
+ bNoLimit = __vmmPhysicalPageFaultCheck(1, ptcbCur, pulGuarder); /* 检查物理内存是否超限 */
+ if (bNoLimit) {
+ pvMem = API_VmmMallocEx(stLen, ulFlag);
+ } else {
+ pvMem = LW_NULL;
+ }
} else {
pvMem = API_VmmMallocAreaEx(stLen, __vmmMapnFill, pmapn, iFlags, ulFlag);
@@ -362,11 +374,13 @@ static VOID __vmmMapnReclaim (PLW_VMM_MAP_NODE pmapn, LW_LD_VPROC *pvproc)
** ulFlag LW_VMM_FLAG_READ | LW_VMM_FLAG_RDWR | LW_VMM_FLAG_EXEC
** iFd 文件描述符
** off 文件偏移量
+** pulGuarder 警戒线程
** 输 出 : 分配的虚拟内存地址, LW_VMM_MAP_FAILED 表示错误
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static PVOID __vmmMmapNew (size_t stLen, INT iFlags, ULONG ulFlag, int iFd, off_t off)
+static PVOID __vmmMmapNew (size_t stLen, INT iFlags, ULONG ulFlag,
+ int iFd, off_t off, LW_OBJECT_HANDLE *pulGuarder)
{
PLW_VMM_MAP_NODE pmapn;
struct stat64 stat64Fd;
@@ -417,7 +431,7 @@ static PVOID __vmmMmapNew (size_t stLen, INT iFlags, ULONG ulFlag, int iFd,
return (LW_VMM_MAP_FAILED);
}
- pmapn->MAPN_pvAddr = __vmmMapnMalloc(pmapn, stLen, iFlags, ulFlag);
+ pmapn->MAPN_pvAddr = __vmmMapnMalloc(pmapn, stLen, iFlags, ulFlag, pulGuarder);
if (pmapn->MAPN_pvAddr == LW_NULL) { /* 申请映射内存 */
_ErrorHandle(ENOMEM);
iErrLevel = 1;
@@ -596,11 +610,13 @@ static PVOID __vmmMmapShrink (PLW_VMM_MAP_NODE pmapn, size_t stNewSize)
** 输 入 : pmapn mmap node
** stNewSize 需要设置的内存区域新大小
** iMoveEn 是否可以重新分配.
+** pulGuarder 警戒线程
** 输 出 : 分配的虚拟内存地址, LW_VMM_MAP_FAILED 表示错误
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static PVOID __vmmMmapExpand (PLW_VMM_MAP_NODE pmapn, size_t stNewSize, INT iMoveEn)
+static PVOID __vmmMmapExpand (PLW_VMM_MAP_NODE pmapn, size_t stNewSize,
+ INT iMoveEn, LW_OBJECT_HANDLE *pulGuarder)
{
PVOID pvRetAddr;
PVOID pvOldAddr;
@@ -618,8 +634,7 @@ static PVOID __vmmMmapExpand (PLW_VMM_MAP_NODE pmapn, size_t stNewSize, INT i
}
pvRetAddr = __vmmMapnMalloc(pmapn, stNewSize,
- pmapn->MAPN_iFlags,
- pmapn->MAPN_ulFlag);
+ pmapn->MAPN_iFlags, pmapn->MAPN_ulFlag, pulGuarder);
if (pvRetAddr == LW_NULL) {
_ErrorHandle(ENOMEM);
return (LW_VMM_MAP_FAILED);
@@ -742,7 +757,8 @@ static VOID __vmmMmapMerge (PLW_VMM_MAP_NODE pmapnL, PLW_VMM_MAP_NODE pmapnR)
LW_API
PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, INT iFd, off_t off)
{
- PVOID pvRet;
+ PVOID pvRet;
+ LW_OBJECT_HANDLE ulGuarder = LW_OBJECT_HANDLE_INVALID;
if ((iFlags & LW_VMM_SHARED_CHANGE) &&
(iFlags & LW_VMM_PRIVATE_CHANGE)) { /* 不允许同时出现两个 */
@@ -767,13 +783,17 @@ PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, IN
__VMM_MMAP_LOCK();
if (pvAddr == LW_NULL) { /* 分配新的内存 */
- pvRet = __vmmMmapNew(stLen, iFlags, ulFlag, iFd, off);
+ pvRet = __vmmMmapNew(stLen, iFlags, ulFlag, iFd, off, &ulGuarder);
} else { /* 修改之前映射的内存 */
pvRet = __vmmMmapChange(pvAddr, stLen, iFlags, ulFlag, iFd, off);
}
__VMM_MMAP_UNLOCK();
+ if (ulGuarder) {
+ __vmmPhysicalPageFaultWarn(ulGuarder); /* 发送警告通知 */
+ }
+
return (pvRet);
}
/*********************************************************************************************************
@@ -793,6 +813,7 @@ PVOID API_VmmMremap (PVOID pvAddr, size_t stOldSize, size_t stNewSize, INT iM
{
PLW_VMM_MAP_NODE pmapn;
PVOID pvRet;
+ LW_OBJECT_HANDLE ulGuarder = LW_OBJECT_HANDLE_INVALID;
if (!ALIGNED(pvAddr, LW_CFG_VMM_PAGE_SIZE) || (stNewSize == 0)) {
_ErrorHandle(EINVAL);
@@ -827,13 +848,17 @@ PVOID API_VmmMremap (PVOID pvAddr, size_t stOldSize, size_t stNewSize, INT iM
pvRet = __vmmMmapShrink(pmapn, stNewSize);
} else if (pmapn->MAPN_stLen < stNewSize) { /* 进行扩展 */
- pvRet = __vmmMmapExpand(pmapn, stNewSize, iMoveEn);
+ pvRet = __vmmMmapExpand(pmapn, stNewSize, iMoveEn, &ulGuarder);
} else {
pvRet = pvAddr;
}
__VMM_MMAP_UNLOCK();
+ if (ulGuarder) {
+ __vmmPhysicalPageFaultWarn(ulGuarder); /* 发送警告通知 */
+ }
+
return (pvRet);
}
/*********************************************************************************************************
diff --git a/SylixOS/kmodule/xtimer/xtimer.c b/SylixOS/kmodule/xtimer/xtimer.c
index 7433013..e5eeb71 100644
--- a/SylixOS/kmodule/xtimer/xtimer.c
+++ b/SylixOS/kmodule/xtimer/xtimer.c
@@ -51,15 +51,38 @@ static INT64 xtimer_last_tick;
/* Timer service task */
static LW_HANDLE xtimer_task = LW_HANDLE_INVALID;
+/* Timer installed? */
+static BOOL xtimer_install = LW_FALSE;
+
+#if __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN
+
+/* Global mutex */
+static LW_SPINLOCK_DEFINE(xtimer_mutex);
+
+/* Timer condition variable */
+static LW_HANDLE xtimer_cond = LW_HANDLE_INVALID;
+
+/* Timer mutex */
+#define XTIMER_LOCK() LW_SPIN_LOCK(&xtimer_mutex)
+#define XTIMER_UNLOCK() LW_SPIN_UNLOCK(&xtimer_mutex)
+
+/* Timer condition */
+#define XTIMER_COND_WAIT(count) \
+ do { \
+ XTIMER_UNLOCK(); \
+ API_SemaphoreBPend(xtimer_cond, count); \
+ XTIMER_LOCK(); \
+ } while (0)
+#define XTIMER_COND_POST() API_SemaphoreBPost(xtimer_cond)
+
+#else /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN */
+
/* Global mutex */
static LW_HANDLE xtimer_mutex = LW_HANDLE_INVALID;
/* Timer condition variable */
static LW_THREAD_COND xtimer_cond;
-/* Timer installed? */
-static BOOL xtimer_install = LW_FALSE;
-
/* Timer mutex */
#define XTIMER_LOCK() API_SemaphoreMPend(xtimer_mutex, LW_OPTION_WAIT_INFINITE)
#define XTIMER_UNLOCK() API_SemaphoreMPost(xtimer_mutex)
@@ -68,6 +91,8 @@ static BOOL xtimer_install = LW_FALSE;
#define XTIMER_COND_WAIT(count) API_ThreadCondWait(&xtimer_cond, xtimer_mutex, count)
#define XTIMER_COND_POST() API_ThreadCondSignal(&xtimer_cond)
+#endif /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_MUTEX */
+
/*
* Start Stop a xtimer internal.
*/
@@ -280,10 +305,11 @@ int xtimer_start (xtimer_t *timer)
}
xtimer_start_internal(timer);
- XTIMER_COND_POST();
XTIMER_UNLOCK();
+ XTIMER_COND_POST();
+
return (ERROR_NONE);
}
@@ -332,10 +358,11 @@ int xtimer_modify (xtimer_t *timer, ULONG count, ULONG interval)
timer->interval = interval;
xtimer_start_internal(timer);
- XTIMER_COND_POST();
XTIMER_UNLOCK();
+ XTIMER_COND_POST();
+
return (ERROR_NONE);
}
@@ -367,6 +394,18 @@ int module_init (void)
{
LW_CLASS_THREADATTR attr;
+#if __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN
+
+ LW_SPIN_INIT(&xtimer_mutex);
+
+ xtimer_cond = API_SemaphoreBCreate("xtmr_cond", LW_FALSE, LW_OPTION_OBJECT_GLOBAL, LW_NULL);
+ if (xtimer_cond == LW_HANDLE_INVALID) {
+ printk(KERN_ERR "xtimer cond create error.\n");
+ return (LW_INIT_RET_ERROR);
+ }
+
+#else /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN */
+
xtimer_mutex = API_SemaphoreMCreate("xtmr_mutex", LW_PRIO_DEF_CEILING,
LW_OPTION_WAIT_PRIORITY | LW_OPTION_INHERIT_PRIORITY |
LW_OPTION_DELETE_SAFE |
@@ -383,14 +422,26 @@ int module_init (void)
return (LW_INIT_RET_ERROR);
}
+#endif /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_MUTEX */
+
API_ThreadAttrBuild(&attr, LW_CFG_THREAD_ITMR_STK_SIZE, LW_PRIO_T_ITIMER,
(LW_CFG_ITIMER_OPTION | LW_OPTION_THREAD_SAFE |
LW_OPTION_OBJECT_GLOBAL | LW_OPTION_THREAD_DETACHED), LW_NULL);
xtimer_task = API_ThreadCreate("t_xtimer", xtimer_service, &attr, LW_NULL);
- if (xtimer_mutex == LW_HANDLE_INVALID) {
+ if (xtimer_task == LW_HANDLE_INVALID) {
+
+#if __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN
+
+ API_SemaphoreBDelete(&xtimer_cond);
+
+#else /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_SPIN */
+
API_SemaphoreMDelete(&xtimer_mutex);
API_ThreadCondDestroy(&xtimer_cond);
+
+#endif /* __SYLIXOS_XTIMER_LT == __SYLIXOS_XTIMER_LT_MUTEX */
+
printk(KERN_ERR "xtimer task create error.\n");
return (LW_INIT_RET_ERROR);
}
diff --git a/SylixOS/kmodule/xtimer/xtimer.h b/SylixOS/kmodule/xtimer/xtimer.h
index a2342cd..756f9ff 100644
--- a/SylixOS/kmodule/xtimer/xtimer.h
+++ b/SylixOS/kmodule/xtimer/xtimer.h
@@ -43,6 +43,14 @@
#include <SylixOS.h>
/*
+ * xtimer internal lock type
+ * Warning: If you are using a Linux compatibility layer, you must choose a spin lock type.
+ */
+#define __SYLIXOS_XTIMER_LT_SPIN 0
+#define __SYLIXOS_XTIMER_LT_MUTEX 1
+#define __SYLIXOS_XTIMER_LT __SYLIXOS_XTIMER_LT_SPIN
+
+/*
* xtimer type.
*/
typedef struct {
@@ -98,4 +106,3 @@ BOOL xtimer_pending(xtimer_t *timer);
#endif /* __SYLIXOS_KERNEL */
#endif /* __XTIMER_H */
-
diff --git a/SylixOS/posix/aio/aio.c b/SylixOS/posix/aio/aio.c
index c19fc29..f732fb2 100644
--- a/SylixOS/posix/aio/aio.c
+++ b/SylixOS/posix/aio/aio.c
@@ -228,10 +228,8 @@ int lio_listio (int mode, struct aiocb * const list[], int nent, struct sigeven
if ((list[iCnt]->aio_lio_opcode != LIO_NOP) &&
(list[iCnt]->aio_req.aioreq_error != EINPROGRESS)) {
- iNotify = list[iCnt]->aio_sigevent.sigev_notify;
- iNotify &= ~SIGEV_THREAD_ID;
- if ((iNotify != SIGEV_SIGNAL) &&
- (iNotify != SIGEV_THREAD)) {
+ iNotify = list[iCnt]->aio_sigevent.sigev_notify;
+ if ((iNotify != SIGEV_THREAD_ID) && (iNotify != SIGEV_SIGNAL) && (iNotify != SIGEV_THREAD)) {
list[iCnt]->aio_sigevent.sigev_notify = SIGEV_NONE;
}
diff --git a/SylixOS/posix/aio/aio_lib.c b/SylixOS/posix/aio/aio_lib.c
index b3c6281..5414893 100644
--- a/SylixOS/posix/aio/aio_lib.c
+++ b/SylixOS/posix/aio/aio_lib.c
@@ -636,12 +636,13 @@ static PVOID __aioNotifyWrapper (PVOID pvArg)
*********************************************************************************************************/
VOID __aioSigevent (LW_OBJECT_HANDLE hThread, struct sigevent *psigevent)
{
+ int iNotify;
pthread_t tid;
pthread_attr_t attr, *pattr;
struct sigevent_notify_arg *psna;
- if ((psigevent->sigev_notify == SIGEV_THREAD) &&
- (psigevent->sigev_notify_function)) {
+ iNotify = psigevent->sigev_notify;
+ if ((iNotify == SIGEV_THREAD) && (psigevent->sigev_notify_function)) {
pattr = (pthread_attr_t *)psigevent->sigev_notify_attributes;
if (!pattr) {
pthread_attr_init(&attr);
@@ -662,7 +663,7 @@ VOID __aioSigevent (LW_OBJECT_HANDLE hThread, struct sigevent *psigevent)
return;
}
- } else if ((psigevent->sigev_notify & SIGEV_NOTIFY_MASK) == SIGEV_SIGNAL) {
+ } else if ((iNotify == SIGEV_SIGNAL) || (iNotify == SIGEV_THREAD_ID)) {
_doSigEvent(hThread, psigevent, SI_ASYNCIO); /* notify */
}
}
diff --git a/SylixOS/system/logLib/logLib.c b/SylixOS/system/logLib/logLib.c
index 3ef7918..93d4ed6 100644
--- a/SylixOS/system/logLib/logLib.c
+++ b/SylixOS/system/logLib/logLib.c
@@ -574,7 +574,7 @@ VOID __logPrintk (int iLevel, PCHAR pcPrintk)
if (ulPartMask == 0) { /* 这个组中与这个文件无关 */
iFdTemp += NFDBITS - 1; /* 进行下一个掩码组判断 */
- } else if (ulPartMask & (ULONG)(1 << (((unsigned)iFdTemp) % NFDBITS))) {
+ } else if (ulPartMask & (ULONG)(1ul << (((unsigned)iFdTemp) % NFDBITS))) {
write(iFdTemp, pcPrintk, stLen); /* 打印 */
}
}
@@ -628,7 +628,7 @@ VOID __logPrintf (CPCHAR pcFormat,
if (ulPartMask == 0) { /* 这个组中与这个文件无关 */
iFdTemp += NFDBITS - 1; /* 进行下一个掩码组判断 */
- } else if (ulPartMask & (ULONG)(1 << (((unsigned)iFdTemp) % NFDBITS))) {
+ } else if (ulPartMask & (ULONG)(1ul << (((unsigned)iFdTemp) % NFDBITS))) {
write(iFdTemp, cPrintBuffer, stLen); /* 打印 */
}
}
diff --git a/SylixOS/system/select/selectLib.c b/SylixOS/system/select/selectLib.c
index 8e97a3c..c7d671e 100644
--- a/SylixOS/system/select/selectLib.c
+++ b/SylixOS/system/select/selectLib.c
@@ -167,7 +167,7 @@ static INT __selFdsetGetFileCounter (INT iWidth,
if (ulPartMask == 0) {
iFd += NFDBITS - 1;
- } else if (ulPartMask & (ULONG)(1 << (((unsigned)iFd) % NFDBITS))) {
+ } else if (ulPartMask & (ULONG)(1ul << (((unsigned)iFd) % NFDBITS))) {
iFoundCounter++;
}
}
@@ -179,7 +179,7 @@ static INT __selFdsetGetFileCounter (INT iWidth,
if (ulPartMask == 0) {
iFd += NFDBITS - 1;
- } else if (ulPartMask & (ULONG)(1 << (((unsigned)iFd) % NFDBITS))) {
+ } else if (ulPartMask & (ULONG)(1ul << (((unsigned)iFd) % NFDBITS))) {
iFoundCounter++;
}
}
@@ -191,7 +191,7 @@ static INT __selFdsetGetFileCounter (INT iWidth,
if (ulPartMask == 0) {
iFd += NFDBITS - 1;
- } else if (ulPartMask & (ULONG)(1 << (((unsigned)iFd) % NFDBITS))) {
+ } else if (ulPartMask & (ULONG)(1ul << (((unsigned)iFd) % NFDBITS))) {
iFoundCounter++;
}
}
diff --git a/SylixOS/system/signal/signalEvent.c b/SylixOS/system/signal/signalEvent.c
index cf11c62..5673160 100644
--- a/SylixOS/system/signal/signalEvent.c
+++ b/SylixOS/system/signal/signalEvent.c
@@ -158,16 +158,17 @@ static INT _doSigEventInternal (LW_OBJECT_HANDLE ulId, PSIGNAL_EVENT_ARG psi
struct siginfo *psiginfo = &psigea->SE_event.SE_siginfo;
#if LW_CFG_POSIX_EN > 0
- iNotify = psigevent->sigev_notify & (~SIGEV_THREAD_ID);
- if (psigevent->sigev_notify & SIGEV_THREAD_ID) {
- ulId = psigevent->sigev_notify_thread_id; /* 向指定线程发送信号 */
+ if (psigevent->sigev_notify == SIGEV_THREAD_ID) { /* 向指定线程发送信号 */
+ ulId = psigevent->sigev_notify_thread_id;
+ iNotify = SIGEV_SIGNAL;
+ } else {
+ iNotify = psigevent->sigev_notify;
}
#else
iNotify = psigevent->sigev_notify;
#endif /* LW_CFG_POSIX_EN > 0 */
- if ((iNotify != SIGEV_SIGNAL) &&
- (iNotify != SIGEV_THREAD)) {
+ if (iNotify != SIGEV_SIGNAL) { /* 内核发送只支持 SIGNAL 类型 */
goto __out;
}
@@ -197,11 +198,6 @@ static INT _doSigEventInternal (LW_OBJECT_HANDLE ulId, PSIGNAL_EVENT_ARG psi
psigevent->sigev_notify,
psigevent->sigev_value.sival_ptr,
LW_NULL);
-
- if (iNotify == SIGEV_THREAD) {
- _ErrorHandle(ENOSYS);
- goto __out;
- }
_sigPendInit(&sigpend);