[hackers] [slstatus] consistent calculation of ram_* on openbsd || Tobias Tschinkowitz

From: <git_AT_suckless.org>
Date: Wed, 16 May 2018 12:25:33 +0200 (CEST)

commit 82eb6e3832dea63be4c22ac4415c3190add43f0b
Author: Tobias Tschinkowitz <he4d_AT_posteo.de>
AuthorDate: Wed May 16 09:57:38 2018 +0200
Commit: Aaron Marcher <me_AT_drkhsh.at>
CommitDate: Wed May 16 12:24:43 2018 +0200

    consistent calculation of ram_* on openbsd

diff --git a/components/ram.c b/components/ram.c
index 1178837..57081d2 100644
--- a/components/ram.c
+++ b/components/ram.c
_AT_@ -60,6 +60,7 @@
         #include <unistd.h>
 
         #define LOG1024 10
+ #define pagetok(size, pageshift) ((size) << (pageshift - LOG1024))
 
         inline int
         load_uvmexp(struct uvmexp *uvmexp)
_AT_@ -81,7 +82,7 @@
 
                 if (load_uvmexp(&uvmexp)) {
                         free_pages = uvmexp.npages - uvmexp.active;
- free = (float)(free_pages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024;
+ free = (float)(pagetok(free_pages, uvmexp.pageshift)) / 1024 / 1024;
                         return bprintf("%f", free);
                 }
 
_AT_@ -109,7 +110,7 @@
                 float total;
 
                 if (load_uvmexp(&uvmexp)) {
- total = (float)(uvmexp.npages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024;
+ total = (float)(pagetok(uvmexp.npages, uvmexp.pageshift)) / 1024 / 1024;
                         return bprintf("%f", total);
                 }
 
_AT_@ -123,8 +124,7 @@
                 float used;
 
                 if (load_uvmexp(&uvmexp)) {
- used = (double) (uvmexp.active * uvmexp.pagesize) /
- 1024 / 1024 / 1024;
+ used = (float)(pagetok(uvmexp.active, uvmexp.pageshift)) / 1024 / 1024;
                         return bprintf("%f", used);
                 }
 
Received on Wed May 16 2018 - 12:25:33 CEST

This archive was generated by hypermail 2.3.0 : Wed May 16 2018 - 12:36:24 CEST