#9224 Backport of #9173 Refactor read_cpu_info and supported 3A4000/3B4000

Tue, 28 May 2019 16:35:59 +0800

author
aoqi
date
Tue, 28 May 2019 16:35:59 +0800
changeset 9578
191e90d9878f
parent 9577
4972f2f8fe2a
child 9579
1938913e9ab2

#9224 Backport of #9173 Refactor read_cpu_info and supported 3A4000/3B4000
Reviewed-by: jiefu

src/cpu/mips/vm/vm_version_mips.cpp file | annotate | diff | comparison | revisions
src/cpu/mips/vm/vm_version_mips.hpp file | annotate | diff | comparison | revisions
src/os_cpu/linux_mips/vm/vm_version_linux_mips.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/cpu/mips/vm/vm_version_mips.cpp	Wed May 08 17:57:33 2019 +0800
     1.2 +++ b/src/cpu/mips/vm/vm_version_mips.cpp	Tue May 28 16:35:59 2019 +0800
     1.3 @@ -115,7 +115,7 @@
     1.4      }
     1.5    }
     1.6  
     1.7 -  if (is_gs464e()) {
     1.8 +  if (is_gs464e() || is_gs464v()) {
     1.9      if (FLAG_IS_DEFAULT(UseSyncLevel)) {
    1.10        FLAG_SET_DEFAULT(UseSyncLevel, 2000);
    1.11      }
    1.12 @@ -128,16 +128,20 @@
    1.13    }
    1.14  
    1.15    char buf[256];
    1.16 -  jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
    1.17 -              (has_l2_cache() ? ", has_l2_cache" : ""),
    1.18 -              (has_16k_page() ? ", has_16k_page" : ""),
    1.19 -              (is_loongson()  ? ", on_loongson"  : ""),
    1.20 -              (is_gs464() ?  ", 3A1000/3B1500" : ""),
    1.21 -              (is_gs464e() ? ", 3A2000/3A3000/3B2000/3B3000" : ""),
    1.22 -              (is_gs264() ?  ", 2K1000" : ""),
    1.23 -              (UseLoongsonISA ? ", UseLoongsonISA" : ""),
    1.24 +  bool is_unknown_loongson_cpu = is_loongson() && !is_gs464() && !is_gs464e() && !is_gs464v() && !is_gs264();
    1.25 +  jio_snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s%s%s, UseSyncLevel:%d",
    1.26 +              (has_l2_cache() ?  ", has_l2_cache" : ""),
    1.27 +              (has_16k_page() ?  ", has_16k_page" : ""),
    1.28 +              (is_loongson()  ?  ", MIPS-compatible Loongson CPU"  : "MIPS"),
    1.29 +              (is_gs464()     ?  ", GS464 (3A1000/3B1500)" : ""),
    1.30 +              (is_gs464e()    ?  ", GS464E (3A2000/3A3000/3B2000/3B3000)" : ""),
    1.31 +              (is_gs464v()    ?  ", GS464V (3A4000/3B4000)" : ""),
    1.32 +              (is_gs264()     ?  ", GS264 (2K1000)" : ""),
    1.33 +              (is_unknown_loongson_cpu ?  ", Unknown Loongson CPU" : ""),
    1.34 +              (UseLoongsonISA ?  ", UseLoongsonISA" : ""),
    1.35                (UseCountTrailingZerosInstructionMIPS64 ? ", UseCountTrailingZerosInstructionMIPS64" : ""),
    1.36 -              (Use3A2000 ? ", Use3A2000" : ""));
    1.37 +              (Use3A2000      ?  ", Use3A2000" : ""),
    1.38 +              UseSyncLevel);
    1.39  
    1.40    // buf is started with ", " or is empty
    1.41    _features_str = strdup(strlen(buf) > 2 ? buf + 2 : buf);
    1.42 @@ -178,7 +182,7 @@
    1.43  }
    1.44  
    1.45  void VM_Version::print_features() {
    1.46 -  tty->print_cr("Version:%s", cpu_features());
    1.47 +  tty->print_cr("Version: %s", cpu_features());
    1.48  }
    1.49  
    1.50  int VM_Version::determine_features() {
     2.1 --- a/src/cpu/mips/vm/vm_version_mips.hpp	Wed May 08 17:57:33 2019 +0800
     2.2 +++ b/src/cpu/mips/vm/vm_version_mips.hpp	Tue May 28 16:35:59 2019 +0800
     2.3 @@ -1,6 +1,6 @@
     2.4  /*
     2.5   * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 - * Copyright (c) 2015, 2017, Loongson Technology. All rights reserved.
     2.7 + * Copyright (c) 2015, 2019, Loongson Technology. All rights reserved.
     2.8   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.9   *
    2.10   * This code is free software; you can redistribute it and/or modify it
    2.11 @@ -57,6 +57,24 @@
    2.12      //////////////////////add some other feature here//////////////////
    2.13    };
    2.14  
    2.15 +  enum Loongson_Family {
    2.16 +    L_3A1000    = 0,
    2.17 +    L_3B1500    = 1,
    2.18 +    L_3A2000    = 2,
    2.19 +    L_3B2000    = 3,
    2.20 +    L_3A3000    = 4,
    2.21 +    L_3B3000    = 5,
    2.22 +    L_2K1000    = 6,
    2.23 +    L_3A4000    = 7,
    2.24 +    L_3B4000    = 8,
    2.25 +    L_UNKNOWN   = 9
    2.26 +  };
    2.27 +
    2.28 +  struct Loongson_Cpuinfo {
    2.29 +    Loongson_Family    id;
    2.30 +    const char* const  match_str;
    2.31 +  };
    2.32 +
    2.33    static int  _features;
    2.34    static const char* _features_str;
    2.35  
     3.1 --- a/src/os_cpu/linux_mips/vm/vm_version_linux_mips.cpp	Wed May 08 17:57:33 2019 +0800
     3.2 +++ b/src/os_cpu/linux_mips/vm/vm_version_linux_mips.cpp	Tue May 28 16:35:59 2019 +0800
     3.3 @@ -1,6 +1,6 @@
     3.4  /*
     3.5   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
     3.6 - * Copyright (c) 2015, 2018, Loongson Technology. All rights reserved.
     3.7 + * Copyright (c) 2015, 2019, Loongson Technology. All rights reserved.
     3.8   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.9   *
    3.10   * This code is free software; you can redistribute it and/or modify it
    3.11 @@ -28,18 +28,6 @@
    3.12  #include "vm_version_mips.hpp"
    3.13  #include "string.h"
    3.14  #include "ctype.h"
    3.15 -#define CPU_FAMILY_AMOUNT 8
    3.16 -
    3.17 -const char cpuinfo[CPU_FAMILY_AMOUNT][20] = {
    3.18 -  "not loongson",
    3.19 -  "3a2000",
    3.20 -  "3a3000",
    3.21 -  "3b2000",
    3.22 -  "3b3000",
    3.23 -  "loongson-3a",
    3.24 -  "loongson-3b",
    3.25 -  "2k1000"
    3.26 -};
    3.27  
    3.28  void read_cpu_info(const char *path, char *result) {
    3.29    FILE *ptr;
    3.30 @@ -70,42 +58,85 @@
    3.31    read_cpu_info("/proc/cpuinfo", res);
    3.32    // res is converted to lower case
    3.33    strlwr(res);
    3.34 -  for (i = 1; i < CPU_FAMILY_AMOUNT; i++) {
    3.35 -    if (strstr(res, cpuinfo[i])) {
    3.36 -      // 3A1000 and 3B1500 need further comparsion
    3.37 -      // test PRID REV in /proc/cpuinfo
    3.38 -      // 3A1000: V0.5
    3.39 -      // 3B1500: V0.7
    3.40 -      if (strcmp(cpuinfo[i], "loongson-3a") == 0 && strstr(res, "v0.5")) {
    3.41 -        break;
    3.42 -      } else if (strcmp(cpuinfo[i], "loongson-3b") == 0 && strstr(res, "v0.7")) {
    3.43 -        break;
    3.44 -      } else {
    3.45 -        break;
    3.46 +
    3.47 +  if (strstr(res, "loongson")) {
    3.48 +    // Loongson CPU
    3.49 +    features |= with_gs_support_m;
    3.50 +
    3.51 +    const struct Loongson_Cpuinfo loongson_cpuinfo[] = {
    3.52 +      {L_3A1000,  "3a1000"},
    3.53 +      {L_3B1500,  "3b1500"},
    3.54 +      {L_3A2000,  "3a2000"},
    3.55 +      {L_3B2000,  "3b2000"},
    3.56 +      {L_3A3000,  "3a3000"},
    3.57 +      {L_3B3000,  "3b3000"},
    3.58 +      {L_2K1000,  "2k1000"},
    3.59 +      {L_3A4000,  "3a4000"},
    3.60 +      {L_3B4000,  "3b4000"},
    3.61 +      {L_UNKNOWN, "unknown"}
    3.62 +    };
    3.63 +
    3.64 +    // Loongson Family
    3.65 +    int detected = 0;
    3.66 +    for (i = 0; i <= L_UNKNOWN; i++) {
    3.67 +      switch (i) {
    3.68 +        // 3A1000 and 3B1500 may use an old kernel and further comparsion is needed
    3.69 +        // test PRID REV in /proc/cpuinfo
    3.70 +        // 3A1000: V0.5, model name: ICT Loongson-3A V0.5  FPU V0.1
    3.71 +        // 3B1500: V0.7, model name: ICT Loongson-3B V0.7  FPU V0.1
    3.72 +        case L_3A1000:
    3.73 +          if (strstr(res, loongson_cpuinfo[i].match_str) || strstr(res, "loongson-3a v0.5")) {
    3.74 +            features |= gs464_m;
    3.75 +            detected++;
    3.76 +            //tty->print_cr("3A1000 platform");
    3.77 +          }
    3.78 +          break;
    3.79 +        case L_3B1500:
    3.80 +          if (strstr(res, loongson_cpuinfo[i].match_str) || strstr(res, "loongson-3b v0.7")) {
    3.81 +            features |= gs464_m;
    3.82 +            detected++;
    3.83 +            //tty->print_cr("3B1500 platform");
    3.84 +          }
    3.85 +          break;
    3.86 +        case L_3A2000:
    3.87 +        case L_3B2000:
    3.88 +        case L_3A3000:
    3.89 +        case L_3B3000:
    3.90 +          if (strstr(res, loongson_cpuinfo[i].match_str)) {
    3.91 +            features |= gs464e_m;
    3.92 +            detected++;
    3.93 +            //tty->print_cr("3A2000/3A3000/3B2000/3B3000 platform");
    3.94 +          }
    3.95 +          break;
    3.96 +        case L_2K1000:
    3.97 +          if (strstr(res, loongson_cpuinfo[i].match_str)) {
    3.98 +            features |= gs264_m;
    3.99 +            detected++;
   3.100 +            //tty->print_cr("2K1000 platform");
   3.101 +          }
   3.102 +          break;
   3.103 +        case L_3A4000:
   3.104 +        case L_3B4000:
   3.105 +          if (strstr(res, loongson_cpuinfo[i].match_str)) {
   3.106 +            features |= gs464v_m;
   3.107 +            detected++;
   3.108 +            //tty->print_cr("3A4000/3B4000 platform");
   3.109 +          }
   3.110 +          break;
   3.111 +        case L_UNKNOWN:
   3.112 +          if (detected == 0) {
   3.113 +            detected++;
   3.114 +            //tty->print_cr("unknown Loongson platform");
   3.115 +          }
   3.116 +          break;
   3.117 +        default:
   3.118 +          ShouldNotReachHere();
   3.119        }
   3.120      }
   3.121 -  }
   3.122 -  //add some other support when detected on loongson
   3.123 -  if (i != CPU_FAMILY_AMOUNT) {
   3.124 -    features |= with_gs_support_m;
   3.125 -  }
   3.126 -  switch (i % CPU_FAMILY_AMOUNT) {
   3.127 -    case 1 :
   3.128 -    case 2 :
   3.129 -    case 3 :
   3.130 -    case 4 :
   3.131 -      features |= gs464e_m;
   3.132 -      //tty->print_cr("3A2000/3A3000/3B2000/3B3000 platform");
   3.133 -      break;
   3.134 -    case 5 :
   3.135 -    case 6 :
   3.136 -      features |= gs464_m;
   3.137 -      //tty->print_cr("3A1000/3B1500 platform");
   3.138 -      break;
   3.139 -    case 7 :
   3.140 -      features |= gs264_m;
   3.141 -      //tty->print_cr("2K1000 platform");
   3.142 -      break;
   3.143 +    assert (detected == 1, "one and only one of LOONGSON_CPU_FAMILY should be detected");
   3.144 +  } else { // not Loongson
   3.145 +    // Not Loongson CPU
   3.146 +    //tty->print_cr("MIPS platform");
   3.147    }
   3.148    return features;
   3.149  }

mercurial