Sun, 12 Mar 2017 09:04:47 +0800
#4670 Detect LoongsonCPUs to adapt different platforms.
1.1 --- a/src/cpu/mips/vm/globals_mips.hpp Sun Mar 05 09:06:36 2017 -0500 1.2 +++ b/src/cpu/mips/vm/globals_mips.hpp Sun Mar 12 09:04:47 2017 +0800 1.3 @@ -87,10 +87,10 @@ 1.4 1.5 #define ARCH_FLAGS(develop, product, diagnostic, experimental, notproduct) \ 1.6 \ 1.7 - product(bool, UseLoongsonISA, true, \ 1.8 + product(bool, UseLoongsonISA, false, \ 1.9 "Use LoongsonISA on Loongson CPUs") \ 1.10 \ 1.11 - product(bool, Use3A2000, true, \ 1.12 + product(bool, Use3A2000, false, \ 1.13 "Use Loongson 3A2000 CPU") \ 1.14 \ 1.15 product(intx, UseSyncLevel, 2000, \
2.1 --- a/src/cpu/mips/vm/vm_version_mips.cpp Sun Mar 05 09:06:36 2017 -0500 2.2 +++ b/src/cpu/mips/vm/vm_version_mips.cpp Sun Mar 12 09:04:47 2017 +0800 2.3 @@ -75,24 +75,12 @@ 2.4 } 2.5 */ 2.6 void VM_Version::initialize() { 2.7 + 2.8 _features = determine_features(); 2.9 //no need, Abstract_VM_Version already define it as false 2.10 _supports_cx8 = true; 2.11 - 2.12 - char buf[256]; 2.13 - jio_snprintf(buf, sizeof(buf), "%s, %s" 2.14 -#ifdef OPT_RANGECHECK 2.15 - ", optimized range check" 2.16 -#endif 2.17 -#ifdef OPT_PHI_1 2.18 - ", optimized phi" 2.19 -#endif 2.20 -#ifdef OPT_MERGE 2.21 - ", optimized merge" 2.22 -#endif 2.23 - , (has_l2_cache() ? "has_l2_cache" : ""), (has_16k_page() ? "has_16k_page" : "") 2.24 - ); 2.25 - //////////////////////add some other feature here////////////////// 2.26 + 2.27 + //////////////////////add some other feature here////////////////// 2.28 #ifdef COMPILER2 2.29 if (MaxVectorSize > 0) { 2.30 if (!is_power_of_2(MaxVectorSize)) { 2.31 @@ -103,11 +91,54 @@ 2.32 MaxVectorSize = 8; 2.33 } 2.34 } 2.35 - if (UseLoongsonISA) 2.36 - UseCountTrailingZerosInstruction = false; // 2017.01.22 Now this guy is only supported on 3A2000/3A3000. 2.37 + 2.38 + if (is_gs464e()) { 2.39 + if (FLAG_IS_DEFAULT(UseCountTrailingZerosInstruction)) { 2.40 + FLAG_SET_DEFAULT(UseCountTrailingZerosInstruction, 1); 2.41 + } 2.42 + } else if (UseCountTrailingZerosInstruction) { 2.43 + if (!FLAG_IS_DEFAULT(UseCountTrailingZerosInstruction)) 2.44 + warning("Only 3A2000/3000 CPUs support UseCountTrailingZerosInstruction"); 2.45 + FLAG_SET_DEFAULT(UseCountTrailingZerosInstruction, 0); 2.46 + } 2.47 #endif 2.48 UseSSE = 0; // Only on x86 and x64 2.49 2.50 + if (is_loongson()) { 2.51 + if (FLAG_IS_DEFAULT(UseLoongsonISA)) { 2.52 + FLAG_SET_DEFAULT(UseLoongsonISA, 1); 2.53 + } 2.54 + } else if (UseLoongsonISA) { 2.55 + if (!FLAG_IS_DEFAULT(UseLoongsonISA)) 2.56 + warning("Only Loongson CPUs support LoongISA"); 2.57 + FLAG_SET_DEFAULT(UseLoongsonISA, 0); 2.58 + } 2.59 + 2.60 + if (is_gs464e()) { 2.61 + if (FLAG_IS_DEFAULT(Use3A2000)) { 2.62 + FLAG_SET_DEFAULT(Use3A2000, 1); 2.63 + } 2.64 + } else if (Use3A2000) { 2.65 + if (!FLAG_IS_DEFAULT(Use3A2000)) 2.66 + warning("Only 3A2000/3000 CPUs support this option"); 2.67 + FLAG_SET_DEFAULT(Use3A2000, 0); 2.68 + } 2.69 + 2.70 + char buf[256]; 2.71 + jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s", 2.72 + (has_l2_cache() ? ", has_l2_cache" : ""), 2.73 + (has_16k_page() ? ", has_16k_page" : ""), 2.74 + (is_loongson() ? ", on_loongson" : ""), 2.75 + (is_gs464() ? ", 3A1000" : ""), 2.76 + (is_gs464v() ? ", 3B1500" : "" ), 2.77 + (is_gs464e() ? ", 3A2000/3A3000" : ""), 2.78 + (UseLoongsonISA ? ", UseLoongsonISA" : ""), 2.79 + (UseCountTrailingZerosInstruction ? ", UseCountTrailingZerosInstruction" : ""), 2.80 + (Use3A2000 ? ", Use3A2000" : "")); 2.81 + 2.82 + // buf is started with ", " or is empty 2.83 + _features_str = strdup(strlen(buf) > 2 ? buf + 2 : buf); 2.84 + 2.85 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { 2.86 FLAG_SET_DEFAULT(AllocatePrefetchStyle, 1); 2.87 } 2.88 @@ -119,7 +150,7 @@ 2.89 if (FLAG_IS_DEFAULT(AllocatePrefetchStepSize)) { 2.90 FLAG_SET_DEFAULT(AllocatePrefetchStepSize, 64); 2.91 } 2.92 - 2.93 + 2.94 if (FLAG_IS_DEFAULT(AllocatePrefetchDistance)) { 2.95 FLAG_SET_DEFAULT(AllocatePrefetchDistance, 64); 2.96 } 2.97 @@ -128,27 +159,27 @@ 2.98 FLAG_SET_DEFAULT(AllocateInstancePrefetchLines, 1); 2.99 } 2.100 2.101 - // buf is started with ", " or is empty 2.102 - _features_str = strdup(buf); 2.103 NOT_PRODUCT( if (PrintMiscellaneous && Verbose) print_features(); ); 2.104 } 2.105 2.106 void VM_Version::print_features() { 2.107 - tty->print_cr("Version:%s", cpu_features()); 2.108 + tty->print_cr("Version:%s", cpu_features()); 2.109 } 2.110 2.111 int VM_Version::determine_features() { 2.112 - //////////////////////add some other feature here////////////////// 2.113 - return spt_16k_page_m; 2.114 + //////////////////////add some other feature here////////////////// 2.115 + int features = platform_features(unknown_m); 2.116 + //spt_16k_page_m; 2.117 + return features; 2.118 } 2.119 2.120 static int saved_features = 0; 2.121 2.122 void VM_Version::allow_all() { 2.123 - saved_features = _features; 2.124 - _features = all_features_m; 2.125 + saved_features = _features; 2.126 + _features = all_features_m; 2.127 } 2.128 2.129 void VM_Version::revert() { 2.130 - _features = saved_features; 2.131 + _features = saved_features; 2.132 }
3.1 --- a/src/cpu/mips/vm/vm_version_mips.hpp Sun Mar 05 09:06:36 2017 -0500 3.2 +++ b/src/cpu/mips/vm/vm_version_mips.hpp Sun Mar 12 09:04:47 2017 +0800 3.3 @@ -25,53 +25,67 @@ 3.4 3.5 #ifndef CPU_MIPS_VM_VM_VERSION_MIPS_HPP 3.6 #define CPU_MIPS_VM_VM_VERSION_MIPS_HPP 3.7 - 3.8 + 3.9 #include "runtime/globals_extension.hpp" 3.10 #include "runtime/vm_version.hpp" 3.11 3.12 3.13 class VM_Version: public Abstract_VM_Version { 3.14 protected: 3.15 - enum Feature_Flag { 3.16 - with_l2_cache = 0, 3.17 - spt_16k_page = 1, 3.18 - //////////////////////add some other feature here////////////////// 3.19 - }; 3.20 + enum Feature_Flag { 3.21 + with_l2_cache = 0, 3.22 + spt_16k_page = 1, 3.23 + gs464v = 2, 3.24 + gs464e = 3, 3.25 + gs464 = 4, 3.26 + with_gs_support = 5, 3.27 + //////////////////////add some other feature here////////////////// 3.28 + }; 3.29 3.30 - enum Feature_Flag_Set { 3.31 - unknown_m = 0, 3.32 - all_features_m = -1, 3.33 - with_l2_cache_m = 1 << with_l2_cache, 3.34 - spt_16k_page_m = 1 << spt_16k_page, 3.35 + enum Feature_Flag_Set { 3.36 + unknown_m = 0, 3.37 + all_features_m = -1, 3.38 + with_l2_cache_m = 1 << with_l2_cache, 3.39 + spt_16k_page_m = 1 << spt_16k_page, 3.40 + with_gs_support_m = 1 << with_gs_support, 3.41 + gs464_m = 1 << gs464, 3.42 + gs464v_m = 1 << gs464v, 3.43 + gs464e_m = 1 << gs464e, 3.44 3.45 - //////////////////////add some other feature here////////////////// 3.46 - }; 3.47 - 3.48 - static int _features; 3.49 - static const char* _features_str; 3.50 + //////////////////////add some other feature here////////////////// 3.51 + }; 3.52 3.53 - static void print_features(); 3.54 - static int determine_features(); 3.55 + static int _features; 3.56 + static const char* _features_str; 3.57 + 3.58 + static void print_features(); 3.59 + static int determine_features(); 3.60 + static int platform_features(int features); 3.61 3.62 public: 3.63 - // Initialization 3.64 - static void initialize(); 3.65 - 3.66 - //mips has no such instructions, use ll/sc instead 3.67 - static bool supports_compare_and_exchange() { return false; } 3.68 + // Initialization 3.69 + static void initialize(); 3.70 3.71 - static bool has_l2_cache() { return _features & with_l2_cache_m; } 3.72 - static bool has_16k_page() { return _features & spt_16k_page_m; } 3.73 + //mips has no such instructions, use ll/sc instead 3.74 + static bool supports_compare_and_exchange() { return false; } 3.75 + 3.76 + static bool has_l2_cache() { return _features & with_l2_cache_m; } 3.77 + static bool has_16k_page() { return _features & spt_16k_page_m; } 3.78 + static bool is_gs464() { return _features & gs464_m; } 3.79 + static bool is_gs464v() { return _features & gs464v_m; } 3.80 + static bool is_gs464e() { return _features & gs464e_m; } 3.81 + static bool is_loongson() { return _features & with_gs_support_m; } 3.82 + static bool support_dsp() { return _features & gs464e_m; } 3.83 static bool supports_ps() { return 1; /*Loongson CPUs support ps instructions*/} 3.84 static bool supports_3d() { return 0; /*Loongson CPUs do not support 3d instructions*/} 3.85 - 3.86 - //////////////////////add some other feature here////////////////// 3.87 3.88 - static const char* cpu_features() { return _features_str; } 3.89 - 3.90 - // Assembler testing 3.91 - static void allow_all(); 3.92 - static void revert(); 3.93 + //////////////////////add some other feature here////////////////// 3.94 + 3.95 + static const char* cpu_features() { return _features_str; } 3.96 + 3.97 + // Assembler testing 3.98 + static void allow_all(); 3.99 + static void revert(); 3.100 }; 3.101 3.102 #endif // CPU_MIPS_VM_VM_VERSION_MIPS_HPP
4.1 --- a/src/os_cpu/linux_mips/vm/vm_version_linux_mips.cpp Sun Mar 05 09:06:36 2017 -0500 4.2 +++ b/src/os_cpu/linux_mips/vm/vm_version_linux_mips.cpp Sun Mar 12 09:04:47 2017 +0800 4.3 @@ -26,4 +26,61 @@ 4.4 #include "precompiled.hpp" 4.5 #include "runtime/os.hpp" 4.6 #include "vm_version_mips.hpp" 4.7 +#include "string.h" 4.8 +#define CPU_FAMILY_AMOUNT 5 4.9 4.10 +const char cpuinfo[CPU_FAMILY_AMOUNT][20] = { 4.11 + "not loongson", 4.12 + "3A2000", 4.13 + "3A3000", 4.14 + "Loongson-3A", 4.15 + "Loongson-3B", 4.16 +}; 4.17 + 4.18 +void read_cpu_info(const char *path, char *result) { 4.19 + FILE *ptr; 4.20 + char buf[1024],i=0; 4.21 + if((ptr=fopen(path, "r")) != NULL) { 4.22 + while(fgets(buf, 1024, ptr)!=NULL) { 4.23 + strcat(result,buf); 4.24 + i++; 4.25 + if (i==10) break; 4.26 + } 4.27 + fclose(ptr); 4.28 + } else { 4.29 + tty->print_cr("fopen %s error\n", path); 4.30 + } 4.31 +} 4.32 + 4.33 +int VM_Version::platform_features(int features) { 4.34 + char res[10240]; 4.35 + int i; 4.36 + features = spt_16k_page_m; //default support 4.37 + memset(res,'\0',1024*sizeof(char)); 4.38 + read_cpu_info("/proc/cpuinfo", res); 4.39 + for (i = 1; i < CPU_FAMILY_AMOUNT; i++){ 4.40 + if (strstr(res, cpuinfo[i])){ 4.41 + break; 4.42 + } 4.43 + } 4.44 + //add some other support when detected on loongson 4.45 + if (i != CPU_FAMILY_AMOUNT) { 4.46 + features |= with_gs_support_m; 4.47 + } 4.48 + switch (i % CPU_FAMILY_AMOUNT) { 4.49 + case 1 : 4.50 + case 2 : 4.51 + features |= gs464e_m; 4.52 + //tty->print_cr("3A2000/3A3000 platform"); 4.53 + break; 4.54 + case 3 : 4.55 + features |= gs464_m; 4.56 + //tty->print_cr("3A1000 platform"); 4.57 + break; 4.58 + case 4 : 4.59 + features |= gs464v_m; 4.60 + //tty->print_cr("3B1500 platform"); 4.61 + break; 4.62 + } 4.63 + return features; 4.64 +}