This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getpriority() and top display for priority is inconsistent


> You seem to have worked it out already so please send a patch in
> git format-patch foramt to the cygwin-patches mailing list.

I tried :-/

<cygwin-patches@cygwin.com>:
Sorry, only subscribers may post. (#5.7.2)

I do not use git to pull Cygwin sources.  The last snapshot (that corresponds to the last-known-stable release I'm allowed to use) is a little old,
but here goes the diff patch:

$ diff -p cygwin-snapshot-20181226-{0,1}/winsup/cygwin/fhandler_process.cc
*** cygwin-snapshot-20181226-0/winsup/cygwin/fhandler_process.cc        2018-08-17 14:41:04.000000000 -0400
--- cygwin-snapshot-20181226-1/winsup/cygwin/fhandler_process.cc        2019-08-06 17:05:35.421073900 -0400
*************** format_process_stat (void *data, char *&
*** 1066,1072 ****
    unsigned long fault_count = 0UL,
                vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
    uint64_t utime = 0ULL, stime = 0ULL, start_time = 0ULL;
!   int priority = 0;
    if (p->process_state & PID_EXITED)
      strcpy (cmd, "<defunct>");
    else
--- 1066,1072 ----
    unsigned long fault_count = 0UL,
                vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
    uint64_t utime = 0ULL, stime = 0ULL, start_time = 0ULL;
!
    if (p->process_state & PID_EXITED)
      strcpy (cmd, "<defunct>");
    else
*************** format_process_stat (void *data, char *&
*** 1095,1101 ****
    HANDLE hProcess;
    VM_COUNTERS vmc;
    KERNEL_USER_TIMES put;
-   PROCESS_BASIC_INFORMATION pbi;
    QUOTA_LIMITS ql;
    SYSTEM_TIMEOFDAY_INFORMATION stodi;
    SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION spt;
--- 1095,1100 ----
*************** format_process_stat (void *data, char *&
*** 1115,1123 ****
      status = NtQueryInformationProcess (hProcess, ProcessTimes,
                                        (PVOID) &put, sizeof put, NULL);
    if (NT_SUCCESS (status))
-     status = NtQueryInformationProcess (hProcess, ProcessBasicInformation,
-                                       (PVOID) &pbi, sizeof pbi, NULL);
-   if (NT_SUCCESS (status))
      status = NtQueryInformationProcess (hProcess, ProcessQuotaLimits,
                                        (PVOID) &ql, sizeof ql, NULL);
    CloseHandle (hProcess);
--- 1114,1119 ----
*************** format_process_stat (void *data, char *&
*** 1138,1154 ****
    stime = put.KernelTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
    start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart)
               * CLOCKS_PER_SEC / NS100PERSEC;
-   /* The BasePriority returned to a 32 bit process under WOW64 is
-      apparently broken, for 32 and 64 bit target processes.  64 bit
-      processes get the correct base priority, even for 32 bit processes. */
-   if (wincap.is_wow64 ())
-     priority = 8; /* Default value. */
-   else
-     priority = pbi.BasePriority;
    unsigned page_size = wincap.page_size ();
    vmsize = vmc.PagefileUsage;
    vmrss = vmc.WorkingSetSize / page_size;
    vmmaxrss = ql.MaximumWorkingSetSize / page_size;

    destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
    return __small_sprintf (destbuf, "%d (%s) %c "
--- 1134,1144 ----
    stime = put.KernelTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
    start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart)
               * CLOCKS_PER_SEC / NS100PERSEC;
    unsigned page_size = wincap.page_size ();
    vmsize = vmc.PagefileUsage;
    vmrss = vmc.WorkingSetSize / page_size;
    vmmaxrss = ql.MaximumWorkingSetSize / page_size;
+   int nice = winprio_to_nice(GetPriorityClass(hProcess));

    destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
    return __small_sprintf (destbuf, "%d (%s) %c "
*************** format_process_stat (void *data, char *&
*** 1160,1166 ****
                          p->pid, cmd, state,
                          p->ppid, p->pgid, p->sid, p->ctty, -1,
                          0, fault_count, fault_count, 0, 0, utime, stime,
!                         utime, stime, priority, 0, 0, 0,
                          start_time, vmsize,
                          vmrss, vmmaxrss
                          );
--- 1150,1156 ----
                          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
                          );


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]