Skip to content

Commit

Permalink
BSD: switch to use sysctl in OpenBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Jan 30, 2024
1 parent a735835 commit 12463ba
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions src/StelLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void StelLogger::init(const QString& logFilePath)

#endif

#if defined Q_OS_BSD4 && !defined Q_OS_MACOS
#if defined Q_OS_FREEBSD || defined Q_OS_NETBSD && !defined Q_OS_MACOS
const char* _model = "hw.model";
const char* _freq = "machdep.tsc_freq";
const char* _ncpu = "hw.ncpu";
Expand All @@ -299,31 +299,17 @@ void StelLogger::init(const QString& logFilePath)
_physmem = "hw.physmem64";
#endif

#ifdef Q_OS_OPENBSD
_freq = "hw.cpuspeed";
#if defined(HW_PHYSMEM64)
_physmem = "hw.physmem64";
#endif
#endif

// CPU info
size_t len = 0;
sysctlbyname(_model, nullptr, &len, nullptr, 0);
std::string model(len, '\0');
sysctlbyname(_model, const_cast<char *>(model.data()), &len, nullptr, 0);
writeLog(QString("Processor name: %1").arg(model.data()));

#ifdef Q_OS_OPENBSD
int freq = 0;
len = sizeof(freq);
sysctlbyname(_freq, &freq, &len, nullptr, 0);
writeLog(QString("Processor speed: %1 MHz").arg(freq));
#else
int64_t freq = 0;
len = sizeof(freq);
sysctlbyname(_freq, &freq, &len, nullptr, 0);
writeLog(QString("Processor speed: %1 MHz").arg(freq/1000000));
#endif

int ncpu = 0;
len = sizeof(ncpu);
Expand All @@ -337,6 +323,42 @@ void StelLogger::init(const QString& logFilePath)
writeLog(QString("Total physical memory: %1 MB").arg(totalRAM/(1024<<10)));
#endif

#ifdef Q_OS_OPENBSD
int mib[2], freq, ncpu;
size_t len;
const char* model;

mib[0] = CTL_HW;
mib[1] = HW_MODEL;
len = sizeof(freq);
sysctl(mib, 2, model.data(), &len, NULL, 0);
writeLog(QString("Processor name: %1").arg(model.data()));

mib[0] = CTL_HW;
mib[1] = HW_CPUSPEED;
len = sizeof(freq);
sysctl(mib, 2, &freq, &len, NULL, 0);
writeLog(QString("Processor speed: %1 MHz").arg(freq));

mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(ncpu);
sysctl(mib, 2, &ncpu, &len, NULL, 0);
writeLog(QString("Processor logical cores: %1").arg(ncpu));

mib[0] = CTL_HW;
#if defined(HW_PHYSMEM64)
mib[1] = HW_PHYSMEM64;
int64_t totalRAM = 0;
#else
mib[1] = HW_PHYSMEM;
int totalRAM = 0;
#endif
len = sizeof(totalRAM);
sysctl(mib, 2, &totalRAM, &len, NULL, 0);
writeLog(QString("Total physical memory: %1 MB").arg(totalRAM/(1024<<10)));
#endif

#ifdef Q_OS_SOLARIS
processor_info_t pinfo;
processor_info(0, &pinfo);
Expand Down

0 comments on commit 12463ba

Please sign in to comment.