Porting sys/sysinfo.h and asm/fcntl.h from Linux

I'm sure this has been asked before, but I've been looking at all the documentation, i.e. porting handbook, faqs, searching the forums for keywords and have turned up nothing. Is there an equivalent set of header files in FreeBSD? This code executes on several of the popular versions of Linux.
 
Code:
struct sysinfo {
        long uptime;             /* Seconds since boot */
        unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
        unsigned long totalram;  /* Total usable main memory size */
        unsigned long freeram;   /* Available memory size */
        unsigned long sharedram; /* Amount of shared memory */
        unsigned long bufferram; /* Memory used by buffers */
        unsigned long totalswap; /* Total swap space size */
        unsigned long freeswap;  /* swap space still available */
        unsigned short procs;    /* Number of current processes */
        unsigned long totalhigh; /* Total high memory size */
        unsigned long freehigh;  /* Available high memory size */
        unsigned int mem_unit;   /* Memory unit size in bytes */
        char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
}

How are you suppose to calculate 1, 5 and 15 minute "load" average? Does FreeBSD kernel even log such things by default, cause no service ran by default caches such data.
 
expl said:
Code:
struct sysinfo {
        long uptime;             /* Seconds since boot */
        unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
        unsigned long totalram;  /* Total usable main memory size */
        unsigned long freeram;   /* Available memory size */
        unsigned long sharedram; /* Amount of shared memory */
        unsigned long bufferram; /* Memory used by buffers */
        unsigned long totalswap; /* Total swap space size */
        unsigned long freeswap;  /* swap space still available */
        unsigned short procs;    /* Number of current processes */
        unsigned long totalhigh; /* Total high memory size */
        unsigned long freehigh;  /* Available high memory size */
        unsigned int mem_unit;   /* Memory unit size in bytes */
        char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding for libc5 */
}

How are you suppose to calculate 1, 5 and 15 minute "load" average? Does FreeBSD kernel even log such things by default, cause no service ran by default caches such data.

getloadavg(3)
 
Quick port of it:

https://code.google.com/p/sysinfo-bsd/source/browse/

Data on structure and header file should be compatible with linux applications.

To download the source install devel/mercurial and type
hg clone [url]https://sysinfo-bsd.googlecode.com/hg/[/url] sysinfo-bsd
Will be fetched to ./sysinfo-bsd/

I am only lost with what exactly is "high memory" in the structure (HMA? kernel reserved ram? ..?)

If anyone is interested in actual FreeBSD port for this lib let me know.
 
Regarding asm/fcntl.h, it has linux kernel specific definitions so there is no reason to port it. After looking at sys_basher source code it does not look like it even needs it included. Ill try to build it when I have some free time.
 
Turns out it also needs libsensors that runs only with linux kernel. And it would be a big task to port it. It would be easer to write a big patch for sysbasher.
 
Ok I compiled it without sensor support and it seems to run (dont have linux box to see if it runs the same).

You need to change all
Code:
#include <asm/fcntl.h>
to
Code:
#include <fcntl.h>

Comment out "open()" declaration in sys_disk.h

And I attached the Makefile patch. Just run "gmake" and ignore all the warnings. (might want to clean up it more, I just changed it enough to compile the application)

It also depends on libsysinfo, just install it from my google code repo. (make & make install)
 

Attachments

  • makefile.diff
    1.7 KB · Views: 286
Thanks for all your help! It compiles and runs successfully. Will that sysinfo library remain at that link?
 
Back
Top