提交 548a9a94 编写于 作者: H hong19860320

fix segmentfault occurs on some devices(MTK and docker),

test=develop
上级 cdd63eb4
...@@ -106,13 +106,17 @@ size_t get_mem_size() { ...@@ -106,13 +106,17 @@ size_t get_mem_size() {
} }
void get_cpu_arch(std::vector<ARMArch>* archs, const int cpu_num) { void get_cpu_arch(std::vector<ARMArch>* archs, const int cpu_num) {
archs->clear(); archs->resize(cpu_num);
for (int i = 0; i < cpu_num; ++i) {
archs->at(i) = kARMArch_UNKOWN;
}
#ifdef LITE_WITH_LINUX #ifdef LITE_WITH_LINUX
//! get CPU ARCH //! get CPU ARCH
FILE* fp = fopen("/proc/cpuinfo", "rb"); FILE* fp = fopen("/proc/cpuinfo", "rb");
if (!fp) { if (!fp) {
return; return;
} }
int cpu_idx = 0;
char line[1024]; char line[1024];
while (!feof(fp)) { while (!feof(fp)) {
char* s = fgets(line, 1024, fp); char* s = fgets(line, 1024, fp);
...@@ -120,77 +124,73 @@ void get_cpu_arch(std::vector<ARMArch>* archs, const int cpu_num) { ...@@ -120,77 +124,73 @@ void get_cpu_arch(std::vector<ARMArch>* archs, const int cpu_num) {
break; break;
} }
if (strstr(line, "part") != NULL) { if (strstr(line, "part") != NULL) {
ARMArch arch_type = kARMArch_UNKOWN;
int arch_id = 0; int arch_id = 0;
sscanf(s, "CPU part\t: %x", &arch_id); sscanf(s, "CPU part\t: %x", &arch_id);
switch (arch_id) { switch (arch_id) {
case 0xd03: case 0xd03:
archs->push_back(kA53); arch_type = kA53;
break; break;
case 0xd05: case 0xd05:
archs->push_back(kA55); arch_type = kA55;
break; break;
case 0xd07: case 0xd07:
archs->push_back(kA57); arch_type = kA57;
break; break;
case 0xd08: case 0xd08:
archs->push_back(kA72); arch_type = kA72;
break; break;
case 0xd09: case 0xd09:
archs->push_back(kA73); arch_type = kA73;
break; break;
case 0xd0a: case 0xd0a:
archs->push_back(kA75); arch_type = kA75;
break; break;
case 0xd40: case 0xd40:
archs->push_back(kA76); arch_type = kA76;
break; break;
case 0x804: case 0x804:
// 855 // 855
archs->push_back(kA76); arch_type = kA76;
break; break;
case 0x805: case 0x805:
// 855 // 855
archs->push_back(kA55); arch_type = kA55;
break; break;
case 0x802: case 0x802:
// 845 // 845
archs->push_back(kA75); arch_type = kA75;
break; break;
case 0x803: case 0x803:
// 845 // 845
archs->push_back(kA55); arch_type = kA55;
break; break;
case 0x801: case 0x801:
// 835 // 835
archs->push_back(kA73); arch_type = kA73;
break; break;
case 0x800: case 0x800:
// 835 // 835
archs->push_back(kA73); arch_type = kA73;
break; break;
case 0x205: case 0x205:
// 820 // 820
archs->push_back(kA72); arch_type = kA72;
break; break;
default: default:
LOG(ERROR) << "Unknow cpu arch: " << arch_id; LOG(ERROR) << "Unknow cpu arch: " << arch_id;
archs->push_back(kARMArch_UNKOWN);
} }
archs->at(cpu_idx) = arch_type;
cpu_idx++;
} }
} }
fclose(fp); fclose(fp);
if (archs->size() < cpu_num) { for (; cpu_idx > 0 && cpu_idx < cpu_num; ++cpu_idx) {
for (int i = archs->size(); i < cpu_num; ++i) { archs->at(cpu_idx) = archs->at(cpu_idx - 1);
archs->push_back(archs->at(i - 1));
}
} }
#elif defined(TARGET_IOS) #elif defined(TARGET_IOS)
for (int i = 0; i < cpu_num; ++i) { for (int i = 0; i < cpu_num; ++i) {
archs->push_back(APPLE); archs->at(i) = APPLE;
}
#else
for (int i = 0; i < cpu_num; ++i) {
archs->push_back(kARMArch_UNKOWN);
} }
#endif #endif
} }
...@@ -829,9 +829,10 @@ int DeviceInfo::Setup() { ...@@ -829,9 +829,10 @@ int DeviceInfo::Setup() {
mem_size_ = get_mem_size(); mem_size_ = get_mem_size();
get_cpu_arch(&archs_, core_num_); get_cpu_arch(&archs_, core_num_);
// set defalut CPU info // set defalut CPU info
SetCacheInfo(0, DEFAULT_L1_CACHE_SIZE); SetCacheInfo(0, 1, DEFAULT_L1_CACHE_SIZE);
SetCacheInfo(1, DEFAULT_L2_CACHE_SIZE); SetCacheInfo(1, 1, DEFAULT_L2_CACHE_SIZE);
SetCacheInfo(2, DEFAULT_L3_CACHE_SIZE); SetCacheInfo(2, 1, DEFAULT_L3_CACHE_SIZE);
LOG(INFO) << "Done";
#ifdef LITE_WITH_LINUX #ifdef LITE_WITH_LINUX
// get max&min freq // get max&min freq
max_freqs_.resize(core_num_); max_freqs_.resize(core_num_);
...@@ -936,9 +937,9 @@ void DeviceInfo::SetRunMode(PowerMode mode, int thread_num) { ...@@ -936,9 +937,9 @@ void DeviceInfo::SetRunMode(PowerMode mode, int thread_num) {
} }
void DeviceInfo::SetCache(int l1size, int l2size, int l3size) { void DeviceInfo::SetCache(int l1size, int l2size, int l3size) {
SetCacheInfo(0, l1size); SetCacheInfo(0, 1, l1size);
SetCacheInfo(1, l2size); SetCacheInfo(1, 1, l2size);
SetCacheInfo(2, l3size); SetCacheInfo(2, 1, l3size);
workspace_.Resize({2 * (l1size + l2size)}); workspace_.Resize({2 * (l1size + l2size)});
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册