Compare commits
79 Commits
OpenHarmon
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b086195e97 | ||
|
|
b90531e366 | ||
|
|
a1a6286500 | ||
|
|
e1027b5902 | ||
|
|
b9a445ca44 | ||
|
|
338044cd9c | ||
|
|
18a2fc8e8d | ||
|
|
fa0e803ac9 | ||
|
|
4f641cc145 | ||
|
|
9063a45d5a | ||
|
|
4b4e1264f5 | ||
|
|
3f5307e7bb | ||
|
|
eddcb840d3 | ||
|
|
a0e205eb0a | ||
|
|
707028dfe1 | ||
|
|
49d72afc8e | ||
|
|
c11ff67869 | ||
|
|
b6a49e7c89 | ||
|
|
e847c8b468 | ||
|
|
faeeaf294c | ||
|
|
b2caf46b4e | ||
|
|
ccbc55df60 | ||
|
|
7f4294af00 | ||
|
|
4a63bacc47 | ||
|
|
ee6f3f0d79 | ||
|
|
e05300cdf0 | ||
|
|
b8951e2cd9 | ||
|
|
e3ce27536c | ||
|
|
a6c5309a5f | ||
|
|
65d5526c70 | ||
|
|
33c4e194b8 | ||
|
|
1b11caa45c | ||
|
|
6ba17fc862 | ||
|
|
f61ecd7669 | ||
|
|
ec3c8be6ee | ||
|
|
3cd28f32ca | ||
|
|
4b6a6e806f | ||
|
|
216c124854 | ||
|
|
e26d969ca8 | ||
|
|
45f66359cd | ||
|
|
5b87a530f5 | ||
|
|
5280a45434 | ||
|
|
f7a8630584 | ||
|
|
cb67dd5498 | ||
|
|
6d8cef40c8 | ||
|
|
41b80ad20a | ||
|
|
47fac7158e | ||
|
|
6c0e1b1f04 | ||
|
|
b06520ac7c | ||
|
|
e4cad073a9 | ||
|
|
b151fa6b65 | ||
|
|
40329e182c | ||
|
|
0f38ecb863 | ||
|
|
3f43438017 | ||
|
|
bc70db58a7 | ||
|
|
ac9399d2b7 | ||
|
|
89850d0715 | ||
|
|
86be540829 | ||
|
|
0f75bf01a6 | ||
|
|
395c0be775 | ||
|
|
a40f8383ee | ||
|
|
87a7df48b8 | ||
|
|
2df39a7e51 | ||
|
|
9f8127cc54 | ||
|
|
2f1ed39bc1 | ||
|
|
0770e5f972 | ||
|
|
0fb16312dc | ||
|
|
9a030d6930 | ||
|
|
29dde5d752 | ||
|
|
b797f50596 | ||
|
|
913d22bf83 | ||
|
|
3824d1e9e4 | ||
|
|
7941b93d1c | ||
|
|
d376efbe46 | ||
|
|
64ddb1ff07 | ||
|
|
f02d40d25d | ||
|
|
672bc729a6 | ||
|
|
a0ad1a4333 | ||
|
|
f504cc9145 |
5
BUILD.gn
5
BUILD.gn
@@ -290,6 +290,7 @@ group("modules") {
|
||||
"security",
|
||||
"shell",
|
||||
"syscall",
|
||||
"testsuites/kernel:kernel_test",
|
||||
]
|
||||
|
||||
deps += [
|
||||
@@ -318,10 +319,12 @@ group("liteos_a") {
|
||||
deps = [
|
||||
":apps",
|
||||
":kernel",
|
||||
":make",
|
||||
":tests",
|
||||
"//prebuilts/lite/sysroot/build:strip",
|
||||
]
|
||||
if (liteos_skip_make == false) {
|
||||
deps += [ ":make" ]
|
||||
}
|
||||
}
|
||||
|
||||
executable("liteos") {
|
||||
|
||||
6
Kconfig
6
Kconfig
@@ -189,7 +189,7 @@ config DEBUG_VERSION
|
||||
It also means you do not want to use debug modules, like shell,telnet,tftp,nfs and
|
||||
memory check, etc.
|
||||
If you select this option that means you enable a debug version for LiteOS.
|
||||
That means you want a opposite behaviour compared to release version.
|
||||
That means you want an opposite behaviour compared to release version.
|
||||
|
||||
config DEBUG_KERNEL
|
||||
bool "Enable Debug LiteOS Kernel Resource"
|
||||
@@ -198,7 +198,7 @@ config DEBUG_KERNEL
|
||||
help
|
||||
If you select this option that means you enable debugging kernel resource.
|
||||
It also means you want to get queue, mutex, semaphore, memory debug information.
|
||||
That means you want a opposite behaviour compared to release version.
|
||||
That means you want an opposite behaviour compared to release version.
|
||||
|
||||
config DEBUG_QUEUE
|
||||
bool "Enable Queue Debugging"
|
||||
@@ -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 infomations 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
|
||||
|
||||
2
Makefile
2
Makefile
@@ -97,7 +97,7 @@ Targets:
|
||||
cleanall: clean all build outputs
|
||||
all: make liteos kernel image and rootfs image (Default target)
|
||||
$(APPS): build all apps
|
||||
$(ROOTFS): make a original rootfs image
|
||||
$(ROOTFS): make an original rootfs image
|
||||
$(LITEOS_LIBS_TARGET): compile all kernel modules (libraries)
|
||||
$(LITEOS_TARGET): make liteos kernel image
|
||||
update_config: update product kernel config (use menuconfig)
|
||||
|
||||
5
OAT.xml
5
OAT.xml
@@ -12,9 +12,10 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
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.
|
||||
|
||||
<!--
|
||||
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>
|
||||
|
||||
12
README.md
12
README.md
@@ -73,9 +73,9 @@ OpenHarmony LiteOS Cortex-A supports the [Hi3518E V300](https://gitee.com/openh
|
||||
|
||||
You need to set up the compilation environment on Linux.
|
||||
|
||||
- [Compilation environment on Linux](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-env-setup-lin.md)
|
||||
- For Hi3518E V300, see [Setting Up the Hi3518 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-board3518-setting.md).
|
||||
- For Hi3516D V300, see [Setting Up the Hi3516 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-board3516-setting.md).
|
||||
- [Setting Up Ubuntu Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-env-setup-linux.md)
|
||||
- For Hi3518E V300, see [Setting Up the Hi3518 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-hi3518-setting.md).
|
||||
- For Hi3516D V300, see [Setting Up the Hi3516 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-hi3516-setting.md).
|
||||
|
||||
### Source Code Acquisition<a name="section11443189655"></a>
|
||||
|
||||
@@ -85,9 +85,9 @@ Download and decompress a set of source code on a Linux server to acquire the [
|
||||
|
||||
For details about how to develop the first application, see:
|
||||
|
||||
- [Developing the First Example Program Running on Hi3518](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-board3518-running.md)
|
||||
- [Developing the First Example Program Running on Hi3518](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-hi3518-running.md)
|
||||
|
||||
- [Developing the First Example Program Running on Hi3516](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-board3516-running.md)
|
||||
- [Developing the First Example Program Running on Hi3516](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-lite-steps-hi3516-running.md)
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
@@ -95,5 +95,5 @@ For details about how to develop the first application, see:
|
||||
|
||||
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md)
|
||||
|
||||
**kernel\_liteos\_a**
|
||||
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md)
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ OpenHarmony LiteOS-A內核支持Hi3518EV300([介紹](https://gitee.com/openhar
|
||||
|
||||
開發者需要在Linux上搭建編譯環境:
|
||||
|
||||
- [Ubuntu編譯環境凖備](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md);
|
||||
- [編譯環境凖備](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-package-environment.md);
|
||||
- Hi3518EV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3518-setting.md);
|
||||
- Hi3516DV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516-setting.md)。
|
||||
|
||||
@@ -95,4 +95,4 @@ OpenHarmony LiteOS-A內核支持Hi3518EV300([介紹](https://gitee.com/openhar
|
||||
|
||||
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
|
||||
|
||||
**kernel\_liteos\_a**
|
||||
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh-HK.md)
|
||||
|
||||
@@ -72,7 +72,7 @@ OpenHarmony LiteOS-A内核支持Hi3518EV300([介绍](https://gitee.com/openhar
|
||||
|
||||
开发者需要在Linux上搭建编译环境:
|
||||
|
||||
- [Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-env-setup.md);
|
||||
- [编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-package-environment.md);
|
||||
- Hi3518EV300单板:参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3518-setting.md);
|
||||
- Hi3516DV300单板:参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516-setting.md)。
|
||||
|
||||
@@ -94,5 +94,5 @@ OpenHarmony LiteOS-A内核支持Hi3518EV300([介绍](https://gitee.com/openhar
|
||||
|
||||
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
|
||||
|
||||
**kernel\_liteos\_a**
|
||||
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh.md)
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#endif
|
||||
int main(int argc, char * const *argv)
|
||||
{
|
||||
(void)argv;
|
||||
int ret;
|
||||
pid_t gid;
|
||||
const char *shellPath = "/bin/mksh";
|
||||
|
||||
144
apps/lms/src/sample_usr_lms.c
Executable file → Normal file
144
apps/lms/src/sample_usr_lms.c
Executable file → Normal file
@@ -50,14 +50,16 @@ static void BufReadTest(void *buf, int start, int end)
|
||||
|
||||
static void LmsMallocTest(void)
|
||||
{
|
||||
#define TEST_SIZE 16
|
||||
printf("\n-------- LmsMallocTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsMallocTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
|
||||
printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
|
||||
BufReadTest(buf, -1, 16);
|
||||
printf("[LmsMallocTest] write overflow error should be triggered, write range[0,16]\n");
|
||||
BufWriteTest(buf, 0, 16);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
|
||||
BufReadTest(buf, -1, TEST_SIZE);
|
||||
printf("[LmsMallocTest] write overflow error should be triggered, write range[0, TEST_SIZE]\n");
|
||||
BufWriteTest(buf, 0, TEST_SIZE);
|
||||
|
||||
free(buf);
|
||||
printf("\n-------- LmsMallocTest End --------\n");
|
||||
@@ -65,46 +67,61 @@ static void LmsMallocTest(void)
|
||||
|
||||
static void LmsReallocTest(void)
|
||||
{
|
||||
#define TEST_SIZE 64
|
||||
#define TEST_SIZE_MIN 32
|
||||
printf("\n-------- LmsReallocTest Start --------\n");
|
||||
char *buf = (char *)malloc(64);
|
||||
printf("[LmsReallocTest] malloc addr:%p size:%d\n", buf, 64);
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,64]\n");
|
||||
BufReadTest(buf, -1, 64);
|
||||
buf = (char *)realloc(buf, 32);
|
||||
printf("[LmsReallocTest] realloc addr:%p size:%d\n", buf, 32);
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1,32]\n");
|
||||
BufReadTest(buf, -1, 32);
|
||||
free(buf);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
|
||||
BufReadTest(buf, -1, TEST_SIZE);
|
||||
char *buf1 = (char *)realloc(buf, TEST_SIZE_MIN);
|
||||
if (buf1 == NULL) {
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
buf = NULL;
|
||||
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE_MIN]\n");
|
||||
BufReadTest(buf1, -1, TEST_SIZE_MIN);
|
||||
free(buf1);
|
||||
printf("\n-------- LmsReallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsCallocTest(void)
|
||||
{
|
||||
#define TEST_SIZE 16
|
||||
printf("\n-------- LmsCallocTest Start --------\n");
|
||||
char *buf = (char *)calloc(4, 4);
|
||||
printf("[LmsCallocTest] calloc addr:%p size:%d\n", buf, 16);
|
||||
printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1,16]\n");
|
||||
BufReadTest(buf, -1, 16);
|
||||
char *buf = (char *)calloc(4, 4); /* 4: test size */
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
|
||||
BufReadTest(buf, -1, TEST_SIZE);
|
||||
free(buf);
|
||||
printf("\n-------- LmsCallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsVallocTest(void)
|
||||
{
|
||||
#define TEST_SIZE 4096
|
||||
printf("\n-------- LmsVallocTest Start --------\n");
|
||||
char *buf = (char *)valloc(4096);
|
||||
printf("[LmsVallocTest] valloc addr:%p size:%d\n", buf, 4096);
|
||||
printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1,4096]\n");
|
||||
BufReadTest(buf, -1, 4096);
|
||||
char *buf = (char *)valloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
|
||||
BufReadTest(buf, -1, TEST_SIZE);
|
||||
free(buf);
|
||||
printf("\n-------- LmsVallocTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsAlignedAllocTest(void)
|
||||
{
|
||||
#define TEST_ALIGN_SIZE 64
|
||||
#define TEST_SIZE 128
|
||||
printf("\n-------- LmsAlignedAllocTest Start --------\n");
|
||||
char *buf = (char *)aligned_alloc(64, 128);
|
||||
printf("[LmsAlignedAllocTest] aligned_alloc boundsize:%d addr:%p size:%d\n", 64, buf, 128);
|
||||
char *buf = (char *)aligned_alloc(TEST_ALIGN_SIZE, TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsAlignedAllocTest] read overflow & underflow error should be triggered, read range[-1,128]\n");
|
||||
BufReadTest(buf, -1, 128);
|
||||
free(buf);
|
||||
@@ -113,44 +130,55 @@ static void LmsAlignedAllocTest(void)
|
||||
|
||||
static void LmsMemsetTest(void)
|
||||
{
|
||||
#define TEST_SIZE 32
|
||||
printf("\n-------- LmsMemsetTest Start --------\n");
|
||||
char *buf = (char *)malloc(32);
|
||||
printf("[LmsMemsetTest] malloc addr:%p size:%d\n", buf, 32);
|
||||
printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", 33);
|
||||
memset(buf, 0, 33);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", TEST_SIZE + 1);
|
||||
memset(buf, 0, TEST_SIZE + 1);
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemsetTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsMemcpyTest(void)
|
||||
{
|
||||
#define TEST_SIZE 20
|
||||
printf("\n-------- LmsMemcpyTest Start --------\n");
|
||||
char *buf = (char *)malloc(20);
|
||||
printf("[LmsMemcpyTest] malloc addr:%p size:%d\n", buf, 20);
|
||||
char localBuf[32] = {0};
|
||||
printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", 21);
|
||||
memcpy(buf, localBuf, 21);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
char localBuf[32] = {0}; /* 32: test size */
|
||||
printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", TEST_SIZE + 1);
|
||||
memcpy(buf, localBuf, TEST_SIZE + 1);
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemcpyTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsMemmoveTest(void)
|
||||
{
|
||||
#define TEST_SIZE 20
|
||||
printf("\n-------- LmsMemmoveTest Start --------\n");
|
||||
char *buf = (char *)malloc(20);
|
||||
printf("[LmsMemmoveTest] malloc addr:%p size:%d\n", buf, 20);
|
||||
printf("[LmsMemmoveTest] memmove overflow error should be triggered, dest addr:%p src addr:%p size:%d\n", buf + 12,
|
||||
buf, 10);
|
||||
memmove(buf + 12, buf, 10);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsMemmoveTest] memmove overflow error should be triggered\n");
|
||||
memmove(buf + 12, buf, 10); /* 12 and 10: test size */
|
||||
free(buf);
|
||||
printf("\n-------- LmsMemmoveTest End --------\n");
|
||||
}
|
||||
|
||||
static void LmsStrcpyTest(void)
|
||||
{
|
||||
#define TEST_SIZE 16
|
||||
printf("\n-------- LmsStrcpyTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsStrcpyTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
char *testStr = "bbbbbbbbbbbbbbbbb";
|
||||
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n", strlen(testStr) + 1);
|
||||
strcpy(buf, testStr);
|
||||
@@ -160,9 +188,12 @@ static void LmsStrcpyTest(void)
|
||||
|
||||
static void LmsStrcatTest(void)
|
||||
{
|
||||
#define TEST_SIZE 16
|
||||
printf("\n-------- LmsStrcatTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsStrcatTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
buf[0] = 'a';
|
||||
buf[1] = 'b';
|
||||
buf[2] = 0;
|
||||
@@ -177,22 +208,30 @@ static void LmsStrcatTest(void)
|
||||
|
||||
static void LmsFreeTest(void)
|
||||
{
|
||||
#define TEST_SIZE 16
|
||||
printf("\n-------- LmsFreeTest Start --------\n");
|
||||
char *buf = (char *)malloc(16);
|
||||
printf("[LmsFreeTest] malloc addr:%p size:%d\n", buf, 16);
|
||||
printf("[LmsFreeTest] free addr:%p\n", buf, 16);
|
||||
char *buf = (char *)malloc(TEST_SIZE);
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("[LmsFreeTest] free size:%d\n", TEST_SIZE);
|
||||
free(buf);
|
||||
printf("[LmsFreeTest] Use after free error should be triggered, read addr:%p range[1,1]\n", buf);
|
||||
printf("[LmsFreeTest] Use after free error should be triggered, read range[1,1]\n");
|
||||
BufReadTest(buf, 1, 1);
|
||||
printf("[LmsFreeTest] double free error should be triggered, free addr:%p\n", buf);
|
||||
printf("[LmsFreeTest] double free error should be triggered\n");
|
||||
free(buf);
|
||||
printf("\n-------- LmsFreeTest End --------\n");
|
||||
}
|
||||
|
||||
int main(int argc, char * const * argv)
|
||||
int main(int argc, char * const *argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
printf("\n############### Lms Test start ###############\n");
|
||||
char *tmp = (char *)malloc(5000);
|
||||
char *tmp = (char *)malloc(5000); /* 5000: test mem size */
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
LmsMallocTest();
|
||||
LmsReallocTest();
|
||||
LmsCallocTest();
|
||||
@@ -204,5 +243,6 @@ int main(int argc, char * const * argv)
|
||||
LmsStrcpyTest();
|
||||
LmsStrcatTest();
|
||||
LmsFreeTest();
|
||||
free(tmp);
|
||||
printf("\n############### Lms Test End ###############\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,17 @@ 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) {
|
||||
goto EXIT:
|
||||
}
|
||||
|
||||
char *buf = (char *)malloc(size);
|
||||
int len = PerfRead(fd, buf, size);
|
||||
PerfPrintBuffer(buf, len);
|
||||
free(buf);
|
||||
if (buf != NULL) {
|
||||
int len = PerfRead(fd, buf, size);
|
||||
PerfPrintBuffer(buf, len);
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "list") == 0) {
|
||||
PerfList();
|
||||
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "stat") == 0) {
|
||||
@@ -77,6 +84,7 @@ int main(int argc, char **argv)
|
||||
PerfUsage();
|
||||
}
|
||||
|
||||
EXIT:
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
|
||||
ssize_t totalWrite = 0;
|
||||
|
||||
if (filePath == NULL || buf == NULL || bufSize == 0) {
|
||||
printf("filePath: %p, buf: %p, bufSize: %u!\n", filePath, buf, bufSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,15 @@
|
||||
#ifndef _SHELL_PRI_H
|
||||
#define _SHELL_PRI_H
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void *ShellEntry(void *argv);
|
||||
extern void ShellEntry(ShellCB *shellCB);
|
||||
extern void *ShellTask(void *argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#ifndef _SHMSG_H
|
||||
#define _SHMSG_H
|
||||
|
||||
#include "shell_list.h"
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -61,8 +62,7 @@ extern "C" {
|
||||
|
||||
typedef void (* OutputFunc)(const char *fmt, ...);
|
||||
extern int ShellTaskInit(ShellCB *shellCB);
|
||||
extern int ShellEntryInit(ShellCB *shellCB);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[]);
|
||||
extern void ChildExec(const char *cmdName, char *const paramArray[], bool foreground);
|
||||
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
|
||||
extern int ShellNotify(ShellCB *shellCB);
|
||||
|
||||
|
||||
@@ -31,13 +31,16 @@
|
||||
|
||||
#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;
|
||||
|
||||
@@ -77,13 +80,8 @@ static int OsShellCreateTask(ShellCB *shellCB)
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = ShellEntryInit(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
(void)pthread_join(shellCB->shellTaskHandle, NULL);
|
||||
(void)pthread_join(shellCB->shellEntryHandle, NULL);
|
||||
shellCB->shellEntryHandle = pthread_self();
|
||||
return 0;
|
||||
|
||||
OUT:
|
||||
ShellDeinit(shellCB);
|
||||
@@ -98,7 +96,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);
|
||||
ChildExec(argv[1], argv + 1, FALSE);
|
||||
}
|
||||
for (i = 0; argv[i]; i++) {
|
||||
len += strlen(argv[i]);
|
||||
@@ -108,11 +106,15 @@ static int DoShellExec(char **argv)
|
||||
if (!cmdLine) {
|
||||
return ret;
|
||||
}
|
||||
memset_s(cmdLine, len, 0, len);
|
||||
errno_t ret1 = memset_s(cmdLine, len, 0, len);
|
||||
if (ret1 != EOK) {
|
||||
free(cmdLine);
|
||||
return ret1;
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
strcat_s(cmdLine, len, argv[j]);
|
||||
strcat_s(cmdLine, len, " ");
|
||||
(void)strcat_s(cmdLine, len, argv[j]);
|
||||
(void)strcat_s(cmdLine, len, " ");
|
||||
}
|
||||
|
||||
cmdLine[len - 2] = '\0'; /* 2, (len - 2) is the end of cmdline buf */
|
||||
@@ -121,11 +123,22 @@ 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;
|
||||
@@ -161,7 +174,12 @@ int main(int argc, char **argv)
|
||||
sem_init(&shellCB->shellSem, 0, 0);
|
||||
|
||||
g_shellCB = shellCB;
|
||||
return OsShellCreateTask(shellCB);
|
||||
ret = OsShellCreateTask(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT3;
|
||||
}
|
||||
|
||||
ShellEntry(shellCB);
|
||||
|
||||
ERR_OUT3:
|
||||
(void)pthread_mutex_destroy(&shellCB->historyMutex);
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "dirent.h"
|
||||
#include "securec.h"
|
||||
|
||||
|
||||
#define SHELL_INIT_MAGIC_FLAG 0xABABABAB
|
||||
#define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */
|
||||
|
||||
@@ -378,7 +377,7 @@ static int OsTabMatchFile(char *cmdKey, unsigned int *len)
|
||||
* Description: Pass in the string and clear useless space ,which include:
|
||||
* 1) The overmatch space which is not be marked by Quote's area
|
||||
* Squeeze the overmatch space into one space
|
||||
* 2) Clear all space before first valid charatctor
|
||||
* 2) Clear all space before first valid character
|
||||
* Input: cmdKey : Pass in the buff string, which is ready to be operated
|
||||
* cmdOut : Pass out the buffer string ,which has already been operated
|
||||
* size : cmdKey length
|
||||
@@ -407,17 +406,17 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
|
||||
|
||||
/* Backup the 'output' start address */
|
||||
outputBak = output;
|
||||
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invalid charactor */
|
||||
/* Scan each character in 'cmdKey',and squeeze the overmuch space and ignore invalid character */
|
||||
for (; *cmdKey != '\0'; cmdKey++) {
|
||||
/* Detected a Double Quotes, switch the matching status */
|
||||
if (*(cmdKey) == '\"') {
|
||||
SWITCH_QUOTES_STATUS(quotes);
|
||||
}
|
||||
/* Ignore the current charactor in following situation */
|
||||
/* Ignore the current character in following situation */
|
||||
/* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
|
||||
/* 2) Current charactor is a space */
|
||||
/* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
|
||||
/* 4) Invalid charactor, such as single quotes */
|
||||
/* 2) Current character is a space */
|
||||
/* 3) Next character is a space too, or the string is been seeked to the end already(\0) */
|
||||
/* 4) Invalid character, such as single quotes */
|
||||
if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
|
||||
continue;
|
||||
}
|
||||
@@ -431,7 +430,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
|
||||
/* Restore the 'output' start address */
|
||||
output = outputBak;
|
||||
len = strlen(output);
|
||||
/* Clear the space which is located at the first charactor in buffer */
|
||||
/* Clear the space which is located at the first character in buffer */
|
||||
if (*output == ' ') {
|
||||
output++;
|
||||
len--;
|
||||
@@ -585,7 +584,6 @@ END:
|
||||
|
||||
unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
|
||||
{
|
||||
/* TODO: complete the usrspace command */
|
||||
unsigned int ret = SH_OK;
|
||||
if (cmdParsed && cmdStr) {
|
||||
ret = SH_NOK;
|
||||
|
||||
@@ -334,12 +334,12 @@ char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
/* If reach a double quotes, switch the quotes matching status */
|
||||
if (*tmpStr == '\"') {
|
||||
SWITCH_QUOTES_STATUS(quotes);
|
||||
/* Ignore the double quote charactor itself */
|
||||
/* Ignore the double quote character itself */
|
||||
tmpStr++;
|
||||
continue;
|
||||
}
|
||||
/* If detected a space which the quotes matching status is false */
|
||||
/* which said has detected the first space for seperator, finish this scan operation */
|
||||
/* which said has detected the first space for separator, finish this scan operation */
|
||||
if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) {
|
||||
break;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
return cmdName;
|
||||
}
|
||||
|
||||
void ChildExec(const char *cmdName, char *const paramArray[])
|
||||
void ChildExec(const char *cmdName, char *const paramArray[], bool foreground)
|
||||
{
|
||||
int ret;
|
||||
pid_t gid;
|
||||
@@ -367,10 +367,12 @@ void ChildExec(const char *cmdName, char *const paramArray[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
exit(1);
|
||||
if (!foreground) {
|
||||
ret = tcsetpgrp(STDIN_FILENO, gid);
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = execve(cmdName, paramArray, NULL);
|
||||
@@ -404,20 +406,30 @@ int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, 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("Faild to fork from shell\n");
|
||||
return;
|
||||
} else if (forkPid == 0) {
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray);
|
||||
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray, foreground);
|
||||
} else {
|
||||
waitpid(forkPid, 0, 0);
|
||||
if (!foreground) {
|
||||
(void)waitpid(forkPid, 0, 0);
|
||||
}
|
||||
ret = tcsetpgrp(STDIN_FILENO, getpid());
|
||||
if (ret != 0) {
|
||||
printf("tcsetpgrp failed, errno %d\n", errno);
|
||||
@@ -503,7 +515,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
|
||||
*output = shiftStr;
|
||||
*outputlen = shiftLen;
|
||||
|
||||
/* Check and parse "./", located at the first two charaters of the cmd */
|
||||
/* Check and parse "./", located at the first two characters of the cmd */
|
||||
if ((shiftLen > removeLen) && (shiftStr[0] == '.') && (shiftStr[1] == '/')) {
|
||||
execLen = strlen(execCmd);
|
||||
newLen = execLen + shiftLen - removeLen; /* i.e., newLen - execLen == shiftLen - removeLen */
|
||||
@@ -567,20 +579,10 @@ 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) {
|
||||
/* recycle zombine child process */
|
||||
RecycleZombieChild();
|
||||
buf = GetCmdline(shellCB);
|
||||
char *buf = GetCmdline(shellCB);
|
||||
if (buf == NULL) {
|
||||
break;
|
||||
}
|
||||
@@ -654,25 +656,19 @@ static int ShellKernelReg(unsigned int shellHandle)
|
||||
return ioctl(STDIN_FILENO, CONSOLE_CONTROL_REG_USERTASK, shellHandle);
|
||||
}
|
||||
|
||||
void *ShellEntry(void *argv)
|
||||
void ShellEntry(ShellCB *shellCB)
|
||||
{
|
||||
char ch;
|
||||
int ret;
|
||||
int n;
|
||||
pid_t tid = syscall(__NR_gettid);
|
||||
ShellCB *shellCB = (ShellCB *)argv;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
(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");
|
||||
@@ -685,32 +681,5 @@ void *ShellEntry(void *argv)
|
||||
ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ extern "C" {
|
||||
|
||||
#define TFTP_NULL_UINT32 ((u32_t)0xffffffffUL)
|
||||
|
||||
#define TFTP_NULL_INT32 -1
|
||||
#define TFTP_NULL_INT32 (-1)
|
||||
|
||||
/** @cond liteos
|
||||
* @defgroup TFTP_Interfaces
|
||||
@@ -114,7 +114,7 @@ typedef enum tagTFTPC_OpCode {
|
||||
TFTPC_OP_RRQ = 1, /* read request */
|
||||
TFTPC_OP_WRQ, /* write request */
|
||||
TFTPC_OP_DATA, /* data packet */
|
||||
TFTPC_OP_ACK, /* acknowledgement */
|
||||
TFTPC_OP_ACK, /* acknowledgment */
|
||||
TFTPC_OP_ERROR, /* error code */
|
||||
TFTPC_OP_OPT /* option code */
|
||||
} TFTPC_OPCODE_E;
|
||||
|
||||
@@ -50,11 +50,11 @@ static char *TftpError[] = {
|
||||
"Error while sending data to the peer\n",
|
||||
"Requested file is not found\n",
|
||||
"This is the error sent by the server when hostname cannot be resolved\n",
|
||||
"Input paramters passed to TFTP interfaces are invalid\n",
|
||||
"Input parameters passed to TFTP interfaces are invalid\n",
|
||||
"Error detected in TFTP packet or the error received from the TFTP server\n",
|
||||
"Error during packet synhronization while sending or unexpected packet is received\n",
|
||||
"File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n",
|
||||
"File name lenght greater than 256\n",
|
||||
"File name length greater than 256\n",
|
||||
"Hostname IP is not valid\n",
|
||||
"TFTP server returned file access error\n",
|
||||
"TFTP server returned error signifying that the DISK is full to write\n",
|
||||
@@ -66,11 +66,11 @@ static char *TftpError[] = {
|
||||
"File create error\n",
|
||||
"File write error\n",
|
||||
"Max time expired while waiting for file to be recived\n",
|
||||
"Error when the received packet is less than 4bytes(error lenght) or greater than 512bytes\n",
|
||||
"Error when the received packet is less than 4bytes(error length) or greater than 512bytes\n",
|
||||
"Returned by TFTP server for protocol user error\n",
|
||||
"The destination file path length greater than 256\n",
|
||||
"Returned by TFTP server for undefined transfer ID\n",
|
||||
"IOCTL fucntion failed at TFTP client while setting the socket to non-block\n",
|
||||
"IOCTL function failed at TFTP client while setting the socket to non-block\n",
|
||||
};
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
|
||||
@@ -189,7 +189,7 @@ u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S
|
||||
if (iRet == -1) {
|
||||
return TFTPC_SELECT_ERROR;
|
||||
} else if (iRet == 0) {
|
||||
return TFTPC_TIMEOUT_ERROR; /* Select timeout occured */
|
||||
return TFTPC_TIMEOUT_ERROR; /* Select timeout occurred */
|
||||
}
|
||||
|
||||
if (!FD_ISSET(iSockNum, &stReadfds)) {
|
||||
@@ -218,7 +218,7 @@ u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S
|
||||
usOpcode = ntohs(pstRecvBuf->usOpcode);
|
||||
/* if this packet is ERROR packet */
|
||||
if (usOpcode == TFTPC_OP_ERROR) {
|
||||
ulError = ntohs (pstRecvBuf->u.stTFTP_Err.usErrNum);
|
||||
ulError = ntohs(pstRecvBuf->u.stTFTP_Err.usErrNum);
|
||||
|
||||
/*If the error is according to RFC,then convert to lwip error codes.
|
||||
Constant values are used in the cases as these error codes are as per
|
||||
@@ -268,7 +268,7 @@ u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S
|
||||
*pulSize = (u32_t)iRet;
|
||||
|
||||
/* If received packet is first block of data(for get operation) or if
|
||||
received packet is acknowledgement for write request (put operation)
|
||||
received packet is acknowledgment for write request (put operation)
|
||||
store the received port number */
|
||||
if (((usOpcode == TFTPC_OP_DATA) &&
|
||||
(ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum) == 1)) ||
|
||||
@@ -687,7 +687,7 @@ u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
|
||||
|
||||
ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf,
|
||||
&ulIgnorePkt, &stServerAddr, pstSendBuf);
|
||||
/* If select timeout occured */
|
||||
/* If select timeout occurred */
|
||||
if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
|
||||
ulTotalTime++;
|
||||
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
|
||||
@@ -727,7 +727,7 @@ u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
|
||||
}
|
||||
|
||||
/* if this packet is unkonwn or incorrect packet */
|
||||
if (ntohs (pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
|
||||
if (ntohs(pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
|
||||
/* Send error packet to server */
|
||||
lwip_tftp_send_error(iSockNum,
|
||||
TFTPC_PROTOCOL_PROTO_ERROR,
|
||||
@@ -982,7 +982,7 @@ u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_
|
||||
return TFTPC_MEMALLOC_ERROR;
|
||||
}
|
||||
|
||||
/* First time intialize the buffer */
|
||||
/* First time initialize the buffer */
|
||||
(void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
|
||||
|
||||
/* The destination path can only be one of the following:
|
||||
@@ -1221,7 +1221,7 @@ u32_t lwip_tftp_inner_put_file(s32_t iSockNum,
|
||||
return TFTPC_MEMALLOC_ERROR;
|
||||
}
|
||||
|
||||
/* First time intialize the buffer */
|
||||
/* First time initialize the buffer */
|
||||
(void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
|
||||
|
||||
/* Initialize from address to the server address at first */
|
||||
@@ -1235,7 +1235,7 @@ u32_t lwip_tftp_inner_put_file(s32_t iSockNum,
|
||||
ulError = lwip_tftp_recv_from_server(iSockNum, &ulPktSize,
|
||||
pstRecvBuf, &ulIgnorePkt,
|
||||
pstServerAddr, pstSendBuf);
|
||||
/* If select timeout occured */
|
||||
/* If select timeout occurred */
|
||||
if (ulError == TFTPC_TIMEOUT_ERROR) {
|
||||
ulTotalTime++;
|
||||
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
|
||||
@@ -1526,7 +1526,7 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
|
||||
|
||||
ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf, &ulIgnorePkt,
|
||||
&stServerAddr, pstSendBuf);
|
||||
/* If select timeout occured */
|
||||
/* If select timeout occurred */
|
||||
if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
|
||||
ulTotalTime++;
|
||||
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
|
||||
@@ -1557,7 +1557,7 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
|
||||
}
|
||||
|
||||
/* if this packet is unkonwn or incorrect packet */
|
||||
if (ntohs (pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
|
||||
if (ntohs(pstRecvBuf->usOpcode) != TFTPC_OP_DATA) {
|
||||
/* Send error packet to server */
|
||||
lwip_tftp_send_error(iSockNum,
|
||||
TFTPC_PROTOCOL_PROTO_ERROR,
|
||||
|
||||
@@ -70,6 +70,10 @@ static void TraceRead(int fd, size_t size)
|
||||
{
|
||||
ssize_t i;
|
||||
ssize_t len;
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *buffer = (char *)malloc(size);
|
||||
if (buffer == NULL) {
|
||||
printf("Read buffer malloc failed.\n");
|
||||
|
||||
@@ -246,7 +246,7 @@ STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v)
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement.
|
||||
* This API is used to implement the atomic auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
@@ -280,7 +280,7 @@ STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
|
||||
* This API is used to implement the atomic auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
@@ -531,7 +531,7 @@ STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v)
|
||||
* @brief Atomic64 auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic64 auto-decrement.
|
||||
* This API is used to implement the atomic64 auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
@@ -566,7 +566,7 @@ STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v)
|
||||
* @brief Atomic64 auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic64 auto-decrement and return the result of auto-decrement.
|
||||
* This API is used to implement the atomic64 auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
|
||||
@@ -55,8 +55,8 @@ extern "C" {
|
||||
#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL)
|
||||
#endif
|
||||
extern VOID OsHwiInit(VOID);
|
||||
extern VOID OsIncHwiFormCnt(UINT32 index);
|
||||
extern UINT32 OsGetHwiFormCnt(UINT32 index);
|
||||
extern VOID OsIncHwiFormCnt(UINT16 cpuid, UINT32 index);
|
||||
extern UINT32 OsGetHwiFormCnt(UINT16 cpuid, 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];
|
||||
@@ -112,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;
|
||||
@@ -531,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
|
||||
@@ -556,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
|
||||
@@ -979,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;
|
||||
@@ -1000,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);
|
||||
@@ -1021,7 +1021,7 @@ STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuID)
|
||||
|
||||
STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
{
|
||||
UINT32 currCpuID = ArchCurrCpuid();
|
||||
UINT32 currCpuid = ArchCurrCpuid();
|
||||
UINT32 ret, target;
|
||||
|
||||
OsCpuStatusSet(CPU_EXC);
|
||||
@@ -1029,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
|
||||
*/
|
||||
@@ -1051,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);
|
||||
@@ -1066,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
|
||||
}
|
||||
@@ -1077,7 +1077,7 @@ STATIC VOID OsCheckCpuStatus(VOID)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsCheckAllCpuStatus();
|
||||
#else
|
||||
g_currHandleExcCpuID = ArchCurrCpuid();
|
||||
g_currHandleExcCpuid = ArchCurrCpuid();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -46,16 +46,11 @@ 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[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC UINT32 g_hwiFormCnt[LOSCFG_KERNEL_CORE_NUM][OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
VOID OsIncHwiFormCnt(UINT32 index)
|
||||
UINT32 OsGetHwiFormCnt(UINT16 cpuid, UINT32 index)
|
||||
{
|
||||
g_hwiFormCnt[index]++;
|
||||
}
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
return g_hwiFormCnt[cpuid][index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
@@ -74,16 +69,17 @@ 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[ArchCurrCpuid()];
|
||||
intCnt = &g_intCount[cpuid];
|
||||
*intCnt = *intCnt + 1;
|
||||
|
||||
OsSchedIrqStartTime();
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqStart();
|
||||
OsCpupIrqStart(cpuid);
|
||||
#endif
|
||||
|
||||
OsSchedIrqStartTime();
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, intNum);
|
||||
hwiForm = (&g_hwiForm[intNum]);
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
@@ -105,14 +101,14 @@ VOID OsInterrupt(UINT32 intNum)
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
}
|
||||
#endif
|
||||
++g_hwiFormCnt[intNum];
|
||||
++g_hwiFormCnt[cpuid][intNum];
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, intNum);
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqEnd(intNum);
|
||||
#endif
|
||||
OsSchedIrqUpdateUsedTime();
|
||||
OsSchedIrqUsedTimeUpdate();
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqEnd(cpuid, intNum);
|
||||
#endif
|
||||
/* Must keep the operation at the end of the interface */
|
||||
*intCnt = *intCnt - 1;
|
||||
}
|
||||
|
||||
@@ -121,8 +121,9 @@ 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)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
bic r0, #(1 << 12) /* i cache */
|
||||
bic r0, #(1 << 2) /* d cache */
|
||||
bic r0, #(1 << 0) /* mmu */
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* enable fpu+neon */
|
||||
@@ -282,11 +283,11 @@ mmu_setup:
|
||||
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)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */
|
||||
orr r12, #(1 << 0) /* mmu enable */
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
orr r12, #(1 << 2) /* D cache enable */
|
||||
orr r12, #(1 << 12) /* I cache enable */
|
||||
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,8 +101,9 @@ __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)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
bic r0, #(1 << 12) /* i cache */
|
||||
bic r0, #(1 << 2) /* d cache */
|
||||
bic r0, #(1 << 0) /* mmu */
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* enable fpu+neon */
|
||||
@@ -269,11 +270,11 @@ mmu_setup:
|
||||
isb
|
||||
|
||||
mrc p15, 0, r12, c1, c0, 0
|
||||
bic r12, #(1 << 29 | 1 << 28)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */
|
||||
orr r12, #(1 << 0) /* mmu enable */
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
orr r12, #(1 << 2) /* D cache enable */
|
||||
orr r12, #(1 << 12) /* I cache enable */
|
||||
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 : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
count : (INT32)(USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
|
||||
for (i = 0; i < maxCount; ++i) {
|
||||
if (LOS_GetUser(&character, src + offset) != LOS_OK) {
|
||||
|
||||
@@ -49,7 +49,7 @@ STATIC UINT32 g_curIrqNum = 0;
|
||||
*/
|
||||
STATIC VOID GicWriteSgi(UINT32 vector, UINT32 cpuMask, UINT32 filter)
|
||||
{
|
||||
UINT32 val = ((filter & 0x3) << 24) | ((cpuMask & 0xFF) << 16) |
|
||||
UINT32 val = ((filter & 0x3) << 24) | ((cpuMask & 0xFF) << 16) | /* 24, 16: Register bit offset */
|
||||
(vector & 0xF);
|
||||
|
||||
GIC_REG_32(GICD_SGIR) = val;
|
||||
@@ -62,7 +62,7 @@ VOID HalIrqSendIpi(UINT32 target, UINT32 ipi)
|
||||
|
||||
VOID HalIrqSetAffinity(UINT32 vector, UINT32 cpuMask)
|
||||
{
|
||||
UINT32 offset = vector / 4;
|
||||
UINT32 offset = vector / 4; /* 4: Interrupt bit width */
|
||||
UINT32 index = vector & 0x3;
|
||||
|
||||
GIC_REG_8(GICD_ITARGETSR(offset) + index) = cpuMask;
|
||||
@@ -80,7 +80,7 @@ VOID HalIrqMask(UINT32 vector)
|
||||
return;
|
||||
}
|
||||
|
||||
GIC_REG_32(GICD_ICENABLER(vector / 32)) = 1U << (vector % 32);
|
||||
GIC_REG_32(GICD_ICENABLER(vector / 32)) = 1U << (vector % 32); /* 32: Interrupt bit width */
|
||||
}
|
||||
|
||||
VOID HalIrqUnmask(UINT32 vector)
|
||||
@@ -89,7 +89,7 @@ VOID HalIrqUnmask(UINT32 vector)
|
||||
return;
|
||||
}
|
||||
|
||||
GIC_REG_32(GICD_ISENABLER(vector >> 5)) = 1U << (vector % 32);
|
||||
GIC_REG_32(GICD_ISENABLER(vector >> 5)) = 1U << (vector % 32); /* 5, 32: Register bit offset */
|
||||
}
|
||||
|
||||
VOID HalIrqPending(UINT32 vector)
|
||||
@@ -98,7 +98,7 @@ VOID HalIrqPending(UINT32 vector)
|
||||
return;
|
||||
}
|
||||
|
||||
GIC_REG_32(GICD_ISPENDR(vector >> 5)) = 1U << (vector % 32);
|
||||
GIC_REG_32(GICD_ISPENDR(vector >> 5)) = 1U << (vector % 32); /* 5, 32: Register bit offset */
|
||||
}
|
||||
|
||||
VOID HalIrqClear(UINT32 vector)
|
||||
@@ -119,24 +119,24 @@ VOID HalIrqInit(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
|
||||
/* set externel interrupts to be level triggered, active low. */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 16) {
|
||||
GIC_REG_32(GICD_ICFGR(i / 16)) = 0;
|
||||
/* set external interrupts to be level triggered, active low. */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 16) { /* 32: Start interrupt number, 16: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICFGR(i / 16)) = 0; /* 16: Register bit offset */
|
||||
}
|
||||
|
||||
/* set externel interrupts to CPU 0 */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 4) {
|
||||
/* set external interrupts to CPU 0 */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 4) { /* 32: Start interrupt number, 4: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ITARGETSR(i / 4)) = 0x01010101;
|
||||
}
|
||||
|
||||
/* set priority on all interrupts */
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 4) {
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 4) { /* 4: Interrupt bit width */
|
||||
GIC_REG_32(GICD_IPRIORITYR(i / 4)) = GICD_INT_DEF_PRI_X4;
|
||||
}
|
||||
|
||||
/* disable all interrupts. */
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) {
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = ~0;
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) { /* 32: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = ~0; /* 32: Interrupt bit width */
|
||||
}
|
||||
|
||||
HalIrqInitPercpu();
|
||||
|
||||
@@ -42,9 +42,9 @@ STATIC UINT32 g_curIrqNum = 0;
|
||||
|
||||
STATIC INLINE UINT64 MpidrToAffinity(UINT64 mpidr)
|
||||
{
|
||||
return ((MPIDR_AFF_LEVEL(mpidr, 3) << 32) |
|
||||
(MPIDR_AFF_LEVEL(mpidr, 2) << 16) |
|
||||
(MPIDR_AFF_LEVEL(mpidr, 1) << 8) |
|
||||
return ((MPIDR_AFF_LEVEL(mpidr, 3) << 32) | /* 3: Serial number, 32: Register bit offset */
|
||||
(MPIDR_AFF_LEVEL(mpidr, 2) << 16) | /* 2: Serial number, 16: Register bit offset */
|
||||
(MPIDR_AFF_LEVEL(mpidr, 1) << 8) | /* 1: Serial number, 8: Register bit offset */
|
||||
(MPIDR_AFF_LEVEL(mpidr, 0)));
|
||||
}
|
||||
|
||||
@@ -106,10 +106,10 @@ STATIC VOID GicSgi(UINT32 irq, UINT32 cpuMask)
|
||||
tList = GicTargetList(&cpu, cpuMask, cluster);
|
||||
|
||||
/* Generates a Group 1 interrupt for the current security state */
|
||||
val = ((MPIDR_AFF_LEVEL(cluster, 3) << 48) |
|
||||
(MPIDR_AFF_LEVEL(cluster, 2) << 32) |
|
||||
(MPIDR_AFF_LEVEL(cluster, 1) << 16) |
|
||||
(irq << 24) | tList);
|
||||
val = ((MPIDR_AFF_LEVEL(cluster, 3) << 48) | /* 3: Serial number, 48: Register bit offset */
|
||||
(MPIDR_AFF_LEVEL(cluster, 2) << 32) | /* 2: Serial number, 32: Register bit offset */
|
||||
(MPIDR_AFF_LEVEL(cluster, 1) << 16) | /* 1: Serial number, 16: Register bit offset */
|
||||
(irq << 24) | tList); /* 24: Register bit offset */
|
||||
|
||||
GiccSetSgi1r(val);
|
||||
}
|
||||
@@ -150,9 +150,9 @@ STATIC INLINE VOID GicdSetGroup(UINT32 irq)
|
||||
{
|
||||
/* configure spi as group 0 on secure mode and group 1 on unsecure mode */
|
||||
#ifdef LOSCFG_ARCH_SECURE_MONITOR_MODE
|
||||
GIC_REG_32(GICD_IGROUPR(irq / 32)) = 0;
|
||||
GIC_REG_32(GICD_IGROUPR(irq / 32)) = 0; /* 32: Interrupt bit width */
|
||||
#else
|
||||
GIC_REG_32(GICD_IGROUPR(irq / 32)) = 0xffffffff;
|
||||
GIC_REG_32(GICD_IGROUPR(irq / 32)) = 0xffffffff; /* 32: Interrupt bit width */
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -248,13 +248,13 @@ UINT32 HalCurIrqGet(VOID)
|
||||
VOID HalIrqMask(UINT32 vector)
|
||||
{
|
||||
INT32 i;
|
||||
const UINT32 mask = 1U << (vector % 32);
|
||||
const UINT32 mask = 1U << (vector % 32); /* 32: Interrupt bit width */
|
||||
|
||||
if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vector < 32) {
|
||||
if (vector < 32) { /* 32: Interrupt bit width */
|
||||
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
|
||||
GIC_REG_32(GICR_ICENABLER0(i)) = mask;
|
||||
GicWaitForRwp(GICR_CTLR(i));
|
||||
@@ -268,19 +268,19 @@ VOID HalIrqMask(UINT32 vector)
|
||||
VOID HalIrqUnmask(UINT32 vector)
|
||||
{
|
||||
INT32 i;
|
||||
const UINT32 mask = 1U << (vector % 32);
|
||||
const UINT32 mask = 1U << (vector % 32); /* 32: Interrupt bit width */
|
||||
|
||||
if ((vector > OS_USER_HWI_MAX) || (vector < OS_USER_HWI_MIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vector < 32) {
|
||||
if (vector < 32) { /* 32: Interrupt bit width */
|
||||
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
|
||||
GIC_REG_32(GICR_ISENABLER0(i)) = mask;
|
||||
GicWaitForRwp(GICR_CTLR(i));
|
||||
}
|
||||
} else {
|
||||
GIC_REG_32(GICD_ISENABLER(vector >> 5)) = mask;
|
||||
GIC_REG_32(GICD_ISENABLER(vector >> 5)) = mask; /* 5: Register bit offset */
|
||||
GicWaitForRwp(GICD_CTLR);
|
||||
}
|
||||
}
|
||||
@@ -291,7 +291,7 @@ VOID HalIrqPending(UINT32 vector)
|
||||
return;
|
||||
}
|
||||
|
||||
GIC_REG_32(GICD_ISPENDR(vector >> 5)) = 1U << (vector % 32);
|
||||
GIC_REG_32(GICD_ISPENDR(vector >> 5)) = 1U << (vector % 32); /* 5: Register bit offset, 32: Interrupt bit width */
|
||||
}
|
||||
|
||||
VOID HalIrqClear(UINT32 vector)
|
||||
@@ -362,30 +362,30 @@ VOID HalIrqInit(VOID)
|
||||
GicWaitForRwp(GICD_CTLR);
|
||||
ISB;
|
||||
|
||||
/* set externel interrupts to be level triggered, active low. */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 16) {
|
||||
/* set external interrupts to be level triggered, active low. */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 16) { /* 32: Start interrupt number, 16: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICFGR(i / 16)) = 0;
|
||||
}
|
||||
|
||||
/* config distributer, mask and clear all spis, set group x */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 32) {
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff;
|
||||
GIC_REG_32(GICD_ICPENDR(i / 32)) = 0xffffffff;
|
||||
GIC_REG_32(GICD_IGRPMODR(i / 32)) = 0;
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i += 32) { /* 32: Start interrupt number, 32: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff; /* 32: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICPENDR(i / 32)) = 0xffffffff; /* 32: Interrupt bit width */
|
||||
GIC_REG_32(GICD_IGRPMODR(i / 32)) = 0; /* 32: Interrupt bit width */
|
||||
|
||||
GicdSetGroup(i);
|
||||
}
|
||||
|
||||
/* set spi priority as default */
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i++) {
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i++) { /* 32: Start interrupt number */
|
||||
GicdSetPmr(i, MIN_INTERRUPT_PRIORITY);
|
||||
}
|
||||
|
||||
GicWaitForRwp(GICD_CTLR);
|
||||
|
||||
/* disable all interrupts. */
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) {
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff;
|
||||
for (i = 0; i < OS_HWI_MAX_NUM; i += 32) { /* 32: Interrupt bit width */
|
||||
GIC_REG_32(GICD_ICENABLER(i / 32)) = 0xffffffff; /* 32: Interrupt bit width */
|
||||
}
|
||||
|
||||
/* enable distributor with ARE, group 1 enabled */
|
||||
@@ -393,7 +393,7 @@ VOID HalIrqInit(VOID)
|
||||
|
||||
/* set spi to boot cpu only. ARE must be enabled */
|
||||
affinity = MpidrToAffinity(AARCH64_SYSREG_READ(mpidr_el1));
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i++) {
|
||||
for (i = 32; i < OS_HWI_MAX_NUM; i++) { /* 32: Start interrupt number */
|
||||
GIC_REG_64(GICD_IROUTER(i)) = affinity;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ enum {
|
||||
#define GICD_PIDR2V3 (GICD_OFFSET + 0xffe8)
|
||||
|
||||
#ifdef LOSCFG_ARCH_GIC_V3
|
||||
#define GICD_IGRPMODR(n) (GICD_OFFSET + 0x0d00 + (n) * 4) /* Interrupt Group Mode Reisters */
|
||||
#define GICD_IROUTER(n) (GICD_OFFSET + 0x6000 + (n) * 8) /* Interrupt Rounter Reisters */
|
||||
#define GICD_IGRPMODR(n) (GICD_OFFSET + 0x0d00 + (n) * 4) /* Interrupt Group Mode Registers */
|
||||
#define GICD_IROUTER(n) (GICD_OFFSET + 0x6000 + (n) * 8) /* Interrupt Rounter Registers */
|
||||
#endif
|
||||
|
||||
#define GIC_REG_8(reg) (*(volatile UINT8 *)((UINTPTR)(GIC_BASE_ADDR + (reg))))
|
||||
|
||||
0
arch/arm/include/gic_v3.h
Executable file → Normal file
0
arch/arm/include/gic_v3.h
Executable file → Normal file
@@ -71,7 +71,7 @@ extern "C" {
|
||||
/* CONSTANTS */
|
||||
|
||||
#define MQ_USE_MAGIC 0x89abcdef
|
||||
/* not suppurt prio */
|
||||
/* not support prio */
|
||||
#define MQ_PRIO_MAX 1
|
||||
|
||||
typedef union send_receive_t {
|
||||
@@ -297,7 +297,7 @@ extern int mq_send(mqd_t personal, const char *msg, size_t msgLen, unsigned int
|
||||
* <li><b>EAGAIN</b>: The message queue is empty.</li>
|
||||
* <li><b>EINVAL</b>: invalid parameter.</li>
|
||||
* <li><b>EMSGSIZE</b>: The message to be received is too long.</li>
|
||||
* <li><b>ETIMEDOUT</b>: The operaton times out.</li>
|
||||
* <li><b>ETIMEDOUT</b>: The operation times out.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @par Dependency:
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
*/
|
||||
|
||||
void *calloc(size_t nitems, size_t size)
|
||||
{ /*lint !e578*/
|
||||
{
|
||||
size_t real_size;
|
||||
void *ptr = NULL;
|
||||
|
||||
@@ -78,7 +78,7 @@ void free(void *ptr)
|
||||
*/
|
||||
|
||||
void *malloc(size_t size)
|
||||
{ /*lint !e31 !e10*/
|
||||
{
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ void *malloc(size_t size)
|
||||
}
|
||||
|
||||
void *zalloc(size_t size)
|
||||
{ /*lint !e10*/
|
||||
{
|
||||
void *ptr = NULL;
|
||||
|
||||
if (size == 0) {
|
||||
@@ -142,4 +142,4 @@ void *realloc(void *ptr, size_t size)
|
||||
}
|
||||
|
||||
return LOS_KernelRealloc(ptr, (UINT32) size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -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 = ((LosTaskCB *)(OsCurrTaskGet()))->priority;
|
||||
outAttr->schedparam.sched_priority = LOS_TaskPriGet(OsCurrTaskGet()->taskID);
|
||||
} else {
|
||||
outAttr->schedpolicy = self->attr.schedpolicy;
|
||||
outAttr->schedparam = self->attr.schedparam;
|
||||
|
||||
@@ -647,7 +647,7 @@ int clock_getres(clockid_t clockID, struct timespec *tp)
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
case CLOCK_MONOTONIC:
|
||||
case CLOCK_REALTIME:
|
||||
/* the accessable rtc resolution */
|
||||
/* the accessible rtc resolution */
|
||||
tp->tv_nsec = OS_SYS_NS_PER_US; /* the precision of clock_gettime is 1us */
|
||||
tp->tv_sec = 0;
|
||||
break;
|
||||
|
||||
@@ -45,8 +45,6 @@
|
||||
#include "bcache.h"
|
||||
#endif
|
||||
|
||||
#include "pthread.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@@ -253,7 +251,7 @@ struct disk_divide_info {
|
||||
* </ul>
|
||||
*
|
||||
* @param diskName [IN] Type #const CHAR * disk driver name.
|
||||
* @param bops [IN] Type #const struct block_operations * block driver control sturcture.
|
||||
* @param bops [IN] Type #const struct block_operations * block driver control structure.
|
||||
* @param priv [IN] Type #VOID * private data of vnode.
|
||||
* @param diskID [IN] Type #INT32 disk id number, less than SYS_MAX_DISK.
|
||||
* @param info [IN] Type #VOID * disk driver partition information.
|
||||
@@ -712,7 +710,7 @@ INT32 los_alloc_diskid_byname(const CHAR *diskName);
|
||||
* @brief get the INUSED disk id.
|
||||
*
|
||||
* @par Description:
|
||||
* Get the correponding INUSED disk id by diskName.
|
||||
* Get the corresponding INUSED disk id by diskName.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
|
||||
@@ -107,7 +107,7 @@ INT32 los_alloc_diskid_byname(const CHAR *diskName)
|
||||
size_t nameLen;
|
||||
|
||||
if (diskName == NULL) {
|
||||
PRINT_ERR("The paramter disk_name is NULL");
|
||||
PRINT_ERR("The parameter disk_name is NULL");
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ INT32 los_get_diskid_byname(const CHAR *diskName)
|
||||
size_t diskNameLen;
|
||||
|
||||
if (diskName == NULL) {
|
||||
PRINT_ERR("The paramter diskName is NULL");
|
||||
PRINT_ERR("The parameter diskName is NULL");
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ INT32 DiskPartitionRegister(los_disk *disk)
|
||||
los_part *part = NULL;
|
||||
struct disk_divide_info parInfo;
|
||||
|
||||
/* Fill disk_divide_info structure to set partition's infomation. */
|
||||
/* Fill disk_divide_info structure to set partition's information. */
|
||||
(VOID)memset_s(parInfo.part, sizeof(parInfo.part), 0, sizeof(parInfo.part));
|
||||
partSize = sizeof(parInfo.part) / sizeof(parInfo.part[0]);
|
||||
|
||||
@@ -788,7 +788,7 @@ INT32 DiskPartitionRegister(los_disk *disk)
|
||||
}
|
||||
|
||||
for (i = 0; i < partSize; i++) {
|
||||
/* Read the disk_divide_info structure to get partition's infomation. */
|
||||
/* Read the disk_divide_info structure to get partition's information. */
|
||||
if ((parInfo.part[i].type != 0) && (parInfo.part[i].type != EXTENDED_PAR) &&
|
||||
(parInfo.part[i].type != EXTENDED_8G)) {
|
||||
part = get_part(DiskAddPart(disk, parInfo.part[i].sector_start, parInfo.part[i].sector_count, TRUE));
|
||||
|
||||
@@ -41,7 +41,7 @@ void RandomOperationsInit(const RandomOperations *r)
|
||||
if (r != NULL) {
|
||||
(void)memcpy_s(&g_randomOp, sizeof(RandomOperations), r, sizeof(RandomOperations));
|
||||
} else {
|
||||
PRINT_ERR("param is invalid\n", __FUNCTION__, __LINE__);
|
||||
PRINT_ERR("%s %d param is invalid\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ static ssize_t TraceWrite(struct file *filep, const char *buffer, size_t buflen)
|
||||
if (info == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset_s(info, infoLen, 0, infoLen);
|
||||
(void)memset_s(info, infoLen, 0, infoLen);
|
||||
|
||||
ret = LOS_CopyToKernel(info, infoLen, buffer, buflen);
|
||||
if (ret != 0) {
|
||||
|
||||
@@ -289,7 +289,7 @@ static INT32 BlockDriverRegisterOperate(mtd_partition *newNode,
|
||||
if (ret) {
|
||||
free(newNode->blockdriver_name);
|
||||
newNode->blockdriver_name = NULL;
|
||||
PRINT_ERR("register blkdev partion error\n");
|
||||
PRINT_ERR("register blkdev partition error\n");
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
@@ -322,7 +322,7 @@ static INT32 CharDriverRegisterOperate(mtd_partition *newNode,
|
||||
|
||||
ret = register_driver(newNode->chardriver_name, param->char_ops, RWE_RW_RW, newNode);
|
||||
if (ret) {
|
||||
PRINT_ERR("register chardev partion error\n");
|
||||
PRINT_ERR("register chardev partition error\n");
|
||||
free(newNode->chardriver_name);
|
||||
newNode->chardriver_name = NULL;
|
||||
return ret;
|
||||
@@ -340,7 +340,7 @@ static INT32 BlockDriverUnregister(mtd_partition *node)
|
||||
if (node->blockdriver_name != NULL) {
|
||||
ret = unregister_blockdriver(node->blockdriver_name);
|
||||
if (ret == -EBUSY) {
|
||||
PRINT_ERR("unregister blkdev partion error:%d\n", ret);
|
||||
PRINT_ERR("unregister blkdev partition error:%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
free(node->blockdriver_name);
|
||||
@@ -356,7 +356,7 @@ static INT32 CharDriverUnregister(mtd_partition *node)
|
||||
if (node->chardriver_name != NULL) {
|
||||
ret = unregister_driver(node->chardriver_name);
|
||||
if (ret == -EBUSY) {
|
||||
PRINT_ERR("unregister chardev partion error:%d\n", ret);
|
||||
PRINT_ERR("unregister chardev partition error:%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
free(node->chardriver_name);
|
||||
|
||||
@@ -1861,7 +1861,7 @@ static FRESULT fatfs_setlabel(los_part *part)
|
||||
return result;
|
||||
}
|
||||
|
||||
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||
int fatfs_mkfs(struct Vnode *device, int sectors, int option)
|
||||
{
|
||||
BYTE *work_buff = NULL;
|
||||
los_part *part = NULL;
|
||||
|
||||
@@ -137,7 +137,7 @@ int fatfs_readdir(struct Vnode *vnode, struct fs_dirent_s *idir);
|
||||
int fatfs_rewinddir(struct Vnode *vnode, struct fs_dirent_s *dir);
|
||||
int fatfs_closedir(struct Vnode *vnode, struct fs_dirent_s *dir);
|
||||
int fatfs_rename(struct Vnode *oldvnode, struct Vnode *newparent, const char *oldname, const char *newname);
|
||||
int fatfs_mkfs (struct Vnode *device, int sectors, int option);
|
||||
int fatfs_mkfs(struct Vnode *device, int sectors, int option);
|
||||
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp);
|
||||
int fatfs_rmdir(struct Vnode *parent, struct Vnode *vp, const char *name);
|
||||
int fatfs_unlink(struct Vnode *parent, struct Vnode *vp, const char *name);
|
||||
|
||||
@@ -319,7 +319,7 @@ FRESULT f_regvirfs(FATFS *fs)
|
||||
|
||||
/* Set the CHILD object field */
|
||||
for (i = 0; i < fs->vir_amount; i++) {
|
||||
pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memeory for current child FATFS object */
|
||||
pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memory for current child FATFS object */
|
||||
if (pfs == NULL) { /* If allocate failed, must call 'f_unregvirfs' to free the previous FATFS object memory */
|
||||
goto ERROUT;
|
||||
}
|
||||
@@ -500,7 +500,7 @@ static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
|
||||
* - FR_OK : The external SD configure is complete, all info has been set to the
|
||||
* each CHILD FATFS
|
||||
* - FR_NOT_MATCHED : The virtual partition's configure does not matched as current setting
|
||||
* - FR_MODIFIED : The virtual partition's configure has been destoried partly or completely
|
||||
* - FR_MODIFIED : The virtual partition's configure has been destroyed partly or completely
|
||||
* - FR_NOVIRPART : The external SD has not been apllied as virtual partition yet
|
||||
*
|
||||
* Others Return Value:
|
||||
@@ -581,11 +581,11 @@ FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
labelTmp = (DWORD *)label;
|
||||
*labelTmp = tmp;
|
||||
tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4);
|
||||
*((DWORD * )(label + 4)) = tmp;
|
||||
*((DWORD *)(label + 4)) = tmp;
|
||||
tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8);
|
||||
*((DWORD * )(label + 8)) = tmp;
|
||||
*((DWORD *)(label + 8)) = tmp;
|
||||
tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12);
|
||||
*((DWORD * )(label + 12)) = tmp;
|
||||
*((DWORD *)(label + 12)) = tmp;
|
||||
|
||||
if (f_checkname(label) != FR_OK) {
|
||||
(void)f_unregvirfs(fs);
|
||||
@@ -721,11 +721,11 @@ FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
|
||||
labelTmp = (DWORD *)label;
|
||||
tmp = *labelTmp;
|
||||
st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0, tmp);
|
||||
tmp = *((DWORD * )(label + 4));
|
||||
tmp = *((DWORD *)(label + 4));
|
||||
st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4, tmp);
|
||||
tmp = *((DWORD * )(label + 8));
|
||||
tmp = *((DWORD *)(label + 8));
|
||||
st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8, tmp);
|
||||
tmp = *((DWORD * )(label + 12));
|
||||
tmp = *((DWORD *)(label + 12));
|
||||
st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12, tmp);
|
||||
|
||||
virpartper += g_fatVirPart.virtualinfo.virpartpercent[i];
|
||||
|
||||
@@ -98,7 +98,7 @@ extern char *rindex(const char *s, int c);
|
||||
* @ingroup fs
|
||||
*
|
||||
* @par Description:
|
||||
* The set_label() function shall set the value of a global varible,
|
||||
* The set_label() function shall set the value of a global variable,
|
||||
* the value will be used to set the label of SD card in format().
|
||||
*
|
||||
* @param name [IN] label to set, the length must be less than 12
|
||||
|
||||
@@ -55,14 +55,15 @@ INT32 OsMountPatchFs(VOID)
|
||||
}
|
||||
partInfo.fsType = strdup(FS_TYPE);
|
||||
if (partInfo.fsType == NULL) {
|
||||
return LOS_NOK;
|
||||
ret = LOS_NOK;
|
||||
goto EXIT;
|
||||
}
|
||||
partInfo.startAddr = PATCHFS_FLASH_ADDR;
|
||||
partInfo.partSize = PATCHFS_FLASH_SIZE;
|
||||
#else
|
||||
ret = GetPartitionInfo(&partInfo);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
goto EXIT;
|
||||
}
|
||||
partInfo.startAddr = (partInfo.startAddr >= 0) ? partInfo.startAddr : PATCHFS_FLASH_ADDR;
|
||||
partInfo.partSize = (partInfo.partSize >= 0) ? partInfo.partSize : PATCHFS_FLASH_SIZE;
|
||||
@@ -71,7 +72,7 @@ INT32 OsMountPatchFs(VOID)
|
||||
ret = LOS_NOK;
|
||||
partInfo.devName = strdup(PATCH_FLASH_DEV_NAME);
|
||||
if (partInfo.devName == NULL) {
|
||||
return LOS_NOK;
|
||||
goto EXIT;
|
||||
}
|
||||
const CHAR *devName = GetDevNameOfPartition(&partInfo);
|
||||
if (devName != NULL) {
|
||||
@@ -92,9 +93,13 @@ INT32 OsMountPatchFs(VOID)
|
||||
ResetDevNameofPartition(&partInfo);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
free(partInfo.devName);
|
||||
partInfo.devName = NULL;
|
||||
free(partInfo.storageType);
|
||||
partInfo.storageType = NULL;
|
||||
free(partInfo.fsType);
|
||||
partInfo.fsType = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ typedef unsigned short fmode_t;
|
||||
#define FMODE_64BITHASH ((fmode_t)0x400)
|
||||
/* 32bit hashes as llseek() offset (for directories) */
|
||||
#define FMODE_32BITHASH ((fmode_t)0x200)
|
||||
/* File is opened using open(.., 3, ..) and is writeable only for ioctls
|
||||
/* File is opened using open(.., 3, ..) and is writable only for ioctls
|
||||
* (specialy hack for floppy.c)
|
||||
*/
|
||||
#define FMODE_WRITE_IOCTL ((fmode_t)0x100)
|
||||
|
||||
@@ -87,7 +87,7 @@ static struct ProcDirEntry *ProcFindNode(struct ProcDirEntry *parent, const char
|
||||
}
|
||||
|
||||
/*
|
||||
* descrition: find the file's handle
|
||||
* description: find the file's handle
|
||||
* path: the file of fullpath
|
||||
* return: the file of handle
|
||||
* add by ll
|
||||
@@ -519,7 +519,7 @@ int ProcOpen(struct ProcFile *procFile)
|
||||
|
||||
static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
|
||||
{
|
||||
if (pde == NULL || pde == NULL || pde->pf == NULL) {
|
||||
if (pde == NULL || pde->pf == NULL) {
|
||||
return PROC_ERROR;
|
||||
}
|
||||
struct ProcFile *procFile = pde->pf;
|
||||
|
||||
@@ -29,10 +29,9 @@ 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, range from 0 to 1MB.
|
||||
Boot command line addr.
|
||||
|
||||
config BOOTENV_RAM
|
||||
bool "Read bootenv from RAM"
|
||||
|
||||
@@ -214,7 +214,7 @@ UINT64 LOS_SizeStrToNum(CHAR *value)
|
||||
UINT64 num = 0;
|
||||
|
||||
/* If the string is a hexadecimal value */
|
||||
if (sscanf_s(value, "0x%x", &num) > 0) {
|
||||
if (sscanf_s(value, "0x%llx", &num) > 0) {
|
||||
value += strlen("0x");
|
||||
if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) {
|
||||
goto ERROUT;
|
||||
@@ -247,4 +247,4 @@ UINT64 LOS_SizeStrToNum(CHAR *value)
|
||||
ERROUT:
|
||||
PRINT_ERR("Invalid value string \"%s\"!\n", value);
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ STATIC INT32 CheckValidation(UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr,
|
||||
|
||||
if ((rootAddr & (alignSize - 1)) || (rootSize & (alignSize - 1)) ||
|
||||
(userAddr & (alignSize - 1)) || (userSize & (alignSize - 1))) {
|
||||
PRINT_ERR("The address or size value should be 0x%x aligned!\n", alignSize);
|
||||
PRINT_ERR("The address or size value should be 0x%llx aligned!\n", alignSize);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
@@ -371,4 +371,4 @@ INT32 OsMountRootfs()
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ static INT32 BcacheSyncBlock(OsBcache *bc, OsBcacheBlock *block)
|
||||
UINT32 len, start, end;
|
||||
|
||||
if (block->modified == TRUE) {
|
||||
D(("bcache writting block = %llu\n", block->num));
|
||||
D(("bcache writing block = %llu\n", block->num));
|
||||
|
||||
ret = FindFlagPos(block->flag, bc->sectorPerBlock >> UNINT_LOG2_SHIFT, &start, &end);
|
||||
if (ret == ENOERR) {
|
||||
@@ -932,7 +932,7 @@ INT32 BlockCacheWrite(OsBcache *bc, const UINT8 *buf, UINT32 *len, UINT64 sector
|
||||
bc->modifiedBlock++;
|
||||
}
|
||||
if ((pos == 0) && (currentSize == bc->blockSize)) {
|
||||
memset_s(block->flag, sizeof(block->flag), 0xFF, sizeof(block->flag));
|
||||
(void)memset_s(block->flag, sizeof(block->flag), 0xFF, sizeof(block->flag));
|
||||
block->allDirty = TRUE;
|
||||
} else {
|
||||
BcacheSetFlag(bc, block, (UINT32)pos, currentSize);
|
||||
|
||||
23
fs/vfs/epoll/fs_epoll.c
Executable file → Normal file
23
fs/vfs/epoll/fs_epoll.c
Executable file → Normal file
@@ -164,23 +164,23 @@ static VOID DoEpollClose(struct epoll_head *epHead)
|
||||
}
|
||||
|
||||
/**
|
||||
* epoll_create,
|
||||
* epoll_create unsupported api
|
||||
*
|
||||
* epoll_create is implemented by calling epoll_create1, it's parameter 'size' is useless.
|
||||
*
|
||||
* epoll_create1,
|
||||
* 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 size: not actually used
|
||||
* @param flags: not actually used
|
||||
* @return epoll fd
|
||||
*/
|
||||
int epoll_create(int size)
|
||||
int epoll_create1(int flags)
|
||||
{
|
||||
(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);
|
||||
@@ -242,6 +242,11 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ev == NULL) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case EPOLL_CTL_ADD:
|
||||
ret = CheckFdExist(epHead, fd);
|
||||
@@ -304,7 +309,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (maxevents <= 0) {
|
||||
if ((maxevents <= 0) || (evs == NULL)) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
2
fs/vfs/include/epoll.h
Executable file → Normal file
2
fs/vfs/include/epoll.h
Executable file → Normal file
@@ -72,7 +72,7 @@ struct epoll_event {
|
||||
epoll_data_t data;
|
||||
};
|
||||
|
||||
int epoll_create(int size);
|
||||
int epoll_create1(int flags);
|
||||
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);
|
||||
|
||||
@@ -133,7 +133,7 @@ int fallocate64(int fd, int mode, off64_t offset, off64_t len)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (filep->f_oflags & O_DIRECTORY) {
|
||||
if ((unsigned int)filep->f_oflags & O_DIRECTORY) {
|
||||
set_errno(EBADF);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
@@ -35,115 +35,174 @@
|
||||
#include "path_cache.h"
|
||||
|
||||
/* vnode operations returns EIO */
|
||||
static int ErrorVopCreate (struct Vnode *parent, const char *name, int mode, struct Vnode **vnode)
|
||||
static int ErrorVopCreate(struct Vnode *parent, const char *name, int mode, struct Vnode **vnode)
|
||||
{
|
||||
(void)parent;
|
||||
(void)name;
|
||||
(void)mode;
|
||||
(void)vnode;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopLookup (struct Vnode *parent, const char *name, int len, struct Vnode **vnode)
|
||||
static int ErrorVopLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode)
|
||||
{
|
||||
(void)parent;
|
||||
(void)name;
|
||||
(void)len;
|
||||
(void)vnode;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopOpen (struct Vnode *vnode, int fd, int mode, int flags)
|
||||
static int ErrorVopOpen(struct Vnode *vnode, int fd, int mode, int flags)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)fd;
|
||||
(void)mode;
|
||||
(void)flags;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopClose (struct Vnode *vnode)
|
||||
static int ErrorVopClose(struct Vnode *vnode)
|
||||
{
|
||||
(void)vnode;
|
||||
/* already closed at force umount, do nothing here */
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int ErrorVopReclaim (struct Vnode *vnode)
|
||||
static int ErrorVopReclaim(struct Vnode *vnode)
|
||||
{
|
||||
(void)vnode;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopUnlink (struct Vnode *parent, struct Vnode *vnode, const char *fileName)
|
||||
static int ErrorVopUnlink(struct Vnode *parent, struct Vnode *vnode, const char *fileName)
|
||||
{
|
||||
(void)parent;
|
||||
(void)vnode;
|
||||
(void)fileName;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopRmdir (struct Vnode *parent, struct Vnode *vnode, const char *dirName)
|
||||
static int ErrorVopRmdir(struct Vnode *parent, struct Vnode *vnode, const char *dirName)
|
||||
{
|
||||
(void)parent;
|
||||
(void)vnode;
|
||||
(void)dirName;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopMkdir (struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode)
|
||||
static int ErrorVopMkdir(struct Vnode *parent, const char *dirName, mode_t mode, struct Vnode **vnode)
|
||||
{
|
||||
(void)parent;
|
||||
(void)dirName;
|
||||
(void)mode;
|
||||
(void)vnode;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopReaddir (struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
static int ErrorVopReaddir(struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)dir;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopOpendir (struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
static int ErrorVopOpendir(struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)dir;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopRewinddir (struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
static int ErrorVopRewinddir(struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)dir;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopClosedir (struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
static int ErrorVopClosedir(struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)dir;
|
||||
/* already closed at force umount, do nothing here */
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int ErrorVopGetattr (struct Vnode *vnode, struct stat *st)
|
||||
static int ErrorVopGetattr(struct Vnode *vnode, struct stat *st)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)st;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopSetattr (struct Vnode *vnode, struct stat *st)
|
||||
static int ErrorVopSetattr(struct Vnode *vnode, struct stat *st)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)st;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopChattr (struct Vnode *vnode, struct IATTR *attr)
|
||||
static int ErrorVopChattr(struct Vnode *vnode, struct IATTR *attr)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)attr;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopRename (struct Vnode *src, struct Vnode *dstParent, const char *srcName, const char *dstName)
|
||||
static int ErrorVopRename(struct Vnode *src, struct Vnode *dstParent, const char *srcName, const char *dstName)
|
||||
{
|
||||
(void)src;
|
||||
(void)dstParent;
|
||||
(void)srcName;
|
||||
(void)dstName;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopTruncate (struct Vnode *vnode, off_t len)
|
||||
static int ErrorVopTruncate(struct Vnode *vnode, off_t len)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)len;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopTruncate64 (struct Vnode *vnode, off64_t len)
|
||||
static int ErrorVopTruncate64(struct Vnode *vnode, off64_t len)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)len;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopFscheck (struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
static int ErrorVopFscheck(struct Vnode *vnode, struct fs_dirent_s *dir)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)dir;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopLink (struct Vnode *src, struct Vnode *dstParent, struct Vnode **dst, const char *dstName)
|
||||
static int ErrorVopLink(struct Vnode *src, struct Vnode *dstParent, struct Vnode **dst, const char *dstName)
|
||||
{
|
||||
(void)src;
|
||||
(void)dstParent;
|
||||
(void)dst;
|
||||
(void)dstName;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorVopSymlink (struct Vnode *parentVnode, struct Vnode **newVnode, const char *path, const char *target)
|
||||
static int ErrorVopSymlink(struct Vnode *parentVnode, struct Vnode **newVnode, const char *path, const char *target)
|
||||
{
|
||||
(void)parentVnode;
|
||||
(void)newVnode;
|
||||
(void)path;
|
||||
(void)target;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static ssize_t ErrorVopReadlink (struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
static ssize_t ErrorVopReadlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
{
|
||||
(void)vnode;
|
||||
(void)buffer;
|
||||
(void)bufLen;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -173,74 +232,107 @@ static struct VnodeOps g_errorVnodeOps = {
|
||||
};
|
||||
|
||||
/* file operations returns EIO */
|
||||
static int ErrorFopOpen (struct file *filep)
|
||||
static int ErrorFopOpen(struct file *filep)
|
||||
{
|
||||
(void)filep;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopClose (struct file *filep)
|
||||
static int ErrorFopClose(struct file *filep)
|
||||
{
|
||||
(void)filep;
|
||||
/* already closed at force umount, do nothing here */
|
||||
return OK;
|
||||
}
|
||||
|
||||
static ssize_t ErrorFopRead (struct file *filep, char *buffer, size_t buflen)
|
||||
static ssize_t ErrorFopRead(struct file *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
(void)filep;
|
||||
(void)buffer;
|
||||
(void)buflen;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static ssize_t ErrorFopWrite (struct file *filep, const char *buffer, size_t buflen)
|
||||
static ssize_t ErrorFopWrite(struct file *filep, const char *buffer, size_t buflen)
|
||||
{
|
||||
(void)filep;
|
||||
(void)buffer;
|
||||
(void)buflen;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static off_t ErrorFopSeek (struct file *filep, off_t offset, int whence)
|
||||
static off_t ErrorFopSeek(struct file *filep, off_t offset, int whence)
|
||||
{
|
||||
(void)filep;
|
||||
(void)offset;
|
||||
(void)whence;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopIoctl (struct file *filep, int cmd, unsigned long arg)
|
||||
static int ErrorFopIoctl(struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
(void)filep;
|
||||
(void)cmd;
|
||||
(void)arg;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopMmap (struct file* filep, struct VmMapRegion *region)
|
||||
static int ErrorFopMmap(struct file* filep, struct VmMapRegion *region)
|
||||
{
|
||||
(void)filep;
|
||||
(void)region;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopPoll (struct file *filep, poll_table *fds)
|
||||
static int ErrorFopPoll(struct file *filep, poll_table *fds)
|
||||
{
|
||||
(void)filep;
|
||||
(void)fds;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopStat (struct file *filep, struct stat* st)
|
||||
static int ErrorFopStat(struct file *filep, struct stat* st)
|
||||
{
|
||||
(void)filep;
|
||||
(void)st;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopFallocate (struct file* filep, int mode, off_t offset, off_t len)
|
||||
static int ErrorFopFallocate(struct file* filep, int mode, off_t offset, off_t len)
|
||||
{
|
||||
(void)filep;
|
||||
(void)mode;
|
||||
(void)offset;
|
||||
(void)len;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopFallocate64 (struct file *filep, int mode, off64_t offset, off64_t len)
|
||||
static int ErrorFopFallocate64(struct file *filep, int mode, off64_t offset, off64_t len)
|
||||
{
|
||||
(void)filep;
|
||||
(void)mode;
|
||||
(void)offset;
|
||||
(void)len;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopFsync (struct file *filep)
|
||||
static int ErrorFopFsync(struct file *filep)
|
||||
{
|
||||
(void)filep;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static ssize_t ErrorFopReadpage (struct file *filep, char *buffer, size_t buflen)
|
||||
static ssize_t ErrorFopReadpage(struct file *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
(void)filep;
|
||||
(void)buffer;
|
||||
(void)buflen;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int ErrorFopUnlink (struct Vnode *vnode)
|
||||
static int ErrorFopUnlink(struct Vnode *vnode)
|
||||
{
|
||||
(void)vnode;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
||||
@@ -637,7 +637,7 @@ void ls(const char *pathname)
|
||||
|
||||
if (statInfo.st_mode & S_IFDIR) { /* list all directory and file */
|
||||
ret = LsDir((pathname == NULL) ? path : pathname);
|
||||
} else { /* show the file infomation */
|
||||
} else { /* show the file information */
|
||||
ret = LsFile(path);
|
||||
}
|
||||
if (ret < 0) {
|
||||
|
||||
@@ -654,7 +654,7 @@ static int os_shell_cmd_do_cp(const char *src_filepath, const char *dst_filename
|
||||
char *dst_filepath = NULL;
|
||||
char *buf = NULL;
|
||||
const char *filename = NULL;
|
||||
size_t r_size, w_size;
|
||||
ssize_t r_size, w_size;
|
||||
int src_fd = -1;
|
||||
int dst_fd = -1;
|
||||
struct stat stat_buf;
|
||||
@@ -1391,8 +1391,8 @@ int checkNum(const char *arg)
|
||||
#ifdef LOSCFG_KERNEL_SYSCALL
|
||||
int osShellCmdSu(int argc, const char **argv)
|
||||
{
|
||||
unsigned int su_uid;
|
||||
unsigned int su_gid;
|
||||
int su_uid;
|
||||
int su_gid;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
|
||||
@@ -198,7 +198,7 @@ int VnodeFree(struct Vnode *vnode)
|
||||
g_totalVnodeSize--;
|
||||
} else {
|
||||
/* for normal vnode, reclaim it to g_VnodeFreeList */
|
||||
memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode));
|
||||
(void)memset_s(vnode, sizeof(struct Vnode), 0, sizeof(struct Vnode));
|
||||
LOS_ListAdd(&g_vnodeFreeList, &vnode->actFreeEntry);
|
||||
g_freeVnodeSize++;
|
||||
}
|
||||
@@ -380,6 +380,11 @@ int VnodeLookupAt(const char *path, struct Vnode **result, uint32_t flags, struc
|
||||
if (orgVnode != NULL) {
|
||||
startVnode = orgVnode;
|
||||
normalizedPath = strdup(path);
|
||||
if (normalizedPath == NULL) {
|
||||
PRINT_ERR("[VFS]lookup failed, strdup err\n");
|
||||
ret = -EINVAL;
|
||||
goto OUT_FREE_PATH;
|
||||
}
|
||||
} else {
|
||||
ret = PreProcess(path, &startVnode, &normalizedPath);
|
||||
if (ret != LOS_OK) {
|
||||
|
||||
@@ -67,6 +67,12 @@ 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-2021 Huawei Device 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:
|
||||
@@ -65,10 +65,12 @@ 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/sched_sq/los_sched.c",
|
||||
"sched/sched_sq/los_sortlink.c",
|
||||
"sched/los_idle.c",
|
||||
"sched/los_priority.c",
|
||||
"sched/los_sched.c",
|
||||
"sched/los_sortlink.c",
|
||||
"sched/los_statistics.c",
|
||||
"vm/los_vm_boot.c",
|
||||
"vm/los_vm_dump.c",
|
||||
"vm/los_vm_fault.c",
|
||||
|
||||
@@ -37,7 +37,7 @@ LOCAL_SRCS := $(wildcard ipc/*.c) $(wildcard core/*.c) $(wildcard mem/membox/*.
|
||||
$(wildcard misc/*.c)\
|
||||
$(wildcard mem/tlsf/*.c) \
|
||||
$(wildcard mp/*.c) \
|
||||
$(wildcard sched/sched_sq/*.c) \
|
||||
$(wildcard sched/*.c) \
|
||||
$(wildcard vm/*.c)
|
||||
|
||||
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -87,7 +87,7 @@ VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB)
|
||||
OsTaskInsertToRecycleList(taskCB);
|
||||
}
|
||||
|
||||
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB)
|
||||
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT16 numCount;
|
||||
@@ -100,12 +100,14 @@ UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB)
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_USER_MODE;
|
||||
if (processCB->threadNumber > 0) {
|
||||
taskCB->basePrio = OS_TCB_FROM_TID(processCB->threadGroupID)->basePrio;
|
||||
LosTaskCB *task = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
task->ops->schedParamGet(task, param);
|
||||
} else {
|
||||
taskCB->basePrio = OS_USER_PROCESS_PRIORITY_HIGHEST;
|
||||
OsSchedProcessDefaultSchedParamGet(param->policy, param);
|
||||
}
|
||||
} else {
|
||||
taskCB->basePrio = OsCurrTaskGet()->basePrio;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
runTask->ops->schedParamGet(runTask, param);
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
@@ -176,7 +178,7 @@ STATIC ProcessGroup *OsFindProcessGroup(UINT32 gid)
|
||||
}
|
||||
}
|
||||
|
||||
PRINT_INFO("%s is find group : %u failed!\n", __FUNCTION__, gid);
|
||||
PRINT_INFO("%s failed! group id = %u\n", __FUNCTION__, gid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -283,7 +285,7 @@ STATIC LosProcessCB *OsFindExitChildProcess(const LosProcessCB *processCB, INT32
|
||||
VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
|
||||
{
|
||||
taskCB->waitID = wakePID;
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
#endif
|
||||
@@ -897,7 +899,7 @@ STATIC INLINE INT32 OsProcessSchedlerParamCheck(INT32 which, INT32 pid, UINT16 p
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, UINT16 prio)
|
||||
STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, const SchedParam *param, UINT16 prio)
|
||||
{
|
||||
LosProcessCB *runProcess = OsCurrProcessGet();
|
||||
|
||||
@@ -907,7 +909,7 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, UINT16 prio)
|
||||
}
|
||||
|
||||
/* user mode process can reduce the priority of itself */
|
||||
if ((runProcess->processID == processCB->processID) && (prio > OsCurrTaskGet()->basePrio)) {
|
||||
if ((runProcess->processID == processCB->processID) && (prio > param->basePrio)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -921,31 +923,33 @@ STATIC BOOL OsProcessCapPermitCheck(const LosProcessCB *processCB, UINT16 prio)
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 OsSetProcessScheduler(INT32 which, INT32 pid, UINT16 prio, UINT16 policy)
|
||||
{
|
||||
LosProcessCB *processCB = NULL;
|
||||
BOOL needSched = FALSE;
|
||||
SchedParam param = { 0 };
|
||||
UINT32 intSave;
|
||||
INT32 ret;
|
||||
|
||||
ret = OsProcessSchedlerParamCheck(which, pid, prio, policy);
|
||||
INT32 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, prio)) {
|
||||
if (!OsProcessCapPermitCheck(processCB, ¶m, prio)) {
|
||||
ret = LOS_EPERM;
|
||||
goto EXIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
needSched = OsSchedModifyProcessSchedParam(pid, policy, prio);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
param.basePrio = prio;
|
||||
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -993,6 +997,7 @@ 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,11 +1015,12 @@ LITE_OS_SEC_TEXT INT32 OsGetProcessPriority(INT32 which, INT32 pid)
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
prio = (INT32)OS_TCB_FROM_TID(processCB->threadGroupID)->basePrio;
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(processCB->threadGroupID);
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
|
||||
OUT:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return prio;
|
||||
return param.basePrio;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 LOS_GetProcessPriority(INT32 pid)
|
||||
@@ -1050,8 +1056,7 @@ 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)OsSchedTaskWait(list->pstNext, LOS_WAIT_FOREVER, TRUE);
|
||||
(VOID)runTask->ops->wait(runTask, list->pstNext, LOS_WAIT_FOREVER);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1202,13 +1207,10 @@ 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,47 +1727,37 @@ 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 childPara = { 0 };
|
||||
UINT32 ret;
|
||||
UINT32 intSave;
|
||||
UINT32 taskID;
|
||||
TSK_INIT_PARAM_S taskParam = { 0 };
|
||||
UINT32 ret, taskID, intSave;
|
||||
SchedParam param = { 0 };
|
||||
|
||||
OsInitCopyTaskParam(childProcessCB, name, entry, size, &childPara);
|
||||
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;
|
||||
}
|
||||
|
||||
ret = LOS_TaskCreateOnly(&taskID, &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);
|
||||
if (ret != LOS_OK) {
|
||||
if (ret == LOS_ERRNO_TSK_TCB_UNAVAILABLE) {
|
||||
return LOS_EAGAIN;
|
||||
@@ -1775,7 +1767,7 @@ STATIC UINT32 OsCopyTask(UINT32 flags, LosProcessCB *childProcessCB, const CHAR
|
||||
|
||||
LosTaskCB *childTaskCB = OS_TCB_FROM_TID(taskID);
|
||||
childTaskCB->taskStatus = runTask->taskStatus;
|
||||
childTaskCB->basePrio = runTask->basePrio;
|
||||
childTaskCB->ops->schedParamModify(childTaskCB, ¶m);
|
||||
if (childTaskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
childTaskCB->taskStatus &= ~OS_TASK_STATUS_RUNNING;
|
||||
} else {
|
||||
@@ -1882,6 +1874,7 @@ 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);
|
||||
@@ -1892,7 +1885,7 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
|
||||
}
|
||||
|
||||
child->processStatus &= ~OS_PROCESS_STATUS_INIT;
|
||||
OsSchedTaskEnQueue(OS_TCB_FROM_TID(child->threadGroupID));
|
||||
taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, group);
|
||||
@@ -2002,6 +1995,8 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
(void)status;
|
||||
|
||||
/* The exit of a kernel - state process must be kernel - state and all threads must actively exit */
|
||||
LosProcessCB *processCB = OsCurrProcessGet();
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -43,6 +43,9 @@
|
||||
#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 */
|
||||
@@ -52,22 +55,232 @@ 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 ret, swtmrHandlerQueue;
|
||||
UINT32 intSave;
|
||||
UINT64 waitTime;
|
||||
|
||||
swtmrHandlerQueue = OsSchedSwtmrHandlerQueueGet();
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[ArchCurrCpuid()];
|
||||
LOS_DL_LIST *head = &srq->swtmrHandlerQueue;
|
||||
for (;;) {
|
||||
ret = LOS_QueueRead(swtmrHandlerQueue, &swtmrHandlePtr, sizeof(CHAR *), LOS_WAIT_FOREVER);
|
||||
if ((ret == LOS_OK) && (swtmrHandlePtr != NULL)) {
|
||||
swtmrHandle.handler = swtmrHandlePtr->handler;
|
||||
swtmrHandle.arg = swtmrHandlePtr->arg;
|
||||
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));
|
||||
(VOID)LOS_MemboxFree(g_swtmrHandlerPool, swtmrHandlePtr);
|
||||
if (swtmrHandle.handler != NULL) {
|
||||
swtmrHandle.handler(swtmrHandle.arg);
|
||||
}
|
||||
SwtmrHandler(&swtmrHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +307,11 @@ 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) {
|
||||
@@ -111,51 +329,58 @@ LITE_OS_SEC_TEXT_INIT VOID OsSwtmrRecycle(UINT32 processID)
|
||||
}
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
STATIC UINT32 SwtmrBaseInit(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
UINT16 index;
|
||||
UINT32 ret;
|
||||
SWTMR_CTRL_S *swtmr = NULL;
|
||||
UINT32 swtmrHandlePoolSize;
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
UINT32 swtmrTaskID, swtmrHandlerQueue;
|
||||
|
||||
if (cpuid == 0) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
ret = LOS_QueueCreate(NULL, OS_SWTMR_HANDLE_QUEUE_SIZE, &swtmrHandlerQueue, 0, sizeof(CHAR *));
|
||||
(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) {
|
||||
ret = LOS_ERRNO_SWTMR_QUEUE_CREATE_FAILED;
|
||||
goto ERROR;
|
||||
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 ret;
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
UINT32 swtmrTaskID;
|
||||
|
||||
if (cpuid == 0) {
|
||||
ret = SwtmrBaseInit();
|
||||
if (ret != LOS_OK) {
|
||||
goto ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
ret = SwtmrTaskCreate(cpuid, &swtmrTaskID);
|
||||
@@ -164,21 +389,88 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
|
||||
goto ERROR;
|
||||
}
|
||||
|
||||
OsSchedRunQueSwtmrInit(swtmrTaskID, swtmrHandlerQueue);
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
|
||||
srq->swtmrTask = OsGetTaskCB(swtmrTaskID);
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Start Software Timer
|
||||
* Input : swtmr --- Need to start software timer
|
||||
*/
|
||||
LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
|
||||
#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)
|
||||
{
|
||||
UINT32 ticks;
|
||||
UINT32 times = 0;
|
||||
|
||||
if ((swtmr->uwOverrun == 0) && ((swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ||
|
||||
(swtmr->ucMode == LOS_SWTMR_MODE_OPP) ||
|
||||
@@ -189,75 +481,122 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(SWTMR_CTRL_S *swtmr)
|
||||
}
|
||||
swtmr->ucState = OS_SWTMR_STATUS_TICKING;
|
||||
|
||||
OsSchedAddSwtmr2TimeList(&swtmr->stSortList, swtmr->startTime, ticks);
|
||||
OsSchedUpdateExpireTime();
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Delete Software Timer
|
||||
* Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL.
|
||||
*/
|
||||
STATIC INLINE VOID OsSwtmrDelete(SWTMR_CTRL_S *swtmr)
|
||||
STATIC INLINE VOID SwtmrDelete(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);
|
||||
}
|
||||
|
||||
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)
|
||||
STATIC INLINE VOID SwtmrRestart(UINT64 startTime, SortLinkList *sortList, UINT16 cpuid)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
SWTMR_CTRL_S *swtmr = LOS_DL_LIST_ENTRY(sortList, SWTMR_CTRL_S, stSortList);
|
||||
SWTMR_LOCK(intSave);
|
||||
swtmr->startTime = startTime;
|
||||
OsSwtmrStart(swtmr);
|
||||
(VOID)SwtmrToStart(swtmr, cpuid);
|
||||
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 = OsSchedSwtmrTimeListFind(checkFunc, arg);
|
||||
BOOL find = SwtmrTimeListFind(checkFunc, arg);
|
||||
SWTMR_UNLOCK(intSave);
|
||||
return find;
|
||||
}
|
||||
@@ -269,7 +608,8 @@ BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
|
||||
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
{
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
UINT64 time = (OsSortLinkGetNextExpireTime(currTime, &OsSchedRunQue()->swtmrSortLink) / OS_CYCLE_PER_TICK);
|
||||
SwtmrRunqueue *srq = &g_swtmrRunqueue[ArchCurrCpuid()];
|
||||
UINT64 time = (OsSortLinkGetNextExpireTime(currTime, &srq->swtmrSortLink) / OS_CYCLE_PER_TICK);
|
||||
if (time > OS_INVALID_VALUE) {
|
||||
time = OS_INVALID_VALUE;
|
||||
}
|
||||
@@ -278,21 +618,19 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
|
||||
|
||||
/*
|
||||
* Description: Stop of Software Timer interface
|
||||
* Input : swtmr --- the software timer contrl handler
|
||||
* Input : swtmr --- the software timer control handler
|
||||
*/
|
||||
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
STATIC VOID SwtmrStop(SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
OsSchedDeSwtmrFromTimeList(&swtmr->stSortList);
|
||||
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
swtmr->uwOverrun = 0;
|
||||
|
||||
OsSchedUpdateExpireTime();
|
||||
DeSwtmrFromTimeList(&swtmr->stSortList);
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Get next software timer expiretime
|
||||
* Input : swtmr --- the software timer contrl handler
|
||||
* Input : swtmr --- the software timer control handler
|
||||
*/
|
||||
LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const SWTMR_CTRL_S *swtmr)
|
||||
{
|
||||
@@ -385,11 +723,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrID)
|
||||
* then start the swtmr again.
|
||||
*/
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
SwtmrStop(swtmr);
|
||||
/* fall-through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
swtmr->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSwtmrStart(swtmr);
|
||||
SwtmrStart(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
@@ -429,7 +766,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrID)
|
||||
ret = LOS_ERRNO_SWTMR_NOT_STARTED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
SwtmrStop(swtmr);
|
||||
break;
|
||||
default:
|
||||
ret = LOS_ERRNO_SWTMR_STATUS_INVALID;
|
||||
@@ -507,10 +844,10 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
|
||||
ret = LOS_ERRNO_SWTMR_NOT_CREATED;
|
||||
break;
|
||||
case OS_SWTMR_STATUS_TICKING:
|
||||
OsSwtmrStop(swtmr);
|
||||
SwtmrStop(swtmr);
|
||||
/* fall-through */
|
||||
case OS_SWTMR_STATUS_CREATED:
|
||||
OsSwtmrDelete(swtmr);
|
||||
SwtmrDelete(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-2021 Huawei Device 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:
|
||||
@@ -90,19 +90,23 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,13 +124,11 @@ 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)) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->joinList)));
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
}
|
||||
}
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_EXIT;
|
||||
@@ -144,7 +146,8 @@ 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);
|
||||
return OsSchedTaskWait(&taskCB->joinList, LOS_WAIT_FOREVER, TRUE);
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
return runTask->ops->wait(runTask, &taskCB->joinList, LOS_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
return LOS_EINVAL;
|
||||
@@ -203,7 +206,7 @@ EXIT:
|
||||
|
||||
UINT32 OsGetIdleTaskId(VOID)
|
||||
{
|
||||
return OsSchedGetRunQueIdle();
|
||||
return OsSchedRunqueueIdleGet();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
||||
@@ -216,6 +219,7 @@ 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
|
||||
@@ -224,10 +228,9 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
||||
ret = LOS_TaskCreateOnly(&idleTaskID, &taskInitParam);
|
||||
LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
|
||||
idleTask->taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
|
||||
OsSchedRunQueIdleInit(idleTaskID);
|
||||
OsSchedSetIdleTaskSchedParam(idleTask);
|
||||
OsSchedRunqueueIdleInit(idleTaskID);
|
||||
|
||||
return ret;
|
||||
return LOS_TaskResume(idleTaskID);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -277,9 +280,9 @@ STATIC INLINE UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
|
||||
/*
|
||||
* gc soft timer works every OS_MP_GC_PERIOD period, to prevent this timer
|
||||
* triggered right at the timeout has reached, we set the timeout as double
|
||||
* of the gc peroid.
|
||||
* of the gc period.
|
||||
*/
|
||||
if (LOS_SemPend(taskCB->syncSignal, OS_MP_GC_PERIOD * 2) != LOS_OK) {
|
||||
if (LOS_SemPend(taskCB->syncSignal, OS_MP_GC_PERIOD * 2) != LOS_OK) { /* 2: Wait 200 ms */
|
||||
ret = LOS_ERRNO_TSK_MP_SYNC_FAILED;
|
||||
}
|
||||
|
||||
@@ -369,12 +372,11 @@ STATIC VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
while (!LOS_ListEmpty(&g_taskRecycleList)) {
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecycleList));
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_taskRecycleList));
|
||||
LOS_ListDelete(&taskCB->pendList);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -391,8 +393,6 @@ 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));
|
||||
|
||||
/*
|
||||
@@ -403,7 +403,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
|
||||
LOS_SpinUnlock(&g_taskSpin);
|
||||
(VOID)LOS_IntUnLock();
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *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)) {
|
||||
@@ -463,10 +463,8 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stack
|
||||
*topStack = (VOID *)LOS_MemAllocAlign(pool, stackSize, LOSCFG_STACK_POINT_ALIGN_SIZE);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
||||
const VOID *stackPtr,
|
||||
const VOID *topStack,
|
||||
const TSK_INIT_PARAM_S *initParam)
|
||||
STATIC VOID TaskCBBaseInit(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 */
|
||||
@@ -475,7 +473,6 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
||||
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,7 +481,6 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
||||
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;
|
||||
@@ -500,10 +496,13 @@ 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;
|
||||
|
||||
OsTaskCBInitBase(taskCB, stackPtr, topStack, initParam);
|
||||
TaskCBBaseInit(taskCB, stackPtr, topStack, initParam);
|
||||
|
||||
numCount = OsProcessAddNewTask(initParam->processID, taskCB);
|
||||
schedParam.policy = policy;
|
||||
numCount = OsProcessAddNewTask(initParam->processID, taskCB, &schedParam);
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
taskCB->futex.index = OS_INVALID_VALUE;
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_USER_MODE) {
|
||||
@@ -514,6 +513,11 @@ 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) {
|
||||
@@ -530,7 +534,6 @@ 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)) {
|
||||
@@ -539,7 +542,7 @@ LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
LOS_ListDelete(LOS_DL_LIST_FIRST(&g_losFreeTask));
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -550,8 +553,6 @@ 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);
|
||||
@@ -559,7 +560,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
return errRet;
|
||||
}
|
||||
|
||||
taskCB = OsGetFreeTaskCB();
|
||||
LosTaskCB *taskCB = OsGetFreeTaskCB();
|
||||
if (taskCB == NULL) {
|
||||
errRet = LOS_ERRNO_TSK_TCB_UNAVAILABLE;
|
||||
goto LOS_ERREND;
|
||||
@@ -576,7 +577,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
goto LOS_ERREND_REWIND_SYNC;
|
||||
}
|
||||
|
||||
stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
|
||||
VOID *stackPtr = OsTaskStackInit(taskCB->taskID, initParam->uwStackSize, topStack, TRUE);
|
||||
errRet = OsTaskCBInit(taskCB, initParam, stackPtr, topStack);
|
||||
if (errRet != LOS_OK) {
|
||||
goto LOS_ERREND_TCB_INIT;
|
||||
@@ -630,7 +631,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);
|
||||
OsSchedTaskEnQueue(taskCB);
|
||||
taskCB->ops->enqueue(OsSchedRunqueue(), taskCB);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* in case created task not running on this core,
|
||||
@@ -647,13 +648,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 errRet;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
BOOL needSched = FALSE;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
|
||||
/* clear pending signal */
|
||||
@@ -667,7 +668,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
OS_GOTO_ERREND();
|
||||
}
|
||||
|
||||
BOOL needSched = OsSchedResume(taskCB);
|
||||
errRet = taskCB->ops->resume(taskCB, &needSched);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -675,7 +676,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
|
||||
LOS_Schedule();
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
return errRet;
|
||||
|
||||
LOS_ERREND:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -723,9 +724,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN
|
||||
LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
|
||||
{
|
||||
UINT32 errRet;
|
||||
UINT16 tempStatus;
|
||||
|
||||
tempStatus = taskCB->taskStatus;
|
||||
UINT16 tempStatus = taskCB->taskStatus;
|
||||
if (tempStatus & OS_TASK_STATUS_UNUSED) {
|
||||
return LOS_ERRNO_TSK_NOT_CREATED;
|
||||
}
|
||||
@@ -739,21 +738,19 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
|
||||
return errRet;
|
||||
}
|
||||
|
||||
OsSchedSuspend(taskCB);
|
||||
return LOS_OK;
|
||||
return taskCB->ops->suspend(taskCB);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
}
|
||||
@@ -842,11 +839,11 @@ LITE_OS_SEC_TEXT VOID OsInactiveTaskDelete(LosTaskCB *taskCB)
|
||||
|
||||
OsTaskReleaseHoldLock(taskCB);
|
||||
|
||||
OsSchedTaskExit(taskCB);
|
||||
taskCB->ops->exit(taskCB);
|
||||
if (taskStatus & OS_TASK_STATUS_PENDING) {
|
||||
LosMux *mux = (LosMux *)taskCB->taskMux;
|
||||
if (LOS_MuxIsValid(mux) == TRUE) {
|
||||
OsMuxBitmapRestore(mux, taskCB, (LosTaskCB *)mux->owner);
|
||||
OsMuxBitmapRestore(mux, NULL, taskCB);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,6 +869,10 @@ 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;
|
||||
}
|
||||
@@ -900,20 +901,22 @@ 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;
|
||||
}
|
||||
|
||||
runTask = OsCurrTaskGet();
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
if (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
OsBackTrace();
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
@@ -928,39 +931,37 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
|
||||
}
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
OsSchedDelay(runTask, tick);
|
||||
UINT32 ret = runTask->ops->delay(runTask, OS_SCHED_TICK_TO_CYCLE(tick));
|
||||
OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, runTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT16 priority;
|
||||
SchedParam param = { 0 };
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
return (UINT16)OS_INVALID;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return (UINT16)OS_INVALID;
|
||||
}
|
||||
|
||||
priority = taskCB->priority;
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return priority;
|
||||
return param.priority;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
SchedParam param = { 0 };
|
||||
|
||||
if (taskPrio > OS_TASK_PRIORITY_LOWEST) {
|
||||
return LOS_ERRNO_TSK_PRIOR_ERROR;
|
||||
@@ -970,7 +971,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
|
||||
}
|
||||
@@ -981,11 +982,15 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
|
||||
return LOS_ERRNO_TSK_NOT_CREATED;
|
||||
}
|
||||
|
||||
BOOL isReady = OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, taskPrio);
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
|
||||
param.priority = taskPrio;
|
||||
|
||||
BOOL needSched = taskCB->ops->schedParamModify(taskCB, ¶m);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
if (isReady && OS_SCHEDULER_ACTIVE) {
|
||||
if (needSched && OS_SCHEDULER_ACTIVE) {
|
||||
LOS_Schedule();
|
||||
}
|
||||
return LOS_OK;
|
||||
@@ -1015,7 +1020,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
|
||||
|
||||
SCHEDULER_LOCK(intSave);
|
||||
/* reset timeslice of yielded task */
|
||||
OsSchedYield();
|
||||
runTask->ops->yield(runTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1045,7 +1050,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;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
SchedParam param = { 0 };
|
||||
|
||||
if (taskInfo == NULL) {
|
||||
return LOS_ERRNO_TSK_PTR_NULL;
|
||||
@@ -1055,7 +1060,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
|
||||
return LOS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1068,8 +1073,9 @@ 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 = taskCB->priority;
|
||||
taskInfo->usTaskPrio = param.priority;
|
||||
taskInfo->uwStackSize = taskCB->stackSize;
|
||||
taskInfo->uwTopOfStack = taskCB->topOfStack;
|
||||
taskInfo->uwEventMask = taskCB->eventMask;
|
||||
@@ -1113,7 +1119,6 @@ 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;
|
||||
@@ -1126,7 +1131,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMa
|
||||
return LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1147,7 +1152,6 @@ 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;
|
||||
|
||||
@@ -1155,7 +1159,7 @@ LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
|
||||
return INVALID_CPU_AFFI_MASK;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1208,7 +1212,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
|
||||
} else if (runTask->signal & SIGNAL_AFFI) {
|
||||
runTask->signal &= ~SIGNAL_AFFI;
|
||||
|
||||
/* pri-queue has updated, notify the target cpu */
|
||||
/* priority queue has updated, notify the target cpu */
|
||||
LOS_MpSchedule((UINT32)runTask->cpuAffiMask);
|
||||
#endif
|
||||
}
|
||||
@@ -1257,19 +1261,19 @@ EXIT:
|
||||
return err;
|
||||
}
|
||||
|
||||
UINT32 OsUserTaskOperatePermissionsCheck(LosTaskCB *taskCB)
|
||||
INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB)
|
||||
{
|
||||
return OsUserProcessOperatePermissionsCheck(taskCB, OsCurrProcessGet()->processID);
|
||||
}
|
||||
|
||||
UINT32 OsUserProcessOperatePermissionsCheck(LosTaskCB *taskCB, UINT32 processID)
|
||||
INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID)
|
||||
{
|
||||
if (taskCB == NULL) {
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
if (processID == OS_INVALID_VALUE) {
|
||||
return OS_INVALID_VALUE;
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
@@ -1347,21 +1351,22 @@ 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;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
policy = -LOS_EINVAL;
|
||||
OS_GOTO_ERREND();
|
||||
}
|
||||
|
||||
policy = taskCB->policy;
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
policy = (INT32)param.policy;
|
||||
|
||||
LOS_ERREND:
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1370,8 +1375,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;
|
||||
@@ -1385,8 +1390,21 @@ 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);
|
||||
needSched = OsSchedModifyTaskSchedParam(OS_TCB_FROM_TID(taskID), policy, priority);
|
||||
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);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
@@ -1411,9 +1429,15 @@ STATIC UINT32 OsTaskJoinCheck(UINT32 taskID)
|
||||
return LOS_EINVAL;
|
||||
}
|
||||
|
||||
if (taskID == OsCurrTaskGet()->taskID) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
if (taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
|
||||
return LOS_EPERM;
|
||||
}
|
||||
|
||||
if (taskCB == OsCurrTaskGet()) {
|
||||
return LOS_EDEADLK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -1421,7 +1445,6 @@ UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 errRet;
|
||||
|
||||
errRet = OsTaskJoinCheck(taskID);
|
||||
@@ -1429,7 +1452,7 @@ UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
|
||||
return errRet;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
@@ -1462,7 +1485,6 @@ UINT32 LOS_TaskDetach(UINT32 taskID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 errRet;
|
||||
|
||||
if (OS_TID_CHECK_INVALID(taskID)) {
|
||||
@@ -1473,7 +1495,7 @@ UINT32 LOS_TaskDetach(UINT32 taskID)
|
||||
return LOS_EINTR;
|
||||
}
|
||||
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
SCHEDULER_LOCK(intSave);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
@@ -54,7 +54,7 @@ extern BOOL OsMemIsHeapNode(const VOID *ptr);
|
||||
extern UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[]);
|
||||
|
||||
/* memory expand size at least 1/8 of pool size if we can */
|
||||
#define MEM_EXPAND_SIZE(poolSize) (poolSize >> 3)
|
||||
#define MEM_EXPAND_SIZE(poolSize) ((poolSize) >> 3)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
|
||||
#define OS_MUX_MAGIC 0xEBCFDEA0
|
||||
|
||||
extern VOID OsMuxBitmapRestore(const LosMux *mutex, const LosTaskCB *taskCB, LosTaskCB *owner);
|
||||
extern VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask);
|
||||
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-2021 Huawei Device 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:
|
||||
@@ -295,11 +295,6 @@ 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
|
||||
@@ -488,7 +483,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);
|
||||
extern UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param);
|
||||
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-2021 Huawei Device 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:
|
||||
@@ -41,7 +41,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_RWLOCK_MAGIC 0xBEFDCAU
|
||||
#define OS_RWLOCK_MAGIC 0xEFDCAU
|
||||
|
||||
enum RwlockMode {
|
||||
RWLOCK_NONE_MODE,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -37,10 +37,11 @@
|
||||
#include "los_hwi.h"
|
||||
#include "hal_timer.h"
|
||||
#ifdef LOSCFG_SCHED_DEBUG
|
||||
#include "los_stat_pri.h"
|
||||
#include "los_statistics_pri.h"
|
||||
#endif
|
||||
#include "los_stackinfo_pri.h"
|
||||
#include "los_futex_pri.h"
|
||||
#include "los_pm_pri.h"
|
||||
#include "los_signal.h"
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#include "los_cpup_pri.h"
|
||||
@@ -48,6 +49,7 @@
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
#include "hm_liteipc.h"
|
||||
#endif
|
||||
#include "los_mp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -55,14 +57,17 @@ 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 (UINT64)(((UINT64)-1) - 1U)
|
||||
#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))
|
||||
|
||||
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)
|
||||
@@ -76,53 +81,65 @@ typedef enum {
|
||||
INT_PEND_TICK = 0x2, /* pending tick */
|
||||
} SchedFlag;
|
||||
|
||||
#define OS_PRIORITY_QUEUE_NUM 32
|
||||
typedef struct {
|
||||
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;
|
||||
LOS_DL_LIST priQueList[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 readyTasks[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 queueBitmap;
|
||||
} HPFQueue;
|
||||
|
||||
extern SchedRunQue g_schedRunQue[LOSCFG_KERNEL_CORE_NUM];
|
||||
typedef struct {
|
||||
HPFQueue queueList[OS_PRIORITY_QUEUE_NUM];
|
||||
UINT32 queueBitmap;
|
||||
} HPFRunqueue;
|
||||
|
||||
STATIC INLINE SchedRunQue *OsSchedRunQue(VOID)
|
||||
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)
|
||||
{
|
||||
return &g_schedRunQue[ArchCurrCpuid()];
|
||||
return &g_schedRunqueue[ArchCurrCpuid()];
|
||||
}
|
||||
|
||||
STATIC INLINE SchedRunQue *OsSchedRunQueByID(UINT16 id)
|
||||
STATIC INLINE SchedRunqueue *OsSchedRunqueueByID(UINT16 id)
|
||||
{
|
||||
return &g_schedRunQue[id];
|
||||
return &g_schedRunqueue[id];
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSchedLockCountGet(VOID)
|
||||
{
|
||||
return OsSchedRunQue()->taskLockCnt;
|
||||
return OsSchedRunqueue()->taskLockCnt;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedLockSet(UINT32 count)
|
||||
{
|
||||
OsSchedRunQue()->taskLockCnt = count;
|
||||
OsSchedRunqueue()->taskLockCnt = count;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedLock(VOID)
|
||||
{
|
||||
OsSchedRunQue()->taskLockCnt++;
|
||||
OsSchedRunqueue()->taskLockCnt++;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedUnlock(VOID)
|
||||
{
|
||||
OsSchedRunQue()->taskLockCnt--;
|
||||
OsSchedRunqueue()->taskLockCnt--;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsSchedUnlockResch(VOID)
|
||||
{
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
if (rq->taskLockCnt > 0) {
|
||||
rq->taskLockCnt--;
|
||||
if ((rq->taskLockCnt == 0) && (rq->schedFlag & INT_PEND_RESCH) && OS_SCHEDULER_ACTIVE) {
|
||||
@@ -135,130 +152,106 @@ STATIC INLINE BOOL OsSchedUnlockResch(VOID)
|
||||
|
||||
STATIC INLINE BOOL OsSchedIsLock(VOID)
|
||||
{
|
||||
return (OsSchedRunQue()->taskLockCnt != 0);
|
||||
return (OsSchedRunqueue()->taskLockCnt != 0);
|
||||
}
|
||||
|
||||
/* Check if preemptable with counter flag */
|
||||
/* Check if preemptible with counter flag */
|
||||
STATIC INLINE BOOL OsPreemptable(VOID)
|
||||
{
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
/*
|
||||
* Unlike OsPreemptableInSched, the int may be not disabled when OsPreemptable
|
||||
* is called, needs mannually disable interrupt, to prevent current task from
|
||||
* being migrated to another core, and get the wrong preeptable status.
|
||||
* is called, needs manually disable interrupt, to prevent current task from
|
||||
* being migrated to another core, and get the wrong preemptable status.
|
||||
*/
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
BOOL preemptable = (rq->taskLockCnt == 0);
|
||||
if (!preemptable) {
|
||||
BOOL preemptible = (rq->taskLockCnt == 0);
|
||||
if (!preemptible) {
|
||||
/* Set schedule flag if preemption is disabled */
|
||||
rq->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return preemptable;
|
||||
return preemptible;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsPreemptableInSched(VOID)
|
||||
{
|
||||
BOOL preemptable = FALSE;
|
||||
SchedRunQue *rq = OsSchedRunQue();
|
||||
BOOL preemptible = FALSE;
|
||||
SchedRunqueue *rq = OsSchedRunqueue();
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
* For smp systems, schedule must hold the task spinlock, and this counter
|
||||
* will increase by 1 in that case.
|
||||
*/
|
||||
preemptable = (rq->taskLockCnt == 1);
|
||||
preemptible = (rq->taskLockCnt == 1);
|
||||
|
||||
#else
|
||||
preemptable = (rq->taskLockCnt == 0);
|
||||
preemptible = (rq->taskLockCnt == 0);
|
||||
#endif
|
||||
if (!preemptable) {
|
||||
if (!preemptible) {
|
||||
/* Set schedule flag if preemption is disabled */
|
||||
rq->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
|
||||
return preemptable;
|
||||
return preemptible;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSchedGetRunQueIdle(VOID)
|
||||
STATIC INLINE UINT32 OsSchedRunqueueIdleGet(VOID)
|
||||
{
|
||||
return OsSchedRunQue()->idleTaskID;
|
||||
return OsSchedRunqueue()->idleTaskID;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedRunQuePendingSet(VOID)
|
||||
STATIC INLINE VOID OsSchedRunqueuePendingSet(VOID)
|
||||
{
|
||||
OsSchedRunQue()->schedFlag |= INT_PEND_RESCH;
|
||||
OsSchedRunqueue()->schedFlag |= INT_PEND_RESCH;
|
||||
}
|
||||
|
||||
#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
|
||||
#define LOS_SCHED_NORMAL 0U
|
||||
#define LOS_SCHED_FIFO 1U
|
||||
#define LOS_SCHED_RR 2U
|
||||
#define LOS_SCHED_IDLE 3U
|
||||
|
||||
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;
|
||||
UINT16 basePrio;
|
||||
UINT16 priority;
|
||||
UINT32 timeSlice;
|
||||
} SchedParam;
|
||||
|
||||
STATIC INLINE UINT32 OsSchedSwtmrHandlerQueueGet(VOID)
|
||||
{
|
||||
return OsSchedRunQue()->swtmrHandlerQueue;
|
||||
}
|
||||
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 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 {
|
||||
union {
|
||||
SchedHPF hpf;
|
||||
} Policy;
|
||||
} SchedPolicy;
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
/**
|
||||
* @ingroup los_sched
|
||||
@@ -348,23 +341,31 @@ BOOL OsSchedSwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg);
|
||||
*/
|
||||
#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 {
|
||||
typedef struct TagTaskCB {
|
||||
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 */
|
||||
@@ -379,8 +380,6 @@ typedef struct {
|
||||
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
|
||||
@@ -468,7 +467,7 @@ STATIC INLINE VOID OsCurrUserTaskSet(UINTPTR thread)
|
||||
ArchCurrUserTaskSet(thread);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedIrqUpdateUsedTime(VOID)
|
||||
STATIC INLINE VOID OsSchedIrqUsedTimeUpdate(VOID)
|
||||
{
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
runTask->irqUsedTime = OsGetCurrSchedTimeCycle() - runTask->irqStartTime;
|
||||
@@ -480,6 +479,121 @@ 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;
|
||||
|
||||
if (!OsIsPmMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -492,25 +606,59 @@ STATIC INLINE VOID OsSchedIrqStartTime(VOID)
|
||||
g_taskScheduled &= ~(1U << (cpuid)); \
|
||||
} while (0);
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
|
||||
VOID OsSchedUpdateExpireTime(VOID);
|
||||
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 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
|
||||
@@ -525,14 +673,6 @@ 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
|
||||
}
|
||||
|
||||
@@ -72,28 +72,42 @@ 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(SortLinkAttribute *head)
|
||||
STATIC INLINE UINT32 OsGetSortLinkNodeNum(const 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
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef struct {
|
||||
} StackInfo;
|
||||
|
||||
#define OS_INVALID_WATERLINE 0xFFFFFFFF
|
||||
#define OS_STACK_MAGIC_CHECK(topstack) (*(UINTPTR *)(topstack) == OS_STACK_MAGIC_WORD) /* 1:magic valid 0:unvalid */
|
||||
#define OS_STACK_MAGIC_CHECK(topstack) (*(UINTPTR *)(topstack) == OS_STACK_MAGIC_WORD) /* 1:magic valid 0:invalid */
|
||||
|
||||
extern VOID OsExcStackInfo(VOID);
|
||||
extern VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum);
|
||||
@@ -81,4 +81,4 @@ extern UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *sta
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_STACK_INFO_PRI_H */
|
||||
#endif /* _LOS_STACK_INFO_PRI_H */
|
||||
|
||||
@@ -40,11 +40,6 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
UINT64 runtime;
|
||||
UINT32 contexSwitch;
|
||||
} SchedPercpu;
|
||||
|
||||
typedef struct {
|
||||
UINT64 allRuntime;
|
||||
UINT64 runTime;
|
||||
@@ -56,9 +51,17 @@ 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,6 +66,10 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -100,13 +104,42 @@ extern SWTMR_CTRL_S *g_swtmrCBArray;
|
||||
* @see LOS_SwtmrStop
|
||||
*/
|
||||
|
||||
extern UINT32 OsSwtmrGetNextTimeout(VOID);
|
||||
extern BOOL OsIsSwtmrTask(const LosTaskCB *taskCB);
|
||||
extern VOID OsSwtmrRestart(UINT64 startTime, SortLinkList *sortList);
|
||||
extern VOID OsSwtmrWake(SchedRunQue *rq, UINT64 currTime, SortLinkList *sortList);
|
||||
extern VOID OsSwtmrResponseTimeReset(UINT64 startTime);
|
||||
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-2021 Huawei Device 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:
|
||||
@@ -43,9 +43,9 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
* Define task siginal types.
|
||||
* Define task signal types.
|
||||
*
|
||||
* Task siginal types.
|
||||
* Task signal types.
|
||||
*/
|
||||
#define SIGNAL_NONE 0U
|
||||
#define SIGNAL_KILL (1U << 0)
|
||||
@@ -73,7 +73,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task control block is unused.
|
||||
*/
|
||||
#define OS_TASK_STATUS_UNUSED 0x0200U
|
||||
#define OS_TASK_STATUS_UNUSED 0x0400U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -81,7 +81,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* The task is joinable.
|
||||
*/
|
||||
#define OS_TASK_FLAG_PTHREAD_JOIN 0x0400U
|
||||
#define OS_TASK_FLAG_PTHREAD_JOIN 0x0800U
|
||||
|
||||
/**
|
||||
* @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 0x0800U
|
||||
#define OS_TASK_FLAG_USER_MODE 0x1000U
|
||||
|
||||
/**
|
||||
* @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 0x1000U
|
||||
#define OS_TASK_FLAG_SYSTEM_TASK 0x2000U
|
||||
|
||||
/**
|
||||
* @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 0x2000U
|
||||
#define OS_TASK_FLAG_NO_DELETE 0x4000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -113,15 +113,7 @@ extern SPIN_LOCK_S g_taskSpin;
|
||||
*
|
||||
* Kills the thread during process exit.
|
||||
*/
|
||||
#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
|
||||
#define OS_TASK_FLAG_EXIT_KILL 0x8000U
|
||||
|
||||
/**
|
||||
* @ingroup los_task
|
||||
@@ -323,8 +315,8 @@ extern UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam);
|
||||
extern INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName);
|
||||
extern VOID OsTaskCBRecycleToFree(VOID);
|
||||
extern VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status);
|
||||
extern UINT32 OsUserTaskOperatePermissionsCheck(LosTaskCB *taskCB);
|
||||
extern UINT32 OsUserProcessOperatePermissionsCheck(LosTaskCB *taskCB, UINT32 processID);
|
||||
extern INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB);
|
||||
extern INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID);
|
||||
extern INT32 OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info);
|
||||
extern VOID OsWriteResourceEvent(UINT32 events);
|
||||
extern VOID OsWriteResourceEventUnsafe(UINT32 events);
|
||||
|
||||
@@ -59,9 +59,9 @@ extern "C" {
|
||||
const CHAR *OsGetRegionNameOrFilePath(LosVmMapRegion *region);
|
||||
INT32 OsRegionOverlapCheckUnlock(LosVmSpace *space, LosVmMapRegion *region);
|
||||
UINT32 OsShellCmdProcessVmUsage(LosVmSpace *space);
|
||||
VOID OsShellCmdProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
VOID OsUProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
VOID OsKProcessPmUsage(LosVmSpace *kAspace, UINT32 *actualPm);
|
||||
UINT32 OsShellCmdProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
UINT32 OsUProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm);
|
||||
UINT32 OsKProcessPmUsage(LosVmSpace *kAspace, UINT32 *actualPm);
|
||||
VOID OsDumpAspace(LosVmSpace *space);
|
||||
UINT32 OsCountRegionPages(LosVmSpace *space, LosVmMapRegion *region, UINT32 *pssPages);
|
||||
UINT32 OsCountAspacePages(LosVmSpace *space);
|
||||
|
||||
@@ -50,7 +50,7 @@ extern "C" {
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#define VM_PAGE_TO_PHYS(page) (page->physAddr)
|
||||
#define VM_PAGE_TO_PHYS(page) ((page)->physAddr)
|
||||
#define VM_ORDER_TO_PAGES(order) (1 << (order))
|
||||
#define VM_ORDER_TO_PHYS(order) (1 << (PAGE_SHIFT + (order)))
|
||||
#define VM_PHYS_TO_ORDER(phys) (min(LOS_LowBitGet((phys) >> PAGE_SHIFT), VM_LIST_ORDER_MAX - 1))
|
||||
|
||||
@@ -86,18 +86,18 @@ extern "C" {
|
||||
#define PERIPH_UNCACHED_SIZE U32_C(PERIPH_PMM_SIZE)
|
||||
#endif
|
||||
|
||||
#define IO_DEVICE_ADDR(paddr) (paddr - PERIPH_PMM_BASE + PERIPH_DEVICE_BASE)
|
||||
#define IO_CACHED_ADDR(paddr) (paddr - PERIPH_PMM_BASE + PERIPH_CACHED_BASE)
|
||||
#define IO_UNCACHED_ADDR(paddr) (paddr - PERIPH_PMM_BASE + PERIPH_UNCACHED_BASE)
|
||||
#define IO_DEVICE_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_DEVICE_BASE)
|
||||
#define IO_CACHED_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_CACHED_BASE)
|
||||
#define IO_UNCACHED_ADDR(paddr) ((paddr) - PERIPH_PMM_BASE + PERIPH_UNCACHED_BASE)
|
||||
|
||||
#define MEM_CACHED_ADDR(paddr) (paddr - DDR_MEM_ADDR + KERNEL_VMM_BASE)
|
||||
#define MEM_UNCACHED_ADDR(paddr) (paddr - DDR_MEM_ADDR + UNCACHED_VMM_BASE)
|
||||
#define MEM_CACHED_ADDR(paddr) ((paddr) - DDR_MEM_ADDR + KERNEL_VMM_BASE)
|
||||
#define MEM_UNCACHED_ADDR(paddr) ((paddr) - DDR_MEM_ADDR + UNCACHED_VMM_BASE)
|
||||
|
||||
#define VMM_TO_UNCACHED_ADDR(vaddr) (vaddr - KERNEL_VMM_BASE + UNCACHED_VMM_BASE)
|
||||
#define UNCACHED_TO_VMM_ADDR(vaddr) (vaddr - UNCACHED_VMM_BASE + KERNEL_VMM_BASE)
|
||||
#define VMM_TO_UNCACHED_ADDR(vaddr) ((vaddr) - KERNEL_VMM_BASE + UNCACHED_VMM_BASE)
|
||||
#define UNCACHED_TO_VMM_ADDR(vaddr) ((vaddr) - UNCACHED_VMM_BASE + KERNEL_VMM_BASE)
|
||||
|
||||
#define VMM_TO_DMA_ADDR(vaddr) (vaddr - KERNEL_VMM_BASE + SYS_MEM_BASE)
|
||||
#define DMA_TO_VMM_ADDR(vaddr) (vaddr - SYS_MEM_BASE + KERNEL_VMM_BASE)
|
||||
#define VMM_TO_DMA_ADDR(vaddr) ((vaddr) - KERNEL_VMM_BASE + SYS_MEM_BASE)
|
||||
#define DMA_TO_VMM_ADDR(vaddr) ((vaddr) - SYS_MEM_BASE + KERNEL_VMM_BASE)
|
||||
|
||||
#if (PERIPH_UNCACHED_BASE >= (0xFFFFFFFFU - PERIPH_UNCACHED_SIZE))
|
||||
#error "Kernel virtual memory space has overflowed!"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -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 = OsSchedTaskWait(&eventCB->stEventList, timeout, TRUE);
|
||||
ret = runTask->ops->wait(runTask, &eventCB->stEventList, timeout);
|
||||
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);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
}
|
||||
|
||||
return exitFlag;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -112,16 +112,16 @@ STATIC VOID OsFutexShowTaskNodeAttr(const LOS_DL_LIST *futexList)
|
||||
LOS_DL_LIST *queueList = NULL;
|
||||
|
||||
tempNode = OS_FUTEX_FROM_FUTEXLIST(futexList);
|
||||
PRINTK("key(pid) : 0x%x(%d) : ->", tempNode->key, tempNode->pid);
|
||||
PRINTK("key(pid) : 0x%x(%u) : ->", tempNode->key, tempNode->pid);
|
||||
|
||||
for (queueList = &tempNode->queueList; ;) {
|
||||
lastNode = OS_FUTEX_FROM_QUEUELIST(queueList);
|
||||
if (!LOS_ListEmpty(&(lastNode->pendList))) {
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(lastNode->pendList)));
|
||||
PRINTK(" %d(%d) ->", taskCB->taskID, taskCB->priority);
|
||||
PRINTK(" %u ->", taskCB->taskID);
|
||||
} else {
|
||||
taskCB = LOS_DL_LIST_ENTRY(lastNode, LosTaskCB, futex);
|
||||
PRINTK(" %d(%d) ->", taskCB->taskID, -1);
|
||||
PRINTK(" %u ->", taskCB->taskID);
|
||||
}
|
||||
queueList = queueList->pstNext;
|
||||
if (queueList == &tempNode->queueList) {
|
||||
@@ -336,20 +336,19 @@ 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) {
|
||||
tempNode = OS_FUTEX_FROM_QUEUELIST(listTail);
|
||||
FutexNode *tempNode = OS_FUTEX_FROM_QUEUELIST(listTail);
|
||||
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
|
||||
if (tempNode == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
if (runTask->priority >= taskTail->priority) {
|
||||
LosTaskCB *taskTail = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
INT32 ret = OsSchedParamCompare(runTask, taskTail);
|
||||
if (ret >= 0) {
|
||||
LOS_ListHeadInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
} else if (runTask->priority < taskTail->priority) {
|
||||
} else {
|
||||
if (listTail->pstPrev == listHead) {
|
||||
LOS_ListTailInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
@@ -364,26 +363,25 @@ 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) {
|
||||
tempNode = OS_FUTEX_FROM_QUEUELIST(listHead);
|
||||
FutexNode *tempNode = OS_FUTEX_FROM_QUEUELIST(listHead);
|
||||
tempNode = OsFutexDeleteAlreadyWakeTaskAndGetNext(tempNode, NULL, FALSE);
|
||||
if (tempNode == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
taskHead = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(tempNode->pendList)));
|
||||
LosTaskCB *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
|
||||
*/
|
||||
if (runTask->priority >= taskHead->priority) {
|
||||
INT32 ret = OsSchedParamCompare(runTask, taskHead);
|
||||
if (ret >= 0) {
|
||||
if (listHead->pstNext == listTail) {
|
||||
LOS_ListHeadInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
continue;
|
||||
} else if (runTask->priority < taskHead->priority) {
|
||||
} else {
|
||||
LOS_ListTailInsert(&(tempNode->queueList), &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -414,10 +412,9 @@ 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;
|
||||
|
||||
if (run->priority < taskHead->priority) {
|
||||
INT32 ret1 = OsSchedParamCompare(run, taskHead);
|
||||
if (ret1 < 0) {
|
||||
/* The one with the highest priority is inserted at the top of the queue */
|
||||
LOS_ListTailInsert(queueList, &(node->queueList));
|
||||
OsFutexReplaceQueueListHeadNode(*firstNode, node);
|
||||
@@ -425,16 +422,16 @@ STATIC INT32 OsFutexInsertTasktoPendList(FutexNode **firstNode, FutexNode *node,
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
if (LOS_ListEmpty(queueList) && (run->priority >= taskHead->priority)) {
|
||||
if (LOS_ListEmpty(queueList) && (ret1 >= 0)) {
|
||||
/* Insert the next position in the queue with equal priority */
|
||||
LOS_ListHeadInsert(queueList, &(node->queueList));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
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))) {
|
||||
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)) {
|
||||
return OsFutexInsertFindFormBackToFront(queueList, run, node);
|
||||
}
|
||||
|
||||
@@ -524,7 +521,7 @@ STATIC INT32 OsFutexWaitParamCheck(const UINT32 *userVaddr, UINT32 flags, UINT32
|
||||
}
|
||||
|
||||
if (!absTime) {
|
||||
return LOS_EINVAL;
|
||||
return LOS_ETIMEDOUT;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
@@ -569,7 +566,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;
|
||||
@@ -600,9 +597,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);
|
||||
@@ -639,17 +636,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)
|
||||
@@ -693,7 +690,7 @@ STATIC VOID OsFutexCheckAndWakePendTask(FutexNode *headNode, const INT32 wakeNum
|
||||
node = *nextNode;
|
||||
taskCB = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(node->pendList)));
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(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-2021 Huawei Device 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:
|
||||
@@ -257,40 +257,36 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask, LosTaskCB *owner)
|
||||
STATIC VOID OsMuxBitmapSet(const LosMux *mutex, const LosTaskCB *runTask)
|
||||
{
|
||||
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 LosTaskCB *taskCB, LosTaskCB *owner)
|
||||
{
|
||||
UINT16 bitMapPri;
|
||||
|
||||
if (mutex->attr.protocol != LOS_MUX_PRIO_INHERIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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. */
|
||||
@@ -303,9 +299,11 @@ 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) && (runTask->priority > mutex->attr.prioceiling)) {
|
||||
LOS_BitmapSet(&runTask->priBitMap, runTask->priority);
|
||||
(VOID)OsSchedModifyTaskSchedParam(runTask, runTask->policy, mutex->attr.prioceiling);
|
||||
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);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -323,27 +321,23 @@ STATIC UINT32 OsMuxPendOp(LosTaskCB *runTask, LosMux *mutex, UINT32 timeout)
|
||||
return LOS_EDEADLK;
|
||||
}
|
||||
|
||||
OsMuxBitmapSet(mutex, runTask, (LosTaskCB *)mutex->owner);
|
||||
OsMuxBitmapSet(mutex, runTask);
|
||||
|
||||
owner = (LosTaskCB *)mutex->owner;
|
||||
runTask->taskMux = (VOID *)mutex;
|
||||
node = OsSchedLockPendFindPos(runTask, &mutex->muxList);
|
||||
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &mutex->muxList);
|
||||
if (node == NULL) {
|
||||
ret = LOS_NOK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_MUTEX, (UINTPTR)mutex, timeout);
|
||||
ret = OsSchedTaskWait(node, timeout, TRUE);
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -440,50 +434,23 @@ 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(mutex->muxList)));
|
||||
OsMuxBitmapRestore(mutex, &mutex->muxList, resumedTask);
|
||||
|
||||
mutex->muxCount = 1;
|
||||
mutex->owner = (VOID *)resumedTask;
|
||||
LOS_ListDelete(&mutex->holdList);
|
||||
LOS_ListTailInsert(&resumedTask->lockList, &mutex->holdList);
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
resumedTask->taskMux = NULL;
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
@@ -494,8 +461,6 @@ 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;
|
||||
}
|
||||
@@ -517,11 +482,9 @@ UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
|
||||
}
|
||||
|
||||
if (mutex->attr.protocol == LOS_MUX_PRIO_PROTECT) {
|
||||
bitMapPri = LOS_HighBitGet(taskCB->priBitMap);
|
||||
if (bitMapPri != LOS_INVALID_BIT_INDEX) {
|
||||
LOS_BitmapClr(&taskCB->priBitMap, bitMapPri);
|
||||
(VOID)OsSchedModifyTaskSchedParam(taskCB, taskCB->policy, bitMapPri);
|
||||
}
|
||||
SchedParam param = { 0 };
|
||||
taskCB->ops->schedParamGet(taskCB, ¶m);
|
||||
taskCB->ops->priorityRestore(taskCB, NULL, ¶m);
|
||||
}
|
||||
|
||||
/* 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-2021 Huawei Device 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:
|
||||
@@ -223,6 +223,7 @@ 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;
|
||||
@@ -249,9 +250,7 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueID
|
||||
return LOS_ERRNO_QUEUE_NOT_CREATE;
|
||||
}
|
||||
|
||||
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)))) {
|
||||
if (OS_QUEUE_IS_WRITE(operateType) && (*bufferSize > (queueCB->queueSize - sizeof(UINT32)))) {
|
||||
return LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG;
|
||||
}
|
||||
return LOS_OK;
|
||||
@@ -259,15 +258,13 @@ 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);
|
||||
queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueID);
|
||||
ret = OsQueueOperateParamCheck(queueCB, queueID, operateType, bufferSize);
|
||||
if (ret != LOS_OK) {
|
||||
goto QUEUE_END;
|
||||
@@ -284,8 +281,9 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
|
||||
goto QUEUE_END;
|
||||
}
|
||||
|
||||
LosTaskCB *runTask = OsCurrTaskGet();
|
||||
OsTaskWaitSetPendMask(OS_TASK_WAIT_QUEUE, queueCB->queueID, timeout);
|
||||
ret = OsSchedTaskWait(&queueCB->readWriteList[readWrite], timeout, TRUE);
|
||||
ret = runTask->ops->wait(runTask, &queueCB->readWriteList[readWrite], timeout);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = LOS_ERRNO_QUEUE_TIMEOUT;
|
||||
goto QUEUE_END;
|
||||
@@ -297,9 +295,9 @@ UINT32 OsQueueOperate(UINT32 queueID, UINT32 operateType, VOID *bufferAddr, UINT
|
||||
OsQueueBufferOperate(queueCB, operateType, bufferAddr, bufferSize);
|
||||
|
||||
if (!LOS_ListEmpty(&queueCB->readWriteList[!readWrite])) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[!readWrite]));
|
||||
LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&queueCB->readWriteList[!readWrite]));
|
||||
OsTaskWakeClearPendMask(resumedTask);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
LOS_Schedule();
|
||||
|
||||
@@ -82,7 +82,7 @@ VOID OsQueueDbgUpdate(UINT32 queueID, TSK_ENTRY_FUNC entry)
|
||||
STATIC INLINE VOID OsQueueInfoOutPut(const LosQueueCB *node)
|
||||
{
|
||||
PRINTK("Queue ID <0x%x> may leak, queue len is 0x%x, "
|
||||
"readable cnt:0x%x, writeable cnt:0x%x, ",
|
||||
"readable cnt:0x%x, writable cnt:0x%x, ",
|
||||
node->queueID,
|
||||
node->queueLen,
|
||||
node->readWriteableCnt[OS_QUEUE_READ],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "los_exc.h"
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
|
||||
#ifdef LOSCFG_BASE_IPC_RWLOCK
|
||||
#define RWLOCK_COUNT_MASK 0x00FFFFFFU
|
||||
|
||||
@@ -120,7 +119,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 (runTask->priority < highestTask->priority) {
|
||||
if (OsSchedParamCompare(runTask, highestTask) < 0) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@@ -164,7 +163,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 = OsSchedTaskWait(node, timeout, TRUE);
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
return LOS_ETIMEDOUT;
|
||||
}
|
||||
@@ -205,7 +204,7 @@ STATIC UINT32 OsRwlockWrPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
|
||||
* write task will be pended.
|
||||
*/
|
||||
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->writeList));
|
||||
ret = OsSchedTaskWait(node, timeout, TRUE);
|
||||
ret = runTask->ops->wait(runTask, node, timeout);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = LOS_ETIMEDOUT;
|
||||
}
|
||||
@@ -355,7 +354,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 (pendedWriteTask->priority <= pendedReadTask->priority) {
|
||||
if (OsSchedParamCompare(pendedWriteTask, pendedReadTask) <= 0) {
|
||||
return RWLOCK_WRITEFIRST_MODE;
|
||||
}
|
||||
return RWLOCK_READFIRST_MODE;
|
||||
@@ -365,7 +364,6 @@ STATIC UINT32 OsRwlockPostOp(LosRwlock *rwlock, BOOL *needSched)
|
||||
{
|
||||
UINT32 rwlockMode;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
UINT16 pendedWriteTaskPri;
|
||||
|
||||
rwlock->rwCount = 0;
|
||||
rwlock->writeOwner = NULL;
|
||||
@@ -378,29 +376,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;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
/* 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)));
|
||||
|
||||
rwlock->rwCount = 1;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
while (!LOS_ListEmpty(&(rwlock->readList))) {
|
||||
resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->readList)));
|
||||
if ((rwlockMode == RWLOCK_READFIRST_MODE) && (resumedTask->priority >= pendedWriteTaskPri)) {
|
||||
break;
|
||||
if (rwlockMode == RWLOCK_READFIRST_MODE) {
|
||||
LosTaskCB *pendedWriteTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(rwlock->writeList)));
|
||||
if (OsSchedParamCompare(resumedTask, pendedWriteTask) >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rwlock->rwCount == INT8_MAX) {
|
||||
return EINVAL;
|
||||
}
|
||||
rwlock->rwCount++;
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
}
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -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 = OsSchedTaskWait(&semPended->semList, timeout, TRUE);
|
||||
retErr = runTask->ops->wait(runTask, &semPended->semList, timeout);
|
||||
if (retErr == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
retErr = LOS_ERRNO_SEM_TIMEOUT;
|
||||
}
|
||||
@@ -237,10 +237,8 @@ OUT:
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
|
||||
{
|
||||
LosSemCB *semPosted = NULL;
|
||||
LosTaskCB *resumedTask = NULL;
|
||||
|
||||
semPosted = GET_SEM(semHandle);
|
||||
LosSemCB *semPosted = GET_SEM(semHandle);
|
||||
if ((semPosted->semID != semHandle) || (semPosted->semStat == OS_SEM_UNUSED)) {
|
||||
return LOS_ERRNO_SEM_INVALID;
|
||||
}
|
||||
@@ -254,7 +252,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);
|
||||
OsSchedTaskWake(resumedTask);
|
||||
resumedTask->ops->wake(resumedTask);
|
||||
if (needSched != NULL) {
|
||||
*needSched = TRUE;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -129,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);
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
OsSigEmptySet(&sigcb->sigwaitmask);
|
||||
}
|
||||
}
|
||||
@@ -152,19 +152,19 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
||||
break;
|
||||
case OS_TASK_WAIT_JOIN:
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
break;
|
||||
case OS_TASK_WAIT_SIGNAL:
|
||||
OsSigWaitTaskWake(taskCB, signo);
|
||||
break;
|
||||
case OS_TASK_WAIT_LITEIPC:
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
break;
|
||||
case OS_TASK_WAIT_FUTEX:
|
||||
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
taskCB->ops->wake(taskCB);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -567,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 = OsSchedTaskWait(&sigcb->waitList, timeout, TRUE);
|
||||
ret = task->ops->wait(task, &sigcb->waitList, timeout);
|
||||
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
|
||||
ret = -EAGAIN;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemboxInit(VOID *pool, UINT32 poolSize, UINT32
|
||||
}
|
||||
|
||||
MEMBOX_LOCK(intSave);
|
||||
boxInfo->uwBlkSize = LOS_MEMBOX_ALLIGNED(blkSize + OS_MEMBOX_NODE_HEAD_SIZE);
|
||||
boxInfo->uwBlkSize = LOS_MEMBOX_ALIGNED(blkSize + OS_MEMBOX_NODE_HEAD_SIZE);
|
||||
boxInfo->uwBlkNum = (poolSize - sizeof(LOS_MEMBOX_INFO)) / boxInfo->uwBlkSize;
|
||||
boxInfo->uwBlkCnt = 0;
|
||||
if (boxInfo->uwBlkNum == 0) {
|
||||
|
||||
@@ -169,7 +169,7 @@ struct OsMemPoolHead {
|
||||
|
||||
/* The memory pool support expand. */
|
||||
#define OS_MEM_POOL_EXPAND_ENABLE 0x01
|
||||
/* The memory pool ssupport no lock. */
|
||||
/* The memory pool support no lock. */
|
||||
#define OS_MEM_POOL_LOCK_ENABLE 0x02
|
||||
|
||||
#define OS_MEM_NODE_MAGIC 0xABCDDCBA
|
||||
@@ -486,7 +486,7 @@ STATIC INLINE VOID OsLmsAllocAlignMark(VOID *ptr, VOID *alignedPtr, UINT32 size)
|
||||
g_lms->simpleMark((UINTPTR)ptr + sizeof(UINT32), (UINTPTR)alignedPtr, LMS_SHADOW_REDZONE_U8);
|
||||
}
|
||||
|
||||
/* mark remining as redzone */
|
||||
/* mark remaining as redzone */
|
||||
g_lms->simpleMark(LMS_ADDR_ALIGN((UINTPTR)alignedPtr + size), (UINTPTR)OS_MEM_NEXT_NODE(allocNode),
|
||||
LMS_SHADOW_REDZONE_U8);
|
||||
}
|
||||
@@ -636,7 +636,7 @@ STATIC INLINE UINT32 OsMemFreeListIndexGet(UINT32 size)
|
||||
}
|
||||
|
||||
STATIC INLINE struct OsMemFreeNodeHead *OsMemFindCurSuitableBlock(struct OsMemPoolHead *poolHead,
|
||||
UINT32 index, UINT32 size)
|
||||
UINT32 index, UINT32 size)
|
||||
{
|
||||
struct OsMemFreeNodeHead *node = NULL;
|
||||
|
||||
@@ -649,9 +649,12 @@ STATIC INLINE struct OsMemFreeNodeHead *OsMemFindCurSuitableBlock(struct OsMemPo
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define BITMAP_INDEX(index) ((index) >> 5)
|
||||
STATIC INLINE UINT32 OsMemNotEmptyIndexGet(struct OsMemPoolHead *poolHead, UINT32 index)
|
||||
{
|
||||
UINT32 mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
|
||||
UINT32 mask;
|
||||
|
||||
mask = poolHead->freeListBitmap[BITMAP_INDEX(index)];
|
||||
mask &= ~((1 << (index & OS_MEM_BITMAP_MASK)) - 1);
|
||||
if (mask != 0) {
|
||||
index = OsMemFFS(mask) + (index & ~OS_MEM_BITMAP_MASK);
|
||||
@@ -685,8 +688,8 @@ STATIC INLINE struct OsMemFreeNodeHead *OsMemFindNextSuitableBlock(VOID *pool, U
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
for (index = LOS_Align(index + 1, 32); index < OS_MEM_FREE_LIST_COUNT; index += 32) {
|
||||
mask = poolHead->freeListBitmap[index >> 5]; /* 5: Divide by 32 to calculate the index of the bitmap array. */
|
||||
for (index = LOS_Align(index + 1, 32); index < OS_MEM_FREE_LIST_COUNT; index += 32) { /* 32: align size */
|
||||
mask = poolHead->freeListBitmap[BITMAP_INDEX(index)];
|
||||
if (mask != 0) {
|
||||
index = OsMemFFS(mask) + index;
|
||||
goto DONE;
|
||||
@@ -707,12 +710,12 @@ DONE:
|
||||
|
||||
STATIC INLINE VOID OsMemSetFreeListBit(struct OsMemPoolHead *head, UINT32 index)
|
||||
{
|
||||
head->freeListBitmap[index >> 5] |= 1U << (index & 0x1f); /* 5: Divide by 32 to calculate the index of the bitmap array. */
|
||||
head->freeListBitmap[BITMAP_INDEX(index)] |= 1U << (index & 0x1f);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsMemClearFreeListBit(struct OsMemPoolHead *head, UINT32 index)
|
||||
{
|
||||
head->freeListBitmap[index >> 5] &= ~(1U << (index & 0x1f)); /* 5: Divide by 32 to calculate the index of the bitmap array. */
|
||||
head->freeListBitmap[BITMAP_INDEX(index)] &= ~(1U << (index & 0x1f));
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsMemListAdd(struct OsMemPoolHead *pool, UINT32 listIndex, struct OsMemFreeNodeHead *node)
|
||||
@@ -1183,42 +1186,45 @@ STATIC INLINE BOOL OsMemIsNodeValid(const struct OsMemNodeHead *node, const stru
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STATIC BOOL MemCheckUsedNode(const struct OsMemPoolHead *pool, const struct OsMemNodeHead *node,
|
||||
const struct OsMemNodeHead *startNode, const struct OsMemNodeHead *endNode)
|
||||
{
|
||||
if (!OsMemIsNodeValid(node, startNode, endNode, pool)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
const struct OsMemNodeHead *nextNode = OS_MEM_NEXT_NODE(node);
|
||||
if (!OsMemIsNodeValid(nextNode, startNode, endNode, pool)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!OS_MEM_NODE_GET_LAST_FLAG(nextNode->sizeAndFlag)) {
|
||||
if (nextNode->ptr.prev != node) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ((node != startNode) &&
|
||||
((!OsMemIsNodeValid(node->ptr.prev, startNode, endNode, pool)) ||
|
||||
(OS_MEM_NEXT_NODE(node->ptr.prev) != node))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemCheckUsedNode(const struct OsMemPoolHead *pool, const struct OsMemNodeHead *node)
|
||||
{
|
||||
struct OsMemNodeHead *startNode = (struct OsMemNodeHead *)OS_MEM_FIRST_NODE(pool);
|
||||
struct OsMemNodeHead *endNode = (struct OsMemNodeHead *)OS_MEM_END_NODE(pool, pool->info.totalSize);
|
||||
struct OsMemNodeHead *nextNode = NULL;
|
||||
BOOL doneFlag = FALSE;
|
||||
|
||||
do {
|
||||
do {
|
||||
if (!OsMemIsNodeValid(node, startNode, endNode, pool)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!OS_MEM_NODE_GET_USED_FLAG(node->sizeAndFlag)) {
|
||||
break;
|
||||
}
|
||||
|
||||
nextNode = OS_MEM_NEXT_NODE(node);
|
||||
if (!OsMemIsNodeValid(nextNode, startNode, endNode, pool)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!OS_MEM_NODE_GET_LAST_FLAG(nextNode->sizeAndFlag)) {
|
||||
if (nextNode->ptr.prev != node) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((node != startNode) &&
|
||||
((!OsMemIsNodeValid(node->ptr.prev, startNode, endNode, pool)) ||
|
||||
(OS_MEM_NEXT_NODE(node->ptr.prev) != node))) {
|
||||
break;
|
||||
}
|
||||
doneFlag = TRUE;
|
||||
} while (0);
|
||||
|
||||
doneFlag = MemCheckUsedNode(pool, node, startNode, endNode);
|
||||
if (!doneFlag) {
|
||||
#if OS_MEM_EXPAND_ENABLE
|
||||
if (OsMemIsLastSentinelNode(endNode) == FALSE) {
|
||||
@@ -1291,16 +1297,17 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
|
||||
|
||||
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret = LOS_NOK;
|
||||
|
||||
if ((pool == NULL) || (ptr == NULL) || !OS_MEM_IS_ALIGNED(pool, sizeof(VOID *)) ||
|
||||
!OS_MEM_IS_ALIGNED(ptr, sizeof(VOID *))) {
|
||||
return LOS_NOK;
|
||||
return ret;
|
||||
}
|
||||
OsHookCall(LOS_HOOK_TYPE_MEM_FREE, pool, ptr);
|
||||
|
||||
UINT32 ret = LOS_NOK;
|
||||
struct OsMemPoolHead *poolHead = (struct OsMemPoolHead *)pool;
|
||||
struct OsMemNodeHead *node = NULL;
|
||||
UINT32 intSave;
|
||||
|
||||
do {
|
||||
UINT32 gapSize = *(UINT32 *)((UINTPTR)ptr - sizeof(UINT32));
|
||||
@@ -1397,7 +1404,7 @@ STATIC INLINE VOID *OsGetRealPtr(const VOID *pool, VOID *ptr)
|
||||
}
|
||||
|
||||
STATIC INLINE VOID *OsMemRealloc(struct OsMemPoolHead *pool, const VOID *ptr,
|
||||
struct OsMemNodeHead *node, UINT32 size, UINT32 intSave)
|
||||
struct OsMemNodeHead *node, UINT32 size, UINT32 intSave)
|
||||
{
|
||||
struct OsMemNodeHead *nextNode = NULL;
|
||||
UINT32 allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
|
||||
@@ -1619,7 +1626,7 @@ STATIC UINT32 OsMemAddrValidCheckPrint(const VOID *pool, struct OsMemFreeNodeHea
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemIntegrityCheckSub(struct OsMemNodeHead **tmpNode, const VOID *pool,
|
||||
const struct OsMemNodeHead *endNode)
|
||||
const struct OsMemNodeHead *endNode)
|
||||
{
|
||||
if (!OS_MEM_MAGIC_VALID(*tmpNode)) {
|
||||
OsMemMagicCheckPrint(tmpNode);
|
||||
@@ -1635,7 +1642,7 @@ STATIC UINT32 OsMemIntegrityCheckSub(struct OsMemNodeHead **tmpNode, const VOID
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemFreeListNodeCheck(const struct OsMemPoolHead *pool,
|
||||
const struct OsMemFreeNodeHead *node)
|
||||
const struct OsMemFreeNodeHead *node)
|
||||
{
|
||||
if (!OsMemAddrValidCheck(pool, node) ||
|
||||
!OsMemAddrValidCheck(pool, node->prev) ||
|
||||
@@ -1698,7 +1705,7 @@ OUT:
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMemIntegrityCheck(const struct OsMemPoolHead *pool, struct OsMemNodeHead **tmpNode,
|
||||
struct OsMemNodeHead **preNode)
|
||||
struct OsMemNodeHead **preNode)
|
||||
{
|
||||
struct OsMemNodeHead *endNode = OS_MEM_END_NODE(pool, pool->info.totalSize);
|
||||
|
||||
@@ -1741,7 +1748,7 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode,
|
||||
usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
|
||||
} else {
|
||||
freeNode = (struct OsMemFreeNodeHead *)tmpNode;
|
||||
PRINTK("\n broken node head: %#x %#x %#x %#x, ",
|
||||
PRINTK("\n broken node head: %#x %#x %#x %#x, %#x",
|
||||
freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
|
||||
freeNode->header.sizeAndFlag);
|
||||
}
|
||||
@@ -1752,7 +1759,7 @@ STATIC VOID OsMemNodeInfo(const struct OsMemNodeHead *tmpNode,
|
||||
usedNode->header.ptr.prev, usedNode->header.magic, usedNode->header.sizeAndFlag);
|
||||
} else {
|
||||
freeNode = (struct OsMemFreeNodeHead *)preNode;
|
||||
PRINTK("prev node head: %#x %#x %#x %#x, ",
|
||||
PRINTK("prev node head: %#x %#x %#x %#x, %#x",
|
||||
freeNode->header.ptr.prev, freeNode->next, freeNode->prev, freeNode->header.magic,
|
||||
freeNode->header.sizeAndFlag);
|
||||
}
|
||||
@@ -1804,7 +1811,7 @@ STATIC VOID OsMemIntegrityCheckError(struct OsMemPoolHead *pool,
|
||||
tmpNode, preNode, taskCB->taskName);
|
||||
#else
|
||||
MEM_UNLOCK(pool, intSave);
|
||||
LOS_Panic("Memory interity check error, cur node: %#x, pre node: %#x\n", tmpNode, preNode);
|
||||
LOS_Panic("Memory integrity check error, cur node: %#x, pre node: %#x\n", tmpNode, preNode);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1846,7 +1853,7 @@ ERROR_OUT:
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsMemInfoGet(struct OsMemPoolHead *poolInfo, struct OsMemNodeHead *node,
|
||||
LOS_MEM_POOL_STATUS *poolStatus)
|
||||
LOS_MEM_POOL_STATUS *poolStatus)
|
||||
{
|
||||
UINT32 totalUsedSize = 0;
|
||||
UINT32 totalFreeSize = 0;
|
||||
@@ -1994,8 +2001,10 @@ UINT32 LOS_MemFreeNodeShow(VOID *pool)
|
||||
} else {
|
||||
UINT32 val = 1 << (((index - OS_MEM_SMALL_BUCKET_COUNT) >> OS_MEM_SLI) + OS_MEM_LARGE_START_BUCKET);
|
||||
UINT32 offset = val >> OS_MEM_SLI;
|
||||
PRINTK("size: [%#x, %#x], num: %u\n", (offset * ((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI))) + val,
|
||||
((offset * (((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI)) + 1)) + val - 1), countNum[index]);
|
||||
PRINTK("size: [%#x, %#x], num: %u\n",
|
||||
(offset * ((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI))) + val,
|
||||
((offset * (((index - OS_MEM_SMALL_BUCKET_COUNT) % (1 << OS_MEM_SLI)) + 1)) + val - 1),
|
||||
countNum[index]);
|
||||
}
|
||||
}
|
||||
PRINTK("\n ********************************************************************\n\n");
|
||||
|
||||
@@ -117,8 +117,10 @@ VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum)
|
||||
VOID OsStackInit(VOID *stacktop, UINT32 stacksize)
|
||||
{
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
(VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize);
|
||||
*((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD;
|
||||
errno_t ret = memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize);
|
||||
if (ret == EOK) {
|
||||
*((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
|
||||
@@ -193,7 +193,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[])
|
||||
|
||||
if (argc == 1) {
|
||||
if (strcmp(argv[0], "-a") == 0) {
|
||||
PRINTK("%s %d.%d.%d.%d %s %s\n", KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE,\
|
||||
PRINTK("%s %d.%d.%d.%d %s %s\n", KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, \
|
||||
__DATE__, __TIME__);
|
||||
return 0;
|
||||
} else if (strcmp(argv[0], "-s") == 0) {
|
||||
|
||||
@@ -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,13 +57,7 @@ STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
|
||||
UINT32 ticks = 0;
|
||||
(VOID)LOS_SwtmrTimeGet(swtmr->usTimerID, &ticks);
|
||||
|
||||
PRINTK("0x%08x "
|
||||
"%-7s "
|
||||
"%-6s "
|
||||
"%-6u "
|
||||
"%-6u "
|
||||
"0x%08x "
|
||||
"%p\n",
|
||||
PRINTK("%7u%10s%8s%12u%7u%#12x%#12x\n",
|
||||
swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT,
|
||||
g_shellSwtmrStatus[swtmr->ucState],
|
||||
g_shellSwtmrMode[swtmr->ucMode],
|
||||
@@ -75,34 +69,15 @@ STATIC VOID OsPrintSwtmrMsg(const SWTMR_CTRL_S *swtmr)
|
||||
|
||||
STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
|
||||
{
|
||||
PRINTK("\r\nSwTmrID State Mode Interval Count Arg handlerAddr\n");
|
||||
PRINTK("---------- ------- ------- --------- ------- ---------- --------\n");
|
||||
PRINTK("\r\nSwTmrID State Mode Interval Count Arg handlerAddr\n");
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv)
|
||||
STATIC UINT32 SwtmrBaseInfoGet(UINT32 timerID)
|
||||
{
|
||||
#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) {
|
||||
@@ -112,13 +87,13 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
|
||||
|
||||
if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
|
||||
PRINTK("\r\nThere is no swtmr was created!\n");
|
||||
return OS_ERROR;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -135,6 +110,70 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
|
||||
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-2021 Huawei Device 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:
|
||||
@@ -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,46 +63,45 @@
|
||||
#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_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32)))
|
||||
#define OS_TASK_SCHED_INFO_LEN (g_taskMaxNum * sizeof(SchedParam))
|
||||
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32) + sizeof(SchedParam)))
|
||||
|
||||
#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 PROCESS_INFO_SHOW(seqBuf, arg...) do { \
|
||||
if (seqBuf != NULL) { \
|
||||
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
|
||||
#define SHOW(arg...) do { \
|
||||
if (seqBuf != NULL) { \
|
||||
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
|
||||
} else { \
|
||||
PRINTK(arg); \
|
||||
} \
|
||||
SaveExcInfo(arg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define PROCESS_INFO_SHOW(seqBuf, arg...) PRINTK(arg)
|
||||
#define SHOW(arg...) PRINTK(arg)
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdProcessMode(UINT16 mode)
|
||||
#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)
|
||||
{
|
||||
if (mode == OS_KERNEL_MODE) {
|
||||
return (UINT8 *)"kernel";
|
||||
@@ -113,7 +112,7 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdProcessMode(UINT16 mode)
|
||||
return (UINT8 *)"ERROR";
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdSchedPolicy(UINT16 policy)
|
||||
STATIC UINT8 *ConvertSchedPolicyToString(UINT16 policy)
|
||||
{
|
||||
if (policy == LOS_SCHED_RR) {
|
||||
return (UINT8 *)"RR";
|
||||
@@ -126,7 +125,7 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdSchedPolicy(UINT16 policy)
|
||||
return (UINT8 *)"ERROR";
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellProcessStatus(UINT16 status)
|
||||
STATIC UINT8 *ConvertProcessStatusToString(UINT16 status)
|
||||
{
|
||||
if (status & OS_PROCESS_STATUS_ZOMBIES) {
|
||||
return (UINT8 *)"Zombies";
|
||||
@@ -140,118 +139,123 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellProcessStatus(UINT16 status)
|
||||
return (UINT8 *)"Pending";
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdProcessTitle(VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
PROCESS_INFO_SHOW(seqBuf, "\r\n PID PPID PGID UID Status ");
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
PROCESS_INFO_SHOW(seqBuf, "VirtualMem ShareMem PhysicalMem ");
|
||||
}
|
||||
|
||||
SHOW("\r\n PID PPID PGID UID Mode Status Policy Priority MTID TTotal");
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
SHOW(" VirtualMem ShareMem PhysicalMem");
|
||||
}
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
|
||||
SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
PROCESS_INFO_SHOW(seqBuf, "Policy Priority MTID TaskTotal Mode ");
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
|
||||
SHOW(" CPUUSE10s");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
PROCESS_INFO_SHOW(seqBuf, " PName\n");
|
||||
SHOW(" PName\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdProcessInfoShow(const LosProcessCB *processCB, const INT32 *group,
|
||||
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID AllProcessDataShow(const LosProcessCB *pcbArray, const SchedParam *param,
|
||||
UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
const UINT32 *procMemUsage = NULL;
|
||||
const INT32 *group = (const INT32 *)((UINTPTR)pcbArray + OS_PROCESS_INFO_LEN);
|
||||
const INT32 *user = (const INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
UINT32 pid = processCB->processID;
|
||||
PROCESS_INFO_SHOW(seqBuf, "%5u%6d%5d%10d%8s", pid, (INT32)processCB->parentProcessID, group[pid], user[pid],
|
||||
OsShellProcessStatus(processCB->processStatus));
|
||||
|
||||
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) {
|
||||
const UINT32 *memArray = (const UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
#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);
|
||||
}
|
||||
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
|
||||
|
||||
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;
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
const LosProcessCB *processCB = pcbArray + pid;
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
OsShellCmdProcessInfoShow(processCB, group, memArray, seqBuf, flag);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
STATIC VOID OsProcessMemUsageGet(UINT32 *memArray)
|
||||
STATIC VOID ProcessMemUsageGet(LosProcessCB *pcbArray)
|
||||
{
|
||||
UINT32 pid;
|
||||
LosProcessCB *processCB = NULL;
|
||||
UINT32 *proMemUsage = NULL;
|
||||
UINT32 intSave, memUsed;
|
||||
UINT32 *memArray = (UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
|
||||
for (pid = 0; pid < g_processMaxNum; ++pid) {
|
||||
processCB = g_processCBArray + pid;
|
||||
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);
|
||||
if (OsProcessIsUnused(processCB)) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
|
||||
continue;
|
||||
}
|
||||
proMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
|
||||
|
||||
LosVmSpace *vmSpace = processCB->vmSpace;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* Process memory usage statistics, idle task defaults to 0 */
|
||||
if (pid == OsGetIdleProcessID()) {
|
||||
proMemUsage[PROCESS_VM_INDEX] = 0;
|
||||
proMemUsage[PROCESS_SM_INDEX] = 0;
|
||||
proMemUsage[PROCESS_PM_INDEX] = 0;
|
||||
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];
|
||||
} else {
|
||||
proMemUsage[PROCESS_VM_INDEX] = OsShellCmdProcessVmUsage(processCB->vmSpace);
|
||||
OsShellCmdProcessPmUsage(processCB->vmSpace, &proMemUsage[PROCESS_SM_INDEX],
|
||||
&proMemUsage[PROCESS_PM_INDEX]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define OS_TASK_STATUS_MASK 0x00FF
|
||||
STATIC VOID OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group,
|
||||
UINT32 **memArray, LosTaskCB **tcbArray,
|
||||
UINT16 flag)
|
||||
STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam)
|
||||
{
|
||||
*group = (INT32 *)((UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN);
|
||||
INT32 *user = (INT32 *)((UINTPTR)*group + OS_PROCESS_GROUP_INFO_LEN);
|
||||
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;
|
||||
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
|
||||
LosTaskCB *taskCB = *tcbArray + tid;
|
||||
const LosTaskCB *taskCB = *tcbArray + tid;
|
||||
if (OsTaskIsUnused(taskCB)) {
|
||||
continue;
|
||||
}
|
||||
@@ -260,18 +264,19 @@ STATIC VOID OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group,
|
||||
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) {
|
||||
LosProcessCB *processCB = *pcbArray + pid;
|
||||
const 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
|
||||
@@ -284,47 +289,28 @@ STATIC VOID OsProcessInfoGet(LosProcessCB **pcbArray, INT32 **group,
|
||||
user[processCB->processID] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
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);
|
||||
|
||||
(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
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
*memArray = (UINT32 *)((UINTPTR)*pcbArray + OS_PROCESS_ALL_INFO_LEN);
|
||||
OsProcessMemUsageGet(*memArray);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdProcessInfoData(const LosProcessCB *pcbArray, const INT32 *group,
|
||||
const UINT32 *memArray, VOID *seqBuf, UINT16 flag)
|
||||
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 - processCpupAll[pid].usage;
|
||||
UINT32 sysUsage = LOS_CPUP_PRECISION - cpupAll[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);
|
||||
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);
|
||||
#endif
|
||||
|
||||
OsShellCmdProcessTitle(seqBuf, flag);
|
||||
OsShellCmdAllProcessInfoShow(pcbArray, group, memArray, seqBuf, flag);
|
||||
ProcessInfoTitle(seqBuf, flag);
|
||||
AllProcessDataShow(pcbArray, param, cpupInfo, seqBuf, flag);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
|
||||
STATIC UINT8 *ConvertTaskStatusToString(UINT16 taskStatus)
|
||||
{
|
||||
if (taskStatus & OS_TASK_STATUS_INIT) {
|
||||
return (UINT8 *)"Init";
|
||||
@@ -332,6 +318,8 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(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) {
|
||||
@@ -349,26 +337,30 @@ LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
|
||||
return (UINT8 *)"Invalid";
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray)
|
||||
STATIC VOID TaskWaterLineGet(UINTPTR waterLineBase, LosTaskCB *tcbArray)
|
||||
{
|
||||
const LosTaskCB *taskCB = NULL;
|
||||
UINT32 loop;
|
||||
UINT32 intSave;
|
||||
UINT32 *taskWaterLine = (UINT32 *)waterLineBase;
|
||||
|
||||
for (loop = 0; loop < g_taskMaxNum; ++loop) {
|
||||
taskCB = allTaskArray + loop;
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = g_taskCBArray + tid;
|
||||
SCHEDULER_LOCK(intSave);
|
||||
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 *OsShellCheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
{
|
||||
*lockID = taskCB->waitID;
|
||||
switch (taskCB->waitFlag) {
|
||||
@@ -403,24 +395,23 @@ STATIC CHAR *OsShellCheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdCheckTaskPend(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
STATIC VOID TaskPendingReasonInfoGet(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
|
||||
{
|
||||
CHAR *reason = NULL;
|
||||
LosTaskCB *owner = NULL;
|
||||
|
||||
if (!(taskCB->taskStatus & OS_TASK_STATUS_PENDING)) {
|
||||
reason = (CHAR *)OsShellCmdConvertTskStatus(taskCB->taskStatus);
|
||||
reason = (CHAR *)ConvertTaskStatusToString(taskCB->taskStatus);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
reason = OsShellCheckTaskWaitFlag(taskCB, lockID);
|
||||
reason = CheckTaskWaitFlag(taskCB, lockID);
|
||||
if (reason == NULL) {
|
||||
reason = "Others";
|
||||
}
|
||||
|
||||
if (taskCB->taskMux != NULL) {
|
||||
*lockID = (UINTPTR)taskCB->taskMux;
|
||||
owner = ((LosMux *)taskCB->taskMux)->owner;
|
||||
LosTaskCB *owner = ((LosMux *)taskCB->taskMux)->owner;
|
||||
if (owner != NULL) {
|
||||
if (snprintf_s(pendReason, maxLen, maxLen - 1, "Mutex-%u", owner->taskID) == EOK) {
|
||||
return;
|
||||
@@ -435,103 +426,133 @@ EXIT:
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID TaskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
PROCESS_INFO_SHOW(seqBuf, "\r\n TID PID ");
|
||||
SHOW("\r\n TID PID");
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
PROCESS_INFO_SHOW(seqBuf, "Affi CPU ");
|
||||
SHOW(" Affi CPU");
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, " Status StackSize WaterLine ");
|
||||
SHOW(" Status Policy Priority StackSize WaterLine");
|
||||
if (flag & OS_PROCESS_INFO_ALL) {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE CPUUSE10s CPUUSE1s ");
|
||||
SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
PROCESS_INFO_SHOW(seqBuf, " StackPoint TopOfStack PendReason LockID ");
|
||||
SHOW(" StackPoint TopOfStack PendReason LockID");
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, "Policy Priority ");
|
||||
} else {
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
PROCESS_INFO_SHOW(seqBuf, "CPUUSE10s ");
|
||||
SHOW(" CPUUSE10s ");
|
||||
#endif /* LOSCFG_KERNEL_CPUP */
|
||||
}
|
||||
PROCESS_INFO_SHOW(seqBuf, " MEMUSE TaskName\n");
|
||||
SHOW(" TaskName\n");
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID AllTaskInfoDataShow(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
#ifdef LOSCFG_SHELL_CMD_DEBUG
|
||||
UINTPTR lockID = 0;
|
||||
CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
|
||||
#endif
|
||||
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) {
|
||||
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
|
||||
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);
|
||||
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;
|
||||
#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;
|
||||
for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
|
||||
for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
|
||||
const LosTaskCB *taskCB = allTaskArray + tid;
|
||||
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);
|
||||
|
||||
OsShellTskInfoData(taskCB, seqBuf, flag);
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTaskArray, VOID *seqBuf, UINT16 flag)
|
||||
STATIC VOID TaskInfoData(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
OsShellCmdTskInfoTitle(seqBuf, flag);
|
||||
OsShellCmdAllTaskInfoData(allTaskArray, seqBuf, flag);
|
||||
TaskInfoTitle(seqBuf, flag);
|
||||
AllTaskInfoDataShow(allTaskArray, cpupInfo, seqBuf, flag);
|
||||
}
|
||||
|
||||
STATIC VOID OsProcessAndTaskInfoGet(LosProcessCB **pcbArray, INT32 **group, LosTaskCB **tcbArray,
|
||||
UINT32 **memArray, UINT16 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)
|
||||
{
|
||||
BOOL lockFlag = FALSE;
|
||||
UINT32 intSave = 0;
|
||||
UINT32 processInfoLen = OS_PROCESS_ALL_INFO_LEN;
|
||||
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);
|
||||
}
|
||||
|
||||
if (LOS_SpinHeld(&g_taskSpin) == FALSE) {
|
||||
SCHEDULER_LOCK(intSave);
|
||||
lockFlag = TRUE;
|
||||
}
|
||||
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;
|
||||
UINT32 processInfoLen = OS_PROCESS_ALL_INFO_LEN;
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
@@ -539,25 +560,35 @@ STATIC VOID OsProcessAndTaskInfoGet(LosProcessCB **pcbArray, INT32 **group, LosT
|
||||
}
|
||||
#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);
|
||||
|
||||
OsProcessInfoGet(pcbArray, group, memArray, tcbArray, flag);
|
||||
taskWaterLine = (UINT32 *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
|
||||
OsShellCmdTaskWaterLineGet(*tcbArray);
|
||||
if (lockFlag == TRUE) {
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
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);
|
||||
}
|
||||
#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;
|
||||
UINT32 *memArray = NULL;
|
||||
SchedParam *schedParam = NULL;
|
||||
UINTPTR cpupInfo = 0;
|
||||
|
||||
if (taskID == OS_ALL_TASK_MASK) {
|
||||
if (flag & OS_PROCESS_MEM_INFO) {
|
||||
@@ -571,9 +602,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf,
|
||||
return LOS_NOK;
|
||||
}
|
||||
(VOID)memset_s(pcbArray, size, 0, size);
|
||||
OsProcessAndTaskInfoGet(&pcbArray, &group, &tcbArray, &memArray, flag);
|
||||
OsShellCmdProcessInfoData(pcbArray, group, memArray, seqBuf, flag);
|
||||
OsShellCmdTskInfoData(tcbArray, seqBuf, flag);
|
||||
ProcessAndTaskInfoGet(&pcbArray, &tcbArray, &schedParam, &cpupInfo, flag);
|
||||
ProcessInfoShow(pcbArray, schedParam, cpupInfo, seqBuf, flag);
|
||||
TaskInfoData(tcbArray, cpupInfo, seqBuf, flag);
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem1, pcbArray);
|
||||
}
|
||||
@@ -595,16 +626,20 @@ 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 (!OsShellShowTickRespo()) {
|
||||
if (!OsShellShowTickResponse()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else if (strcmp("-t", argv[0]) == 0) {
|
||||
if (!OsShellShowSchedParam()) {
|
||||
if (!OsShellShowSchedStatistics()) {
|
||||
return LOS_OK;
|
||||
}
|
||||
goto TASK_HELP;
|
||||
#endif
|
||||
} else {
|
||||
goto TASK_HELP;
|
||||
}
|
||||
@@ -614,7 +649,9 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
|
||||
|
||||
TASK_HELP:
|
||||
PRINTK("Unknown option: %s\n", argv[0]);
|
||||
PRINTK("usage: task or task -a\n");
|
||||
PRINTK("Usage:\n");
|
||||
PRINTK(" task --- Basic information about all created processes.\n");
|
||||
PRINTK(" task -a --- Complete information about all created processes.\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ STATIC INLINE CHAR *OsLockDepErrorStringGet(enum LockDepErrType type)
|
||||
errorString = "lockdep overflow";
|
||||
break;
|
||||
default:
|
||||
errorString = "unknow error code";
|
||||
errorString = "unknown error code";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
|
||||
OsPrintLockDepInfo("task name : %s\n", temp->taskName);
|
||||
OsPrintLockDepInfo("task id : %u\n", temp->taskID);
|
||||
OsPrintLockDepInfo("cpu num : %u\n", temp->currCpu);
|
||||
OsPrintLockDepInfo("start dumping lockdep infomation\n");
|
||||
OsPrintLockDepInfo("start dumping lockdep information\n");
|
||||
for (i = 0; i < lockDep->lockDepth; i++) {
|
||||
if (lockDep->heldLocks[i].lockPtr == lock) {
|
||||
OsPrintLockDepInfo("[%d] %s <-- addr:0x%x\n", i, LOCKDEP_GET_NAME(lockDep, i),
|
||||
@@ -165,7 +165,7 @@ STATIC VOID OsLockDepDumpLock(const LosTaskCB *task, const SPIN_LOCK_S *lock,
|
||||
}
|
||||
}
|
||||
|
||||
STATIC BOOL OsLockDepCheckDependancy(const LosTaskCB *current, LosTaskCB *lockOwner)
|
||||
STATIC BOOL OsLockDepCheckDependency(const LosTaskCB *current, LosTaskCB *lockOwner)
|
||||
{
|
||||
BOOL checkResult = TRUE;
|
||||
SPIN_LOCK_S *lockTemp = NULL;
|
||||
@@ -217,7 +217,7 @@ VOID OsLockDepCheckIn(SPIN_LOCK_S *lock)
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
if (OsLockDepCheckDependancy(current, lockOwner) != TRUE) {
|
||||
if (OsLockDepCheckDependency(current, lockOwner) != TRUE) {
|
||||
checkResult = LOCKDEP_ERR_DEAD_LOCK;
|
||||
goto OUT;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ VOID OsLockDepCheckOut(SPIN_LOCK_S *lock)
|
||||
/* record lock holding time */
|
||||
heldlocks[depth].holdTime = OsLockDepGetCycles() - heldlocks[depth].holdTime;
|
||||
|
||||
/* if unlock a older lock, needs move heldLock records */
|
||||
/* if unlock an older lock, needs move heldLock records */
|
||||
while (depth < lockDep->lockDepth - 1) {
|
||||
lockDep->heldLocks[depth] = lockDep->heldLocks[depth + 1];
|
||||
depth++;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
OsSchedRunQuePendingSet();
|
||||
OsSchedRunqueuePendingSet();
|
||||
}
|
||||
|
||||
VOID OsMpHaltHandler(VOID)
|
||||
|
||||
@@ -1,323 +0,0 @@
|
||||
/*
|
||||
* 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 %10d\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%d %+16lf ms %12d\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%d %+10lf%14d%14d%14d %+11lf %+11lf %+11lf%14d %+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
|
||||
|
||||
187
kernel/base/sched/los_idle.c
Normal file
187
kernel/base/sched/los_idle.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
546
kernel/base/sched/los_priority.c
Normal file
546
kernel/base/sched/los_priority.c
Normal file
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
538
kernel/base/sched/los_sched.c
Normal file
538
kernel/base/sched/los_sched.c
Normal file
@@ -0,0 +1,538 @@
|
||||
/*
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device 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:
|
||||
@@ -30,7 +30,6 @@
|
||||
*/
|
||||
|
||||
#include "los_sortlink_pri.h"
|
||||
#include "los_mp.h"
|
||||
|
||||
VOID OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
|
||||
{
|
||||
@@ -82,12 +81,6 @@ VOID OsAdd2SortLink(SortLinkAttribute *head, SortLinkList *node, UINT64 response
|
||||
node->cpuid = idleCpu;
|
||||
#endif
|
||||
LOS_SpinUnlock(&head->spinLock);
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (idleCpu != ArchCurrCpuid()) {
|
||||
LOS_MpSchedule(CPUID_TO_AFFI_MASK(idleCpu));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node)
|
||||
@@ -99,6 +92,21 @@ VOID OsDeleteFromSortLink(SortLinkAttribute *head, SortLinkList *node)
|
||||
LOS_SpinUnlock(&head->spinLock);
|
||||
}
|
||||
|
||||
UINT32 OsSortLinkAdjustNodeResponseTime(SortLinkAttribute *head, SortLinkList *node, UINT64 responseTime)
|
||||
{
|
||||
UINT32 ret = LOS_NOK;
|
||||
|
||||
LOS_SpinLock(&head->spinLock);
|
||||
if (node->responseTime != OS_SORT_LINK_INVALID_TIME) {
|
||||
OsDeleteNodeSortLink(head, node);
|
||||
SET_SORTLIST_VALUE(node, responseTime);
|
||||
AddNode2SortLink(head, node);
|
||||
ret = LOS_OK;
|
||||
}
|
||||
LOS_SpinUnlock(&head->spinLock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
UINT64 OsSortLinkGetTargetExpireTime(UINT64 currTime, const SortLinkList *targetSortList)
|
||||
{
|
||||
if (currTime >= targetSortList->responseTime) {
|
||||
172
kernel/base/sched/los_statistics.c
Normal file
172
kernel/base/sched/los_statistics.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
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