Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misuse of the getrusage() function #573

Closed
Rhialto opened this issue Jun 17, 2023 · 3 comments
Closed

Misuse of the getrusage() function #573

Rhialto opened this issue Jun 17, 2023 · 3 comments
Labels
(Duplicate) An issue was already created for the described problem. Please also refer to the other issue. (*WON'T FIX*) The requested change was rejected or the described behavior is by design.

Comments

@Rhialto
Copy link
Contributor

Rhialto commented Jun 17, 2023

In my quest to make Hercules compile cleanly, I came across this compiler warning from gcc 10 on NetBSD:

hsccmd.c: In function 'qproc_cmd':
hsccmd.c:9409:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
 9409 |             if (getrusage( (int) sysblk.cputid[i], &rusage ) == 0)
      |                            ^

According to my manual, the first argument to getrusage() should be an integer value, either RUSAGE_SELF or RUSAGE_CHILDREN. The specified value is of type TID, apparently a "CPU thread id". That can't work.

The linux manual page at https://linux.die.net/man/2/getrusage shows a third possible value: RUSAGE_THREAD (since Linux 2.6.26) which indicates the current thread, not some random specified thread.

This isn't fixable with a simple patch. The whole context (looping over threads and trying to obtain each of their resource usages) is inapplicable here.

hyperion/hsccmd.c

Lines 9402 to 9409 in 65c97fd

for (i=0; i < sysblk.maxcpu; i++)
{
if (IS_CPU_ONLINE( i ))
{
struct rusage rusage;
char* pmsg = "";
if (getrusage( (int) sysblk.cputid[i], &rusage ) == 0)

Whatever this function (which handles the qproc command) tries to do can't be done with getrusage(), if at all (within POSIX), and probably needs to be re-thought. Hence no patch, sorry about that.

@Fish-Git
Copy link
Member

FYI:

This is a very old issue, and was discussed to death many times in many different GitHub Issues over the years, in both the old Hercules repository as well as in SDL's repository too:

I personally am not the least bit interested in dredging up this long standing known issue just so we can once again beat a dead horse that has already been resting peacefully in its tomb for years now.

I am closing this issue.

@Fish-Git Fish-Git added (*WON'T FIX*) The requested change was rejected or the described behavior is by design. (Duplicate) An issue was already created for the described problem. Please also refer to the other issue. labels Jun 17, 2023
@wrljet
Copy link
Member

wrljet commented Jun 18, 2023

I've been meaning to bring this up for a year or so, but haven't gotten around to it. :)

@Fish-Git
Copy link
Member

Fish-Git commented Jun 18, 2023

(EDIT: fixed below issue #217 link)

Well, if you read that first issue (#217), you'll see Mark's comment where he says it did work at one point in time, but then they changed things.

It's kind of frustrating that, apparently, neither Linux nor POSIX seems to support/provide any way today to do what we ultimately need to do: obtain resource usage for another thread in our own damn process!   :(

It's trivially easy to do so on Windows, but it seems Linux/POSIX either doesn't provide that ability, or else they're hiding it.

Isn't there some tool on Linux that allows you to see (display) CPU and memory usage, etc, for all/ANY processes in the system? Do those tools allow you to drill down and see such information for each thread in a process? If they do, then there's obviously a way to do it! We just need to learn HOW.

In any case, it's not my problem, so I'm not going to worry about it. I don't know Linux. I'm not a Linux developer. I leave such things up to the other developers on our team who are experienced at Linux. That's their job. I deal with the Windows side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(Duplicate) An issue was already created for the described problem. Please also refer to the other issue. (*WON'T FIX*) The requested change was rejected or the described behavior is by design.
Projects
None yet
Development

No branches or pull requests

3 participants