OS2 World Community Forum
OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Mentore on September 25, 2024, 02:25:59 pm
-
Hiya all,
Trying to port NGSpice 4.2 (3.1 compiled just fine). Everything right until this:
get_avail_mem_size.c:26:2: error: #error "Unable to define getMemorySize( ) for an unknown OS."
Where can I find the definition of getMemorySize() under OS/2? Or should I try and clear this OS definition in configuring the environment?
TIA
Mentore
-
Looks like you will have to write an OS/2 get_avail_mem_size.
-
Looks like you will have to write an OS/2 get_avail_mem_size.
Oh, that may be actual fun :) guess I'll give it a go asap.
Mentore
-
#if defined(_WIN32)
#undef BOOLEAN
#include <windows.h>
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#if defined(BSD) && defined(HAVE_SYS_SYSCTL_H)
#include <sys/sysctl.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#import <mach/mach.h>
#import <mach/mach_host.h>
#endif
#elif defined(__OS2__)
#define INCL_BASE
#include <os2.h>
#else
#error "Unable to define getMemorySize( ) for an unknown OS."
#endif
...
unsigned long long getAvailableMemorySize(void)
{
...
#elif defined(__OS2__)
unsigned long mem_got;
if (NO_ERROR == DosQuerySysInfo(QSV_TOTAVAILMEM,QSV_TOTAVAILMEM,&mem_got,sizeof(mem_got)))
{
return (unsigned long long)mem_got;
}
return 0L;
...
-
Looks like you will have to write an OS/2 get_avail_mem_size.
Oh, that may be actual fun :) guess I'll give it a go asap.
Mentore
libc has that implemented since long. see https://github.com/bitwiseworks/libc/commit/1ee2ad15bb9db8f0a327ec6a3cf6c216d2004b8c
-
Looks like you will have to write an OS/2 get_avail_mem_size.
Oh, that may be actual fun :) guess I'll give it a go asap.
Mentore
libc has that implemented since long. see https://github.com/bitwiseworks/libc/commit/1ee2ad15bb9db8f0a327ec6a3cf6c216d2004b8c
The libc implementation returns size in pages whereas in this case it is supposed to be returned in bytes. But of course that is easy enough to take into account.
-
#if defined(_WIN32)
#undef BOOLEAN
#include <windows.h>
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#if defined(BSD) && defined(HAVE_SYS_SYSCTL_H)
#include <sys/sysctl.h>
#endif
#if defined(__APPLE__) && defined(__MACH__)
#import <mach/mach.h>
#import <mach/mach_host.h>
#endif
#elif defined(__OS2__)
#define INCL_BASE
#include <os2.h>
#else
#error "Unable to define getMemorySize( ) for an unknown OS."
#endif
...
unsigned long long getAvailableMemorySize(void)
{
...
#elif defined(__OS2__)
unsigned long mem_got;
if (NO_ERROR == DosQuerySysInfo(QSV_TOTAVAILMEM,QSV_TOTAVAILMEM,&mem_got,sizeof(mem_got)))
{
return (unsigned long long)mem_got;
}
return 0L;
...
You guys are invaluable 8)
It's compiling... Will let you know.
Mentore
-
You guys are invaluable 8)
It's compiling... Will let you know.
Mentore
Compiled. Had to circumvent other two problems though:
- In get_resident_set_size.c there are some calls to get the memory used by the process. I don't know if we have getrusage available, so I remembered processes on OS/2 were limited to 512MB and decided to return a fixed size of 400MB. I'm almost sure it's a stupid idea 8) but will try it. I have to search for getrusage in libc.
- BOOL is defined as unsigned int, conflicting with os2.h definition. Corrected.
- There was another reference to getMemorySize() in another .c file, also tackled this.
Now ngspice-42.exe is available under OS/2 as beta - will try and see if I can use rusage instead of reporting a fixed 400MB memory used by the process.
Mentore
-
Last update: yes, getrusage is available in our libc. Compiling it - will test this binary asap and - if it works as I expect - it's going to HobbesArchive.
Mentore
-
Last update: yes, getrusage is available in our libc. Compiling it - will test this binary asap and - if it works as I expect - it's going to HobbesArchive.
Mentore
Seems like our getrusage does not return any memory size information, only use of time ("ru_utime", "ru_stime").
I suspect this is not what you are looking for.
As to memory: Rich Walsh has elaborated somewhere in this forum about what the various memory sizes mean and how they play together:
https://www.os2world.com/forum/index.php/topic,3445.msg41758.html#msg41758
It would be nice if we could get that added to "getrusage".
-
Last update: yes, getrusage is available in our libc. Compiling it - will test this binary asap and - if it works as I expect - it's going to HobbesArchive.
Mentore
Seems like our getrusage does not return any memory size information, only use of time ("ru_utime", "ru_stime").
I suspect this is not what you are looking for.
As to memory: Rich Walsh has elaborated somewhere in this forum about what the various memory sizes mean and how they play together:
https://www.os2world.com/forum/index.php/topic,3445.msg41758.html#msg41758
It would be nice if we could get that added to "getrusage".
This is pretty interesting. I did a little testing of the executable and found it works (at least to some extent), but - since it still doesn't launch any graphical interface like gnuplot - I'll surely have to get back to it.
What's sure is that I need to know what actually getrusage does (or, for what's worth, GetProcessInfo from the Win32 counterpart) - the other methods in that function involve using the /proc interface which OS/2 allegedly doesn't implement.
Mentore