Clean up some code

This commit is contained in:
Justine Tunney 2023-10-11 11:45:31 -07:00
parent ec3275179f
commit 285c565051
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
33 changed files with 122 additions and 382 deletions

View file

@ -29,10 +29,17 @@
#include "libc/sysv/errfuns.h"
#define CTL_KERN 1
#define CTL_VM 2
#define CTL_HW 6
#define VM_LOADAVG 2
#define KERN_BOOTTIME 21
#define HW_PHYSMEM (IsXnu() ? 24 : 5)
struct loadavg {
uint32_t ldavg[3];
int64_t fscale;
};
static int64_t GetUptime(void) {
if (IsNetbsd()) return 0; // TODO(jart): Why?
struct timeval x;
@ -50,7 +57,20 @@ static int64_t GetPhysmem(void) {
return x;
}
static void GetLoads(uint64_t loads[3]) {
size_t size;
struct loadavg loadinfo;
int mib[2] = {CTL_VM, VM_LOADAVG};
size = sizeof(loadinfo);
if (sys_sysctl(mib, 2, &loadinfo, &size, 0, 0) != -1) {
for (int i = 0; i < 3; i++) {
loads[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale * 65536;
}
}
}
static int sys_sysinfo_bsd(struct sysinfo *info) {
GetLoads(info->loads);
info->uptime = GetUptime();
info->totalram = GetPhysmem();
info->bufferram = GetPhysmem();