public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: getpriority() and top display for priority inconsistent
@ 2019-08-08 13:46 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
  2019-08-08 15:40 ` Corinna Vinschen
  0 siblings, 1 reply; 10+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin @ 2019-08-08 13:46 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

> I pushed your patch with a short commit message.

Thanks!  Thinking about that a little more, getpriority(PRIO_PROCESS) returns the cached version of priority (since the last
setpriority()) but should return "live" version by re-getting and re-caching the actual thing from the system:
1. The priority could have been changed from the outside (it is a windows process, after all, and anybody can use Task Manager, for example);
2. When pulling group or user priorities from getpriority(), those things get returned from fresh "winpids", which gets constructed
   on-the-fly and so "nice" gets populated from the system; so the results can be, again, inconsistent (e.g. if compared to getpriority() for
   the process alone, since it is a cached one);
3. "/proc/PID/stat" always shows the live results (even before my change, although it was showing the "wrong" value).

Thoughts?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: getpriority() and top display for priority inconsistent
@ 2019-08-14 20:01 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
  2019-08-15  7:29 ` Corinna Vinschen
  0 siblings, 1 reply; 10+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin @ 2019-08-14 20:01 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

> Feel free to provide a patch, just, please, create a valid git commit message

"getpriority() consistent with process priority https://cygwin.com/ml/cygwin/2019-08/msg00122.html"

The changeset is really trivial:

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index a914ae8..20126ce 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3977,7 +3977,12 @@ getpriority (int which, id_t who)
       if (!who)
        who = myself->pid;
       if ((pid_t) who == myself->pid)
-       return myself->nice;
+        {
+          DWORD winprio = GetPriorityClass(GetCurrentProcess());
+          if (winprio != nice_to_winprio(myself->nice))
+            myself->nice = winprio_to_nice(winprio);
+          return myself->nice;
+        }
       break;
     case PRIO_PGRP:
       if (!who)

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2019-08-15 11:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 13:46 getpriority() and top display for priority inconsistent Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-08 15:40 ` Corinna Vinschen
2019-08-14 20:01 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15  7:29 ` Corinna Vinschen
2019-08-15  9:41   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15 10:20     ` Corinna Vinschen
2019-08-15 10:23       ` Corinna Vinschen
2019-08-15 11:04       ` Houder
2019-08-15 11:13         ` john doe
2019-08-15 10:54     ` john doe

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).