• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "common_components/common_runtime/base_runtime_param.h"
17 
18 #include "common_components/platform/cpu.h"
19 
20 namespace common {
InitHeapSize()21 size_t BaseRuntimeParam::InitHeapSize()
22 {
23     constexpr auto DEFAULT_HEAP_SIZE_PERCENTAGE = 0.6;
24     size_t systemSize = PhysicalSize();
25     size_t initHeapSize =
26         systemSize > 1 * GB ? std::min(systemSize * DEFAULT_HEAP_SIZE_PERCENTAGE / KB, 1.2 * MB) : 64 * KB;
27     return initHeapSize;
28 }
29 
SetConfigHeapSize(RuntimeParam & param,size_t configHeapSize)30 void BaseRuntimeParam::SetConfigHeapSize(RuntimeParam &param, size_t configHeapSize)
31 {
32     param.heapParam.heapSize = std::min(configHeapSize, MAX_HEAP_POOL_SIZE) / KB;
33 }
34 
SetMaxGarbageCacheSize(RuntimeParam & param,uint64_t maxGarbageCacheSize)35 void BaseRuntimeParam::SetMaxGarbageCacheSize(RuntimeParam &param, uint64_t maxGarbageCacheSize)
36 {
37     param.gcParam.maxGarbageCacheSize = maxGarbageCacheSize;
38 }
39 /**
40  * Determine the default stack size and heap size according to system memory.
41  * If system memory size is less then 1GB, heap size is 64MB and stack size is 64KB.
42  * Otherwise heap size is 256MB and stack size is 1MB.
43  */
DefaultRuntimeParam()44 RuntimeParam BaseRuntimeParam::DefaultRuntimeParam()
45 {
46     RuntimeParam param;
47 
48 #define INIT_DEFAULT_PARAM(key, subKey, type, minValue, maxValue, defaultValue) \
49         param.key.subKey = (defaultValue)
50 
51     RUNTIME_PARAM_LIST(INIT_DEFAULT_PARAM);
52 #undef INIT_DEFAULT_PARAM
53 
54     return param;
55 }
56 } // namespace common
57