Skip to content

Commit 9086f8c

Browse files
Yadong WangRealFYang
authored andcommitted
8278890: riscv: Missing features string in VM_Version
Reviewed-by: fyang
1 parent a7e7183 commit 9086f8c

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

src/hotspot/cpu/riscv/vm_version_riscv.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232

3333
#include OS_HEADER_INLINE(os)
3434

35+
const char* VM_Version::_uarch = "";
3536
uint32_t VM_Version::_initial_vector_length = 0;
3637

37-
void VM_Version::get_processor_features() {
38+
void VM_Version::initialize() {
39+
get_os_cpu_info();
40+
3841
if (FLAG_IS_DEFAULT(UseFMA)) {
3942
FLAG_SET_DEFAULT(UseFMA, true);
4043
}
@@ -117,13 +120,23 @@ void VM_Version::get_processor_features() {
117120
FLAG_SET_DEFAULT(AvoidUnalignedAccesses, true);
118121
}
119122

123+
char buf[512];
124+
buf[0] = '\0';
125+
if (_uarch != NULL && strcmp(_uarch, "") != 0) snprintf(buf, sizeof(buf), "%s,", _uarch);
126+
strcat(buf, "rv64");
127+
#define ADD_FEATURE_IF_SUPPORTED(id, name, bit) if (_features & CPU_##id) strcat(buf, name);
128+
CPU_FEATURE_FLAGS(ADD_FEATURE_IF_SUPPORTED)
129+
#undef ADD_FEATURE_IF_SUPPORTED
130+
131+
_features_string = os::strdup(buf);
132+
120133
#ifdef COMPILER2
121-
get_c2_processor_features();
134+
initialize_c2();
122135
#endif // COMPILER2
123136
}
124137

125138
#ifdef COMPILER2
126-
void VM_Version::get_c2_processor_features() {
139+
void VM_Version::initialize_c2() {
127140
// lack of cmove in riscv64
128141
if (UseCMoveUnconditionally) {
129142
FLAG_SET_DEFAULT(UseCMoveUnconditionally, false);
@@ -164,11 +177,6 @@ void VM_Version::get_c2_processor_features() {
164177
}
165178
#endif // COMPILER2
166179

167-
void VM_Version::initialize() {
168-
get_cpu_info();
169-
get_processor_features();
170-
}
171-
172180
void VM_Version::initialize_cpu_information(void) {
173181
// do nothing if cpu info has been initialized
174182
if (_initialized) {

src/hotspot/cpu/riscv/vm_version_riscv.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
class VM_Version : public Abstract_VM_Version {
3636
#ifdef COMPILER2
3737
private:
38-
static void get_c2_processor_features();
38+
static void initialize_c2();
3939
#endif // COMPILER2
4040

4141
protected:
42+
static const char* _uarch;
4243
static uint32_t _initial_vector_length;
43-
static void get_processor_features();
44-
static void get_cpu_info();
44+
static void get_os_cpu_info();
4545
static uint32_t get_current_vector_length();
4646

4747
public:
@@ -53,14 +53,14 @@ class VM_Version : public Abstract_VM_Version {
5353

5454
enum Feature_Flag {
5555
#define CPU_FEATURE_FLAGS(decl) \
56-
decl(I, "I", 8) \
57-
decl(M, "M", 12) \
58-
decl(A, "A", 0) \
59-
decl(F, "F", 5) \
60-
decl(D, "D", 3) \
61-
decl(C, "C", 2) \
62-
decl(V, "V", 21) \
63-
decl(B, "B", 1)
56+
decl(I, "i", 8) \
57+
decl(M, "m", 12) \
58+
decl(A, "a", 0) \
59+
decl(F, "f", 5) \
60+
decl(D, "d", 3) \
61+
decl(C, "c", 2) \
62+
decl(V, "v", 21) \
63+
decl(B, "b", 1)
6464

6565
#define DECLARE_CPU_FEATURE_FLAG(id, name, bit) CPU_##id = (1 << bit),
6666
CPU_FEATURE_FLAGS(DECLARE_CPU_FEATURE_FLAG)

src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ uint32_t VM_Version::get_current_vector_length() {
7979
return (uint32_t)read_csr(CSR_VLENB);
8080
}
8181

82-
void VM_Version::get_cpu_info() {
82+
void VM_Version::get_os_cpu_info() {
8383

8484
uint64_t auxv = getauxval(AT_HWCAP);
8585

@@ -100,4 +100,19 @@ void VM_Version::get_cpu_info() {
100100
HWCAP_ISA_C |
101101
HWCAP_ISA_V |
102102
HWCAP_ISA_B);
103+
104+
if (FILE *f = fopen("/proc/cpuinfo", "r")) {
105+
char buf[512], *p;
106+
while (fgets(buf, sizeof (buf), f) != NULL) {
107+
if ((p = strchr(buf, ':')) != NULL) {
108+
if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) {
109+
char* uarch = os::strdup(p + 2);
110+
uarch[strcspn(uarch, "\n")] = '\0';
111+
_uarch = uarch;
112+
break;
113+
}
114+
}
115+
}
116+
fclose(f);
117+
}
103118
}

0 commit comments

Comments
 (0)