sysinfo: switch to c++
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ StdBinCommands
|
|||||||
release.c
|
release.c
|
||||||
renice.c
|
renice.c
|
||||||
rescan.c
|
rescan.c
|
||||||
sysinfo.c
|
sysinfo.cpp
|
||||||
unchop.c
|
unchop.c
|
||||||
uptime.cpp
|
uptime.cpp
|
||||||
vmstat.cpp
|
vmstat.cpp
|
||||||
|
|||||||
@@ -143,12 +143,10 @@ struct cache_description {
|
|||||||
static void
|
static void
|
||||||
print_intel_cache_descriptors(enum cpu_types type, cpuid_info *info)
|
print_intel_cache_descriptors(enum cpu_types type, cpuid_info *info)
|
||||||
{
|
{
|
||||||
int i, j, maxDesc;
|
|
||||||
|
|
||||||
uint8 cacheDescriptors[15]; // Max
|
uint8 cacheDescriptors[15]; // Max
|
||||||
|
|
||||||
maxDesc = 0;
|
int maxDesc = 0;
|
||||||
i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// put valid values into array
|
// put valid values into array
|
||||||
if ((info->regs.eax & 0x80000000) == 0) {
|
if ((info->regs.eax & 0x80000000) == 0) {
|
||||||
@@ -187,11 +185,12 @@ print_intel_cache_descriptors(enum cpu_types type, cpuid_info *info)
|
|||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
for (i = 0; i < maxDesc; i++) {
|
for (int i = 0; i < maxDesc; i++) {
|
||||||
// ignore NULL descriptors
|
// ignore NULL descriptors
|
||||||
if (cacheDescriptors[i] == 0)
|
if (cacheDescriptors[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
int j;
|
||||||
for (j = 0; sIntelCacheDescriptions[j].code; j++) {
|
for (j = 0; sIntelCacheDescriptions[j].code; j++) {
|
||||||
if (cacheDescriptors[i] == sIntelCacheDescriptions[j].code) {
|
if (cacheDescriptors[i] == sIntelCacheDescriptions[j].code) {
|
||||||
if (cacheDescriptors[i] == 0x40) {
|
if (cacheDescriptors[i] == 0x40) {
|
||||||
@@ -217,17 +216,16 @@ print_intel_cache_descriptors(enum cpu_types type, cpuid_info *info)
|
|||||||
static void
|
static void
|
||||||
print_TLB(uint32 reg, const char *pages)
|
print_TLB(uint32 reg, const char *pages)
|
||||||
{
|
{
|
||||||
int num;
|
|
||||||
int entries[2];
|
int entries[2];
|
||||||
int ways[2];
|
int ways[2];
|
||||||
char *name[2] = { "Inst TLB", "Data TLB" };
|
const char *name[2] = { "Inst TLB", "Data TLB" };
|
||||||
|
|
||||||
entries[0] = (reg & 0xff);
|
entries[0] = (reg & 0xff);
|
||||||
ways[0] = ((reg >> 8) & 0xff);
|
ways[0] = ((reg >> 8) & 0xff);
|
||||||
entries[1] = ((reg >> 16) & 0xff);
|
entries[1] = ((reg >> 16) & 0xff);
|
||||||
ways[1] = ((reg >> 24) & 0xff);
|
ways[1] = ((reg >> 24) & 0xff);
|
||||||
|
|
||||||
for (num = 0; num < 2; num++) {
|
for (int num = 0; num < 2; num++) {
|
||||||
printf("\t%s: %s%s%u entries, ", name[num],
|
printf("\t%s: %s%s%u entries, ", name[num],
|
||||||
pages ? pages : "", pages ? " pages, " : "", entries[num]);
|
pages ? pages : "", pages ? " pages, " : "", entries[num]);
|
||||||
|
|
||||||
@@ -301,28 +299,21 @@ static void
|
|||||||
print_intel_cache_desc(int32 cpu)
|
print_intel_cache_desc(int32 cpu)
|
||||||
{
|
{
|
||||||
cpuid_info info;
|
cpuid_info info;
|
||||||
uint32 type;
|
|
||||||
uint32 level;
|
|
||||||
bool isFullyAssoc;
|
|
||||||
uint32 lineSize;
|
|
||||||
uint32 linesPerTag;
|
|
||||||
uint32 ways;
|
|
||||||
uint32 sets;
|
|
||||||
|
|
||||||
// A second parameters needs to be passed to CPUID which determines the cache level to query
|
// A second parameters needs to be passed to CPUID which determines the cache level to query
|
||||||
get_cpuid(&info, 0x00000004, cpu);
|
get_cpuid(&info, 0x00000004, cpu);
|
||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
type = info.regs.eax & 0xf;
|
uint32 type = info.regs.eax & 0xf;
|
||||||
level = (info.regs.eax & 0x70) >> 4;
|
uint32 level = (info.regs.eax & 0x70) >> 4;
|
||||||
isFullyAssoc = info.regs.eax & 0x100;
|
bool isFullyAssoc = info.regs.eax & 0x100;
|
||||||
|
|
||||||
lineSize = (info.regs.ebx & 0xfff) + 1;
|
uint32 lineSize = (info.regs.ebx & 0xfff) + 1;
|
||||||
linesPerTag = ((info.regs.ebx & 0x3ff000) >> 12) + 1;
|
uint32 linesPerTag = ((info.regs.ebx & 0x3ff000) >> 12) + 1;
|
||||||
ways = ((info.regs.ebx & 0xffc00000) >> 22) + 1;
|
uint32 ways = ((info.regs.ebx & 0xffc00000) >> 22) + 1;
|
||||||
|
|
||||||
sets = info.regs.ecx;
|
uint32 sets = info.regs.ecx;
|
||||||
|
|
||||||
printf("\tL%ld ",level);
|
printf("\tL%ld ",level);
|
||||||
|
|
||||||
@@ -340,7 +331,7 @@ print_intel_cache_desc(int32 cpu)
|
|||||||
printf("%lu lines/tag, %lu bytes/line\n", linesPerTag, lineSize);
|
printf("%lu lines/tag, %lu bytes/line\n", linesPerTag, lineSize);
|
||||||
|
|
||||||
get_cpuid(&info, 0x80000006, cpu);
|
get_cpuid(&info, 0x80000006, cpu);
|
||||||
print_level2_cache(info.regs.ecx, "L2 cache");
|
print_level2_cache(sets, "L2 cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -361,11 +352,10 @@ print_amd_power_management_features(uint32 features)
|
|||||||
"TS", "FID", "VID", "TTP", "TM", "STC",
|
"TS", "FID", "VID", "TTP", "TM", "STC",
|
||||||
};
|
};
|
||||||
int32 found = 4;
|
int32 found = 4;
|
||||||
int32 i;
|
|
||||||
|
|
||||||
printf("\tPower Management Features:");
|
printf("\tPower Management Features:");
|
||||||
|
|
||||||
for (i = 0; i < 6; i++) {
|
for (int32 i = 0; i < 6; i++) {
|
||||||
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
||||||
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
||||||
found++;
|
found++;
|
||||||
@@ -391,9 +381,8 @@ print_amd_features(uint32 features)
|
|||||||
NULL, "FFXSTR", NULL, "RDTSCP", NULL, "64", "3DNow+", "3DNow!"
|
NULL, "FFXSTR", NULL, "RDTSCP", NULL, "64", "3DNow+", "3DNow!"
|
||||||
};
|
};
|
||||||
int32 found = 0;
|
int32 found = 0;
|
||||||
int32 i;
|
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (int32 i = 0; i < 32; i++) {
|
||||||
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
||||||
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
||||||
found++;
|
found++;
|
||||||
@@ -419,9 +408,8 @@ print_extended_features(uint32 features)
|
|||||||
NULL, "AES", "XSAVE", "OSXSAVE", NULL, NULL, NULL, NULL
|
NULL, "AES", "XSAVE", "OSXSAVE", NULL, NULL, NULL, NULL
|
||||||
};
|
};
|
||||||
int32 found = 0;
|
int32 found = 0;
|
||||||
int32 i;
|
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (int32 i = 0; i < 32; i++) {
|
||||||
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
||||||
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
||||||
found++;
|
found++;
|
||||||
@@ -451,9 +439,8 @@ print_features(uint32 features)
|
|||||||
"HTT", "TM", NULL, "PBE",
|
"HTT", "TM", NULL, "PBE",
|
||||||
};
|
};
|
||||||
int32 found = 0;
|
int32 found = 0;
|
||||||
int32 i;
|
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (int32 i = 0; i < 32; i++) {
|
||||||
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
if ((features & (1UL << i)) && kFeatures[i] != NULL) {
|
||||||
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
printf("%s%s", found == 0 ? "\t\t" : " ", kFeatures[i]);
|
||||||
found++;
|
found++;
|
||||||
@@ -476,7 +463,7 @@ print_processor_signature(system_info *sys_info, cpuid_info *info, const char *p
|
|||||||
{
|
{
|
||||||
|
|
||||||
if ((sys_info->cpu_type & B_CPU_x86_VENDOR_MASK) == B_CPU_AMD_x86) {
|
if ((sys_info->cpu_type & B_CPU_x86_VENDOR_MASK) == B_CPU_AMD_x86) {
|
||||||
printf("\t%s%sype %u, family %u, model %u, stepping %u, features 0x%08lx\n",
|
printf("\t%s%sype %lu, family %lu, model %u, stepping %lu, features 0x%08lx\n",
|
||||||
prefix ? prefix : "", prefix && prefix[0] ? "t" : "T",
|
prefix ? prefix : "", prefix && prefix[0] ? "t" : "T",
|
||||||
info->eax_1.type,
|
info->eax_1.type,
|
||||||
info->eax_1.family + (info->eax_1.family == 0xf ? info->eax_1.extended_family : 0),
|
info->eax_1.family + (info->eax_1.family == 0xf ? info->eax_1.extended_family : 0),
|
||||||
@@ -485,7 +472,7 @@ print_processor_signature(system_info *sys_info, cpuid_info *info, const char *p
|
|||||||
info->eax_1.features);
|
info->eax_1.features);
|
||||||
} else if ((sys_info->cpu_type & B_CPU_x86_VENDOR_MASK) == B_CPU_INTEL_x86) {
|
} else if ((sys_info->cpu_type & B_CPU_x86_VENDOR_MASK) == B_CPU_INTEL_x86) {
|
||||||
// model calculation is different for INTEL
|
// model calculation is different for INTEL
|
||||||
printf("\t%s%sype %u, family %u, model %u, stepping %u, features 0x%08lx\n",
|
printf("\t%s%sype %lu, family %lu, model %u, stepping %lu, features 0x%08lx\n",
|
||||||
prefix ? prefix : "", prefix && prefix[0] ? "t" : "T",
|
prefix ? prefix : "", prefix && prefix[0] ? "t" : "T",
|
||||||
info->eax_1.type,
|
info->eax_1.type,
|
||||||
info->eax_1.family + (info->eax_1.family == 0xf ? info->eax_1.extended_family : 0),
|
info->eax_1.family + (info->eax_1.family == 0xf ? info->eax_1.extended_family : 0),
|
||||||
@@ -521,34 +508,32 @@ dump_cpu(system_info *info, int32 cpu)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
cpuid_info baseInfo;
|
cpuid_info baseInfo;
|
||||||
cpuid_info cpuInfo;
|
|
||||||
int32 maxStandardFunction, maxExtendedFunction = 0;
|
|
||||||
|
|
||||||
if (get_cpuid(&baseInfo, 0, cpu) != B_OK) {
|
if (get_cpuid(&baseInfo, 0, cpu) != B_OK) {
|
||||||
// this CPU doesn't support cpuid
|
// this CPU doesn't support cpuid
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxStandardFunction = baseInfo.eax_0.max_eax;
|
int32 maxStandardFunction = baseInfo.eax_0.max_eax;
|
||||||
if (maxStandardFunction >= 500)
|
if (maxStandardFunction >= 500)
|
||||||
maxStandardFunction = 0; /* old Pentium sample chips has cpu signature here */
|
maxStandardFunction = 0; /* old Pentium sample chips has cpu signature here */
|
||||||
|
|
||||||
/* Extended cpuid */
|
/* Extended cpuid */
|
||||||
|
|
||||||
|
cpuid_info cpuInfo;
|
||||||
get_cpuid(&cpuInfo, 0x80000000, cpu);
|
get_cpuid(&cpuInfo, 0x80000000, cpu);
|
||||||
|
|
||||||
// extended cpuid is only supported if max_eax is greater than the service id
|
// extended cpuid is only supported if max_eax is greater than the service id
|
||||||
|
int32 maxExtendedFunction = 0;
|
||||||
if (cpuInfo.eax_0.max_eax > 0x80000000)
|
if (cpuInfo.eax_0.max_eax > 0x80000000)
|
||||||
maxExtendedFunction = cpuInfo.eax_0.max_eax & 0xff;
|
maxExtendedFunction = cpuInfo.eax_0.max_eax & 0xff;
|
||||||
|
|
||||||
if (maxExtendedFunction >=4 ) {
|
if (maxExtendedFunction >=4 ) {
|
||||||
char buffer[49];
|
char buffer[49];
|
||||||
char *name = buffer;
|
char *name = buffer;
|
||||||
int32 i;
|
|
||||||
|
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (int32 i = 0; i < 3; i++) {
|
||||||
cpuid_info nameInfo;
|
cpuid_info nameInfo;
|
||||||
get_cpuid(&nameInfo, 0x80000002 + i, cpu);
|
get_cpuid(&nameInfo, 0x80000002 + i, cpu);
|
||||||
|
|
||||||
@@ -653,7 +638,6 @@ dump_cpus(system_info *info)
|
|||||||
const char *vendor = get_cpu_vendor_string(info->cpu_type);
|
const char *vendor = get_cpu_vendor_string(info->cpu_type);
|
||||||
const char *model = get_cpu_model_string(info);
|
const char *model = get_cpu_model_string(info);
|
||||||
char modelString[32];
|
char modelString[32];
|
||||||
int32 cpu;
|
|
||||||
|
|
||||||
if (model == NULL && vendor == NULL)
|
if (model == NULL && vendor == NULL)
|
||||||
model = "(Unknown)";
|
model = "(Unknown)";
|
||||||
@@ -670,7 +654,7 @@ dump_cpus(system_info *info)
|
|||||||
info->id[0], info->id[1]);
|
info->id[0], info->id[1]);
|
||||||
|
|
||||||
#ifdef __INTEL__
|
#ifdef __INTEL__
|
||||||
for (cpu = 0; cpu < info->cpu_count; cpu++)
|
for (int32 cpu = 0; cpu < info->cpu_count; cpu++)
|
||||||
dump_cpu(info, cpu);
|
dump_cpu(info, cpu);
|
||||||
#endif // __INTEL__
|
#endif // __INTEL__
|
||||||
}
|
}
|
||||||
@@ -750,15 +734,12 @@ dump_system_info(system_info *info)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
system_info info;
|
|
||||||
const char *opt;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!is_computer_on()) {
|
if (!is_computer_on()) {
|
||||||
printf("The computer is not on! No info available\n");
|
printf("The computer is not on! No info available\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
system_info info;
|
||||||
if (get_system_info(&info) != B_OK) {
|
if (get_system_info(&info) != B_OK) {
|
||||||
printf("Error getting system information!\n");
|
printf("Error getting system information!\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -767,8 +748,8 @@ main(int argc, char *argv[])
|
|||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
dump_system_info(&info);
|
dump_system_info(&info);
|
||||||
} else {
|
} else {
|
||||||
for (i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
opt = argv[i];
|
const char *opt = argv[i];
|
||||||
if (strncmp(opt, "-id", strlen(opt)) == 0) {
|
if (strncmp(opt, "-id", strlen(opt)) == 0) {
|
||||||
/* note: the original also assumes this option on "sysinfo -" */
|
/* note: the original also assumes this option on "sysinfo -" */
|
||||||
printf("0x%.8lx 0x%.8lx\n", info.id[0], info.id[1]);
|
printf("0x%.8lx 0x%.8lx\n", info.id[0], info.id[1]);
|
||||||
Reference in New Issue
Block a user