diff options
| author | Ron Yorston <rmy@pobox.com> | 2021-02-19 13:10:06 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2021-02-19 13:10:06 +0000 |
| commit | 5369ddc1db797a96cced91bd467d172d41d41f9d (patch) | |
| tree | e23a4a4d60c911dee512185cd4bc98429ebe0d1a | |
| parent | b4fcd6e378f30ffa36a87617d4c9e6113f70308d (diff) | |
| download | busybox-w32-5369ddc1db797a96cced91bd467d172d41d41f9d.tar.gz busybox-w32-5369ddc1db797a96cced91bd467d172d41d41f9d.tar.bz2 busybox-w32-5369ddc1db797a96cced91bd467d172d41d41f9d.zip | |
win32: update sysinfo(2) implementation
Add a call to GetPerformanceInfo. Treat the SystemCache member of
the PERFORMANCE_INFORMATION structure as buffer RAM. Deduct it
from available RAM.
The numbers reported by 'free' move about in vaguely sensible
ways when I start and stop programs, though I still don't know
if they're in any way accurate.
| -rw-r--r-- | include/mingw.h | 2 | ||||
| -rw-r--r-- | win32/mingw.c | 36 |
2 files changed, 23 insertions, 15 deletions
diff --git a/include/mingw.h b/include/mingw.h index c2a8b61bf..5cb5cb88c 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
| @@ -364,8 +364,6 @@ struct sysinfo { | |||
| 364 | unsigned long totalhigh; /* Total high memory size */ | 364 | unsigned long totalhigh; /* Total high memory size */ |
| 365 | unsigned long freehigh; /* Available high memory size */ | 365 | unsigned long freehigh; /* Available high memory size */ |
| 366 | unsigned int mem_unit; /* Memory unit size in bytes */ | 366 | unsigned int mem_unit; /* Memory unit size in bytes */ |
| 367 | char _f[20-2*sizeof(long)-sizeof(int)]; | ||
| 368 | /* Padding to 64 bytes */ | ||
| 369 | }; | 367 | }; |
| 370 | 368 | ||
| 371 | int sysinfo(struct sysinfo *info); | 369 | int sysinfo(struct sysinfo *info); |
diff --git a/win32/mingw.c b/win32/mingw.c index ddc64b43a..73179dac9 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <aclapi.h> | 5 | #include <aclapi.h> |
| 6 | #endif | 6 | #endif |
| 7 | #include <ntdef.h> | 7 | #include <ntdef.h> |
| 8 | #include <psapi.h> | ||
| 8 | 9 | ||
| 9 | #if defined(__MINGW64_VERSION_MAJOR) | 10 | #if defined(__MINGW64_VERSION_MAJOR) |
| 10 | #if ENABLE_GLOBBING | 11 | #if ENABLE_GLOBBING |
| @@ -1371,25 +1372,34 @@ int mingw_unlink(const char *pathname) | |||
| 1371 | int sysinfo(struct sysinfo *info) | 1372 | int sysinfo(struct sysinfo *info) |
| 1372 | { | 1373 | { |
| 1373 | DECLARE_PROC_ADDR(BOOL, GlobalMemoryStatusEx, LPMEMORYSTATUSEX); | 1374 | DECLARE_PROC_ADDR(BOOL, GlobalMemoryStatusEx, LPMEMORYSTATUSEX); |
| 1375 | DECLARE_PROC_ADDR(BOOL, GetPerformanceInfo, PPERFORMANCE_INFORMATION, DWORD); | ||
| 1374 | MEMORYSTATUSEX mem; | 1376 | MEMORYSTATUSEX mem; |
| 1377 | PERFORMANCE_INFORMATION perf; | ||
| 1375 | 1378 | ||
| 1376 | memset((void *)info, 0, sizeof(struct sysinfo)); | 1379 | memset((void *)info, 0, sizeof(struct sysinfo)); |
| 1377 | 1380 | memset((void *)&perf, 0, sizeof(PERFORMANCE_INFORMATION)); | |
| 1378 | if (!INIT_PROC_ADDR(kernel32.dll, GlobalMemoryStatusEx)) { | 1381 | info->mem_unit = 4096; |
| 1379 | return -1; | 1382 | |
| 1383 | if (INIT_PROC_ADDR(psapi.dll, GetPerformanceInfo)) { | ||
| 1384 | perf.cb = sizeof(PERFORMANCE_INFORMATION); | ||
| 1385 | GetPerformanceInfo(&perf, perf.cb); | ||
| 1386 | } | ||
| 1387 | |||
| 1388 | if (INIT_PROC_ADDR(kernel32.dll, GlobalMemoryStatusEx)) { | ||
| 1389 | mem.dwLength = sizeof(MEMORYSTATUSEX); | ||
| 1390 | if (GlobalMemoryStatusEx(&mem)) { | ||
| 1391 | info->totalram = mem.ullTotalPhys >> 12; | ||
| 1392 | info->bufferram = (perf.SystemCache * perf.PageSize) >> 12; | ||
| 1393 | if ((mem.ullAvailPhys >> 12) > info->bufferram) | ||
| 1394 | info->freeram = (mem.ullAvailPhys >> 12) - info->bufferram; | ||
| 1395 | info->totalswap = (mem.ullTotalPageFile - mem.ullTotalPhys) >> 12; | ||
| 1396 | if (mem.ullAvailPageFile > mem.ullAvailPhys) | ||
| 1397 | info->freeswap = (mem.ullAvailPageFile-mem.ullAvailPhys) >> 12; | ||
| 1398 | } | ||
| 1380 | } | 1399 | } |
| 1381 | 1400 | ||
| 1382 | mem.dwLength = sizeof(MEMORYSTATUSEX); | ||
| 1383 | if (!GlobalMemoryStatusEx(&mem)) | ||
| 1384 | return -1; | ||
| 1385 | |||
| 1386 | info->mem_unit = 1; | ||
| 1387 | info->totalram = mem.ullTotalPhys; | ||
| 1388 | info->freeram = mem.ullAvailPhys; | ||
| 1389 | info->totalswap = mem.ullTotalPageFile - mem.ullTotalPhys; | ||
| 1390 | info->freeswap = mem.ullAvailPageFile - mem.ullAvailPhys; | ||
| 1391 | |||
| 1392 | info->uptime = GetTickCount64() / 1000; | 1401 | info->uptime = GetTickCount64() / 1000; |
| 1402 | info->procs = perf.ProcessCount; | ||
| 1393 | 1403 | ||
| 1394 | return 0; | 1404 | return 0; |
| 1395 | } | 1405 | } |
