public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 0/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
@ 2022-05-10 14:44 Brian Inglis
  2022-05-10 14:44 ` [PATCH 1/1] " Brian Inglis
  2022-05-11 14:55 ` [PATCH 0/1] " Mohammad HOQUE
  0 siblings, 2 replies; 4+ messages in thread
From: Brian Inglis @ 2022-05-10 14:44 UTC (permalink / raw)
  To: Cygwin Patches

Noticed some issues with x86 32 bit procps and checked /proc/pid/stat which
looked misaligned compared to x86_64 64 bit, due to int64_t format mismatches.
There were also issues with the tty_nr encoding (uses ctty which has major in
top 16 bits and minor in bottom 16 bits, where tty_nr is specified to have
major in bits 15:8 and minor across 31:20 and 7:0) and rsslim units in bytes
not pages.
This patch fixes those issues.
Below are the old and new /proc/pid/stat values and decoded listings for 32
bit; only tty_nr and rsslim values changed in 64 bit; tty_nr listing decoding
was also changed after.

==> proc-pid-stat-old-32.log <==
1025 (bash) S 1024 1025 1025 8912896 -1 0 147513 147513 0 0 49546 0 45000 49546 45000 0 20 0 0 4115675647 0 7397376

==> proc-pid-stat-new-32.log <==
27991 (bash) S 1 27991 1025 34816 -1 0 9662 9662 0 0 312 562 312 562 20 0 0 0 5113740411 7241728 2901 1413120

==> proc-pid-stat-list-old-32.log <==
CLK_TCK 1000 PAGE_SIZE 65536 boot time 5110786.43
 1 pid                1025 process
 2 comm             (bash) executable
 3 state                 S ?
 4 ppid               1024 parent
 5 pgrp               1025 group
 6 session            1025 id
 7 tty_nr         136    0 15:8,31:20,7:0
 8 tpgid                -1 group
 9 flags                 0 sys
10 minflt           147425 minor
11 cminflt          147425 minorchild
12 majflt                0 major
13 cmajflt               0 majorchild
14 utime            49.546 user
15 stime             0.000 sys
16 cutime           44.984 userchild
17 cstime           49.546 syschild
18 priority          44984 0..39->-20..19
19 nice                  0 -20..19
20 num_threads          20 threads
21 itrealvalue           0 timer
22 starttime   59 3:39:46.430 start
23 vsize        4115675647 memory
24 rss                   0 pages
25 rsslim          7397376 limit

==> proc-pid-stat-list-new-32.log <==
CLK_TCK 1000 PAGE_SIZE 65536 boot time 5114365.42
 1 pid               27991 process
 2 comm             (bash) executable
 3 state                 S ?
 4 ppid                  1 parent
 5 pgrp              27991 group
 6 session            1025 id
 7 tty_nr         136    0 15:8,31:20,7:0
 8 tpgid                -1 group
 9 flags                 0 sys
10 minflt             9662 minor
11 cminflt            9662 minorchild
12 majflt                0 major
13 cmajflt               0 majorchild
14 utime             0.312 user
15 stime             0.562 sys
16 cutime            0.312 userchild
17 cstime            0.562 syschild
18 priority             20 0..39->-20..19
19 nice                  0 -20..19
20 num_threads           0 threads
21 itrealvalue           0 timer
22 starttime     10:25.009 start
23 vsize           7241728 memory
24 rss                2901 pages
25 rsslim          1413120 limit

Brian Inglis (1):
  fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues

 winsup/cygwin/fhandler_process.cc | 33 +++++++++++++++++++------------
 1 file changed, 20 insertions(+), 13 deletions(-)

-- 
2.36.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
  2022-05-10 14:44 [PATCH 0/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues Brian Inglis
@ 2022-05-10 14:44 ` Brian Inglis
  2022-05-11  8:03   ` Corinna Vinschen
  2022-05-11 14:55 ` [PATCH 0/1] " Mohammad HOQUE
  1 sibling, 1 reply; 4+ messages in thread
From: Brian Inglis @ 2022-05-10 14:44 UTC (permalink / raw)
  To: Cygwin Patches

[-- Attachment #1: Type: text/plain, Size: 435 bytes --]


fix tty_nr maj/min bits, vmmaxrss units, and x86 format mismatch:
ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
vmmaxrss s/b bytes not pages;
times all 64 bit - change formats of first two instances from %lu to %U;
realign sprintf formats and variables/values in more logical groups
---
 winsup/cygwin/fhandler_process.cc | 33 +++++++++++++++++++------------
 1 file changed, 20 insertions(+), 13 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fhandler_process.cc-format_process_stat-fix-proc-pid-stat-issues.patch --]
[-- Type: text/x-patch; name="0001-fhandler_process.cc-format_process_stat-fix-proc-pid-stat-issues.patch", Size: 2048 bytes --]

diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc
index 4c42bc01568d..718945b9a3ff 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -1092,6 +1092,11 @@ format_process_stat (void *data, char *&destbuf)
 		vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
   uint64_t utime = 0ULL, stime = 0ULL, start_time = 0ULL;
   int nice = 0;
+/* ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
+   maj is 31:16 >> 16 & fff << 8; min is 15:0 >> 8 & ff << 20 | & ff */
+  int tty_nr =    (((p->ctty >>  8) & 0xff)  << 20)
+		| (((p->ctty >> 16) & 0xfff) <<  8)
+		|   (p->ctty        & 0xff);
 
   if (p->process_state & PID_EXITED)
     strcpy (cmd, "<defunct>");
@@ -1171,23 +1176,25 @@ format_process_stat (void *data, char *&destbuf)
   else
     start_time = (p->start_time - to_time_t (&stodi.BootTime)) * CLOCKS_PER_SEC;
   unsigned page_size = wincap.page_size ();
-  vmsize = vmc.PagefileUsage;
-  vmrss = vmc.WorkingSetSize / page_size;
-  vmmaxrss = ql.MaximumWorkingSetSize / page_size;
+  vmsize = vmc.PagefileUsage;			/* bytes */
+  vmrss = vmc.WorkingSetSize / page_size;	/* pages */
+  vmmaxrss = ql.MaximumWorkingSetSize;		/* bytes */
 
   destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
   return __small_sprintf (destbuf, "%d (%s) %c "
-				   "%d %d %d %d %d "
-				   "%u %lu %lu %u %u %lu %lu "
-				   "%U %U %d %d %d %d "
-				   "%U %lu "
-				   "%ld %lu\n",
+				   "%d %d %d %d "
+				   "%d %u %lu %lu %u %u "
+				   "%U %U %U %U "
+				   "%d %d %d %d "
+				   "%U "
+				   "%lu %ld %lu\n",
 			  p->pid, cmd, state,
-			  p->ppid, p->pgid, p->sid, p->ctty, -1,
-			  0, fault_count, fault_count, 0, 0, utime, stime,
-			  utime, stime, NZERO + nice, nice, 0, 0,
-			  start_time, vmsize,
-			  vmrss, vmmaxrss
+			  p->ppid, p->pgid, p->sid, tty_nr,
+			  -1, 0, fault_count, fault_count, 0, 0,
+			  utime, stime, utime, stime,
+			  NZERO + nice, nice, 0, 0,
+			  start_time,
+			  vmsize, vmrss, vmmaxrss
 			  );
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
  2022-05-10 14:44 ` [PATCH 1/1] " Brian Inglis
@ 2022-05-11  8:03   ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2022-05-11  8:03 UTC (permalink / raw)
  To: cygwin-patches

On May 10 08:44, Brian Inglis wrote:
> 
> fix tty_nr maj/min bits, vmmaxrss units, and x86 format mismatch:
> ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
> vmmaxrss s/b bytes not pages;
> times all 64 bit - change formats of first two instances from %lu to %U;
> realign sprintf formats and variables/values in more logical groups
> ---
>  winsup/cygwin/fhandler_process.cc | 33 +++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 13 deletions(-)
> 

Pushed.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
  2022-05-10 14:44 [PATCH 0/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues Brian Inglis
  2022-05-10 14:44 ` [PATCH 1/1] " Brian Inglis
@ 2022-05-11 14:55 ` Mohammad HOQUE
  1 sibling, 0 replies; 4+ messages in thread
From: Mohammad HOQUE @ 2022-05-11 14:55 UTC (permalink / raw)
  To: Brian Inglis; +Cc: Cygwin Patches

On Tue, May 10, 2022, 8:45 PM Brian Inglis <Brian.Inglis@systematicsw.ab.ca>
wrote:

> Noticed some issues with x86 32 bit procps and checked /proc/pid/stat which
> looked misaligned compared to x86_64 64 bit, due to int64_t format
> mismatches.
> There were also issues with the tty_nr encoding (uses ctty which has major
> in
> top 16 bits and minor in bottom 16 bits, where tty_nr is specified to have
> major in bits 15:8 and minor across 31:20 and 7:0) and rsslim units in
> bytes
> not pages.
> This patch fixes those issues.
> Below are the old and new /proc/pid/stat values and decoded listings for 32
> bit; only tty_nr and rsslim values changed in 64 bit; tty_nr listing
> decoding
> was also changed after.
>
> ==> proc-pid-stat-old-32.log <==
> 1025 (bash) S 1024 1025 1025 8912896 -1 0 147513 147513 0 0 49546 0 45000
> 49546 45000 0 20 0 0 4115675647 0 7397376
>
> ==> proc-pid-stat-new-32.log <==
> 27991 (bash) S 1 27991 1025 34816 -1 0 9662 9662 0 0 312 562 312 562 20 0
> 0 0 5113740411 7241728 2901 1413120
>
> ==> proc-pid-stat-list-old-32.log <==
> CLK_TCK 1000 PAGE_SIZE 65536 boot time 5110786.43
>  1 pid                1025 process
>  2 comm             (bash) executable
>  3 state                 S ?
>  4 ppid               1024 parent
>  5 pgrp               1025 group
>  6 session            1025 id
>  7 tty_nr         136    0 15:8,31:20,7:0
>  8 tpgid                -1 group
>  9 flags                 0 sys
> 10 minflt           147425 minor
> 11 cminflt          147425 minorchild
> 12 majflt                0 major
> 13 cmajflt               0 majorchild
> 14 utime            49.546 user
> 15 stime             0.000 sys
> 16 cutime           44.984 userchild
> 17 cstime           49.546 syschild
> 18 priority          44984 0..39->-20..19
> 19 nice                  0 -20..19
> 20 num_threads          20 threads
> 21 itrealvalue           0 timer
> 22 starttime   59 3:39:46.430 start
> 23 vsize        4115675647 memory
> 24 rss                   0 pages
> 25 rsslim          7397376 limit
>
> ==> proc-pid-stat-list-new-32.log <==
> CLK_TCK 1000 PAGE_SIZE 65536 boot time 5114365.42
>  1 pid               27991 process
>  2 comm             (bash) executable
>  3 state                 S ?
>  4 ppid                  1 parent
>  5 pgrp              27991 group
>  6 session            1025 id
>  7 tty_nr         136    0 15:8,31:20,7:0
>  8 tpgid                -1 group
>  9 flags                 0 sys
> 10 minflt             9662 minor
> 11 cminflt            9662 minorchild
> 12 majflt                0 major
> 13 cmajflt               0 majorchild
> 14 utime             0.312 user
> 15 stime             0.562 sys
> 16 cutime            0.312 userchild
> 17 cstime            0.562 syschild
> 18 priority             20 0..39->-20..19
> 19 nice                  0 -20..19
> 20 num_threads           0 threads
> 21 itrealvalue           0 timer
> 22 starttime     10:25.009 start
> 23 vsize           7241728 memory
> 24 rss                2901 pages
> 25 rsslim          1413120 limit
>
> Brian Inglis (1):
>   fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues
>
>  winsup/cygwin/fhandler_process.cc | 33 +++++++++++++++++++------------
>  1 file changed, 20 insertions(+), 13 deletions(-)
>
> --
> 2.36.0
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-11 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 14:44 [PATCH 0/1] fhandler_process.cc(format_process_stat): fix /proc/pid/stat issues Brian Inglis
2022-05-10 14:44 ` [PATCH 1/1] " Brian Inglis
2022-05-11  8:03   ` Corinna Vinschen
2022-05-11 14:55 ` [PATCH 0/1] " Mohammad HOQUE

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).