Author Topic: [GCC] Unable to define getMemorySize()  (Read 2707 times)

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
[GCC] Unable to define getMemorySize()
« 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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5095
  • Karma: +117/-1
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #1 on: September 25, 2024, 06:31:10 pm »
Looks like you will have to write an OS/2 get_avail_mem_size.

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #2 on: September 26, 2024, 12:38:34 pm »
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

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #3 on: September 26, 2024, 04:01:19 pm »
#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;
...
« Last Edit: September 26, 2024, 04:11:20 pm by Lars »

Silvan Scherrer

  • Full Member
  • ***
  • Posts: 204
  • Karma: +1/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #4 on: September 26, 2024, 05:40:24 pm »
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
kind regards
Silvan
CTO bww bitwise works GmbH

Please help us with donations, so we can further work on OS/2 based projects. Our Shop is at https://www.bitwiseworks.com/shop/index.php

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #5 on: September 27, 2024, 09:44:10 am »
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.

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #6 on: September 30, 2024, 09:56:12 am »
#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

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #7 on: September 30, 2024, 11:58:26 am »

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

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #8 on: September 30, 2024, 12:19:06 pm »
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

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #9 on: September 30, 2024, 01:57:45 pm »
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".

Mentore

  • Full Member
  • ***
  • Posts: 224
  • Karma: +11/-0
    • View Profile
Re: [GCC] Unable to define getMemorySize()
« Reply #10 on: October 01, 2024, 08:14:11 am »
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