comparison src/os_cpu/solaris_sparc/vm/vm_version_solaris_sparc.cpp @ 2080:c04052fd6ae1

7006505: Use kstat info to identify SPARC processor Summary: read Solaris kstat data to get more precise CPU information Reviewed-by: iveresov, never, twisti, dholmes
author kvn
date Thu, 16 Dec 2010 14:15:12 -0800
parents f95d63e2154a
children c52cba2a3359
comparison
equal deleted inserted replaced
2079:cccd1b172b85 2080:c04052fd6ae1
27 #include "vm_version_sparc.hpp" 27 #include "vm_version_sparc.hpp"
28 28
29 # include <sys/auxv.h> 29 # include <sys/auxv.h>
30 # include <sys/auxv_SPARC.h> 30 # include <sys/auxv_SPARC.h>
31 # include <sys/systeminfo.h> 31 # include <sys/systeminfo.h>
32 # include <kstat.h>
32 33
33 // We need to keep these here as long as we have to build on Solaris 34 // We need to keep these here as long as we have to build on Solaris
34 // versions before 10. 35 // versions before 10.
35 #ifndef SI_ARCHITECTURE_32 36 #ifndef SI_ARCHITECTURE_32
36 #define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */ 37 #define SI_ARCHITECTURE_32 516 /* basic 32-bit SI_ARCHITECTURE */
94 // Next values are not defined before Solaris 10 95 // Next values are not defined before Solaris 10
95 // but Solaris 8 is used for jdk6 update builds. 96 // but Solaris 8 is used for jdk6 update builds.
96 #ifndef AV_SPARC_ASI_BLK_INIT 97 #ifndef AV_SPARC_ASI_BLK_INIT
97 #define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */ 98 #define AV_SPARC_ASI_BLK_INIT 0x0080 /* ASI_BLK_INIT_xxx ASI */
98 #endif 99 #endif
100 if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m;
101
99 #ifndef AV_SPARC_FMAF 102 #ifndef AV_SPARC_FMAF
100 #define AV_SPARC_FMAF 0x0100 /* Sparc64 Fused Multiply-Add */ 103 #define AV_SPARC_FMAF 0x0100 /* Fused Multiply-Add */
101 #endif 104 #endif
102 if (av & AV_SPARC_ASI_BLK_INIT) features |= blk_init_instructions_m;
103 if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m; 105 if (av & AV_SPARC_FMAF) features |= fmaf_instructions_m;
106
107 #ifndef AV_SPARC_FMAU
108 #define AV_SPARC_FMAU 0x0200 /* Unfused Multiply-Add */
109 #endif
110 if (av & AV_SPARC_FMAU) features |= fmau_instructions_m;
111
112 #ifndef AV_SPARC_VIS3
113 #define AV_SPARC_VIS3 0x0400 /* VIS3 instruction set extensions */
114 #endif
115 if (av & AV_SPARC_VIS3) features |= vis3_instructions_m;
116
104 } else { 117 } else {
105 // getisax(2) failed, use the old legacy code. 118 // getisax(2) failed, use the old legacy code.
106 #ifndef PRODUCT 119 #ifndef PRODUCT
107 if (PrintMiscellaneous && Verbose) 120 if (PrintMiscellaneous && Verbose)
108 tty->print_cr("getisax(2) is not supported."); 121 tty->print_cr("getisax(2) is not supported.");
138 } 151 }
139 152
140 // Determine the machine type. 153 // Determine the machine type.
141 do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m); 154 do_sysinfo(SI_MACHINE, "sun4v", &features, sun4v_m);
142 155
156 {
157 // Using kstat to determine the machine type.
158 kstat_ctl_t* kc = kstat_open();
159 kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, NULL);
160 const char* implementation = "UNKNOWN";
161 if (ksp != NULL) {
162 if (kstat_read(kc, ksp, NULL) != -1 && ksp->ks_data != NULL) {
163 kstat_named_t* knm = (kstat_named_t *)ksp->ks_data;
164 for (int i = 0; i < ksp->ks_ndata; i++) {
165 if (strcmp((const char*)&(knm[i].name),"implementation") == 0) {
166 #ifndef KSTAT_DATA_STRING
167 #define KSTAT_DATA_STRING 9
168 #endif
169 if (knm[i].data_type == KSTAT_DATA_CHAR) {
170 // VM is running on Solaris 8 which does not have value.str.
171 implementation = &(knm[i].value.c[0]);
172 } else if (knm[i].data_type == KSTAT_DATA_STRING) {
173 // VM is running on Solaris 10.
174 #ifndef KSTAT_NAMED_STR_PTR
175 // Solaris 8 was used to build VM, define the structure it misses.
176 struct str_t {
177 union {
178 char *ptr; /* NULL-term string */
179 char __pad[8]; /* 64-bit padding */
180 } addr;
181 uint32_t len; /* # bytes for strlen + '\0' */
182 };
183 #define KSTAT_NAMED_STR_PTR(knptr) (( (str_t*)&((knptr)->value) )->addr.ptr)
184 #endif
185 implementation = KSTAT_NAMED_STR_PTR(&knm[i]);
186 }
187 #ifndef PRODUCT
188 if (PrintMiscellaneous && Verbose) {
189 tty->print_cr("cpu_info.implementation: %s", implementation);
190 }
191 #endif
192 if (strncmp(implementation, "SPARC64", 7) == 0) {
193 features |= sparc64_family_m;
194 } else if (strncmp(implementation, "UltraSPARC-T", 12) == 0) {
195 features |= T_family_m;
196 if (strncmp(implementation, "UltraSPARC-T1", 13) == 0) {
197 features |= T1_model_m;
198 }
199 }
200 break;
201 }
202 } // for(
203 }
204 }
205 assert(strcmp(implementation, "UNKNOWN") != 0,
206 "unknown cpu info (changed kstat interface?)");
207 kstat_close(kc);
208 }
209
143 return features; 210 return features;
144 } 211 }