fix: 修复samgr_lite栈溢出的问题

共享task的内存默认为0x800,当任务函数调用层次较为复杂的时候,就会出现栈溢出的
问题,增加栈大小可配置参数,根据不同的情况进行栈大小调节

Signed-off-by: SimonLi <likailong@huawei.com>
This commit is contained in:
SimonLi 2021-11-26 22:36:09 +08:00
parent 9186205af0
commit b8f4b31181
4 changed files with 31 additions and 3 deletions

18
config.gni Normal file
View File

@ -0,0 +1,18 @@
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
declare_args() {
# configuration for samgr_lite created shared task's stack size.
# 0 means using system default thread stack size, other positive values will be accepted.
config_ohos_distributedschedule_samgr_lite_shared_task_size = 2048
}

View File

@ -10,8 +10,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import("../config.gni")
defines = []
if (defined(config_ohos_distributedschedule_samgr_lite_shared_task_size) &&
config_ohos_distributedschedule_samgr_lite_shared_task_size > 0) {
defines += [ "SHARED_TASK_STACK_SIZE=$config_ohos_distributedschedule_samgr_lite_shared_task_size" ]
}
config("external_settings_shared") { config("external_settings_shared") {
defines = [ "LAYER_INIT_SHARED_LIB" ] defines += [ "LAYER_INIT_SHARED_LIB" ]
} }
config("samgr_public") { config("samgr_public") {

View File

@ -441,7 +441,8 @@ static void AddTaskPool(ServiceImpl *service, TaskConfig *cfg, const char *name)
int pos = (int)cfg->priority / PROPERTY_STEP; int pos = (int)cfg->priority / PROPERTY_STEP;
SamgrLiteImpl *samgr = GetImplement(); SamgrLiteImpl *samgr = GetImplement();
if (samgr->sharedPool[pos] == NULL) { if (samgr->sharedPool[pos] == NULL) {
TaskConfig shareCfg = DEFAULT_TASK_CFG(pos); TaskConfig shareCfg = {LEVEL_HIGH, (int16) ((pos) * PROPERTY_STEP + 1),
SHARED_TASK_STACK_SIZE, 25, SHARED_TASK};
samgr->sharedPool[pos] = SAMGR_CreateFixedTaskPool(&shareCfg, name, DEFAULT_SIZE); samgr->sharedPool[pos] = SAMGR_CreateFixedTaskPool(&shareCfg, name, DEFAULT_SIZE);
} }
service->taskPool = samgr->sharedPool[pos]; service->taskPool = samgr->sharedPool[pos];

View File

@ -31,7 +31,6 @@ extern "C" {
#define SINGLE_SIZE 1 #define SINGLE_SIZE 1
#define MAX_POOL_NUM 8 #define MAX_POOL_NUM 8
#define PROPERTY_STEP 8 #define PROPERTY_STEP 8
#define DEFAULT_TASK_CFG(pos) {LEVEL_HIGH, (int16) ((pos) * PROPERTY_STEP + 1), 0x800, 25, SHARED_TASK}
#define WDG_SAMGR_INIT_TIME 1000 #define WDG_SAMGR_INIT_TIME 1000
#define WDG_SVC_REG_TIME 5000 #define WDG_SVC_REG_TIME 5000
#define WDG_SVC_BOOT_TIME 5000 #define WDG_SVC_BOOT_TIME 5000