From 497b24715e004df8822863885ab900c34bc1575d Mon Sep 17 00:00:00 2001 From: kuangyufei Date: Wed, 4 Nov 2020 23:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E7=A1=AC=E4=BB=B6=E4=B8=AD=E6=96=AD?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=BA=90=E7=A0=81=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E5=AF=B9CPU=E5=90=84=E4=B8=AA=E5=AF=84=E5=AD=98=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=B3=A8=E9=87=8A=20=E9=B8=BF=E8=92=99?= =?UTF-8?q?=E5=86=85=E6=A0=B8=E6=BA=90=E7=A0=81=E5=88=86=E6=9E=90=E7=B3=BB?= =?UTF-8?q?=E5=88=97=20=E3=80=90=20CSDN=20|=20OSCHINA=20|=20WIKI=20?= =?UTF-8?q?=E3=80=91=20=E9=B8=BF=E8=92=99=E5=86=85=E6=A0=B8=E6=BA=90?= =?UTF-8?q?=E7=A0=81=E6=B3=A8=E9=87=8A=E4=B8=AD=E6=96=87=E7=89=88=20?= =?UTF-8?q?=E3=80=90=20CSDN=E4=BB=93=20|=20Gitee=E4=BB=93=20|=20Github?= =?UTF-8?q?=E4=BB=93=20|=20Coding=E4=BB=93=20=E3=80=91=E5=9B=9B=E5=A4=A7?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E6=AF=8F=E6=97=A5=E5=90=8C=E6=AD=A5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BB=A3=E7=A0=81=E5=92=8Cwiki=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=BB=99=E9=B8=BF=E8=92=99=E5=86=85=E6=A0=B8=E6=BA=90=E7=A0=81?= =?UTF-8?q?=E9=80=90=E8=A1=8C=E5=8A=A0=E4=B8=8A=E4=B8=AD=E6=96=87=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3,=E8=AF=A6=E7=BB=86=E9=98=90=E8=BF=B0=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E5=92=8C=E4=BB=A3=E7=A0=81=E7=BB=86=E8=8A=82,=20?= =?UTF-8?q?=E7=B2=BE=E8=AF=BB=20HarmonyOS=20=E5=86=85=E6=A0=B8=E6=BA=90?= =?UTF-8?q?=E7=A0=81,=20=E5=B0=86=E8=BF=85=E9=80=9F=E6=8B=94=E9=AB=98?= =?UTF-8?q?=E5=AF=B9=E8=AE=A1=E7=AE=97=E6=9C=BA=E6=95=B4=E4=BD=93=E7=90=86?= =?UTF-8?q?=E8=A7=A3,=E4=BB=8E=E6=AD=A4=E9=AB=98=E5=B1=8B=E5=BB=BA?= =?UTF-8?q?=E7=93=B4=E7=9C=8B=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arch/arm/arm/src/include/los_hwi_pri.h | 2 +- arch/arm/arm/src/los_hwi.c | 82 +++++++++++------------ arch/arm/include/los_hwi.h | 32 ++++----- kernel/base/sched/sched_sq/los_priqueue.c | 34 +++++----- kernel/extended/cpup/los_cpup.c | 4 +- platform/hw/arm/interrupt/gic/gic_v2.c | 22 +++--- platform/hw/arm/interrupt/gic/gic_v3.c | 8 +-- platform/hw/include/gic_common.h | 62 ++++++++++------- syscall/process_syscall.c | 28 ++++---- zzz/git/push.sh | 2 +- 10 files changed, 144 insertions(+), 132 deletions(-) diff --git a/arch/arm/arm/src/include/los_hwi_pri.h b/arch/arm/arm/src/include/los_hwi_pri.h index ea1726b6..5571c309 100644 --- a/arch/arm/arm/src/include/los_hwi_pri.h +++ b/arch/arm/arm/src/include/los_hwi_pri.h @@ -49,7 +49,7 @@ extern "C" { #error "OS_HWI_FORM_EXC_NUM must be zero" #endif -#ifdef LOSCFG_NO_SHARED_IRQ +#ifdef LOSCFG_NO_SHARED_IRQ //不共享中断 #define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pfnHook != NULL) #else #define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL) diff --git a/arch/arm/arm/src/los_hwi.c b/arch/arm/arm/src/los_hwi.c index 733fc010..07ef73e8 100644 --- a/arch/arm/arm/src/los_hwi.c +++ b/arch/arm/arm/src/los_hwi.c @@ -48,71 +48,71 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin); #define HWI_LOCK(state) LOS_SpinLockSave(&g_hwiSpin, &(state)) #define HWI_UNLOCK(state) LOS_SpinUnlockRestore(&g_hwiSpin, (state)) -size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0}; -HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; -STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0}; -STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0}; +size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0};//记录每个CPU core的中断数量 +HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; //记录每个硬件中断实体内容 @note_what 表用 form 来表示?有种写 HTML的感觉 +STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};//记录每个硬中断的名称 +STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};//记录每个硬中断的总数量 -VOID OsIncHwiFormCnt(UINT32 index) +VOID OsIncHwiFormCnt(UINT32 index) //增加一个中断数,递增的,所以只有++ ,没有--, { g_hwiFormCnt[index]++; } -UINT32 OsGetHwiFormCnt(UINT32 index) +UINT32 OsGetHwiFormCnt(UINT32 index)//获取某个中断的中断次数 { return g_hwiFormCnt[index]; } -CHAR *OsGetHwiFormName(UINT32 index) +CHAR *OsGetHwiFormName(UINT32 index)//获取某个中断的名称 { return g_hwiFormName[index]; } typedef VOID (*HWI_PROC_FUNC0)(VOID); typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *); -VOID OsInterrupt(UINT32 intNum) +VOID OsInterrupt(UINT32 intNum)//中断实际处理函数 { HwiHandleForm *hwiForm = NULL; UINT32 *intCnt = NULL; - intCnt = &g_intCount[ArchCurrCpuid()]; + intCnt = &g_intCount[ArchCurrCpuid()];//当前CPU的中断总数量 ++ *intCnt = *intCnt + 1; -#ifdef LOSCFG_CPUP_INCLUDE_IRQ +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //开启查询系统CPU的占用率的中断 OsCpupIrqStart(); #endif #ifdef LOSCFG_KERNEL_TICKLESS OsTicklessUpdate(intNum); #endif - hwiForm = (&g_hwiForm[intNum]); -#ifndef LOSCFG_NO_SHARED_IRQ - while (hwiForm->pstNext != NULL) { - hwiForm = hwiForm->pstNext; + hwiForm = (&g_hwiForm[intNum]);//获取对应中断的实体 +#ifndef LOSCFG_NO_SHARED_IRQ //如果没有定义不共享中断 ,意思就是如果是共享中断 + while (hwiForm->pstNext != NULL) { //一直撸到最后 + hwiForm = hwiForm->pstNext;//下一个继续撸 #endif - if (hwiForm->uwParam) { - HWI_PROC_FUNC2 func = (HWI_PROC_FUNC2)hwiForm->pfnHook; + if (hwiForm->uwParam) {//有参数的情况 + HWI_PROC_FUNC2 func = (HWI_PROC_FUNC2)hwiForm->pfnHook;//获取回调函数 if (func != NULL) { UINTPTR *param = (UINTPTR *)(hwiForm->uwParam); - func((INT32)(*param), (VOID *)(*(param + 1))); + func((INT32)(*param), (VOID *)(*(param + 1)));//运行带参数的回调函数 } - } else { - HWI_PROC_FUNC0 func = (HWI_PROC_FUNC0)hwiForm->pfnHook; + } else {//木有参数的情况 + HWI_PROC_FUNC0 func = (HWI_PROC_FUNC0)hwiForm->pfnHook;//获取回调函数 if (func != NULL) { - func(); + func();//运行回调函数 } } #ifndef LOSCFG_NO_SHARED_IRQ } #endif - ++g_hwiFormCnt[intNum]; + ++g_hwiFormCnt[intNum];//中断数量计数器++ - *intCnt = *intCnt - 1; -#ifdef LOSCFG_CPUP_INCLUDE_IRQ + *intCnt = *intCnt - 1; //@note_why 这里没看明白有什么要 -1 +#ifdef LOSCFG_CPUP_INCLUDE_IRQ //开启查询系统CPU的占用率的中断 OsCpupIrqEnd(intNum); #endif } - +//copy 硬中断参数 STATIC HWI_ARG_T OsHwiCpIrqParam(const HwiIrqParam *irqParam) { HwiIrqParam *paramByAlloc = NULL; @@ -134,16 +134,16 @@ STATIC UINT32 OsHwiDelNoShared(HWI_HANDLE_T hwiNum) UINT32 intSave; HWI_LOCK(intSave); - g_hwiForm[hwiNum].pfnHook = NULL; - if (g_hwiForm[hwiNum].uwParam) { - (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)g_hwiForm[hwiNum].uwParam); + g_hwiForm[hwiNum].pfnHook = NULL;//回调函数直接NULL + if (g_hwiForm[hwiNum].uwParam) {//如有参数 + (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)g_hwiForm[hwiNum].uwParam);//释放内存 } - g_hwiForm[hwiNum].uwParam = 0; + g_hwiForm[hwiNum].uwParam = 0; //NULL HWI_UNLOCK(intSave); return LOS_OK; } - +//创建一个不支持共享的中断 STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam) { @@ -152,14 +152,14 @@ STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, HWI_LOCK(intSave); if (g_hwiForm[hwiNum].pfnHook == NULL) { - g_hwiForm[hwiNum].pfnHook = hwiHandler; + g_hwiForm[hwiNum].pfnHook = hwiHandler;//记录上回调函数 - retParam = OsHwiCpIrqParam(irqParam); + retParam = OsHwiCpIrqParam(irqParam);//参数copy一份出来记录 if (retParam == LOS_NOK) { HWI_UNLOCK(intSave); return OS_ERRNO_HWI_NO_MEMORY; } - g_hwiForm[hwiNum].uwParam = retParam; + g_hwiForm[hwiNum].uwParam = retParam;//作为硬中断处理函数的参数 } else { HWI_UNLOCK(intSave); return OS_ERRNO_HWI_ALREADY_CREATED; @@ -167,7 +167,7 @@ STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, HWI_UNLOCK(intSave); return LOS_OK; } -#else +#else //删除一个共性的中断 STATIC UINT32 OsHwiDelShared(HWI_HANDLE_T hwiNum, const HwiIrqParam *irqParam) { HwiHandleForm *hwiForm = NULL; @@ -225,7 +225,7 @@ STATIC UINT32 OsHwiDelShared(HWI_HANDLE_T hwiNum, const HwiIrqParam *irqParam) HWI_UNLOCK(intSave); return LOS_OK; } - +//创建一个共享硬件中断 STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam) { @@ -287,7 +287,7 @@ STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, /* * Description : initialization of the hardware interrupt */ -LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID) +LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)//硬件中断初始化 { UINT32 hwiNum; @@ -303,7 +303,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID) return; } - +//创建一个硬中断 LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T hwiMode, @@ -313,21 +313,21 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, UINT32 ret; (VOID)hwiPrio; - if (hwiHandler == NULL) { + if (hwiHandler == NULL) {//中断处理函数不能为NULL return OS_ERRNO_HWI_PROC_FUNC_NULL; } - if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) { + if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) {//中断数区间限制 return OS_ERRNO_HWI_NUM_INVALID; } -#ifdef LOSCFG_NO_SHARED_IRQ +#ifdef LOSCFG_NO_SHARED_IRQ //不支持共享中断 ret = OsHwiCreateNoShared(hwiNum, hwiMode, hwiHandler, irqParam); #else ret = OsHwiCreateShared(hwiNum, hwiMode, hwiHandler, irqParam); #endif return ret; } - +//删除一个硬中断 LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) { UINT32 ret; @@ -336,7 +336,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irq return OS_ERRNO_HWI_NUM_INVALID; } -#ifdef LOSCFG_NO_SHARED_IRQ +#ifdef LOSCFG_NO_SHARED_IRQ //不支持共享中断 ret = OsHwiDelNoShared(hwiNum); #else ret = OsHwiDelShared(hwiNum, irqParam); diff --git a/arch/arm/include/los_hwi.h b/arch/arm/include/los_hwi.h index c221aefc..1c56fdc5 100644 --- a/arch/arm/include/los_hwi.h +++ b/arch/arm/include/los_hwi.h @@ -212,19 +212,19 @@ extern size_t g_intCount[]; /** * @ingroup los_hwi - * Define the type of a hardware interrupt number. + * Define the type of a hardware interrupt number. //定义硬件中断号的类型 */ typedef UINT32 HWI_HANDLE_T; /** * @ingroup los_hwi - * Define the type of a hardware interrupt priority. + * Define the type of a hardware interrupt priority. //定义硬件中断优先级的类型 */ -typedef UINT16 HWI_PRIOR_T; +typedef UINT16 HWI_PRIOR_T; //定义 /** * @ingroup los_hwi - * Define the type of hardware interrupt mode configurations. + * Define the type of hardware interrupt mode configurations. //定义硬件中断配置的类型 */ typedef UINT16 HWI_MODE_T; @@ -232,12 +232,12 @@ typedef UINT16 HWI_MODE_T; * @ingroup los_hwi * Define the type of the parameter used for the hardware interrupt creation function. * The function of this parameter varies among platforms. - */ + */ //定义用于硬件中断创建功能的参数类型。此参数的功能因平台而异 typedef UINTPTR HWI_ARG_T; /** * @ingroup los_hwi - * Define the type of a hardware interrupt handling function. + * Define the type of a hardware interrupt handling function. //定义硬件中断处理函数的类型 */ typedef VOID (*HWI_PROC_FUNC)(VOID); @@ -247,21 +247,21 @@ typedef VOID (*HWI_PROC_FUNC)(VOID); * * IRQF_SHARED - allow sharing the irq among several devices */ -#define IRQF_SHARED 0x8000U +#define IRQF_SHARED 0x8000U //IRQF_SHARED-允许在多个设备之间共享irq -typedef struct tagHwiHandleForm { - HWI_PROC_FUNC pfnHook; - HWI_ARG_T uwParam; - struct tagHwiHandleForm *pstNext; +typedef struct tagHwiHandleForm { + HWI_PROC_FUNC pfnHook; //中断处理函数 + HWI_ARG_T uwParam; //中断处理函数参数 + struct tagHwiHandleForm *pstNext; //节点,指向下一个中断 } HwiHandleForm; -typedef struct tagIrqParam { - int swIrq; - VOID *pDevId; - const CHAR *pName; +typedef struct tagIrqParam { //中断参数 + int swIrq; // 软件中断 + VOID *pDevId; // 设备ID + const CHAR *pName; //名称 } HwiIrqParam; -extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; +extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];//最大中断数量,OS_HWI_MAX_NUM 见于 ..\vendor_hisi_hi3861_hi3861\hi3861\platform\os\Huawei_LiteOS\arch\los_hwi.h /** * @ingroup los_hwi diff --git a/kernel/base/sched/sched_sq/los_priqueue.c b/kernel/base/sched/sched_sq/los_priqueue.c index 250afc5b..9db5d97f 100644 --- a/kernel/base/sched/sched_sq/los_priqueue.c +++ b/kernel/base/sched/sched_sq/los_priqueue.c @@ -41,7 +41,7 @@ extern "C" { #endif #endif /* __cplusplus */ -//*kfy 0x80000000U = 10000000000000000000000000000000(32个0) +// 0x80000000U = 10000000000000000000000000000000(32个0) #define PRIQUEUE_PRIOR0_BIT 0x80000000U LITE_OS_SEC_BSS LOS_DL_LIST *g_priQueueList = NULL;//队列链表 @@ -84,11 +84,11 @@ VOID OsPriQueueEnqueueHead(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIS */ LOS_ASSERT(priqueueItem->pstNext == NULL); - if (LOS_ListEmpty(&priQueueList[priority])) { - *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority; + if (LOS_ListEmpty(&priQueueList[priority])) {//队列不为空 + *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;//位图调度器上记录优先级 } - LOS_ListHeadInsert(&priQueueList[priority], priqueueItem); + LOS_ListHeadInsert(&priQueueList[priority], priqueueItem);//从头部插入 } VOID OsPriQueueEnqueue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem, UINT32 priority) @@ -100,21 +100,21 @@ VOID OsPriQueueEnqueue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *p */ LOS_ASSERT(priqueueItem->pstNext == NULL); - if (LOS_ListEmpty(&priQueueList[priority])) { - *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;//移到对应位 + if (LOS_ListEmpty(&priQueueList[priority])) {////队列不为空 + *bitMap |= PRIQUEUE_PRIOR0_BIT >> priority;//位图调度器上记录优先级 } - LOS_ListTailInsert(&priQueueList[priority], priqueueItem); + LOS_ListTailInsert(&priQueueList[priority], priqueueItem);//从尾部插入 } - +//出队列 VOID OsPriQueueDequeue(LOS_DL_LIST *priQueueList, UINT32 *bitMap, LOS_DL_LIST *priqueueItem) { LosTaskCB *task = NULL; - LOS_ListDelete(priqueueItem); + LOS_ListDelete(priqueueItem);//将item从队列中摘除 - task = LOS_DL_LIST_ENTRY(priqueueItem, LosTaskCB, pendList); - if (LOS_ListEmpty(&priQueueList[task->priority])) { - *bitMap &= ~(PRIQUEUE_PRIOR0_BIT >> task->priority); + task = LOS_DL_LIST_ENTRY(priqueueItem, LosTaskCB, pendList);//通过pendList节点,找到task + if (LOS_ListEmpty(&priQueueList[task->priority])) {//队列不为空时 + *bitMap &= ~(PRIQUEUE_PRIOR0_BIT >> task->priority);//位图调度器上记录优先级 } } @@ -128,7 +128,7 @@ VOID OsPriQueueProcessDequeue(LOS_DL_LIST *priqueueItem) g_priQueueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> runProcess->priority); } } - +//队列大小 UINT32 OsPriQueueProcessSize(LOS_DL_LIST *priQueueList, UINT32 priority) { UINT32 itemCnt = 0; @@ -137,7 +137,7 @@ UINT32 OsPriQueueProcessSize(LOS_DL_LIST *priQueueList, UINT32 priority) LOS_ASSERT(OsIntLocked()); LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); - LOS_DL_LIST_FOR_EACH(curNode, &priQueueList[priority]) { + LOS_DL_LIST_FOR_EACH(curNode, &priQueueList[priority]) {//遍历队列 ++itemCnt; } @@ -158,7 +158,7 @@ UINT32 OsPriQueueSize(LOS_DL_LIST *priQueueList, UINT32 priority) LOS_DL_LIST_FOR_EACH(curNode, &priQueueList[priority]) {//循环查找这优先级的数量 #if (LOSCFG_KERNEL_SMP == YES) - task = OS_TCB_FROM_PENDLIST(curNode);//找到task + task = OS_TCB_FROM_PENDLIST(curNode);//通过pendList节点找到task if (!(task->cpuAffiMask & (1U << cpuID))) {//属不属于当前CPU continue; } @@ -175,7 +175,7 @@ LOS_DL_LIST *OsTaskPriQueueTop(VOID) LosProcessCB *processCB = LOS_DL_LIST_ENTRY(OsPriQueueTop(g_priQueueList, &g_priQueueBitmap), LosProcessCB, pendList); - return OsPriQueueTop(processCB->threadPriQueueList, &processCB->threadScheduleMap); + return OsPriQueueTop(processCB->threadPriQueueList, &processCB->threadScheduleMap);//获取进程就绪队列中优先级最高的task } STATIC INLINE VOID OsDequeEmptySchedMap(LosProcessCB *processCB) @@ -185,7 +185,7 @@ STATIC INLINE VOID OsDequeEmptySchedMap(LosProcessCB *processCB) OsPriQueueProcessDequeue(&processCB->pendList); } } - +//这个函数留给大家看,内核最美函数 获取优先级最高的task,了解了这个函数就了解了调度的机制 LITE_OS_SEC_TEXT_MINOR LosTaskCB *OsGetTopTask(VOID) { UINT32 priority, processPriority; diff --git a/kernel/extended/cpup/los_cpup.c b/kernel/extended/cpup/los_cpup.c index 9436e8a5..4fcdefa9 100644 --- a/kernel/extended/cpup/los_cpup.c +++ b/kernel/extended/cpup/los_cpup.c @@ -506,14 +506,14 @@ LITE_OS_SEC_TEXT UINT32 OsAllCpuUsageUnsafe(UINT16 maxNum, CPUP_INFO_S *cpupInfo OsProcessCycleStart(); return LOS_OK; } - +// shell cpup 命令,查看所有CPU的使用情况 89.9% LITE_OS_SEC_TEXT_MINOR UINT32 LOS_AllCpuUsage(UINT16 maxNum, CPUP_INFO_S *cpupInfo, UINT16 mode, UINT16 flag) { UINT32 intSave; UINT32 ret; SCHEDULER_LOCK(intSave); - ret = OsAllCpuUsageUnsafe(maxNum, cpupInfo, mode, flag); + ret = OsAllCpuUsageUnsafe(maxNum, cpupInfo, mode, flag);//所有CPU使用情况 SCHEDULER_UNLOCK(intSave); return ret; diff --git a/platform/hw/arm/interrupt/gic/gic_v2.c b/platform/hw/arm/interrupt/gic/gic_v2.c index df789ceb..e7b76e4a 100644 --- a/platform/hw/arm/interrupt/gic/gic_v2.c +++ b/platform/hw/arm/interrupt/gic/gic_v2.c @@ -72,7 +72,7 @@ UINT32 HalCurIrqGet(VOID) { return g_curIrqNum; } - +//屏蔽中断 VOID HalIrqMask(UINT32 vector) { if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) { @@ -81,7 +81,7 @@ VOID HalIrqMask(UINT32 vector) GIC_REG_32(GICD_ICENABLER(vector / 32)) = 1U << (vector % 32); } - +//解除屏蔽 VOID HalIrqUnmask(UINT32 vector) { if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) { @@ -104,36 +104,36 @@ VOID HalIrqClear(UINT32 vector) { GIC_REG_32(GICC_EOIR) = vector; } - +//给每个CPU core初始化硬件中断 VOID HalIrqInitPercpu(VOID) { - /* unmask interrupts */ + /* unmask interrupts */ //取消屏蔽中断 GIC_REG_32(GICC_PMR) = 0xFF; - /* enable gic cpu interface */ + /* enable gic cpu interface */ //启用gic cpu接口 GIC_REG_32(GICC_CTLR) = 1; } - +//硬件中断初始化 VOID HalIrqInit(VOID) { UINT32 i; - /* set externel interrupts to be level triggered, active low. */ + /* set externel interrupts to be level triggered, active low. */ //将外部中断设置为电平触发,低电平激活 for (i = 32; i < OS_HWI_MAX_NUM; i += 16) { GIC_REG_32(GICD_ICFGR(i / 16)) = 0; } - /* set externel interrupts to CPU 0 */ + /* set externel interrupts to CPU 0 */ //将外部中断设置为CPU 0 for (i = 32; i < OS_HWI_MAX_NUM; i += 4) { GIC_REG_32(GICD_ITARGETSR(i / 4)) = 0x01010101; } - /* set priority on all interrupts */ + /* set priority on all interrupts */ //设置所有中断的优先级 for (i = 0; i < OS_HWI_MAX_NUM; i += 4) { GIC_REG_32(GICD_IPRIORITYR(i / 4)) = GICD_INT_DEF_PRI_X4; } - /* disable all interrupts. */ + /* disable all interrupts. */ //禁用所有中断。 for (i = 0; i < OS_HWI_MAX_NUM; i += 32) { GIC_REG_32(GICD_ICENABLER(i / 32)) = ~0; } @@ -151,7 +151,7 @@ VOID HalIrqInit(VOID) LOS_HwiCreate(LOS_MP_IPI_HALT, 0xa0, 0, OsMpScheduleHandler, 0);//中断处理函数 #endif } - +//硬中断处理函数,这里由硬件触发 VOID HalIrqHandler(VOID) { UINT32 iar = GIC_REG_32(GICC_IAR); diff --git a/platform/hw/arm/interrupt/gic/gic_v3.c b/platform/hw/arm/interrupt/gic/gic_v3.c index 2cfbc41a..62dd6ab2 100644 --- a/platform/hw/arm/interrupt/gic/gic_v3.c +++ b/platform/hw/arm/interrupt/gic/gic_v3.c @@ -243,18 +243,18 @@ UINT32 HalCurIrqGet(VOID) { return g_curIrqNum; } - +//屏蔽所有CPU的硬件中断 VOID HalIrqMask(UINT32 vector) { INT32 i; - const UINT32 mask = 1U << (vector % 32); + const UINT32 mask = 1U << (vector % 32);//通过参数获取掩码 if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) { return; } if (vector < 32) { - for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) { + for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {// GIC_REG_32(GICR_ICENABLER0(i)) = mask; GicWaitForRwp(GICR_CTLR(i)); } @@ -263,7 +263,7 @@ VOID HalIrqMask(UINT32 vector) GicWaitForRwp(GICD_CTLR); } } - +//取消屏蔽硬件中断 VOID HalIrqUnmask(UINT32 vector) { INT32 i; diff --git a/platform/hw/include/gic_common.h b/platform/hw/include/gic_common.h index 239b003a..f672a368 100644 --- a/platform/hw/include/gic_common.h +++ b/platform/hw/include/gic_common.h @@ -35,7 +35,19 @@ #include "stdint.h" #include "asm/platform.h" #include "los_config.h" +/************************************************************************************* +* +* GIC(Generic Interrupt Controller)是ARM公司提供的一个通用的中断控制器, +* 其architecture specification目前有四个版本, +* V1~V4(V2最多支持8个ARM core,V3/V4支持更多的ARM core,主要用于ARM64服务器系统结构 +* GIC-v2支持三种类型的中断 +* PPI:私有外设中断(Private Peripheral Interrupt),是每个CPU私有的中断。最多支持16个PPI中断, +* 硬件中断号从ID16~ID31。PPI通常会送达到指定的CPU上,应用场景有CPU本地时钟。 +* SPI:公用外设中断(Shared Peripheral Interrupt),最多可以支持988个外设中断,硬件中断号从ID32~ID1019。 +* SGI:软件触发中断(Software Generated Interrupt)通常用于多核间通讯,最多支持16个SGI中断,硬件中断号从ID0~ID15。 +* SGI通常在内核中被用作 IPI 中断(inter-processor interrupts),并会送达到系统指定的CPU上。 +**************************************************************************************/ /* gic arch revision */ enum { GICV1 = 1, @@ -48,37 +60,37 @@ enum { #define GIC_REV_OFFSET 0x4 #ifdef LOSCFG_PLATFORM_BSP_GIC_V2 -#define GICC_CTLR (GICC_OFFSET + 0x00) /* CPU Interface Control Register */ -#define GICC_PMR (GICC_OFFSET + 0x04) /* Interrupt Priority Mask Register */ -#define GICC_BPR (GICC_OFFSET + 0x08) /* Binary Point Register */ -#define GICC_IAR (GICC_OFFSET + 0x0c) /* Interrupt Acknowledge Register */ -#define GICC_EOIR (GICC_OFFSET + 0x10) /* End of Interrupt Register */ -#define GICC_RPR (GICC_OFFSET + 0x14) /* Running Priority Register */ -#define GICC_HPPIR (GICC_OFFSET + 0x18) /* Highest Priority Pending Interrupt Register */ +#define GICC_CTLR (GICC_OFFSET + 0x00) /* CPU Interface Control Register */ //CPU接口控制寄存器 +#define GICC_PMR (GICC_OFFSET + 0x04) /* Interrupt Priority Mask Register */ //中断优先级屏蔽寄存器 +#define GICC_BPR (GICC_OFFSET + 0x08) /* Binary Point Register */ //二进制点寄存器 +#define GICC_IAR (GICC_OFFSET + 0x0c) /* Interrupt Acknowledge Register */ //中断确认寄存器 +#define GICC_EOIR (GICC_OFFSET + 0x10) /* End of Interrupt Register */ //中断结尾寄存器 +#define GICC_RPR (GICC_OFFSET + 0x14) /* Running Priority Register */ //运行优先寄存器 +#define GICC_HPPIR (GICC_OFFSET + 0x18) /* Highest Priority Pending Interrupt Register */ //最高优先级挂起中断寄存器 #endif -#define GICD_CTLR (GICD_OFFSET + 0x000) /* Distributor Control Register */ -#define GICD_TYPER (GICD_OFFSET + 0x004) /* Interrupt Controller Type Register */ -#define GICD_IIDR (GICD_OFFSET + 0x008) /* Distributor Implementer Identification Register */ -#define GICD_IGROUPR(n) (GICD_OFFSET + 0x080 + (n) * 4) /* Interrupt Group Registers */ -#define GICD_ISENABLER(n) (GICD_OFFSET + 0x100 + (n) * 4) /* Interrupt Set-Enable Registers */ -#define GICD_ICENABLER(n) (GICD_OFFSET + 0x180 + (n) * 4) /* Interrupt Clear-Enable Registers */ -#define GICD_ISPENDR(n) (GICD_OFFSET + 0x200 + (n) * 4) /* Interrupt Set-Pending Registers */ -#define GICD_ICPENDR(n) (GICD_OFFSET + 0x280 + (n) * 4) /* Interrupt Clear-Pending Registers */ -#define GICD_ISACTIVER(n) (GICD_OFFSET + 0x300 + (n) * 4) /* GICv2 Interrupt Set-Active Registers */ -#define GICD_ICACTIVER(n) (GICD_OFFSET + 0x380 + (n) * 4) /* Interrupt Clear-Active Registers */ -#define GICD_IPRIORITYR(n) (GICD_OFFSET + 0x400 + (n) * 4) /* Interrupt Priority Registers */ -#define GICD_ITARGETSR(n) (GICD_OFFSET + 0x800 + (n) * 4) /* Interrupt Processor Targets Registers */ -#define GICD_ICFGR(n) (GICD_OFFSET + 0xc00 + (n) * 4) /* Interrupt Configuration Registers */ -#define GICD_SGIR (GICD_OFFSET + 0xf00) /* Software Generated Interrupt Register */ -#define GICD_CPENDSGIR(n) (GICD_OFFSET + 0xf10 + (n) * 4) /* SGI Clear-Pending Registers; NOT available on cortex-a9 */ -#define GICD_SPENDSGIR(n) (GICD_OFFSET + 0xf20 + (n) * 4) /* SGI Set-Pending Registers; NOT available on cortex-a9 */ +#define GICD_CTLR (GICD_OFFSET + 0x000) /* Distributor Control Register */ //仲裁控制寄存器 +#define GICD_TYPER (GICD_OFFSET + 0x004) /* Interrupt Controller Type Register */ //中断控制器类型寄存器 +#define GICD_IIDR (GICD_OFFSET + 0x008) /* Distributor Implementer Identification Register */ //仲裁身份寄存器 +#define GICD_IGROUPR(n) (GICD_OFFSET + 0x080 + (n) * 4) /* Interrupt Group Registers */ //中断组寄存器 +#define GICD_ISENABLER(n) (GICD_OFFSET + 0x100 + (n) * 4) /* Interrupt Set-Enable Registers */ //中断设置使能寄存器 +#define GICD_ICENABLER(n) (GICD_OFFSET + 0x180 + (n) * 4) /* Interrupt Clear-Enable Registers */ //中断清除使能寄存器 +#define GICD_ISPENDR(n) (GICD_OFFSET + 0x200 + (n) * 4) /* Interrupt Set-Pending Registers */ //中断设置挂起寄存器 +#define GICD_ICPENDR(n) (GICD_OFFSET + 0x280 + (n) * 4) /* Interrupt Clear-Pending Registers */ //中断清除挂起寄存器 +#define GICD_ISACTIVER(n) (GICD_OFFSET + 0x300 + (n) * 4) /* GICv2 Interrupt Set-Active Registers */ //GICv2中断设置激活寄存器 +#define GICD_ICACTIVER(n) (GICD_OFFSET + 0x380 + (n) * 4) /* Interrupt Clear-Active Registers */ //GICv2中断清除激活寄存器 +#define GICD_IPRIORITYR(n) (GICD_OFFSET + 0x400 + (n) * 4) /* Interrupt Priority Registers */ //中断优先级寄存器 +#define GICD_ITARGETSR(n) (GICD_OFFSET + 0x800 + (n) * 4) /* Interrupt Processor Targets Registers */ //中断处理器目标寄存器 +#define GICD_ICFGR(n) (GICD_OFFSET + 0xc00 + (n) * 4) /* Interrupt Configuration Registers */ //中断配置寄存器 +#define GICD_SGIR (GICD_OFFSET + 0xf00) /* Software Generated Interrupt Register */ //由软件产生的中断寄存器 +#define GICD_CPENDSGIR(n) (GICD_OFFSET + 0xf10 + (n) * 4) /* SGI Clear-Pending Registers; NOT available on cortex-a9 */ //SGI清除挂起寄存器;在cortex-a9上不可用 +#define GICD_SPENDSGIR(n) (GICD_OFFSET + 0xf20 + (n) * 4) /* SGI Set-Pending Registers; NOT available on cortex-a9 */ //SGI设置挂起寄存器;在cortex-a9上不可用 #define GICD_PIDR2V2 (GICD_OFFSET + 0xfe8) #define GICD_PIDR2V3 (GICD_OFFSET + 0xffe8) #ifdef LOSCFG_PLATFORM_BSP_GIC_V3 -#define GICD_IGRPMODR(n) (GICD_OFFSET + 0x0d00 + (n) * 4) /* Interrupt Group Mode Reisters */ -#define GICD_IROUTER(n) (GICD_OFFSET + 0x6000 + (n) * 8) /* Interrupt Rounter Reisters */ +#define GICD_IGRPMODR(n) (GICD_OFFSET + 0x0d00 + (n) * 4) /* Interrupt Group Mode Registers */ //中断组模式寄存器 +#define GICD_IROUTER(n) (GICD_OFFSET + 0x6000 + (n) * 8) /* Interrupt Rounter Registers */ //中断阻断寄存器 #endif #define GIC_REG_8(reg) (*(volatile UINT8 *)((UINTPTR)(GIC_BASE_ADDR + (reg)))) diff --git a/syscall/process_syscall.c b/syscall/process_syscall.c index ede81553..b5cf00d8 100644 --- a/syscall/process_syscall.c +++ b/syscall/process_syscall.c @@ -759,7 +759,7 @@ static int GetGroups(int size, int list[]) return groupCount; } #endif - +//系统调用之获取组 int SysGetGroups(int size, int list[]) { #ifdef LOSCFG_SECURITY_CAPABILITY @@ -785,7 +785,7 @@ int SysGetGroups(int size, int list[]) return groupCount; #endif } - +//系统调用之设置组 int SysSetGroups(int size, int list[]) { #ifdef LOSCFG_SECURITY_CAPABILITY @@ -842,13 +842,13 @@ EXIT: return 0; #endif } - +//系统调用之创建一个用户线程 unsigned int SysCreateUserThread(const TSK_ENTRY_FUNC func, const UserTaskParam *userParam, bool joinable) { TSK_INIT_PARAM_S param = { 0 }; int ret; - ret = LOS_ArchCopyFromUser(&(param.userParam), userParam, sizeof(UserTaskParam)); + ret = LOS_ArchCopyFromUser(&(param.userParam), userParam, sizeof(UserTaskParam));//参数copy,将用户空间的参数信息copy到内核空间 if (ret != 0) { return OS_INVALID_VALUE; } @@ -860,9 +860,9 @@ unsigned int SysCreateUserThread(const TSK_ENTRY_FUNC func, const UserTaskParam param.uwResved = OS_TASK_FLAG_DETACHED; } - return OsCreateUserTask(OS_INVALID_VALUE, ¶m); + return OsCreateUserTask(OS_INVALID_VALUE, ¶m);//创建用户task } -//系统调用-设置线程使用区域,所有的系统调用都运行在内核态,也运行在内核空间 +//系统调用之设置线程使用区域,所有的系统调用都运行在内核态,也运行在内核空间 int SysSetThreadArea(const char *area) { unsigned int intSave; @@ -887,12 +887,12 @@ OUT: SCHEDULER_UNLOCK(intSave); return ret; } -//获取系统调用线程的使用区域 +//系统调用之获取线程的使用区域 char *SysGetThreadArea(void) { return (char *)(OsCurrTaskGet()->userArea);//直接返回使用区域 } - +//系统调用之设置任务为分离模式 int SysUserThreadSetDeatch(unsigned int taskID) { unsigned int intSave; @@ -916,7 +916,7 @@ EXIT: SCHEDULER_UNLOCK(intSave); return ret; } - +//系统调用之线程分离,意思是这是一个独立的线程 int SysUserThreadDetach(unsigned int taskID) { unsigned int intSave; @@ -942,7 +942,7 @@ int SysUserThreadDetach(unsigned int taskID) return LOS_OK; } - +//系统调用之线程联结,意思是这是一个可联结的线程 int SysThreadJoin(unsigned int taskID) { unsigned int intSave; @@ -966,12 +966,12 @@ EXIT: SCHEDULER_UNLOCK(intSave); return ret; } - +//系统调用之退出线程组 void SysUserExitGroup(int status) { OsTaskExitGroup((unsigned int)status); } - +//系统调用之退出线程 void SysThreadExit(int status) { OsTaskToExit(OsCurrTaskGet(), (unsigned int)status); @@ -990,10 +990,10 @@ int SysFutex(const unsigned int *uAddr, unsigned int flags, int val, return -OsFutexWait(uAddr, flags, val, absTime); } - +//获取当前任务ID unsigned int SysGetTid(void) { - return OsCurrTaskGet()->taskID; + return OsCurrTaskGet()->taskID;//获取当前任务ID } #ifdef __cplusplus diff --git a/zzz/git/push.sh b/zzz/git/push.sh index e9eb47ac..9784f03b 100644 --- a/zzz/git/push.sh +++ b/zzz/git/push.sh @@ -1,5 +1,5 @@ git add -A -git commit -m '对 cpu sortlink 部分代码注释 +git commit -m '对硬件中断部分源码注释,对CPU各个寄存器功能注释 鸿蒙内核源码分析系列 【 CSDN | OSCHINA | WIKI 】 鸿蒙内核源码注释中文版 【 CSDN仓 | Gitee仓 | Github仓 | Coding仓 】四大仓库每日同步更新代码和wiki 项目给鸿蒙内核源码逐行加上中文注解,详细阐述框架和代码细节, 精读 HarmonyOS 内核源码, 将迅速拔高对计算机整体理解,从此高屋建瓴看问题.' -- GitLab