Compare commits
24 Commits
weekly_202
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00a43c7b12 | ||
|
|
5e3e1daf0f | ||
|
|
6be4577b12 | ||
|
|
91c538f27e | ||
|
|
93b2acdbe4 | ||
|
|
886c4f181d | ||
|
|
ee95e95a2f | ||
|
|
efd0e27784 | ||
|
|
bc7ff8f15b | ||
|
|
93989ae946 | ||
|
|
d8a6768d94 | ||
|
|
eb618aa22b | ||
|
|
7fa0a51b96 | ||
|
|
f60fdfecda | ||
|
|
1c18d227cf | ||
|
|
146c23f42f | ||
|
|
c49b81895e | ||
|
|
f60bc94cf2 | ||
|
|
174db030a4 | ||
|
|
d161a0b03d | ||
|
|
ba727e2678 | ||
|
|
a6ac7597f8 | ||
|
|
cdcf600571 | ||
|
|
1bb40f9848 |
37
BUILD.gn
37
BUILD.gn
@@ -35,7 +35,6 @@ declare_args() {
|
||||
tee_enable = false
|
||||
liteos_name = "OHOS_Image"
|
||||
liteos_skip_make = false
|
||||
liteos_is_mini = false
|
||||
}
|
||||
|
||||
tee = ""
|
||||
@@ -129,9 +128,7 @@ config("stdinc_config") {
|
||||
"-isystem",
|
||||
std_include,
|
||||
]
|
||||
if (!defined(LOSCFG_LIBC_NEWLIB)) {
|
||||
cflags += [ "-nostdinc" ]
|
||||
}
|
||||
cflags += [ "-nostdinc" ]
|
||||
asmflags = cflags
|
||||
}
|
||||
|
||||
@@ -292,7 +289,6 @@ group("modules") {
|
||||
"security",
|
||||
"shell",
|
||||
"syscall",
|
||||
"testsuites/kernel:kernel_test",
|
||||
]
|
||||
|
||||
deps += [
|
||||
@@ -318,17 +314,13 @@ group("kernel") {
|
||||
}
|
||||
|
||||
group("liteos_a") {
|
||||
deps = [ ":kernel" ]
|
||||
if (!liteos_is_mini) {
|
||||
deps += [
|
||||
":apps",
|
||||
":tests",
|
||||
"//third_party/musl/scripts/build_lite:strip",
|
||||
]
|
||||
if (liteos_skip_make == false) {
|
||||
deps += [ ":make" ]
|
||||
}
|
||||
}
|
||||
deps = [
|
||||
":apps",
|
||||
":kernel",
|
||||
":make",
|
||||
":tests",
|
||||
"//prebuilts/lite/sysroot/build:strip",
|
||||
]
|
||||
}
|
||||
|
||||
executable("liteos") {
|
||||
@@ -344,17 +336,6 @@ executable("liteos") {
|
||||
"-Wl,--no-eh-frame-hdr",
|
||||
]
|
||||
|
||||
if (defined(LOSCFG_LIBC_NEWLIB)) {
|
||||
ldflags += [
|
||||
"-Wl,--wrap=_free_r",
|
||||
"-Wl,--wrap,_malloc_usable_size_r",
|
||||
"-Wl,--wrap,_malloc_r",
|
||||
"-Wl,--wrap,_memalign_r",
|
||||
"-Wl,--wrap,_realloc_r",
|
||||
"-Wl,--wrap,_fseeko_r",
|
||||
]
|
||||
ldflags -= [ "-nostdlib" ]
|
||||
}
|
||||
libgcc = exec_script("//build/lite/run_shell_cmd.py",
|
||||
[ "$cc -print-libgcc-file-name" ],
|
||||
"trim string")
|
||||
@@ -366,7 +347,7 @@ executable("liteos") {
|
||||
} else {
|
||||
ldflags +=
|
||||
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
|
||||
ldflags += [ "-nostartfiles" ]
|
||||
ldflags += [ "-Wl,-nostartfiles" ]
|
||||
inputs = [ "tools/build/liteos.ld" ]
|
||||
}
|
||||
|
||||
|
||||
2
Kconfig
2
Kconfig
@@ -265,7 +265,7 @@ config MEM_LEAKCHECK
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the information of mem node.
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the informations of mem node.
|
||||
config BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
bool "Enable integrity check or not"
|
||||
default n
|
||||
|
||||
5
Makefile
5
Makefile
@@ -82,6 +82,9 @@ endif
|
||||
ifeq ($(LOSCFG_STORAGE_SPINAND), y)
|
||||
FSTYPE = yaffs2
|
||||
endif
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
FSTYPE = jffs2
|
||||
endif
|
||||
ROOTFS_DIR = $(OUT)/rootfs
|
||||
ROOTFS_ZIP = $(OUT)/rootfs.zip
|
||||
|
||||
@@ -118,7 +121,7 @@ sysroot:
|
||||
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
|
||||
ifeq ($(origin SYSROOT_PATH),file)
|
||||
$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
|
||||
ln -snf $(LITEOSTOPDIR)/../../third_party/musl/scripts/build_lite/Makefile && \
|
||||
ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \
|
||||
$(MAKE) TARGETS=liteos_a_user \
|
||||
ARCH=$(ARCH) \
|
||||
TARGET=$(LOSCFG_LLVM_TARGET) \
|
||||
|
||||
5
OAT.xml
5
OAT.xml
@@ -15,7 +15,7 @@
|
||||
-->
|
||||
|
||||
<!--
|
||||
This is the configuration file template for OpenHarmony OSS Audit Tool. Please copy it to your project root dir and modify it by referring to OpenHarmony/tools_oat/README.
|
||||
This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
@@ -24,7 +24,6 @@
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
<policyitem type="copyright" name="Huawei Technologies Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
|
||||
<policyitem type="copyright" name="Huawei Device Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
|
||||
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
|
||||
</policy>
|
||||
</policylist>
|
||||
@@ -39,7 +38,7 @@
|
||||
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
|
||||
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for license header policies">
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
|
||||
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
|
||||
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
|
||||
|
||||
@@ -33,7 +33,6 @@ OpenHarmony LiteOS-A内核是基于Huawei LiteOS内核演进发展的新一代
|
||||
│ ├── quickstart # 系统快速启动接口目录
|
||||
│ ├── random # 随机数设备驱动
|
||||
│ └── video # framebuffer驱动框架
|
||||
├── figures # 内核架构图
|
||||
├── fs # 文件系统模块,主要来源于NuttX开源项目
|
||||
│ ├── fat # fat文件系统
|
||||
│ ├── jffs2 # jffs2文件系统
|
||||
@@ -55,9 +54,7 @@ OpenHarmony LiteOS-A内核是基于Huawei LiteOS内核演进发展的新一代
|
||||
│ ├── include # 对外暴露头文件存放目录
|
||||
│ └── uart # 串口相关逻辑代码
|
||||
├── security # 安全特性相关的代码,包括进程权限管理和虚拟id映射管理
|
||||
├── shell # 接收用户输入的命令,内核去执行
|
||||
├── syscall # 系统调用
|
||||
├── testsuilts # 测试套件
|
||||
└── tools # 构建工具及相关配置和代码
|
||||
```
|
||||
|
||||
@@ -84,7 +81,7 @@ OpenHarmony LiteOS-A内核支持[Hi3516DV300](https://gitee.com/openharmony/docs
|
||||
|
||||
### 编译构建<a name="section2081013992812"></a>
|
||||
|
||||
如果这是您的首次应用程序开发,可参考:
|
||||
开发者开发第一个应用程序可参考:
|
||||
|
||||
- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516-running.md)。
|
||||
|
||||
|
||||
@@ -180,8 +180,7 @@ static void LmsStrcpyTest(void)
|
||||
return;
|
||||
}
|
||||
char *testStr = "bbbbbbbbbbbbbbbbb";
|
||||
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n",
|
||||
(int)strlen(testStr) + 1);
|
||||
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n", strlen(testStr) + 1);
|
||||
strcpy(buf, testStr);
|
||||
free(buf);
|
||||
printf("\n-------- LmsStrcpyTest End --------\n");
|
||||
|
||||
@@ -42,7 +42,7 @@ copy("copy_mksh_src") {
|
||||
|
||||
build_ext_component("build_mksh") {
|
||||
deps = [ ":copy_mksh_src" ]
|
||||
deps += [ "//third_party/musl:sysroot_lite" ]
|
||||
deps += [ "//prebuilts/lite/sysroot" ]
|
||||
exec_path = rebase_path("$target_out_dir/mksh_build")
|
||||
|
||||
cflags = [
|
||||
|
||||
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
|
||||
PerfStop(fd);
|
||||
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "read") == 0) {
|
||||
size_t size = strtoul(argv[THREE_ARGS - 1], NULL, 0);
|
||||
if (size == 0) {
|
||||
if (size <= 0) {
|
||||
goto EXIT:
|
||||
}
|
||||
|
||||
|
||||
@@ -32,15 +32,13 @@
|
||||
#ifndef _SHELL_PRI_H
|
||||
#define _SHELL_PRI_H
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void ShellEntry(ShellCB *shellCB);
|
||||
extern void *ShellEntry(void *argv);
|
||||
extern void *ShellTask(void *argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#ifndef _SHMSG_H
|
||||
#define _SHMSG_H
|
||||
|
||||
#include "shell_list.h"
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -62,7 +61,8 @@ extern "C" {
|
||||
|
||||
typedef void (* OutputFunc)(const char *fmt, ...);
|
||||
extern int ShellTaskInit(ShellCB *shellCB);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[], bool foreground);
|
||||
extern int ShellEntryInit(ShellCB *shellCB);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[]);
|
||||
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
|
||||
extern int ShellNotify(ShellCB *shellCB);
|
||||
|
||||
|
||||
@@ -31,16 +31,13 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include "show.h"
|
||||
#include "shmsg.h"
|
||||
#include "shcmd.h"
|
||||
#include "shell_pri.h"
|
||||
#include "semaphore.h"
|
||||
#include "securec.h"
|
||||
#include "unistd.h"
|
||||
#include <sys/syscall.h>
|
||||
|
||||
ShellCB *g_shellCB = NULL;
|
||||
|
||||
@@ -80,8 +77,13 @@ static int OsShellCreateTask(ShellCB *shellCB)
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
shellCB->shellEntryHandle = pthread_self();
|
||||
return 0;
|
||||
ret = ShellEntryInit(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
(void)pthread_join(shellCB->shellTaskHandle, NULL);
|
||||
(void)pthread_join(shellCB->shellEntryHandle, NULL);
|
||||
|
||||
OUT:
|
||||
ShellDeinit(shellCB);
|
||||
@@ -96,7 +98,7 @@ static int DoShellExec(char **argv)
|
||||
char *cmdLine = NULL;
|
||||
|
||||
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
ChildExec(argv[1], argv + 1, FALSE);
|
||||
ChildExec(argv[1], argv + 1);
|
||||
}
|
||||
for (i = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]);
|
||||
@@ -123,22 +125,11 @@ static int DoShellExec(char **argv)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ShellSigChildHook(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = SH_NOK;
|
||||
ShellCB *shellCB = NULL;
|
||||
|
||||
(void)signal(SIGCHLD, ShellSigChildHook);
|
||||
|
||||
if (argc > 1) {
|
||||
ret = DoShellExec(argv + 1);
|
||||
return ret;
|
||||
@@ -174,12 +165,7 @@ int main(int argc, char **argv)
|
||||
sem_init(&shellCB->shellSem, 0, 0);
|
||||
|
||||
g_shellCB = shellCB;
|
||||
ret = OsShellCreateTask(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT3;
|
||||
}
|
||||
|
||||
ShellEntry(shellCB);
|
||||
return OsShellCreateTask(shellCB);
|
||||
|
||||
ERR_OUT3:
|
||||
(void)pthread_mutex_destroy(&shellCB->historyMutex);
|
||||
|
||||
@@ -351,7 +351,7 @@ char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
return cmdName;
|
||||
}
|
||||
|
||||
void ChildExec(const char *cmdName, char *const paramArray[], bool foreground)
|
||||
void ChildExec(const char *cmdName, char *const paramArray[])
|
||||
{
|
||||
int ret;
|
||||
pid_t gid;
|
||||
@@ -367,12 +367,10 @@ void ChildExec(const char *cmdName, char *const paramArray[], bool foreground)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!foreground) {
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = execve(cmdName, paramArray, NULL);
|
||||
@@ -406,30 +404,20 @@ int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, CmdParsed *cmdParsed)
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
|
||||
{
|
||||
bool foreground = FALSE;
|
||||
int ret;
|
||||
pid_t forkPid;
|
||||
|
||||
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
|
||||
if ((cmdParsed->paramCnt > 1) && (strcmp(cmdParsed->paramArray[cmdParsed->paramCnt - 1], "&") == 0)) {
|
||||
free(cmdParsed->paramArray[cmdParsed->paramCnt - 1]);
|
||||
cmdParsed->paramArray[cmdParsed->paramCnt - 1] = NULL;
|
||||
cmdParsed->paramCnt--;
|
||||
foreground = TRUE;
|
||||
}
|
||||
|
||||
forkPid = fork();
|
||||
if (forkPid < 0) {
|
||||
printf("Failed to fork from shell\n");
|
||||
printf("Faild to fork from shell\n");
|
||||
return;
|
||||
} else if (forkPid == 0) {
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray, foreground);
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
|
||||
} else {
|
||||
if (!foreground) {
|
||||
(void)waitpid(forkPid, 0, 0);
|
||||
}
|
||||
waitpid(forkPid, 0, 0);
|
||||
ret = tcsetpgrp(STDIN_FILENO, getpid());
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
@@ -579,10 +567,20 @@ static void ExecCmdline(const char *cmdline)
|
||||
free(output);
|
||||
}
|
||||
|
||||
void RecycleZombieChild(void)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
static void ShellCmdProcess(ShellCB *shellCB)
|
||||
{
|
||||
char *buf = NULL;
|
||||
while (1) {
|
||||
char *buf = GetCmdline(shellCB);
|
||||
/* recycle zombine child process */
|
||||
RecycleZombieChild();
|
||||
buf = GetCmdline(shellCB);
|
||||
if (buf == NULL) {
|
||||
break;
|
||||
}
|
||||
@@ -656,19 +654,25 @@ static int ShellKernelReg(unsigned int shellHandle)
|
||||
return ioctl(STDIN_FILENO, CONSOLE_CONTROL_REG_USERTASK, shellHandle);
|
||||
}
|
||||
|
||||
void ShellEntry(ShellCB *shellCB)
|
||||
void *ShellEntry(void *argv)
|
||||
{
|
||||
char ch;
|
||||
int ret;
|
||||
int n;
|
||||
pid_t tid = syscall(__NR_gettid);
|
||||
ShellCB *shellCB = (ShellCB *)argv;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
|
||||
ret = prctl(PR_SET_NAME, "ShellEntry");
|
||||
if (ret != SH_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = ShellKernelReg((int)tid);
|
||||
if (ret != 0) {
|
||||
printf("another shell is already running!\n");
|
||||
@@ -681,5 +685,32 @@ void ShellEntry(ShellCB *shellCB)
|
||||
ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);
|
||||
}
|
||||
}
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ShellEntryInit(ShellCB *shellCB)
|
||||
{
|
||||
int ret;
|
||||
size_t stackSize = SHELL_ENTRY_STACKSIZE;
|
||||
void *arg = NULL;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
pthread_attr_setstacksize(&attr, stackSize);
|
||||
arg = (void *)shellCB;
|
||||
ret = pthread_create(&shellCB->shellEntryHandle, &attr, &ShellEntry, arg);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -500,7 +500,7 @@ static void lwip_tftp_send_error(s32_t iSockNum, u32_t ulError, const char *szEr
|
||||
}
|
||||
}
|
||||
|
||||
/* INTERFACE to get a file using filename
|
||||
/* INTEFACE to get a file using filename
|
||||
ulHostAddr - IP address of Host
|
||||
szSrcFileName - Source file
|
||||
szDestDirPath - Destination file path
|
||||
@@ -1419,7 +1419,7 @@ err_handler:
|
||||
}
|
||||
|
||||
#ifdef TFTP_TO_RAWMEM
|
||||
/* INTERFACE to get a file using filename
|
||||
/* INTEFACE to get a file using filename
|
||||
ulHostAddr - IP address of Host
|
||||
szSrcFileName - Source file
|
||||
szDestMemAddr - The target memory address in the client
|
||||
@@ -1437,8 +1437,10 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
|
||||
{
|
||||
s32_t iSockNum = TFTP_NULL_INT32;
|
||||
u32_t ulSrcStrLen;
|
||||
u32_t lDestStrLen;
|
||||
u32_t ulSize;
|
||||
u32_t ulRecvSize = TFTP_NULL_UINT32;
|
||||
s32_t iErrCode;
|
||||
u32_t ulErrCode;
|
||||
u16_t usReadReq;
|
||||
u16_t usTempServPort;
|
||||
|
||||
@@ -51,7 +51,7 @@ build_ext_component("build_toybox") {
|
||||
":copy_toybox_config",
|
||||
":copy_toybox_src",
|
||||
]
|
||||
deps += [ "//third_party/musl:sysroot_lite" ]
|
||||
deps += [ "//prebuilts/lite/sysroot" ]
|
||||
exec_path = rebase_path("$target_out_dir/toybox_build")
|
||||
|
||||
cflags = [
|
||||
|
||||
@@ -70,7 +70,7 @@ static void TraceRead(int fd, size_t size)
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t len;
|
||||
if (size == 0) {
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ extern "C" {
|
||||
#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL)
|
||||
#endif
|
||||
extern VOID OsHwiInit(VOID);
|
||||
extern VOID OsIncHwiFormCnt(UINT16 cpuid, UINT32 index);
|
||||
extern UINT32 OsGetHwiFormCnt(UINT16 cpuid, UINT32 index);
|
||||
extern VOID OsIncHwiFormCnt(UINT32 index);
|
||||
extern UINT32 OsGetHwiFormCnt(UINT32 index);
|
||||
extern CHAR *OsGetHwiFormName(UINT32 index);
|
||||
extern VOID OsInterrupt(UINT32 intNum);
|
||||
extern VOID OsSyscallHandleInit(VOID);
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
|
||||
STATIC UINTPTR g_minAddr;
|
||||
STATIC UINTPTR g_maxAddr;
|
||||
STATIC UINT32 g_currHandleExcCpuid = INVALID_CPUID;
|
||||
STATIC UINT32 g_currHandleExcCpuID = INVALID_CPUID;
|
||||
VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr);
|
||||
UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 };
|
||||
BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM];
|
||||
@@ -88,7 +88,6 @@ STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
|
||||
#define OS_MAX_BACKTRACE 15U
|
||||
#define DUMPSIZE 128U
|
||||
#define DUMPREGS 12U
|
||||
#define COM_REGS 4U
|
||||
#define INSTR_SET_MASK 0x01000020U
|
||||
#define THUMB_INSTR_LEN 2U
|
||||
#define ARM_INSTR_LEN 4U
|
||||
@@ -113,11 +112,11 @@ STATIC const StackInfo g_excStack[] = {
|
||||
UINT32 OsGetSystemStatus(VOID)
|
||||
{
|
||||
UINT32 flag;
|
||||
UINT32 cpuid = g_currHandleExcCpuid;
|
||||
UINT32 cpuID = g_currHandleExcCpuID;
|
||||
|
||||
if (cpuid == INVALID_CPUID) {
|
||||
if (cpuID == INVALID_CPUID) {
|
||||
flag = OS_SYSTEM_NORMAL;
|
||||
} else if (cpuid == ArchCurrCpuid()) {
|
||||
} else if (cpuID == ArchCurrCpuid()) {
|
||||
flag = OS_SYSTEM_EXC_CURR_CPU;
|
||||
} else {
|
||||
flag = OS_SYSTEM_EXC_OTHER_CPU;
|
||||
@@ -517,22 +516,13 @@ VOID OsDumpContextMem(const ExcContext *excBufAddr)
|
||||
return;
|
||||
}
|
||||
|
||||
for (excReg = &(excBufAddr->R0); count < COM_REGS; excReg++, count++) {
|
||||
for (excReg = &(excBufAddr->R0); count <= DUMPREGS; excReg++, count++) {
|
||||
if (IS_VALID_ADDR(*excReg)) {
|
||||
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
|
||||
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
|
||||
}
|
||||
}
|
||||
for (excReg = &(excBufAddr->R4); count < DUMPREGS; excReg++, count++) {
|
||||
if (IS_VALID_ADDR(*excReg)) {
|
||||
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
|
||||
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
|
||||
}
|
||||
}
|
||||
if (IS_VALID_ADDR(excBufAddr->R12)) {
|
||||
PrintExcInfo("\ndump mem around R12:%p", excBufAddr->R12);
|
||||
OsDumpMemByte(DUMPSIZE, (excBufAddr->R12 - (DUMPSIZE >> 1)));
|
||||
}
|
||||
|
||||
if (IS_VALID_ADDR(excBufAddr->SP)) {
|
||||
PrintExcInfo("\ndump mem around SP:%p", excBufAddr->SP);
|
||||
OsDumpMemByte(DUMPSIZE, (excBufAddr->SP - (DUMPSIZE >> 1)));
|
||||
@@ -541,11 +531,11 @@ VOID OsDumpContextMem(const ExcContext *excBufAddr)
|
||||
|
||||
STATIC VOID OsExcRestore(VOID)
|
||||
{
|
||||
UINT32 currCpuid = ArchCurrCpuid();
|
||||
UINT32 currCpuID = ArchCurrCpuid();
|
||||
|
||||
g_excFromUserMode[currCpuid] = FALSE;
|
||||
g_intCount[currCpuid] = 0;
|
||||
g_curNestCount[currCpuid] = 0;
|
||||
g_excFromUserMode[currCpuID] = FALSE;
|
||||
g_intCount[currCpuID] = 0;
|
||||
g_curNestCount[currCpuID] = 0;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsCpuStatusSet(CPU_RUNNING);
|
||||
#endif
|
||||
@@ -566,15 +556,15 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_SpinLock(&g_excSerializerSpin);
|
||||
if (g_nextExcWaitCpu != INVALID_CPUID) {
|
||||
g_currHandleExcCpuid = g_nextExcWaitCpu;
|
||||
g_currHandleExcCpuID = g_nextExcWaitCpu;
|
||||
g_nextExcWaitCpu = INVALID_CPUID;
|
||||
} else {
|
||||
g_currHandleExcCpuid = INVALID_CPUID;
|
||||
g_currHandleExcCpuID = INVALID_CPUID;
|
||||
}
|
||||
g_currHandleExcPID = OS_INVALID_VALUE;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
#else
|
||||
g_currHandleExcCpuid = INVALID_CPUID;
|
||||
g_currHandleExcCpuID = INVALID_CPUID;
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
@@ -655,7 +645,6 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
|
||||
const StackInfo *stack = NULL;
|
||||
vaddr_t kvaddr;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
|
||||
taskCB = OsCurrTaskGet();
|
||||
stackStart = taskCB->userMapBase;
|
||||
@@ -666,7 +655,6 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
|
||||
}
|
||||
return found;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Search in the task stacks */
|
||||
for (index = 0; index < g_taskMaxNum; index++) {
|
||||
@@ -991,14 +979,14 @@ VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr)
|
||||
#define EXC_WAIT_INTER 50U
|
||||
#define EXC_WAIT_TIME 2000U
|
||||
|
||||
STATIC VOID WaitAllCpuStop(UINT32 cpuid)
|
||||
STATIC VOID WaitAllCpuStop(UINT32 cpuID)
|
||||
{
|
||||
UINT32 i;
|
||||
UINT32 time = 0;
|
||||
|
||||
while (time < EXC_WAIT_TIME) {
|
||||
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
|
||||
if ((i != cpuid) && !OsCpuStatusIsHalt(i)) {
|
||||
if ((i != cpuID) && !OsCpuStatusIsHalt(i)) {
|
||||
LOS_Mdelay(EXC_WAIT_INTER);
|
||||
time += EXC_WAIT_INTER;
|
||||
break;
|
||||
@@ -1012,19 +1000,19 @@ STATIC VOID WaitAllCpuStop(UINT32 cpuid)
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuid)
|
||||
STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuID)
|
||||
{
|
||||
while (1) {
|
||||
LOS_SpinLock(&g_excSerializerSpin);
|
||||
if ((g_currHandleExcCpuid == INVALID_CPUID) || (g_currHandleExcCpuid == currCpuid)) {
|
||||
g_currHandleExcCpuid = currCpuid;
|
||||
if ((g_currHandleExcCpuID == INVALID_CPUID) || (g_currHandleExcCpuID == currCpuID)) {
|
||||
g_currHandleExcCpuID = currCpuID;
|
||||
g_currHandleExcPID = OsCurrProcessGet()->processID;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_nextExcWaitCpu == INVALID_CPUID) {
|
||||
g_nextExcWaitCpu = currCpuid;
|
||||
g_nextExcWaitCpu = currCpuID;
|
||||
}
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
LOS_Mdelay(EXC_WAIT_INTER);
|
||||
@@ -1033,7 +1021,7 @@ STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuid)
|
||||
|
||||
STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
{
|
||||
UINT32 currCpuid = ArchCurrCpuid();
|
||||
UINT32 currCpuID = ArchCurrCpuid();
|
||||
UINT32 ret, target;
|
||||
|
||||
OsCpuStatusSet(CPU_EXC);
|
||||
@@ -1041,17 +1029,17 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
|
||||
LOS_SpinLock(&g_excSerializerSpin);
|
||||
/* Only the current CPU anomaly */
|
||||
if (g_currHandleExcCpuid == INVALID_CPUID) {
|
||||
g_currHandleExcCpuid = currCpuid;
|
||||
if (g_currHandleExcCpuID == INVALID_CPUID) {
|
||||
g_currHandleExcCpuID = currCpuID;
|
||||
g_currHandleExcPID = OsCurrProcessGet()->processID;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
#ifndef LOSCFG_SAVE_EXCINFO
|
||||
if (g_excFromUserMode[currCpuid] == FALSE) {
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuid));
|
||||
if (g_excFromUserMode[currCpuID] == FALSE) {
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
|
||||
HalIrqSendIpi(target, LOS_MP_IPI_HALT);
|
||||
}
|
||||
#endif
|
||||
} else if (g_excFromUserMode[currCpuid] == TRUE) {
|
||||
} else if (g_excFromUserMode[currCpuID] == TRUE) {
|
||||
/* Both cores raise exceptions, and the current core is a user-mode exception.
|
||||
* Both cores are abnormal and come from the same process
|
||||
*/
|
||||
@@ -1063,12 +1051,12 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
}
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
|
||||
OsWaitOtherCoresHandleExcEnd(currCpuid);
|
||||
OsWaitOtherCoresHandleExcEnd(currCpuID);
|
||||
} else {
|
||||
if ((g_currHandleExcCpuid < LOSCFG_KERNEL_CORE_NUM) && (g_excFromUserMode[g_currHandleExcCpuid] == TRUE)) {
|
||||
g_currHandleExcCpuid = currCpuid;
|
||||
if ((g_currHandleExcCpuID < LOSCFG_KERNEL_CORE_NUM) && (g_excFromUserMode[g_currHandleExcCpuID] == TRUE)) {
|
||||
g_currHandleExcCpuID = currCpuID;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuid));
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
|
||||
HalIrqSendIpi(target, LOS_MP_IPI_HALT);
|
||||
} else {
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
@@ -1078,7 +1066,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
#ifndef LOSCFG_SAVE_EXCINFO
|
||||
/* use halt ipi to stop other active cores */
|
||||
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
|
||||
WaitAllCpuStop(currCpuid);
|
||||
WaitAllCpuStop(currCpuID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1089,7 +1077,7 @@ STATIC VOID OsCheckCpuStatus(VOID)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsCheckAllCpuStatus();
|
||||
#else
|
||||
g_currHandleExcCpuid = ArchCurrCpuid();
|
||||
g_currHandleExcCpuID = ArchCurrCpuid();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,16 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin);
|
||||
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[LOSCFG_KERNEL_CORE_NUM][OS_HWI_MAX_NUM] = {0};
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT16 cpuid, UINT32 index)
|
||||
VOID OsIncHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[cpuid][index];
|
||||
g_hwiFormCnt[index]++;
|
||||
}
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
@@ -69,17 +74,16 @@ VOID OsInterrupt(UINT32 intNum)
|
||||
{
|
||||
HwiHandleForm *hwiForm = NULL;
|
||||
UINT32 *intCnt = NULL;
|
||||
UINT16 cpuid = ArchCurrCpuid();
|
||||
|
||||
/* Must keep the operation at the beginning of the interface */
|
||||
intCnt = &g_intCount[cpuid];
|
||||
intCnt = &g_intCount[ArchCurrCpuid()];
|
||||
*intCnt = *intCnt + 1;
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqStart(cpuid);
|
||||
#endif
|
||||
|
||||
OsSchedIrqStartTime();
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqStart();
|
||||
#endif
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, intNum);
|
||||
hwiForm = (&g_hwiForm[intNum]);
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
@@ -101,14 +105,14 @@ VOID OsInterrupt(UINT32 intNum)
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
}
|
||||
#endif
|
||||
++g_hwiFormCnt[cpuid][intNum];
|
||||
++g_hwiFormCnt[intNum];
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, intNum);
|
||||
OsSchedIrqUsedTimeUpdate();
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqEnd(cpuid, intNum);
|
||||
OsCpupIrqEnd(intNum);
|
||||
#endif
|
||||
OsSchedIrqUpdateUsedTime();
|
||||
|
||||
/* Must keep the operation at the end of the interface */
|
||||
*intCnt = *intCnt - 1;
|
||||
}
|
||||
|
||||
@@ -121,9 +121,8 @@ reset_vector:
|
||||
mcr p15, 0, r0, c13, c0, 4
|
||||
/* do some early cpu setup: i/d cache disable, mmu disabled */
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
bic r0, #(1 << 12) /* i cache */
|
||||
bic r0, #(1 << 2) /* d cache */
|
||||
bic r0, #(1 << 0) /* mmu */
|
||||
bic r0, #(1<<12)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* enable fpu+neon */
|
||||
@@ -276,18 +275,18 @@ mmu_setup:
|
||||
mov r12, #0x7 /* 0b0111 */
|
||||
mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */
|
||||
isb
|
||||
mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxiliary Control Register */
|
||||
mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
|
||||
orr r12, r12, #(1 << 6) /* SMP, Enables coherent requests to the processor. */
|
||||
orr r12, r12, #(1 << 2) /* Enable D-side prefetch */
|
||||
orr r12, r12, #(1 << 11) /* Global BP Enable bit */
|
||||
mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxiliary Control Register */
|
||||
mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
|
||||
dsb
|
||||
mrc p15, 0, r12, c1, c0, 0
|
||||
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */
|
||||
orr r12, #(1 << 0) /* mmu enable */
|
||||
bic r12, #(1 << 29 | 1 << 28)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2) /* D cache enable */
|
||||
orr r12, #(1 << 12) /* I cache enable */
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
|
||||
isb
|
||||
ldr pc, =1f /* Convert to VA */
|
||||
|
||||
@@ -101,9 +101,8 @@ __exception_handlers:
|
||||
reset_vector:
|
||||
/* do some early cpu setup: i/d cache disable, mmu disabled */
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
bic r0, #(1 << 12) /* i cache */
|
||||
bic r0, #(1 << 2) /* d cache */
|
||||
bic r0, #(1 << 0) /* mmu */
|
||||
bic r0, #(1<<12)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* enable fpu+neon */
|
||||
@@ -270,11 +269,11 @@ mmu_setup:
|
||||
isb
|
||||
|
||||
mrc p15, 0, r12, c1, c0, 0
|
||||
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */
|
||||
orr r12, #(1 << 0) /* mmu enable */
|
||||
bic r12, #(1 << 29 | 1 << 28)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2) /* D cache enable */
|
||||
orr r12, #(1 << 12) /* I cache enable */
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
|
||||
isb
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
|
||||
}
|
||||
|
||||
maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
|
||||
count : (INT32)(USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
count : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
|
||||
for (i = 0; i < maxCount; ++i) {
|
||||
if (LOS_GetUser(&character, src + offset) != LOS_OK) {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/hdf_core/adapter/khdf/liteos/lite.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
MODULE_NAME := usb_base
|
||||
|
||||
@@ -122,13 +122,13 @@ LOCAL_SRCS += $(STORAGE_SRC)/umass.c
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_USB_HID_CLASS)_$(LOSCFG_DRIVERS_HDF_INPUT), y_y)
|
||||
LOCAL_FLAGS += -I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/model/input/driver \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/include/core \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/core/common/include/host \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/utils \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/osal \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/ability/sbuf/include \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/hdf_core/framework/include/osal \
|
||||
LOCAL_FLAGS += -I$(LITEOSTOPDIR)/../../drivers/framework/model/input/driver \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/include/core \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/core/common/include/host \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/utils \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/osal \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/ability/sbuf/include \
|
||||
-I$(LITEOSTOPDIR)/../../drivers/framework/include/osal \
|
||||
-I$(LITEOSTOPDIR)/../../third_party/FreeBSD/sys/dev/evdev
|
||||
|
||||
LOCAL_SRCS += $(INPUT_SRC)/uhid.c \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -158,7 +158,7 @@ STATIC VOID SetPthreadAttr(const _pthread_data *self, const pthread_attr_t *attr
|
||||
}
|
||||
if (outAttr->inheritsched == PTHREAD_INHERIT_SCHED) {
|
||||
if (self->task == NULL) {
|
||||
outAttr->schedparam.sched_priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
|
||||
outAttr->schedparam.sched_priority = ((LosTaskCB *)(OsCurrTaskGet()))->priority;
|
||||
} else {
|
||||
outAttr->schedpolicy = self->attr.schedpolicy;
|
||||
outAttr->schedparam = self->attr.schedparam;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
#ifdef LOSCFG_AARCH64
|
||||
/*
|
||||
* This two structures originally didn't exit,
|
||||
* This two structures originally did't exit,
|
||||
* they added by liteos to support 64bit interfaces on 32bit platform,
|
||||
* in 64bit platform, timeval64 define to timeval which is platform adaptive.
|
||||
*/
|
||||
@@ -387,16 +387,9 @@ int gettimeofday64(struct timeval64 *tv, struct timezone *tz)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB
|
||||
int gettimeofday(struct timeval *tv, void *_tz)
|
||||
#else
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
#endif
|
||||
{
|
||||
struct timeval64 stTimeVal64 = {0};
|
||||
#ifdef LOSCFG_LIBC_NEWLIB
|
||||
struct timezone *tz = (struct timezone *)_tz;
|
||||
#endif
|
||||
|
||||
if (tv == NULL) {
|
||||
TIME_RETURN(EINVAL);
|
||||
@@ -478,6 +471,7 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
|
||||
uint64_t runtime;
|
||||
UINT32 intSave;
|
||||
UINT32 tid = GetTidFromClockID(clockID);
|
||||
|
||||
if (OS_TID_CHECK_INVALID(tid)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -724,7 +718,6 @@ typedef struct {
|
||||
|
||||
static VOID SwtmrProc(UINTPTR tmrArg)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
INT32 sig, ret;
|
||||
UINT32 intSave;
|
||||
pid_t pid;
|
||||
@@ -768,47 +761,9 @@ static VOID SwtmrProc(UINTPTR tmrArg)
|
||||
return;
|
||||
EXIT:
|
||||
PRINT_ERR("Dispatch signals failed!, ret: %d\r\n", ret);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
int timer_create(clockid_t clockID, struct sigevent *restrict evp, timer_t *restrict timerID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT16 swtmrID;
|
||||
#ifdef LOSCFG_SECURITY_VID
|
||||
UINT16 vid;
|
||||
#endif
|
||||
|
||||
if (!timerID || (clockID != CLOCK_REALTIME) || !evp) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((evp->sigev_notify != SIGEV_THREAD) || evp->sigev_notify_attributes) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, (SWTMR_PROC_FUNC)evp->sigev_notify_function,
|
||||
&swtmrID, (UINTPTR)evp->sigev_value.sival_ptr);
|
||||
if (ret != LOS_OK) {
|
||||
errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_VID
|
||||
vid = AddNodeByRid(swtmrID);
|
||||
if (vid == MAX_INVALID_TIMER_VID) {
|
||||
(VOID)LOS_SwtmrDelete(swtmrID);
|
||||
return -1;
|
||||
}
|
||||
swtmrID = vid;
|
||||
#endif
|
||||
*timerID = (timer_t)(UINTPTR)swtmrID;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int OsTimerCreate(clockid_t clockID, struct ksigevent *evp, timer_t *timerID)
|
||||
{
|
||||
UINT32 ret;
|
||||
@@ -868,7 +823,6 @@ int timer_delete(timer_t timerID)
|
||||
{
|
||||
UINT16 swtmrID = (UINT16)(UINTPTR)timerID;
|
||||
VOID *arg = NULL;
|
||||
UINTPTR swtmrProc;
|
||||
|
||||
#ifdef LOSCFG_SECURITY_VID
|
||||
swtmrID = GetRidByVid(swtmrID);
|
||||
@@ -878,11 +832,10 @@ int timer_delete(timer_t timerID)
|
||||
}
|
||||
|
||||
arg = (VOID *)OS_SWT_FROM_SID(swtmrID)->uwArg;
|
||||
swtmrProc = (UINTPTR)OS_SWT_FROM_SID(swtmrID)->pfnHandler;
|
||||
if (LOS_SwtmrDelete(swtmrID)) {
|
||||
goto ERROUT;
|
||||
}
|
||||
if ((swtmrProc == (UINTPTR)SwtmrProc) && (arg != NULL)) {
|
||||
if (arg != NULL) {
|
||||
free(arg);
|
||||
}
|
||||
|
||||
@@ -1026,11 +979,7 @@ STATIC INT32 DoNanoSleep(UINT64 nanoseconds)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_LIBC_NEWLIB
|
||||
int usleep(unsigned long useconds)
|
||||
#else
|
||||
int usleep(unsigned useconds)
|
||||
#endif
|
||||
{
|
||||
return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ config DRIVERS
|
||||
Answer Y to enable LiteOS support driver.
|
||||
|
||||
source "bsd/dev/usb/Kconfig"
|
||||
source "../../drivers/hdf_core/adapter/khdf/liteos/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/Kconfig"
|
||||
|
||||
# Device driver Kconfig import
|
||||
source "$(DEVICE_PATH)/drivers/Kconfig"
|
||||
@@ -17,4 +17,5 @@ source "drivers/char/video/Kconfig"
|
||||
source "drivers/char/trace/Kconfig"
|
||||
source "drivers/char/perf/Kconfig"
|
||||
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "../../drivers/liteos/hievent/Kconfig"
|
||||
|
||||
@@ -163,7 +163,7 @@ extern "C" {
|
||||
#define DISK_ATA_GET_MODEL 21 /* Get model name */
|
||||
#define DISK_ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_CACHE
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
#define DISK_DIRECT_BUFFER_SIZE 4 /* los_disk direct io buffer when bcache is off */
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
extern "C"{
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ kernel_module(module_name) {
|
||||
|
||||
include_dirs = [ "$LITEOSTOPDIR/fs/jffs2/include" ]
|
||||
|
||||
if (defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)) {
|
||||
include_dirs += [ "//device/qemu/drivers/cfiflash" ]
|
||||
}
|
||||
|
||||
public_configs = [ ":public" ]
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ LOCAL_SRCS := $(wildcard src/*.c)
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/fs/jffs2/include
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
#include "fs/driver.h"
|
||||
#include "mtd/mtd_legacy_lite.h"
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
#include "cfiflash.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define DRIVER_NAME_ADD_SIZE 3
|
||||
pthread_mutex_t g_mtdPartitionLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -129,10 +134,17 @@ static VOID MtdNorParamAssign(partition_param *spinorParam, const struct MtdDev
|
||||
* you can change the SPIBLK_NAME or SPICHR_NAME to NULL.
|
||||
*/
|
||||
spinorParam->flash_mtd = (struct MtdDev *)spinorMtd;
|
||||
#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
spinorParam->flash_ops = GetDevSpinorOps();
|
||||
spinorParam->char_ops = GetMtdCharFops();
|
||||
spinorParam->blockname = SPIBLK_NAME;
|
||||
spinorParam->charname = SPICHR_NAME;
|
||||
#else
|
||||
spinorParam->flash_ops = GetCfiBlkOps();
|
||||
spinorParam->char_ops = NULL;
|
||||
spinorParam->blockname = CFI_DRIVER;
|
||||
spinorParam->charname = NULL;
|
||||
#endif
|
||||
spinorParam->partition_head = g_spinorPartitionHead;
|
||||
spinorParam->block_size = spinorMtd->eraseSize;
|
||||
}
|
||||
@@ -146,7 +158,11 @@ static VOID MtdDeinitSpinorParam(VOID)
|
||||
|
||||
static partition_param *MtdInitSpinorParam(partition_param *spinorParam)
|
||||
{
|
||||
#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
struct MtdDev *spinorMtd = GetMtd("spinor");
|
||||
#else
|
||||
struct MtdDev *spinorMtd = GetCfiMtdDev();
|
||||
#endif
|
||||
if (spinorMtd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -343,8 +343,7 @@ static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, co
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp,
|
||||
BYTE type, const char *target)
|
||||
static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp, BYTE type, const char *target)
|
||||
{
|
||||
struct Vnode *vp = NULL;
|
||||
FATFS *fs = (FATFS *)parent->originMount->data;
|
||||
@@ -1409,7 +1408,7 @@ DWORD fattime_format(time_t time)
|
||||
ftime |= ((DWORD)((st.tm_year > YEAR_OFFSET) ? (st.tm_year - YEAR_OFFSET) : 0)) << FTIME_YEAR_OFFSET;
|
||||
ftime <<= FTIME_DATE_OFFSET;
|
||||
|
||||
ftime |= (DWORD)st.tm_sec / SEC_MULTIPLIER;
|
||||
ftime = (DWORD)st.tm_sec / SEC_MULTIPLIER;
|
||||
ftime |= ((DWORD)st.tm_min) << FTIME_MIN_OFFSET;
|
||||
ftime |= ((DWORD)st.tm_hour) << FTIME_HR_OFFSET;
|
||||
|
||||
@@ -2167,7 +2166,7 @@ int fatfs_symlink(struct Vnode *parentVnode, struct Vnode **newVnode, const char
|
||||
ssize_t fatfs_readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
{
|
||||
int ret;
|
||||
FRESULT res;
|
||||
FRESULT res = FR_OK;
|
||||
DWORD clust;
|
||||
QWORD sect;
|
||||
DIR_FILE *dfp = (DIR_FILE *)(vnode->data);
|
||||
|
||||
@@ -64,7 +64,7 @@ extern "C" {
|
||||
#define MBR_PRIMARY_PART_NUM 4
|
||||
#define JUMP_CODE "\xEB\xFE\x90"
|
||||
|
||||
/* Partition type */
|
||||
/* Partiton type */
|
||||
#define FAT12 0x01 /* FAT12 as primary partition in first physical 32MB */
|
||||
#define FAT16 0x04 /* FAT16 with less than 65536 sectors(32MB) */
|
||||
#define EXTENDED_PARTITION_CHS 0x05
|
||||
|
||||
@@ -179,7 +179,7 @@ static INT FatfsDisablePart(void *handle)
|
||||
* Scan the FAT inside the boundary of CHILD FATFS limit, and update the free cluster and last cluster
|
||||
* for all CHILD FATFS.
|
||||
* Acceptable Return Value:
|
||||
* - FR_OK : Successfully scanned the FAT and update field.
|
||||
* - FR_OK : Successfully scaned the FAT and update field.
|
||||
* Others Return Value:
|
||||
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
|
||||
* - FR_DENIED : The virtual partition feature has been shut down by switcher
|
||||
|
||||
@@ -373,7 +373,7 @@ static FRESULT FatfsCheckScanFatParam(FATFS *fs)
|
||||
* Scan the FAT inside the boundary of CHILD FATFS limit, and update the free cluster and last cluster
|
||||
*
|
||||
* Acceptable Return Value:
|
||||
* - FR_OK : Successfully scanned the FAT and update field.
|
||||
* - FR_OK : Successfully scaned the FAT and update field.
|
||||
*
|
||||
* Others Return Value:
|
||||
* - FR_INVAILD_FATFS : The FATFS object has error or the info in it has been occuried
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -244,9 +244,8 @@ extern int chattr(const char *pathname, struct IATTR *attr);
|
||||
*
|
||||
* @retval #0 On success.
|
||||
* @retval #-1 On failure with errno set.
|
||||
* @retval CONTINE_NUTTX_FCNTL doesn't support some cmds in VfsFcntl, needs to continue going through
|
||||
* Nuttx vfs operation.</li>
|
||||
*
|
||||
* @retval CONTINE_NUTTX_FCNTL doesn't support some cmds in VfsFcntl, needs to continue going through Nuttx vfs operation.</li>
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>fs.h</li></ul>
|
||||
* @see None
|
||||
|
||||
@@ -49,7 +49,7 @@ struct Mount {
|
||||
LIST_HEAD vnodeList; /* list of vnodes */
|
||||
int vnodeSize; /* size of vnode list */
|
||||
LIST_HEAD activeVnodeList; /* list of active vnodes */
|
||||
int activeVnodeSize; /* size of active vnodes list */
|
||||
int activeVnodeSize; /* szie of active vnodes list */
|
||||
void *data; /* private data */
|
||||
uint32_t hashseed; /* Random seed for vfshash */
|
||||
unsigned long mountFlags; /* Flags for mount */
|
||||
|
||||
@@ -2311,7 +2311,7 @@ diff -Nupr old/fs/jffs2/erase.c new/fs/jffs2/erase.c
|
||||
diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
--- old/fs/jffs2/file.c 2022-05-09 17:22:53.000000000 +0800
|
||||
+++ new/fs/jffs2/file.c 2022-05-10 09:43:14.250000000 +0800
|
||||
@@ -9,335 +9,30 @@
|
||||
@@ -9,325 +9,34 @@
|
||||
* For licensing information, see the file 'LICENCE' in this directory.
|
||||
*
|
||||
*/
|
||||
@@ -2336,35 +2336,32 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- loff_t pos, unsigned len, unsigned flags,
|
||||
- struct page **pagep, void **fsdata);
|
||||
-static int jffs2_readpage (struct file *filp, struct page *pg);
|
||||
-
|
||||
-int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
||||
-{
|
||||
- struct inode *inode = filp->f_mapping->host;
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
- int ret;
|
||||
-
|
||||
- ret = file_write_and_wait_range(filp, start, end);
|
||||
- if (ret)
|
||||
- return ret;
|
||||
|
||||
- inode_lock(inode);
|
||||
- /* Trigger GC to flush any pending writes for this inode */
|
||||
- jffs2_flush_wbuf_gc(c, inode->i_ino);
|
||||
- inode_unlock(inode);
|
||||
+static unsigned char gc_buffer[PAGE_SIZE]; //avoids malloc when user may be under memory pressure
|
||||
|
||||
-int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
|
||||
- return 0;
|
||||
-}
|
||||
|
||||
-const struct file_operations jffs2_file_operations =
|
||||
+unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
|
||||
+ struct jffs2_inode_info *f,
|
||||
+ unsigned long offset,
|
||||
+ unsigned long *priv)
|
||||
{
|
||||
- struct inode *inode = filp->f_mapping->host;
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
+ /* FIXME: This works only with one file system mounted at a time */
|
||||
int ret;
|
||||
-
|
||||
- ret = file_write_and_wait_range(filp, start, end);
|
||||
+ ret = jffs2_read_inode_range(c, f, gc_buffer,
|
||||
+ offset & ~(PAGE_SIZE-1), PAGE_SIZE);
|
||||
if (ret)
|
||||
- return ret;
|
||||
-
|
||||
- inode_lock(inode);
|
||||
- /* Trigger GC to flush any pending writes for this inode */
|
||||
- jffs2_flush_wbuf_gc(c, inode->i_ino);
|
||||
- inode_unlock(inode);
|
||||
-
|
||||
- return 0;
|
||||
-}
|
||||
-
|
||||
-const struct file_operations jffs2_file_operations =
|
||||
-{
|
||||
- .llseek = generic_file_llseek,
|
||||
- .open = generic_file_open,
|
||||
- .read_iter = generic_file_read_iter,
|
||||
@@ -2398,8 +2395,9 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
- unsigned char *pg_buf;
|
||||
- int ret;
|
||||
-
|
||||
+ /* FIXME: This works only with one file system mounted at a time */
|
||||
int ret;
|
||||
|
||||
- jffs2_dbg(2, "%s(): ino #%lu, page at offset 0x%lx\n",
|
||||
- __func__, inode->i_ino, pg->index << PAGE_SHIFT);
|
||||
-
|
||||
@@ -2438,15 +2436,18 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
-{
|
||||
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
|
||||
- int ret;
|
||||
-
|
||||
+ ret = jffs2_read_inode_range(c, f, gc_buffer,
|
||||
+ offset & ~(PAGE_SIZE-1), PAGE_SIZE);
|
||||
+ if (ret)
|
||||
+ return ERR_PTR(ret);
|
||||
|
||||
- mutex_lock(&f->sem);
|
||||
- ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
|
||||
- mutex_unlock(&f->sem);
|
||||
- return ret;
|
||||
+ return ERR_PTR(ret);
|
||||
+ return gc_buffer;
|
||||
}
|
||||
|
||||
-
|
||||
-static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
|
||||
- loff_t pos, unsigned len, unsigned flags,
|
||||
- struct page **pagep, void **fsdata)
|
||||
@@ -2457,15 +2458,20 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- struct page *pg;
|
||||
- struct inode *inode = mapping->host;
|
||||
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
- pgoff_t index = pos >> PAGE_SHIFT;
|
||||
- uint32_t pageofs = index << PAGE_SHIFT;
|
||||
- int ret = 0;
|
||||
-
|
||||
- pg = grab_cache_page_write_begin(mapping, index, flags);
|
||||
- if (!pg)
|
||||
- return -ENOMEM;
|
||||
- *pagep = pg;
|
||||
-
|
||||
- jffs2_dbg(1, "%s()\n", __func__);
|
||||
-
|
||||
- if (pageofs > inode->i_size) {
|
||||
- /* Make new hole frag from old EOF to new page */
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
- struct jffs2_raw_inode ri;
|
||||
- struct jffs2_full_dnode *fn;
|
||||
- uint32_t alloc_len;
|
||||
@@ -2476,7 +2482,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
|
||||
- ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
|
||||
- if (ret)
|
||||
- goto out_err;
|
||||
- goto out_page;
|
||||
-
|
||||
- mutex_lock(&f->sem);
|
||||
- memset(&ri, 0, sizeof(ri));
|
||||
@@ -2506,7 +2512,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- ret = PTR_ERR(fn);
|
||||
- jffs2_complete_reservation(c);
|
||||
- mutex_unlock(&f->sem);
|
||||
- goto out_err;
|
||||
- goto out_page;
|
||||
- }
|
||||
- ret = jffs2_add_full_dnode_to_inode(c, f, fn);
|
||||
- if (f->metadata) {
|
||||
@@ -2521,7 +2527,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- jffs2_free_full_dnode(fn);
|
||||
- jffs2_complete_reservation(c);
|
||||
- mutex_unlock(&f->sem);
|
||||
- goto out_err;
|
||||
- goto out_page;
|
||||
- }
|
||||
- jffs2_complete_reservation(c);
|
||||
- inode->i_size = pageofs;
|
||||
@@ -2529,19 +2535,6 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- }
|
||||
-
|
||||
- /*
|
||||
- * While getting a page and reading data in, lock c->alloc_sem until
|
||||
- * the page is Uptodate. Otherwise GC task may attempt to read the same
|
||||
- * page in read_cache_page(), which causes a deadlock.
|
||||
- */
|
||||
- mutex_lock(&c->alloc_sem);
|
||||
- pg = grab_cache_page_write_begin(mapping, index, flags);
|
||||
- if (!pg) {
|
||||
- ret = -ENOMEM;
|
||||
- goto release_sem;
|
||||
- }
|
||||
- *pagep = pg;
|
||||
-
|
||||
- /*
|
||||
- * Read in the page if it wasn't already present. Cannot optimize away
|
||||
- * the whole page write case until jffs2_write_end can handle the
|
||||
- * case of a short-copy.
|
||||
@@ -2550,20 +2543,19 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- mutex_lock(&f->sem);
|
||||
- ret = jffs2_do_readpage_nolock(inode, pg);
|
||||
- mutex_unlock(&f->sem);
|
||||
- if (ret) {
|
||||
- unlock_page(pg);
|
||||
- put_page(pg);
|
||||
- goto release_sem;
|
||||
- }
|
||||
- if (ret)
|
||||
- goto out_page;
|
||||
- }
|
||||
- jffs2_dbg(1, "end write_begin(). pg->flags %lx\n", pg->flags);
|
||||
-
|
||||
-release_sem:
|
||||
- mutex_unlock(&c->alloc_sem);
|
||||
-out_err:
|
||||
- return ret;
|
||||
-}
|
||||
-
|
||||
-out_page:
|
||||
- unlock_page(pg);
|
||||
- put_page(pg);
|
||||
- return ret;
|
||||
+ /* Do nothing */
|
||||
}
|
||||
|
||||
-static int jffs2_write_end(struct file *filp, struct address_space *mapping,
|
||||
- loff_t pos, unsigned len, unsigned copied,
|
||||
- struct page *pg, void *fsdata)
|
||||
@@ -2661,8 +2653,7 @@ diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
|
||||
- unlock_page(pg);
|
||||
- put_page(pg);
|
||||
- return writtenlen > 0 ? writtenlen : ret;
|
||||
+ /* Do nothing */
|
||||
}
|
||||
-}
|
||||
diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
--- old/fs/jffs2/fs.c 2022-05-09 17:22:53.000000000 +0800
|
||||
+++ new/fs/jffs2/fs.c 2022-05-10 16:13:37.830000000 +0800
|
||||
@@ -2778,11 +2769,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
ri->version = cpu_to_je32(++f->highest_version);
|
||||
+ ri->uid = cpu_to_je16(inode->i_uid);
|
||||
+ ri->gid = cpu_to_je16(inode->i_gid);
|
||||
|
||||
- ri->uid = cpu_to_je16((ivalid & ATTR_UID)?
|
||||
- from_kuid(&init_user_ns, iattr->ia_uid):i_uid_read(inode));
|
||||
- ri->gid = cpu_to_je16((ivalid & ATTR_GID)?
|
||||
- from_kgid(&init_user_ns, iattr->ia_gid):i_gid_read(inode));
|
||||
+
|
||||
+ if (ivalid & CHG_UID) {
|
||||
+ if (((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) && (!IsCapPermit(CAP_CHOWN))) {
|
||||
+ jffs2_complete_reservation(c);
|
||||
@@ -2804,7 +2791,16 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
+ ri->gid = cpu_to_je16(attr->attr_chg_gid);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
|
||||
- ri->uid = cpu_to_je16((ivalid & ATTR_UID)?
|
||||
- from_kuid(&init_user_ns, iattr->ia_uid):i_uid_read(inode));
|
||||
- ri->gid = cpu_to_je16((ivalid & ATTR_GID)?
|
||||
- from_kgid(&init_user_ns, iattr->ia_gid):i_gid_read(inode));
|
||||
-
|
||||
- if (ivalid & ATTR_MODE)
|
||||
- ri->mode = cpu_to_jemode(iattr->ia_mode);
|
||||
- else
|
||||
- ri->mode = cpu_to_jemode(inode->i_mode);
|
||||
+ if (ivalid & CHG_MODE) {
|
||||
+ if (!IsCapPermit(CAP_FOWNER) && (c_uid != inode->i_uid)) {
|
||||
+ jffs2_complete_reservation(c);
|
||||
@@ -2818,10 +2814,6 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- if (ivalid & ATTR_MODE)
|
||||
- ri->mode = cpu_to_jemode(iattr->ia_mode);
|
||||
- else
|
||||
- ri->mode = cpu_to_jemode(inode->i_mode);
|
||||
+ if (ivalid & CHG_ATIME) {
|
||||
+ if ((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) {
|
||||
+ return -EPERM;
|
||||
@@ -2831,7 +2823,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
+ } else {
|
||||
+ ri->atime = cpu_to_je32(inode->i_atime);
|
||||
+ }
|
||||
|
||||
+
|
||||
+ if (ivalid & CHG_MTIME) {
|
||||
+ if ((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) {
|
||||
+ return -EPERM;
|
||||
@@ -2883,7 +2875,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
if (IS_ERR(new_metadata)) {
|
||||
jffs2_complete_reservation(c);
|
||||
jffs2_free_raw_inode(ri);
|
||||
@@ -147,23 +140,20 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
|
||||
@@ -147,23 +140,20 @@ int jffs2_do_setattr (struct inode *inod
|
||||
return PTR_ERR(new_metadata);
|
||||
}
|
||||
/* It worked. Update the inode */
|
||||
@@ -2916,7 +2908,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
f->metadata = NULL;
|
||||
} else {
|
||||
f->metadata = new_metadata;
|
||||
@@ -182,315 +172,201 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
|
||||
@@ -182,315 +172,201 @@ int jffs2_do_setattr (struct inode *inod
|
||||
We are protected from a simultaneous write() extending i_size
|
||||
back past iattr->ia_size, because do_truncate() holds the
|
||||
generic inode semaphore. */
|
||||
@@ -2935,43 +2927,31 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
{
|
||||
- struct inode *inode = d_inode(dentry);
|
||||
- int rc;
|
||||
-
|
||||
- rc = setattr_prepare(dentry, iattr);
|
||||
- if (rc)
|
||||
- return rc;
|
||||
-
|
||||
- rc = jffs2_do_setattr(inode, iattr);
|
||||
- if (!rc && (iattr->ia_valid & ATTR_MODE))
|
||||
- rc = posix_acl_chmod(inode, inode->i_mode);
|
||||
+ /* We can forget about this inode for now - drop all
|
||||
+ * the nodelists associated with it, etc.
|
||||
+ */
|
||||
+ struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
+ struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
|
||||
+
|
||||
+ jffs2_do_clear_inode(c, f);
|
||||
+}
|
||||
|
||||
- rc = setattr_prepare(dentry, iattr);
|
||||
- if (rc)
|
||||
- return rc;
|
||||
+static struct jffs2_inode *ilookup(struct super_block *sb, uint32_t ino)
|
||||
+{
|
||||
+ struct jffs2_inode *node = NULL;
|
||||
|
||||
- rc = jffs2_do_setattr(inode, iattr);
|
||||
- if (!rc && (iattr->ia_valid & ATTR_MODE))
|
||||
- rc = posix_acl_chmod(inode, inode->i_mode);
|
||||
+ if (sb->s_root == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
|
||||
- return rc;
|
||||
+ // Check for this inode in the cache
|
||||
+ Jffs2NodeLock();
|
||||
+ (void)Jffs2HashGet(&sb->s_node_hash_lock, &sb->s_node_hash[0], sb, ino, &node);
|
||||
+ Jffs2NodeUnlock();
|
||||
+ return node;
|
||||
+ jffs2_do_clear_inode(c, f);
|
||||
}
|
||||
|
||||
-int jffs2_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||
+struct jffs2_inode *new_inode(struct super_block *sb)
|
||||
+static struct jffs2_inode *ilookup(struct super_block *sb, uint32_t ino)
|
||||
{
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(dentry->d_sb);
|
||||
- unsigned long avail;
|
||||
-
|
||||
+ struct jffs2_inode *node = NULL;
|
||||
|
||||
- buf->f_type = JFFS2_SUPER_MAGIC;
|
||||
- buf->f_bsize = 1 << PAGE_SHIFT;
|
||||
- buf->f_blocks = c->flash_size >> PAGE_SHIFT;
|
||||
@@ -2990,35 +2970,47 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
- spin_unlock(&c->erase_completion_lock);
|
||||
-
|
||||
- buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT;
|
||||
+ struct jffs2_inode *inode = NULL;
|
||||
+ if (sb->s_root == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
|
||||
- return 0;
|
||||
-}
|
||||
+ inode = zalloc(sizeof (struct jffs2_inode));
|
||||
+ if (inode == NULL)
|
||||
+ return 0;
|
||||
|
||||
+ D2(PRINTK("malloc new_inode %x ####################################\n",
|
||||
+ inode));
|
||||
+ // Check for this inode in the cache
|
||||
+ Jffs2NodeLock();
|
||||
+ (void)Jffs2HashGet(&sb->s_node_hash_lock, &sb->s_node_hash[0], sb, ino, &node);
|
||||
+ Jffs2NodeUnlock();
|
||||
+ return node;
|
||||
}
|
||||
|
||||
-
|
||||
-void jffs2_evict_inode (struct inode *inode)
|
||||
-{
|
||||
+struct jffs2_inode *new_inode(struct super_block *sb)
|
||||
{
|
||||
- /* We can forget about this inode for now - drop all
|
||||
- * the nodelists associated with it, etc.
|
||||
- */
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
|
||||
- struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
|
||||
+ inode->i_sb = sb;
|
||||
+ inode->i_ino = 1;
|
||||
+ inode->i_nlink = 1; // Let JFFS2 manage the link count
|
||||
+ inode->i_size = 0;
|
||||
+ LOS_ListInit((&(inode->i_hashlist)));
|
||||
+ struct jffs2_inode *inode = NULL;
|
||||
|
||||
- jffs2_dbg(1, "%s(): ino #%lu mode %o\n",
|
||||
- __func__, inode->i_ino, inode->i_mode);
|
||||
- truncate_inode_pages_final(&inode->i_data);
|
||||
- clear_inode(inode);
|
||||
- jffs2_do_clear_inode(c, f);
|
||||
+ inode = zalloc(sizeof (struct jffs2_inode));
|
||||
+ if (inode == NULL)
|
||||
+ return 0;
|
||||
+
|
||||
+ D2(PRINTK("malloc new_inode %x ####################################\n",
|
||||
+ inode));
|
||||
+
|
||||
+ inode->i_sb = sb;
|
||||
+ inode->i_ino = 1;
|
||||
+ inode->i_nlink = 1; // Let JFFS2 manage the link count
|
||||
+ inode->i_size = 0;
|
||||
+ LOS_ListInit((&(inode->i_hashlist)));
|
||||
+
|
||||
+ return inode;
|
||||
}
|
||||
|
||||
@@ -3083,16 +3075,16 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
- inode->i_ctime = ITIME(je32_to_cpu(latest_node.ctime));
|
||||
-
|
||||
- set_nlink(inode, f->inocache->pino_nlink);
|
||||
-
|
||||
- inode->i_blocks = (inode->i_size + 511) >> 9;
|
||||
+ inode->i_atime = je32_to_cpu(latest_node.atime);
|
||||
+ inode->i_mtime = je32_to_cpu(latest_node.mtime);
|
||||
+ inode->i_ctime = je32_to_cpu(latest_node.ctime);
|
||||
+ inode->i_nlink = f->inocache->pino_nlink;
|
||||
|
||||
- switch (inode->i_mode & S_IFMT) {
|
||||
- inode->i_blocks = (inode->i_size + 511) >> 9;
|
||||
+ (void)mutex_unlock(&f->sem);
|
||||
|
||||
- switch (inode->i_mode & S_IFMT) {
|
||||
-
|
||||
- case S_IFLNK:
|
||||
- inode->i_op = &jffs2_symlink_inode_operations;
|
||||
- inode->i_link = f->target;
|
||||
@@ -3162,21 +3154,20 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
jffs2_dbg(1, "jffs2_read_inode() returning\n");
|
||||
- unlock_new_inode(inode);
|
||||
- return inode;
|
||||
+ Jffs2NodeUnlock();
|
||||
|
||||
-
|
||||
-error_io:
|
||||
- ret = -EIO;
|
||||
-error:
|
||||
- mutex_unlock(&f->sem);
|
||||
- iget_failed(inode);
|
||||
- return ERR_PTR(ret);
|
||||
+ return inode;
|
||||
}
|
||||
-}
|
||||
+ Jffs2NodeUnlock();
|
||||
|
||||
-void jffs2_dirty_inode(struct inode *inode, int flags)
|
||||
-{
|
||||
- struct iattr iattr;
|
||||
|
||||
-
|
||||
- if (!(inode->i_state & I_DIRTY_DATASYNC)) {
|
||||
- jffs2_dbg(2, "%s(): not calling setattr() for ino #%lu\n",
|
||||
- __func__, inode->i_ino);
|
||||
@@ -3195,19 +3186,16 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
- iattr.ia_ctime = inode->i_ctime;
|
||||
-
|
||||
- jffs2_do_setattr(inode, &iattr);
|
||||
-}
|
||||
+// -------------------------------------------------------------------------
|
||||
+// Decrement the reference count on an inode. If this makes the ref count
|
||||
+// zero, then this inode can be freed.
|
||||
+ return inode;
|
||||
}
|
||||
|
||||
-int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc)
|
||||
+int jffs2_iput(struct jffs2_inode *i)
|
||||
{
|
||||
-{
|
||||
- struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
|
||||
-
|
||||
- if (c->flags & JFFS2_SB_FLAG_RO && !sb_rdonly(sb))
|
||||
- return -EROFS;
|
||||
-
|
||||
|
||||
- /* We stop if it was running, then restart if it needs to.
|
||||
- This also catches the case where it was stopped and this
|
||||
- is just a remount to restart it.
|
||||
@@ -3218,9 +3206,12 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
- jffs2_flush_wbuf_pad(c);
|
||||
- mutex_unlock(&c->alloc_sem);
|
||||
- }
|
||||
-
|
||||
- if (!(fc->sb_flags & SB_RDONLY))
|
||||
- jffs2_start_garbage_collect_thread(c);
|
||||
+// -------------------------------------------------------------------------
|
||||
+// Decrement the reference count on an inode. If this makes the ref count
|
||||
+// zero, then this inode can be freed.
|
||||
+
|
||||
+int jffs2_iput(struct jffs2_inode *i)
|
||||
+{
|
||||
+ // Called in jffs2_find
|
||||
+ // (and jffs2_open and jffs2_ops_mkdir?)
|
||||
+ // super.c jffs2_fill_super,
|
||||
@@ -3242,6 +3233,9 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
+ free(i);
|
||||
+ Jffs2NodeUnlock();
|
||||
|
||||
- if (!(fc->sb_flags & SB_RDONLY))
|
||||
- jffs2_start_garbage_collect_thread(c);
|
||||
-
|
||||
- fc->sb_flags |= SB_NOATIME;
|
||||
return 0;
|
||||
}
|
||||
@@ -3348,7 +3342,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
{
|
||||
/*
|
||||
* Pick a inocache hash size based on the size of the medium.
|
||||
@@ -510,118 +386,17 @@ static int calculate_inocache_hashsize(uint32_t flash_size)
|
||||
@@ -510,117 +386,17 @@ static int calculate_inocache_hashsize(u
|
||||
return hashsize;
|
||||
}
|
||||
|
||||
@@ -3444,9 +3438,8 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
- jffs2_free_ino_caches(c);
|
||||
- jffs2_free_raw_node_refs(c);
|
||||
- kvfree(c->blocks);
|
||||
- jffs2_clear_xattr_subsystem(c);
|
||||
- jffs2_sum_exit(c);
|
||||
- out_inohash:
|
||||
- jffs2_clear_xattr_subsystem(c);
|
||||
- kfree(c->inocache_list);
|
||||
- out_wbuf:
|
||||
- jffs2_flash_cleanup(c);
|
||||
@@ -3455,7 +3448,8 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
-}
|
||||
-
|
||||
void jffs2_gc_release_inode(struct jffs2_sb_info *c,
|
||||
struct jffs2_inode_info *f)
|
||||
- struct jffs2_inode_info *f)
|
||||
+ struct jffs2_inode_info *f)
|
||||
{
|
||||
- iput(OFNI_EDONI_2SFFJ(f));
|
||||
+ struct jffs2_inode *node = OFNI_EDONI_2SFFJ(f);
|
||||
@@ -3470,7 +3464,7 @@ diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
|
||||
struct jffs2_inode_cache *ic;
|
||||
|
||||
if (unlinked) {
|
||||
@@ -669,72 +444,9 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
|
||||
@@ -668,72 +444,9 @@ struct jffs2_inode_info *jffs2_gc_fetch_
|
||||
Just iget() it, and if read_inode() is necessary that's OK.
|
||||
*/
|
||||
inode = jffs2_iget(OFNI_BS_2SFFJ(c), inum);
|
||||
@@ -5505,7 +5499,7 @@ diff -Nupr old/fs/jffs2/readinode.c new/fs/jffs2/readinode.c
|
||||
break;
|
||||
|
||||
default:
|
||||
+ JFFS2_ERROR("Unknown f->inocache->state %d!\n", f->inocache->state);
|
||||
+ JFFS2_ERROR("Unknow f->inocache->state %d!\n", f->inocache->state);
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
@@ -5562,7 +5556,7 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
|
||||
#define DEFAULT_EMPTY_SCAN_SIZE 256
|
||||
|
||||
@@ -74,7 +73,7 @@ static int file_dirty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
|
||||
@@ -74,7 +73,7 @@ static int file_dirty(struct jffs2_sb_in
|
||||
return ret;
|
||||
if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
|
||||
return ret;
|
||||
@@ -5571,13 +5565,15 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
think it's recoverable now. */
|
||||
jeb->dirty_size += jeb->wasted_size;
|
||||
c->dirty_size += jeb->wasted_size;
|
||||
@@ -95,40 +94,26 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
@@ -95,40 +94,26 @@ int jffs2_scan_medium(struct jffs2_sb_in
|
||||
unsigned char *flashbuf = NULL;
|
||||
uint32_t buf_size = 0;
|
||||
struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
|
||||
-#ifndef __ECOS
|
||||
- size_t pointlen, try_size;
|
||||
-
|
||||
+ struct super_block *sb = NULL;
|
||||
+ struct MtdNorDev *device = NULL;
|
||||
|
||||
- ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
|
||||
- (void **)&flashbuf, NULL);
|
||||
- if (!ret && pointlen < c->mtd->size) {
|
||||
@@ -5590,9 +5586,6 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
- if (ret && ret != -EOPNOTSUPP)
|
||||
- jffs2_dbg(1, "MTD point failed %d\n", ret);
|
||||
-#endif
|
||||
+ struct super_block *sb = NULL;
|
||||
+ struct MtdNorDev *device = NULL;
|
||||
+
|
||||
if (!flashbuf) {
|
||||
/* For NAND it's quicker to read a whole eraseblock at a time,
|
||||
apparently */
|
||||
@@ -5620,7 +5613,7 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
}
|
||||
|
||||
if (jffs2_sum_active()) {
|
||||
@@ -140,7 +125,9 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
@@ -140,7 +125,9 @@ int jffs2_scan_medium(struct jffs2_sb_in
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5631,7 +5624,7 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
struct jffs2_eraseblock *jeb = &c->blocks[i];
|
||||
|
||||
cond_resched();
|
||||
@@ -269,14 +256,10 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
@@ -269,19 +256,12 @@ int jffs2_scan_medium(struct jffs2_sb_in
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
@@ -5641,254 +5634,20 @@ diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
|
||||
}
|
||||
ret = 0;
|
||||
out:
|
||||
- jffs2_sum_reset_collected(s);
|
||||
- kfree(s);
|
||||
+ kfree(flashbuf);
|
||||
out_buf:
|
||||
if (buf_size)
|
||||
kfree(flashbuf);
|
||||
@@ -413,7 +396,7 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
|
||||
if (!ref)
|
||||
return -ENOMEM;
|
||||
|
||||
- /* BEFORE jffs2_build_xattr_subsystem() called,
|
||||
+ /* BEFORE jffs2_build_xattr_subsystem() called,
|
||||
* and AFTER xattr_ref is marked as a dead xref,
|
||||
* ref->xid is used to store 32bit xid, xd is not used
|
||||
* ref->ino is used to store 32bit inode-number, ic is not used
|
||||
@@ -486,10 +469,10 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
struct jffs2_sum_marker *sm;
|
||||
void *sumptr = NULL;
|
||||
uint32_t sumlen;
|
||||
-
|
||||
+
|
||||
if (!buf_size) {
|
||||
/* XIP case. Just look, point at the summary if it's there */
|
||||
- sm = (void *)buf + c->sector_size - sizeof(*sm);
|
||||
+ sm = (struct jffs2_sum_marker *)((uint8_t *)buf + c->sector_size - sizeof(*sm));
|
||||
if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
|
||||
sumptr = buf + je32_to_cpu(sm->offset);
|
||||
sumlen = c->sector_size - je32_to_cpu(sm->offset);
|
||||
@@ -502,13 +485,13 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
buf_len = sizeof(*sm);
|
||||
|
||||
/* Read as much as we want into the _end_ of the preallocated buffer */
|
||||
- err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
|
||||
+ err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
|
||||
jeb->offset + c->sector_size - buf_len,
|
||||
- buf_len);
|
||||
+ buf_len);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
- sm = (void *)buf + buf_size - sizeof(*sm);
|
||||
+ sm = (struct jffs2_sum_marker *)((uint8_t *)buf + buf_size - sizeof(*sm));
|
||||
if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
|
||||
sumlen = c->sector_size - je32_to_cpu(sm->offset);
|
||||
sumptr = buf + buf_size - sumlen;
|
||||
@@ -523,18 +506,15 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
sumptr = kmalloc(sumlen, GFP_KERNEL);
|
||||
if (!sumptr)
|
||||
return -ENOMEM;
|
||||
- memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
|
||||
+ memcpy((uint8_t *)sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
|
||||
}
|
||||
if (buf_len < sumlen) {
|
||||
/* Need to read more so that the entire summary node is present */
|
||||
- err = jffs2_fill_scan_buf(c, sumptr,
|
||||
+ err = jffs2_fill_scan_buf(c, sumptr,
|
||||
jeb->offset + c->sector_size - sumlen,
|
||||
- sumlen - buf_len);
|
||||
- if (err) {
|
||||
- if (sumlen > buf_size)
|
||||
- kfree(sumptr);
|
||||
+ sumlen - buf_len);
|
||||
+ if (err)
|
||||
return err;
|
||||
- }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,7 +525,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
|
||||
if (buf_size && sumlen > buf_size)
|
||||
kfree(sumptr);
|
||||
- /* If it returns with a real error, bail.
|
||||
+ /* If it returns with a real error, bail.
|
||||
If it returns positive, that's a block classification
|
||||
(i.e. BLK_STATE_xxx) so return that too.
|
||||
If it returns zero, fall through to full scan. */
|
||||
@@ -607,7 +587,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
/* Now ofs is a complete physical flash offset as it always was... */
|
||||
ofs += jeb->offset;
|
||||
|
||||
- noise = 10;
|
||||
+ noise = 1;
|
||||
|
||||
dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset);
|
||||
|
||||
@@ -700,7 +680,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
scan_end = buf_len;
|
||||
goto more_empty;
|
||||
}
|
||||
-
|
||||
+
|
||||
/* See how much more there is to read in this eraseblock... */
|
||||
buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
|
||||
if (!buf_len) {
|
||||
@@ -950,7 +930,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
jffs2_dbg(1, "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n",
|
||||
jeb->offset, jeb->free_size, jeb->dirty_size,
|
||||
jeb->unchecked_size, jeb->used_size, jeb->wasted_size);
|
||||
-
|
||||
+
|
||||
/* mark_node_obsolete can add to wasted !! */
|
||||
if (jeb->wasted_size) {
|
||||
jeb->dirty_size += jeb->wasted_size;
|
||||
@@ -978,7 +958,6 @@ struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uin
|
||||
pr_notice("%s(): allocation of inode cache failed\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
- memset(ic, 0, sizeof(*ic));
|
||||
|
||||
ic->ino = ino;
|
||||
ic->nodes = (void *)ic;
|
||||
@@ -1069,7 +1048,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
pseudo_random += je32_to_cpu(rd->version);
|
||||
|
||||
/* Should never happen. Did. (OLPC trac #4184)*/
|
||||
- checkedlen = strnlen(rd->name, rd->nsize);
|
||||
+ checkedlen = strnlen((const char *)rd->name, rd->nsize);
|
||||
if (checkedlen < rd->nsize) {
|
||||
pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n",
|
||||
ofs, checkedlen);
|
||||
@@ -1081,7 +1060,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
memcpy(&fd->name, rd->name, checkedlen);
|
||||
fd->name[checkedlen] = 0;
|
||||
|
||||
- crc = crc32(0, fd->name, checkedlen);
|
||||
+ crc = crc32(0, fd->name, rd->nsize);
|
||||
if (crc != je32_to_cpu(rd->name_crc)) {
|
||||
pr_notice("%s(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
|
||||
__func__, ofs, je32_to_cpu(rd->name_crc), crc);
|
||||
@@ -1106,7 +1085,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
fd->next = NULL;
|
||||
fd->version = je32_to_cpu(rd->version);
|
||||
fd->ino = je32_to_cpu(rd->ino);
|
||||
- fd->nhash = full_name_hash(NULL, fd->name, checkedlen);
|
||||
+ fd->nhash = full_name_hash(fd->name, checkedlen);
|
||||
fd->type = rd->type;
|
||||
jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
|
||||
|
||||
diff
|
||||
@@ -9,18 +9,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||
-
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/slab.h>
|
||||
-#include <linux/mtd/mtd.h>
|
||||
#include <linux/pagemap.h>
|
||||
-#include <linux/crc32.h>
|
||||
#include <linux/compiler.h>
|
||||
#include "nodelist.h"
|
||||
#include "summary.h"
|
||||
#include "debug.h"
|
||||
+#include "mtd_dev.h"
|
||||
+#include "los_typedef.h"
|
||||
+#include "los_crc32.h"
|
||||
|
||||
#define DEFAULT_EMPTY_SCAN_SIZE 256
|
||||
|
||||
@@ -74,7 +73,7 @@ static int file_dirty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
|
||||
return ret;
|
||||
if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
|
||||
return ret;
|
||||
- /* Turned wasted size into dirty, since we apparently
|
||||
+ /* Turned wasted size into dirty, since we apparently
|
||||
think it's recoverable now. */
|
||||
jeb->dirty_size += jeb->wasted_size;
|
||||
c->dirty_size += jeb->wasted_size;
|
||||
@@ -95,40 +94,26 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
unsigned char *flashbuf = NULL;
|
||||
uint32_t buf_size = 0;
|
||||
struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
|
||||
- if (buf_size)
|
||||
- kfree(flashbuf);
|
||||
-#ifndef __ECOS
|
||||
- size_t pointlen, try_size;
|
||||
-
|
||||
- ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
|
||||
- (void **)&flashbuf, NULL);
|
||||
- if (!ret && pointlen < c->mtd->size) {
|
||||
- /* Don't muck about if it won't let us point to the whole flash */
|
||||
- jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
|
||||
- pointlen);
|
||||
- mtd_unpoint(c->mtd, 0, pointlen);
|
||||
- flashbuf = NULL;
|
||||
- }
|
||||
- if (ret && ret != -EOPNOTSUPP)
|
||||
- jffs2_dbg(1, "MTD point failed %d\n", ret);
|
||||
- else
|
||||
- mtd_unpoint(c->mtd, 0, c->mtd->size);
|
||||
-#endif
|
||||
+ struct super_block *sb = NULL;
|
||||
+ struct MtdNorDev *device = NULL;
|
||||
+
|
||||
if (!flashbuf) {
|
||||
/* For NAND it's quicker to read a whole eraseblock at a time,
|
||||
apparently */
|
||||
if (jffs2_cleanmarker_oob(c))
|
||||
- try_size = c->sector_size;
|
||||
+ buf_size = c->sector_size;
|
||||
else
|
||||
- try_size = PAGE_SIZE;
|
||||
+ buf_size = PAGE_SIZE;
|
||||
|
||||
jffs2_dbg(1, "Trying to allocate readbuf of %zu "
|
||||
- "bytes\n", try_size);
|
||||
+ "bytes\n", buf_size);
|
||||
|
||||
- flashbuf = mtd_kmalloc_up_to(c->mtd, &try_size);
|
||||
+ flashbuf = kmalloc(buf_size, GFP_KERNEL);
|
||||
if (!flashbuf)
|
||||
return -ENOMEM;
|
||||
|
||||
jffs2_dbg(1, "Allocated readbuf of %zu bytes\n",
|
||||
- try_size);
|
||||
-
|
||||
- buf_size = (uint32_t)try_size;
|
||||
+ buf_size);
|
||||
}
|
||||
|
||||
if (jffs2_sum_active()) {
|
||||
@@ -140,7 +125,9 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
}
|
||||
}
|
||||
|
||||
- for (i=0; i<c->nr_blocks; i++) {
|
||||
+ sb = OFNI_BS_2SFFJ(c);
|
||||
+ device = (struct MtdNorDev*)(sb->s_dev);
|
||||
+ for (i=device->blockStart; i<c->nr_blocks + device->blockStart; i++) {
|
||||
struct jffs2_eraseblock *jeb = &c->blocks[i];
|
||||
|
||||
cond_resched();
|
||||
@@ -269,14 +256,10 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
|
||||
ret = -EIO;
|
||||
goto out;
|
||||
}
|
||||
- spin_lock(&c->erase_completion_lock);
|
||||
- jffs2_garbage_collect_trigger(c);
|
||||
- spin_unlock(&c->erase_completion_lock);
|
||||
}
|
||||
ret = 0;
|
||||
out:
|
||||
- jffs2_sum_reset_collected(s);
|
||||
- kfree(s);
|
||||
+
|
||||
+ kfree(flashbuf);
|
||||
out_buf:
|
||||
if (buf_size)
|
||||
kfree(flashbuf);
|
||||
@@ -413,7 +396,7 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
|
||||
+
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -411,7 +391,7 @@ static int jffs2_scan_xref_node(struct j
|
||||
if (!ref)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -5897,7 +5656,7 @@ diff
|
||||
* and AFTER xattr_ref is marked as a dead xref,
|
||||
* ref->xid is used to store 32bit xid, xd is not used
|
||||
* ref->ino is used to store 32bit inode-number, ic is not used
|
||||
@@ -486,10 +469,10 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -484,10 +464,10 @@ static int jffs2_scan_eraseblock (struct
|
||||
struct jffs2_sum_marker *sm;
|
||||
void *sumptr = NULL;
|
||||
uint32_t sumlen;
|
||||
@@ -5910,7 +5669,7 @@ diff
|
||||
if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
|
||||
sumptr = buf + je32_to_cpu(sm->offset);
|
||||
sumlen = c->sector_size - je32_to_cpu(sm->offset);
|
||||
@@ -502,13 +485,13 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -500,13 +480,13 @@ static int jffs2_scan_eraseblock (struct
|
||||
buf_len = sizeof(*sm);
|
||||
|
||||
/* Read as much as we want into the _end_ of the preallocated buffer */
|
||||
@@ -5927,7 +5686,7 @@ diff
|
||||
if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
|
||||
sumlen = c->sector_size - je32_to_cpu(sm->offset);
|
||||
sumptr = buf + buf_size - sumlen;
|
||||
@@ -523,18 +506,15 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -521,18 +501,15 @@ static int jffs2_scan_eraseblock (struct
|
||||
sumptr = kmalloc(sumlen, GFP_KERNEL);
|
||||
if (!sumptr)
|
||||
return -ENOMEM;
|
||||
@@ -5950,7 +5709,7 @@ diff
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,7 +525,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -543,7 +520,7 @@ static int jffs2_scan_eraseblock (struct
|
||||
|
||||
if (buf_size && sumlen > buf_size)
|
||||
kfree(sumptr);
|
||||
@@ -5959,7 +5718,7 @@ diff
|
||||
If it returns positive, that's a block classification
|
||||
(i.e. BLK_STATE_xxx) so return that too.
|
||||
If it returns zero, fall through to full scan. */
|
||||
@@ -607,7 +587,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -605,7 +582,7 @@ full_scan:
|
||||
/* Now ofs is a complete physical flash offset as it always was... */
|
||||
ofs += jeb->offset;
|
||||
|
||||
@@ -5968,7 +5727,7 @@ diff
|
||||
|
||||
dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset);
|
||||
|
||||
@@ -700,7 +680,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -698,7 +675,7 @@ scan_more:
|
||||
scan_end = buf_len;
|
||||
goto more_empty;
|
||||
}
|
||||
@@ -5977,7 +5736,7 @@ diff
|
||||
/* See how much more there is to read in this eraseblock... */
|
||||
buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
|
||||
if (!buf_len) {
|
||||
@@ -950,7 +930,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -948,7 +925,7 @@ scan_more:
|
||||
jffs2_dbg(1, "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n",
|
||||
jeb->offset, jeb->free_size, jeb->dirty_size,
|
||||
jeb->unchecked_size, jeb->used_size, jeb->wasted_size);
|
||||
@@ -5986,7 +5745,7 @@ diff
|
||||
/* mark_node_obsolete can add to wasted !! */
|
||||
if (jeb->wasted_size) {
|
||||
jeb->dirty_size += jeb->wasted_size;
|
||||
@@ -978,7 +958,6 @@ struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uin
|
||||
@@ -976,7 +953,6 @@ struct jffs2_inode_cache *jffs2_scan_mak
|
||||
pr_notice("%s(): allocation of inode cache failed\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
@@ -5994,7 +5753,7 @@ diff
|
||||
|
||||
ic->ino = ino;
|
||||
ic->nodes = (void *)ic;
|
||||
@@ -1069,7 +1048,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -1067,7 +1043,7 @@ static int jffs2_scan_dirent_node(struct
|
||||
pseudo_random += je32_to_cpu(rd->version);
|
||||
|
||||
/* Should never happen. Did. (OLPC trac #4184)*/
|
||||
@@ -6003,7 +5762,7 @@ diff
|
||||
if (checkedlen < rd->nsize) {
|
||||
pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n",
|
||||
ofs, checkedlen);
|
||||
@@ -1081,7 +1060,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -1079,7 +1055,7 @@ static int jffs2_scan_dirent_node(struct
|
||||
memcpy(&fd->name, rd->name, checkedlen);
|
||||
fd->name[checkedlen] = 0;
|
||||
|
||||
@@ -6012,7 +5771,7 @@ diff
|
||||
if (crc != je32_to_cpu(rd->name_crc)) {
|
||||
pr_notice("%s(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
|
||||
__func__, ofs, je32_to_cpu(rd->name_crc), crc);
|
||||
@@ -1106,7 +1085,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
||||
@@ -1104,7 +1080,7 @@ static int jffs2_scan_dirent_node(struct
|
||||
fd->next = NULL;
|
||||
fd->version = je32_to_cpu(rd->version);
|
||||
fd->ino = je32_to_cpu(rd->ino);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -682,6 +682,7 @@ int VfsJffs2Rmdir(struct Vnode *parentVnode, struct Vnode *targetVnode, const ch
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
|
||||
ret = jffs2_rmdir(parentInode, targetInode, (const unsigned char *)path);
|
||||
|
||||
if (ret == 0) {
|
||||
(void)jffs2_iput(targetInode);
|
||||
}
|
||||
@@ -780,6 +781,7 @@ ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
|
||||
cnt = (bufLen - 1) < targetLen ? (bufLen - 1) : targetLen;
|
||||
if (LOS_CopyFromKernel(buffer, bufLen, (const char *)f->target, cnt) != 0) {
|
||||
cnt = 0;
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return -EFAULT;
|
||||
}
|
||||
@@ -807,6 +809,7 @@ int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const c
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
|
||||
ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path);
|
||||
|
||||
if (ret == 0) {
|
||||
(void)jffs2_iput(targetInode);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ struct ProcData {
|
||||
#define S_IALLUGO (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
|
||||
/**
|
||||
* Interface for modules using proc below internal proc module;
|
||||
* Interface for modules using proc below internal proc moudule;
|
||||
*/
|
||||
/**
|
||||
* @ingroup procfs
|
||||
|
||||
@@ -135,7 +135,7 @@ void ProcFdInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("fd", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create /proc/fd error.\n");
|
||||
PRINT_ERR("creat /proc/fd error.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -154,8 +154,7 @@ static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)
|
||||
|
||||
VnodeHold();
|
||||
LosBufPrintf(buf, "\n=================================================================\n");
|
||||
LosBufPrintf(buf,
|
||||
"VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
|
||||
LosBufPrintf(buf, "VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
|
||||
vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList());
|
||||
vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
|
||||
vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
|
||||
|
||||
@@ -91,7 +91,7 @@ void ProcMountsInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("mounts", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create mounts error!\n");
|
||||
PRINT_ERR("creat mounts error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ void ProcUptimeInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("uptime", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create /proc/uptime error!\n");
|
||||
PRINT_ERR("creat /proc/uptime error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,8 @@ static struct ProcDirEntry g_procRootDirEntry = {
|
||||
|
||||
int ProcMatch(unsigned int len, const char *name, struct ProcDirEntry *pn)
|
||||
{
|
||||
if (len != pn->nameLen) {
|
||||
if (len != pn->nameLen)
|
||||
return 0;
|
||||
}
|
||||
return !strncmp(name, pn->name, len);
|
||||
}
|
||||
|
||||
@@ -388,9 +387,8 @@ static void FreeProcEntry(struct ProcDirEntry *entry)
|
||||
|
||||
void ProcFreeEntry(struct ProcDirEntry *pn)
|
||||
{
|
||||
if (atomic_dec_and_test(&pn->count)) {
|
||||
if (atomic_dec_and_test(&pn->count))
|
||||
FreeProcEntry(pn);
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -62,8 +62,8 @@ int OsShellCmdWriteProc(int argc, char **argv)
|
||||
|
||||
if (argc == WRITEPROC_ARGC) {
|
||||
value = argv[0];
|
||||
path = argv[2]; // 2: index of path
|
||||
len = strlen(value) + 1; /* + 1:add the \0 */
|
||||
path = argv[2];
|
||||
len = strlen(value) + 1; /* +1:add the \0 */
|
||||
if (strncmp(argv[1], ">>", strlen(">>")) == 0) {
|
||||
if ((realpath(path, realPath) == NULL) || (strncmp(realPath, rootProcDir, strlen(rootProcDir)) != 0)) {
|
||||
PRINT_ERR("No such file or directory\n");
|
||||
|
||||
@@ -29,9 +29,10 @@ endchoice
|
||||
config BOOTENV_ADDR
|
||||
int "Address of boot command line (KB)"
|
||||
depends on PLATFORM_ROOTFS && (STORAGE_SPINOR || STORAGE_SPINAND || STORAGE_EMMC)
|
||||
range 0 1024
|
||||
default 512
|
||||
help
|
||||
Boot command line addr.
|
||||
Boot command line addr, range from 0 to 1MB.
|
||||
|
||||
config BOOTENV_RAM
|
||||
bool "Read bootenv from RAM"
|
||||
|
||||
@@ -33,6 +33,10 @@ MODULE_NAME := rootfs
|
||||
|
||||
LOCAL_SRCS := $(wildcard los_rootfs.c los_bootargs.c)
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -32,10 +32,14 @@
|
||||
#include "los_base.h"
|
||||
#include "string.h"
|
||||
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
#include "mtd_list.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
#include "cfiflash.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_STORAGE_EMMC
|
||||
#include "disk.h"
|
||||
#endif
|
||||
@@ -94,6 +98,19 @@ INT32 LOS_GetCmdLine(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
struct MtdDev *mtd = GetCfiMtdDev();
|
||||
if (mtd == NULL) {
|
||||
PRINT_ERR("Get CFI mtd failed!\n");
|
||||
goto ERROUT;
|
||||
}
|
||||
g_alignSize = mtd->eraseSize;
|
||||
ret = mtd->read(mtd, CFIFLASH_BOOTARGS_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
|
||||
if (ret == COMMAND_LINE_SIZE) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRINT_ERR("Read cmdline error!\n");
|
||||
ERROUT:
|
||||
free(g_cmdLine);
|
||||
|
||||
@@ -37,11 +37,15 @@
|
||||
#include "sys/stat.h"
|
||||
#include "sys/types.h"
|
||||
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
#include "mtd_list.h"
|
||||
#include "mtd_partition.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
#include "cfiflash.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_STORAGE_EMMC
|
||||
#include "disk.h"
|
||||
#include "ff.h"
|
||||
@@ -124,7 +128,14 @@ STATIC INT32 AddEmmcParts(INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32
|
||||
|
||||
STATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr, UINT64 userSize)
|
||||
{
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND)
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
if ((strcmp(dev, "cfi-flash") == 0) && (rootAddr != CFIFLASH_ROOT_ADDR)) {
|
||||
PRINT_ERR("Error rootAddr, must be %#0x!\n", CFIFLASH_ROOT_ADDR);
|
||||
return LOS_NOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
INT32 ret;
|
||||
INT32 blk0 = 0;
|
||||
INT32 blk2 = 2;
|
||||
|
||||
@@ -59,6 +59,12 @@
|
||||
#define ROOTFS_ADDR 0x600000
|
||||
#define ROOTFS_SIZE 0x800000
|
||||
#define USERFS_SIZE 0x80000
|
||||
#elif defined (LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
#define ROOT_DEV_NAME "/dev/cfiflash0"
|
||||
#define USER_DEV_NAME "/dev/cfiflash2"
|
||||
#define ROOTFS_ADDR CFIFLASH_ROOT_ADDR
|
||||
#define ROOTFS_SIZE 0x1B00000
|
||||
#define USERFS_SIZE (CFIFLASH_CAPACITY - ROOTFS_ADDR - ROOTFS_SIZE)
|
||||
#elif defined (LOSCFG_STORAGE_EMMC)
|
||||
#define ROOT_DEV_NAME "/dev/mmcblk0p0"
|
||||
#ifdef LOSCFG_PLATFORM_PATCHFS
|
||||
|
||||
@@ -581,8 +581,8 @@ static OsBcacheBlock *AllocNewBlock(OsBcache *bc, BOOL read, UINT64 num)
|
||||
DelBlock(bc, prefer);
|
||||
}
|
||||
|
||||
if (prefer->used) { /* do not combine with next check */
|
||||
MergeSyncBlocks(bc, prefer); /* prefer->used may be changed here */
|
||||
if (prefer->used) {
|
||||
MergeSyncBlocks(bc, prefer);
|
||||
}
|
||||
|
||||
if (prefer->used) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -164,23 +164,23 @@ static VOID DoEpollClose(struct epoll_head *epHead)
|
||||
}
|
||||
|
||||
/**
|
||||
* epoll_create unsupported api
|
||||
*
|
||||
* epoll_create is implemented by calling epoll_create1, it's parameter 'size' is useless.
|
||||
*
|
||||
* epoll_create1,
|
||||
* epoll_create,
|
||||
* The simple version of epoll does not use red-black trees,
|
||||
* so when fd is normal value (greater than 0),
|
||||
* actually allocated epoll can manage num of EPOLL_DEFAULT_SIZE
|
||||
*
|
||||
* @param flags: not actually used
|
||||
* @param size: not actually used
|
||||
* @return epoll fd
|
||||
*/
|
||||
int epoll_create1(int flags)
|
||||
int epoll_create(int size)
|
||||
{
|
||||
(void)flags;
|
||||
int fd = -1;
|
||||
|
||||
if (size <= 0) {
|
||||
set_errno(EINVAL);
|
||||
return fd;
|
||||
}
|
||||
|
||||
struct epoll_head *epHead = (struct epoll_head *)malloc(sizeof(struct epoll_head));
|
||||
if (epHead == NULL) {
|
||||
set_errno(ENOMEM);
|
||||
@@ -304,7 +304,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout
|
||||
int pollSize;
|
||||
|
||||
epHead = EpollGetDataBuff(epfd);
|
||||
if (epHead == NULL) {
|
||||
if (epHead== NULL) {
|
||||
set_errno(EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ typedef struct tagOsBcache {
|
||||
* <li>The block number is automatically adjusted if position is greater than block size.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #0 read succeeded
|
||||
* @retval #0 read succeded
|
||||
* @retval #INT32 read failed
|
||||
*
|
||||
* @par Dependency:
|
||||
@@ -168,7 +168,7 @@ INT32 BlockCacheRead(OsBcache *bc,
|
||||
* <li>The block number is automatically adjusted if position is greater than block size.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #0 write succeeded
|
||||
* @retval #0 write succeded
|
||||
* @retval #INT32 write failed
|
||||
*
|
||||
* @par Dependency:
|
||||
@@ -193,7 +193,7 @@ INT32 BlockCacheWrite(OsBcache *bc,
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #0 sync succeeded
|
||||
* @retval #0 sync succeded
|
||||
* @retval #INT32 sync failed
|
||||
*
|
||||
* @par Dependency:
|
||||
@@ -219,7 +219,7 @@ INT32 BlockCacheSync(OsBcache *bc);
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @retval #OsBcache * init succeeded
|
||||
* @retval #OsBcache * init succeded
|
||||
* @retval #NULL init failed
|
||||
*
|
||||
* @par Dependency:
|
||||
|
||||
@@ -72,7 +72,7 @@ struct epoll_event {
|
||||
epoll_data_t data;
|
||||
};
|
||||
|
||||
int epoll_create1(int flags);
|
||||
int epoll_create(int size);
|
||||
int epoll_close(int epfd);
|
||||
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev);
|
||||
int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout);
|
||||
|
||||
@@ -160,7 +160,7 @@ typedef int VfsHashCmp(struct Vnode *vnode, void *arg);
|
||||
|
||||
int VnodesInit(void);
|
||||
int VnodeDevInit(void);
|
||||
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode);
|
||||
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode);
|
||||
int VnodeFree(struct Vnode *vnode);
|
||||
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags);
|
||||
int VnodeLookupFullpath(const char *fullpath, struct Vnode **vnode, uint32_t flags);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -225,6 +225,7 @@ static char *vfs_normalize_fullpath(const char *directory, const char *filename,
|
||||
/* it's a absolute path, use it directly */
|
||||
|
||||
fullpath = strdup(filename); /* copy string */
|
||||
|
||||
if (fullpath == NULL) {
|
||||
*pathname = NULL;
|
||||
set_errno(ENOMEM);
|
||||
@@ -257,10 +258,11 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
|
||||
}
|
||||
|
||||
#ifdef VFS_USING_WORKDIR
|
||||
if (directory == NULL) {
|
||||
if (directory == NULL)
|
||||
{
|
||||
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
|
||||
directory = curr->files->workdir;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((directory == NULL) && (filename[0] != '/')) {
|
||||
PRINT_ERR("NO_WORKING_DIR\n");
|
||||
@@ -273,18 +275,20 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
|
||||
|
||||
if ((filename[0] != '/') && (strlen(directory) + namelen + 2 > TEMP_PATH_MAX)) {
|
||||
#ifdef VFS_USING_WORKDIR
|
||||
if (dir_flags == TRUE) {
|
||||
if (dir_flags == TRUE)
|
||||
{
|
||||
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
|
||||
fullpath = vfs_normalize_fullpath(directory, filename, pathname, namelen);
|
||||
#ifdef VFS_USING_WORKDIR
|
||||
if (dir_flags == TRUE) {
|
||||
if (dir_flags == TRUE)
|
||||
{
|
||||
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (fullpath == NULL) {
|
||||
return -get_errno();
|
||||
@@ -304,7 +308,7 @@ int vfs_normalize_path(const char *directory, const char *filename, char **pathn
|
||||
|
||||
int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname)
|
||||
{
|
||||
/* Get path by dirfd */
|
||||
/* Get path by dirfd*/
|
||||
char *relativeoldpath = NULL;
|
||||
char *fullpath = NULL;
|
||||
int ret = 0;
|
||||
|
||||
@@ -133,7 +133,7 @@ int fallocate64(int fd, int mode, off64_t offset, off64_t len)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if ((unsigned int)filep->f_oflags & O_DIRECTORY) {
|
||||
if (filep->f_oflags & O_DIRECTORY) {
|
||||
set_errno(EBADF);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ static struct file_operations_vfs g_errorFileOps = {
|
||||
.unlink = ErrorFopUnlink,
|
||||
};
|
||||
|
||||
static struct Mount* GetDevMountPoint(const struct Vnode *dev)
|
||||
static struct Mount* GetDevMountPoint(struct Vnode *dev)
|
||||
{
|
||||
struct Mount *mnt = NULL;
|
||||
LIST_HEAD *mntList = GetMountList();
|
||||
@@ -394,7 +394,7 @@ static void FilePreClose(struct file *filep, const struct file_operations_vfs *o
|
||||
}
|
||||
}
|
||||
|
||||
static void FileDisableAndClean(const struct Mount *mnt)
|
||||
static void FileDisableAndClean(struct Mount *mnt)
|
||||
{
|
||||
struct filelist *flist = &tg_filelist;
|
||||
struct file *filep = NULL;
|
||||
@@ -435,7 +435,7 @@ static void VnodeTryFree(struct Vnode *vnode)
|
||||
vnode->fop = &g_errorFileOps;
|
||||
}
|
||||
|
||||
static void VnodeTryFreeAll(const struct Mount *mount)
|
||||
static void VnodeTryFreeAll(struct Mount *mount)
|
||||
{
|
||||
struct Vnode *vnode = NULL;
|
||||
struct Vnode *nextVnode = NULL;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -132,19 +132,19 @@ int VfsPermissionCheck(uint fuid, uint fgid, uint fileMode, int accMode)
|
||||
#ifdef VFS_USING_WORKDIR
|
||||
static int SetWorkDir(const char *dir, size_t len)
|
||||
{
|
||||
errno_t ret;
|
||||
uint lock_flags;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
errno_t ret;
|
||||
uint lock_flags;
|
||||
LosProcessCB *curr = OsCurrProcessGet();
|
||||
|
||||
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
|
||||
ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
|
||||
curr->files->workdir[PATH_MAX - 1] = '\0';
|
||||
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
|
||||
if (ret != EOK) {
|
||||
return -1;
|
||||
}
|
||||
spin_lock_irqsave(&curr->files->workdir_lock, lock_flags);
|
||||
ret = strncpy_s(curr->files->workdir, PATH_MAX, dir, len);
|
||||
curr->files->workdir[PATH_MAX - 1] = '\0';
|
||||
spin_unlock_irqrestore(&curr->files->workdir_lock, lock_flags);
|
||||
if (ret != EOK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -155,6 +155,7 @@ int chdir(const char *path)
|
||||
char *fullpath_bak = NULL;
|
||||
struct stat statBuff;
|
||||
|
||||
|
||||
if (!path) {
|
||||
set_errno(EFAULT);
|
||||
return -1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -57,6 +57,7 @@ int utime(const char *path, const struct utimbuf *ptimes)
|
||||
|
||||
/* Sanity checks */
|
||||
|
||||
|
||||
if (path == NULL) {
|
||||
ret = -EINVAL;
|
||||
goto errout;
|
||||
|
||||
@@ -66,6 +66,7 @@ static int iov_trans_to_buf(char *buf, ssize_t totallen, const struct iovec *iov
|
||||
} else {
|
||||
writepart = bytestowrite - ret;
|
||||
curbuf += writepart;
|
||||
totallen -= writepart;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -239,7 +239,7 @@ BOOL VnodeInUseIter(const struct Mount *mount)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int VnodeHold(void)
|
||||
int VnodeHold()
|
||||
{
|
||||
int ret = LOS_MuxLock(&g_vnodeMux, LOS_WAIT_FOREVER);
|
||||
if (ret != LOS_OK) {
|
||||
@@ -248,7 +248,7 @@ int VnodeHold(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int VnodeDrop(void)
|
||||
int VnodeDrop()
|
||||
{
|
||||
int ret = LOS_MuxUnlock(&g_vnodeMux);
|
||||
if (ret != LOS_OK) {
|
||||
@@ -583,7 +583,7 @@ int VnodeCreate(struct Vnode *parent, const char *name, int mode, struct Vnode *
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VnodeDevInit(void)
|
||||
int VnodeDevInit()
|
||||
{
|
||||
struct Vnode *devNode = NULL;
|
||||
struct Mount *devMount = NULL;
|
||||
@@ -616,7 +616,7 @@ int VnodeGetattr(struct Vnode *vnode, struct stat *buf)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
struct Vnode *VnodeGetRoot(void)
|
||||
struct Vnode *VnodeGetRoot()
|
||||
{
|
||||
return g_rootVnode;
|
||||
}
|
||||
@@ -697,7 +697,7 @@ LIST_HEAD* GetVnodeActiveList()
|
||||
return &g_vnodeActiveList;
|
||||
}
|
||||
|
||||
int VnodeClearCache(void)
|
||||
int VnodeClearCache()
|
||||
{
|
||||
struct Vnode *item = NULL;
|
||||
struct Vnode *nextItem = NULL;
|
||||
|
||||
@@ -67,12 +67,6 @@ config PAGE_TABLE_FINE_LOCK
|
||||
help
|
||||
This option will enable fine lock for page table.
|
||||
|
||||
config ENABLE_KERNEL_TEST
|
||||
bool "Enable kernel test"
|
||||
default n
|
||||
help
|
||||
This option will enable kernel test.
|
||||
|
||||
######################### config options of extended #####################
|
||||
source "kernel/extended/Kconfig"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
@@ -65,12 +65,10 @@ kernel_module(module_name) {
|
||||
"mp/los_mp.c",
|
||||
"mp/los_percpu.c",
|
||||
"mp/los_spinlock.c",
|
||||
"mp/los_stat.c",
|
||||
"om/los_err.c",
|
||||
"sched/los_idle.c",
|
||||
"sched/los_priority.c",
|
||||
"sched/los_sched.c",
|
||||
"sched/los_sortlink.c",
|
||||
"sched/los_statistics.c",
|
||||
"sched/sched_sq/los_sched.c",
|
||||
"sched/sched_sq/los_sortlink.c",
|
||||
"vm/los_vm_boot.c",
|
||||
"vm/los_vm_dump.c",
|
||||
"vm/los_vm_fault.c",
|
||||
@@ -90,13 +88,8 @@ kernel_module(module_name) {
|
||||
}
|
||||
|
||||
public_configs = [ ":public" ]
|
||||
configs += [ ":private" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
config("private") {
|
||||
cflags = [ "-Wno-frame-address" ]
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/hdf_core/adapter/khdf/liteos/lite.mk
|
||||
include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
@@ -37,9 +37,9 @@ LOCAL_SRCS := $(wildcard ipc/*.c) $(wildcard core/*.c) $(wildcard mem/membox/*.
|
||||
$(wildcard misc/*.c)\
|
||||
$(wildcard mem/tlsf/*.c) \
|
||||
$(wildcard mp/*.c) \
|
||||
$(wildcard sched/*.c) \
|
||||
$(wildcard sched/sched_sq/*.c) \
|
||||
$(wildcard vm/*.c)
|
||||
|
||||
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) -Wno-frame-address
|
||||
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK)
|
||||
|
||||
include $(MODULE)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -87,7 +87,7 @@ VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB)
|
||||
OsTaskInsertToRecycleList(taskCB);
|
||||
}
|
||||
|
||||
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
|
||||
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT16 numCount;
|
||||
@@ -100,14 +100,12 @@ UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_USER_MODE;
|
||||
if (processCB->threadNumber > 0) {
|
||||
LosTaskCB *task = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
task->ops->schedParamGet(task, param);
|
||||
taskCB->basePrio = OS_TCB_FROM_TID(processCB->threadGroupID)->basePrio;
|
||||
} else {
|
||||
OsSchedProcessDefaultSchedParamGet(param->policy, param);
|
||||
taskCB->basePrio = OS_USER_PROCESS_PRIORITY_HIGHEST;
|
||||
}
|
||||
} else {
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
runTask->ops->schedParamGet(runTask, param);
|
||||
taskCB->basePrio = OsCurrTaskGet()->basePrio;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
@@ -285,7 +283,7 @@ STATIC LosProcessCB *OsFindExitChildProcess(const LosProcessCB *processCB, INT32
|
||||
VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
|
||||
{
|
||||
taskCB->waitID = wakePID;
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
#endif
|
||||
@@ -899,7 +897,7 @@ STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 p
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedParam *param, UINT16 prio)
|
||||
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, UINT16 prio)
|
||||
{
|
||||
LosProcessCB *runProcess = OsCurrProcessGet();
|
||||
|
||||
@@ -909,7 +907,7 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedPa
|
||||
}
|
||||
|
||||
/* user mode process can reduce the priority of itself */
|
||||
if ((runProcess->processID == processCB->processID) && (prio > param->basePrio)) {
|
||||
if ((runProcess->processID == processCB->processID) && (prio > OsCurrTaskGet()->basePrio)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -923,33 +921,31 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedPa
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
|
||||
{
|
||||
SchedParam param = { 0 };
|
||||
LosProcessCB *processCB = NULL;
|
||||
BOOL needSched = FALSE;
|
||||
UINT32 intSave;
|
||||
INT32 ret;
|
||||
|
||||
INT32 ret = OsProcessSchedlerParamCheck(which, pid, prio, policy);
|
||||
ret = OsProcessSchedlerParamCheck(which, pid, prio, policy);
|
||||
if (ret != LOS_OK) {
|
||||
return -ret;
|
||||
}
|
||||
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
processCB = OS_PCB_FROM_PID(pid);
|
||||
if (OsProcessIsInactive(processCB)) {
|
||||
ret = LOS_ESRCH;
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
if (!OsProcessCapPermitCheck(processCB, ¶m, prio)) {
|
||||
if (!OsProcessCapPermitCheck(processCB, prio)) {
|
||||
ret = LOS_EPERM;
|
||||
goto EXIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
param.basePrio = prio;
|
||||
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
needSched = OsSchedModifyProcessSchedParam(pid, policy, prio);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -995,8 +991,8 @@ LITE_OS_SEC_TEXT INT32 LOS_SetProcessPriority(INT32 pid, UINT16 prio)
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
|
||||
{
|
||||
INT32 prio;
|
||||
UINT32 intSave;
|
||||
SchedParam param = { 0 };
|
||||
(VOID)which;
|
||||
|
||||
if (OS_PID_CHECK_INVALID(pid)) {
|
||||
@@ -1010,15 +1006,15 @@ LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(pid);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return -LOS_ESRCH;
|
||||
prio = -LOS_ESRCH;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
prio = (INT32)OS_TCB_FROM_TID(processCB->threadGroupID)->basePrio;
|
||||
|
||||
OUT:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return param.basePrio;
|
||||
return prio;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 LOS_GetProcessPriority(INT32 pid)
|
||||
@@ -1054,7 +1050,8 @@ STATIC VOID OsWaitInsertWaitListInOrder(LosTaskCB *runTask, LosProcessCB *proces
|
||||
/* if runTask->waitFlag == OS_PROCESS_WAIT_PRO,
|
||||
* this node is inserted directly into the header of the waitList
|
||||
*/
|
||||
(VOID)runTask->ops->wait(runTask, list->pstNext, LOS_WAIT_FOREVER);
|
||||
|
||||
(VOID)OsSchedTaskWait(list->pstNext, LOS_WAIT_FOREVER, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1205,10 +1202,13 @@ STATIC INT32 OsWait(INT32 pid, USER INT32 *status, USER siginfo_t *info, UINT32
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
LosProcessCB *childCB = NULL;
|
||||
LosProcessCB *processCB = NULL;
|
||||
LosTaskCB *runTask = NULL;
|
||||
|
||||
LosProcessCB *processCB = OsCurrProcessGet();
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
SCHEDULER_LOCK(intSave);
|
||||
processCB = OsCurrProcessGet();
|
||||
runTask = OsCurrTaskGet();
|
||||
|
||||
ret = OsWaitChildProcessCheck(processCB, pid, &childCB);
|
||||
if (ret != LOS_OK) {
|
||||
pid = -ret;
|
||||
@@ -1725,37 +1725,47 @@ STATIC UINT32 OsCopyUser(LosProcessCB *childCB, LosProcessCB *parentCB)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsInitCopyTaskParam(LosProcessCB *childProcessCB, const CHAR *name, UINTPTR entry, UINT32 size,
|
||||
TSK_INIT_PARAM_S *childPara)
|
||||
{
|
||||
LosTaskCB *mainThread = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
mainThread = OsCurrTaskGet();
|
||||
|
||||
if (OsProcessIsUserMode(childProcessCB)) {
|
||||
childPara->pfnTaskEntry = mainThread->taskEntry;
|
||||
childPara->uwStackSize = mainThread->stackSize;
|
||||
childPara->userParam.userArea = mainThread->userArea;
|
||||
childPara->userParam.userMapBase = mainThread->userMapBase;
|
||||
childPara->userParam.userMapSize = mainThread->userMapSize;
|
||||
} else {
|
||||
childPara->pfnTaskEntry = (TSK_ENTRY_FUNC)entry;
|
||||
childPara->uwStackSize = size;
|
||||
}
|
||||
childPara->pcName = (CHAR *)name;
|
||||
childPara->policy = mainThread->policy;
|
||||
childPara->usTaskPrio = mainThread->priority;
|
||||
childPara->processID = childProcessCB->processID;
|
||||
if (mainThread->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
|
||||
childPara->uwResved = LOS_TASK_ATTR_JOINABLE;
|
||||
}
|
||||
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR *name, UINTPTR entry, UINT32 size)
|
||||
{
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
TSK_INIT_PARAM_S taskParam = { 0 };
|
||||
UINT32 ret, taskID, intSave;
|
||||
SchedParam param = { 0 };
|
||||
TSK_INIT_PARAM_S childPara = { 0 };
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
UINT32 taskID;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsProcessIsUserMode(childProcessCB)) {
|
||||
taskParam.pfnTaskEntry = runTask->taskEntry;
|
||||
taskParam.uwStackSize = runTask->stackSize;
|
||||
taskParam.userParam.userArea = runTask->userArea;
|
||||
taskParam.userParam.userMapBase = runTask->userMapBase;
|
||||
taskParam.userParam.userMapSize = runTask->userMapSize;
|
||||
} else {
|
||||
taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)entry;
|
||||
taskParam.uwStackSize = size;
|
||||
}
|
||||
if (runTask->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
|
||||
taskParam.uwResved = LOS_TASK_ATTR_JOINABLE;
|
||||
}
|
||||
OsInitCopyTaskParam(childProcessCB, name, entry, size, &childPara);
|
||||
|
||||
runTask->ops->schedParamGet(runTask, ¶m);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
taskParam.pcName = (CHAR *)name;
|
||||
taskParam.policy = param.policy;
|
||||
taskParam.usTaskPrio = param.priority;
|
||||
taskParam.processID = childProcessCB->processID;
|
||||
|
||||
ret = LOS_TaskCreateOnly(&taskID, &taskParam);
|
||||
ret = LOS_TaskCreateOnly(&taskID, &childPara);
|
||||
if (ret != LOS_OK) {
|
||||
if (ret == LOS_ERRNO_TSK_TCB_UNAVAILABLE) {
|
||||
return LOS_EAGAIN;
|
||||
@@ -1765,7 +1775,7 @@ STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR
|
||||
|
||||
LosTaskCB *childTaskCB = OS_TCB_FROM_TID(taskID);
|
||||
childTaskCB->taskStatus = runTask->taskStatus;
|
||||
childTaskCB->ops->schedParamModify(childTaskCB, ¶m);
|
||||
childTaskCB->basePrio = runTask->basePrio;
|
||||
if (childTaskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
childTaskCB->taskStatus &= ~OS_TASK_STATUS_RUNNING;
|
||||
} else {
|
||||
@@ -1872,7 +1882,6 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
|
||||
UINT32 ret;
|
||||
ProcessGroup *group = NULL;
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(child->threadGroupID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (run->group->groupID == OS_USER_PRIVILEGE_PROCESS_GROUP) {
|
||||
ret = OsSetProcessGroupIDUnsafe(child->processID, child->processID, &group);
|
||||
@@ -1883,7 +1892,7 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
|
||||
}
|
||||
|
||||
child->processStatus &= ~OS_PROCESS_STATUS_INIT;
|
||||
taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
|
||||
OsSchedTaskEnQueue(OS_TCB_FROM_TID(child->threadGroupID));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, group);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -43,9 +43,6 @@
|
||||
#error "swtmr maxnum cannot be zero"
|
||||
#endif /* LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0 */
|
||||
|
||||
STATIC INLINE VOID SwtmrDelete(SWTMR_CTRL_S *swtmr);
|
||||
STATIC INLINE UINT64 SwtmrToStart(SWTMR_CTRL_S *swtmr, UINT16 cpuid);
|
||||
|
||||
LITE_OS_SEC_BSS SWTMR_CTRL_S *g_swtmrCBArray = NULL; /* First address in Timer memory space */
|
||||
LITE_OS_SEC_BSS UINT8 *g_swtmrHandlerPool = NULL; /* Pool of Swtmr Handler */
|
||||
LITE_OS_SEC_BSS LOS_DL_LIST g_swtmrFreeList; /* Free list of Software Timer */
|
||||
@@ -55,232 +52,22 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_swtmrSpin);
|
||||
#define SWTMR_LOCK(state) LOS_SpinLockSave(&g_swtmrSpin, &(state))
|
||||
#define SWTMR_UNLOCK(state) LOS_SpinUnlockRestore(&g_swtmrSpin, (state))
|
||||
|
||||
typedef struct {
|
||||
SortLinkAttribute swtmrSortLink;
|
||||
LosTaskCB *swtmrTask; /* software timer task id */
|
||||
LOS_DL_LIST swtmrHandlerQueue; /* software timer timeout queue id */
|
||||
} SwtmrRunqueue;
|
||||
|
||||
STATIC SwtmrRunqueue g_swtmrRunqueue[LOSCFG_KERNEL_CORE_NUM];
|
||||
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
#define OS_SWTMR_PERIOD_TO_CYCLE(period) (((UINT64)(period) * OS_NS_PER_TICK) / OS_NS_PER_CYCLE)
|
||||
STATIC SwtmrDebugData *g_swtmrDebugData = NULL;
|
||||
|
||||
BOOL OsSwtmrDebugDataUsed(UINT32 swtmrID)
|
||||
{
|
||||
if (swtmrID > LOSCFG_BASE_CORE_SWTMR_LIMIT) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return g_swtmrDebugData[swtmrID].swtmrUsed;
|
||||
}
|
||||
|
||||
UINT32 OsSwtmrDebugDataGet(UINT32 swtmrID, SwtmrDebugData *data, UINT32 len, UINT8 *mode)
|
||||
{
|
||||
UINT32 intSave;
|
||||
errno_t ret;
|
||||
|
||||
if ((swtmrID > LOSCFG_BASE_CORE_SWTMR_LIMIT) || (data == NULL) ||
|
||||
(mode == NULL) || (len < sizeof(SwtmrDebugData))) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
SWTMR_CTRL_S *swtmr = &g_swtmrCBArray[swtmrID];
|
||||
SWTMR_LOCK(intSave);
|
||||
ret = memcpy_s(data, len, &g_swtmrDebugData[swtmrID], sizeof(SwtmrDebugData));
|
||||
*mode = swtmr->ucMode;
|
||||
SWTMR_UNLOCK(intSave);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID SwtmrDebugDataInit(VOID)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
UINT32 size = sizeof(SwtmrDebugData) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
g_swtmrDebugData = (SwtmrDebugData *)LOS_MemAlloc(m_aucSysMem1, size);
|
||||
if (g_swtmrDebugData == NULL) {
|
||||
PRINT_ERR("SwtmrDebugDataInit malloc failed!\n");
|
||||
return;
|
||||
}
|
||||
(VOID)memset_s(g_swtmrDebugData, size, 0, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrDebugDataUpdate(SWTMR_CTRL_S *swtmr, UINT32 ticks, UINT32 times)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
SwtmrDebugData *data = &g_swtmrDebugData[swtmr->usTimerID];
|
||||
if (data->period != ticks) {
|
||||
(VOID)memset_s(&data->base, sizeof(SwtmrDebugBase), 0, sizeof(SwtmrDebugBase));
|
||||
data->period = ticks;
|
||||
}
|
||||
data->base.startTime = swtmr->startTime;
|
||||
data->base.times += times;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrDebugDataStart(SWTMR_CTRL_S *swtmr, UINT16 cpuid)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
SwtmrDebugData *data = &g_swtmrDebugData[swtmr->usTimerID];
|
||||
data->swtmrUsed = TRUE;
|
||||
data->handler = swtmr->pfnHandler;
|
||||
data->cpuid = cpuid;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrDebugWaitTimeCalculate(UINT32 swtmrID, SwtmrHandlerItemPtr swtmrHandler)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
SwtmrDebugBase *data = &g_swtmrDebugData[swtmrID].base;
|
||||
swtmrHandler->swtmrID = swtmrID;
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 waitTime = currTime - data->startTime;
|
||||
data->waitTime += waitTime;
|
||||
if (waitTime > data->waitTimeMax) {
|
||||
data->waitTimeMax = waitTime;
|
||||
}
|
||||
data->readyStartTime = currTime;
|
||||
data->waitCount++;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrDebugDataClear(UINT32 swtmrID)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
(VOID)memset_s(&g_swtmrDebugData[swtmrID], sizeof(SwtmrDebugData), 0, sizeof(SwtmrDebugData));
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrHandler(SwtmrHandlerItemPtr swtmrHandle)
|
||||
{
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
UINT32 intSave;
|
||||
SwtmrDebugBase *data = &g_swtmrDebugData[swtmrHandle->swtmrID].base;
|
||||
UINT64 startTime = OsGetCurrSchedTimeCycle();
|
||||
#endif
|
||||
swtmrHandle->handler(swtmrHandle->arg);
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
UINT64 runTime = OsGetCurrSchedTimeCycle() - startTime;
|
||||
SWTMR_LOCK(intSave);
|
||||
data->runTime += runTime;
|
||||
if (runTime > data->runTimeMax) {
|
||||
data->runTimeMax = runTime;
|
||||
}
|
||||
runTime = startTime - data->readyStartTime;
|
||||
data->readyTime += runTime;
|
||||
if (runTime > data->readyTimeMax) {
|
||||
data->readyTimeMax = runTime;
|
||||
}
|
||||
data->runCount++;
|
||||
SWTMR_UNLOCK(intSave);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrWake(SwtmrRunqueue *srq, UINT64 startTime, SortLinkList *sortList)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
SwtmrHandlerItemPtr swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
|
||||
LOS_ASSERT(swtmrHandler != NULL);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
|
||||
|
||||
SWTMR_LOCK(intSave);
|
||||
swtmrHandler->handler = swtmr->pfnHandler;
|
||||
swtmrHandler->arg = swtmr->uwArg;
|
||||
LOS_ListTailInsert(&srq->swtmrHandlerQueue, &swtmrHandler->node);
|
||||
SwtmrDebugWaitTimeCalculate(swtmr->usTimerID, swtmrHandler);
|
||||
|
||||
if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
|
||||
SwtmrDelete(swtmr);
|
||||
|
||||
if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
} else {
|
||||
swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
}
|
||||
} else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
} else {
|
||||
swtmr->uwOverrun++;
|
||||
swtmr->startTime = startTime;
|
||||
(VOID)SwtmrToStart(swtmr, ArchCurrCpuid());
|
||||
}
|
||||
|
||||
SWTMR_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ScanSwtmrTimeList(SwtmrRunqueue *srq)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SortLinkAttribute *swtmrSortLink = &srq->swtmrSortLink;
|
||||
LOS_DL_LIST *listObject = &swtmrSortLink->sortLink;
|
||||
|
||||
/*
|
||||
* it needs to be carefully coped with, since the swtmr is in specific sortlink
|
||||
* while other cores still has the chance to process it, like stop the timer.
|
||||
*/
|
||||
LOS_SpinLockSave(&swtmrSortLink->spinLock, &intSave);
|
||||
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
LOS_SpinUnlockRestore(&swtmrSortLink->spinLock, intSave);
|
||||
return;
|
||||
}
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
while (sortList->responseTime <= currTime) {
|
||||
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
UINT64 startTime = GET_SORTLIST_VALUE(sortList);
|
||||
OsDeleteNodeSortLink(swtmrSortLink, sortList);
|
||||
LOS_SpinUnlockRestore(&swtmrSortLink->spinLock, intSave);
|
||||
|
||||
SwtmrWake(srq, startTime, sortList);
|
||||
|
||||
LOS_SpinLockSave(&swtmrSortLink->spinLock, &intSave);
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
break;
|
||||
}
|
||||
|
||||
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
}
|
||||
|
||||
LOS_SpinUnlockRestore(&swtmrSortLink->spinLock, intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID SwtmrTask(VOID)
|
||||
{
|
||||
SwtmrHandlerItemPtr swtmrHandlePtr = NULL;
|
||||
SwtmrHandlerItem swtmrHandle;
|
||||
UINT32 intSave;
|
||||
UINT64 waitTime;
|
||||
UINT32 ret, swtmrHandlerQueue;
|
||||
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[ArchCurrCpuid()];
|
||||
LOS_DL_LIST *head = &srq->swtmrHandlerQueue;
|
||||
swtmrHandlerQueue = OsSchedSwtmrHandlerQueueGet();
|
||||
for (;;) {
|
||||
waitTime = OsSortLinkGetNextExpireTime(OsGetCurrSchedTimeCycle(), &srq->swtmrSortLink);
|
||||
if (waitTime != 0) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
srq->swtmrTask->ops->delay(srq->swtmrTask, waitTime);
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, srq->swtmrTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
ScanSwtmrTimeList(srq);
|
||||
|
||||
while (!LOS_ListEmpty(head)) {
|
||||
SwtmrHandlerItemPtr swtmrHandlePtr = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(head), SwtmrHandlerItem, node);
|
||||
LOS_ListDelete(&swtmrHandlePtr->node);
|
||||
|
||||
(VOID)memcpy_s(&swtmrHandle, sizeof(SwtmrHandlerItem), swtmrHandlePtr, sizeof(SwtmrHandlerItem));
|
||||
ret = LOS_QueueRead(swtmrHandlerQueue, &swtmrHandlePtr, sizeof(CHAR *), LOS_WAIT_FOREVER);
|
||||
if ((ret == LOS_OK) && (swtmrHandlePtr != NULL)) {
|
||||
swtmrHandle.handler = swtmrHandlePtr->handler;
|
||||
swtmrHandle.arg = swtmrHandlePtr->arg;
|
||||
(VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandlePtr);
|
||||
SwtmrHandler(&swtmrHandle);
|
||||
if (swtmrHandle.handler != NULL) {
|
||||
swtmrHandle.handler(swtmrHandle.arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,11 +94,6 @@ STATIC UINT32 SwtmrTaskCreate(UINT16 cpuid, UINT32 *swtmrTaskID)
|
||||
return ret;
|
||||
}
|
||||
|
||||
UINT32 OsSwtmrTaskIDGetByCpuid(UINT16 cpuid)
|
||||
{
|
||||
return g_swtmrRunqueue[cpuid].swtmrTask->taskID;
|
||||
}
|
||||
|
||||
BOOL OsIsSwtmrTask(const LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskEntry == (TSK_ENTRY_FUNC)SwtmrTask) {
|
||||
@@ -329,58 +111,51 @@ LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINT32 processID)
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 SwtmrBaseInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = sizeof(SWTMR_CTRL_S) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
SWTMR_CTRL_S *swtmr = (SWTMR_CTRL_S *)LOS_MemAlloc(m_aucSysMem0, size); /* system resident resource */
|
||||
if (swtmr == NULL) {
|
||||
return LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
}
|
||||
|
||||
(VOID)memset_s(swtmr, size, 0, size);
|
||||
g_swtmrCBArray = swtmr;
|
||||
LOS_ListInit(&g_swtmrFreeList);
|
||||
for (UINT16 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
|
||||
swtmr->usTimerID = index;
|
||||
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->stSortList.sortLinkNode);
|
||||
}
|
||||
|
||||
size = LOS_MEMBOX_SIZE(sizeof(SwtmrHandlerItem), OS_SWTMR_HANDLE_QUEUE_SIZE);
|
||||
g_swtmrHandlerPool = (UINT8 *)LOS_MemAlloc(m_aucSysMem1, size); /* system resident resource */
|
||||
if (g_swtmrHandlerPool == NULL) {
|
||||
return LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
}
|
||||
|
||||
ret = LOS_MemboxInit(g_swtmrHandlerPool, size, sizeof(SwtmrHandlerItem));
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM;
|
||||
}
|
||||
|
||||
for (UINT16 index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[index];
|
||||
/* The linked list of all cores must be initialized at core 0 startup for load balancing */
|
||||
OsSortLinkInit(&srq->swtmrSortLink);
|
||||
LOS_ListInit(&srq->swtmrHandlerQueue);
|
||||
srq->swtmrTask = NULL;
|
||||
}
|
||||
|
||||
SwtmrDebugDataInit();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT16 index;
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 swtmrHandlePoolSize;
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
UINT32 swtmrTaskID;
|
||||
UINT32 swtmrTaskID, swtmrHandlerQueue;
|
||||
|
||||
if (cpuid == 0) {
|
||||
ret = SwtmrBaseInit();
|
||||
if (ret != LOS_OK) {
|
||||
size = sizeof(SWTMR_CTRL_S) * LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
swtmr = (SWTMR_CTRL_S *)LOS_MemAlloc(m_aucSysMem0, size); /* system resident resource */
|
||||
if (swtmr == NULL) {
|
||||
ret = LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
(VOID)memset_s(swtmr, size, 0, size);
|
||||
g_swtmrCBArray = swtmr;
|
||||
LOS_ListInit(&g_swtmrFreeList);
|
||||
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
|
||||
swtmr->usTimerID = index;
|
||||
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->stSortList.sortLinkNode);
|
||||
}
|
||||
|
||||
swtmrHandlePoolSize = LOS_MEMBOX_SIZE(sizeof(SwtmrHandlerItem), OS_SWTMR_HANDLE_QUEUE_SIZE);
|
||||
|
||||
g_swtmrHandlerPool = (UINT8 *)LOS_MemAlloc(m_aucSysMem1, swtmrHandlePoolSize); /* system resident resource */
|
||||
if (g_swtmrHandlerPool == NULL) {
|
||||
ret = LOS_ERRNO_SWTMR_NO_MEMORY;
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
ret = LOS_MemboxInit(g_swtmrHandlerPool, swtmrHandlePoolSize, sizeof(SwtmrHandlerItem));
|
||||
if (ret != LOS_OK) {
|
||||
ret = LOS_ERRNO_SWTMR_HANDLER_POOL_NO_MEM;
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ret = LOS_QueueCreate(NULL, OS_SWTMR_HANDLE_QUEUE_SIZE, &swtmrHandlerQueue, 0, sizeof(CHAR *));
|
||||
if (ret != LOS_OK) {
|
||||
ret = LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED;
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
ret = SwtmrTaskCreate(cpuid, &swtmrTaskID);
|
||||
@@ -389,88 +164,25 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
srq->swtmrTask = OsGetTaskCB(swtmrTaskID);
|
||||
OsSchedRunQueSwtmrInit(swtmrTaskID, swtmrHandlerQueue);
|
||||
return LOS_OK;
|
||||
|
||||
ERROR:
|
||||
PRINT_ERR("OsSwtmrInit error! ret = %u\n", ret);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, g_swtmrCBArray);
|
||||
g_swtmrCBArray = NULL;
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, g_swtmrHandlerPool);
|
||||
g_swtmrHandlerPool = NULL;
|
||||
PRINT_ERR("OsSwtmrInit error! ret = %u\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
STATIC INLINE VOID FindIdleSwtmrRunqueue(UINT16 *idleCpuid)
|
||||
{
|
||||
SwtmrRunqueue *idleRq = &g_swtmrRunqueue[0];
|
||||
UINT32 nodeNum = OsGetSortLinkNodeNum(&idleRq->swtmrSortLink);
|
||||
UINT16 cpuid = 1;
|
||||
do {
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
UINT32 temp = OsGetSortLinkNodeNum(&srq->swtmrSortLink);
|
||||
if (nodeNum > temp) {
|
||||
*idleCpuid = cpuid;
|
||||
nodeNum = temp;
|
||||
}
|
||||
cpuid++;
|
||||
} while (cpuid < LOSCFG_KERNEL_CORE_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC INLINE VOID AddSwtmr2TimeList(SortLinkList *node, UINT64 responseTime, UINT16 cpuid)
|
||||
{
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
OsAdd2SortLink(&srq->swtmrSortLink, node, responseTime, cpuid);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID DeSwtmrFromTimeList(SortLinkList *node)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT16 cpuid = OsGetSortLinkNodeCpuid(node);
|
||||
#else
|
||||
UINT16 cpuid = 0;
|
||||
#endif
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
OsDeleteFromSortLink(&srq->swtmrSortLink, node);
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID SwtmrAdjustCheck(UINT16 cpuid, UINT64 responseTime)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if ((srq->swtmrTask == NULL) || !OsTaskIsBlocked(srq->swtmrTask)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
if (responseTime >= GET_SORTLIST_VALUE(&srq->swtmrTask->sortList)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = OsSchedTimeoutQueueAdjust(srq->swtmrTask, responseTime);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret != LOS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cpuid == ArchCurrCpuid()) {
|
||||
OsSchedExpireTimeUpdate();
|
||||
} else {
|
||||
LOS_MpSchedule(CPUID_TO_AFFI_MASK(cpuid));
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT64 SwtmrToStart(SWTMR_CTRL_S *swtmr, UINT16 cpuid)
|
||||
/*
|
||||
* Description: Start Software Timer
|
||||
* Input : swtmr --- Need to start software timer
|
||||
*/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
UINT32 ticks;
|
||||
UINT32 times = 0;
|
||||
|
||||
if ((swtmr->uwOverrun == 0) && ((swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ||
|
||||
(swtmr->ucMode == LOS_SWTMR_MODE_OPP) ||
|
||||
@@ -481,122 +193,75 @@ STATIC UINT64 SwtmrToStart(SWTMR_CTRL_S *swtmr, UINT16 cpuid)
|
||||
}
|
||||
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
|
||||
|
||||
UINT64 period = (UINT64)ticks * OS_CYCLE_PER_TICK;
|
||||
UINT64 responseTime = swtmr->startTime + period;
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
if (responseTime < currTime) {
|
||||
times = (UINT32)((currTime - swtmr->startTime) / period);
|
||||
swtmr->startTime += times * period;
|
||||
responseTime = swtmr->startTime + period;
|
||||
PRINT_WARN("Swtmr already timeout! SwtmrID: %u\n", swtmr->usTimerID);
|
||||
}
|
||||
|
||||
AddSwtmr2TimeList(&swtmr->stSortList, responseTime, cpuid);
|
||||
SwtmrDebugDataUpdate(swtmr, ticks, times);
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Start Software Timer
|
||||
* Input : swtmr --- Need to start software timer
|
||||
*/
|
||||
STATIC INLINE VOID SwtmrStart(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
UINT64 responseTime;
|
||||
UINT16 idleCpu = 0;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
FindIdleSwtmrRunqueue(&idleCpu);
|
||||
#endif
|
||||
swtmr->startTime = OsGetCurrSchedTimeCycle();
|
||||
responseTime = SwtmrToStart(swtmr, idleCpu);
|
||||
|
||||
SwtmrDebugDataStart(swtmr, idleCpu);
|
||||
|
||||
SwtmrAdjustCheck(idleCpu, responseTime);
|
||||
OsSchedAddSwtmr2TimeList(&swtmr->stSortList, swtmr->startTime, ticks);
|
||||
OsSchedUpdateExpireTime();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Delete Software Timer
|
||||
* Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL.
|
||||
*/
|
||||
STATIC INLINE VOID SwtmrDelete(SWTMR_CTRL_S *swtmr)
|
||||
STATIC INLINE VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
/* insert to free list */
|
||||
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->stSortList.sortLinkNode);
|
||||
swtmr->ucState = OS_SWTMR_STATUS_UNUSED;
|
||||
swtmr->uwOwnerPid = 0;
|
||||
|
||||
SwtmrDebugDataClear(swtmr->usTimerID);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SwtmrRestart(UINT64 startTime, SortLinkList *sortList, UINT16 cpuid)
|
||||
VOID OsSwtmrWake(SchedRunQue *rq, UINT64 startTime, SortLinkList *sortList)
|
||||
{
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_SWTMR_EXPIRED, swtmr);
|
||||
LOS_SpinLock(&g_swtmrSpin);
|
||||
SwtmrHandlerItemPtr swtmrHandler = (SwtmrHandlerItemPtr)LOS_MemboxAlloc(g_swtmrHandlerPool);
|
||||
if (swtmrHandler != NULL) {
|
||||
swtmrHandler->handler = swtmr->pfnHandler;
|
||||
swtmrHandler->arg = swtmr->uwArg;
|
||||
|
||||
if (LOS_QueueWrite(rq->swtmrHandlerQueue, swtmrHandler, sizeof(CHAR *), LOS_NO_WAIT)) {
|
||||
(VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandler);
|
||||
}
|
||||
}
|
||||
|
||||
if (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) {
|
||||
OsSwtmrDelete(swtmr);
|
||||
|
||||
if (swtmr->usTimerID < (OS_SWTMR_MAX_TIMERID - LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
swtmr->usTimerID += LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
} else {
|
||||
swtmr->usTimerID %= LOSCFG_BASE_CORE_SWTMR_LIMIT;
|
||||
}
|
||||
} else if (swtmr->ucMode == LOS_SWTMR_MODE_NO_SELFDELETE) {
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
} else {
|
||||
swtmr->uwOverrun++;
|
||||
swtmr->startTime = startTime;
|
||||
OsSwtmrStart(swtmr);
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&g_swtmrSpin);
|
||||
}
|
||||
|
||||
VOID OsSwtmrRestart(UINT64 startTime, SortLinkList *sortList)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
SWTMR_LOCK(intSave);
|
||||
swtmr->startTime = startTime;
|
||||
(VOID)SwtmrToStart(swtmr, cpuid);
|
||||
OsSwtmrStart(swtmr);
|
||||
SWTMR_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID OsSwtmrResponseTimeReset(UINT64 startTime)
|
||||
{
|
||||
UINT16 cpuid = ArchCurrCpuid();
|
||||
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[cpuid].swtmrSortLink;
|
||||
LOS_DL_LIST *listHead = &swtmrSortLink->sortLink;
|
||||
LOS_DL_LIST *listNext = listHead->pstNext;
|
||||
|
||||
LOS_SpinLock(&swtmrSortLink->spinLock);
|
||||
while (listNext != listHead) {
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
|
||||
OsDeleteNodeSortLink(swtmrSortLink, sortList);
|
||||
LOS_SpinUnlock(&swtmrSortLink->spinLock);
|
||||
|
||||
SwtmrRestart(startTime, sortList, cpuid);
|
||||
|
||||
LOS_SpinLock(&swtmrSortLink->spinLock);
|
||||
listNext = listNext->pstNext;
|
||||
}
|
||||
LOS_SpinUnlock(&swtmrSortLink->spinLock);
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL SwtmrRunqueueFind(SortLinkAttribute *swtmrSortLink, SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
|
||||
{
|
||||
LOS_DL_LIST *listObject = &swtmrSortLink->sortLink;
|
||||
LOS_DL_LIST *list = listObject->pstNext;
|
||||
|
||||
LOS_SpinLock(&swtmrSortLink->spinLock);
|
||||
while (list != listObject) {
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
|
||||
if (checkFunc((UINTPTR)listSorted, arg)) {
|
||||
LOS_SpinUnlock(&swtmrSortLink->spinLock);
|
||||
return TRUE;
|
||||
}
|
||||
list = list->pstNext;
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&swtmrSortLink->spinLock);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC BOOL SwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
|
||||
{
|
||||
for (UINT16 cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
|
||||
SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[ArchCurrCpuid()].swtmrSortLink;
|
||||
if (SwtmrRunqueueFind(swtmrSortLink, checkFunc, arg)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
SWTMR_LOCK(intSave);
|
||||
BOOL find = SwtmrTimeListFind(checkFunc, arg);
|
||||
BOOL find = OsSchedSwtmrTimeListFind(checkFunc, arg);
|
||||
SWTMR_UNLOCK(intSave);
|
||||
return find;
|
||||
}
|
||||
@@ -608,8 +273,7 @@ BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[ArchCurrCpuid()];
|
||||
UINT64 time = (OsSortLinkGetNextExpireTime(currTime, &srq->swtmrSortLink) / OS_CYCLE_PER_TICK);
|
||||
UINT64 time = (OsSortLinkGetNextExpireTime(currTime, &OsSchedRunQue()->swtmrSortLink) / OS_CYCLE_PER_TICK);
|
||||
if (time > OS_INVALID_VALUE) {
|
||||
time = OS_INVALID_VALUE;
|
||||
}
|
||||
@@ -620,12 +284,14 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
* Description: Stop of Software Timer interface
|
||||
* Input : swtmr --- the software timer control handler
|
||||
*/
|
||||
STATIC VOID SwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
OsSchedDeSwtmrFromTimeList(&swtmr->stSortList);
|
||||
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
swtmr->uwOverrun = 0;
|
||||
|
||||
DeSwtmrFromTimeList(&swtmr->stSortList);
|
||||
OsSchedUpdateExpireTime();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -723,10 +389,11 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
|
||||
* then start the swtmr again.
|
||||
*/
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
SwtmrStop(swtmr);
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall-through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
SwtmrStart(swtmr);
|
||||
swtmr->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSwtmrStart(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
@@ -766,7 +433,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
SwtmrStop(swtmr);
|
||||
OsSwtmrStop(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
@@ -844,10 +511,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
SwtmrStop(swtmr);
|
||||
OsSwtmrStop(swtmr);
|
||||
/* fall-through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
SwtmrDelete(swtmr);
|
||||
OsSwtmrDelete(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -90,23 +90,19 @@ VOID OsSetMainTask()
|
||||
{
|
||||
UINT32 i;
|
||||
CHAR *name = "osMain";
|
||||
SchedParam schedParam = { 0 };
|
||||
|
||||
schedParam.policy = LOS_SCHED_RR;
|
||||
schedParam.basePrio = OS_PROCESS_PRIORITY_HIGHEST;
|
||||
schedParam.priority = OS_TASK_PRIORITY_LOWEST;
|
||||
|
||||
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
|
||||
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
g_mainTask[i].taskID = LOSCFG_BASE_CORE_TSK_LIMIT;
|
||||
g_mainTask[i].processID = OS_KERNEL_PROCESS_GROUP;
|
||||
g_mainTask[i].basePrio = OS_TASK_PRIORITY_HIGHEST;
|
||||
g_mainTask[i].priority = OS_TASK_PRIORITY_LOWEST;
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
g_mainTask[i].lockDep.lockDepth = 0;
|
||||
g_mainTask[i].lockDep.waitLock = NULL;
|
||||
#endif
|
||||
(VOID)strncpy_s(g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, OS_TCB_NAME_LEN - 1);
|
||||
LOS_ListInit(&g_mainTask[i].lockList);
|
||||
(VOID)OsSchedParamInit(&g_mainTask[i], schedParam.policy, &schedParam, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +120,13 @@ VOID OsTaskInsertToRecycleList(LosTaskCB *taskCB)
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB)
|
||||
{
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
|
||||
if (!LOS_ListEmpty(&taskCB->joinList)) {
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
}
|
||||
}
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_EXIT;
|
||||
@@ -146,8 +144,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB)
|
||||
|
||||
if ((taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) && LOS_ListEmpty(&taskCB->joinList)) {
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_JOIN, taskCB->taskID, LOS_WAIT_FOREVER);
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
return runTask->ops->wait(runTask, &taskCB->joinList, LOS_WAIT_FOREVER);
|
||||
return OsSchedTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER, TRUE);
|
||||
}
|
||||
|
||||
return LOS_EINVAL;
|
||||
@@ -206,7 +203,7 @@ EXIT:
|
||||
|
||||
UINT32 OsGetIdleTaskId(VOID)
|
||||
{
|
||||
return OsSchedRunqueueIdleGet();
|
||||
return OsSchedGetRunQueIdle();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
||||
@@ -219,21 +216,18 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
||||
taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)OsIdleTask;
|
||||
taskInitParam.uwStackSize = LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE;
|
||||
taskInitParam.pcName = "Idle";
|
||||
taskInitParam.policy = LOS_SCHED_IDLE;
|
||||
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
|
||||
taskInitParam.processID = OsGetIdleProcessID();
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
|
||||
#endif
|
||||
ret = LOS_TaskCreateOnly(&idleTaskID, &taskInitParam);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
|
||||
idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
|
||||
OsSchedRunqueueIdleInit(idleTaskID);
|
||||
OsSchedRunQueIdleInit(idleTaskID);
|
||||
OsSchedSetIdleTaskSchedParam(idleTask);
|
||||
|
||||
return LOS_TaskResume(idleTaskID);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -375,11 +369,12 @@ STATIC VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
while (!LOS_ListEmpty(&g_taskRecycleList)) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecycleList));
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecycleList));
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -396,6 +391,8 @@ LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
LOS_ASSERT(!OS_TID_CHECK_INVALID(taskID));
|
||||
|
||||
/*
|
||||
@@ -406,7 +403,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
(VOID)LOS_IntUnLock();
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB->joinRetval = taskCB->taskEntry(taskCB->args[0], taskCB->args[1],
|
||||
taskCB->args[2], taskCB->args[3]); /* 2 & 3: just for args array index */
|
||||
if (!(taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) {
|
||||
@@ -466,8 +463,10 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stack
|
||||
*topStack = (VOID *)LOS_MemAllocAlign(pool, stackSize, LOSCFG_STACK_POINT_ALIGN_SIZE);
|
||||
}
|
||||
|
||||
STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *topStack,
|
||||
const TSK_INIT_PARAM_S *initParam)
|
||||
LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
||||
const VOID *stackPtr,
|
||||
const VOID *topStack,
|
||||
const TSK_INIT_PARAM_S *initParam)
|
||||
{
|
||||
taskCB->stackPointer = (VOID *)stackPtr;
|
||||
taskCB->args[0] = initParam->auwArgs[0]; /* 0~3: just for args array index */
|
||||
@@ -476,6 +475,7 @@ STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *
|
||||
taskCB->args[3] = initParam->auwArgs[3];
|
||||
taskCB->topOfStack = (UINTPTR)topStack;
|
||||
taskCB->stackSize = initParam->uwStackSize;
|
||||
taskCB->priority = initParam->usTaskPrio;
|
||||
taskCB->taskEntry = initParam->pfnTaskEntry;
|
||||
taskCB->signal = SIGNAL_NONE;
|
||||
|
||||
@@ -484,6 +484,7 @@ STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *
|
||||
taskCB->cpuAffiMask = (initParam->usCpuAffiMask) ?
|
||||
initParam->usCpuAffiMask : LOSCFG_KERNEL_CPU_MASK;
|
||||
#endif
|
||||
taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;
|
||||
taskCB->taskStatus = OS_TASK_STATUS_INIT;
|
||||
if (initParam->uwResved & LOS_TASK_ATTR_JOINABLE) {
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;
|
||||
@@ -499,13 +500,10 @@ STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 numCount;
|
||||
SchedParam schedParam = { 0 };
|
||||
UINT16 policy = (initParam->policy == LOS_SCHED_NORMAL) ? LOS_SCHED_RR : initParam->policy;
|
||||
|
||||
TaskCBBaseInit(taskCB, stackPtr, topStack, initParam);
|
||||
OsTaskCBInitBase(taskCB, stackPtr, topStack, initParam);
|
||||
|
||||
schedParam.policy = policy;
|
||||
numCount = OsProcessAddNewTask(initParam->processID, taskCB, &schedParam);
|
||||
numCount = OsProcessAddNewTask(initParam->processID, taskCB);
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
taskCB->futex.index = OS_INVALID_VALUE;
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_USER_MODE) {
|
||||
@@ -516,11 +514,6 @@ STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = OsSchedParamInit(taskCB, policy, &schedParam, initParam);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (initParam->pcName != NULL) {
|
||||
ret = (UINT32)OsSetTaskName(taskCB, initParam->pcName, FALSE);
|
||||
if (ret == LOS_OK) {
|
||||
@@ -537,6 +530,7 @@ STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam,
|
||||
LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (LOS_ListEmpty(&g_losFreeTask)) {
|
||||
@@ -545,7 +539,7 @@ LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
LOS_ListDelete(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -556,6 +550,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
{
|
||||
UINT32 intSave, errRet;
|
||||
VOID *topStack = NULL;
|
||||
VOID *stackPtr = NULL;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
VOID *pool = NULL;
|
||||
|
||||
errRet = OsTaskCreateParamCheck(taskID, initParam, &pool);
|
||||
@@ -563,7 +559,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
return errRet;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OsGetFreeTaskCB();
|
||||
taskCB = OsGetFreeTaskCB();
|
||||
if (taskCB == NULL) {
|
||||
errRet = LOS_ERRNO_TSK_TCB_UNAVAILABLE;
|
||||
goto LOS_ERREND;
|
||||
@@ -580,7 +576,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
goto LOS_ERREND_REWIND_SYNC;
|
||||
}
|
||||
|
||||
VOID *stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
|
||||
stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
|
||||
errRet = OsTaskCBInit(taskCB, initParam, stackPtr, topStack);
|
||||
if (errRet != LOS_OK) {
|
||||
goto LOS_ERREND_TCB_INIT;
|
||||
@@ -634,7 +630,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *in
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(*taskID);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
|
||||
OsSchedTaskEnQueue(taskCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* in case created task not running on this core,
|
||||
@@ -651,13 +647,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 errRet;
|
||||
BOOL needSched = FALSE;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
/* clear pending signal */
|
||||
@@ -671,7 +667,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
OS_GOTO_ERREND();
|
||||
}
|
||||
|
||||
errRet = taskCB->ops->resume(taskCB, &needSched);
|
||||
BOOL needSched = OsSchedResume(taskCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -679,7 +675,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
LOS_Schedule();
|
||||
}
|
||||
|
||||
return errRet;
|
||||
return LOS_OK;
|
||||
|
||||
LOS_ERREND:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -727,7 +723,9 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN
|
||||
LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT32 errRet;
|
||||
UINT16 tempStatus = taskCB->taskStatus;
|
||||
UINT16 tempStatus;
|
||||
|
||||
tempStatus = taskCB->taskStatus;
|
||||
if (tempStatus & OS_TASK_STATUS_UNUSED) {
|
||||
return LOS_ERRNO_TSK_NOT_CREATED;
|
||||
}
|
||||
@@ -741,19 +739,21 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
|
||||
return errRet;
|
||||
}
|
||||
|
||||
return taskCB->ops->suspend(taskCB);
|
||||
OsSchedSuspend(taskCB);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 errRet;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
}
|
||||
@@ -842,11 +842,11 @@ LITE_OS_SEC_TEXT VOID OsInactiveTaskDelete(LosTaskCB *taskCB)
|
||||
|
||||
OsTaskReleaseHoldLock(taskCB);
|
||||
|
||||
taskCB->ops->exit(taskCB);
|
||||
OsSchedTaskExit(taskCB);
|
||||
if (taskStatus & OS_TASK_STATUS_PENDING) {
|
||||
LosMux *mux = (LosMux *)taskCB->taskMux;
|
||||
if (LOS_MuxIsValid(mux) == TRUE) {
|
||||
OsMuxBitmapRestore(mux, NULL, taskCB);
|
||||
OsMuxBitmapRestore(mux, taskCB, (LosTaskCB *)mux->owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,10 +872,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB == OsCurrTaskGet()) {
|
||||
if (!OsPreemptable()) {
|
||||
return LOS_ERRNO_TSK_DELETE_LOCKED;
|
||||
}
|
||||
|
||||
OsRunningTaskToExit(taskCB, OS_PRO_EXIT_OK);
|
||||
return LOS_NOK;
|
||||
}
|
||||
@@ -904,22 +900,20 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
|
||||
|
||||
LOS_ERREND:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if (ret == LOS_OK) {
|
||||
LOS_Schedule();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = NULL;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
PRINT_ERR("In interrupt not allow delay task!\n");
|
||||
return LOS_ERRNO_TSK_DELAY_IN_INT;
|
||||
}
|
||||
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
runTask = OsCurrTaskGet();
|
||||
if (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
OsBackTrace();
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
@@ -934,37 +928,39 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UINT32 ret = runTask->ops->delay(runTask, OS_SCHED_TICK_TO_CYCLE(tick));
|
||||
OsSchedDelay(runTask, tick);
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, runTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return ret;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SchedParam param = { 0 };
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT16 priority;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return (UINT16)OS_INVALID;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return (UINT16)OS_INVALID;
|
||||
}
|
||||
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
priority = taskCB->priority;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return param.priority;
|
||||
return priority;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SchedParam param = { 0 };
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
if (taskPrio > OS_TASK_PRIORITY_LOWEST) {
|
||||
return LOS_ERRNO_TSK_PRIOR_ERROR;
|
||||
@@ -974,7 +970,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
}
|
||||
@@ -985,15 +981,11 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
return LOS_ERRNO_TSK_NOT_CREATED;
|
||||
}
|
||||
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
|
||||
param.priority = taskPrio;
|
||||
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
BOOL isReady = OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, taskPrio);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
if (needSched && OS_SCHEDULER_ACTIVE) {
|
||||
if (isReady && OS_SCHEDULER_ACTIVE) {
|
||||
LOS_Schedule();
|
||||
}
|
||||
return LOS_OK;
|
||||
@@ -1023,7 +1015,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
/* reset timeslice of yielded task */
|
||||
runTask->ops->yield(runTask);
|
||||
OsSchedYield();
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1053,7 +1045,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo)
|
||||
{
|
||||
UINT32 intSave;
|
||||
SchedParam param = { 0 };
|
||||
LosTaskCB *taskCB = NULL;
|
||||
|
||||
if (taskInfo == NULL) {
|
||||
return LOS_ERRNO_TSK_PTR_NULL;
|
||||
@@ -1063,7 +1055,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1076,9 +1068,8 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
|
||||
taskInfo->uwSP = ArchSPGet();
|
||||
}
|
||||
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
taskInfo->usTaskStatus = taskCB->taskStatus;
|
||||
taskInfo->usTaskPrio = param.priority;
|
||||
taskInfo->usTaskPrio = taskCB->priority;
|
||||
taskInfo->uwStackSize = taskCB->stackSize;
|
||||
taskInfo->uwTopOfStack = taskCB->topOfStack;
|
||||
taskInfo->uwEventMask = taskCB->eventMask;
|
||||
@@ -1122,6 +1113,7 @@ LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMas
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
BOOL needSched = FALSE;
|
||||
UINT32 intSave;
|
||||
UINT16 currCpuMask;
|
||||
@@ -1134,7 +1126,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMa
|
||||
return LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1155,6 +1147,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define INVALID_CPU_AFFI_MASK 0
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT16 cpuAffiMask;
|
||||
UINT32 intSave;
|
||||
|
||||
@@ -1162,7 +1155,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
|
||||
return INVALID_CPU_AFFI_MASK;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1215,7 +1208,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
|
||||
} else if (runTask->signal & SIGNAL_AFFI) {
|
||||
runTask->signal &= ~SIGNAL_AFFI;
|
||||
|
||||
/* priority queue has updated, notify the target cpu */
|
||||
/* pri-queue has updated, notify the target cpu */
|
||||
LOS_MpSchedule((UINT32)runTask->cpuAffiMask);
|
||||
#endif
|
||||
}
|
||||
@@ -1354,22 +1347,21 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S
|
||||
LITE_OS_SEC_TEXT INT32 LOS_GetTaskScheduler(INT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
INT32 policy;
|
||||
SchedParam param = { 0 };
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return -LOS_EINVAL;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
policy = -LOS_EINVAL;
|
||||
OS_GOTO_ERREND();
|
||||
}
|
||||
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
policy = (INT32)param.policy;
|
||||
policy = taskCB->policy;
|
||||
|
||||
LOS_ERREND:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1378,8 +1370,8 @@ LOS_ERREND:
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
|
||||
{
|
||||
SchedParam param = { 0 };
|
||||
UINT32 intSave;
|
||||
BOOL needSched = FALSE;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return LOS_ESRCH;
|
||||
@@ -1393,21 +1385,8 @@ LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_EPERM;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
param.policy = policy;
|
||||
param.priority = priority;
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
needSched = OsSchedModifyTaskSchedParam(OS_TCB_FROM_TID(taskID), policy, priority);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -1432,15 +1411,9 @@ STATIC UINT32 OsTaskJoinCheck(UINT32 taskID)
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_EPERM;
|
||||
}
|
||||
|
||||
if (taskCB == OsCurrTaskGet()) {
|
||||
if (taskID == OsCurrTaskGet()->taskID) {
|
||||
return LOS_EDEADLK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -1448,6 +1421,7 @@ UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 errRet;
|
||||
|
||||
errRet = OsTaskJoinCheck(taskID);
|
||||
@@ -1455,7 +1429,7 @@ UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
|
||||
return errRet;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1488,6 +1462,7 @@ UINT32 LOS_TaskDetach(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 errRet;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
@@ -1498,7 +1473,7 @@ UINT32 LOS_TaskDetach(UINT32 taskID)
|
||||
return LOS_EINTR;
|
||||
}
|
||||
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
|
||||
#define OS_MUX_MAGIC 0xEBCFDEA0
|
||||
|
||||
extern VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask);
|
||||
extern VOID OsMuxBitmapRestore(const LosMux *mutex, const LosTaskCB *taskCB, LosTaskCB *owner);
|
||||
extern UINT32 OsMuxLockUnsafe(LosMux *mutex, UINT32 timeout);
|
||||
extern UINT32 OsMuxTrylockUnsafe(LosMux *mutex, UINT32 timeout);
|
||||
extern UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -295,6 +295,11 @@ STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
|
||||
return (processCB->processMode == OS_USER_MODE);
|
||||
}
|
||||
|
||||
#define LOS_SCHED_NORMAL 0U
|
||||
#define LOS_SCHED_FIFO 1U
|
||||
#define LOS_SCHED_RR 2U
|
||||
#define LOS_SCHED_IDLE 3U
|
||||
|
||||
#define LOS_PRIO_PROCESS 0U
|
||||
#define LOS_PRIO_PGRP 1U
|
||||
#define LOS_PRIO_USER 2U
|
||||
@@ -483,7 +488,7 @@ extern UINTPTR OsGetSigHandler(VOID);
|
||||
extern VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID);
|
||||
extern INT32 OsSendSignalToProcessGroup(INT32 pid, siginfo_t *info, INT32 permission);
|
||||
extern INT32 OsSendSignalToAllProcess(siginfo_t *info, INT32 permission);
|
||||
extern UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param);
|
||||
extern UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB);
|
||||
extern VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB);
|
||||
extern VOID OsProcessThreadGroupDestroy(VOID);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -41,7 +41,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_RWLOCK_MAGIC 0xEFDCAU
|
||||
#define OS_RWLOCK_MAGIC 0xBEFDCAU
|
||||
|
||||
enum RwlockMode {
|
||||
RWLOCK_NONE_MODE,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -37,13 +37,10 @@
|
||||
#include "los_hwi.h"
|
||||
#include "hal_timer.h"
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#include "los_statistics_pri.h"
|
||||
#include "los_stat_pri.h"
|
||||
#endif
|
||||
#include "los_stackinfo_pri.h"
|
||||
#include "los_futex_pri.h"
|
||||
#ifdef LOSCFG_KERNEL_PM
|
||||
#include "los_pm_pri.h"
|
||||
#endif
|
||||
#include "los_signal.h"
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#include "los_cpup_pri.h"
|
||||
@@ -51,7 +48,6 @@
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
#include "hm_liteipc.h"
|
||||
#endif
|
||||
#include "los_mp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -59,17 +55,14 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_SCHED_MINI_PERIOD (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
|
||||
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
|
||||
#define OS_SCHED_MAX_RESPONSE_TIME OS_SORT_LINK_INVALID_TIME
|
||||
#define OS_SCHED_TICK_TO_CYCLE(ticks) ((UINT64)ticks * OS_CYCLE_PER_TICK)
|
||||
#define AFFI_MASK_TO_CPUID(mask) ((UINT16)((mask) - 1))
|
||||
#define OS_SCHED_MINI_PERIOD (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND_MINI)
|
||||
#define OS_TICK_RESPONSE_PRECISION (UINT32)((OS_SCHED_MINI_PERIOD * 75) / 100)
|
||||
#define OS_SCHED_MAX_RESPONSE_TIME (UINT64)(((UINT64)-1) - 1U)
|
||||
|
||||
extern UINT32 g_taskScheduled;
|
||||
#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
|
||||
#define OS_SCHEDULER_ALL_ACTIVE (g_taskScheduled == LOSCFG_KERNEL_CPU_MASK)
|
||||
|
||||
typedef struct TagTaskCB LosTaskCB;
|
||||
typedef BOOL (*SCHED_TL_FIND_FUNC)(UINTPTR, UINTPTR);
|
||||
|
||||
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
|
||||
@@ -83,65 +76,53 @@ typedef enum {
|
||||
INT_PEND_TICK = 0x2, /* pending tick */
|
||||
} SchedFlag;
|
||||
|
||||
#define OS_PRIORITY_QUEUE_NUM 32
|
||||
typedef struct {
|
||||
LOS_DL_LIST priQueList[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 readyTasks[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 queueBitmap;
|
||||
} HPFQueue;
|
||||
SortLinkAttribute taskSortLink; /* task sort link */
|
||||
SortLinkAttribute swtmrSortLink; /* swtmr sort link */
|
||||
UINT64 responseTime; /* Response time for current CPU tick interrupts */
|
||||
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
|
||||
UINT32 idleTaskID; /* idle task id */
|
||||
UINT32 taskLockCnt; /* task lock flag */
|
||||
UINT32 swtmrTaskID; /* software timer task id */
|
||||
UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
|
||||
UINT32 schedFlag; /* pending scheduler flag */
|
||||
} SchedRunQue;
|
||||
|
||||
typedef struct {
|
||||
HPFQueue queueList[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 queueBitmap;
|
||||
} HPFRunqueue;
|
||||
extern SchedRunQue g_schedRunQue[LOSCFG_KERNEL_CORE_NUM];
|
||||
|
||||
typedef struct {
|
||||
SortLinkAttribute timeoutQueue; /* task timeout queue */
|
||||
HPFRunqueue *hpfRunqueue;
|
||||
UINT64 responseTime; /* Response time for current CPU tick interrupts */
|
||||
UINT32 responseID; /* The response ID of the current CPU tick interrupt */
|
||||
UINT32 idleTaskID; /* idle task id */
|
||||
UINT32 taskLockCnt; /* task lock flag */
|
||||
UINT32 schedFlag; /* pending scheduler flag */
|
||||
} SchedRunqueue;
|
||||
|
||||
extern SchedRunqueue g_schedRunqueue[LOSCFG_KERNEL_CORE_NUM];
|
||||
|
||||
VOID OsSchedExpireTimeUpdate(VOID);
|
||||
|
||||
STATIC INLINE SchedRunqueue *OsSchedRunqueue(VOID)
|
||||
STATIC INLINE SchedRunQue *OsSchedRunQue(VOID)
|
||||
{
|
||||
return &g_schedRunqueue[ArchCurrCpuid()];
|
||||
return &g_schedRunQue[ArchCurrCpuid()];
|
||||
}
|
||||
|
||||
STATIC INLINE SchedRunqueue *OsSchedRunqueueByID(UINT16 id)
|
||||
STATIC INLINE SchedRunQue *OsSchedRunQueByID(UINT16 id)
|
||||
{
|
||||
return &g_schedRunqueue[id];
|
||||
return &g_schedRunQue[id];
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSchedLockCountGet(VOID)
|
||||
{
|
||||
return OsSchedRunqueue()->taskLockCnt;
|
||||
return OsSchedRunQue()->taskLockCnt;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedLockSet(UINT32 count)
|
||||
{
|
||||
OsSchedRunqueue()->taskLockCnt = count;
|
||||
OsSchedRunQue()->taskLockCnt = count;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedLock(VOID)
|
||||
{
|
||||
OsSchedRunqueue()->taskLockCnt++;
|
||||
OsSchedRunQue()->taskLockCnt++;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedUnlock(VOID)
|
||||
{
|
||||
OsSchedRunqueue()->taskLockCnt--;
|
||||
OsSchedRunQue()->taskLockCnt--;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsSchedUnlockResch(VOID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
if (rq->taskLockCnt > 0) {
|
||||
rq->taskLockCnt--;
|
||||
if ((rq->taskLockCnt == 0) && (rq->schedFlag & INT_PEND_RESCH) && OS_SCHEDULER_ACTIVE) {
|
||||
@@ -154,13 +135,13 @@ STATIC INLINE BOOL OsSchedUnlockResch(VOID)
|
||||
|
||||
STATIC INLINE BOOL OsSchedIsLock(VOID)
|
||||
{
|
||||
return (OsSchedRunqueue()->taskLockCnt != 0);
|
||||
return (OsSchedRunQue()->taskLockCnt != 0);
|
||||
}
|
||||
|
||||
/* Check if preemptible with counter flag */
|
||||
STATIC INLINE BOOL OsPreemptable(VOID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
/*
|
||||
* Unlike OsPreemptableInSched, the int may be not disabled when OsPreemptable
|
||||
* is called, needs manually disable interrupt, to prevent current task from
|
||||
@@ -179,7 +160,7 @@ STATIC INLINE BOOL OsPreemptable(VOID)
|
||||
STATIC INLINE BOOL OsPreemptableInSched(VOID)
|
||||
{
|
||||
BOOL preemptible = FALSE;
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
@@ -199,61 +180,85 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
|
||||
return preemptible;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSchedRunqueueIdleGet(VOID)
|
||||
STATIC INLINE UINT32 OsSchedGetRunQueIdle(VOID)
|
||||
{
|
||||
return OsSchedRunqueue()->idleTaskID;
|
||||
return OsSchedRunQue()->idleTaskID;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedRunqueuePendingSet(VOID)
|
||||
STATIC INLINE VOID OsSchedRunQuePendingSet(VOID)
|
||||
{
|
||||
OsSchedRunqueue()->schedFlag |= INT_PEND_RESCH;
|
||||
OsSchedRunQue()->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
|
||||
#define LOS_SCHED_NORMAL 0U
|
||||
#define LOS_SCHED_FIFO 1U
|
||||
#define LOS_SCHED_RR 2U
|
||||
#define LOS_SCHED_IDLE 3U
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
STATIC INLINE VOID FindIdleRunQue(UINT16 *idleCpuID)
|
||||
{
|
||||
SchedRunQue *idleRq = OsSchedRunQueByID(0);
|
||||
UINT32 nodeNum = OsGetSortLinkNodeNum(&idleRq->taskSortLink) + OsGetSortLinkNodeNum(&idleRq->swtmrSortLink);
|
||||
UINT16 cpuID = 1;
|
||||
do {
|
||||
SchedRunQue *rq = OsSchedRunQueByID(cpuID);
|
||||
UINT32 temp = OsGetSortLinkNodeNum(&rq->taskSortLink) + OsGetSortLinkNodeNum(&rq->swtmrSortLink);
|
||||
if (nodeNum > temp) {
|
||||
*idleCpuID = cpuID;
|
||||
nodeNum = temp;
|
||||
}
|
||||
cpuID++;
|
||||
} while (cpuID < LOSCFG_KERNEL_CORE_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
UINT16 policy;
|
||||
UINT16 basePrio;
|
||||
UINT16 priority;
|
||||
UINT32 timeSlice;
|
||||
} SchedParam;
|
||||
STATIC INLINE VOID OsSchedAddTask2TimeList(SortLinkList *node, UINT64 startTime, UINT32 waitTicks)
|
||||
{
|
||||
UINT16 idleCpu = 0;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
FindIdleRunQue(&idleCpu);
|
||||
#endif
|
||||
SchedRunQue *rq = OsSchedRunQueByID(idleCpu);
|
||||
UINT64 responseTime = startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK;
|
||||
OsAdd2SortLink(&rq->taskSortLink, node, responseTime, idleCpu);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
UINT16 policy; /* This field must be present for all scheduling policies and must be the first in the structure */
|
||||
UINT16 basePrio;
|
||||
UINT16 priority;
|
||||
UINT32 initTimeSlice;
|
||||
UINT32 priBitmap; /**< Bitmap for recording the change of task priority, the priority can not be greater than 31 */
|
||||
} SchedHPF;
|
||||
STATIC INLINE UINT32 OsSchedSwtmrHandlerQueueGet(VOID)
|
||||
{
|
||||
return OsSchedRunQue()->swtmrHandlerQueue;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
SchedHPF hpf;
|
||||
} Policy;
|
||||
} SchedPolicy;
|
||||
STATIC INLINE VOID OsSchedDeTaskFromTimeList(SortLinkList *node)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SchedRunQue *rq = OsSchedRunQueByID(node->cpuid);
|
||||
#else
|
||||
SchedRunQue *rq = OsSchedRunQueByID(0);
|
||||
#endif
|
||||
OsDeleteFromSortLink(&rq->taskSortLink, node);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
VOID (*dequeue)(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
VOID (*enqueue)(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
VOID (*start)(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
VOID (*exit)(LosTaskCB *taskCB);
|
||||
UINT32 (*wait)(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout);
|
||||
VOID (*wake)(LosTaskCB *taskCB);
|
||||
BOOL (*schedParamModify)(LosTaskCB *taskCB, const SchedParam *param);
|
||||
UINT32 (*schedParamGet)(const LosTaskCB *taskCB, SchedParam *param);
|
||||
UINT32 (*delay)(LosTaskCB *taskCB, UINT64 waitTime);
|
||||
VOID (*yield)(LosTaskCB *taskCB);
|
||||
UINT32 (*suspend)(LosTaskCB *taskCB);
|
||||
UINT32 (*resume)(LosTaskCB *taskCB, BOOL *needSched);
|
||||
UINT64 (*deadlineGet)(const LosTaskCB *taskCB);
|
||||
VOID (*timeSliceUpdate)(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime);
|
||||
INT32 (*schedParamCompare)(const SchedPolicy *sp1, const SchedPolicy *sp2);
|
||||
VOID (*priorityInheritance)(LosTaskCB *owner, const SchedParam *param);
|
||||
VOID (*priorityRestore)(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param);
|
||||
} SchedOps;
|
||||
STATIC INLINE VOID OsSchedAddSwtmr2TimeList(SortLinkList *node, UINT64 startTime, UINT32 waitTicks)
|
||||
{
|
||||
UINT16 idleCpu = 0;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
FindIdleRunQue(&idleCpu);
|
||||
#endif
|
||||
SchedRunQue *rq = OsSchedRunQueByID(idleCpu);
|
||||
UINT64 responseTime = startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK;
|
||||
OsAdd2SortLink(&rq->swtmrSortLink, node, responseTime, idleCpu);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedDeSwtmrFromTimeList(SortLinkList *node)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SchedRunQue *rq = OsSchedRunQueByID(node->cpuid);
|
||||
#else
|
||||
SchedRunQue *rq = OsSchedRunQueByID(0);
|
||||
#endif
|
||||
OsDeleteFromSortLink(&rq->swtmrSortLink, node);
|
||||
}
|
||||
|
||||
VOID OsSchedRunQueIdleInit(UINT32 idleTaskID);
|
||||
VOID OsSchedRunQueSwtmrInit(UINT32 swtmrTaskID, UINT32 swtmrQueue);
|
||||
VOID OsSchedRunQueInit(VOID);
|
||||
BOOL OsSchedSwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
|
||||
|
||||
/**
|
||||
* @ingroup los_sched
|
||||
@@ -343,31 +348,23 @@ typedef struct {
|
||||
*/
|
||||
#define OS_TASK_STATUS_EXIT 0x0100U
|
||||
|
||||
#define OS_TASK_STATUS_BLOCKED (OS_TASK_STATUS_INIT | OS_TASK_STATUS_PENDING | \
|
||||
OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The delayed operation of this task is frozen.
|
||||
*/
|
||||
#define OS_TASK_STATUS_FROZEN 0x0200U
|
||||
|
||||
#define OS_TCB_NAME_LEN 32
|
||||
|
||||
typedef struct TagTaskCB {
|
||||
typedef struct {
|
||||
VOID *stackPointer; /**< Task stack pointer */
|
||||
UINT16 taskStatus; /**< Task status */
|
||||
|
||||
/* The scheduling */
|
||||
UINT16 basePrio;
|
||||
UINT16 priority; /**< Task priority */
|
||||
UINT16 policy;
|
||||
UINT64 startTime; /**< The start time of each phase of task */
|
||||
UINT64 waitTime; /**< Task delay time, tick number */
|
||||
UINT64 irqStartTime; /**< Interrupt start time */
|
||||
UINT32 irqUsedTime; /**< Interrupt consumption time */
|
||||
UINT32 initTimeSlice; /**< Task init time slice */
|
||||
INT32 timeSlice; /**< Task remaining time slice */
|
||||
UINT32 waitTimes; /**< Task delay time, tick number */
|
||||
SortLinkList sortList; /**< Task sortlink node */
|
||||
const SchedOps *ops;
|
||||
SchedPolicy sp;
|
||||
|
||||
UINT32 stackSize; /**< Task stack size */
|
||||
UINTPTR topOfStack; /**< Task stack top */
|
||||
@@ -382,6 +379,8 @@ typedef struct TagTaskCB {
|
||||
LOS_DL_LIST threadList; /**< thread list */
|
||||
UINT32 eventMask; /**< Event mask */
|
||||
UINT32 eventMode; /**< Event mode */
|
||||
UINT32 priBitMap; /**< BitMap for recording the change of task priority,
|
||||
the priority can not be greater than 31 */
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
OsCpupBase taskCpup; /**< task cpu usage */
|
||||
#endif
|
||||
@@ -469,7 +468,7 @@ STATIC INLINE VOID OsCurrUserTaskSet(UINTPTR thread)
|
||||
ArchCurrUserTaskSet(thread);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedIrqUsedTimeUpdate(VOID)
|
||||
STATIC INLINE VOID OsSchedIrqUpdateUsedTime(VOID)
|
||||
{
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
runTask->irqUsedTime = OsGetCurrSchedTimeCycle() - runTask->irqStartTime;
|
||||
@@ -481,123 +480,6 @@ STATIC INLINE VOID OsSchedIrqStartTime(VOID)
|
||||
runTask->irqStartTime = OsGetCurrSchedTimeCycle();
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
STATIC INLINE VOID IdleRunqueueFind(UINT16 *idleCpuid)
|
||||
{
|
||||
SchedRunqueue *idleRq = OsSchedRunqueueByID(0);
|
||||
UINT32 nodeNum = OsGetSortLinkNodeNum(&idleRq->timeoutQueue);
|
||||
UINT16 cpuid = 1;
|
||||
do {
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(cpuid);
|
||||
UINT32 temp = OsGetSortLinkNodeNum(&rq->timeoutQueue);
|
||||
if (nodeNum > temp) {
|
||||
*idleCpuid = cpuid;
|
||||
nodeNum = temp;
|
||||
}
|
||||
cpuid++;
|
||||
} while (cpuid < LOSCFG_KERNEL_CORE_NUM);
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC INLINE VOID OsSchedTimeoutQueueAdd(LosTaskCB *taskCB, UINT64 responseTime)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT16 cpuid = AFFI_MASK_TO_CPUID(taskCB->cpuAffiMask);
|
||||
if (cpuid >= LOSCFG_KERNEL_CORE_NUM) {
|
||||
cpuid = 0;
|
||||
IdleRunqueueFind(&cpuid);
|
||||
}
|
||||
#else
|
||||
UINT16 cpuid = 0;
|
||||
#endif
|
||||
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(cpuid);
|
||||
OsAdd2SortLink(&rq->timeoutQueue, &taskCB->sortList, responseTime, cpuid);
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if ((cpuid != ArchCurrCpuid()) && (responseTime < rq->responseTime)) {
|
||||
rq->schedFlag |= INT_PEND_TICK;
|
||||
LOS_MpSchedule(CPUID_TO_AFFI_MASK(cpuid));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedTimeoutQueueDelete(LosTaskCB *taskCB)
|
||||
{
|
||||
SortLinkList *node = &taskCB->sortList;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(node->cpuid);
|
||||
#else
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(0);
|
||||
#endif
|
||||
UINT64 oldResponseTime = GET_SORTLIST_VALUE(node);
|
||||
OsDeleteFromSortLink(&rq->timeoutQueue, node);
|
||||
if (oldResponseTime <= rq->responseTime) {
|
||||
rq->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSchedTimeoutQueueAdjust(LosTaskCB *taskCB, UINT64 responseTime)
|
||||
{
|
||||
UINT32 ret;
|
||||
SortLinkList *node = &taskCB->sortList;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT16 cpuid = node->cpuid;
|
||||
#else
|
||||
UINT16 cpuid = 0;
|
||||
#endif
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(cpuid);
|
||||
ret = OsSortLinkAdjustNodeResponseTime(&rq->timeoutQueue, node, responseTime);
|
||||
if (ret == LOS_OK) {
|
||||
rq->schedFlag |= INT_PEND_TICK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SchedTaskFreeze(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT64 responseTime;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_PM
|
||||
if (!OsIsPmMode()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(taskCB->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY))) {
|
||||
return;
|
||||
}
|
||||
|
||||
responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
|
||||
OsSchedTimeoutQueueDelete(taskCB);
|
||||
SET_SORTLIST_VALUE(&taskCB->sortList, responseTime);
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_FROZEN;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SchedTaskUnfreeze(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT64 currTime, responseTime;
|
||||
|
||||
if (!(taskCB->taskStatus & OS_TASK_STATUS_FROZEN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_FROZEN;
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
responseTime = GET_SORTLIST_VALUE(&taskCB->sortList);
|
||||
if (responseTime > currTime) {
|
||||
OsSchedTimeoutQueueAdd(taskCB, responseTime);
|
||||
return;
|
||||
}
|
||||
|
||||
SET_SORTLIST_VALUE(&taskCB->sortList, OS_SORT_LINK_INVALID_TIME);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_PENDING) {
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
}
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_BLOCKED;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Schedule flag, one bit represents one core.
|
||||
* This flag is used to prevent kernel scheduling before OSStartToRun.
|
||||
@@ -610,59 +492,25 @@ STATIC INLINE VOID SchedTaskUnfreeze(LosTaskCB *taskCB)
|
||||
g_taskScheduled &= ~(1U << (cpuid)); \
|
||||
} while (0);
|
||||
|
||||
STATIC INLINE LosTaskCB *HPFRunqueueTopTaskGet(HPFRunqueue *rq)
|
||||
{
|
||||
LosTaskCB *newTask = NULL;
|
||||
UINT32 baseBitmap = rq->queueBitmap;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
#endif
|
||||
|
||||
while (baseBitmap) {
|
||||
UINT32 basePrio = CLZ(baseBitmap);
|
||||
HPFQueue *queueList = &rq->queueList[basePrio];
|
||||
UINT32 bitmap = queueList->queueBitmap;
|
||||
while (bitmap) {
|
||||
UINT32 priority = CLZ(bitmap);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueList[priority], LosTaskCB, pendList) {
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (newTask->cpuAffiMask & (1U << cpuid)) {
|
||||
#endif
|
||||
return newTask;
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
}
|
||||
#endif
|
||||
}
|
||||
bitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - priority - 1));
|
||||
}
|
||||
baseBitmap &= ~(1U << (OS_PRIORITY_QUEUE_NUM - basePrio - 1));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID HPFSchedPolicyInit(SchedRunqueue *rq);
|
||||
VOID HPFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
|
||||
const SchedParam *parentParam, const TSK_INIT_PARAM_S *param);
|
||||
VOID HPFProcessDefaultSchedParamGet(SchedParam *param);
|
||||
|
||||
VOID IdleTaskSchedParamInit(LosTaskCB *taskCB);
|
||||
|
||||
INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2);
|
||||
VOID OsSchedPriorityInheritance(LosTaskCB *owner, const SchedParam *param);
|
||||
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
|
||||
const SchedParam *parentParam, const TSK_INIT_PARAM_S *param);
|
||||
VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param);
|
||||
|
||||
VOID OsSchedResponseTimeReset(UINT64 responseTime);
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
|
||||
VOID OsSchedUpdateExpireTime(VOID);
|
||||
VOID OsSchedToUserReleaseLock(VOID);
|
||||
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
|
||||
VOID OsSchedTaskEnQueue(LosTaskCB *taskCB);
|
||||
UINT32 OsSchedTaskWait(LOS_DL_LIST *list, UINT32 timeout, BOOL needSched);
|
||||
VOID OsSchedTaskWake(LosTaskCB *resumedTask);
|
||||
BOOL OsSchedModifyTaskSchedParam(LosTaskCB *taskCB, UINT16 policy, UINT16 priority);
|
||||
BOOL OsSchedModifyProcessSchedParam(UINT32 pid, UINT16 policy, UINT16 priority);
|
||||
VOID OsSchedSuspend(LosTaskCB *taskCB);
|
||||
BOOL OsSchedResume(LosTaskCB *taskCB);
|
||||
VOID OsSchedDelay(LosTaskCB *runTask, UINT32 tick);
|
||||
VOID OsSchedYield(VOID);
|
||||
VOID OsSchedTaskExit(LosTaskCB *taskCB);
|
||||
VOID OsSchedTick(VOID);
|
||||
UINT32 OsSchedInit(VOID);
|
||||
VOID OsSchedStart(VOID);
|
||||
|
||||
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID);
|
||||
VOID OsSchedRunqueueInit(VOID);
|
||||
|
||||
/*
|
||||
* This function simply picks the next task and switches to it.
|
||||
* Current task needs to already be in the right state or the right
|
||||
@@ -677,6 +525,14 @@ VOID OsSchedIrqEndCheckNeedSched(VOID);
|
||||
*/
|
||||
LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList);
|
||||
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
VOID OsSchedDebugRecordData(VOID);
|
||||
#endif
|
||||
|
||||
UINT32 OsShellShowTickRespo(VOID);
|
||||
|
||||
UINT32 OsShellShowSchedParam(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -61,11 +61,11 @@ STATIC INLINE VOID OsSemDbgTimeUpdateHook(UINT32 semID)
|
||||
return;
|
||||
}
|
||||
/* Update the SEM_DEBUG_CB of the semaphore when created or deleted */
|
||||
extern VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creator, UINT16 count);
|
||||
STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semID, TSK_ENTRY_FUNC creator, UINT16 count)
|
||||
extern VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creater, UINT16 count);
|
||||
STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semID, TSK_ENTRY_FUNC creater, UINT16 count)
|
||||
{
|
||||
#ifdef LOSCFG_DEBUG_SEMAPHORE
|
||||
OsSemDbgUpdate(semID, creator, count);
|
||||
OsSemDbgUpdate(semID, creater, count);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,42 +72,28 @@ STATIC INLINE UINT64 OsGetSortLinkNextExpireTime(SortLinkAttribute *sortHeader,
|
||||
LOS_DL_LIST *head = &sortHeader->sortLink;
|
||||
LOS_DL_LIST *list = head->pstNext;
|
||||
|
||||
LOS_SpinLock(&sortHeader->spinLock);
|
||||
if (LOS_ListEmpty(head)) {
|
||||
LOS_SpinUnlock(&sortHeader->spinLock);
|
||||
return OS_SORT_LINK_INVALID_TIME - tickPrecision;
|
||||
}
|
||||
|
||||
SortLinkList *listSorted = LOS_DL_LIST_ENTRY(list, SortLinkList, sortLinkNode);
|
||||
if (listSorted->responseTime <= (startTime + tickPrecision)) {
|
||||
LOS_SpinUnlock(&sortHeader->spinLock);
|
||||
return startTime + tickPrecision;
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&sortHeader->spinLock);
|
||||
return listSorted->responseTime;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsGetSortLinkNodeNum(const SortLinkAttribute *head)
|
||||
STATIC INLINE UINT32 OsGetSortLinkNodeNum(SortLinkAttribute *head)
|
||||
{
|
||||
return head->nodeNum;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT16 OsGetSortLinkNodeCpuid(const SortLinkList *node)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
return node->cpuid;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
VOID OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
|
||||
VOID OsAdd2SortLink(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime, UINT16 idleCpu);
|
||||
VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node);
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList);
|
||||
UINT64 OsSortLinkGetNextExpireTime(UINT64 currTime, const SortLinkAttribute *sortLinkHeader);
|
||||
UINT32 OsSortLinkAdjustNodeResponseTime(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -40,6 +40,11 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
UINT64 runtime;
|
||||
UINT32 contexSwitch;
|
||||
} SchedPercpu;
|
||||
|
||||
typedef struct {
|
||||
UINT64 allRuntime;
|
||||
UINT64 runTime;
|
||||
@@ -51,17 +56,9 @@ typedef struct {
|
||||
UINT64 pendCount;
|
||||
UINT64 waitSchedTime; /* task status is ready to running times */
|
||||
UINT64 waitSchedCount;
|
||||
SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM];
|
||||
} SchedStat;
|
||||
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
VOID OsSchedDebugRecordData(VOID);
|
||||
UINT32 OsShellShowTickResponse(VOID);
|
||||
UINT32 OsShellShowSchedStatistics(VOID);
|
||||
UINT32 OsSchedDebugInit(VOID);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
@@ -66,10 +66,6 @@ typedef struct {
|
||||
SWTMR_PROC_FUNC handler; /**< Callback function that handles software timer timeout */
|
||||
UINTPTR arg; /**< Parameter passed in when the callback function
|
||||
that handles software timer timeout is called */
|
||||
LOS_DL_LIST node;
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
UINT32 swtmrID;
|
||||
#endif
|
||||
} SwtmrHandlerItem;
|
||||
|
||||
/**
|
||||
@@ -104,42 +100,13 @@ extern SWTMR_CTRL_S *g_swtmrCBArray;
|
||||
* @see LOS_SwtmrStop
|
||||
*/
|
||||
|
||||
extern UINT32 OsSwtmrGetNextTimeout(VOID);
|
||||
extern BOOL OsIsSwtmrTask(const LosTaskCB *taskCB);
|
||||
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
|
||||
extern VOID OsSwtmrRestart(UINT64 startTime, SortLinkList *sortList);
|
||||
extern VOID OsSwtmrWake(SchedRunQue *rq, UINT64 currTime, SortLinkList *sortList);
|
||||
extern UINT32 OsSwtmrInit(VOID);
|
||||
extern VOID OsSwtmrRecycle(UINT32 processID);
|
||||
extern BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
|
||||
extern SPIN_LOCK_S g_swtmrSpin;
|
||||
extern UINT32 OsSwtmrTaskIDGetByCpuid(UINT16 cpuid);
|
||||
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
typedef struct {
|
||||
UINT64 startTime;
|
||||
UINT64 waitTimeMax;
|
||||
UINT64 waitTime;
|
||||
UINT64 waitCount;
|
||||
UINT64 readyStartTime;
|
||||
UINT64 readyTime;
|
||||
UINT64 readyTimeMax;
|
||||
UINT64 runTime;
|
||||
UINT64 runTimeMax;
|
||||
UINT64 runCount;
|
||||
UINT32 times;
|
||||
} SwtmrDebugBase;
|
||||
|
||||
typedef struct {
|
||||
SwtmrDebugBase base;
|
||||
SWTMR_PROC_FUNC handler;
|
||||
UINT32 period;
|
||||
UINT32 cpuid;
|
||||
BOOL swtmrUsed;
|
||||
} SwtmrDebugData;
|
||||
|
||||
extern BOOL OsSwtmrDebugDataUsed(UINT32 swtmrID);
|
||||
extern UINT32 OsSwtmrDebugDataGet(UINT32 swtmrID, SwtmrDebugData *data, UINT32 len, UINT8 *mode);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -73,7 +73,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task control block is unused.
|
||||
*/
|
||||
#define OS_TASK_STATUS_UNUSED 0x0400U
|
||||
#define OS_TASK_STATUS_UNUSED 0x0200U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -81,7 +81,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task is joinable.
|
||||
*/
|
||||
#define OS_TASK_FLAG_PTHREAD_JOIN 0x0800U
|
||||
#define OS_TASK_FLAG_PTHREAD_JOIN 0x0400U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -89,7 +89,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task is user mode task.
|
||||
*/
|
||||
#define OS_TASK_FLAG_USER_MODE 0x1000U
|
||||
#define OS_TASK_FLAG_USER_MODE 0x0800U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -97,7 +97,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task is system-level task, like idle, swtmr and etc.
|
||||
*/
|
||||
#define OS_TASK_FLAG_SYSTEM_TASK 0x2000U
|
||||
#define OS_TASK_FLAG_SYSTEM_TASK 0x1000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -105,7 +105,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task is no-delete system task, like resourceTask.
|
||||
*/
|
||||
#define OS_TASK_FLAG_NO_DELETE 0x4000U
|
||||
#define OS_TASK_FLAG_NO_DELETE 0x2000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -113,7 +113,15 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* Kills the thread during process exit.
|
||||
*/
|
||||
#define OS_TASK_FLAG_EXIT_KILL 0x8000U
|
||||
#define OS_TASK_FLAG_EXIT_KILL 0x4000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Flag that indicates the task or task control block status.
|
||||
*
|
||||
* The delayed operation of this task is frozen.
|
||||
*/
|
||||
#define OS_TASK_FLAG_FREEZE 0x8000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
|
||||
@@ -59,9 +59,9 @@ extern "C" {
|
||||
const CHAR *OsGetRegionNameOrFilePath(LosVmMapRegion *region);
|
||||
INT32 OsRegionOverlapCheckUnlock(LosVmSpace *space, LosVmMapRegion *region);
|
||||
UINT32 OsShellCmdProcessVmUsage(LosVmSpace *space);
|
||||
UINT32 OsShellCmdProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
UINT32 OsUProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
UINT32 OsKProcessPmUsage(LosVmSpace *kAspace, UINT32 *actualPm);
|
||||
VOID OsShellCmdProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
VOID OsUProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
VOID OsKProcessPmUsage(LosVmSpace *kAspace, UINT32 *actualPm);
|
||||
VOID OsDumpAspace(LosVmSpace *space);
|
||||
UINT32 OsCountRegionPages(LosVmSpace *space, LosVmMapRegion *region, UINT32 *pssPages);
|
||||
UINT32 OsCountAspacePages(LosVmSpace *space);
|
||||
@@ -70,7 +70,7 @@ VOID OsVmPhysDump(VOID);
|
||||
VOID OsVmPhysUsedInfoGet(UINT32 *usedCount, UINT32 *totalCount);
|
||||
INT32 OsRegionOverlapCheck(LosVmSpace *space, LosVmMapRegion *region);
|
||||
VOID OsDumpPte(VADDR_T vaddr);
|
||||
LosProcessCB *OsGetPIDByAspace(const LosVmSpace *space);
|
||||
LosProcessCB *OsGetPIDByAspace(LosVmSpace *space);
|
||||
CHAR *OsArchFlagsToStr(const UINT32 archFlags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -193,7 +193,7 @@ VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB);
|
||||
|
||||
LosFilePage *OsPageCacheAlloc(struct page_mapping *mapping, VM_OFFSET_T pgoff);
|
||||
LosFilePage *OsFindGetEntry(struct page_mapping *mapping, VM_OFFSET_T pgoff);
|
||||
LosMapInfo *OsGetMapInfo(const LosFilePage *page, const LosArchMmu *archMmu, VADDR_T vaddr);
|
||||
LosMapInfo *OsGetMapInfo(LosFilePage *page, LosArchMmu *archMmu, VADDR_T vaddr);
|
||||
VOID OsAddMapInfo(LosFilePage *page, LosArchMmu *archMmu, VADDR_T vaddr);
|
||||
VOID OsDelMapInfo(LosVmMapRegion *region, LosVmPgFault *pgFault, BOOL cleanDirty);
|
||||
VOID OsFileCacheFlush(struct page_mapping *mapping);
|
||||
@@ -208,7 +208,7 @@ VOID OsDeletePageCacheLru(LosFilePage *page);
|
||||
VOID OsPageRefDecNoLock(LosFilePage *page);
|
||||
VOID OsPageRefIncLocked(LosFilePage *page);
|
||||
int OsTryShrinkMemory(size_t nPage);
|
||||
VOID OsMarkPageDirty(LosFilePage *fpage, const LosVmMapRegion *region, int off, int len);
|
||||
VOID OsMarkPageDirty(LosFilePage *fpage, LosVmMapRegion *region, int off, int len);
|
||||
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
VOID ResetPageCacheHitInfo(int *try, int *hit);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -147,7 +147,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsEventReadImp(PEVENT_CB_S eventCB, UINT32 eventM
|
||||
runTask->eventMode = mode;
|
||||
runTask->taskEvent = eventCB;
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_EVENT, eventMask, timeout);
|
||||
ret = runTask->ops->wait(runTask, &eventCB->stEventList, timeout);
|
||||
ret = OsSchedTaskWait(&eventCB->stEventList, timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
return LOS_ERRNO_EVENT_READ_TIMEOUT;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ LITE_OS_SEC_TEXT STATIC UINT8 OsEventResume(LosTaskCB *resumedTask, const PEVENT
|
||||
|
||||
resumedTask->taskEvent = NULL;
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
}
|
||||
|
||||
return exitFlag;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -118,10 +118,10 @@ STATIC VOID OsFutexShowTaskNodeAttr(const LOS_DL_LIST *futexList)
|
||||
lastNode = OS_FUTEX_FROM_QUEUELIST(queueList);
|
||||
if (!LOS_ListEmpty(&(lastNode->pendList))) {
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(lastNode->pendList)));
|
||||
PRINTK(" %u ->", taskCB->taskID);
|
||||
PRINTK(" %u(%u) ->", taskCB->taskID, taskCB->priority);
|
||||
} else {
|
||||
taskCB = LOS_DL_LIST_ENTRY(lastNode, LosTaskCB, futex);
|
||||
PRINTK(" %u ->", taskCB->taskID);
|
||||
PRINTK(" %u(%d) ->", taskCB->taskID, -1);
|
||||
}
|
||||
queueList = queueList->pstNext;
|
||||
if (queueList == &tempNode->queueList) {
|
||||
@@ -336,19 +336,20 @@ STATIC INT32 OsFutexInsertFindFormBackToFront(LOS_DL_LIST *queueList, const LosT
|
||||
{
|
||||
LOS_DL_LIST *listHead = queueList;
|
||||
LOS_DL_LIST *listTail = queueList->pstPrev;
|
||||
FutexNode *tempNode = NULL;
|
||||
LosTaskCB *taskTail = NULL;
|
||||
|
||||
for (; listHead != listTail; listTail = listTail->pstPrev) {
|
||||
FutexNode *tempNode = OS_FUTEX_FROM_QUEUELIST(listTail);
|
||||
tempNode = OS_FUTEX_FROM_QUEUELIST(listTail);
|
||||
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
|
||||
if (tempNode == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
LosTaskCB *taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
INT32 ret = OsSchedParamCompare(runTask, taskTail);
|
||||
if (ret >= 0) {
|
||||
taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
if (runTask->priority >= taskTail->priority) {
|
||||
LOS_ListHeadInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
} else {
|
||||
} else if (runTask->priority < taskTail->priority) {
|
||||
if (listTail->pstPrev == listHead) {
|
||||
LOS_ListTailInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
@@ -363,25 +364,26 @@ STATIC INT32 OsFutexInsertFindFromFrontToBack(LOS_DL_LIST *queueList, const LosT
|
||||
{
|
||||
LOS_DL_LIST *listHead = queueList;
|
||||
LOS_DL_LIST *listTail = queueList->pstPrev;
|
||||
FutexNode *tempNode = NULL;
|
||||
LosTaskCB *taskHead = NULL;
|
||||
|
||||
for (; listHead != listTail; listHead = listHead->pstNext) {
|
||||
FutexNode *tempNode = OS_FUTEX_FROM_QUEUELIST(listHead);
|
||||
tempNode = OS_FUTEX_FROM_QUEUELIST(listHead);
|
||||
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
|
||||
if (tempNode == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
LosTaskCB *taskHead = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
taskHead = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
/* High priority comes before low priority,
|
||||
* in the case of the same priority, after the current node
|
||||
*/
|
||||
INT32 ret = OsSchedParamCompare(runTask, taskHead);
|
||||
if (ret >= 0) {
|
||||
if (runTask->priority >= taskHead->priority) {
|
||||
if (listHead->pstNext == listTail) {
|
||||
LOS_ListHeadInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
} else if (runTask->priority < taskHead->priority) {
|
||||
LOS_ListTailInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -412,9 +414,10 @@ STATIC INT32 OsFutexInsertTasktoPendList(FutexNode **firstNode, FutexNode *node,
|
||||
{
|
||||
LosTaskCB *taskHead = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&((*firstNode)->pendList)));
|
||||
LOS_DL_LIST *queueList = &((*firstNode)->queueList);
|
||||
FutexNode *tailNode = NULL;
|
||||
LosTaskCB *taskTail = NULL;
|
||||
|
||||
INT32 ret1 = OsSchedParamCompare(run, taskHead);
|
||||
if (ret1 < 0) {
|
||||
if (run->priority < taskHead->priority) {
|
||||
/* The one with the highest priority is inserted at the top of the queue */
|
||||
LOS_ListTailInsert(queueList, &(node->queueList));
|
||||
OsFutexReplaceQueueListHeadNode(*firstNode, node);
|
||||
@@ -422,16 +425,16 @@ STATIC INT32 OsFutexInsertTasktoPendList(FutexNode **firstNode, FutexNode *node,
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (LOS_ListEmpty(queueList) && (ret1 >= 0)) {
|
||||
if (LOS_ListEmpty(queueList) && (run->priority >= taskHead->priority)) {
|
||||
/* Insert the next position in the queue with equal priority */
|
||||
LOS_ListHeadInsert(queueList, &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
FutexNode *tailNode = OS_FUTEX_FROM_QUEUELIST(LOS_DL_LIST_LAST(queueList));
|
||||
LosTaskCB *taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tailNode->pendList)));
|
||||
INT32 ret2 = OsSchedParamCompare(taskTail, run);
|
||||
if ((ret2 <= 0) || (ret1 > ret2)) {
|
||||
tailNode = OS_FUTEX_FROM_QUEUELIST(LOS_DL_LIST_LAST(queueList));
|
||||
taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tailNode->pendList)));
|
||||
if ((run->priority >= taskTail->priority) ||
|
||||
((run->priority - taskHead->priority) > (taskTail->priority - run->priority))) {
|
||||
return OsFutexInsertFindFormBackToFront(queueList, run, node);
|
||||
}
|
||||
|
||||
@@ -521,7 +524,7 @@ STATIC INT32 OsFutexWaitParamCheck(const UINT32 *userVaddr, UINT32 flags, UINT32
|
||||
}
|
||||
|
||||
if (!absTime) {
|
||||
return LOS_ETIMEDOUT;
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
@@ -566,7 +569,7 @@ STATIC INT32 OsFutexInsertTaskToHash(LosTaskCB **taskCB, FutexNode **node, const
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const UINT32 val, const UINT32 timeout)
|
||||
STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const UINT32 val, const UINT32 timeOut)
|
||||
{
|
||||
INT32 futexRet;
|
||||
UINT32 intSave, lockVal;
|
||||
@@ -597,9 +600,9 @@ STATIC INT32 OsFutexWaitTask(const UINT32 *userVaddr, const UINT32 flags, const
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_FUTEX, futexKey, timeOut);
|
||||
OsSchedTaskWait(&(node->pendList), timeOut, FALSE);
|
||||
OsSchedLock();
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_FUTEX, futexKey, timeout);
|
||||
taskCB->ops->wait(taskCB, &(node->pendList), timeout);
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
|
||||
futexRet = OsFutexUnlock(&hashNode->listLock);
|
||||
@@ -636,17 +639,17 @@ EXIT_UNLOCK_ERR:
|
||||
INT32 OsFutexWait(const UINT32 *userVaddr, UINT32 flags, UINT32 val, UINT32 absTime)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 timeout = LOS_WAIT_FOREVER;
|
||||
UINT32 timeOut = LOS_WAIT_FOREVER;
|
||||
|
||||
ret = OsFutexWaitParamCheck(userVaddr, flags, absTime);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
if (absTime != LOS_WAIT_FOREVER) {
|
||||
timeout = OsNS2Tick((UINT64)absTime * OS_SYS_NS_PER_US);
|
||||
timeOut = OsNS2Tick((UINT64)absTime * OS_SYS_NS_PER_US);
|
||||
}
|
||||
|
||||
return OsFutexWaitTask(userVaddr, flags, val, timeout);
|
||||
return OsFutexWaitTask(userVaddr, flags, val, timeOut);
|
||||
}
|
||||
|
||||
STATIC INT32 OsFutexWakeParamCheck(const UINT32 *userVaddr, UINT32 flags)
|
||||
@@ -690,7 +693,7 @@ STATIC VOID OsFutexCheckAndWakePendTask(FutexNode *headNode, const INT32 wakeNum
|
||||
node = *nextNode;
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(node->pendList)));
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
*wakeAny = TRUE;
|
||||
*nextNode = OS_FUTEX_FROM_QUEUELIST(LOS_DL_LIST_FIRST(&(node->queueList)));
|
||||
if (node != headNode) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -257,36 +257,40 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask)
|
||||
STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask, LosTaskCB *owner)
|
||||
{
|
||||
if (mutex->attr.protocol != LOS_MUX_PRIO_INHERIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
SchedParam param = { 0 };
|
||||
LosTaskCB *owner = (LosTaskCB *)mutex->owner;
|
||||
INT32 ret = OsSchedParamCompare(owner, runTask);
|
||||
if (ret > 0) {
|
||||
runTask->ops->schedParamGet(runTask, ¶m);
|
||||
owner->ops->priorityInheritance(owner, ¶m);
|
||||
if ((owner->priority > runTask->priority) && (mutex->attr.protocol == LOS_MUX_PRIO_INHERIT)) {
|
||||
LOS_BitmapSet(&(owner->priBitMap), owner->priority);
|
||||
(VOID)OsSchedModifyTaskSchedParam(owner, owner->policy, runTask->priority);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask)
|
||||
VOID OsMuxBitmapRestore(const LosMux *mutex, const LosTaskCB *taskCB, LosTaskCB *owner)
|
||||
{
|
||||
UINT16 bitMapPri;
|
||||
|
||||
if (mutex->attr.protocol != LOS_MUX_PRIO_INHERIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
SchedParam param = { 0 };
|
||||
LosTaskCB *owner = (LosTaskCB *)mutex->owner;
|
||||
runTask->ops->schedParamGet(runTask, ¶m);
|
||||
owner->ops->priorityRestore(owner, list, ¶m);
|
||||
if (owner->priority >= taskCB->priority) {
|
||||
bitMapPri = LOS_LowBitGet(owner->priBitMap);
|
||||
if (bitMapPri != LOS_INVALID_BIT_INDEX) {
|
||||
LOS_BitmapClr(&(owner->priBitMap), bitMapPri);
|
||||
OsSchedModifyTaskSchedParam(owner, owner->policy, bitMapPri);
|
||||
}
|
||||
} else {
|
||||
if (LOS_HighBitGet(owner->priBitMap) != taskCB->priority) {
|
||||
LOS_BitmapClr(&(owner->priBitMap), taskCB->priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
|
||||
{
|
||||
UINT32 ret;
|
||||
LOS_DL_LIST *node = NULL;
|
||||
LosTaskCB *owner = NULL;
|
||||
|
||||
if ((mutex->muxList.pstPrev == NULL) || (mutex->muxList.pstNext == NULL)) {
|
||||
/* This is for mutex macro initialization. */
|
||||
@@ -299,11 +303,9 @@ STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
|
||||
mutex->muxCount++;
|
||||
mutex->owner = (VOID *)runTask;
|
||||
LOS_ListTailInsert(&runTask->lockList, &mutex->holdList);
|
||||
if (mutex->attr.protocol == LOS_MUX_PRIO_PROTECT) {
|
||||
SchedParam param = { 0 };
|
||||
runTask->ops->schedParamGet(runTask, ¶m);
|
||||
param.priority = mutex->attr.prioceiling;
|
||||
runTask->ops->priorityInheritance(runTask, ¶m);
|
||||
if ((mutex->attr.protocol == LOS_MUX_PRIO_PROTECT) && (runTask->priority > mutex->attr.prioceiling)) {
|
||||
LOS_BitmapSet(&runTask->priBitMap, runTask->priority);
|
||||
(VOID)OsSchedModifyTaskSchedParam(runTask, runTask->policy, mutex->attr.prioceiling);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -321,23 +323,27 @@ STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
|
||||
return LOS_EDEADLK;
|
||||
}
|
||||
|
||||
OsMuxBitmapSet(mutex, runTask);
|
||||
OsMuxBitmapSet(mutex, runTask, (LosTaskCB *)mutex->owner);
|
||||
|
||||
owner = (LosTaskCB *)mutex->owner;
|
||||
runTask->taskMux = (VOID *)mutex;
|
||||
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &mutex->muxList);
|
||||
node = OsSchedLockPendFindPos(runTask, &mutex->muxList);
|
||||
if (node == NULL) {
|
||||
ret = LOS_NOK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_MUTEX, (UINTPTR)mutex, timeout);
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
ret = OsSchedTaskWait(node, timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
OsMuxBitmapRestore(mutex, NULL, runTask);
|
||||
runTask->taskMux = NULL;
|
||||
ret = LOS_ETIMEDOUT;
|
||||
}
|
||||
|
||||
if (timeout != LOS_WAIT_FOREVER) {
|
||||
OsMuxBitmapRestore(mutex, runTask, owner);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -434,23 +440,50 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxTrylock(LosMux *mutex)
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC VOID OsMuxPostOpSub(LosTaskCB *taskCB, LosMux *mutex)
|
||||
{
|
||||
LosTaskCB *pendedTask = NULL;
|
||||
UINT16 bitMapPri;
|
||||
|
||||
if (!LOS_ListEmpty(&mutex->muxList)) {
|
||||
bitMapPri = LOS_HighBitGet(taskCB->priBitMap);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, (&mutex->muxList), LosTaskCB, pendList) {
|
||||
if (bitMapPri != pendedTask->priority) {
|
||||
LOS_BitmapClr(&taskCB->priBitMap, pendedTask->priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
bitMapPri = LOS_LowBitGet(taskCB->priBitMap);
|
||||
LOS_BitmapClr(&taskCB->priBitMap, bitMapPri);
|
||||
(VOID)OsSchedModifyTaskSchedParam((LosTaskCB *)mutex->owner, ((LosTaskCB *)mutex->owner)->policy, bitMapPri);
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMuxPostOp(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
|
||||
{
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
|
||||
if (LOS_ListEmpty(&mutex->muxList)) {
|
||||
LOS_ListDelete(&mutex->holdList);
|
||||
mutex->owner = NULL;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(mutex->muxList)));
|
||||
OsMuxBitmapRestore(mutex, &mutex->muxList, resumedTask);
|
||||
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(mutex->muxList)));
|
||||
if (mutex->attr.protocol == LOS_MUX_PRIO_INHERIT) {
|
||||
if (resumedTask->priority > taskCB->priority) {
|
||||
if (LOS_HighBitGet(taskCB->priBitMap) != resumedTask->priority) {
|
||||
LOS_BitmapClr(&taskCB->priBitMap, resumedTask->priority);
|
||||
}
|
||||
} else if (taskCB->priBitMap != 0) {
|
||||
OsMuxPostOpSub(taskCB, mutex);
|
||||
}
|
||||
}
|
||||
mutex->muxCount = 1;
|
||||
mutex->owner = (VOID *)resumedTask;
|
||||
LOS_ListDelete(&mutex->holdList);
|
||||
LOS_ListTailInsert(&resumedTask->lockList, &mutex->holdList);
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->taskMux = NULL;
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
@@ -461,6 +494,8 @@ STATIC UINT32 OsMuxPostOp(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
|
||||
|
||||
UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
|
||||
{
|
||||
UINT16 bitMapPri;
|
||||
|
||||
if (mutex->magic != OS_MUX_MAGIC) {
|
||||
return LOS_EBADF;
|
||||
}
|
||||
@@ -482,9 +517,11 @@ UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
|
||||
}
|
||||
|
||||
if (mutex->attr.protocol == LOS_MUX_PRIO_PROTECT) {
|
||||
SchedParam param = { 0 };
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
taskCB->ops->priorityRestore(taskCB, NULL, ¶m);
|
||||
bitMapPri = LOS_HighBitGet(taskCB->priBitMap);
|
||||
if (bitMapPri != LOS_INVALID_BIT_INDEX) {
|
||||
LOS_BitmapClr(&taskCB->priBitMap, bitMapPri);
|
||||
(VOID)OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, bitMapPri);
|
||||
}
|
||||
}
|
||||
|
||||
/* Whether a task block the mutex lock. */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -223,7 +223,6 @@ STATIC VOID OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *
|
||||
PRINT_ERR("get msgdatasize failed\n");
|
||||
return;
|
||||
}
|
||||
msgDataSize = (*bufferSize < msgDataSize) ? *bufferSize : msgDataSize;
|
||||
if (memcpy_s(bufferAddr, *bufferSize, queueNode, msgDataSize) != EOK) {
|
||||
PRINT_ERR("copy message to buffer failed\n");
|
||||
return;
|
||||
@@ -250,7 +249,9 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueID
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
if (OS_QUEUE_IS_READ(operateType) && (*bufferSize < (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL;
|
||||
} else if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
|
||||
}
|
||||
return LOS_OK;
|
||||
@@ -258,13 +259,15 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueID
|
||||
|
||||
UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
|
||||
{
|
||||
LosQueueCB *queueCB = NULL;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
UINT32 ret;
|
||||
UINT32 readWrite = OS_QUEUE_READ_WRITE_GET(operateType);
|
||||
UINT32 intSave;
|
||||
OsHookCall(LOS_HOOK_TYPE_QUEUE_READ, (LosQueueCB *)GET_QUEUE_HANDLE(queueID), operateType, *bufferSize, timeout);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
ret = OsQueueOperateParamCheck(queueCB, queueID, operateType, bufferSize);
|
||||
if (ret != LOS_OK) {
|
||||
goto QUEUE_END;
|
||||
@@ -281,9 +284,8 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_QUEUE, queueCB->queueID, timeout);
|
||||
ret = runTask->ops->wait(runTask, &queueCB->readWriteList[readWrite], timeout);
|
||||
ret = OsSchedTaskWait(&queueCB->readWriteList[readWrite], timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = LOS_ERRNO_QUEUE_TIMEOUT;
|
||||
goto QUEUE_END;
|
||||
@@ -295,9 +297,9 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
|
||||
OsQueueBufferOperate(queueCB, operateType, bufferAddr, bufferSize);
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[!readWrite])) {
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[!readWrite]));
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[!readWrite]));
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
LOS_Schedule();
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#ifdef LOSCFG_DEBUG_QUEUE
|
||||
|
||||
typedef struct {
|
||||
TSK_ENTRY_FUNC creator; /* The task entry who created this queue */
|
||||
TSK_ENTRY_FUNC creater; /* The task entry who created this queue */
|
||||
UINT64 lastAccessTime; /* The last access time */
|
||||
} QueueDebugCB;
|
||||
STATIC QueueDebugCB *g_queueDebugArray = NULL;
|
||||
@@ -74,7 +74,7 @@ VOID OsQueueDbgTimeUpdate(UINT32 queueID)
|
||||
VOID OsQueueDbgUpdate(UINT32 queueID, TSK_ENTRY_FUNC entry)
|
||||
{
|
||||
QueueDebugCB *queueDebug = &g_queueDebugArray[GET_QUEUE_INDEX(queueID)];
|
||||
queueDebug->creator = entry;
|
||||
queueDebug->creater = entry;
|
||||
queueDebug->lastAccessTime = LOS_TickCountGet();
|
||||
return;
|
||||
}
|
||||
@@ -91,8 +91,8 @@ STATIC INLINE VOID OsQueueInfoOutPut(const LosQueueCB *node)
|
||||
|
||||
STATIC INLINE VOID OsQueueOpsOutput(const QueueDebugCB *node)
|
||||
{
|
||||
PRINTK("TaskEntry of creator:0x%p, Latest operation time: 0x%llx\n",
|
||||
node->creator, node->lastAccessTime);
|
||||
PRINTK("TaskEntry of creater:0x%p, Latest operation time: 0x%llx\n",
|
||||
node->creater, node->lastAccessTime);
|
||||
}
|
||||
|
||||
STATIC VOID SortQueueIndexArray(UINT32 *indexArray, UINT32 count)
|
||||
@@ -149,7 +149,7 @@ VOID OsQueueCheck(VOID)
|
||||
&g_queueDebugArray[index], sizeof(QueueDebugCB));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if ((queueNode.queueState == OS_QUEUE_UNUSED) ||
|
||||
((queueNode.queueState == OS_QUEUE_INUSED) && (queueDebugNode.creator == NULL))) {
|
||||
((queueNode.queueState == OS_QUEUE_INUSED) && (queueDebugNode.creater == NULL))) {
|
||||
continue;
|
||||
}
|
||||
if ((queueNode.queueState == OS_QUEUE_INUSED) &&
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "los_exc.h"
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
|
||||
#ifdef LOSCFG_BASE_IPC_RWLOCK
|
||||
#define RWLOCK_COUNT_MASK 0x00FFFFFFU
|
||||
|
||||
@@ -96,7 +97,7 @@ UINT32 LOS_RwlockDestroy(LosRwlock *rwlock)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsRwlockCheck(const LosRwlock *rwlock)
|
||||
STATIC UINT32 OsRwlockCheck(LosRwlock *rwlock)
|
||||
{
|
||||
if (rwlock == NULL) {
|
||||
return LOS_EINVAL;
|
||||
@@ -119,7 +120,7 @@ STATIC BOOL OsRwlockPriCompare(LosTaskCB *runTask, LOS_DL_LIST *rwList)
|
||||
{
|
||||
if (!LOS_ListEmpty(rwList)) {
|
||||
LosTaskCB *highestTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(rwList));
|
||||
if (OsSchedParamCompare(runTask, highestTask) < 0) {
|
||||
if (runTask->priority < highestTask->priority) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@@ -163,7 +164,7 @@ STATIC UINT32 OsRwlockRdPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
|
||||
* is lower than the first pended write task, current read task will be pended.
|
||||
*/
|
||||
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->readList));
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
ret = OsSchedTaskWait(node, timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
return LOS_ETIMEDOUT;
|
||||
}
|
||||
@@ -204,7 +205,7 @@ STATIC UINT32 OsRwlockWrPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
|
||||
* write task will be pended.
|
||||
*/
|
||||
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->writeList));
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
ret = OsSchedTaskWait(node, timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = LOS_ETIMEDOUT;
|
||||
}
|
||||
@@ -354,7 +355,7 @@ STATIC UINT32 OsRwlockGetMode(LOS_DL_LIST *readList, LOS_DL_LIST *writeList)
|
||||
}
|
||||
LosTaskCB *pendedReadTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(readList));
|
||||
LosTaskCB *pendedWriteTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(writeList));
|
||||
if (OsSchedParamCompare(pendedWriteTask, pendedReadTask) <= 0) {
|
||||
if (pendedWriteTask->priority <= pendedReadTask->priority) {
|
||||
return RWLOCK_WRITEFIRST_MODE;
|
||||
}
|
||||
return RWLOCK_READFIRST_MODE;
|
||||
@@ -364,6 +365,7 @@ STATIC UINT32 OsRwlockPostOp(LosRwlock *rwlock, BOOL *needSched)
|
||||
{
|
||||
UINT32 rwlockMode;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
UINT16 pendedWriteTaskPri;
|
||||
|
||||
rwlock->rwCount = 0;
|
||||
rwlock->writeOwner = NULL;
|
||||
@@ -376,29 +378,29 @@ STATIC UINT32 OsRwlockPostOp(LosRwlock *rwlock, BOOL *needSched)
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)));
|
||||
rwlock->rwCount = -1;
|
||||
rwlock->writeOwner = (VOID *)resumedTask;
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
rwlock->rwCount = 1;
|
||||
/* In this case, rwlock will wake the valid pended read task. */
|
||||
if (rwlockMode == RWLOCK_READFIRST_MODE) {
|
||||
pendedWriteTaskPri = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)))->priority;
|
||||
}
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
rwlock->rwCount = 1;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
while (!LOS_ListEmpty(&(rwlock->readList))) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
|
||||
if (rwlockMode == RWLOCK_READFIRST_MODE) {
|
||||
LosTaskCB *pendedWriteTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)));
|
||||
if (OsSchedParamCompare(resumedTask, pendedWriteTask) >= 0) {
|
||||
break;
|
||||
}
|
||||
if ((rwlockMode == RWLOCK_READFIRST_MODE) && (resumedTask->priority >= pendedWriteTaskPri)) {
|
||||
break;
|
||||
}
|
||||
if (rwlock->rwCount == INT8_MAX) {
|
||||
return EINVAL;
|
||||
}
|
||||
rwlock->rwCount++;
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
}
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -225,7 +225,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_SEM_PEND, semPended, runTask, timeout);
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_SEM, semPended->semID, timeout);
|
||||
retErr = runTask->ops->wait(runTask, &semPended->semList, timeout);
|
||||
retErr = OsSchedTaskWait(&semPended->semList, timeout, TRUE);
|
||||
if (retErr == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
retErr = LOS_ERRNO_SEM_TIMEOUT;
|
||||
}
|
||||
@@ -237,8 +237,10 @@ OUT:
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
|
||||
{
|
||||
LosSemCB *semPosted = NULL;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
LosSemCB *semPosted = GET_SEM(semHandle);
|
||||
|
||||
semPosted = GET_SEM(semHandle);
|
||||
if ((semPosted->semID != semHandle) || (semPosted->semStat == OS_SEM_UNUSED)) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
@@ -252,7 +254,7 @@ LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
|
||||
if (!LOS_ListEmpty(&semPosted->semList)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(semPosted->semList)));
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ STATIC VOID OsSemPendedTaskNamePrint(LosSemCB *semNode)
|
||||
typedef struct {
|
||||
UINT16 origSemCount; /* Number of original available semaphores */
|
||||
UINT64 lastAccessTime; /* The last operation time */
|
||||
TSK_ENTRY_FUNC creator; /* The task entry who created this sem */
|
||||
TSK_ENTRY_FUNC creater; /* The task entry who created this sem */
|
||||
} SemDebugCB;
|
||||
STATIC SemDebugCB *g_semDebugArray = NULL;
|
||||
|
||||
@@ -110,10 +110,10 @@ VOID OsSemDbgTimeUpdate(UINT32 semID)
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creator, UINT16 count)
|
||||
VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creater, UINT16 count)
|
||||
{
|
||||
SemDebugCB *semDebug = &g_semDebugArray[GET_SEM_INDEX(semID)];
|
||||
semDebug->creator = creator;
|
||||
semDebug->creater = creater;
|
||||
semDebug->lastAccessTime = LOS_TickCountGet();
|
||||
semDebug->origSemCount = count;
|
||||
return;
|
||||
@@ -133,7 +133,7 @@ STATIC VOID OsSemSort(UINT32 *semIndexArray, UINT32 usedCount)
|
||||
|
||||
/* It will Print out ALL the Used Semaphore List. */
|
||||
PRINTK("Used Semaphore List: \n");
|
||||
PRINTK("\r\n SemID Count OriginalCount Creator(TaskEntry) LastAccessTime\n");
|
||||
PRINTK("\r\n SemID Count OriginalCount Creater(TaskEntry) LastAccessTime\n");
|
||||
PRINTK(" ------ ------ ------------- ------------------ -------------- \n");
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
@@ -145,11 +145,11 @@ STATIC VOID OsSemSort(UINT32 *semIndexArray, UINT32 usedCount)
|
||||
(VOID)memcpy_s(&semNode, sizeof(LosSemCB), semCB, sizeof(LosSemCB));
|
||||
(VOID)memcpy_s(&semDebug, sizeof(SemDebugCB), &g_semDebugArray[semIndexArray[i]], sizeof(SemDebugCB));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
if ((semNode.semStat != OS_SEM_USED) || (semDebug.creator == NULL)) {
|
||||
if ((semNode.semStat != OS_SEM_USED) || (semDebug.creater == NULL)) {
|
||||
continue;
|
||||
}
|
||||
PRINTK(" 0x%-07x0x%-07u0x%-14u%-22p0x%llx\n", semNode.semID, semDebug.origSemCount,
|
||||
semNode.semCount, semDebug.creator, semDebug.lastAccessTime);
|
||||
semNode.semCount, semDebug.creater, semDebug.lastAccessTime);
|
||||
if (!LOS_ListEmpty(&semNode.semList)) {
|
||||
OsSemPendedTaskNamePrint(semCB);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ UINT32 OsSemInfoGetFullData(VOID)
|
||||
for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
|
||||
semNode = GET_SEM(i);
|
||||
semDebug = &g_semDebugArray[i];
|
||||
if ((semNode->semStat == OS_SEM_USED) && (semDebug->creator != NULL)) {
|
||||
if ((semNode->semStat == OS_SEM_USED) && (semDebug->creater != NULL)) {
|
||||
usedSemCnt++;
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ UINT32 OsSemInfoGetFullData(VOID)
|
||||
for (i = 0; i < LOSCFG_BASE_IPC_SEM_LIMIT; i++) {
|
||||
semNode = GET_SEM(i);
|
||||
semDebug = &g_semDebugArray[i];
|
||||
if ((semNode->semStat != OS_SEM_USED) || (semDebug->creator == NULL)) {
|
||||
if ((semNode->semStat != OS_SEM_USED) || (semDebug->creater == NULL)) {
|
||||
continue;
|
||||
}
|
||||
*(semIndexArray + count) = i;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -78,6 +78,7 @@ STATIC VOID OsMoveTmpInfoToUnbInfo(sig_cb *sigcb, INT32 signo)
|
||||
/* delete tmpinfo from tmpList. */
|
||||
*prevHook = tmpInfoNode->next;
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
|
||||
tmpInfoNode = *prevHook;
|
||||
break;
|
||||
}
|
||||
prevHook = &tmpInfoNode->next;
|
||||
@@ -128,7 +129,7 @@ STATIC INLINE VOID OsSigWaitTaskWake(LosTaskCB *taskCB, INT32 signo)
|
||||
if (!LOS_ListEmpty(&sigcb->waitList) && OsSigIsMember(&sigcb->sigwaitmask, signo)) {
|
||||
OsMoveTmpInfoToUnbInfo(sigcb, signo);
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
OsSigEmptySet(&sigcb->sigwaitmask);
|
||||
}
|
||||
}
|
||||
@@ -151,19 +152,19 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
||||
break;
|
||||
case OS_TASK_WAIT_JOIN:
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
break;
|
||||
case OS_TASK_WAIT_SIGNAL:
|
||||
OsSigWaitTaskWake(taskCB, signo);
|
||||
break;
|
||||
case OS_TASK_WAIT_LITEIPC:
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
break;
|
||||
case OS_TASK_WAIT_FUTEX:
|
||||
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -283,7 +284,7 @@ static int SigProcessSignalHandler(LosTaskCB *tcb, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If the default tcb is not set, then set this one as default. */
|
||||
/* If the default tcb is not setted, then set this one as default. */
|
||||
if (!info->defaultTcb) {
|
||||
info->defaultTcb = tcb;
|
||||
}
|
||||
@@ -304,7 +305,7 @@ static int SigProcessSignalHandler(LosTaskCB *tcb, void *arg)
|
||||
/* Is this signal unblocked on this thread? */
|
||||
isMember = OsSigIsMember(&tcb->sig.sigprocmask, info->sigInfo->si_signo);
|
||||
if ((!isMember) && (!info->receivedTcb) && (tcb != info->awakenedTcb)) {
|
||||
/* if unblockedTcb of this signal is not set, then set it. */
|
||||
/* if unblockedTcb of this signal is not setted, then set it. */
|
||||
if (!info->unblockedTcb) {
|
||||
info->unblockedTcb = tcb;
|
||||
}
|
||||
@@ -566,7 +567,7 @@ int OsSigTimedWaitNoLock(sigset_t *set, siginfo_t *info, unsigned int timeout)
|
||||
|
||||
sigcb->sigwaitmask |= *set;
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_SIGNAL, sigcb->sigwaitmask, timeout);
|
||||
ret = task->ops->wait(task, &sigcb->waitList, timeout);
|
||||
ret = OsSchedTaskWait(&sigcb->waitList, timeout, TRUE);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = -EAGAIN;
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ STATIC INLINE VOID OsLmsReallocMergeNodeMark(struct OsMemNodeHead *node)
|
||||
}
|
||||
|
||||
g_lms->simpleMark((UINTPTR)node + OS_MEM_NODE_HEAD_SIZE, (UINTPTR)OS_MEM_NEXT_NODE(node),
|
||||
LMS_SHADOW_ACCESSIBLE_U8);
|
||||
LMS_SHADOW_ACCESSABLE_U8);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsLmsReallocSplitNodeMark(struct OsMemNodeHead *node)
|
||||
@@ -918,7 +918,7 @@ STATIC UINT32 OsMemPoolAdd(VOID *pool, UINT32 size)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemPoolDelete(const VOID *pool)
|
||||
STATIC UINT32 OsMemPoolDelete(VOID *pool)
|
||||
{
|
||||
UINT32 ret = LOS_NOK;
|
||||
VOID *nextPool = NULL;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "shcmd.h"
|
||||
#include "shell.h"
|
||||
|
||||
#define OS_ALL_SWTMR_MASK 0xffffffff
|
||||
|
||||
#define SWTMR_STRLEN 12
|
||||
|
||||
LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = {
|
||||
@@ -57,7 +57,13 @@ STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
|
||||
UINT32 ticks = 0;
|
||||
(VOID)LOS_SwtmrTimeGet(swtmr->usTimerID, &ticks);
|
||||
|
||||
PRINTK("%7u%10s%8s%12u%7u%#12x%#12x\n",
|
||||
PRINTK("0x%08x "
|
||||
"%-7s "
|
||||
"%-6s "
|
||||
"%-6u "
|
||||
"%-6u "
|
||||
"0x%08x "
|
||||
"%p\n",
|
||||
swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT,
|
||||
g_shellSwtmrStatus[swtmr->ucState],
|
||||
g_shellSwtmrMode[swtmr->ucMode],
|
||||
@@ -69,15 +75,34 @@ STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
|
||||
|
||||
STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
|
||||
{
|
||||
PRINTK("\r\nSwTmrID State Mode Interval Count Arg handlerAddr\n");
|
||||
PRINTK("\r\nSwTmrID State Mode Interval Count Arg handlerAddr\n");
|
||||
PRINTK("---------- ------- ------- --------- ------- ---------- --------\n");
|
||||
}
|
||||
|
||||
STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv)
|
||||
{
|
||||
#define OS_ALL_SWTMR_MASK 0xffffffff
|
||||
SWTMR_CTRL_S *swtmr = g_swtmrCBArray;
|
||||
SWTMR_CTRL_S *swtmr1 = g_swtmrCBArray;
|
||||
UINT16 index;
|
||||
size_t timerID;
|
||||
UINT16 num = 0;
|
||||
CHAR *endPtr = NULL;
|
||||
|
||||
if (argc > 1) {
|
||||
PRINTK("\nUsage: swtmr [ID]\n");
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
timerID = OS_ALL_SWTMR_MASK;
|
||||
} else {
|
||||
timerID = strtoul((CHAR *)argv[0], &endPtr, 0);
|
||||
if ((endPtr == NULL) || (*endPtr != 0) || (timerID > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
|
||||
return OS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
|
||||
if (swtmr1->ucState == 0) {
|
||||
@@ -87,13 +112,13 @@ STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
|
||||
|
||||
if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
|
||||
PRINTK("\r\nThere is no swtmr was created!\n");
|
||||
return LOS_NOK;
|
||||
return OS_ERROR;
|
||||
}
|
||||
|
||||
if (timerID == OS_ALL_SWTMR_MASK) {
|
||||
OsPrintSwtmrMsgHead();
|
||||
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
|
||||
if (swtmr->ucState != 0) {
|
||||
OsPrintSwtmrMsgHead();
|
||||
OsPrintSwtmrMsg(swtmr);
|
||||
}
|
||||
}
|
||||
@@ -110,70 +135,6 @@ STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
STATIC VOID OsSwtmrTimeInfoShow(VOID)
|
||||
{
|
||||
UINT8 mode;
|
||||
SwtmrDebugData data;
|
||||
|
||||
PRINTK("SwtmrID Cpuid Mode Period(us) WaitTime(us) WaitMax(us) RTime(us) RTimeMax(us) ReTime(us)"
|
||||
" ReTimeMax(us) RunCount LostNum Handler\n");
|
||||
for (UINT32 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {
|
||||
if (!OsSwtmrDebugDataUsed(index)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
UINT32 ret = OsSwtmrDebugDataGet(index, &data, sizeof(SwtmrDebugData), &mode);
|
||||
if (ret != LOS_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
SwtmrDebugBase *base = &data.base;
|
||||
UINT64 waitTime = ((base->waitTime / base->waitCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
UINT64 waitTimeMax = (base->waitTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
UINT64 runTime = ((base->runTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
UINT64 runTimeMax = (base->runTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
UINT64 readyTime = ((base->readyTime / base->runCount) * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
UINT64 readyTimeMax = (base->readyTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
PRINTK("%4u%10u%7s%14u%13llu%12llu%10llu%13llu%10llu%14llu%15llu%11u%#12x\n",
|
||||
index, data.cpuid, g_shellSwtmrMode[mode], data.period * OS_US_PER_TICK, waitTime, waitTimeMax,
|
||||
runTime, runTimeMax, readyTime, readyTimeMax, base->runCount, base->times, data.handler);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const CHAR **argv)
|
||||
{
|
||||
UINT32 timerID;
|
||||
CHAR *endPtr = NULL;
|
||||
|
||||
if (argc > 1) {
|
||||
goto SWTMR_HELP;
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
timerID = OS_ALL_SWTMR_MASK;
|
||||
#ifdef LOSCFG_SWTMR_DEBUG
|
||||
} else if (strcmp("-t", argv[0]) == 0) {
|
||||
OsSwtmrTimeInfoShow();
|
||||
return LOS_OK;
|
||||
#endif
|
||||
} else {
|
||||
timerID = strtoul(argv[0], &endPtr, 0);
|
||||
if ((endPtr == NULL) || (*endPtr != 0) || (timerID > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
|
||||
PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
|
||||
return LOS_NOK;
|
||||
}
|
||||
}
|
||||
|
||||
return SwtmrBaseInfoGet(timerID);
|
||||
SWTMR_HELP:
|
||||
PRINTK("Usage:\n");
|
||||
PRINTK(" swtmr --- Information about all created software timers.\n");
|
||||
PRINTK(" swtmr ID --- Specifies information about a software timer.\n");
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);
|
||||
|
||||
#endif /* LOSCFG_SHELL */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
@@ -52,7 +52,7 @@
|
||||
#include "fs/file.h"
|
||||
#endif
|
||||
#include "los_sched_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
|
||||
|
||||
#define OS_PROCESS_MEM_INFO 0x2U
|
||||
#define OS_PROCESS_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB)))
|
||||
@@ -63,45 +63,46 @@
|
||||
#define OS_PROCESS_CPUP_LEN (g_processMaxNum * sizeof(CPUP_INFO_S))
|
||||
#define OS_PROCESS_AND_TASK_CPUP_LEN ((g_processMaxNum + g_taskMaxNum) * sizeof(CPUP_INFO_S))
|
||||
#define OS_PROCESS_CPUP_ALLINFO_LEN (OS_PROCESS_AND_TASK_CPUP_LEN * 3)
|
||||
STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
|
||||
STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
|
||||
#else
|
||||
#define OS_PROCESS_CPUP_ALLINFO_LEN 0
|
||||
#endif
|
||||
#define OS_PROCESS_ALL_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB) + sizeof(UINT32)) + \
|
||||
OS_PROCESS_CPUP_ALLINFO_LEN + OS_PROCESS_UID_INFO_LEN)
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpupAll = NULL;
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpup10s = NULL;
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *processCpup1s = NULL;
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpupAll = NULL;
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpup10s = NULL;
|
||||
LITE_OS_SEC_BSS STATIC CPUP_INFO_S *taskCpup1s = NULL;
|
||||
#endif
|
||||
|
||||
STATIC UINT32 *taskWaterLine = NULL;
|
||||
#define OS_INVALID_SEM_ID 0xFFFFFFFF
|
||||
#define OS_TASK_WATER_LINE_SIZE (g_taskMaxNum * sizeof(UINT32))
|
||||
#define OS_TASK_INFO_LEN (g_taskMaxNum * sizeof(LosTaskCB))
|
||||
#define OS_TASK_SCHED_INFO_LEN (g_taskMaxNum * sizeof(SchedParam))
|
||||
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32) + sizeof(SchedParam)))
|
||||
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32)))
|
||||
|
||||
#undef SHOW
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#if defined(LOSCFG_BLACKBOX) && defined(LOSCFG_SAVE_EXCINFO)
|
||||
#define SaveExcInfo(arg, ...) WriteExcInfoToBuf(arg, ##__VA_ARGS__)
|
||||
#else
|
||||
#define SaveExcInfo(arg, ...)
|
||||
#endif
|
||||
#define SHOW(arg...) do { \
|
||||
if (seqBuf != NULL) { \
|
||||
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
|
||||
#define PROCESS_INFO_SHOW(seqBuf, arg...) do { \
|
||||
if (seqBuf != NULL) { \
|
||||
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
|
||||
} else { \
|
||||
PRINTK(arg); \
|
||||
} \
|
||||
SaveExcInfo(arg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define SHOW(arg...) PRINTK(arg)
|
||||
#define PROCESS_INFO_SHOW(seqBuf, arg...) PRINTK(arg)
|
||||
#endif
|
||||
|
||||
#define VM_INDEX PROCESS_VM_INDEX
|
||||
#define SM_INDEX PROCESS_SM_INDEX
|
||||
#define PM_INDEX PROCESS_PM_INDEX
|
||||
#define CPUP_MULT LOS_CPUP_PRECISION_MULT
|
||||
|
||||
STATIC UINT8 *ConvertProcessModeToString(UINT16 mode)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdProcessMode(UINT16 mode)
|
||||
{
|
||||
if (mode == OS_KERNEL_MODE) {
|
||||
return (UINT8 *)"kernel";
|
||||
@@ -112,7 +113,7 @@ STATIC UINT8 *ConvertProcessModeToString(UINT16 mode)
|
||||
return (UINT8 *)"ERROR";
|
||||
}
|
||||
|
||||
STATIC UINT8 *ConvertSchedPolicyToString(UINT16 policy)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdSchedPolicy(UINT16 policy)
|
||||
{
|
||||
if (policy == LOS_SCHED_RR) {
|
||||
return (UINT8 *)"RR";
|
||||
@@ -125,7 +126,7 @@ STATIC UINT8 *ConvertSchedPolicyToString(UINT16 policy)
|
||||
return (UINT8 *)"ERROR";
|
||||
}
|
||||
|
||||
STATIC UINT8 *ConvertProcessStatusToString(UINT16 status)
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellProcessStatus(UINT16 status)
|
||||
{
|
||||
if (status & OS_PROCESS_STATUS_ZOMBIES) {
|
||||
return (UINT8 *)"Zombies";
|
||||
@@ -139,123 +140,118 @@ STATIC UINT8 *ConvertProcessStatusToString(UINT16 status)
|
||||
return (UINT8 *)"Pending";
|
||||
}
|
||||
|
||||
STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID OsShellCmdProcessTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
SHOW("\r\n PID PPID PGID UID Mode Status Policy Priority MTID TTotal");
|
||||
PROCESS_INFO_SHOW(seqBuf, "\r\n PID PPID PGID UID Status ");
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
PROCESS_INFO_SHOW(seqBuf, "VirtualMem ShareMem PhysicalMem ");
|
||||
}
|
||||
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
SHOW(" VirtualMem ShareMem PhysicalMem");
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
PROCESS_INFO_SHOW(seqBuf, "Policy Priority MTID TaskTotal Mode ");
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW(" CPUUSE10s");
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW(" PName\n");
|
||||
PROCESS_INFO_SHOW(seqBuf, " PName\n");
|
||||
}
|
||||
|
||||
STATIC VOID AllProcessDataShow(const LosProcessCB *pcbArray, const SchedParam *param,
|
||||
UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID OsShellCmdProcessInfoShow(const LosProcessCB *processCB, const INT32 *group,
|
||||
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const INT32 *group = (const INT32 *)((UINTPTR)pcbArray + OS_PROCESS_INFO_LEN);
|
||||
const UINT32 *procMemUsage = NULL;
|
||||
const INT32 *user = (const INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
const UINT32 *memArray = (const UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
#else
|
||||
(VOID)cpupInfo;
|
||||
#endif
|
||||
UINT32 pid = processCB->processID;
|
||||
PROCESS_INFO_SHOW(seqBuf, "%5u%6d%5d%10d%8s", pid, (INT32)processCB->parentProcessID, group[pid], user[pid],
|
||||
OsShellProcessStatus(processCB->processStatus));
|
||||
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = pcbArray + pid;
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
procMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
PROCESS_INFO_SHOW(seqBuf, "%#11x%#9x%#12x", procMemUsage[PROCESS_VM_INDEX], procMemUsage[PROCESS_SM_INDEX],
|
||||
procMemUsage[PROCESS_PM_INDEX]);
|
||||
}
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%4u.%-2u%7u.%-2u%6u.%-2u ",
|
||||
processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
|
||||
processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT,
|
||||
processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
|
||||
processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT,
|
||||
processCpup1s[pid].usage / LOS_CPUP_PRECISION_MULT,
|
||||
processCpup1s[pid].usage % LOS_CPUP_PRECISION_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
PROCESS_INFO_SHOW(seqBuf, "%6s%9u%5d%10u%7s ",
|
||||
OsShellCmdSchedPolicy(LOS_SCHED_RR), OS_TCB_FROM_TID(processCB->threadGroupID)->basePrio,
|
||||
(INT32)processCB->threadGroupID, processCB->threadNumber,
|
||||
OsShellCmdProcessMode(processCB->processMode));
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%7u.%-2u ",
|
||||
processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
|
||||
processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
PROCESS_INFO_SHOW(seqBuf, " %-32s\n", processCB->processName);
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdAllProcessInfoShow(const LosProcessCB *pcbArray, const INT32 *group,
|
||||
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const LosProcessCB *processCB = NULL;
|
||||
UINT32 pid;
|
||||
|
||||
for (pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
processCB = pcbArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SHOW("%5u%6d%5d%6d%7s%8s%7s%9u%5u%7u", pid, (INT32)processCB->parentProcessID, group[pid], user[pid],
|
||||
ConvertProcessModeToString(processCB->processMode), ConvertProcessStatusToString(processCB->processStatus),
|
||||
ConvertSchedPolicyToString(LOS_SCHED_RR), param[processCB->threadGroupID].basePrio,
|
||||
processCB->threadGroupID, processCB->threadNumber);
|
||||
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
const UINT32 *memUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
SHOW("%#11x%#9x%#12x", memUsage[VM_INDEX], memUsage[SM_INDEX], memUsage[PM_INDEX]);
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT,
|
||||
cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT,
|
||||
cpup1s[pid].usage / CPUP_MULT, cpup1s[pid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%7u.%-2u ", cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW("%-32s\n", processCB->processName);
|
||||
OsShellCmdProcessInfoShow(processCB, group, memArray, seqBuf, flag);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
STATIC VOID ProcessMemUsageGet(LosProcessCB *pcbArray)
|
||||
STATIC VOID OsProcessMemUsageGet(UINT32 *memArray)
|
||||
{
|
||||
UINT32 intSave, memUsed;
|
||||
UINT32 *memArray = (UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
UINT32 pid;
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 *proMemUsage = NULL;
|
||||
|
||||
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = g_processCBArray + pid;
|
||||
UINT32 *proMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
for (pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
processCB = g_processCBArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
LosVmSpace *vmSpace = processCB->vmSpace;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
proMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
|
||||
/* Process memory usage statistics, idle task defaults to 0 */
|
||||
if (pid == OsGetIdleProcessID()) {
|
||||
proMemUsage[VM_INDEX] = 0;
|
||||
proMemUsage[SM_INDEX] = 0;
|
||||
proMemUsage[PM_INDEX] = 0;
|
||||
} else if (vmSpace == LOS_GetKVmSpace()) {
|
||||
(VOID)OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
|
||||
proMemUsage[VM_INDEX] = proMemUsage[PM_INDEX];
|
||||
proMemUsage[PROCESS_VM_INDEX] = 0;
|
||||
proMemUsage[PROCESS_SM_INDEX] = 0;
|
||||
proMemUsage[PROCESS_PM_INDEX] = 0;
|
||||
} else {
|
||||
memUsed = OsShellCmdProcessVmUsage(vmSpace);
|
||||
if (memUsed == 0) {
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
continue;
|
||||
}
|
||||
proMemUsage[VM_INDEX] = memUsed;
|
||||
memUsed = OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
|
||||
if (memUsed == 0) {
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
}
|
||||
proMemUsage[PROCESS_VM_INDEX] = OsShellCmdProcessVmUsage(processCB->vmSpace);
|
||||
OsShellCmdProcessPmUsage(processCB->vmSpace, &proMemUsage[PROCESS_SM_INDEX],
|
||||
&proMemUsage[PROCESS_PM_INDEX]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define OS_TASK_STATUS_MASK 0x00FF
|
||||
STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam)
|
||||
STATIC VOID OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group,
|
||||
UINT32 **memArray, LosTaskCB **tcbArray,
|
||||
UINT16 flag)
|
||||
{
|
||||
INT32 *group = (INT32 *)((UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN);
|
||||
INT32 *user = (INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
SchedParam *param = (SchedParam *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
|
||||
*schedParam = param;
|
||||
*group = (INT32 *)((UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN);
|
||||
INT32 *user = (INT32 *)((UINTPTR)*group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
|
||||
const LosTaskCB *taskCB = *tcbArray + tid;
|
||||
LosTaskCB *taskCB = *tcbArray + tid;
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
continue;
|
||||
}
|
||||
@@ -264,19 +260,18 @@ STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedP
|
||||
if (!OsProcessIsDead(processCB) && !OsProcessIsInit(processCB)) {
|
||||
processCB->processStatus |= (taskCB->taskStatus & OS_TASK_STATUS_MASK);
|
||||
}
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m[tid]);
|
||||
}
|
||||
|
||||
for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = *pcbArray + pid;
|
||||
LosProcessCB *processCB = *pcbArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (processCB->group != NULL) {
|
||||
group[processCB->processID] = processCB->group->groupID;
|
||||
(*group)[processCB->processID] = processCB->group->groupID;
|
||||
} else {
|
||||
group[processCB->processID] = -1;
|
||||
(*group)[processCB->processID] = -1;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
@@ -289,28 +284,47 @@ STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedP
|
||||
user[processCB->processID] = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID ProcessInfoShow(const LosProcessCB *pcbArray, const SchedParam *param,
|
||||
UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
UINT32 pid = OsGetIdleProcessID();
|
||||
UINT32 sysUsage = LOS_CPUP_PRECISION - cpupAll[pid].usage;
|
||||
processCpupAll = (CPUP_INFO_S *)((UINTPTR)user + OS_PROCESS_UID_INFO_LEN);
|
||||
taskCpupAll = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_CPUP_LEN);
|
||||
processCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
taskCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_CPUP_LEN);
|
||||
processCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
taskCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup1s + OS_PROCESS_CPUP_LEN);
|
||||
|
||||
SHOW("\n allCpu(%%): %4u.%02u sys, %4u.%02u idle\n", sysUsage / CPUP_MULT, sysUsage % CPUP_MULT,
|
||||
cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_ALL_TIME, processCpupAll, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_TEN_SECONDS, processCpup10s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_ONE_SECONDS, processCpup1s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
#endif
|
||||
|
||||
ProcessInfoTitle(seqBuf, flag);
|
||||
AllProcessDataShow(pcbArray, param, cpupInfo, seqBuf, flag);
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
*memArray = (UINT32 *)((UINTPTR)*pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
OsProcessMemUsageGet(*memArray);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
STATIC VOID OsShellCmdProcessInfoData(const LosProcessCB *pcbArray, const INT32 *group,
|
||||
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
UINT32 pid = OsGetIdleProcessID();
|
||||
UINT32 sysUsage = LOS_CPUP_PRECISION - processCpupAll[pid].usage;
|
||||
|
||||
PROCESS_INFO_SHOW(seqBuf, "\n allCpu(%%): %4u.%02u sys, %4u.%02u idle\n",
|
||||
sysUsage / LOS_CPUP_PRECISION_MULT,
|
||||
sysUsage % LOS_CPUP_PRECISION_MULT,
|
||||
processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
|
||||
processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT);
|
||||
#endif
|
||||
|
||||
OsShellCmdProcessTitle(seqBuf, flag);
|
||||
OsShellCmdAllProcessInfoShow(pcbArray, group, memArray, seqBuf, flag);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
|
||||
{
|
||||
if (taskStatus & OS_TASK_STATUS_INIT) {
|
||||
return (UINT8 *)"Init";
|
||||
@@ -318,8 +332,6 @@ STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
return (UINT8 *)"Running";
|
||||
} else if (taskStatus & OS_TASK_STATUS_READY) {
|
||||
return (UINT8 *)"Ready";
|
||||
} else if (taskStatus & OS_TASK_STATUS_FROZEN) {
|
||||
return (UINT8 *)"Frozen";
|
||||
} else if (taskStatus & OS_TASK_STATUS_SUSPENDED) {
|
||||
return (UINT8 *)"Suspended";
|
||||
} else if (taskStatus & OS_TASK_STATUS_DELAY) {
|
||||
@@ -337,30 +349,26 @@ STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
return (UINT8 *)"Invalid";
|
||||
}
|
||||
|
||||
STATIC VOID TaskWaterLineGet(UINTPTR waterLineBase, LosTaskCB *tcbArray)
|
||||
STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 *taskWaterLine = (UINT32 *)waterLineBase;
|
||||
const LosTaskCB *taskCB = NULL;
|
||||
UINT32 loop;
|
||||
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = g_taskCBArray + tid;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
for (loop = 0; loop < g_taskMaxNum; ++loop) {
|
||||
taskCB = allTaskArray + loop;
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
tcbArray[tid].taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
continue;
|
||||
}
|
||||
|
||||
(VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
|
||||
(const UINTPTR *)taskCB->topOfStack, &taskWaterLine[taskCB->taskID]);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
#define OS_PEND_REASON_MAX_LEN 20
|
||||
|
||||
STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
STATIC CHAR *OsShellCheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
{
|
||||
*lockID = taskCB->waitID;
|
||||
switch (taskCB->waitFlag) {
|
||||
@@ -395,23 +403,24 @@ STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC VOID TaskPendingReasonInfoGet(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
STATIC VOID OsShellCmdCheckTaskPend(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
{
|
||||
CHAR *reason = NULL;
|
||||
LosTaskCB *owner = NULL;
|
||||
|
||||
if (!(taskCB->taskStatus & OS_TASK_STATUS_PENDING)) {
|
||||
reason = (CHAR *)ConvertTaskStatusToString(taskCB->taskStatus);
|
||||
reason = (CHAR *)OsShellCmdConvertTskStatus(taskCB->taskStatus);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
reason = CheckTaskWaitFlag(taskCB, lockID);
|
||||
reason = OsShellCheckTaskWaitFlag(taskCB, lockID);
|
||||
if (reason == NULL) {
|
||||
reason = "Others";
|
||||
}
|
||||
|
||||
if (taskCB->taskMux != NULL) {
|
||||
*lockID = (UINTPTR)taskCB->taskMux;
|
||||
LosTaskCB *owner = ((LosMux *)taskCB->taskMux)->owner;
|
||||
owner = ((LosMux *)taskCB->taskMux)->owner;
|
||||
if (owner != NULL) {
|
||||
if (snprintf_s(pendReason, maxLen, maxLen - 1, "Mutex-%u", owner->taskID) == EOK) {
|
||||
return;
|
||||
@@ -426,169 +435,129 @@ EXIT:
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID TaskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
SHOW("\r\n TID PID");
|
||||
PROCESS_INFO_SHOW(seqBuf, "\r\n TID PID ");
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SHOW(" Affi CPU");
|
||||
PROCESS_INFO_SHOW(seqBuf, "Affi CPU ");
|
||||
#endif
|
||||
SHOW(" Status Policy Priority StackSize WaterLine");
|
||||
PROCESS_INFO_SHOW(seqBuf, " Status StackSize WaterLine ");
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
SHOW(" StackPoint TopOfStack PendReason LockID");
|
||||
PROCESS_INFO_SHOW(seqBuf, " StackPoint TopOfStack PendReason LockID ");
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, "Policy Priority ");
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW(" CPUUSE10s ");
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW(" TaskName\n");
|
||||
PROCESS_INFO_SHOW(seqBuf, " MEMUSE TaskName\n");
|
||||
}
|
||||
|
||||
STATIC VOID AllTaskInfoDataShow(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const SchedParam *param = (const SchedParam *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN);
|
||||
const UINT32 *waterLine = (const UINT32 *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN);
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
const CPUP_INFO_S *cpupAll = NULL;
|
||||
const CPUP_INFO_S *cpup10s = NULL;
|
||||
const CPUP_INFO_S *cpup1s = NULL;
|
||||
TaskCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
|
||||
#else
|
||||
(VOID)cpupInfo;
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
UINTPTR lockID = 0;
|
||||
CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
|
||||
#endif
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = allTaskArray + tid;
|
||||
PROCESS_INFO_SHOW(seqBuf, " %4u%5u", taskCB->taskID, taskCB->processID);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
|
||||
#endif
|
||||
|
||||
PROCESS_INFO_SHOW(seqBuf, "%12s%#10x%#10x", OsShellCmdConvertTskStatus(taskCB->taskStatus),
|
||||
taskCB->stackSize, taskWaterLine[taskCB->taskID]);
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%4u.%-2u%7u.%-2u%6u.%-2u ",
|
||||
taskCpupAll[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
|
||||
taskCpupAll[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT,
|
||||
taskCpup10s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
|
||||
taskCpup10s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT,
|
||||
taskCpup1s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
|
||||
taskCpup1s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
OsShellCmdCheckTaskPend(taskCB, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
|
||||
PROCESS_INFO_SHOW(seqBuf, "%#12x%#12x%11s%#11x", taskCB->stackPointer, taskCB->topOfStack, pendReason, lockID);
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, "%7s%9u", OsShellCmdSchedPolicy(taskCB->policy), taskCB->priority);
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%7u.%-2u ",
|
||||
taskCpup10s[taskCB->taskID].usage / LOS_CPUP_PRECISION_MULT,
|
||||
taskCpup10s[taskCB->taskID].usage % LOS_CPUP_PRECISION_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
PROCESS_INFO_SHOW(seqBuf, "%#10x %-32s\n", OsTaskMemUsage(taskCB->taskID), taskCB->taskName);
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdAllTaskInfoData(const LosTaskCB *allTaskArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const LosTaskCB *taskCB = NULL;
|
||||
UINT32 pid;
|
||||
UINT32 loop;
|
||||
|
||||
for (pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
for (loop = 0; loop < g_taskMaxNum; ++loop) {
|
||||
taskCB = allTaskArray + loop;
|
||||
if (OsTaskIsUnused(taskCB) || (taskCB->processID != pid)) {
|
||||
continue;
|
||||
}
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
UINTPTR lockID = 0;
|
||||
CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
|
||||
#endif
|
||||
SHOW(" %4u%5u", tid, taskCB->processID);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
SHOW("%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
|
||||
#endif
|
||||
SHOW("%9s%7s%9u%#10x%#10x", ConvertTaskStatusToString(taskCB->taskStatus),
|
||||
ConvertSchedPolicyToString(param[tid].policy), param[tid].priority, taskCB->stackSize, waterLine[tid]);
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[tid].usage / CPUP_MULT, cpupAll[tid].usage % CPUP_MULT,
|
||||
cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT,
|
||||
cpup1s[tid].usage / CPUP_MULT, cpup1s[tid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
TaskPendingReasonInfoGet(taskCB, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
|
||||
SHOW("%#12x%#12x%11s%#11x", taskCB->stackPointer, taskCB->topOfStack, pendReason, lockID);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
SHOW("%8u.%-2u ", cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT);
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
SHOW(" %-32s\n", taskCB->taskName);
|
||||
OsShellTskInfoData(taskCB, seqBuf, flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID TaskInfoData(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTaskArray, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
TaskInfoTitle(seqBuf, flag);
|
||||
AllTaskInfoDataShow(allTaskArray, cpupInfo, seqBuf, flag);
|
||||
OsShellCmdTskInfoTitle(seqBuf, flag);
|
||||
OsShellCmdAllTaskInfoData(allTaskArray, seqBuf, flag);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
|
||||
const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
|
||||
STATIC VOID OsProcessAndTaskInfoGet(LosProcessCB **pcbArray, INT32 **group, LosTaskCB **tcbArray,
|
||||
UINT32 **memArray, UINT16 flag)
|
||||
{
|
||||
UINTPTR processCpupAll = base + OS_PROCESS_UID_INFO_LEN;
|
||||
*cpupAll = (CPUP_INFO_S *)(processCpupAll + OS_PROCESS_CPUP_LEN);
|
||||
UINTPTR processCpup10s = processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN;
|
||||
*cpup10s = (CPUP_INFO_S *)(processCpup10s + OS_PROCESS_CPUP_LEN);
|
||||
UINTPTR processCpup1s = processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN;
|
||||
*cpup1s = (CPUP_INFO_S *)(processCpup1s + OS_PROCESS_CPUP_LEN);
|
||||
}
|
||||
|
||||
STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
|
||||
const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
|
||||
{
|
||||
*cpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
|
||||
*cpup10s = (CPUP_INFO_S *)((UINTPTR)*cpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
*cpup1s = (CPUP_INFO_S *)((UINTPTR)*cpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
}
|
||||
|
||||
STATIC VOID TaskCpupInfoGet(UINTPTR base)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
CPUP_INFO_S *processCpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
|
||||
CPUP_INFO_S *processCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
CPUP_INFO_S *processCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_ALL_TIME, processCpupAll, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_TEN_SECONDS, processCpup10s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_ONE_SECONDS, processCpup1s, OS_PROCESS_AND_TASK_CPUP_LEN);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* | pcb | group | user | task and process cpup | process mem | tcb | sched param | task water line |
|
||||
*/
|
||||
STATIC VOID ProcessAndTaskInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray,
|
||||
SchedParam **schedParam, UINTPTR *cpupInfo, UINT16 flag)
|
||||
{
|
||||
UINT32 intSave;
|
||||
BOOL lockFlag = FALSE;
|
||||
UINT32 intSave = 0;
|
||||
UINT32 processInfoLen = OS_PROCESS_ALL_INFO_LEN;
|
||||
|
||||
if (LOS_SpinHeld(&g_taskSpin) == FALSE) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
lockFlag = TRUE;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
processInfoLen += OS_PROCESS_MEM_ALL_INFO_LEN;
|
||||
}
|
||||
#endif
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s(*pcbArray, OS_PROCESS_INFO_LEN, g_processCBArray, OS_PROCESS_INFO_LEN);
|
||||
*tcbArray = (LosTaskCB *)((UINTPTR)*pcbArray + processInfoLen);
|
||||
(VOID)memcpy_s(*tcbArray, OS_TASK_INFO_LEN, g_taskCBArray, OS_TASK_INFO_LEN);
|
||||
|
||||
ProcessInfoGet(pcbArray, tcbArray, schedParam);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
*cpupInfo = (UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN + OS_PROCESS_GROUP_INFO_LEN;
|
||||
TaskCpupInfoGet(*cpupInfo);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
ProcessMemUsageGet(*pcbArray);
|
||||
OsProcessInfoGet(pcbArray, group, memArray, tcbArray, flag);
|
||||
taskWaterLine = (UINT32 *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
|
||||
OsShellCmdTaskWaterLineGet(*tcbArray);
|
||||
if (lockFlag == TRUE) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
TaskWaterLineGet((UINTPTR)*tcbArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN, *tcbArray);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
UINT32 size;
|
||||
LosProcessCB *pcbArray = NULL;
|
||||
INT32 *group = NULL;
|
||||
LosTaskCB *tcbArray = NULL;
|
||||
SchedParam *schedParam = NULL;
|
||||
UINTPTR cpupInfo = 0;
|
||||
UINT32 *memArray = NULL;
|
||||
|
||||
if (taskID == OS_ALL_TASK_MASK) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
@@ -602,9 +571,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf,
|
||||
return LOS_NOK;
|
||||
}
|
||||
(VOID)memset_s(pcbArray, size, 0, size);
|
||||
ProcessAndTaskInfoGet(&pcbArray, &tcbArray, &schedParam, &cpupInfo, flag);
|
||||
ProcessInfoShow(pcbArray, schedParam, cpupInfo, seqBuf, flag);
|
||||
TaskInfoData(tcbArray, cpupInfo, seqBuf, flag);
|
||||
OsProcessAndTaskInfoGet(&pcbArray, &group, &tcbArray, &memArray, flag);
|
||||
OsShellCmdProcessInfoData(pcbArray, group, memArray, seqBuf, flag);
|
||||
OsShellCmdTskInfoData(tcbArray, seqBuf, flag);
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pcbArray);
|
||||
}
|
||||
@@ -626,20 +595,16 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
|
||||
if (argc == 1) {
|
||||
if (strcmp("-a", argv[0]) == 0) {
|
||||
flag |= OS_PROCESS_INFO_ALL;
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
} else if (strcmp("-i", argv[0]) == 0) {
|
||||
if (!OsShellShowTickResponse()) {
|
||||
if (!OsShellShowTickRespo()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else if (strcmp("-t", argv[0]) == 0) {
|
||||
if (!OsShellShowSchedStatistics()) {
|
||||
if (!OsShellShowSchedParam()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else {
|
||||
goto TASK_HELP;
|
||||
}
|
||||
@@ -649,9 +614,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
|
||||
|
||||
TASK_HELP:
|
||||
PRINTK("Unknown option: %s\n", argv[0]);
|
||||
PRINTK("Usage:\n");
|
||||
PRINTK(" task --- Basic information about all created processes.\n");
|
||||
PRINTK(" task -a --- Complete information about all created processes.\n");
|
||||
PRINTK("usage: task or task -a\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,11 @@ VOID OsLockDepCheckIn(SPIN_LOCK_S *lock)
|
||||
{
|
||||
UINT32 intSave;
|
||||
enum LockDepErrType checkResult = LOCKDEP_SUCCESS;
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
VOID *requestAddr = (VOID *)__builtin_return_address(1);
|
||||
#else
|
||||
VOID *requestAddr = (VOID *)__builtin_return_address(0);
|
||||
#endif
|
||||
LosTaskCB *current = OsCurrTaskGet();
|
||||
LockDep *lockDep = ¤t->lockDep;
|
||||
LosTaskCB *lockOwner = NULL;
|
||||
@@ -271,8 +275,12 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
|
||||
{
|
||||
UINT32 intSave;
|
||||
INT32 depth;
|
||||
enum LockDepErrType checkResult;
|
||||
enum LockDepErrType checkResult = LOCKDEP_SUCCESS;
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
VOID *requestAddr = (VOID *)__builtin_return_address(1);
|
||||
#else
|
||||
VOID *requestAddr = (VOID *)__builtin_return_address(0);
|
||||
#endif
|
||||
LosTaskCB *current = OsCurrTaskGet();
|
||||
LosTaskCB *owner = NULL;
|
||||
LockDep *lockDep = NULL;
|
||||
|
||||
@@ -62,7 +62,7 @@ VOID OsMpScheduleHandler(VOID)
|
||||
* set schedule flag to differ from wake function,
|
||||
* so that the scheduler can be triggered at the end of irq.
|
||||
*/
|
||||
OsSchedRunqueuePendingSet();
|
||||
OsSchedRunQuePendingSet();
|
||||
}
|
||||
|
||||
VOID OsMpHaltHandler(VOID)
|
||||
|
||||
323
kernel/base/mp/los_stat.c
Normal file
323
kernel/base/mp/los_stat.c
Normal file
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_task_pri.h"
|
||||
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SCHED_STATISTICS
|
||||
#define HIGHTASKPRI 16
|
||||
#define NS_PER_MS 1000000
|
||||
#define DECIMAL_TO_PERCENTAGE 100
|
||||
|
||||
typedef struct {
|
||||
UINT64 idleRuntime;
|
||||
UINT64 idleStarttime;
|
||||
UINT64 highTaskRuntime;
|
||||
UINT64 highTaskStarttime;
|
||||
UINT64 spinWaitRuntime;
|
||||
UINT64 sumPriority;
|
||||
UINT32 prioritySwitch;
|
||||
UINT32 highTaskSwitch;
|
||||
UINT32 contexSwitch;
|
||||
UINT32 hwiNum;
|
||||
UINT32 ipiIrqNum;
|
||||
} MpStatPercpu;
|
||||
|
||||
STATIC BOOL g_mpStaticStartFlag = FALSE;
|
||||
STATIC UINT64 g_mpStaticStartTime;
|
||||
STATIC MpStatPercpu g_mpStatPercpu[LOSCFG_KERNEL_SMP_CORE_NUM] = {0};
|
||||
|
||||
STATIC VOID OsMpSchedStatistics(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
UINT32 cpuid;
|
||||
UINT32 idleTaskID;
|
||||
UINT64 now, runtime;
|
||||
|
||||
if (g_mpStaticStartFlag != TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpuid = ArchCurrCpuid();
|
||||
idleTaskID = OsGetIdleTaskId();
|
||||
now = LOS_CurrNanosec();
|
||||
|
||||
g_mpStatPercpu[cpuid].contexSwitch++;
|
||||
|
||||
if ((runTask->taskID != idleTaskID) && (newTask->taskID == idleTaskID)) {
|
||||
g_mpStatPercpu[cpuid].idleStarttime = now;
|
||||
}
|
||||
|
||||
if ((runTask->taskID == idleTaskID) && (newTask->taskID != idleTaskID)) {
|
||||
runtime = now - g_mpStatPercpu[cpuid].idleStarttime;
|
||||
g_mpStatPercpu[cpuid].idleRuntime += runtime;
|
||||
g_mpStatPercpu[cpuid].idleStarttime = 0;
|
||||
}
|
||||
|
||||
if ((runTask->priority >= HIGHTASKPRI) && (newTask->priority < HIGHTASKPRI)) {
|
||||
g_mpStatPercpu[cpuid].highTaskStarttime = now;
|
||||
}
|
||||
|
||||
if ((runTask->priority < HIGHTASKPRI) && (newTask->priority >= HIGHTASKPRI)) {
|
||||
runtime = now - g_mpStatPercpu[cpuid].highTaskStarttime;
|
||||
g_mpStatPercpu[cpuid].highTaskRuntime += runtime;
|
||||
g_mpStatPercpu[cpuid].highTaskStarttime = 0;
|
||||
}
|
||||
|
||||
if (newTask->priority < HIGHTASKPRI) {
|
||||
g_mpStatPercpu[cpuid].highTaskSwitch++;
|
||||
}
|
||||
|
||||
if (newTask->taskID != idleTaskID) {
|
||||
g_mpStatPercpu[cpuid].sumPriority += newTask->priority;
|
||||
g_mpStatPercpu[cpuid].prioritySwitch++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsSchedStatistics(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
UINT64 runtime;
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
UINT64 now = LOS_CurrNanosec();
|
||||
|
||||
SchedStat *schedRun = &runTask->schedStat;
|
||||
SchedStat *schedNew = &newTask->schedStat;
|
||||
SchedPercpu *cpuRun = &schedRun->schedPercpu[cpuid];
|
||||
SchedPercpu *cpuNew = &schedNew->schedPercpu[cpuid];
|
||||
|
||||
/* calculate one chance of running time */
|
||||
runtime = now - schedRun->startRuntime;
|
||||
|
||||
/* add running timer to running task statistics */
|
||||
cpuRun->runtime += runtime;
|
||||
schedRun->allRuntime += runtime;
|
||||
|
||||
/* add context switch counters and schedule start time */
|
||||
cpuNew->contexSwitch++;
|
||||
schedNew->allContextSwitch++;
|
||||
schedNew->startRuntime = now;
|
||||
OsMpSchedStatistics(runTask, newTask);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsSpinWaitStatistics(UINT64 spinWaitRuntime)
|
||||
{
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
g_mpStatPercpu[cpuid].spinWaitRuntime += spinWaitRuntime;
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsHwiStatistics(size_t intNum)
|
||||
{
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
|
||||
if ((g_mpStaticStartFlag != TRUE) || (intNum == OS_TICK_INT_NUM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_mpStatPercpu[cpuid].hwiNum++;
|
||||
/* 16: 0~15 is ipi interrupts */
|
||||
if (intNum < 16) {
|
||||
g_mpStatPercpu[cpuid].ipiIrqNum++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdDumpSched(VOID)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 loop;
|
||||
UINT32 cpuid;
|
||||
UINT32 affinity;
|
||||
|
||||
PRINTK("\n");
|
||||
PRINTK("Task TID Total Time Total CST "
|
||||
"CPU Time CST\n");
|
||||
PRINTK("---- --- ------------------ ---------- -"
|
||||
"--- ------------------ ----------\n");
|
||||
|
||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
affinity = (UINT32)taskCB->cpuAffiMask;
|
||||
|
||||
PRINTK("%-30s0x%-6x%+16lf ms %10u\n", taskCB->taskName, taskCB->taskID,
|
||||
(DOUBLE)(taskCB->schedStat.allRuntime) / NS_PER_MS,
|
||||
taskCB->schedStat.allContextSwitch);
|
||||
|
||||
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
|
||||
if (!((1U << cpuid) & affinity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PRINTK(" "
|
||||
"CPU%u %+16lf ms %12u\n", cpuid,
|
||||
(DOUBLE)(taskCB->schedStat.schedPercpu[cpuid].runtime) / NS_PER_MS,
|
||||
taskCB->schedStat.schedPercpu[cpuid].contexSwitch);
|
||||
}
|
||||
}
|
||||
|
||||
PRINTK("\n");
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStart(VOID)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 loop;
|
||||
UINT32 cpuid = 0;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
if (g_mpStaticStartFlag) {
|
||||
PRINT_WARN("mp static has started\n");
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_mpStaticStartTime = LOS_CurrNanosec();
|
||||
|
||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
cpuid = taskCB->currCpu;
|
||||
#endif
|
||||
if ((UINT32)(OS_TASK_INVALID_CPUID) == cpuid) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(taskCB->taskName, "Idle")) {
|
||||
g_mpStatPercpu[cpuid].idleStarttime = g_mpStaticStartTime;
|
||||
}
|
||||
if (taskCB->priority < HIGHTASKPRI) {
|
||||
g_mpStatPercpu[cpuid].highTaskStarttime = g_mpStaticStartTime;
|
||||
g_mpStatPercpu[cpuid].highTaskSwitch++;
|
||||
}
|
||||
if (strcmp(taskCB->taskName, "Idle")) {
|
||||
g_mpStatPercpu[cpuid].sumPriority += taskCB->priority;
|
||||
g_mpStatPercpu[cpuid].prioritySwitch++;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_mpStaticStartFlag = TRUE;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
PRINTK("mp static start\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsMpStaticShow(UINT64 mpStaticPastTime)
|
||||
{
|
||||
UINT32 cpuid;
|
||||
PRINTK("\n");
|
||||
PRINTK("Passed Time: %+16lf ms\n", (DOUBLE)mpStaticPastTime / NS_PER_MS);
|
||||
PRINTK("--------------------------------\n");
|
||||
PRINTK("CPU Idle(%%) schedule noTick Hwi MP Hwi MP Loss(%%) "
|
||||
"avg PRI HiTSK(%%) HiTSK SCH HiTSK P(ms)\n");
|
||||
PRINTK("---- --------- ---------- ---------- ---------- ---------- "
|
||||
"---------- ---------- ---------- ----------\n");
|
||||
|
||||
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
|
||||
PRINTK("CPU%u %+10lf%14u%14u%14u %+11lf %+11lf %+11lf%14u %+11lf\n", cpuid,
|
||||
((DOUBLE)(g_mpStatPercpu[cpuid].idleRuntime) / mpStaticPastTime) * DECIMAL_TO_PERCENTAGE,
|
||||
g_mpStatPercpu[cpuid].contexSwitch,
|
||||
g_mpStatPercpu[cpuid].hwiNum,
|
||||
g_mpStatPercpu[cpuid].ipiIrqNum,
|
||||
((DOUBLE)(g_mpStatPercpu[cpuid].spinWaitRuntime) / mpStaticPastTime) * DECIMAL_TO_PERCENTAGE,
|
||||
(g_mpStatPercpu[cpuid].prioritySwitch == 0) ? OS_TASK_PRIORITY_LOWEST :
|
||||
((DOUBLE)(g_mpStatPercpu[cpuid].sumPriority) / (g_mpStatPercpu[cpuid].prioritySwitch)),
|
||||
((DOUBLE)(g_mpStatPercpu[cpuid].highTaskRuntime) / mpStaticPastTime) * DECIMAL_TO_PERCENTAGE,
|
||||
g_mpStatPercpu[cpuid].highTaskSwitch,
|
||||
(g_mpStatPercpu[cpuid].highTaskSwitch == 0) ? 0 :
|
||||
((DOUBLE)(g_mpStatPercpu[cpuid].highTaskRuntime) / (g_mpStatPercpu[cpuid].highTaskSwitch)) / NS_PER_MS);
|
||||
}
|
||||
|
||||
PRINTK("\n");
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStop(VOID)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 loop;
|
||||
UINT32 cpuid = 0;
|
||||
UINT64 mpStaticStopTime;
|
||||
UINT64 mpStaticPastTime;
|
||||
UINT64 runtime;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
if (g_mpStaticStartFlag != TRUE) {
|
||||
PRINT_WARN("Please set mp static start\n");
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
g_mpStaticStartFlag = FALSE;
|
||||
mpStaticStopTime = LOS_CurrNanosec();
|
||||
mpStaticPastTime = mpStaticStopTime - g_mpStaticStartTime;
|
||||
|
||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
cpuid = taskCB->currCpu;
|
||||
#endif
|
||||
if (cpuid == (UINT32)(OS_TASK_INVALID_CPUID)) {
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(taskCB->taskName, "Idle")) {
|
||||
runtime = mpStaticStopTime - g_mpStatPercpu[cpuid].idleStarttime;
|
||||
g_mpStatPercpu[cpuid].idleRuntime += runtime;
|
||||
g_mpStatPercpu[cpuid].idleStarttime = 0;
|
||||
}
|
||||
if (taskCB->priority < HIGHTASKPRI) {
|
||||
runtime = mpStaticStopTime - g_mpStatPercpu[cpuid].highTaskStarttime;
|
||||
g_mpStatPercpu[cpuid].highTaskRuntime += runtime;
|
||||
g_mpStatPercpu[cpuid].highTaskStarttime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
OsMpStaticShow(mpStaticPastTime);
|
||||
|
||||
(VOID)memset_s(g_mpStatPercpu, sizeof(g_mpStatPercpu), 0, sizeof(g_mpStatPercpu));
|
||||
g_mpStaticStartTime = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_sched_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
STATIC VOID IdleDequeue(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC VOID IdleEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC UINT32 IdleWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks);
|
||||
STATIC VOID IdleWake(LosTaskCB *resumedTask);
|
||||
STATIC UINT32 IdleSchedParamGet(const LosTaskCB *taskCB, SchedParam *param);
|
||||
STATIC VOID IdleYield(LosTaskCB *runTask);
|
||||
STATIC VOID IdleStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC UINT32 IdleResume(LosTaskCB *taskCB, BOOL *needSched);
|
||||
STATIC UINT64 IdleTimeSliceGet(const LosTaskCB *taskCB);
|
||||
STATIC VOID IdleTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime);
|
||||
STATIC INT32 IdleParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2);
|
||||
STATIC VOID IdlePriorityInheritance(LosTaskCB *owner, const SchedParam *param);
|
||||
STATIC VOID IdlePriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param);
|
||||
|
||||
const STATIC SchedOps g_idleOps = {
|
||||
.dequeue = IdleDequeue,
|
||||
.enqueue = IdleEnqueue,
|
||||
.wait = IdleWait,
|
||||
.wake = IdleWake,
|
||||
.schedParamModify = NULL,
|
||||
.schedParamGet = IdleSchedParamGet,
|
||||
.delay = NULL,
|
||||
.yield = IdleYield,
|
||||
.start = IdleStartToRun,
|
||||
.exit = NULL,
|
||||
.suspend = NULL,
|
||||
.resume = IdleResume,
|
||||
.deadlineGet = IdleTimeSliceGet,
|
||||
.timeSliceUpdate = IdleTimeSliceUpdate,
|
||||
.schedParamCompare = IdleParamCompare,
|
||||
.priorityInheritance = IdlePriorityInheritance,
|
||||
.priorityRestore = IdlePriorityRestore,
|
||||
};
|
||||
|
||||
STATIC VOID IdleTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime)
|
||||
{
|
||||
(VOID)rq;
|
||||
|
||||
taskCB->startTime = currTime;
|
||||
}
|
||||
|
||||
STATIC UINT64 IdleTimeSliceGet(const LosTaskCB *taskCB)
|
||||
{
|
||||
(VOID)taskCB;
|
||||
return (OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION);
|
||||
}
|
||||
|
||||
STATIC VOID IdleEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
(VOID)rq;
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_BLOCKED;
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_READY;
|
||||
}
|
||||
|
||||
STATIC VOID IdleDequeue(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
(VOID)rq;
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
|
||||
}
|
||||
|
||||
STATIC VOID IdleStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
IdleDequeue(rq, taskCB);
|
||||
}
|
||||
|
||||
STATIC VOID IdleYield(LosTaskCB *runTask)
|
||||
{
|
||||
(VOID)runTask;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC UINT32 IdleWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks)
|
||||
{
|
||||
(VOID)runTask;
|
||||
(VOID)list;
|
||||
(VOID)ticks;
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
STATIC VOID IdleWake(LosTaskCB *resumedTask)
|
||||
{
|
||||
LOS_ListDelete(&resumedTask->pendList);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PENDING;
|
||||
|
||||
if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
|
||||
OsSchedTimeoutQueueDelete(resumedTask);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
|
||||
}
|
||||
|
||||
if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
resumedTask->schedStat.pendTime += OsGetCurrSchedTimeCycle() - resumedTask->startTime;
|
||||
resumedTask->schedStat.pendCount++;
|
||||
#endif
|
||||
resumedTask->ops->enqueue(OsSchedRunqueue(), resumedTask);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 IdleResume(LosTaskCB *taskCB, BOOL *needSched)
|
||||
{
|
||||
*needSched = FALSE;
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_SUSPENDED;
|
||||
if (!OsTaskIsBlocked(taskCB)) {
|
||||
taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
|
||||
*needSched = TRUE;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 IdleSchedParamGet(const LosTaskCB *taskCB, SchedParam *param)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
param->policy = sched->policy;
|
||||
param->basePrio = sched->basePrio;
|
||||
param->priority = sched->priority;
|
||||
param->timeSlice = 0;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 IdleParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC VOID IdlePriorityInheritance(LosTaskCB *owner, const SchedParam *param)
|
||||
{
|
||||
(VOID)owner;
|
||||
(VOID)param;
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC VOID IdlePriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param)
|
||||
{
|
||||
(VOID)owner;
|
||||
(VOID)list;
|
||||
(VOID)param;
|
||||
return;
|
||||
}
|
||||
|
||||
VOID IdleTaskSchedParamInit(LosTaskCB *taskCB)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
sched->policy = LOS_SCHED_IDLE;
|
||||
sched->basePrio = OS_PROCESS_PRIORITY_LOWEST;
|
||||
sched->priority = OS_TASK_PRIORITY_LOWEST;
|
||||
sched->initTimeSlice = 0;
|
||||
taskCB->timeSlice = sched->initTimeSlice;
|
||||
taskCB->taskStatus = OS_TASK_STATUS_SUSPENDED;
|
||||
taskCB->ops = &g_idleOps;
|
||||
}
|
||||
@@ -1,546 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_sched_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_tick_pri.h"
|
||||
#include "los_mp.h"
|
||||
|
||||
#define OS_SCHED_FIFO_TIMEOUT 0x7FFFFFFF
|
||||
#define PRIQUEUE_PRIOR0_BIT 0x80000000U
|
||||
#define OS_SCHED_TIME_SLICES_MIN ((5000 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 5ms */
|
||||
#define OS_SCHED_TIME_SLICES_MAX ((LOSCFG_BASE_CORE_TIMESLICE_TIMEOUT * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE)
|
||||
#define OS_SCHED_TIME_SLICES_DIFF (OS_SCHED_TIME_SLICES_MAX - OS_SCHED_TIME_SLICES_MIN)
|
||||
#define OS_SCHED_READY_MAX 30
|
||||
#define OS_TIME_SLICE_MIN (INT32)((50 * OS_SYS_NS_PER_US) / OS_NS_PER_CYCLE) /* 50us */
|
||||
|
||||
STATIC HPFRunqueue g_schedHPF;
|
||||
|
||||
STATIC VOID HPFDequeue(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC VOID HPFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC UINT32 HPFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks);
|
||||
STATIC VOID HPFWake(LosTaskCB *resumedTask);
|
||||
STATIC BOOL HPFSchedParamModify(LosTaskCB *taskCB, const SchedParam *param);
|
||||
STATIC UINT32 HPFSchedParamGet(const LosTaskCB *taskCB, SchedParam *param);
|
||||
STATIC UINT32 HPFDelay(LosTaskCB *runTask, UINT64 waitTime);
|
||||
STATIC VOID HPFYield(LosTaskCB *runTask);
|
||||
STATIC VOID HPFStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB);
|
||||
STATIC VOID HPFExit(LosTaskCB *taskCB);
|
||||
STATIC UINT32 HPFSuspend(LosTaskCB *taskCB);
|
||||
STATIC UINT32 HPFResume(LosTaskCB *taskCB, BOOL *needSched);
|
||||
STATIC UINT64 HPFTimeSliceGet(const LosTaskCB *taskCB);
|
||||
STATIC VOID HPFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime);
|
||||
STATIC INT32 HPFParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2);
|
||||
STATIC VOID HPFPriorityInheritance(LosTaskCB *owner, const SchedParam *param);
|
||||
STATIC VOID HPFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param);
|
||||
|
||||
const STATIC SchedOps g_priorityOps = {
|
||||
.dequeue = HPFDequeue,
|
||||
.enqueue = HPFEnqueue,
|
||||
.wait = HPFWait,
|
||||
.wake = HPFWake,
|
||||
.schedParamModify = HPFSchedParamModify,
|
||||
.schedParamGet = HPFSchedParamGet,
|
||||
.delay = HPFDelay,
|
||||
.yield = HPFYield,
|
||||
.start = HPFStartToRun,
|
||||
.exit = HPFExit,
|
||||
.suspend = HPFSuspend,
|
||||
.resume = HPFResume,
|
||||
.deadlineGet = HPFTimeSliceGet,
|
||||
.timeSliceUpdate = HPFTimeSliceUpdate,
|
||||
.schedParamCompare = HPFParamCompare,
|
||||
.priorityInheritance = HPFPriorityInheritance,
|
||||
.priorityRestore = HPFPriorityRestore,
|
||||
};
|
||||
|
||||
STATIC VOID HPFTimeSliceUpdate(SchedRunqueue *rq, LosTaskCB *taskCB, UINT64 currTime)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
LOS_ASSERT(currTime >= taskCB->startTime);
|
||||
|
||||
INT32 incTime = (currTime - taskCB->startTime - taskCB->irqUsedTime);
|
||||
|
||||
LOS_ASSERT(incTime >= 0);
|
||||
|
||||
if (sched->policy == LOS_SCHED_RR) {
|
||||
taskCB->timeSlice -= incTime;
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
taskCB->schedStat.timeSliceRealTime += incTime;
|
||||
#endif
|
||||
}
|
||||
taskCB->irqUsedTime = 0;
|
||||
taskCB->startTime = currTime;
|
||||
if (taskCB->timeSlice <= OS_TIME_SLICE_MIN) {
|
||||
rq->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
taskCB->schedStat.allRuntime += incTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC UINT64 HPFTimeSliceGet(const LosTaskCB *taskCB)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
INT32 timeSlice = taskCB->timeSlice;
|
||||
|
||||
timeSlice = (timeSlice <= OS_TIME_SLICE_MIN) ? sched->initTimeSlice : timeSlice;
|
||||
return (taskCB->startTime + timeSlice);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 TimeSliceCalculate(HPFRunqueue *rq, UINT16 basePrio, UINT16 priority)
|
||||
{
|
||||
UINT32 time;
|
||||
UINT32 readyTasks;
|
||||
|
||||
HPFQueue *queueList = &rq->queueList[basePrio];
|
||||
readyTasks = queueList->readyTasks[priority];
|
||||
if (readyTasks > OS_SCHED_READY_MAX) {
|
||||
return OS_SCHED_TIME_SLICES_MIN;
|
||||
}
|
||||
time = ((OS_SCHED_READY_MAX - readyTasks) * OS_SCHED_TIME_SLICES_DIFF) / OS_SCHED_READY_MAX;
|
||||
return (time + OS_SCHED_TIME_SLICES_MIN);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID PriQueHeadInsert(HPFRunqueue *rq, UINT32 basePrio, LOS_DL_LIST *priQue, UINT32 priority)
|
||||
{
|
||||
HPFQueue *queueList = &rq->queueList[basePrio];
|
||||
LOS_DL_LIST *priQueList = &queueList->priQueList[0];
|
||||
UINT32 *bitmap = &queueList->queueBitmap;
|
||||
|
||||
/*
|
||||
* Task control blocks are inited as zero. And when task is deleted,
|
||||
* and at the same time would be deleted from priority queue or
|
||||
* other lists, task pend node will restored as zero.
|
||||
*/
|
||||
LOS_ASSERT(priQue->pstNext == NULL);
|
||||
|
||||
if (*bitmap == 0) {
|
||||
rq->queueBitmap |= PRIQUEUE_PRIOR0_BIT >> basePrio;
|
||||
}
|
||||
|
||||
if (LOS_ListEmpty(&priQueList[priority])) {
|
||||
*bitmap |= PRIQUEUE_PRIOR0_BIT >> priority;
|
||||
}
|
||||
|
||||
LOS_ListHeadInsert(&priQueList[priority], priQue);
|
||||
queueList->readyTasks[priority]++;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID PriQueTailInsert(HPFRunqueue *rq, UINT32 basePrio, LOS_DL_LIST *priQue, UINT32 priority)
|
||||
{
|
||||
HPFQueue *queueList = &rq->queueList[basePrio];
|
||||
LOS_DL_LIST *priQueList = &queueList->priQueList[0];
|
||||
UINT32 *bitmap = &queueList->queueBitmap;
|
||||
|
||||
/*
|
||||
* Task control blocks are inited as zero. And when task is deleted,
|
||||
* and at the same time would be deleted from priority queue or
|
||||
* other lists, task pend node will restored as zero.
|
||||
*/
|
||||
LOS_ASSERT(priQue->pstNext == NULL);
|
||||
|
||||
if (*bitmap == 0) {
|
||||
rq->queueBitmap |= PRIQUEUE_PRIOR0_BIT >> basePrio;
|
||||
}
|
||||
|
||||
if (LOS_ListEmpty(&priQueList[priority])) {
|
||||
*bitmap |= PRIQUEUE_PRIOR0_BIT >> priority;
|
||||
}
|
||||
|
||||
LOS_ListTailInsert(&priQueList[priority], priQue);
|
||||
queueList->readyTasks[priority]++;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID PriQueDelete(HPFRunqueue *rq, UINT32 basePrio, LOS_DL_LIST *priQue, UINT32 priority)
|
||||
{
|
||||
HPFQueue *queueList = &rq->queueList[basePrio];
|
||||
LOS_DL_LIST *priQueList = &queueList->priQueList[0];
|
||||
UINT32 *bitmap = &queueList->queueBitmap;
|
||||
|
||||
LOS_ListDelete(priQue);
|
||||
queueList->readyTasks[priority]--;
|
||||
if (LOS_ListEmpty(&priQueList[priority])) {
|
||||
*bitmap &= ~(PRIQUEUE_PRIOR0_BIT >> priority);
|
||||
}
|
||||
|
||||
if (*bitmap == 0) {
|
||||
rq->queueBitmap &= ~(PRIQUEUE_PRIOR0_BIT >> basePrio);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID PriQueInsert(HPFRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
LOS_ASSERT(!(taskCB->taskStatus & OS_TASK_STATUS_READY));
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
|
||||
switch (sched->policy) {
|
||||
case LOS_SCHED_RR: {
|
||||
if (taskCB->timeSlice > OS_TIME_SLICE_MIN) {
|
||||
PriQueHeadInsert(rq, sched->basePrio, &taskCB->pendList, sched->priority);
|
||||
} else {
|
||||
sched->initTimeSlice = TimeSliceCalculate(rq, sched->basePrio, sched->priority);
|
||||
taskCB->timeSlice = sched->initTimeSlice;
|
||||
PriQueTailInsert(rq, sched->basePrio, &taskCB->pendList, sched->priority);
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
taskCB->schedStat.timeSliceTime = taskCB->schedStat.timeSliceRealTime;
|
||||
taskCB->schedStat.timeSliceCount++;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LOS_SCHED_FIFO: {
|
||||
/* The time slice of FIFO is always greater than 0 unless the yield is called */
|
||||
if ((taskCB->timeSlice > OS_TIME_SLICE_MIN) && (taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
|
||||
PriQueHeadInsert(rq, sched->basePrio, &taskCB->pendList, sched->priority);
|
||||
} else {
|
||||
sched->initTimeSlice = OS_SCHED_FIFO_TIMEOUT;
|
||||
taskCB->timeSlice = sched->initTimeSlice;
|
||||
PriQueTailInsert(rq, sched->basePrio, &taskCB->pendList, sched->priority);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOS_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_BLOCKED;
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_READY;
|
||||
}
|
||||
|
||||
STATIC VOID HPFEnqueue(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
if (!(taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
|
||||
taskCB->startTime = OsGetCurrSchedTimeCycle();
|
||||
}
|
||||
#endif
|
||||
PriQueInsert(rq->hpfRunqueue, taskCB);
|
||||
}
|
||||
|
||||
STATIC VOID HPFDequeue(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
PriQueDelete(rq->hpfRunqueue, sched->basePrio, &taskCB->pendList, sched->priority);
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_READY;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID HPFStartToRun(SchedRunqueue *rq, LosTaskCB *taskCB)
|
||||
{
|
||||
HPFDequeue(rq, taskCB);
|
||||
}
|
||||
|
||||
STATIC VOID HPFExit(LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
HPFDequeue(OsSchedRunqueue(), taskCB);
|
||||
} else if (taskCB->taskStatus & OS_TASK_STATUS_PENDING) {
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_PENDING;
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & (OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME)) {
|
||||
OsSchedTimeoutQueueDelete(taskCB);
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_DELAY | OS_TASK_STATUS_PEND_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID HPFYield(LosTaskCB *runTask)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
runTask->timeSlice = 0;
|
||||
|
||||
runTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
HPFEnqueue(rq, runTask);
|
||||
OsSchedResched();
|
||||
}
|
||||
|
||||
STATIC UINT32 HPFDelay(LosTaskCB *runTask, UINT64 waitTime)
|
||||
{
|
||||
runTask->taskStatus |= OS_TASK_STATUS_DELAY;
|
||||
runTask->waitTime = waitTime;
|
||||
|
||||
OsSchedResched();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HPFWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 ticks)
|
||||
{
|
||||
runTask->taskStatus |= OS_TASK_STATUS_PENDING;
|
||||
LOS_ListTailInsert(list, &runTask->pendList);
|
||||
|
||||
if (ticks != LOS_WAIT_FOREVER) {
|
||||
runTask->taskStatus |= OS_TASK_STATUS_PEND_TIME;
|
||||
runTask->waitTime = OS_SCHED_TICK_TO_CYCLE(ticks);
|
||||
}
|
||||
|
||||
if (OsPreemptableInSched()) {
|
||||
OsSchedResched();
|
||||
if (runTask->taskStatus & OS_TASK_STATUS_TIMEOUT) {
|
||||
runTask->taskStatus &= ~OS_TASK_STATUS_TIMEOUT;
|
||||
return LOS_ERRNO_TSK_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID HPFWake(LosTaskCB *resumedTask)
|
||||
{
|
||||
LOS_ListDelete(&resumedTask->pendList);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PENDING;
|
||||
|
||||
if (resumedTask->taskStatus & OS_TASK_STATUS_PEND_TIME) {
|
||||
OsSchedTimeoutQueueDelete(resumedTask);
|
||||
resumedTask->taskStatus &= ~OS_TASK_STATUS_PEND_TIME;
|
||||
}
|
||||
|
||||
if (!(resumedTask->taskStatus & OS_TASK_STATUS_SUSPENDED)) {
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
resumedTask->schedStat.pendTime += OsGetCurrSchedTimeCycle() - resumedTask->startTime;
|
||||
resumedTask->schedStat.pendCount++;
|
||||
#endif
|
||||
HPFEnqueue(OsSchedRunqueue(), resumedTask);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC BOOL BasePriorityModify(SchedRunqueue *rq, LosTaskCB *taskCB, UINT16 priority)
|
||||
{
|
||||
LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID);
|
||||
BOOL needSched = FALSE;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(taskCB, &processCB->threadSiblingList, LosTaskCB, threadList) {
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
taskCB->ops->dequeue(rq, taskCB);
|
||||
sched->basePrio = priority;
|
||||
taskCB->ops->enqueue(rq, taskCB);
|
||||
} else {
|
||||
sched->basePrio = priority;
|
||||
}
|
||||
if (taskCB->taskStatus & (OS_TASK_STATUS_READY | OS_TASK_STATUS_RUNNING)) {
|
||||
needSched = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return needSched;
|
||||
}
|
||||
|
||||
STATIC BOOL HPFSchedParamModify(LosTaskCB *taskCB, const SchedParam *param)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
BOOL needSched = FALSE;
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
|
||||
if (sched->policy != param->policy) {
|
||||
sched->policy = param->policy;
|
||||
taskCB->timeSlice = 0;
|
||||
}
|
||||
|
||||
if (sched->basePrio != param->basePrio) {
|
||||
needSched = BasePriorityModify(rq, taskCB, param->basePrio);
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
HPFDequeue(rq, taskCB);
|
||||
sched->priority = param->priority;
|
||||
HPFEnqueue(rq, taskCB);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
sched->priority = param->priority;
|
||||
OsHookCall(LOS_HOOK_TYPE_TASK_PRIMODIFY, taskCB, sched->priority);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_INIT) {
|
||||
HPFEnqueue(rq, taskCB);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return needSched;
|
||||
}
|
||||
|
||||
STATIC UINT32 HPFSchedParamGet(const LosTaskCB *taskCB, SchedParam *param)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
param->policy = sched->policy;
|
||||
param->basePrio = sched->basePrio;
|
||||
param->priority = sched->priority;
|
||||
param->timeSlice = sched->initTimeSlice;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HPFSuspend(LosTaskCB *taskCB)
|
||||
{
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_READY) {
|
||||
HPFDequeue(OsSchedRunqueue(), taskCB);
|
||||
}
|
||||
|
||||
SchedTaskFreeze(taskCB);
|
||||
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_SUSPENDED;
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, taskCB);
|
||||
if (taskCB == OsCurrTaskGet()) {
|
||||
OsSchedResched();
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 HPFResume(LosTaskCB *taskCB, BOOL *needSched)
|
||||
{
|
||||
*needSched = FALSE;
|
||||
|
||||
SchedTaskUnfreeze(taskCB);
|
||||
|
||||
taskCB->taskStatus &= ~OS_TASK_STATUS_SUSPENDED;
|
||||
if (!OsTaskIsBlocked(taskCB)) {
|
||||
HPFEnqueue(OsSchedRunqueue(), taskCB);
|
||||
*needSched = TRUE;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 HPFParamCompare(const SchedPolicy *sp1, const SchedPolicy *sp2)
|
||||
{
|
||||
SchedHPF *param1 = (SchedHPF *)sp1;
|
||||
SchedHPF *param2 = (SchedHPF *)sp2;
|
||||
|
||||
if (param1->basePrio != param2->basePrio) {
|
||||
return (param1->basePrio - param2->basePrio);
|
||||
}
|
||||
|
||||
return (param1->priority - param2->priority);
|
||||
}
|
||||
|
||||
STATIC VOID HPFPriorityInheritance(LosTaskCB *owner, const SchedParam *param)
|
||||
{
|
||||
SchedHPF *sp = (SchedHPF *)&owner->sp;
|
||||
|
||||
if ((param->policy != LOS_SCHED_RR) && (param->policy != LOS_SCHED_FIFO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sp->priority <= param->priority) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_BitmapSet(&sp->priBitmap, sp->priority);
|
||||
sp->priority = param->priority;
|
||||
}
|
||||
|
||||
STATIC VOID HPFPriorityRestore(LosTaskCB *owner, const LOS_DL_LIST *list, const SchedParam *param)
|
||||
{
|
||||
UINT16 priority;
|
||||
LosTaskCB *pendedTask = NULL;
|
||||
|
||||
if ((param->policy != LOS_SCHED_RR) && (param->policy != LOS_SCHED_FIFO)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SchedHPF *sp = (SchedHPF *)&owner->sp;
|
||||
if (sp->priority < param->priority) {
|
||||
if (LOS_HighBitGet(sp->priBitmap) != param->priority) {
|
||||
LOS_BitmapClr(&sp->priBitmap, param->priority);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (sp->priBitmap == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((list != NULL) && !LOS_ListEmpty((LOS_DL_LIST *)list)) {
|
||||
priority = LOS_HighBitGet(sp->priBitmap);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, list, LosTaskCB, pendList) {
|
||||
SchedHPF *pendSp = (SchedHPF *)&pendedTask->sp;
|
||||
if ((pendedTask->ops == owner->ops) && (priority != pendSp->priority)) {
|
||||
LOS_BitmapClr(&sp->priBitmap, pendSp->priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
priority = LOS_LowBitGet(sp->priBitmap);
|
||||
if (priority != LOS_INVALID_BIT_INDEX) {
|
||||
LOS_BitmapClr(&sp->priBitmap, priority);
|
||||
sp->priority = priority;
|
||||
}
|
||||
}
|
||||
|
||||
VOID HPFTaskSchedParamInit(LosTaskCB *taskCB, UINT16 policy,
|
||||
const SchedParam *parentParam,
|
||||
const TSK_INIT_PARAM_S *param)
|
||||
{
|
||||
SchedHPF *sched = (SchedHPF *)&taskCB->sp;
|
||||
|
||||
sched->policy = policy;
|
||||
if (param != NULL) {
|
||||
sched->priority = param->usTaskPrio;
|
||||
} else {
|
||||
sched->priority = parentParam->priority;
|
||||
}
|
||||
sched->basePrio = parentParam->basePrio;
|
||||
|
||||
sched->initTimeSlice = 0;
|
||||
taskCB->timeSlice = sched->initTimeSlice;
|
||||
taskCB->ops = &g_priorityOps;
|
||||
}
|
||||
|
||||
VOID HPFProcessDefaultSchedParamGet(SchedParam *param)
|
||||
{
|
||||
param->basePrio = OS_USER_PROCESS_PRIORITY_HIGHEST;
|
||||
}
|
||||
|
||||
VOID HPFSchedPolicyInit(SchedRunqueue *rq)
|
||||
{
|
||||
if (ArchCurrCpuid() > 0) {
|
||||
rq->hpfRunqueue = &g_schedHPF;
|
||||
return;
|
||||
}
|
||||
|
||||
for (UINT16 index = 0; index < OS_PRIORITY_QUEUE_NUM; index++) {
|
||||
HPFQueue *queueList = &g_schedHPF.queueList[index];
|
||||
LOS_DL_LIST *priQue = &queueList->priQueList[0];
|
||||
for (UINT16 prio = 0; prio < OS_PRIORITY_QUEUE_NUM; prio++) {
|
||||
LOS_ListInit(&priQue[prio]);
|
||||
}
|
||||
}
|
||||
|
||||
rq->hpfRunqueue = &g_schedHPF;
|
||||
}
|
||||
@@ -1,538 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_sched_pri.h"
|
||||
#include "los_hw_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_swtmr_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_arch_mmu.h"
|
||||
#include "los_hook.h"
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#include "los_cpup_pri.h"
|
||||
#endif
|
||||
#include "los_hw_tick_pri.h"
|
||||
#include "los_tick_pri.h"
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
#include "los_stackinfo_pri.h"
|
||||
#endif
|
||||
#include "los_mp.h"
|
||||
|
||||
SchedRunqueue g_schedRunqueue[LOSCFG_KERNEL_CORE_NUM];
|
||||
|
||||
STATIC INLINE VOID SchedNextExpireTimeSet(UINT32 responseID, UINT64 taskEndTime, UINT32 oldResponseID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
BOOL isTimeSlice = FALSE;
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 nextExpireTime = OsGetSortLinkNextExpireTime(&rq->timeoutQueue, currTime, OS_TICK_RESPONSE_PRECISION);
|
||||
|
||||
rq->schedFlag &= ~INT_PEND_TICK;
|
||||
if (rq->responseID == oldResponseID) {
|
||||
/* This time has expired, and the next time the theory has expired is infinite */
|
||||
rq->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
|
||||
/* The current thread's time slice has been consumed, but the current system lock task cannot
|
||||
* trigger the schedule to release the CPU
|
||||
*/
|
||||
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
|
||||
nextExpireTime = taskEndTime;
|
||||
isTimeSlice = TRUE;
|
||||
}
|
||||
|
||||
if ((rq->responseTime <= nextExpireTime) ||
|
||||
((rq->responseTime - nextExpireTime) < OS_TICK_RESPONSE_PRECISION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isTimeSlice) {
|
||||
/* The expiration time of the current system is the thread's slice expiration time */
|
||||
rq->responseID = responseID;
|
||||
} else {
|
||||
rq->responseID = OS_INVALID_VALUE;
|
||||
}
|
||||
|
||||
UINT64 nextResponseTime = nextExpireTime - currTime;
|
||||
rq->responseTime = currTime + HalClockTickTimerReload(nextResponseTime);
|
||||
}
|
||||
|
||||
VOID OsSchedExpireTimeUpdate(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!OS_SCHEDULER_ACTIVE || OS_INT_ACTIVE) {
|
||||
OsSchedRunqueuePendingSet();
|
||||
return;
|
||||
}
|
||||
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
SCHEDULER_LOCK(intSave);
|
||||
UINT64 deadline = runTask->ops->deadlineGet(runTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
SchedNextExpireTimeSet(runTask->taskID, deadline, runTask->taskID);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SchedTimeoutTaskWake(SchedRunqueue *rq, UINT64 currTime, LosTaskCB *taskCB, BOOL *needSched)
|
||||
{
|
||||
#ifndef LOSCFG_SCHED_DEBUG
|
||||
(VOID)currTime;
|
||||
#endif
|
||||
|
||||
LOS_SpinLock(&g_taskSpin);
|
||||
UINT16 tempStatus = taskCB->taskStatus;
|
||||
if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) {
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
|
||||
if (tempStatus & OS_TASK_STATUS_PENDING) {
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
taskCB->taskMux = NULL;
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
}
|
||||
|
||||
if (!(tempStatus & OS_TASK_STATUS_SUSPENDED)) {
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
taskCB->schedStat.pendTime += currTime - taskCB->startTime;
|
||||
taskCB->schedStat.pendCount++;
|
||||
#endif
|
||||
taskCB->ops->enqueue(rq, taskCB);
|
||||
*needSched = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL SchedTimeoutQueueScan(SchedRunqueue *rq)
|
||||
{
|
||||
BOOL needSched = FALSE;
|
||||
SortLinkAttribute *timeoutQueue = &rq->timeoutQueue;
|
||||
LOS_DL_LIST *listObject = &timeoutQueue->sortLink;
|
||||
/*
|
||||
* When task is pended with timeout, the task block is on the timeout sortlink
|
||||
* (per cpu) and ipc(mutex,sem and etc.)'s block at the same time, it can be waken
|
||||
* up by either timeout or corresponding ipc it's waiting.
|
||||
*
|
||||
* Now synchronize sortlink procedure is used, therefore the whole task scan needs
|
||||
* to be protected, preventing another core from doing sortlink deletion at same time.
|
||||
*/
|
||||
LOS_SpinLock(&timeoutQueue->spinLock);
|
||||
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
LOS_SpinUnlock(&timeoutQueue->spinLock);
|
||||
return needSched;
|
||||
}
|
||||
|
||||
SortLinkList *sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
while (sortList->responseTime <= currTime) {
|
||||
LosTaskCB *taskCB = LOS_DL_LIST_ENTRY(sortList, LosTaskCB, sortList);
|
||||
OsDeleteNodeSortLink(timeoutQueue, &taskCB->sortList);
|
||||
LOS_SpinUnlock(&timeoutQueue->spinLock);
|
||||
|
||||
SchedTimeoutTaskWake(rq, currTime, taskCB, &needSched);
|
||||
|
||||
LOS_SpinLock(&timeoutQueue->spinLock);
|
||||
if (LOS_ListEmpty(listObject)) {
|
||||
break;
|
||||
}
|
||||
|
||||
sortList = LOS_DL_LIST_ENTRY(listObject->pstNext, SortLinkList, sortLinkNode);
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&timeoutQueue->spinLock);
|
||||
|
||||
return needSched;
|
||||
}
|
||||
|
||||
VOID OsSchedTick(VOID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
|
||||
if (rq->responseID == OS_INVALID_VALUE) {
|
||||
if (SchedTimeoutQueueScan(rq)) {
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
rq->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
}
|
||||
rq->schedFlag |= INT_PEND_TICK;
|
||||
rq->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
|
||||
VOID OsSchedResponseTimeReset(UINT64 responseTime)
|
||||
{
|
||||
OsSchedRunqueue()->responseTime = responseTime;
|
||||
}
|
||||
|
||||
VOID OsSchedRunqueueInit(VOID)
|
||||
{
|
||||
if (ArchCurrCpuid() != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (UINT16 index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(index);
|
||||
OsSortLinkInit(&rq->timeoutQueue);
|
||||
rq->responseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
rq->idleTaskID = idleTaskID;
|
||||
}
|
||||
|
||||
UINT32 OsSchedInit(VOID)
|
||||
{
|
||||
for (UINT16 cpuId = 0; cpuId < LOSCFG_KERNEL_CORE_NUM; cpuId++) {
|
||||
HPFSchedPolicyInit(OsSchedRunqueueByID(cpuId));
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
UINT32 ret = OsSchedDebugInit();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the return value greater than 0, task1 has a lower priority than task2.
|
||||
* If the return value less than 0, task1 has a higher priority than task2.
|
||||
* If the return value is 0, task1 and task2 have the same priority.
|
||||
*/
|
||||
INT32 OsSchedParamCompare(const LosTaskCB *task1, const LosTaskCB *task2)
|
||||
{
|
||||
SchedHPF *rp1 = (SchedHPF *)&task1->sp;
|
||||
SchedHPF *rp2 = (SchedHPF *)&task2->sp;
|
||||
|
||||
if (rp1->policy == rp2->policy) {
|
||||
return task1->ops->schedParamCompare(&task1->sp, &task2->sp);
|
||||
}
|
||||
|
||||
if (rp1->policy == LOS_SCHED_IDLE) {
|
||||
return 1;
|
||||
} else if (rp2->policy == LOS_SCHED_IDLE) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const TSK_INIT_PARAM_S *param)
|
||||
{
|
||||
switch (policy) {
|
||||
case LOS_SCHED_FIFO:
|
||||
case LOS_SCHED_RR:
|
||||
HPFTaskSchedParamInit(taskCB, policy, parentParam, param);
|
||||
break;
|
||||
case LOS_SCHED_IDLE:
|
||||
IdleTaskSchedParamInit(taskCB);
|
||||
break;
|
||||
default:
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsSchedProcessDefaultSchedParamGet(UINT16 policy, SchedParam *param)
|
||||
{
|
||||
switch (policy) {
|
||||
case LOS_SCHED_FIFO:
|
||||
case LOS_SCHED_RR:
|
||||
HPFProcessDefaultSchedParamGet(param);
|
||||
break;
|
||||
case LOS_SCHED_IDLE:
|
||||
default:
|
||||
PRINT_ERR("Invalid process-level scheduling policy, %u\n", policy);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
STATIC LosTaskCB *TopTaskGet(SchedRunqueue *rq)
|
||||
{
|
||||
LosTaskCB *newTask = HPFRunqueueTopTaskGet(rq->hpfRunqueue);
|
||||
|
||||
if (newTask == NULL) {
|
||||
newTask = OS_TCB_FROM_TID(rq->idleTaskID);
|
||||
}
|
||||
|
||||
newTask->ops->start(rq, newTask);
|
||||
return newTask;
|
||||
}
|
||||
|
||||
VOID OsSchedStart(VOID)
|
||||
{
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
UINT32 intSave;
|
||||
|
||||
PRINTK("cpu %d entering scheduler\n", cpuid);
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
OsTickStart();
|
||||
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
LosTaskCB *newTask = TopTaskGet(rq);
|
||||
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
* attention: current cpu needs to be set, in case first task deletion
|
||||
* may fail because this flag mismatch with the real current cpu.
|
||||
*/
|
||||
newTask->currCpu = cpuid;
|
||||
#endif
|
||||
|
||||
OsCurrTaskSet((VOID *)newTask);
|
||||
|
||||
newTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
|
||||
OsSwtmrResponseTimeReset(newTask->startTime);
|
||||
|
||||
/* System start schedule */
|
||||
OS_SCHEDULER_SET(cpuid);
|
||||
|
||||
rq->responseID = OS_INVALID;
|
||||
UINT64 deadline = newTask->ops->deadlineGet(newTask);
|
||||
SchedNextExpireTimeSet(newTask->taskID, deadline, OS_INVALID);
|
||||
OsTaskContextLoad(newTask);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
VOID OsSchedToUserReleaseLock(VOID)
|
||||
{
|
||||
/* The scheduling lock needs to be released before returning to user mode */
|
||||
LOCKDEP_CHECK_OUT(&g_taskSpin);
|
||||
ArchSpinUnlock(&g_taskSpin.rawLock);
|
||||
|
||||
OsSchedUnlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
STATIC VOID TaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
if (!OS_STACK_MAGIC_CHECK(runTask->topOfStack)) {
|
||||
LOS_Panic("CURRENT task ID: %s:%d stack overflow!\n", runTask->taskName, runTask->taskID);
|
||||
}
|
||||
|
||||
if (((UINTPTR)(newTask->stackPointer) <= newTask->topOfStack) ||
|
||||
((UINTPTR)(newTask->stackPointer) > (newTask->topOfStack + newTask->stackSize))) {
|
||||
LOS_Panic("HIGHEST task ID: %s:%u SP error! StackPointer: %p TopOfStack: %p\n",
|
||||
newTask->taskName, newTask->taskID, newTask->stackPointer, newTask->topOfStack);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC INLINE VOID SchedSwitchCheck(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
TaskStackCheck(runTask, newTask);
|
||||
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR */
|
||||
OsHookCall(LOS_HOOK_TYPE_TASK_SWITCHEDIN, newTask, runTask);
|
||||
}
|
||||
|
||||
STATIC VOID SchedTaskSwitch(SchedRunqueue *rq, LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
SchedSwitchCheck(runTask, newTask);
|
||||
|
||||
runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
|
||||
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* mask new running task's owner processor */
|
||||
runTask->currCpu = OS_TASK_INVALID_CPUID;
|
||||
newTask->currCpu = ArchCurrCpuid();
|
||||
#endif
|
||||
|
||||
OsCurrTaskSet((VOID *)newTask);
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (newTask->archMmu != runTask->archMmu) {
|
||||
LOS_ArchMmuContextSwitch((LosArchMmu *)newTask->archMmu);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
OsCpupCycleEndStart(runTask->taskID, newTask->taskID);
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
UINT64 waitStartTime = newTask->startTime;
|
||||
#endif
|
||||
if (runTask->taskStatus & OS_TASK_STATUS_READY) {
|
||||
/* When a thread enters the ready queue, its slice of time is updated */
|
||||
newTask->startTime = runTask->startTime;
|
||||
} else {
|
||||
/* The currently running task is blocked */
|
||||
newTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
/* The task is in a blocking state and needs to update its time slice before pend */
|
||||
runTask->ops->timeSliceUpdate(rq, runTask, newTask->startTime);
|
||||
|
||||
if (runTask->taskStatus & (OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY)) {
|
||||
OsSchedTimeoutQueueAdd(runTask, runTask->startTime + runTask->waitTime);
|
||||
}
|
||||
}
|
||||
|
||||
UINT64 deadline = newTask->ops->deadlineGet(newTask);
|
||||
SchedNextExpireTimeSet(newTask->taskID, deadline, runTask->taskID);
|
||||
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
newTask->schedStat.waitSchedTime += newTask->startTime - waitStartTime;
|
||||
newTask->schedStat.waitSchedCount++;
|
||||
runTask->schedStat.runTime = runTask->schedStat.allRuntime;
|
||||
runTask->schedStat.switchCount++;
|
||||
#endif
|
||||
/* do the task context switch */
|
||||
OsTaskSchedule(newTask, runTask);
|
||||
}
|
||||
|
||||
VOID OsSchedIrqEndCheckNeedSched(VOID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
|
||||
runTask->ops->timeSliceUpdate(rq, runTask, OsGetCurrSchedTimeCycle());
|
||||
|
||||
if (OsPreemptable() && (rq->schedFlag & INT_PEND_RESCH)) {
|
||||
rq->schedFlag &= ~INT_PEND_RESCH;
|
||||
|
||||
LOS_SpinLock(&g_taskSpin);
|
||||
|
||||
runTask->ops->enqueue(rq, runTask);
|
||||
|
||||
LosTaskCB *newTask = TopTaskGet(rq);
|
||||
if (runTask != newTask) {
|
||||
SchedTaskSwitch(rq, runTask, newTask);
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
}
|
||||
|
||||
if (rq->schedFlag & INT_PEND_TICK) {
|
||||
OsSchedExpireTimeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsSchedResched(VOID)
|
||||
{
|
||||
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_ASSERT(rq->taskLockCnt == 1);
|
||||
#else
|
||||
LOS_ASSERT(rq->taskLockCnt == 0);
|
||||
#endif
|
||||
|
||||
rq->schedFlag &= ~INT_PEND_RESCH;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
LosTaskCB *newTask = TopTaskGet(rq);
|
||||
if (runTask == newTask) {
|
||||
return;
|
||||
}
|
||||
|
||||
SchedTaskSwitch(rq, runTask, newTask);
|
||||
}
|
||||
|
||||
VOID LOS_Schedule(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
OsSchedRunqueuePendingSet();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!OsPreemptable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* trigger schedule in task will also do the slice check
|
||||
* if necessary, it will give up the timeslice more in time.
|
||||
* otherwise, there's no other side effects.
|
||||
*/
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
runTask->ops->timeSliceUpdate(rq, runTask, OsGetCurrSchedTimeCycle());
|
||||
|
||||
/* add run task back to ready queue */
|
||||
runTask->ops->enqueue(rq, runTask);
|
||||
|
||||
/* reschedule to new thread */
|
||||
OsSchedResched();
|
||||
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE LOS_DL_LIST *SchedLockPendFindPosSub(const LosTaskCB *runTask, const LOS_DL_LIST *lockList)
|
||||
{
|
||||
LosTaskCB *pendedTask = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, lockList, LosTaskCB, pendList) {
|
||||
INT32 ret = OsSchedParamCompare(pendedTask, runTask);
|
||||
if (ret < 0) {
|
||||
continue;
|
||||
} else if (ret > 0) {
|
||||
return &pendedTask->pendList;
|
||||
} else {
|
||||
return pendedTask->pendList.pstNext;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList)
|
||||
{
|
||||
if (LOS_ListEmpty(lockList)) {
|
||||
return lockList;
|
||||
}
|
||||
|
||||
LosTaskCB *pendedTask1 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(lockList));
|
||||
INT32 ret = OsSchedParamCompare(pendedTask1, runTask);
|
||||
if (ret > 0) {
|
||||
return lockList->pstNext;
|
||||
}
|
||||
|
||||
LosTaskCB *pendedTask2 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_LAST(lockList));
|
||||
ret = OsSchedParamCompare(pendedTask2, runTask);
|
||||
if (ret <= 0) {
|
||||
return lockList;
|
||||
}
|
||||
|
||||
return SchedLockPendFindPosSub(runTask, lockList);
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_statistics_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#ifdef LOSCFG_SCHED_TICK_DEBUG
|
||||
typedef struct {
|
||||
UINT64 responseTime;
|
||||
UINT64 responseTimeMax;
|
||||
UINT64 count;
|
||||
} SchedTickDebug;
|
||||
STATIC SchedTickDebug *g_schedTickDebug = NULL;
|
||||
|
||||
UINT32 OsSchedDebugInit(VOID)
|
||||
{
|
||||
UINT32 size = sizeof(SchedTickDebug) * LOSCFG_KERNEL_CORE_NUM;
|
||||
g_schedTickDebug = (SchedTickDebug *)LOS_MemAlloc(m_aucSysMem0, size);
|
||||
if (g_schedTickDebug == NULL) {
|
||||
return LOS_ERRNO_TSK_NO_MEMORY;
|
||||
}
|
||||
|
||||
(VOID)memset_s(g_schedTickDebug, size, 0, size);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID OsSchedDebugRecordData(VOID)
|
||||
{
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
SchedTickDebug *schedDebug = &g_schedTickDebug[ArchCurrCpuid()];
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
LOS_ASSERT(currTime >= rq->responseTime);
|
||||
UINT64 usedTime = currTime - rq->responseTime;
|
||||
schedDebug->responseTime += usedTime;
|
||||
if (usedTime > schedDebug->responseTimeMax) {
|
||||
schedDebug->responseTimeMax = usedTime;
|
||||
}
|
||||
schedDebug->count++;
|
||||
}
|
||||
|
||||
UINT32 OsShellShowTickResponse(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT16 cpu;
|
||||
|
||||
UINT32 tickSize = sizeof(SchedTickDebug) * LOSCFG_KERNEL_CORE_NUM;
|
||||
SchedTickDebug *schedDebug = (SchedTickDebug *)LOS_MemAlloc(m_aucSysMem1, tickSize);
|
||||
if (schedDebug == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
(VOID)memcpy_s((CHAR *)schedDebug, tickSize, (CHAR *)g_schedTickDebug, tickSize);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
PRINTK("cpu ATRTime(us) ATRTimeMax(us) TickCount\n");
|
||||
for (cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
|
||||
SchedTickDebug *schedData = &schedDebug[cpu];
|
||||
UINT64 averTime = 0;
|
||||
if (schedData->count > 0) {
|
||||
averTime = schedData->responseTime / schedData->count;
|
||||
averTime = (averTime * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
UINT64 timeMax = (schedData->responseTimeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
PRINTK("%3u%14llu%15llu%11llu\n", cpu, averTime, timeMax, schedData->count);
|
||||
}
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, schedDebug);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID SchedDataGet(const LosTaskCB *taskCB, UINT64 *runTime, UINT64 *timeSlice,
|
||||
UINT64 *pendTime, UINT64 *schedWait)
|
||||
{
|
||||
if (taskCB->schedStat.switchCount >= 1) {
|
||||
UINT64 averRunTime = taskCB->schedStat.runTime / taskCB->schedStat.switchCount;
|
||||
*runTime = (averRunTime * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
|
||||
if (taskCB->schedStat.timeSliceCount > 1) {
|
||||
UINT64 averTimeSlice = taskCB->schedStat.timeSliceTime / (taskCB->schedStat.timeSliceCount - 1);
|
||||
*timeSlice = (averTimeSlice * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
|
||||
if (taskCB->schedStat.pendCount > 1) {
|
||||
UINT64 averPendTime = taskCB->schedStat.pendTime / taskCB->schedStat.pendCount;
|
||||
*pendTime = (averPendTime * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
|
||||
if (taskCB->schedStat.waitSchedCount > 0) {
|
||||
UINT64 averSchedWait = taskCB->schedStat.waitSchedTime / taskCB->schedStat.waitSchedCount;
|
||||
*schedWait = (averSchedWait * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US;
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 OsShellShowSchedStatistics(VOID)
|
||||
{
|
||||
UINT32 taskLinkNum[LOSCFG_KERNEL_CORE_NUM];
|
||||
UINT32 intSave;
|
||||
LosTaskCB task;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
for (UINT16 cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
|
||||
SchedRunqueue *rq = OsSchedRunqueueByID(cpu);
|
||||
taskLinkNum[cpu] = OsGetSortLinkNodeNum(&rq->timeoutQueue);
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
for (UINT16 cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
|
||||
PRINTK("cpu: %u Task SortMax: %u\n", cpu, taskLinkNum[cpu]);
|
||||
}
|
||||
|
||||
PRINTK(" Tid AverRunTime(us) SwitchCount AverTimeSlice(us) TimeSliceCount AverReadyWait(us) "
|
||||
"AverPendTime(us) TaskName \n");
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
|
||||
LosTaskCB *taskCB = g_taskCBArray + tid;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (OsTaskIsUnused(taskCB) || (taskCB->processID == OsGetIdleProcessID())) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
continue;
|
||||
}
|
||||
|
||||
(VOID)memcpy_s(&task, sizeof(LosTaskCB), taskCB, sizeof(LosTaskCB));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
UINT64 averRunTime = 0;
|
||||
UINT64 averTimeSlice = 0;
|
||||
UINT64 averPendTime = 0;
|
||||
UINT64 averSchedWait = 0;
|
||||
|
||||
SchedDataGet(&task, &averRunTime, &averTimeSlice, &averPendTime, &averSchedWait);
|
||||
|
||||
PRINTK("%5u%19llu%15llu%19llu%18llu%19llu%18llu %-32s\n", taskCB->taskID,
|
||||
averRunTime, taskCB->schedStat.switchCount,
|
||||
averTimeSlice, taskCB->schedStat.timeSliceCount - 1,
|
||||
averSchedWait, averPendTime, taskCB->taskName);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
1231
kernel/base/sched/sched_sq/los_sched.c
Normal file
1231
kernel/base/sched/sched_sq/los_sched.c
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user